+
+ /**
+ * @return {@link SubmodelComponentParams}, which describe this {@link SubmodelComponent}.
+ */
+ public SubmodelComponentParams calculateParams()
+ {
+ SubmodelComponentParams params = new SubmodelComponentParams();
+ params.type = SubmodelComponent.class.getSimpleName();
+ params.composition = calculateCompositionParams();
+
+ Rectangle bounds = getBounds();
+ params.width = bounds.width;
+ params.height = bounds.height;
+
+ List<Pin> pinList = pinsUnmodifiable;
+ InterfacePinParams[] iPins = new InterfacePinParams[pinList.size()];
+ int i = 0;
+ for (Pin p : pinList)
+ {
+ InterfacePinParams iPinParams = new InterfacePinParams();
+ iPins[i] = iPinParams;
+ iPinParams.location = p.getRelPos();
+ iPinParams.logicWidth = p.logicWidth;
+ i++;
+ }
+ params.interfacePins = iPins;
+ return params;
+ }
+
+ protected ComponentCompositionParams calculateCompositionParams()
+ {
+ ComponentCompositionParams params = new ComponentCompositionParams();
+ params.innerScale = getSubmodelScale();
+
+ List<GUIComponent> compList = submodelModifiable.getComponents();
+ Iterator<GUIComponent> componentIt = compList.iterator();
+ componentIt.next(); // Skip inner SubmodelInterface
+ InnerComponentParams[] comps = new InnerComponentParams[compList.size() - 1];
+ int i = 0;
+ while (componentIt.hasNext())
+ {
+ GUIComponent component = componentIt.next();
+ InnerComponentParams inner = new InnerComponentParams();
+ comps[i] = inner;
+ inner.logicWidth = component.getPins().get(0).logicWidth; // This could be done a little more elegantly
+ Rectangle bounds = component.getBounds();
+ inner.pos = new Point(bounds.x, bounds.y);
+ inner.type = component.getIdentifier();
+ i++;
+ }
+ params.subComps = comps;
+
+ List<GUIWire> wireList = submodelModifiable.getWires();
+ InnerWireParams wires[] = new InnerWireParams[wireList.size()];
+ i = 0;
+ for (GUIWire wire : wireList)
+ {
+ InnerWireParams inner = new InnerWireParams();
+ wires[i] = inner;
+ InnerPinParams pin1Params = new InnerPinParams(), pin2Params = new InnerPinParams();
+
+ pin1Params.pinIndex = wire.getPin1().component.getPins().indexOf(wire.getPin1());
+ pin1Params.compId = compList.indexOf(wire.getPin1().component);
+ pin2Params.pinIndex = wire.getPin2().component.getPins().indexOf(wire.getPin2());
+ pin2Params.compId = compList.indexOf(wire.getPin2().component);
+ inner.pin1 = pin1Params;
+ inner.pin2 = pin2Params;
+ inner.path = wire.getPath();
+ i++;
+ }
+ params.innerWires = wires;
+ return params;
+ }