Merge branch 'development' of
authorFabian Stemmler <stemmler@in.tum.de>
Wed, 29 May 2019 10:42:50 +0000 (12:42 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Wed, 29 May 2019 10:42:50 +0000 (12:42 +0200)
https://gitlab.lrz.de/lrr-tum/students/eragp-misim-2019 into development

# Conflicts:
# LogicUI/oldsrc/RSLatchGUIExample.java
# LogicUI/src/era/mi/gui/LogicUIStandalone.java
# LogicUI/src/era/mi/gui/components/GUIManualSwitch.java
# SampleERCP/src/sampleercp/parts/LogicUIPart.java

1  2 
LogicUI/oldsrc/RSLatchGUIExample.java
LogicUI/src/era/mi/gui/LogicUIStandalone.java
LogicUI/src/era/mi/gui/components/GUIManualSwitch.java

index 0000000,0fb1886..5c104d7
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,61 +1,62 @@@
+ package era.mi.gui.examples;
+ import era.mi.gui.LogicUICanvas;
+ import era.mi.gui.LogicUIStandalone;
+ import era.mi.gui.components.GUIManualSwitch;
+ import era.mi.gui.components.GUINotGate;
+ import era.mi.gui.components.GUIOrGateOld;
+ import era.mi.gui.wires.WireConnectionPoint;
+ import era.mi.logic.timeline.Timeline;
+ import era.mi.logic.wires.Wire;
+ import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+ public class RSLatchGUIExample
+ {
+       private static final int WIRE_DELAY = 10;
+       private static final int OR_DELAY = 50;
+       private static final int NOT_DELAY = 50;
+       public static void main(String[] args)
+       {
+               Timeline t = new Timeline(11);
++              t.setTimeFunction(() -> System.currentTimeMillis()); // real time simulation
+               LogicUIStandalone ui = new LogicUIStandalone(t);
+               addComponentsAndWires(ui.getLogicUICanvas(), t);
+               ui.run();
+       }
+       public static void addComponentsAndWires(LogicUICanvas ui, Timeline t)
+       {
+               Wire r = new Wire(t, 1, WIRE_DELAY);
+               Wire s = new Wire(t, 1, WIRE_DELAY);
+               Wire t2 = new Wire(t, 1, WIRE_DELAY);
+               Wire t1 = new Wire(t, 1, WIRE_DELAY);
+               Wire q = new Wire(t, 1, WIRE_DELAY);
+               Wire nq = new Wire(t, 1, WIRE_DELAY);
+               GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(t, r.createReadWriteEnd()), 100, 100);
+               GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(t, s.createReadWriteEnd()), 100, 200);
+               GUIOrGateOld or1 = ui.addComponent(new GUIOrGateOld(t, OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()),
+                               160, 102.5);
+               GUIOrGateOld or2 = ui.addComponent(new GUIOrGateOld(t, OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()),
+                               160, 192.5);
+               GUINotGate not1 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);
+               GUINotGate not2 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);
+               WireConnectionPoint p1 = ui.addComponent(new WireConnectionPoint(q, 3), 250, 112.5);
+               WireConnectionPoint p2 = ui.addComponent(new WireConnectionPoint(nq, 3), 250, 202.5);
+               WireConnectionPoint o1 = ui.addComponent(new WireConnectionPoint(q, 1), 270, 112.5);
+               WireConnectionPoint o2 = ui.addComponent(new WireConnectionPoint(nq, 1), 270, 202.5);
+               ui.addWire(rIn, 0, or1, 0);
+               ui.addWire(sIn, 0, or2, 1);
+               ui.addWire(or1, 2, not1, 0);
+               ui.addWire(or2, 2, not2, 0);
+               ui.addWire(not1, 1, p1, 0);
+               ui.addWire(not2, 1, p2, 0);
+               ui.addWire(p1, 1, or2, 0, new Point(250, 130), new Point(140, 185), new Point(140, 197.5));
+               ui.addWire(p2, 1, or1, 1, new Point(250, 185), new Point(140, 130), new Point(140, 117.5));
+               ui.addWire(p1, 2, o1, 0);
+               ui.addWire(p2, 2, o2, 0);
+       }
+ }
@@@ -49,33 -50,33 +50,34 @@@ public class LogicUIStandalon
        public void run()
        {
                AtomicBoolean running = new AtomicBoolean(true);
-               Thread simulationThread = new Thread(() ->
-               {
-                       while (running.get())
-                       {
-                               // always execute to keep timeline from "hanging behind" for too long
-                               timeline.executeUntil(timeline.laterThan(System.currentTimeMillis()), System.currentTimeMillis() + 10);
-                               long sleepTime;
-                               if (timeline.hasNext())
-                                       sleepTime = timeline.nextEventTime() - System.currentTimeMillis();
-                               else
-                                       sleepTime = 10;
-                               try
-                               {
-                                       if (sleepTime > 0)
-                                               Thread.sleep(sleepTime);
-                               }
-                               catch (InterruptedException e)
-                               {
-                               } // it is normal execution flow to be interrupted
-                       }
-               });
-               simulationThread.start();
-               timeline.addEventAddedListener(event ->
-               {
-                       if (event.getTiming() <= System.currentTimeMillis())
-                               simulationThread.interrupt();
-               });
+ //            Thread simulationThread = new Thread(() ->
+ //            {
+ //                    while (running.get())
+ //                    {
+ //                            // always execute to keep timeline from "hanging behind" for too long
++//                            timeline.executeUntil(timeline.laterThan(System.currentTimeMillis()), System.currentTimeMillis() + 10);         
+ //                            model.timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
+ //                            long sleepTime;
+ //                            if (model.timeline.hasNext())
+ //                                    sleepTime = model.timeline.nextEventTime() - System.currentTimeMillis();
+ //                            else
+ //                                    sleepTime = 10;
+ //                            try
+ //                            {
+ //                                    if (sleepTime > 0)
+ //                                            Thread.sleep(sleepTime);
+ //                            }
+ //                            catch (InterruptedException e)
+ //                            {
+ //                            } // it is normal execution flow to be interrupted
+ //                    }
+ //            });
+ //            simulationThread.start();
+ //            model.timeline.addEventAddedListener(event ->
+ //            {
+ //                    if (event.getTiming() <= System.currentTimeMillis())
+ //                            simulationThread.interrupt();
+ //            });
  
                shell.open();
                while (!shell.isDisposed())
index fde7bbd,0000000..bcfa464
mode 100644,000000..100644
--- /dev/null
@@@ -1,96 -1,0 +1,6 @@@
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import era.mi.logic.components.ManualSwitch;
- import era.mi.logic.timeline.Timeline;
- import era.mi.logic.types.Bit;
- import era.mi.logic.wires.Wire.ReadEnd;
- import era.mi.logic.wires.Wire.ReadWriteEnd;
- import net.haspamelodica.swt.helper.gcs.GeneralGC;
- import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
- import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
- import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
- public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent
 +package era.mi.gui.components;
 +
-       private static final Map<Bit, String> bitNames;
-       static
-       {
-               Map<Bit, String> bitNamesModifiable = new HashMap<>();
-               bitNamesModifiable.put(Bit.ONE, "1");
-               bitNamesModifiable.put(Bit.ZERO, "0");
-               bitNamesModifiable.put(Bit.Z, "Z");
-               bitNamesModifiable.put(Bit.U, "U");
-               bitNamesModifiable.put(Bit.X, "X");
-               bitNames = Collections.unmodifiableMap(bitNamesModifiable);
-       }
-       private final ReadEnd we;
-       private final List<ReadEnd> connectedWireEnds;
-       private final List<Point> wireEndConnectionPoints;
-       public GUIManualSwitch(Timeline timeline, ReadWriteEnd output)
-       {
-               super(timeline, output);
-               this.we = output;
-               List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();
-               List<Point> wireEndConnectionPointsModifiable = new ArrayList<>();
-               connectedWireEndsModifiable.add(output);
-               wireEndConnectionPointsModifiable.add(new Point(20, 7.5));
-               this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable);
-               this.wireEndConnectionPoints = Collections.unmodifiableList(wireEndConnectionPointsModifiable);
-       }
-       @Override
-       public Rectangle getBounds()
-       {
-               return new Rectangle(0, 0, 20, 15);
-       }
-       @Override
-       public void render(GeneralGC gc)
-       {
-               gc.drawRectangle(0, 0, 20, 15);
-               String label = bitNames.get(we.getValue());
-               Font oldFont = gc.getFont();
-               Font labelFont = new Font(oldFont.getName(), 6, oldFont.getStyle());
-               gc.setFont(labelFont);
-               Point textExtent = gc.textExtent(label);
-               gc.drawText(label, 10 - textExtent.x / 2, 7.5 - textExtent.y / 2, true);
-               gc.setFont(oldFont);
-       }
-       @Override
-       public boolean clicked(double x, double y)
-       {
-               timeline.addEvent((e) -> toggle(), (int) (System.currentTimeMillis() - timeline.getSimulationTime()));
-               return true;
-       }
-       @Override
-       public int getConnectedWireEndsCount()
-       {
-               return connectedWireEnds.size();
-       }
-       @Override
-       public ReadEnd getConnectedWireEnd(int connectionIndex)
-       {
-               return connectedWireEnds.get(connectionIndex);
-       }
++public class GUIManualSwitch
 +{
-       @Override
-       public Point getWireEndConnectionPoint(int connectionI)
-       {
-               return wireEndConnectionPoints.get(connectionI);
-       }
- }
 +
++}