+ 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.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME)).findAny()).isPresent())
+ submodelModifiable.destroyComponent(o.get());
+
+ tempModel.getComponentsByName().values().stream()
+ .filter(c -> !c.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
+ .forEach(c -> IndirectModelComponentCreator.createComponent(submodelModifiable, c.getIDForSerializing(iP),
+ c.getParamsForSerializingJSON(iP), c.getName()).moveTo(c.getPosX(), c.getPosY()));
+ for (ModelWire w : tempModel.getWiresByName().values())
+ createWire(Function.identity(), submodelModifiable, w);
+ }
+ if (snapWCPs)
+ submodelModifiable.getComponentsByName().values().stream().filter(c -> c instanceof ModelWireCrossPoint).forEach(c ->
+ {
+ double x = c.getPosX();
+ double y = c.getPosY();
+ c.moveTo(x % GRIDSIZE == 0 ? x - 1 : x, y % GRIDSIZE == 0 ? y - 1 : y);
+ });
+ if (warnNonSnappedPoints)
+ {
+ submodelModifiable.getComponentsByName().values().forEach(c ->
+ {
+ double x = c.getPosX();
+ double y = c.getPosY();
+ if (c instanceof ModelWireCrossPoint)
+ {
+ x++;
+ y++;
+ }
+ if (x % GRIDSIZE != 0 || y % GRIDSIZE != 0)
+ System.out.println(" Component " + c.getName() + " (type " + c.getIDForSerializing(new IdentifyParams())
+ + ") is not snapped to grid: " + x + "," + y);
+ });
+ submodelModifiable.getWiresByName().values().stream().forEach(w ->
+ {
+ Point[] p = w.getPath();
+ if (p != null)
+ for (int i = 0; i < p.length; i++)
+ if (p[i].x % GRIDSIZE != 0 || p[i].y % GRIDSIZE != 0)
+ System.out.println(
+ " Wire " + w.name + " path point #" + i + " is not snapped to grid: " + p[i].x + "," + p[i].y);
+ });
+ comp.getPins().values().forEach(p ->
+ {
+ if (p.getRelX() % GRIDSIZE != 0 || p.getRelY() % GRIDSIZE != 0)
+ System.out.println(" Interface point " + p.name + " is not snapped to grid: " + p.getRelX() + "," + p.getRelY());
+ });
+ }
+ SubmodelComponentSerializer.serialize(comp, componentPath.toString());
+ if (changeComponentNames && (comp.getHighLevelStateHandler() == null
+ || !(comp.getHighLevelStateHandler() instanceof DefaultHighLevelStateHandler)))
+ {
+ System.out.println(" A non-default HighLevelStateHandler was detected. Check for changes there manually.");
+ System.out.print(" Empty line to continue to next component, old component name to get new component name >");
+ for (String line = sysin.nextLine(); !line.equals(""); line = sysin.nextLine())
+ System.out.println(" " + line + "->" + componentNameRemapping.get(line) + " >");
+ }