From: Daniel Kirschten Date: Tue, 18 Jun 2019 07:17:57 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/development' into development X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=82cc1d386820c179be331790fa3c1fae22bada76;hp=47f890be22d1b184e059c92ef9f94caff18f3306;p=Mograsim.git Merge remote-tracking branch 'origin/development' into development --- diff --git a/net.mograsim.logic.ui/FullAdder.json b/net.mograsim.logic.ui/FullAdder.json new file mode 100644 index 00000000..4740f057 --- /dev/null +++ b/net.mograsim.logic.ui/FullAdder.json @@ -0,0 +1,180 @@ +{ + "type": "SimpleRectangularSubmodelComponent", + "width": 35.0, + "height": 30.0, + "interfacePins": [ + { + "location": { + "x": 0.0, + "y": 5.0 + }, + "logicWidth": 1 + }, + { + "location": { + "x": 0.0, + "y": 15.0 + }, + "logicWidth": 1 + }, + { + "location": { + "x": 0.0, + "y": 25.0 + }, + "logicWidth": 1 + }, + { + "location": { + "x": 35.0, + "y": 5.0 + }, + "logicWidth": 1 + }, + { + "location": { + "x": 35.0, + "y": 15.0 + }, + "logicWidth": 1 + } + ], + "composition": { + "innerScale": 0.4, + "subComps": [ + { + "pos": { + "x": 5.0, + "y": 40.0 + }, + "type": "class:net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder", + "logicWidth": 1 + }, + { + "pos": { + "x": 45.0, + "y": 7.5 + }, + "type": "class:net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder", + "logicWidth": 1 + }, + { + "pos": { + "x": 57.5, + "y": 40.0 + }, + "type": "class:net.mograsim.logic.ui.model.components.GUINandGate", + "logicWidth": 1 + } + ], + "innerWires": [ + { + "pin1": { + "compId": 0, + "pinIndex": 0 + }, + "pin2": { + "compId": 2, + "pinIndex": 0 + }, + "path": [] + }, + { + "pin1": { + "compId": 0, + "pinIndex": 1 + }, + "pin2": { + "compId": 1, + "pinIndex": 0 + } + }, + { + "pin1": { + "compId": 0, + "pinIndex": 2 + }, + "pin2": { + "compId": 1, + "pinIndex": 1 + } + }, + { + "pin1": { + "compId": 1, + "pinIndex": 2 + }, + "pin2": { + "compId": 2, + "pinIndex": 1 + } + }, + { + "pin1": { + "compId": 1, + "pinIndex": 3 + }, + "pin2": { + "compId": 3, + "pinIndex": 2 + }, + "path": [] + }, + { + "pin1": { + "compId": 2, + "pinIndex": 2 + }, + "pin2": { + "compId": 0, + "pinIndex": 3 + }, + "path": [] + }, + { + "pin1": { + "compId": 2, + "pinIndex": 3 + }, + "pin2": { + "compId": 3, + "pinIndex": 1 + }, + "path": [ + { + "x": 82.5, + "y": 22.5 + }, + { + "x": 82.5, + "y": 35.0 + }, + { + "x": 52.5, + "y": 35.0 + }, + { + "x": 52.5, + "y": 45.0 + } + ] + }, + { + "pin1": { + "compId": 3, + "pinIndex": 0 + }, + "pin2": { + "compId": 0, + "pinIndex": 4 + } + } + ] + }, + "specialized": { + "input_count": 3, + "label": "GUIfulladder", + "logic_width": 1, + "output_count": 2 + } +} \ No newline at end of file diff --git a/net.mograsim.logic.ui/HalfAdder.json b/net.mograsim.logic.ui/HalfAdder.json new file mode 100644 index 00000000..99fd0f4b --- /dev/null +++ b/net.mograsim.logic.ui/HalfAdder.json @@ -0,0 +1,304 @@ +{ + "type": "SimpleRectangularSubmodelComponent", + "width": 35.0, + "height": 20.0, + "interfacePins": [ + { + "location": { + "x": 0.0, + "y": 5.0 + }, + "logicWidth": 1 + }, + { + "location": { + "x": 0.0, + "y": 15.0 + }, + "logicWidth": 1 + }, + { + "location": { + "x": 35.0, + "y": 5.0 + }, + "logicWidth": 1 + }, + { + "location": { + "x": 35.0, + "y": 15.0 + }, + "logicWidth": 1 + } + ], + "composition": { + "innerScale": 0.4, + "subComps": [ + { + "pos": { + "x": 10.0, + "y": 15.0 + }, + "type": "class:net.mograsim.logic.ui.model.components.GUINandGate", + "logicWidth": 1 + }, + { + "pos": { + "x": 40.0, + "y": 2.5 + }, + "type": "class:net.mograsim.logic.ui.model.components.GUINandGate", + "logicWidth": 1 + }, + { + "pos": { + "x": 40.0, + "y": 27.5 + }, + "type": "class:net.mograsim.logic.ui.model.components.GUINandGate", + "logicWidth": 1 + }, + { + "pos": { + "x": 65.0, + "y": 2.5 + }, + "type": "class:net.mograsim.logic.ui.model.components.GUINandGate", + "logicWidth": 1 + }, + { + "pos": { + "x": 4.0, + "y": 11.5 + }, + "type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint", + "logicWidth": 1 + }, + { + "pos": { + "x": 4.0, + "y": 36.5 + }, + "type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint", + "logicWidth": 1 + }, + { + "pos": { + "x": 34.0, + "y": 24.0 + }, + "type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint", + "logicWidth": 1 + } + ], + "innerWires": [ + { + "pin1": { + "compId": 0, + "pinIndex": 0 + }, + "pin2": { + "compId": 5, + "pinIndex": 0 + }, + "path": [] + }, + { + "pin1": { + "compId": 5, + "pinIndex": 0 + }, + "pin2": { + "compId": 2, + "pinIndex": 1 + }, + "path": [ + { + "x": 5.0, + "y": 7.5 + } + ] + }, + { + "pin1": { + "compId": 5, + "pinIndex": 0 + }, + "pin2": { + "compId": 1, + "pinIndex": 1 + }, + "path": [ + { + "x": 5.0, + "y": 20.0 + } + ] + }, + { + "pin1": { + "compId": 0, + "pinIndex": 1 + }, + "pin2": { + "compId": 6, + "pinIndex": 0 + }, + "path": [] + }, + { + "pin1": { + "compId": 6, + "pinIndex": 0 + }, + "pin2": { + "compId": 3, + "pinIndex": 2 + }, + "path": [ + { + "x": 5.0, + "y": 42.5 + } + ] + }, + { + "pin1": { + "compId": 6, + "pinIndex": 0 + }, + "pin2": { + "compId": 1, + "pinIndex": 2 + }, + "path": [ + { + "x": 5.0, + "y": 30.0 + } + ] + }, + { + "pin1": { + "compId": 1, + "pinIndex": 0 + }, + "pin2": { + "compId": 7, + "pinIndex": 0 + }, + "path": [] + }, + { + "pin1": { + "compId": 7, + "pinIndex": 0 + }, + "pin2": { + "compId": 0, + "pinIndex": 3 + }, + "path": [ + { + "x": 80.0, + "y": 25.0 + }, + { + "x": 80.0, + "y": 37.5 + } + ] + }, + { + "pin1": { + "compId": 7, + "pinIndex": 0 + }, + "pin2": { + "compId": 2, + "pinIndex": 2 + }, + "path": [ + { + "x": 35.0, + "y": 17.5 + } + ] + }, + { + "pin1": { + "compId": 7, + "pinIndex": 0 + }, + "pin2": { + "compId": 3, + "pinIndex": 1 + }, + "path": [ + { + "x": 35.0, + "y": 32.5 + } + ] + }, + { + "pin1": { + "compId": 2, + "pinIndex": 0 + }, + "pin2": { + "compId": 4, + "pinIndex": 1 + }, + "path": [ + { + "x": 62.5, + "y": 12.5 + }, + { + "x": 62.5, + "y": 7.5 + } + ] + }, + { + "pin1": { + "compId": 3, + "pinIndex": 0 + }, + "pin2": { + "compId": 4, + "pinIndex": 2 + }, + "path": [ + { + "x": 62.5, + "y": 37.5 + }, + { + "x": 62.5, + "y": 17.5 + } + ] + }, + { + "pin1": { + "compId": 4, + "pinIndex": 0 + }, + "pin2": { + "compId": 0, + "pinIndex": 2 + }, + "path": [] + } + ] + }, + "specialized": { + "input_count": 2, + "label": "GUIhalfadder", + "logic_width": 1, + "output_count": 2 + } +} \ No newline at end of file diff --git a/net.mograsim.logic.ui/Test.json b/net.mograsim.logic.ui/Test.json new file mode 100644 index 00000000..4e376db1 --- /dev/null +++ b/net.mograsim.logic.ui/Test.json @@ -0,0 +1,34 @@ +{ + "type": "SimpleRectangularSubmodelComponent", + "width": 35.0, + "height": 10.0, + "interfacePins": [ + { + "location": { + "x": 0.0, + "y": 5.0 + }, + "logicWidth": 1 + } + ], + "composition": { + "innerScale": 0.4, + "subComps": [ + { + "pos": { + "x": 0.0, + "y": 0.0 + }, + "type": "file:HalfAdder.json", + "logicWidth": 1 + } + ], + "innerWires": [] + }, + "specialized": { + "input_count": 1, + "label": "Test", + "logic_width": 1, + "output_count": 0 + } +} \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/JsonExample.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/JsonExample.java index ac39fa34..82b2c8c4 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/JsonExample.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/JsonExample.java @@ -11,14 +11,14 @@ import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent import net.mograsim.logic.ui.model.components.SubmodelComponent; 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.params.SubComponentParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams; import net.mograsim.logic.ui.model.wires.GUIWire; public class JsonExample { public static void main(String[] args) { - SimpleLogicUIStandalone.executeVisualisation(JsonExample::createHalfAdderExample); + SimpleLogicUIStandalone.executeVisualisation(JsonExample::refJsonFromJsonTest); } private static class TestComponent extends SimpleRectangularSubmodelComponent @@ -28,16 +28,16 @@ public class JsonExample super(model, 1, "Test"); setInputCount(1); setSubmodelScale(.4); - GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.rc"); + GUICustomComponentCreator.create(submodelModifiable, "HalfAdder.json"); } } - // Execute only after HalfAdder.rc has been created + // Execute only after HalfAdder.json has been created public static void refJsonFromJsonTest(ViewModelModifiable model) { TestComponent t = new TestComponent(model); - t.calculateParams().writeJson("Test.sc"); - SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.sc"); + t.calculateParams().writeJson("Test.json"); + SubmodelComponent c = GUICustomComponentCreator.create(model, "Test.json"); c.moveTo(0, 50); } @@ -46,47 +46,30 @@ public class JsonExample { GUIhalfadder tmp = new GUIhalfadder(model); tmp.moveTo(1000, 50); - SubComponentParams p = tmp.calculateParams(); - SubComponentParams pC = tmp.calculateParams(); + SubmodelComponentParams p = tmp.calculateParams(); try { - p.writeJson("HalfAdder.rc"); - pC.writeJson("HalfAdder.sc"); - p = SubComponentParams.readJson("HalfAdder.rc"); - pC = SubComponentParams.readJson("HalfAdder.sc"); + p.writeJson("HalfAdder.json"); + p = SubmodelComponentParams.readJson("HalfAdder.json"); } catch (IOException e) { e.printStackTrace(); } - SubmodelComponent adder = GUICustomComponentCreator.create(model, p, ""); - adder = GUICustomComponentCreator.create(model, pC, ""); - adder.moveTo(0, 200); + GUICustomComponentCreator.create(model, p, ""); } @SuppressWarnings("unused") // for GUIWires being created public static void createFromJsonExample(ViewModelModifiable model) { - SimpleRectangularSubmodelComponent tmp = new GUIhalfadder(model); - tmp.moveTo(1000, 50); - SubComponentParams p = tmp.calculateParams(); - try - { - p.writeJson("HalfAdder.rc"); - p = SubComponentParams.readJson("HalfAdder.rc"); - } - catch (IOException e) - { - e.printStackTrace(); - } - tmp = new GUIfulladder(model); - SubComponentParams pC = tmp.calculateParams(); + SimpleRectangularSubmodelComponent tmp = new GUIfulladder(model); + SubmodelComponentParams pC = tmp.calculateParams(); tmp.moveTo(1000, 100); try { - pC.writeJson("FullAdder.sc"); - pC = SubComponentParams.readJson("FullAdder.sc"); + pC.writeJson("FullAdder.json"); + pC = SubmodelComponentParams.readJson("FullAdder.json"); } catch (IOException e) { diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java index 5f74dadd..89c532e4 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java @@ -4,10 +4,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Consumer; +import java.util.function.Supplier; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.ui.model.ViewModelModifiable; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams; import net.mograsim.logic.ui.model.wires.Pin; public abstract class GUIComponent @@ -23,6 +25,8 @@ public abstract class GUIComponent private final List redrawListeners; private final Runnable redrawListenerForSubcomponents; + // Defines how the GUIComponent is referenced in SubmodelComponentParams + protected Supplier identifierDelegate = () -> "class:".concat(getClass().getCanonicalName()); public GUIComponent(ViewModelModifiable model) { @@ -130,8 +134,11 @@ public abstract class GUIComponent callRedrawListeners(); } + /** + * @return an identifier used to reference this GUIComponent inside of {@link SubmodelComponentParams} + */ public String getIdentifier() { - return "class:".concat(getClass().getCanonicalName()); + return identifierDelegate.get(); } } \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java index c27b0154..c1503978 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java @@ -6,39 +6,32 @@ import java.lang.reflect.InvocationTargetException; import java.util.Map; import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.params.GeneralComponentParams; -import net.mograsim.logic.ui.model.components.params.GeneralComponentParams.InnerComponentParams; -import net.mograsim.logic.ui.model.components.params.SubComponentParams; -import net.mograsim.logic.ui.model.components.params.SubComponentParams.InnerWireParams; -import net.mograsim.logic.ui.model.components.params.SubComponentParams.InterfacePinParams; +import net.mograsim.logic.ui.model.components.params.ComponentCompositionParams; +import net.mograsim.logic.ui.model.components.params.ComponentCompositionParams.InnerComponentParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams.InnerWireParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams.InterfacePinParams; import net.mograsim.logic.ui.model.wires.GUIWire; -public class GUICustomComponentCreator +/** + * Creates {@link SubmodelComponent}s from {@link SubmodelComponentParams} + */ +public final class GUICustomComponentCreator { private static final String rectC = SimpleRectangularSubmodelComponent.class.getSimpleName(); - private static class CustomRectComponent extends SimpleRectangularSubmodelComponent - { - private String path; - - protected CustomRectComponent(ViewModelModifiable model, int logicWidth, String label, String path) - { - super(model, logicWidth, label); - this.path = path; - } - - @Override - public String getIdentifier() - { - return "file:".concat(path); - } - } - + /** + * Creates a {@link SubmodelComponent} from the {@link SubmodelComponentParams}, specified at the given path. The returned SubmodelComponent + * can also be e.g. a {@link SimpleRectangularSubmodelComponent}, depending on what the {@link SubmodelComponentParams} describe. + * + * @param path The path of the file describing the {@link SubmodelComponentParams}, which define the new {@link SubmodelComponent} + * @return A new SubmodelComponent, as described in the file located at the given path + */ public static SubmodelComponent create(ViewModelModifiable model, String path) { try { - SubComponentParams params = SubComponentParams.readJson(path); + SubmodelComponentParams params = SubmodelComponentParams.readJson(path); SubmodelComponent ret = create(model, params, path); return ret; } @@ -47,55 +40,73 @@ public class GUICustomComponentCreator System.err.println("Failed to construct GUICustomComponent. Parameters were not found."); e.printStackTrace(); } - return new CustomRectComponent(model, 0, "ERROR", "NONE"); + return new SimpleRectangularSubmodelComponent(model, 0, "ERROR"); } /** - * @param path This value is used when the new SubmodelComponent is an inner component to a different SubmodelComponent, which is being - * saved to a file; Then, the new SubmodelComponent is referenced by its given path within the file. + * Creates a {@link SubmodelComponent} from the specified {@link SubmodelComponentParams}. The returned SubmodelComponent can also be e.g. a + * {@link SimpleRectangularSubmodelComponent}, depending on what the {@link SubmodelComponentParams} describe. + * + * @param params The parameters describing the {@link SubmodelComponent} + * @param path This value is used when the new {@link SubmodelComponent} is an inner component to a different SubmodelComponent, which + * is being saved to a file; Then, the new {@link SubmodelComponent} is referenced by its given path within the file. + * @return A new SubmodelComponent, as described by the {@link SubmodelComponentParams} */ - public static SubmodelComponent create(ViewModelModifiable model, SubComponentParams params, String path) + public static SubmodelComponent create(ViewModelModifiable model, SubmodelComponentParams params, String path) { - // TODO: Clean up this mess SubmodelComponent comp = null; if (rectC.equals(params.type)) { - try - { - Map m = params.specialized; - SimpleRectangularSubmodelComponent rect = new CustomRectComponent(model, - ((Number) m.get(SimpleRectangularSubmodelComponent.kLogicWidth)).intValue(), - (String) m.get(SimpleRectangularSubmodelComponent.kLabel), path); - rect.setSubmodelScale(params.composition.innerScale); - rect.setSize(params.width, params.height); - rect.setInputCount(((Number) m.get(SimpleRectangularSubmodelComponent.kInCount)).intValue()); - rect.setOutputCount(((Number) m.get(SimpleRectangularSubmodelComponent.kOutCount)).intValue()); - comp = rect; - } - catch (ClassCastException | NullPointerException e) - { - System.err.println("Failed to specialize component!"); - e.printStackTrace(); - } + comp = createRectComponent(model, params); } + if (comp == null) { - // As SubmodelComponent is abstract, for now SubmodelComponents are instantiated as SimpleRectangularSubmodelComponents - comp = new CustomRectComponent(model, 0, "", path); + comp = createSubmodelComponent(model, params); + } + comp.identifierDelegate = () -> "file:".concat(path); + initInnerComponents(comp, params.composition); + return comp; + } - comp.setSubmodelScale(params.composition.innerScale); - comp.setSize(params.width, params.height); - for (InterfacePinParams iPinParams : params.interfacePins) - { - comp.addSubmodelInterface(iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y); - } + // May return null + private static SimpleRectangularSubmodelComponent createRectComponent(ViewModelModifiable model, SubmodelComponentParams params) + { + try + { + Map m = params.specialized; + SimpleRectangularSubmodelComponent rect = new SimpleRectangularSubmodelComponent(model, + ((Number) m.get(SimpleRectangularSubmodelComponent.kLogicWidth)).intValue(), + (String) m.get(SimpleRectangularSubmodelComponent.kLabel)); + rect.setSubmodelScale(params.composition.innerScale); + rect.setSize(params.width, params.height); + rect.setInputCount(((Number) m.get(SimpleRectangularSubmodelComponent.kInCount)).intValue()); + rect.setOutputCount(((Number) m.get(SimpleRectangularSubmodelComponent.kOutCount)).intValue()); + return rect; + } + catch (ClassCastException | NullPointerException e) + { + System.err.println("Failed to specialize component!"); + e.printStackTrace(); + return null; + } + } + + private static SubmodelComponent createSubmodelComponent(ViewModelModifiable model, SubmodelComponentParams params) + { + // As SubmodelComponent is abstract, for now SubmodelComponents are instantiated as SimpleRectangularSubmodelComponents + SubmodelComponent comp = new SimpleRectangularSubmodelComponent(model, 0, ""); + comp.setSubmodelScale(params.composition.innerScale); + comp.setSize(params.width, params.height); + for (InterfacePinParams iPinParams : params.interfacePins) + { + comp.addSubmodelInterface(iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y); } - initSubmodelComponents(comp, params.composition); return comp; } @SuppressWarnings("unused") - private static void initSubmodelComponents(SubmodelComponent comp, GeneralComponentParams params) + private static void initInnerComponents(SubmodelComponent comp, ComponentCompositionParams params) { try { @@ -127,9 +138,10 @@ public class GUICustomComponentCreator innerWire.path); } } - catch (Exception e) + catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException + | ClassNotFoundException | IllegalArgumentException e) { - System.err.println("Failed to create custom component!"); + System.err.println("Failed to initialize custom component!"); e.printStackTrace(); } } diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java index 0e6e3268..da8bd485 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java @@ -11,7 +11,7 @@ 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.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.params.SubComponentParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams; import net.mograsim.logic.ui.model.wires.Pin; public class SimpleRectangularSubmodelComponent extends SubmodelComponent @@ -129,9 +129,9 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent } @Override - public SubComponentParams calculateParams() + public SubmodelComponentParams calculateParams() { - SubComponentParams ret = super.calculateParams(); + SubmodelComponentParams ret = super.calculateParams(); ret.type = SimpleRectangularSubmodelComponent.class.getSimpleName(); Map m = new TreeMap<>(); m.put(kLabel, label); diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java index 106c5ffe..f82c3773 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java @@ -15,14 +15,14 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.ui.LogicUIRenderer; import net.mograsim.logic.ui.model.ViewModel; import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.params.GeneralComponentParams; -import net.mograsim.logic.ui.model.components.params.GeneralComponentParams.InnerComponentParams; -import net.mograsim.logic.ui.model.components.params.SubComponentParams; -import net.mograsim.logic.ui.model.components.params.SubComponentParams.InterfacePinParams; +import net.mograsim.logic.ui.model.components.params.ComponentCompositionParams; +import net.mograsim.logic.ui.model.components.params.ComponentCompositionParams.InnerComponentParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams.InterfacePinParams; import net.mograsim.logic.ui.model.wires.GUIWire; import net.mograsim.logic.ui.model.wires.Pin; -import net.mograsim.logic.ui.model.components.params.SubComponentParams.InnerPinParams; -import net.mograsim.logic.ui.model.components.params.SubComponentParams.InnerWireParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams.InnerPinParams; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams.InnerWireParams; public abstract class SubmodelComponent extends GUIComponent { @@ -210,9 +210,12 @@ public abstract class SubmodelComponent extends GUIComponent } } - public SubComponentParams calculateParams() + /** + * @return {@link SubmodelComponentParams}, which describe this {@link SubmodelComponent}. + */ + public SubmodelComponentParams calculateParams() { - SubComponentParams params = new SubComponentParams(); + SubmodelComponentParams params = new SubmodelComponentParams(); params.type = SubmodelComponent.class.getSimpleName(); params.composition = calculateCompositionParams(); @@ -235,9 +238,9 @@ public abstract class SubmodelComponent extends GUIComponent return params; } - protected GeneralComponentParams calculateCompositionParams() + protected ComponentCompositionParams calculateCompositionParams() { - GeneralComponentParams params = new GeneralComponentParams(); + ComponentCompositionParams params = new ComponentCompositionParams(); params.innerScale = getSubmodelScale(); List compList = submodelModifiable.getComponents(); diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/ComponentCompositionParams.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/ComponentCompositionParams.java new file mode 100644 index 00000000..67cbdfec --- /dev/null +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/ComponentCompositionParams.java @@ -0,0 +1,18 @@ +package net.mograsim.logic.ui.model.components.params; + +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.mograsim.logic.ui.model.components.params.SubmodelComponentParams.InnerWireParams; + +public class ComponentCompositionParams +{ + public double innerScale; + public InnerComponentParams[] subComps; + public InnerWireParams[] innerWires; + + public static class InnerComponentParams + { + public Point pos; + public String type; + public int logicWidth; + } +} diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/GeneralComponentParams.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/GeneralComponentParams.java deleted file mode 100644 index 5d5bc118..00000000 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/GeneralComponentParams.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.mograsim.logic.ui.model.components.params; - -import net.haspamelodica.swt.helper.swtobjectwrappers.Point; -import net.mograsim.logic.ui.model.components.params.SubComponentParams.InnerWireParams; - -public class GeneralComponentParams -{ - public double innerScale; - public InnerComponentParams[] subComps; - public InnerWireParams[] innerWires; - - public static class InnerComponentParams - { - public Point pos; - public String type; - public int logicWidth; - } -} diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/SubComponentParams.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/SubComponentParams.java deleted file mode 100644 index 8ea235f6..00000000 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/SubComponentParams.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.mograsim.logic.ui.model.components.params; - -import java.io.IOException; -import java.util.Map; - -import net.haspamelodica.swt.helper.swtobjectwrappers.Point; - -public class SubComponentParams -{ - public String type; - public final static String fileExtension = ".sc"; - public double width, height; - public InterfacePinParams[] interfacePins; - public GeneralComponentParams composition; - public Map specialized; - - public static class InterfacePinParams - { - public Point location; - public int logicWidth; - } - - public static class InnerWireParams - { - public InnerPinParams pin1, pin2; - public Point[] path; - } - - public static class InnerPinParams - { - public int compId, pinIndex; - } - - public static SubComponentParams readJson(String path) throws IOException - { - return JsonHandler.readJson(path, SubComponentParams.class); - } - - /** - * Writes this {@link SubComponentParams} object into a file in json format. The correct file extension is important! Check - * {@link SubComponentParams}.fileExtension - */ - public void writeJson(String path) - { - try - { - JsonHandler.writeJson(this, path); - } - catch (IOException e) - { - System.err.println("Failed to write SubComponentParams to file"); - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/SubmodelComponentParams.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/SubmodelComponentParams.java new file mode 100644 index 00000000..e0205c0f --- /dev/null +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/params/SubmodelComponentParams.java @@ -0,0 +1,58 @@ +package net.mograsim.logic.ui.model.components.params; + +import java.io.IOException; +import java.util.Map; + +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.mograsim.logic.ui.model.components.SubmodelComponent; + +/** + * This class contains all the information necessary to create a new {@link SubmodelComponent} + */ +public class SubmodelComponentParams +{ + public String type; + public double width, height; + public InterfacePinParams[] interfacePins; + public ComponentCompositionParams composition; + public Map specialized; + + public static class InterfacePinParams + { + public Point location; + public int logicWidth; + } + + public static class InnerWireParams + { + public InnerPinParams pin1, pin2; + public Point[] path; + } + + public static class InnerPinParams + { + public int compId, pinIndex; + } + + public static SubmodelComponentParams readJson(String path) throws IOException + { + return JsonHandler.readJson(path, SubmodelComponentParams.class); + } + + /** + * Writes this {@link SubmodelComponentParams} object into a file in json format. The correct file extension is important! Check + * {@link SubmodelComponentParams}.fileExtension + */ + public void writeJson(String path) + { + try + { + JsonHandler.writeJson(this, path); + } + catch (IOException e) + { + System.err.println("Failed to write SubComponentParams to file"); + e.printStackTrace(); + } + } +} \ No newline at end of file