import java.io.IOException;
+import com.google.gson.JsonNull;
+
import net.mograsim.logic.ui.SimpleLogicUIStandalone;
import net.mograsim.logic.ui.model.ViewModelModifiable;
-import net.mograsim.logic.ui.model.components.GUIBitDisplay;
-import net.mograsim.logic.ui.model.components.GUICustomComponentCreator;
-import net.mograsim.logic.ui.model.components.GUIManualSwitch;
-import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
-import net.mograsim.logic.ui.model.components.SubmodelComponent;
-import net.mograsim.logic.ui.model.components.SubmodelComponentParams;
+import net.mograsim.logic.ui.model.components.atomic.GUIBitDisplay;
+import net.mograsim.logic.ui.model.components.atomic.GUIManualSwitch;
+import net.mograsim.logic.ui.model.components.mi.nandbased.GUI_rsLatch;
import net.mograsim.logic.ui.model.components.mi.nandbased.GUIfulladder;
import net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder;
+import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent;
+import net.mograsim.logic.ui.model.components.submodels.SubmodelComponent;
import net.mograsim.logic.ui.model.wires.GUIWire;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
+import net.mograsim.logic.ui.serializing.SubmodelComponentDeserializer;
+import net.mograsim.logic.ui.serializing.SubmodelComponentParams;
+import net.mograsim.logic.ui.util.JsonHandler;
public class JsonExample
{
public static void main(String[] args)
{
- SimpleLogicUIStandalone.executeVisualisation(JsonExample::refJsonFromJsonTest);
+ SimpleLogicUIStandalone.executeVisualisation(JsonExample::basicTest);
+ }
+
+ public static void mappingTest(ViewModelModifiable model)
+ {
+ IndirectGUIComponentCreator.createComponent(model, "Am2901", JsonNull.INSTANCE);
}
private static class TestComponent extends SimpleRectangularSubmodelComponent
super(model, 1, "Test");
setSubmodelScale(.4);
setInputPins("Input pin #0");
- GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.json");
+ SubmodelComponentDeserializer.create(submodelModifiable, "HalfAdder.json");
+ }
+ }
+
+ @SuppressWarnings("unused") // GUIWires being created
+ private static void basicTest(ViewModelModifiable viewModel)
+ {
+ GUI_rsLatch comp = new GUI_rsLatch(viewModel);
+ comp.moveTo(30, 0);
+ SubmodelComponentParams params = comp.calculateParams();
+ String jsonString = JsonHandler.toJson(params);
+ System.out.println(jsonString);
+ SubmodelComponentParams paramsD = JsonHandler.fromJson(jsonString, SubmodelComponentParams.class);
+ SubmodelComponent componentD = SubmodelComponentDeserializer.create(viewModel, paramsD);
+ componentD.moveTo(30, 50);
+ double h = 0;
+ for (String s : comp.getInputPinNames())
+ {
+ GUIManualSwitch sw = new GUIManualSwitch(viewModel);
+ sw.moveTo(0, h);
+ new GUIWire(viewModel, sw.getOutputPin(), comp.getPin(s));
+ sw = new GUIManualSwitch(viewModel);
+ sw.moveTo(0, h + 50);
+ new GUIWire(viewModel, sw.getOutputPin(), componentD.getPin(s));
+ h += 20;
+ }
+ h = 0;
+ for (String s : comp.getOutputPinNames())
+ {
+ GUIBitDisplay bd = new GUIBitDisplay(viewModel);
+ bd.moveTo(80, h);
+ new GUIWire(viewModel, bd.getInputPin(), comp.getPin(s));
+ bd = new GUIBitDisplay(viewModel);
+ bd.moveTo(80, h + 50);
+ new GUIWire(viewModel, bd.getInputPin(), componentD.getPin(s));
+ h += 20;
}
}
{
TestComponent t = new TestComponent(model);
t.calculateParams().writeJson("Test.json");
- SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.json");
+ SubmodelComponent c = SubmodelComponentDeserializer.create(model, "Test.json");
c.moveTo(0, 50);
-
}
public static void createHalfAdderExample(ViewModelModifiable model)
e.printStackTrace();
}
- GUICustomComponentCreator.create(model, p, "");
+ SubmodelComponentDeserializer.create(model, p);
}
@SuppressWarnings("unused") // for GUIWires being created
e.printStackTrace();
}
- SimpleRectangularSubmodelComponent adder = (SimpleRectangularSubmodelComponent) GUICustomComponentCreator.create(model,
+ SimpleRectangularSubmodelComponent adder = (SimpleRectangularSubmodelComponent) SubmodelComponentDeserializer.create(model,
"FullAdder.json");
GUIManualSwitch swA = new GUIManualSwitch(model);
new GUIWire(model, adder.getPin("Y"), bdY.getInputPin());
new GUIWire(model, adder.getPin("Z"), bdZ.getInputPin());
- SubmodelComponent adder2 = GUICustomComponentCreator.create(model, pC, "");
+ SubmodelComponent adder2 = SubmodelComponentDeserializer.create(model, pC);
swA = new GUIManualSwitch(model);
swA.moveTo(0, 70);