X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fserializing%2FLegacySubmodelComponentSerializer.java;h=37b05a908c4d2c99107333ddbc7bda7750b86138;hb=3a52b6bffe52db5dd5ca907b4b3dfd368a58e14f;hp=2ede422c671fbe11f1d7ee70a9051f1da102c9e5;hpb=853d979edee5d49d3b3c5fe08609f6cfd82d863f;p=Mograsim.git
diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/LegacySubmodelComponentSerializer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/LegacySubmodelComponentSerializer.java
index 2ede422c..37b05a90 100644
--- a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/LegacySubmodelComponentSerializer.java
+++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/LegacySubmodelComponentSerializer.java
@@ -9,12 +9,13 @@ import java.util.function.Function;
import com.google.gson.JsonElement;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
-import net.mograsim.logic.model.model.ViewModelModifiable;
-import net.mograsim.logic.model.model.components.GUIComponent;
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.model.components.ModelComponent;
import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
-import net.mograsim.logic.model.model.wires.GUIWire;
+import net.mograsim.logic.model.model.wires.ModelWire;
import net.mograsim.logic.model.model.wires.MovablePin;
import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.model.wires.PinUsage;
import net.mograsim.logic.model.serializing.LegacySubmodelComponentParams.LegacyInterfacePinParams;
import net.mograsim.logic.model.serializing.LegacySubmodelComponentParams.LegacySubmodelParameters;
import net.mograsim.logic.model.serializing.LegacySubmodelComponentParams.LegacySubmodelParameters.LegacyInnerComponentParams;
@@ -36,23 +37,23 @@ public final class LegacySubmodelComponentSerializer
// convenience methods
/**
- * Like {@link #deserialize(ViewModelModifiable, LegacySubmodelComponentParams)}, but first reading the
+ * Like {@link #deserialize(LogicModelModifiable, LegacySubmodelComponentParams)}, but first reading the
* {@link LegacySubmodelComponentParams} from the given file path.
*
* @author Daniel Kirschten
*/
- public static SubmodelComponent deserialize(ViewModelModifiable model, String sourcePath) throws IOException
+ public static SubmodelComponent deserialize(LogicModelModifiable model, String sourcePath) throws IOException
{
return deserialize(model, JsonHandler.readJson(sourcePath, LegacySubmodelComponentParams.class));
}
/**
- * Like {@link #deserialize(ViewModelModifiable, LegacySubmodelComponentParams, String, JsonElement)}, but first reading the
+ * Like {@link #deserialize(LogicModelModifiable, LegacySubmodelComponentParams, String, JsonElement)}, but first reading the
* {@link LegacySubmodelComponentParams} from the given file path.
*
* @author Daniel Kirschten
*/
- public static SubmodelComponent deserialize(ViewModelModifiable model, String sourcePath, String idForSerializingOverride,
+ public static SubmodelComponent deserialize(LogicModelModifiable model, String sourcePath, String idForSerializingOverride,
JsonElement paramsForSerializingOverride) throws IOException
{
return deserialize(model, JsonHandler.readJson(sourcePath, LegacySubmodelComponentParams.class), idForSerializingOverride,
@@ -60,23 +61,23 @@ public final class LegacySubmodelComponentSerializer
}
/**
- * Like {@link #deserialize(ViewModelModifiable, LegacySubmodelComponentParams, String)}, but first reading the
+ * Like {@link #deserialize(LogicModelModifiable, LegacySubmodelComponentParams, String)}, but first reading the
* {@link LegacySubmodelComponentParams} from the given file path.
*
* @author Daniel Kirschten
*/
- public static SubmodelComponent deserialize(ViewModelModifiable model, String sourcePath, String name) throws IOException
+ public static SubmodelComponent deserialize(LogicModelModifiable model, String sourcePath, String name) throws IOException
{
return deserialize(model, JsonHandler.readJson(sourcePath, LegacySubmodelComponentParams.class), name);
}
/**
- * Like {@link #deserialize(ViewModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement)}, but first reading the
+ * Like {@link #deserialize(LogicModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement)}, but first reading the
* {@link LegacySubmodelComponentParams} from the given file path.
*
* @author Daniel Kirschten
*/
- public static SubmodelComponent deserialize(ViewModelModifiable model, String sourcePath, String name, String idForSerializingOverride,
+ public static SubmodelComponent deserialize(LogicModelModifiable model, String sourcePath, String name, String idForSerializingOverride,
JsonElement paramsForSerializingOverride) throws IOException
{
return deserialize(model, JsonHandler.readJson(sourcePath, LegacySubmodelComponentParams.class), name, idForSerializingOverride,
@@ -84,34 +85,34 @@ public final class LegacySubmodelComponentSerializer
}
/**
- * {@link #deserialize(ViewModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement)} with no
+ * {@link #deserialize(LogicModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement)} with no
* idForSerializingOverride
set and using the default name.
*
* @author Daniel Kirschten
*/
- public static SubmodelComponent deserialize(ViewModelModifiable model, LegacySubmodelComponentParams params)
+ public static SubmodelComponent deserialize(LogicModelModifiable model, LegacySubmodelComponentParams params)
{
return deserialize(model, params, null, null, null);
}
/**
- * {@link #deserialize(ViewModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement)} using the default name.
+ * {@link #deserialize(LogicModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement)} using the default name.
*
* @author Daniel Kirschten
*/
- public static SubmodelComponent deserialize(ViewModelModifiable model, LegacySubmodelComponentParams params,
+ public static SubmodelComponent deserialize(LogicModelModifiable model, LegacySubmodelComponentParams params,
String idForSerializingOverride, JsonElement paramsForSerializingOverride)
{
return deserialize(model, params, null, idForSerializingOverride, paramsForSerializingOverride);
}
/**
- * {@link #deserialize(ViewModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement)} with no
+ * {@link #deserialize(LogicModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement)} with no
* idForSerializingOverride
set.
*
* @author Daniel Kirschten
*/
- public static SubmodelComponent deserialize(ViewModelModifiable model, LegacySubmodelComponentParams params, String name)
+ public static SubmodelComponent deserialize(LogicModelModifiable model, LegacySubmodelComponentParams params, String name)
{
return deserialize(model, params, name, null, null);
}
@@ -133,9 +134,9 @@ public final class LegacySubmodelComponentSerializer
*
* @author Daniel Kirschten
*/
- public static void serialize(SubmodelComponent comp, IdentifierGetter idGetter, String targetPath) throws IOException
+ public static void serialize(SubmodelComponent comp, IdentifyParams idParams, String targetPath) throws IOException
{
- JsonHandler.writeJson(serialize(comp, idGetter), targetPath);
+ JsonHandler.writeJson(serialize(comp, idParams), targetPath);
}
/**
@@ -146,7 +147,7 @@ public final class LegacySubmodelComponentSerializer
*/
public static LegacySubmodelComponentParams serialize(SubmodelComponent comp)
{
- return serialize(comp, new IdentifierGetter());
+ return serialize(comp, new IdentifyParams());
}
// "core" methods
@@ -162,8 +163,8 @@ public final class LegacySubmodelComponentSerializer
* @author Fabian Stemmler
* @author Daniel Kirschten
*/
- @SuppressWarnings("unused") // for GUIWire being created
- public static SubmodelComponent deserialize(ViewModelModifiable model, LegacySubmodelComponentParams params, String name,
+ @SuppressWarnings("unused") // for ModelWire being created
+ public static SubmodelComponent deserialize(LogicModelModifiable model, LegacySubmodelComponentParams params, String name,
String idForSerializingOverride, JsonElement paramsForSerializingOverride)
{
DeserializedSubmodelComponent comp = new DeserializedSubmodelComponent(model, name, idForSerializingOverride,
@@ -171,23 +172,24 @@ public final class LegacySubmodelComponentSerializer
comp.setSubmodelScale(params.submodel.innerScale);
comp.setSize(params.width, params.height);
for (LegacyInterfacePinParams iPinParams : params.interfacePins)
- comp.addSubmodelInterface(
- new MovablePin(comp, iPinParams.name, iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y));
+ // TRISTATE because we don't have a better choice
+ comp.addSubmodelInterface(new MovablePin(comp, iPinParams.name, iPinParams.logicWidth, PinUsage.TRISTATE, iPinParams.location.x,
+ iPinParams.location.y));
LegacySubmodelParameters submodelParams = params.submodel;
- ViewModelModifiable submodelModifiable = comp.getSubmodelModifiable();
- Map componentsByName = submodelModifiable.getComponentsByName();
- GUIComponent[] components = new GUIComponent[submodelParams.subComps.length];
+ LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
+ Map componentsByName = submodelModifiable.getComponentsByName();
+ ModelComponent[] components = new ModelComponent[submodelParams.subComps.length];
for (int i = 0; i < components.length; i++)
{
LegacyInnerComponentParams cParams = submodelParams.subComps[i];
- components[i] = IndirectGUIComponentCreator.createComponent(submodelModifiable, cParams.id, cParams.params, cParams.name);
+ components[i] = IndirectModelComponentCreator.createComponent(submodelModifiable, cParams.id, cParams.params, cParams.name);
components[i].moveTo(cParams.pos.x, cParams.pos.y);
}
for (int i = 0; i < submodelParams.innerWires.length; i++)
{
LegacyInnerWireParams innerWire = submodelParams.innerWires[i];
- new GUIWire(submodelModifiable, innerWire.name, componentsByName.get(innerWire.pin1.compName).getPin(innerWire.pin1.pinName),
+ new ModelWire(submodelModifiable, innerWire.name, componentsByName.get(innerWire.pin1.compName).getPin(innerWire.pin1.pinName),
componentsByName.get(innerWire.pin2.compName).getPin(innerWire.pin2.pinName), innerWire.path);
}
comp.setSymbolRenderer(SubmodelComponentSnippetSuppliers.symbolRendererSupplier.getSnippetSupplier(params.symbolRendererSnippetID)
@@ -204,28 +206,28 @@ public final class LegacySubmodelComponentSerializer
* Subcomponents are serialized in the following way:
* If a subcomponent is a SubmodelComponent
which has been deserialized, and it has an
* {@link DeserializedSubmodelComponent#idForSerializingOverride idForSerializingOverride} set (e.g. non-null; see
- * {@link #deserialize(ViewModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement) deserialize(...)}), this ID and
+ * {@link #deserialize(LogicModelModifiable, LegacySubmodelComponentParams, String, String, JsonElement) deserialize(...)}), this ID and
* the component's {@link DeserializedSubmodelComponent#paramsForSerializingOverride paramsForSerializingOverride} are written.
* If this case doesn't apply (e.g. if the subcomponent is not a SubmodelComponent
; or it is a
* SubmodelComponent
, but hasn't been deserialized; or it has no
* {@link DeserializedSubmodelComponent#idForSerializingOverride idForSerializingOverride} set), the ID defined by idGetter
- * and the params obtained by {@link GUIComponent#getParamsForSerializing() getParams()} are written.
+ * and the params obtained by {@link ModelComponent#getParamsForSerializing() getParams()} are written.
* CodeSnippets are serialized using the ID defined by idGetter
and the params obtained by the respective
* getParamsForSerializing methods ({@link Renderer#getParamsForSerializing()}).
*
* @author Fabian Stemmler
* @author Daniel Kirschten
*/
- public static LegacySubmodelComponentParams serialize(SubmodelComponent comp, IdentifierGetter idGetter)
+ public static LegacySubmodelComponentParams serialize(SubmodelComponent comp, IdentifyParams idParams)
{
LegacySubmodelParameters submodelParams = new LegacySubmodelParameters();
submodelParams.innerScale = comp.getSubmodelScale();
- Map components = new HashMap<>(comp.submodel.getComponentsByName());
+ Map components = new HashMap<>(comp.submodel.getComponentsByName());
components.remove(SubmodelComponent.SUBMODEL_INTERFACE_NAME);
LegacyInnerComponentParams[] componentParams = new LegacyInnerComponentParams[components.size()];
int i1 = 0;
- for (GUIComponent innerComponent : components.values())
+ for (ModelComponent innerComponent : components.values())
{
LegacyInnerComponentParams innerComponentParams = new LegacyInnerComponentParams();
componentParams[i1] = innerComponentParams;
@@ -238,18 +240,18 @@ public final class LegacySubmodelComponentSerializer
innerComponentParams.params = innerCompCasted.paramsForSerializingOverride;
} else
{
- innerComponentParams.id = idGetter.componentIDs.apply(innerComponent);
- innerComponentParams.params = innerComponent.getParamsForSerializing(idGetter);
+ innerComponentParams.id = innerComponent.getIDForSerializing(idParams);
+ innerComponentParams.params = innerComponent.getParamsForSerializingJSON(idParams);
}
innerComponentParams.name = innerComponent.name;
i1++;
}
submodelParams.subComps = componentParams;
- Collection wires = comp.submodel.getWiresByName().values();
+ Collection wires = comp.submodel.getWiresByName().values();
LegacyInnerWireParams wireParams[] = new LegacyInnerWireParams[wires.size()];
i1 = 0;
- for (GUIWire innerWire : wires)
+ for (ModelWire innerWire : wires)
{
LegacyInnerWireParams innerWireParams = new LegacyInnerWireParams();
wireParams[i1] = innerWireParams;
@@ -289,22 +291,22 @@ public final class LegacySubmodelComponentSerializer
Renderer symbolRenderer = comp.getSymbolRenderer();
if (symbolRenderer != null)
{
- params.symbolRendererSnippetID = idGetter.symbolRendererIDs.apply(symbolRenderer);
- params.symbolRendererParams = symbolRenderer.getParamsForSerializingJSON(idGetter);
+ params.symbolRendererSnippetID = symbolRenderer.getIDForSerializing(idParams);
+ params.symbolRendererParams = symbolRenderer.getParamsForSerializingJSON(idParams);
}
Renderer outlineRenderer = comp.getOutlineRenderer();
if (outlineRenderer != null)
{
- params.outlineRendererSnippetID = idGetter.outlineRendererIDs.apply(outlineRenderer);
- params.outlineRendererParams = outlineRenderer.getParamsForSerializingJSON(idGetter);
+ params.outlineRendererSnippetID = outlineRenderer.getIDForSerializing(idParams);
+ params.outlineRendererParams = outlineRenderer.getParamsForSerializingJSON(idParams);
}
HighLevelStateHandler highLevelStateHandler = comp.getHighLevelStateHandler();
if (highLevelStateHandler != null)
{
- params.highLevelStateHandlerSnippetID = idGetter.highLevelStateHandlerIDs.apply(highLevelStateHandler);
- params.highLevelStateHandlerParams = highLevelStateHandler.getParamsForSerializingJSON(idGetter);
+ params.highLevelStateHandlerSnippetID = highLevelStateHandler.getIDForSerializing(idParams);
+ params.highLevelStateHandlerParams = highLevelStateHandler.getParamsForSerializingJSON(idParams);
}
return params;