- System.out.print(" Usage for interface pin " + pin.name + " (empty: " + pin.usage + ") >");
- String usageStr = sysin.nextLine().toUpperCase();
- PinUsage usage = usageStr.equals("") ? pin.usage
- : usageStr.equals("I") ? PinUsage.INPUT
- : usageStr.equals("O") ? PinUsage.OUTPUT
- : usageStr.equals("T") ? PinUsage.TRISTATE : PinUsage.valueOf(usageStr);
- setInterfacePinUsage(comp, pin, usage);
- });
+ Map<String, String> componentNameRemapping = new HashMap<>();
+ componentNameRemapping.put(SubmodelComponent.SUBMODEL_INTERFACE_NAME, SubmodelComponent.SUBMODEL_INTERFACE_NAME);
+ LogicModelModifiable tempModel = new LogicModelModifiable();
+ IdentifyParams iP = new IdentifyParams();
+ submodelModifiable.getComponentsByName().entrySet().stream()
+ .filter(e -> !e.getKey().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
+ .sorted(Comparator.comparing(Entry::getKey, ReserializeJSONsSettingUsages::compareStringsWithIntegers)).forEach(e ->
+ {
+ String oldName = e.getKey();
+ ModelComponent subcomp = e.getValue();
+ String defaultName = tempModel.getDefaultComponentName(subcomp);
+ String newName = null;
+ while (newName == null)
+ {
+ System.out.print(" New name for component " + oldName + " of type " + subcomp.getIDForSerializing(iP)
+ + " (empty: " + defaultName + ") >");
+ newName = sysin.nextLine();
+ if (newName.equals(""))
+ newName = defaultName;
+ if (tempModel.getComponentsByName().containsKey(newName))
+ {
+ System.err.println(" There already is a component with that name");
+ newName = null;
+ }
+ }
+ componentNameRemapping.put(oldName, newName);
+ IndirectModelComponentCreator.createComponent(tempModel, subcomp.getIDForSerializing(iP),
+ subcomp.getParamsForSerializingJSON(iP), newName).moveTo(subcomp.getPosX(), subcomp.getPosY());
+ });
+ SubmodelInterface tempSubmodelInterface = new SubmodelInterface(tempModel);
+ for (Pin p : submodelModifiable.getComponentsByName().get(SubmodelComponent.SUBMODEL_INTERFACE_NAME).getPins().values())
+ tempSubmodelInterface
+ .addPin(new Pin(tempModel, tempSubmodelInterface, p.name, p.logicWidth, p.usage, p.getRelX(), p.getRelY()));
+ for (ModelWire w : submodelModifiable.getWiresByName().values())
+ createWire(componentNameRemapping::get, tempModel, w);
+
+ Optional<ModelComponent> o;
+ while ((o = submodelModifiable.getComponentsByName().values().stream()
+ .filter(c -> !c.name.equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME)).findAny()).isPresent())
+ submodelModifiable.destroyComponent(o.get());
+
+ tempModel.getComponentsByName().values().stream().filter(c -> !c.name.equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
+ .forEach(c -> IndirectModelComponentCreator
+ .createComponent(submodelModifiable, c.getIDForSerializing(iP), c.getParamsForSerializingJSON(iP), c.name)
+ .moveTo(c.getPosX(), c.getPosY()));
+ for (ModelWire w : tempModel.getWiresByName().values())
+ createWire(Function.identity(), submodelModifiable, w);
+ }