- /**
- * @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.
- */
- public static SubmodelComponent create(ViewModelModifiable model, SubComponentParams params, String path)
+ // May return null
+ private static SimpleRectangularSubmodelComponent createRectComponent(ViewModelModifiable model, SubmodelComponentParams params)
+ {
+ try
+ {
+ Map<String, Object> 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);
+
+ 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)
+ {
+ System.err.println("Failed to specialize component!");
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private static SubmodelComponent createSubmodelComponent(ViewModelModifiable model, SubmodelComponentParams params)