Timeline updated (executeUntil, setTimeFunction)
[Mograsim.git] / era.mi / src / era / mi / logic / tests / GUITest.java
index 54f9269..0ff118a 100644 (file)
@@ -15,12 +15,12 @@ import javax.swing.JFrame;
 import javax.swing.JPanel;\r
 import javax.swing.WindowConstants;\r
 \r
-import era.mi.logic.Simulation;\r
 import era.mi.logic.components.ManualSwitch;\r
 import era.mi.logic.components.gates.NotGate;\r
 import era.mi.logic.components.gates.OrGate;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.timeline.Timeline.ExecutionResult;\r
-import era.mi.logic.wires.WireArray;\r
+import era.mi.logic.wires.Wire;\r
 \r
 public class GUITest extends JPanel\r
 {\r
@@ -31,20 +31,22 @@ public class GUITest extends JPanel
        private static final int OR_DELAY = 100;\r
        private static final int NOT_DELAY = 100;\r
 \r
-       WireArray r = new WireArray(1, WIRE_DELAY);\r
-       WireArray s = new WireArray(1, WIRE_DELAY);\r
-       WireArray t1 = new WireArray(1, WIRE_DELAY);\r
-       WireArray t2 = new WireArray(1, WIRE_DELAY);\r
-       WireArray q = new WireArray(1, WIRE_DELAY);\r
-       WireArray nq = new WireArray(1, WIRE_DELAY);\r
+       private Timeline t = new Timeline(11);\r
 \r
-       ManualSwitch rIn = new ManualSwitch(r);\r
-       ManualSwitch sIn = new ManualSwitch(s);\r
+       Wire r = new Wire(t, 1, WIRE_DELAY);\r
+       Wire s = new Wire(t, 1, WIRE_DELAY);\r
+       Wire t1 = new Wire(t, 1, WIRE_DELAY);\r
+       Wire t2 = new Wire(t, 1, WIRE_DELAY);\r
+       Wire q = new Wire(t, 1, WIRE_DELAY);\r
+       Wire nq = new Wire(t, 1, WIRE_DELAY);\r
 \r
-       OrGate or1 = new OrGate(OR_DELAY, t2, r, nq);\r
-       OrGate or2 = new OrGate(OR_DELAY, t1, s, q);\r
-       NotGate not1 = new NotGate(NOT_DELAY, t2, q);\r
-       NotGate not2 = new NotGate(NOT_DELAY, t1, nq);\r
+       ManualSwitch rIn = new ManualSwitch(t, r.createReadWriteEnd());\r
+       ManualSwitch sIn = new ManualSwitch(t, s.createReadWriteEnd());\r
+\r
+       OrGate or1 = new OrGate(t, OR_DELAY, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
+       OrGate or2 = new OrGate(t, OR_DELAY, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
+       NotGate not1 = new NotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
+       NotGate not2 = new NotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
 \r
        Map<ManualSwitch, Rectangle> switchMap = new HashMap<>();\r
 \r
@@ -109,6 +111,11 @@ public class GUITest extends JPanel
                });\r
        }\r
 \r
+       public Timeline getTimeline()\r
+       {\r
+               return t;\r
+       };\r
+\r
        @Override\r
        public void paint(Graphics some_g)\r
        {\r
@@ -170,14 +177,14 @@ public class GUITest extends JPanel
                g.setFont(g.getFont().deriveFont(Math.min(height, width) / 40f));\r
        }\r
 \r
-       private static void drawString(Graphics g, String s, int x, int y, double anchorX, double anchorY)\r
+       private void drawString(Graphics g, String s, int x, int y, double anchorX, double anchorY)\r
        {\r
                int h = g.getFontMetrics().getAscent();\r
                int w = g.getFontMetrics().stringWidth(s);\r
                g.drawString(s, x - (int) (w * anchorX), y + (int) (h * anchorY));\r
        }\r
 \r
-       private void drawWire(Graphics g, WireArray wa, String name, double x1, double y1, double x2, double y2)\r
+       private void drawWire(Graphics g, Wire wa, String name, double x1, double y1, double x2, double y2)\r
        {\r
                setTo(g, wa);\r
                g.drawLine(gX(x1), gY(y1), gX(x2), gY(y2));\r
@@ -224,7 +231,7 @@ public class GUITest extends JPanel
                g.setColor(Color.BLACK);\r
        }\r
 \r
-       private static void setTo(Graphics g, WireArray wa)\r
+       private static void setTo(Graphics g, Wire wa)\r
        {\r
                switch (wa.getValue())\r
                {\r
@@ -275,9 +282,9 @@ public class GUITest extends JPanel
 \r
                while (f.isVisible())\r
                {\r
-                       ExecutionResult er = Simulation.TIMELINE.executeUpTo((lastFrame - begin) * 3, lastFrame + 14);\r
-//                             if (Simulation.TIMELINE.hasNext()) \r
-//                             Simulation.TIMELINE.executeNext();\r
+                       ExecutionResult er = gt.getTimeline().executeUntil(gt.getTimeline().laterThan((lastFrame - begin) * 3), lastFrame + 14);\r
+//                             if (t.hasNext()) \r
+//                             t.executeNext();\r
                        if (er != ExecutionResult.NOTHING_DONE)\r
                                gt.repaint(12);\r
                        try\r