-mograsim version: 0.1.0
+mograsim version: 0.1.1
{
"type": "SimpleRectangularSubmodelComponent",
"width": 35.0,
"y": 40.0
},
"type": "class:net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder",
- "logicWidth": 1
+ "params": {}
},
{
"pos": {
"y": 7.5
},
"type": "class:net.mograsim.logic.ui.model.components.mi.nandbased.GUIhalfadder",
- "logicWidth": 1
+ "params": {}
},
{
"pos": {
"y": 40.0
},
"type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
- "logicWidth": 1
+ "params": {
+ "logicWidth": 1
+ }
}
],
"innerWires": [
-mograsim version: 0.1.0
+mograsim version: 0.1.1
{
"type": "SimpleRectangularSubmodelComponent",
"width": 35.0,
"y": 15.0
},
"type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
- "logicWidth": 1
+ "params": {
+ "logicWidth": 1
+ }
},
{
"pos": {
"y": 2.5
},
"type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
- "logicWidth": 1
+ "params": {
+ "logicWidth": 1
+ }
},
{
"pos": {
"y": 27.5
},
"type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
- "logicWidth": 1
+ "params": {
+ "logicWidth": 1
+ }
},
{
"pos": {
"y": 2.5
},
"type": "class:net.mograsim.logic.ui.model.components.GUINandGate",
- "logicWidth": 1
+ "params": {
+ "logicWidth": 1
+ }
},
{
"pos": {
"y": 11.5
},
"type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint",
- "logicWidth": 1
+ "params": {
+ "logicWidth": 1
+ }
},
{
"pos": {
"y": 36.5
},
"type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint",
- "logicWidth": 1
+ "params": {
+ "logicWidth": 1
+ }
},
{
"pos": {
"y": 24.0
},
"type": "class:net.mograsim.logic.ui.model.wires.WireCrossPoint",
- "logicWidth": 1
+ "params": {
+ "logicWidth": 1
+ }
}
],
"innerWires": [
-mograsim version: 0.1.0
+mograsim version: 0.1.1
{
"type": "SimpleRectangularSubmodelComponent",
"width": 35.0,
"y": 0.0
},
"type": "file:HalfAdder.json",
- "logicWidth": 1
+ "params": {}
}
],
"innerWires": []
bdZ = new GUIBitDisplay(model);
bdZ.moveTo(90, 85);
- new GUIWire(model, swA.getOutputPin(), adder.getPin("A"));
- new GUIWire(model, swB.getOutputPin(), adder.getPin("B"));
- new GUIWire(model, swC.getOutputPin(), adder.getPin("C"));
+ new GUIWire(model, swA.getOutputPin(), adder2.getPin("A"));
+ new GUIWire(model, swB.getOutputPin(), adder2.getPin("B"));
+ new GUIWire(model, swC.getOutputPin(), adder2.getPin("C"));
- new GUIWire(model, adder.getPin("Y"), bdY.getInputPin());
- new GUIWire(model, adder.getPin("Z"), bdZ.getInputPin());
+ new GUIWire(model, adder2.getPin("Y"), bdY.getInputPin());
+ new GUIWire(model, adder2.getPin("Z"), bdZ.getInputPin());
}
}
\ No newline at end of file
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
{
return identifierDelegate.get();
}
+
+ @SuppressWarnings("static-method")
+ public Map<String, Object> getInstantiationParameters()
+ {
+ return new TreeMap<>();
+ }
}
\ No newline at end of file
import net.mograsim.logic.ui.model.components.SubmodelComponentParams.InnerWireParams;
import net.mograsim.logic.ui.model.components.SubmodelComponentParams.InterfacePinParams;
import net.mograsim.logic.ui.model.wires.GUIWire;
+import net.mograsim.logic.ui.model.wires.WireCrossPoint;
/**
* Creates {@link SubmodelComponent}s from {@link SubmodelComponentParams}
if (path.startsWith("class:"))
{
path = path.substring(6);
- components[i] = createInnerComponentFromClass(comp, path, cParams.logicWidth);
+ components[i] = createInnerComponentFromClass(comp, path, cParams.params);
components[i].moveTo(cParams.pos.x, cParams.pos.y);
} else if (path.startsWith("file:"))
{
}
}
- private static GUIComponent createInnerComponentFromClass(SubmodelComponent parent, String classname, int logicWidth)
- throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
- NoSuchMethodException, SecurityException, ClassNotFoundException
+ private static GUIComponent createInnerComponentFromClass(SubmodelComponent parent, String classname, Map<String, Object> params)
+ throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException,
+ ClassNotFoundException
{
Class<?> c = Class.forName(classname);
Object comp;
- try
+ if (SimpleRectangularGUIGate.class.isAssignableFrom(c) || WireCrossPoint.class.equals(c))
+ {
+ Constructor<?> constructor = c.getConstructor(ViewModelModifiable.class, int.class);
+ comp = constructor.newInstance(parent.submodelModifiable,
+ ((Number) params.get(SimpleRectangularGUIGate.kLogicWidth)).intValue());
+ } else
{
Constructor<?> constructor = c.getConstructor(ViewModelModifiable.class);
comp = constructor.newInstance(parent.submodelModifiable);
}
- catch (@SuppressWarnings("unused") NoSuchMethodException e)
- {
- Constructor<?> constructor = c.getConstructor(ViewModelModifiable.class, int.class);
- comp = constructor.newInstance(parent.submodelModifiable, logicWidth);
- }
-
- if (comp instanceof GUIComponent)
- return (GUIComponent) comp;
- throw new IllegalArgumentException("Class given as subcomponent was not a GUIComponent!");
+ return (GUIComponent) comp;
}
}
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
private MovablePin outputPin;
private final List<Pin> inputPins;
+ public static final String kLogicWidth = "logicWidth";
+
protected SimpleRectangularGUIGate(ViewModelModifiable model, int logicWidth, String label, boolean isInverted)
{
super(model);
if (isInverted)
gc.drawOval(posX + rectWidth, posY + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam);
}
+
+ @Override
+ public Map<String, Object> getInstantiationParameters()
+ {
+ Map<String, Object> m = super.getInstantiationParameters();
+ m.put(kLogicWidth, logicWidth);
+ return m;
+ }
}
\ No newline at end of file
GUIComponent component = componentIt.next();
InnerComponentParams inner = new InnerComponentParams();
comps[i] = inner;
- inner.logicWidth = component.getPins().iterator().next().logicWidth; // TODO This could be done a little more elegantly
+ inner.params = component.getInstantiationParameters();
Rectangle bounds = component.getBounds();
inner.pos = new Point(bounds.x, bounds.y);
inner.type = component.getIdentifier();
public static class InterfacePinParams
{
- public Point location;
- public String name;
- public int logicWidth;
+ Point location;
+ String name;
+ int logicWidth;
}
public static class InnerWireParams
{
- public InnerPinParams pin1, pin2;
- public Point[] path;
+ InnerPinParams pin1, pin2;
+ Point[] path;
}
public static class InnerPinParams
{
- public int compId;
- public String pinName;
+ int compId;
+ String pinName;
}
public static class ComponentCompositionParams
public static class InnerComponentParams
{
- public Point pos;
- public String type;
- public int logicWidth;
+ Point pos;
+ String type;
+ Map<String, Object> params;
}
}
package net.mograsim.logic.ui.model.wires;
+import java.util.Map;
+
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
import net.mograsim.logic.core.LogicObservable;
import net.mograsim.logic.ui.ColorHelper;
import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.model.components.GUIComponent;
+import net.mograsim.logic.ui.model.components.SimpleRectangularGUIGate;
public class WireCrossPoint extends GUIComponent
{
{
return pin;
}
+
+ @Override
+ public Map<String, Object> getInstantiationParameters()
+ {
+ Map<String, Object> m = super.getInstantiationParameters();
+ m.put(SimpleRectangularGUIGate.kLogicWidth, logicWidth);
+ return m;
+ }
+
}
\ No newline at end of file
{
private static Gson parser = new GsonBuilder().setPrettyPrinting().create();
- @SuppressWarnings("resource")
public static <T> T readJson(String path, Class<T> type) throws IOException
{
- FileReader reader = new FileReader(path);
- BufferedReader bf = new BufferedReader(reader);
- bf.readLine(); // Skip version
- String json = bf.lines().dropWhile(s -> s.length() == 0 || s.charAt(0) != '{').reduce("", (x, y) -> x.concat(y));
- T params = parser.fromJson(json, type);
- reader.close();
- return params;
+ try (FileReader reader = new FileReader(path); BufferedReader bf = new BufferedReader(reader))
+ {
+ String json = bf.lines().dropWhile(s -> s.length() == 0 || s.charAt(0) != '{').reduce("", (x, y) -> x.concat(y));
+ T params = parser.fromJson(json, type);
+ return params;
+ }
}
public static void writeJson(Object o, String path) throws IOException
{
- @SuppressWarnings("resource")
- FileWriter writer = new FileWriter(path);
- writer.write(String.format("mograsim version: %s\n", Version.current.toString()));
- writer.write(parser.toJson(o));
- writer.close(); // TODO: Insure that writer is closed
+ try (FileWriter writer = new FileWriter(path))
+ {
+ writer.write(String.format("mograsim version: %s\n", Version.jsonCompVersion.toString()));
+ writer.write(parser.toJson(o));
+ }
}
}
public final class Version
{
- public final static Version current = new Version(0, 1, 0);
+ public final static Version jsonCompVersion = new Version(0, 1, 1);
public final int major, minor, patch;
public Version(int major, int minor, int patch)