X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2Fmi%2Fnandbased%2FGUIdlatch4.java;h=388c454520b57925d85bee6ae238ad880470772d;hb=5ece0acf049bf9af2933f513fe0206565681f622;hp=440cfb40e19bd6a19a21eab2a85ac7097e6a4341;hpb=b37ba7609a925cc945bbac0f6ead619d07912238;p=Mograsim.git diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch4.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch4.java index 440cfb40..388c4545 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch4.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch4.java @@ -1,17 +1,30 @@ package net.mograsim.logic.ui.model.components.mi.nandbased; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.mograsim.logic.core.types.Bit; +import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent; +import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent; import net.mograsim.logic.ui.model.wires.GUIWire; import net.mograsim.logic.ui.model.wires.Pin; import net.mograsim.logic.ui.model.wires.WireCrossPoint; +import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator; public class GUIdlatch4 extends SimpleRectangularSubmodelComponent { + private GUIdlatch dlatch1; + private GUIdlatch dlatch2; + private GUIdlatch dlatch3; + private GUIdlatch dlatch4; + public GUIdlatch4(ViewModelModifiable model) { - super(model, 1, "GUIdlatch4"); + this(model, null); + } + + public GUIdlatch4(ViewModelModifiable model, String name) + { + super(model, 1, "GUIdlatch4", name); setSubmodelScale(.4); setInputPins("D1", "D2", "D3", "D4", "C"); setOutputPins("Q1", "Q2", "Q3", "Q4"); @@ -31,10 +44,10 @@ public class GUIdlatch4 extends SimpleRectangularSubmodelComponent Pin Q3 = getSubmodelPin("Q3"); Pin Q4 = getSubmodelPin("Q4"); - GUIdlatch dlatch1 = new GUIdlatch(submodelModifiable); - GUIdlatch dlatch2 = new GUIdlatch(submodelModifiable); - GUIdlatch dlatch3 = new GUIdlatch(submodelModifiable); - GUIdlatch dlatch4 = new GUIdlatch(submodelModifiable); + dlatch1 = new GUIdlatch(submodelModifiable); + dlatch2 = new GUIdlatch(submodelModifiable); + dlatch3 = new GUIdlatch(submodelModifiable); + dlatch4 = new GUIdlatch(submodelModifiable); WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1); WireCrossPoint cp3 = new WireCrossPoint(submodelModifiable, 1); @@ -63,5 +76,71 @@ public class GUIdlatch4 extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, dlatch2.getPin("Q"), Q2, new Point[0]); new GUIWire(submodelModifiable, dlatch3.getPin("Q"), Q3, new Point[0]); new GUIWire(submodelModifiable, dlatch4.getPin("Q"), Q4, new Point[0]); + + addAtomicHighLevelStateID("q1"); + addAtomicHighLevelStateID("q2"); + addAtomicHighLevelStateID("q3"); + addAtomicHighLevelStateID("q4"); + addAtomicHighLevelStateID("q"); + } + + @Override + public void setAtomicHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "q1": + dlatch1.setHighLevelState("q", newState); + break; + case "q2": + dlatch2.setHighLevelState("q", newState); + break; + case "q3": + dlatch3.setHighLevelState("q", newState); + break; + case "q4": + dlatch4.setHighLevelState("q", newState); + break; + case "q": + BitVector newStateCasted = (BitVector) newState; + setHighLevelState("q1", newStateCasted.getBit(0)); + setHighLevelState("q2", newStateCasted.getBit(1)); + setHighLevelState("q3", newStateCasted.getBit(2)); + setHighLevelState("q4", newStateCasted.getBit(3)); + break; + default: + // should not happen because we tell SubmodelComponent to only allow these state IDs. + throw new IllegalStateException("Illegal atomic state ID: " + stateID); + } + } + + @Override + public Object getAtomicHighLevelState(String stateID) + { + switch (stateID) + { + case "q1": + return dlatch1.getHighLevelState("q"); + case "q2": + return dlatch2.getHighLevelState("q"); + case "q3": + return dlatch3.getHighLevelState("q"); + case "q4": + return dlatch4.getHighLevelState("q"); + case "q": + Bit q1 = (Bit) getHighLevelState("q1"); + Bit q2 = (Bit) getHighLevelState("q2"); + Bit q3 = (Bit) getHighLevelState("q3"); + Bit q4 = (Bit) getHighLevelState("q4"); + return BitVector.of(q1, q2, q3, q4); + default: + // should not happen because we tell SubmodelComponent to only allow these state IDs. + throw new IllegalStateException("Illegal atomic state ID: " + stateID); + } + } + + static + { + IndirectGUIComponentCreator.setComponentSupplier(GUIdlatch4.class.getCanonicalName(), (m, p, n) -> new GUIdlatch4(m, n)); } } \ No newline at end of file