X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FGUICustomComponentCreator.java;h=0e23febabbc6e7f4fdcc5e736e42e75afef526e6;hb=a84700145147c263ad6692c99117a7cf37832378;hp=2f3e405e485dd79aa05daababc39a58e351b4d68;hpb=a93901091c018edc992828e3a23817e97a98e4ca;p=Mograsim.git 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 2f3e405e..0e23feba 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,11 +6,13 @@ import java.lang.reflect.InvocationTargetException; import java.util.Map; import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.SubmodelComponentParams.ComponentCompositionParams.InnerComponentParams; import net.mograsim.logic.ui.model.components.SubmodelComponentParams.ComponentCompositionParams; +import net.mograsim.logic.ui.model.components.SubmodelComponentParams.ComponentCompositionParams.InnerComponentParams; 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.MovablePin; +import net.mograsim.logic.ui.model.wires.WireCrossPoint; /** * Creates {@link SubmodelComponent}s from {@link SubmodelComponentParams} @@ -79,9 +81,20 @@ public final class GUICustomComponentCreator ((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()); + // rect.setSize(params.width, params.height); + + int inputCount = ((Number) m.get(SimpleRectangularSubmodelComponent.kInCount)).intValue(); + String[] inputNames = new String[inputCount]; + for (int i = 0; i < inputCount; i++) + inputNames[i] = params.interfacePins[i].name; + rect.setInputPins(inputNames); + + int outputCount = ((Number) m.get(SimpleRectangularSubmodelComponent.kOutCount)).intValue(); + String[] outputPins = new String[outputCount]; + for (int i = 0; i < outputCount; i++) + outputPins[i] = params.interfacePins[inputCount + i].name; + rect.setOutputPins(outputPins); + return rect; } catch (ClassCastException | NullPointerException e) @@ -100,7 +113,8 @@ public final class GUICustomComponentCreator comp.setSize(params.width, params.height); for (InterfacePinParams iPinParams : params.interfacePins) { - comp.addSubmodelInterface(iPinParams.name, iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y); + comp.addSubmodelInterface( + new MovablePin(comp, iPinParams.name, iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y)); } return comp; } @@ -118,7 +132,7 @@ public final class GUICustomComponentCreator 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:")) { @@ -133,9 +147,8 @@ public final class GUICustomComponentCreator { InnerWireParams innerWire = params.innerWires[i]; new GUIWire(comp.submodelModifiable, - comp.submodelModifiable.getComponents().get(innerWire.pin1.compId).getPins().get(innerWire.pin1.pinIndex), - comp.submodelModifiable.getComponents().get(innerWire.pin2.compId).getPins().get(innerWire.pin2.pinIndex), - innerWire.path); + comp.submodelModifiable.getComponents().get(innerWire.pin1.compId).getPin(innerWire.pin1.pinName), + comp.submodelModifiable.getComponents().get(innerWire.pin2.compId).getPin(innerWire.pin2.pinName), innerWire.path); } } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException @@ -146,25 +159,22 @@ public final class GUICustomComponentCreator } } - 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 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; } }