X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fmi%2Fnandbased%2FGUIram2.java;h=2f45cb7d104b0648d05d7cbf3ae72e0061ca755d;hb=5b66e19c7dcae146d504e9fe3899486d46c86639;hp=2ebc1e338368dd019acc39dfd5d8155390114d56;hpb=b5d8c2d71e27350ea7c9314e40df5bb0584271cd;p=Mograsim.git diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/model/components/mi/nandbased/GUIram2.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/model/components/mi/nandbased/GUIram2.java index 2ebc1e33..2f45cb7d 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/model/components/mi/nandbased/GUIram2.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/model/components/mi/nandbased/GUIram2.java @@ -1,21 +1,20 @@ package net.mograsim.logic.model.model.components.mi.nandbased; +import java.util.Arrays; + import net.haspamelodica.swt.helper.swtobjectwrappers.Point; -import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.submodels.SimpleRectangularSubmodelComponent; import net.mograsim.logic.model.model.wires.GUIWire; import net.mograsim.logic.model.model.wires.Pin; import net.mograsim.logic.model.model.wires.WireCrossPoint; import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; +import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.StandardHighLevelStateHandler; +import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.atomic.BitVectorSplittingAtomicHighLevelStateHandler; +import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.subcomponent.DelegatingSubcomponentHighLevelStateHandler; public class GUIram2 extends SimpleRectangularSubmodelComponent { - private GUIdlatch4 cell00; - private GUIdlatch4 cell01; - private GUIdlatch4 cell10; - private GUIdlatch4 cell11; - public GUIram2(ViewModelModifiable model) { this(model, null); @@ -55,10 +54,10 @@ public class GUIram2 extends SimpleRectangularSubmodelComponent GUIdemux2 demuxA = new GUIdemux2 (submodelModifiable); GUIdemux2 demuxB = new GUIdemux2 (submodelModifiable); GUIand41 weAndB = new GUIand41 (submodelModifiable); - cell00 = new GUIdlatch4 (submodelModifiable); - cell01 = new GUIdlatch4 (submodelModifiable); - cell10 = new GUIdlatch4 (submodelModifiable); - cell11 = new GUIdlatch4 (submodelModifiable); + GUIdlatch4 cell00 = new GUIdlatch4 (submodelModifiable); + GUIdlatch4 cell01 = new GUIdlatch4 (submodelModifiable); + GUIdlatch4 cell10 = new GUIdlatch4 (submodelModifiable); + GUIdlatch4 cell11 = new GUIdlatch4 (submodelModifiable); GUIand41 andA00 = new GUIand41 (submodelModifiable); GUIandor414 andorA01 = new GUIandor414(submodelModifiable); GUIandor414 andorA10 = new GUIandor414(submodelModifiable); @@ -284,46 +283,14 @@ public class GUIram2 extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, andorB11.getPin("Y4"), QB4 , new Point(175, 770), new Point(175, 895), new Point(340, 895), new Point(340, 750)); //@formatter:on - addHighLevelStateSubcomponentID("c00", cell00); - addHighLevelStateSubcomponentID("c01", cell01); - addHighLevelStateSubcomponentID("c10", cell10); - addHighLevelStateSubcomponentID("c11", cell11); - addAtomicHighLevelStateID("q"); - } - - @Override - public void setAtomicHighLevelState(String stateID, Object newState) - { - switch (stateID) - { - case "q": - BitVector newStateCasted = (BitVector) newState; - setHighLevelState("c00.q", newStateCasted.subVector(0, 4)); - setHighLevelState("c01.q", newStateCasted.subVector(4, 8)); - setHighLevelState("c10.q", newStateCasted.subVector(8, 12)); - setHighLevelState("c11.q", newStateCasted.subVector(12, 16)); - 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 "q": - BitVector q00 = (BitVector) getHighLevelState("c00.q"); - BitVector q01 = (BitVector) getHighLevelState("c01.q"); - BitVector q10 = (BitVector) getHighLevelState("c10.q"); - BitVector q11 = (BitVector) getHighLevelState("c11.q"); - return q00.concat(q01).concat(q10).concat(q11); - default: - // should not happen because we tell SubmodelComponent to only allow these state IDs. - throw new IllegalStateException("Illegal atomic state ID: " + stateID); - } + StandardHighLevelStateHandler highLevelStateHandler = new StandardHighLevelStateHandler(this); + highLevelStateHandler.addSubcomponentHighLevelState("c00", DelegatingSubcomponentHighLevelStateHandler::new).set(cell00, null); + highLevelStateHandler.addSubcomponentHighLevelState("c01", DelegatingSubcomponentHighLevelStateHandler::new).set(cell01, null); + highLevelStateHandler.addSubcomponentHighLevelState("c10", DelegatingSubcomponentHighLevelStateHandler::new).set(cell10, null); + highLevelStateHandler.addSubcomponentHighLevelState("c11", DelegatingSubcomponentHighLevelStateHandler::new).set(cell11, null); + highLevelStateHandler.addAtomicHighLevelState("q", BitVectorSplittingAtomicHighLevelStateHandler::new) + .set(Arrays.asList("c11.q", "c10.q", "c01.q", "c00.q"), Arrays.asList(4, 4, 4, 4)); + setHighLevelStateHandler(highLevelStateHandler); } static