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.DelegatingAtomicHighLevelStateHandler;
public class GUIdff extends SimpleRectangularSubmodelComponent
{
- private GUI_rsLatch _rsLatch;
+ private StandardHighLevelStateHandler highLevelStateHandler;
public GUIdff(ViewModelModifiable model)
{
GUI_rsLatch _rsLatch1 = new GUI_rsLatch(submodelModifiable);
GUInand3 nand3 = new GUInand3(submodelModifiable);
GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
- GUI_rsLatch _rsLatch2 = this._rsLatch = new GUI_rsLatch(submodelModifiable);
+ GUI_rsLatch _rsLatch2 = new GUI_rsLatch(submodelModifiable);
WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
new GUIWire(submodelModifiable, _rsLatch2.getPin("Q"), Q);
new GUIWire(submodelModifiable, _rsLatch2.getPin("_Q"), _Q);
- addAtomicHighLevelStateID("q");
+ this.highLevelStateHandler = new StandardHighLevelStateHandler(this);
+ highLevelStateHandler.addAtomicHighLevelState("q", DelegatingAtomicHighLevelStateHandler::new).set(_rsLatch2, "q");
}
@Override
- public void setAtomicHighLevelState(String stateID, Object newState)
+ public Object getHighLevelState(String stateID)
{
- switch (stateID)
- {
- case "q":
- _rsLatch.setHighLevelState("q", newState);
- break;
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ return highLevelStateHandler.getHighLevelState(stateID);
}
@Override
- public Object getAtomicHighLevelState(String stateID)
+ public void setHighLevelState(String stateID, Object newState)
{
- switch (stateID)
- {
- case "q":
- return _rsLatch.getHighLevelState("q");
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ highLevelStateHandler.setHighLevelState(stateID, newState);
}
static
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.DelegatingAtomicHighLevelStateHandler;
public class GUIdlatch extends SimpleRectangularSubmodelComponent
{
- private GUI_rsLatch _rsLatch;
+ private StandardHighLevelStateHandler highLevelStateHandler;
public GUIdlatch(ViewModelModifiable model)
{
GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
- _rsLatch = new GUI_rsLatch(submodelModifiable);
+ GUI_rsLatch _rsLatch = new GUI_rsLatch(submodelModifiable);
WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
new GUIWire(submodelModifiable, _rsLatch.getPin("Q"), Q, new Point[0]);
new GUIWire(submodelModifiable, _rsLatch.getPin("_Q"), _Q);
- addAtomicHighLevelStateID("q");
+ this.highLevelStateHandler = new StandardHighLevelStateHandler(this);
+ highLevelStateHandler.addAtomicHighLevelState("q", DelegatingAtomicHighLevelStateHandler::new).set(_rsLatch, "q");
}
@Override
- public void setAtomicHighLevelState(String stateID, Object newState)
+ public Object getHighLevelState(String stateID)
{
- switch (stateID)
- {
- case "q":
- _rsLatch.setHighLevelState("q", newState);
- break;
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ return highLevelStateHandler.getHighLevelState(stateID);
}
@Override
- public Object getAtomicHighLevelState(String stateID)
+ public void setHighLevelState(String stateID, Object newState)
{
- switch (stateID)
- {
- case "q":
- return _rsLatch.getHighLevelState("q");
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ highLevelStateHandler.setHighLevelState(stateID, newState);
}
static
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.Bit;
-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.atomic.DelegatingAtomicHighLevelStateHandler;
public class GUIdlatch4 extends SimpleRectangularSubmodelComponent
{
- private GUIdlatch dlatch1;
- private GUIdlatch dlatch2;
- private GUIdlatch dlatch3;
- private GUIdlatch dlatch4;
+ private StandardHighLevelStateHandler highLevelStateHandler;
public GUIdlatch4(ViewModelModifiable model)
{
Pin Q3 = getSubmodelPin("Q3");
Pin Q4 = getSubmodelPin("Q4");
- dlatch1 = new GUIdlatch(submodelModifiable);
- dlatch2 = new GUIdlatch(submodelModifiable);
- dlatch3 = new GUIdlatch(submodelModifiable);
- dlatch4 = new GUIdlatch(submodelModifiable);
+ GUIdlatch dlatch1 = new GUIdlatch(submodelModifiable);
+ GUIdlatch dlatch2 = new GUIdlatch(submodelModifiable);
+ GUIdlatch dlatch3 = new GUIdlatch(submodelModifiable);
+ GUIdlatch dlatch4 = new GUIdlatch(submodelModifiable);
WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
WireCrossPoint cp3 = new WireCrossPoint(submodelModifiable, 1);
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");
+ this.highLevelStateHandler = new StandardHighLevelStateHandler(this);
+ highLevelStateHandler.addAtomicHighLevelState("q1", DelegatingAtomicHighLevelStateHandler::new).set(dlatch1, "q");
+ highLevelStateHandler.addAtomicHighLevelState("q2", DelegatingAtomicHighLevelStateHandler::new).set(dlatch2, "q");
+ highLevelStateHandler.addAtomicHighLevelState("q3", DelegatingAtomicHighLevelStateHandler::new).set(dlatch3, "q");
+ highLevelStateHandler.addAtomicHighLevelState("q4", DelegatingAtomicHighLevelStateHandler::new).set(dlatch4, "q");
+ highLevelStateHandler.addAtomicHighLevelState("q", BitVectorSplittingAtomicHighLevelStateHandler::new)
+ .set(Arrays.asList("q1", "q2", "q3", "q4"), Arrays.asList(1, 1, 1, 1));
}
@Override
- public void setAtomicHighLevelState(String stateID, Object newState)
+ public Object getHighLevelState(String stateID)
{
- 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.getLSBit(0));
- setHighLevelState("q2", newStateCasted.getLSBit(1));
- setHighLevelState("q3", newStateCasted.getLSBit(2));
- setHighLevelState("q4", newStateCasted.getLSBit(3));
- break;
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ return highLevelStateHandler.getHighLevelState(stateID);
}
@Override
- public Object getAtomicHighLevelState(String stateID)
+ public void setHighLevelState(String stateID, Object newState)
{
- 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(q4, q3, q2, q1);
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ highLevelStateHandler.setHighLevelState(stateID, newState);
}
static
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;
+ private StandardHighLevelStateHandler highLevelStateHandler;
public GUIram2(ViewModelModifiable model)
{
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);
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");
+ this.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("c00.q", "c01.q", "c10.q", "c11.q"), Arrays.asList(4, 4, 4, 4));
}
@Override
- public void setAtomicHighLevelState(String stateID, Object newState)
+ public Object getHighLevelState(String stateID)
{
- 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);
- }
+ return highLevelStateHandler.getHighLevelState(stateID);
}
@Override
- public Object getAtomicHighLevelState(String stateID)
+ public void setHighLevelState(String stateID, Object newState)
{
- 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);
- }
+ highLevelStateHandler.setHighLevelState(stateID, newState);
}
static
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 GUIram4 extends SimpleRectangularSubmodelComponent
{
+ private StandardHighLevelStateHandler highLevelStateHandler;
+
public GUIram4(ViewModelModifiable model)
{
this(model, null);
new GUIWire(submodelModifiable, andorA11.getPin("Y4"), QA4 , new Point(195, 770), new Point(195, 895), new Point(325, 895), new Point(325, 350));
//@formatter:on
- addHighLevelStateSubcomponentID("c00", cell00);
- addHighLevelStateSubcomponentID("c01", cell01);
- addHighLevelStateSubcomponentID("c10", cell10);
- addHighLevelStateSubcomponentID("c11", cell11);
- addAtomicHighLevelStateID("q");
- }
+ this.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);
- @Override
- public void setAtomicHighLevelState(String stateID, Object newState)
- {
- switch (stateID)
- {
- case "q":
- BitVector newStateCasted = (BitVector) newState;
- setHighLevelState("c00.q", newStateCasted.subVector(0, 16));
- setHighLevelState("c01.q", newStateCasted.subVector(16, 32));
- setHighLevelState("c10.q", newStateCasted.subVector(32, 48));
- setHighLevelState("c11.q", newStateCasted.subVector(48, 64));
- break;
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
- }
-
- @Override
- protected void setSubcomponentHighLevelState(String subcomponentID, String subcomponentHighLevelStateID, Object newState)
- {
- if (checkSubcomponentID(subcomponentID))
- setHighLevelState(translateDirectCellAccess(subcomponentID, subcomponentHighLevelStateID), newState);
- else
- super.setSubcomponentHighLevelState(subcomponentID, subcomponentHighLevelStateID, newState);
+ highLevelStateHandler.addSubcomponentHighLevelState("c0000", DelegatingSubcomponentHighLevelStateHandler::new).set(cell00, "c00");
+ highLevelStateHandler.addSubcomponentHighLevelState("c0001", DelegatingSubcomponentHighLevelStateHandler::new).set(cell01, "c00");
+ highLevelStateHandler.addSubcomponentHighLevelState("c0010", DelegatingSubcomponentHighLevelStateHandler::new).set(cell10, "c00");
+ highLevelStateHandler.addSubcomponentHighLevelState("c0011", DelegatingSubcomponentHighLevelStateHandler::new).set(cell11, "c00");
+ highLevelStateHandler.addSubcomponentHighLevelState("c0100", DelegatingSubcomponentHighLevelStateHandler::new).set(cell00, "c01");
+ highLevelStateHandler.addSubcomponentHighLevelState("c0101", DelegatingSubcomponentHighLevelStateHandler::new).set(cell01, "c01");
+ highLevelStateHandler.addSubcomponentHighLevelState("c0110", DelegatingSubcomponentHighLevelStateHandler::new).set(cell10, "c01");
+ highLevelStateHandler.addSubcomponentHighLevelState("c0111", DelegatingSubcomponentHighLevelStateHandler::new).set(cell11, "c01");
+ highLevelStateHandler.addSubcomponentHighLevelState("c1000", DelegatingSubcomponentHighLevelStateHandler::new).set(cell00, "c10");
+ highLevelStateHandler.addSubcomponentHighLevelState("c1001", DelegatingSubcomponentHighLevelStateHandler::new).set(cell01, "c10");
+ highLevelStateHandler.addSubcomponentHighLevelState("c1010", DelegatingSubcomponentHighLevelStateHandler::new).set(cell10, "c10");
+ highLevelStateHandler.addSubcomponentHighLevelState("c1011", DelegatingSubcomponentHighLevelStateHandler::new).set(cell11, "c10");
+ highLevelStateHandler.addSubcomponentHighLevelState("c1100", DelegatingSubcomponentHighLevelStateHandler::new).set(cell00, "c11");
+ highLevelStateHandler.addSubcomponentHighLevelState("c1101", DelegatingSubcomponentHighLevelStateHandler::new).set(cell01, "c11");
+ highLevelStateHandler.addSubcomponentHighLevelState("c1110", DelegatingSubcomponentHighLevelStateHandler::new).set(cell10, "c11");
+ highLevelStateHandler.addSubcomponentHighLevelState("c1111", DelegatingSubcomponentHighLevelStateHandler::new).set(cell11, "c11");
+ highLevelStateHandler.addAtomicHighLevelState("q", BitVectorSplittingAtomicHighLevelStateHandler::new)
+ .set(Arrays.asList("c00.q", "c01.q", "c10.q", "c11.q"), Arrays.asList(16, 16, 16, 16));
}
@Override
- public Object getAtomicHighLevelState(String stateID)
+ public Object getHighLevelState(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);
- }
+ return highLevelStateHandler.getHighLevelState(stateID);
}
@Override
- protected Object getSubcomponentHighLevelState(String subcomponentID, String subcomponentHighLevelStateID)
- {
- if (checkSubcomponentID(subcomponentID))
- return getHighLevelState(translateDirectCellAccess(subcomponentID, subcomponentHighLevelStateID));
- return super.getSubcomponentHighLevelState(subcomponentID, subcomponentHighLevelStateID);
- }
-
- private static String translateDirectCellAccess(String subcomponentID, String subcomponentHighLevelStateID)
- {
- return 'c' + subcomponentID.substring(3, 5) + "." + subcomponentID.substring(0, 3) + '.' + subcomponentHighLevelStateID;
- }
-
- private static boolean checkSubcomponentID(String subcomponentID)
+ public void setHighLevelState(String stateID, Object newState)
{
- if (subcomponentID.length() != 5 || subcomponentID.charAt(0) != 'c')
- return false;
- char addr3 = subcomponentID.charAt(1);
- char addr2 = subcomponentID.charAt(2);
- char addr1 = subcomponentID.charAt(3);
- char addr0 = subcomponentID.charAt(4);
- return (addr3 == '0' || addr3 == '1') || (addr2 == '0' || addr2 == '1') || (addr1 == '0' || addr1 == '1')
- || (addr0 == '0' || addr0 == '1');
+ highLevelStateHandler.setHighLevelState(stateID, newState);
}
static
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.subcomponent.DelegatingSubcomponentHighLevelStateHandler;
public class GUIAm2901 extends SimpleRectangularSubmodelComponent
{
+ private StandardHighLevelStateHandler highLevelStateHandler;
+
public GUIAm2901(ViewModelModifiable model)
{
this(model, null);
new GUIWire(submodelModifiable, cpFneq0, notFneq0.getPin("B"), new Point(315, 455));
new GUIWire(submodelModifiable, notFneq0.getPin("Y"), Feq0, new Point[0]);
- addHighLevelStateSubcomponentID("regs", ram);
- addHighLevelStateSubcomponentID("qreg", qreg);
+ this.highLevelStateHandler = new StandardHighLevelStateHandler(this);
+ highLevelStateHandler.addSubcomponentHighLevelState("regs", DelegatingSubcomponentHighLevelStateHandler::new).set(ram, null);
+ highLevelStateHandler.addSubcomponentHighLevelState("qreg", DelegatingSubcomponentHighLevelStateHandler::new).set(qreg, null);
+ }
+
+ @Override
+ public Object getHighLevelState(String stateID)
+ {
+ return highLevelStateHandler.getHighLevelState(stateID);
+ }
+
+ @Override
+ public void setHighLevelState(String stateID, Object newState)
+ {
+ highLevelStateHandler.setHighLevelState(stateID, newState);
}
static
package net.mograsim.logic.model.model.components.mi.nandbased.am2901;
+import java.util.Arrays;
+
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.model.model.ViewModelModifiable;
import net.mograsim.logic.model.model.components.mi.nandbased.GUIand;
import net.mograsim.logic.model.model.components.mi.nandbased.GUIdff;
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.atomic.DelegatingAtomicHighLevelStateHandler;
public class GUIAm2901QReg extends SimpleRectangularSubmodelComponent
{
- private GUIdff dff1;
- private GUIdff dff2;
- private GUIdff dff3;
- private GUIdff dff4;
+ private StandardHighLevelStateHandler highLevelStateHandler;
public GUIAm2901QReg(ViewModelModifiable model)
{
Pin Q4 = getSubmodelPin("Q4");
GUIand and = new GUIand(submodelModifiable);
- dff1 = new GUIdff(submodelModifiable);
- dff2 = new GUIdff(submodelModifiable);
- dff3 = new GUIdff(submodelModifiable);
- dff4 = new GUIdff(submodelModifiable);
+ GUIdff dff1 = new GUIdff(submodelModifiable);
+ GUIdff dff2 = new GUIdff(submodelModifiable);
+ GUIdff dff3 = new GUIdff(submodelModifiable);
+ GUIdff dff4 = new GUIdff(submodelModifiable);
WireCrossPoint cpC1 = new WireCrossPoint(submodelModifiable, 1);
WireCrossPoint cpC2 = new WireCrossPoint(submodelModifiable, 1);
new GUIWire(submodelModifiable, dff3.getPin("Q"), Q3, new Point[0]);
new GUIWire(submodelModifiable, dff4.getPin("Q"), Q4, new Point[0]);
- addAtomicHighLevelStateID("q1");
- addAtomicHighLevelStateID("q2");
- addAtomicHighLevelStateID("q3");
- addAtomicHighLevelStateID("q4");
- addAtomicHighLevelStateID("q");
+ this.highLevelStateHandler = new StandardHighLevelStateHandler(this);
+ highLevelStateHandler.addAtomicHighLevelState("q1", DelegatingAtomicHighLevelStateHandler::new).set(dff1, "q");
+ highLevelStateHandler.addAtomicHighLevelState("q2", DelegatingAtomicHighLevelStateHandler::new).set(dff2, "q");
+ highLevelStateHandler.addAtomicHighLevelState("q3", DelegatingAtomicHighLevelStateHandler::new).set(dff3, "q");
+ highLevelStateHandler.addAtomicHighLevelState("q4", DelegatingAtomicHighLevelStateHandler::new).set(dff4, "q");
+ highLevelStateHandler.addAtomicHighLevelState("q", BitVectorSplittingAtomicHighLevelStateHandler::new)
+ .set(Arrays.asList("q1", "q2", "q3", "q4"), Arrays.asList(1, 1, 1, 1));
}
@Override
- public void setAtomicHighLevelState(String stateID, Object newState)
+ public Object getHighLevelState(String stateID)
{
- switch (stateID)
- {
- case "q1":
- dff1.setHighLevelState("q", newState);
- break;
- case "q2":
- dff2.setHighLevelState("q", newState);
- break;
- case "q3":
- dff3.setHighLevelState("q", newState);
- break;
- case "q4":
- dff4.setHighLevelState("q", newState);
- break;
- case "q":
- BitVector newStateCasted = (BitVector) newState;
- setHighLevelState("q1", newStateCasted.getLSBit(0));
- setHighLevelState("q2", newStateCasted.getLSBit(1));
- setHighLevelState("q3", newStateCasted.getLSBit(2));
- setHighLevelState("q4", newStateCasted.getLSBit(3));
- break;
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ return highLevelStateHandler.getHighLevelState(stateID);
}
@Override
- public Object getAtomicHighLevelState(String stateID)
+ public void setHighLevelState(String stateID, Object newState)
{
- switch (stateID)
- {
- case "q1":
- return dff1.getHighLevelState("q");
- case "q2":
- return dff2.getHighLevelState("q");
- case "q3":
- return dff3.getHighLevelState("q");
- case "q4":
- return dff4.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(q4, q3, q2, q1);
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ highLevelStateHandler.setHighLevelState(stateID, newState);
}
static