Merge remote-tracking branch 'origin/development' into development
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 26 Jun 2019 19:19:17 +0000 (21:19 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 26 Jun 2019 19:19:17 +0000 (21:19 +0200)
net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java

index b42a05f..c493cc4 100644 (file)
@@ -1,6 +1,7 @@
 package net.mograsim.logic.ui.model.components.mi.nandbased;
 
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.components.GUINandGate;
 import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
@@ -10,6 +11,8 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint;
 
 public class GUI_rsLatch extends SimpleRectangularSubmodelComponent
 {
+       private GUIWire wireQ, wire_Q;
+
        public GUI_rsLatch(ViewModelModifiable model)
        {
                super(model, 1, "_rsLatch");
@@ -44,7 +47,25 @@ public class GUI_rsLatch extends SimpleRectangularSubmodelComponent
                new GUIWire(submodelModifiable, nand2.getPin("Y"), cp2, new Point(65, 22.5));
                new GUIWire(submodelModifiable, cp1, nand2.getPin("A"), new Point[0]);
                new GUIWire(submodelModifiable, cp2, nand1.getPin("B"), new Point(65, 42.5), new Point(5, 42.5), new Point(5, 22.5));
-               new GUIWire(submodelModifiable, cp1, Q, new Point(35, 17.5), new Point(35, 7.5), new Point(65, 7.5), new Point(65, 12.5));
-               new GUIWire(submodelModifiable, cp2, _Q, new Point[0]);
+               wireQ = new GUIWire(submodelModifiable, cp1, Q, new Point(35, 17.5), new Point(35, 7.5), new Point(65, 7.5), new Point(65, 12.5));
+               wire_Q = new GUIWire(submodelModifiable, cp2, _Q, new Point[0]);
+       }
+
+       @Override
+       public void setHighLevelState(String stateID, Object newState)
+       {
+               if ("q".equals(stateID))
+               {
+                       // TODO force this to happen without any Timeline updates in the meantime.
+                       // Maybe make it a requirement of setHighLevelState that the Timeline is "halted" during a call?
+                       BitVector newStateCasted = (BitVector) newState;
+                       if (wireQ.hasLogicModelBinding())
+                               wireQ.forceWireValues(newStateCasted);
+                       // We set both wires because then both outputs go to their correct state at the same time, and to avoid problems when not both
+                       // inputs are 1
+                       if (wire_Q.hasLogicModelBinding())
+                               wire_Q.forceWireValues(newStateCasted.not());
+               } else
+                       super.setHighLevelState(stateID, newState);
        }
 }
\ No newline at end of file
index b9c8a10..3b909c5 100644 (file)
@@ -6,7 +6,6 @@ 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;
-import net.mograsim.logic.core.LogicObservable;
 import net.mograsim.logic.core.LogicObserver;
 import net.mograsim.logic.core.components.BitDisplay;
 import net.mograsim.logic.core.types.BitVectorFormatter;
@@ -58,21 +57,16 @@ public class GUIBitDisplay extends GUIComponent
 
        public void setLogicModelBinding(BitDisplay bitDisplay)
        {
-               deregisterLogicObs(this.bitDisplay);
+               if (this.bitDisplay != null)
+                       this.bitDisplay.deregisterObserver(logicObs);
                this.bitDisplay = bitDisplay;
-               registerLogicObs(bitDisplay);
+               if (bitDisplay != null)
+                       bitDisplay.registerObserver(logicObs);
        }
 
-       private void registerLogicObs(LogicObservable observable)
+       public boolean hasLogicModelBinding()
        {
-               if (observable != null)
-                       observable.registerObserver(logicObs);
-       }
-
-       private void deregisterLogicObs(LogicObservable observable)
-       {
-               if (observable != null)
-                       observable.deregisterObserver(logicObs);
+               return bitDisplay != null;
        }
 
        public BitDisplay getBitDisplay()
index 6e566c4..a852c57 100644 (file)
@@ -138,6 +138,14 @@ public abstract class GUIComponent
                return pin;
        }
 
+       // high-level access
+
+       @SuppressWarnings({ "static-method", "unused" }) // this method is intended to be overridden
+       public void setHighLevelState(String stateID, Object newState)
+       {
+               throw new IllegalArgumentException("No high level state with ID " + stateID);
+       }
+
        // "graphical" operations
 
        /**
index be4c327..77decef 100644 (file)
@@ -9,6 +9,7 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.core.LogicObservable;
 import net.mograsim.logic.core.LogicObserver;
 import net.mograsim.logic.core.components.ManualSwitch;
+import net.mograsim.logic.core.types.Bit;
 import net.mograsim.logic.core.types.BitVectorFormatter;
 import net.mograsim.logic.core.wires.Wire.ReadEnd;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
@@ -68,6 +69,22 @@ public class GUIManualSwitch extends GUIComponent
                registerLogicObs(logicSwitch);
        }
 
+       public boolean hasLogicModelBinding()
+       {
+               return logicSwitch != null;
+       }
+
+       @Override
+       public void setHighLevelState(String stateID, Object newState)
+       {
+               if ("out".equals(stateID))
+               {
+                       if (logicSwitch != null)
+                               logicSwitch.setToValueOf((Bit) newState);
+               } else
+                       super.setHighLevelState(stateID, newState);
+       }
+
        private void registerLogicObs(LogicObservable observable)
        {
                if (observable != null)
index 08b1d42..db6d440 100644 (file)
@@ -10,7 +10,9 @@ import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.core.LogicObserver;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.types.BitVectorFormatter;
+import net.mograsim.logic.core.wires.Wire;
 import net.mograsim.logic.core.wires.Wire.ReadEnd;
 import net.mograsim.logic.ui.ColorHelper;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
@@ -308,6 +310,23 @@ public class GUIWire
                        end.registerObserver(logicObs);
        }
 
+       /**
+        * Returns whether this {@link GUIWire} has a logic model binding or not.
+        */
+       public boolean hasLogicModelBinding()
+       {
+               return end != null;
+       }
+
+       /**
+        * If this {@link GUIWire} has a logic model binding, delegates to {@link Wire#forceValues(BitVector)} for the {@link Wire}
+        * corresponding to this {@link GUIWire}.
+        */
+       public void forceWireValues(BitVector values)
+       {
+               end.getWire().forceValues(values);
+       }
+
        // listeners
 
        // @formatter:off
index c412c56..de5ba4a 100644 (file)
@@ -95,6 +95,14 @@ public class WireCrossPoint extends GUIComponent
                        end.registerObserver(logicObs);
        }
 
+       /**
+        * Returns whether this {@link WireCrossPoint} has a logic model binding or not.
+        */
+       public boolean hasLogicModelBinding()
+       {
+               return end != null;
+       }
+
        // serializing
 
        @Override