Pins are now accessed via name, not index
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / GUICustomComponentCreator.java
index ea45b61..02b022a 100644 (file)
@@ -79,9 +79,21 @@ 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);
+
+                       // TODO save & restore names
+                       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 +112,7 @@ public final class GUICustomComponentCreator
                comp.setSize(params.width, params.height);
                for (InterfacePinParams iPinParams : params.interfacePins)
                {
-                       comp.addSubmodelInterface(iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y);
+                       comp.addSubmodelInterface(iPinParams.name, iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y);
                }
                return comp;
        }
@@ -133,9 +145,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