import net.mograsim.logic.model.serializing.IdentifyParams;
import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
import net.mograsim.logic.model.serializing.SubmodelComponentSerializer;
+import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
public class ReserializeJSONsSettingUsages
{
}
}
- public static void reserializeJSON(Path json, Scanner sysin)
+ public static void reserializeJSON(Path componentPath, Scanner sysin)
{
try
{
DeserializedSubmodelComponent comp = (DeserializedSubmodelComponent) IndirectModelComponentCreator
- .createComponent(new LogicModelModifiable(), "jsonfile:" + json.toString());
- System.out.println("Reserializing " + json);
+ .createComponent(new LogicModelModifiable(), "jsonfile:" + componentPath.toString());
+ System.out.println("Reserializing " + componentPath);
if (changePinUsages)
comp.getSupermodelPins().entrySet().stream().sorted(Comparator.comparing(Entry::getKey)).map(Entry::getValue).forEach(pin ->
{
setInterfacePinUsage(comp, pin, usage);
});
LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
+ Map<String, String> componentNameRemapping = new HashMap<>();
if (changeComponentNames)
{
- Map<String, String> componentNameRemapping = new HashMap<>();
componentNameRemapping.put(SubmodelComponent.SUBMODEL_INTERFACE_NAME, SubmodelComponent.SUBMODEL_INTERFACE_NAME);
LogicModelModifiable tempModel = new LogicModelModifiable();
IdentifyParams iP = new IdentifyParams();
{
System.out.print(" New name for component " + oldName + " of type " + subcomp.getIDForSerializing(iP)
+ " (empty: " + defaultName + ") >");
- newName = sysin.nextLine();
+// newName = sysin.nextLine();
+ newName = "";
+ System.out.println();
if (newName.equals(""))
newName = defaultName;
if (tempModel.getComponentsByName().containsKey(newName))
Optional<ModelComponent> o;
while ((o = submodelModifiable.getComponentsByName().values().stream()
- .filter(c -> !c.name.equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME)).findAny()).isPresent())
+ .filter(c -> !c.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME)).findAny()).isPresent())
submodelModifiable.destroyComponent(o.get());
- tempModel.getComponentsByName().values().stream().filter(c -> !c.name.equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
+ 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.name)
+ .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);
}
- SubmodelComponentSerializer.serialize(comp, json.toString());
+ 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) + " >");
+ }
}
catch (Exception e)
{
- System.err.println("An error occurred visiting " + json + ":");
+ System.err.println("An error occurred visiting " + componentPath + ":");
e.printStackTrace();
}
}
private static Pin getRemappedPin(Function<String, String> componentNameRemapping, LogicModelModifiable tempModelForDefaultNames,
Pin pin)
{
- return tempModelForDefaultNames.getComponentsByName().get(componentNameRemapping.apply(pin.component.name)).getPin(pin.name);
+ return tempModelForDefaultNames.getComponentsByName().get(componentNameRemapping.apply(pin.component.getName())).getPin(pin.name);
}
private static int compareStringsWithIntegers(String a, String b)