this.supermodelPins = new HashMap<>();
this.supermodelMovablePinsUnmodifiable = Collections.unmodifiableMap(supermodelPins);
this.supermodelUnmovablePinsUnmodifiable = Collections.unmodifiableMap(supermodelPins);
- this.submodelInterface = new SubmodelInterface(submodelModifiable, SUBMODEL_INTERFACE_NAME);
+ this.submodelInterface = new SubmodelInterface(submodelModifiable);
this.submodelScale = 1;
this.maxVisibleRegionFillRatioForAlpha0 = 0.8;
// serializing
+ /**
+ * {@link SubmodelComponent}'s implementation of {@link ModelComponent#getIDForSerializing(IdentifyParams)} returns "submodel". It is
+ * recommended to override this behaviour.
+ *
+ * @see ModelComponent#getIDForSerializing(IdentifyParams)
+ * @see ModelComponent#getParamsForSerializing(IdentifyParams)
+ */
@Override
public String getIDForSerializing(IdentifyParams idParams)
{
return "submodel";// TODO what ID?
}
+ /**
+ * {@link SubmodelComponent}'s implementation of {@link ModelComponent#getParamsForSerializing(IdentifyParams)} returns an instance of
+ * {@link SubmodelComponentParams}. It is recommended to override this behaviour.
+ *
+ * @see ModelComponent#getIDForSerializing(IdentifyParams)
+ * @see ModelComponent#getParamsForSerializing(IdentifyParams)
+ */
@Override
- public SubmodelComponentParams getParamsForSerializing(IdentifyParams idParams)
+ public Object getParamsForSerializing(IdentifyParams idParams)
{
return SubmodelComponentSerializer.serialize(this, idParams);
}
public class SubmodelInterface extends ModelComponent
{
- public SubmodelInterface(LogicModelModifiable model, String name)
+ public SubmodelInterface(LogicModelModifiable model)
{
- super(model, name, true);
+ super(model, SubmodelComponent.SUBMODEL_INTERFACE_NAME, true);
}
@Override
/**
* See {@link #idForSerializingOverride}
*/
- public final JsonElement paramsForSerializingOverride;
+ public final Object paramsForSerializingOverride;
public DeserializedSubmodelComponent(LogicModelModifiable model, String name, String idForSerializingOverride,
- JsonElement paramsForSerializingOverride)
+ Object paramsForSerializingOverride)
{
super(model, name, false);
this.idForSerializingOverride = idForSerializingOverride;
init();
}
+ /**
+ * If this component has an {@link #idForSerializingOverride} set (e.g. non-null) (see
+ * {@link SubmodelComponentSerializer#deserialize(LogicModelModifiable, SubmodelComponentParams, String, String, JsonElement)
+ * SubmodelComponentSerializer.deserialize(...)}), this ID is returned<br>
+ * If this case doesn't apply (this component has no {@link #idForSerializingOverride} set),
+ * {@link SubmodelComponent#getIDForSerializing(IdentifyParams)} is invoced.
+ */
+ @Override
+ public String getIDForSerializing(IdentifyParams idParams)
+ {
+ return idForSerializingOverride == null ? super.getIDForSerializing(idParams) : idForSerializingOverride;
+ }
+
+ /**
+ * If this component has an {@link #idForSerializingOverride} set (e.g. non-null) (see
+ * {@link SubmodelComponentSerializer#deserialize(LogicModelModifiable, SubmodelComponentParams, String, String, JsonElement)
+ * SubmodelComponentSerializer.deserialize(...)}), {@link #paramsForSerializingOverride} is returned<br>
+ * If this case doesn't apply (this component has no {@link #idForSerializingOverride} set),
+ * {@link SubmodelComponent#getParamsForSerializing(IdentifyParams)} is invoced.
+ */
+ @Override
+ public Object getParamsForSerializing(IdentifyParams idParams)
+ {
+ return idForSerializingOverride == null ? super.getParamsForSerializing(idParams) : paramsForSerializingOverride;
+ }
+
@Override
public void setSymbolRenderer(Renderer symbolRenderer)
{
}
/**
- * {@link #serialize(SubmodelComponent, Function)} using a default {@link IdentifierGetter} (see <code>IdentifierGetter</code>'s
- * {@link IdentifierGetter#IdentifierGetter() default constructor})
+ * {@link #serialize(SubmodelComponent, Function)} using the default {@link IdentifyParams} (see <code>IdentifyParams</code>'s
+ * {@link IdentifyParams#IdentifyParams() default constructor})
*
* @author Daniel Kirschten
*/
LegacyInnerComponentParams innerComponentParams = new LegacyInnerComponentParams();
componentParams[i1] = innerComponentParams;
innerComponentParams.pos = new Point(innerComponent.getPosX(), innerComponent.getPosY());
- DeserializedSubmodelComponent innerCompCasted;
- if (innerComponent instanceof DeserializedSubmodelComponent
- && (innerCompCasted = (DeserializedSubmodelComponent) innerComponent).idForSerializingOverride != null)
- {
- innerComponentParams.id = innerCompCasted.idForSerializingOverride;
- innerComponentParams.params = innerCompCasted.paramsForSerializingOverride;
- } else
- {
- innerComponentParams.id = innerComponent.getIDForSerializing(idParams);
- innerComponentParams.params = innerComponent.getParamsForSerializingJSON(idParams);
- }
+ innerComponentParams.id = innerComponent.getIDForSerializing(idParams);
+ innerComponentParams.params = innerComponent.getParamsForSerializingJSON(idParams);
innerComponentParams.name = innerComponent.name;
i1++;
}
import java.util.Map;
import java.util.Set;
-import com.google.gson.JsonElement;
-
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
import net.mograsim.logic.model.model.LogicModel;
import net.mograsim.logic.model.model.LogicModelModifiable;
}
/**
- * Like {@link #serialize(LogicModel)}, but instead of returning the generated {@link LogicModelParams} they are written to a file at the
- * given path.
+ * Like {@link #serialize(LogicModel)}, but instead of returning the generated {@link LogicModelParams} they are written to a file at
+ * the given path.
*
* @author Daniel Kirschten
*/
}
/**
- * Like {@link #serialize(LogicModel, IdentifierGetter)}, but instead of returning the generated {@link LogicModelParams} they are written
+ * Like {@link #serialize(LogicModel, IdentifyParams)}, but instead of returning the generated {@link LogicModelParams} they are written
* to a file at the given path.
*
* @author Daniel Kirschten
}
/**
- * {@link #serialize(LogicModel, IdentifierGetter)} using a default {@link IdentifierGetter} (see <code>IdentifierGetter</code>'s
- * {@link IdentifierGetter#IdentifierGetter() default constructor})
+ * {@link #serialize(LogicModel, IdentifyParams)} using the default {@link IdentifyParams} (see <code>IdentifyParams</code>'s
+ * {@link IdentifyParams#IdentifyParams() default constructor})
*
* @author Daniel Kirschten
*/
// "core" methods
/**
- * Deserializes components and wires from the specified {@link LogicModelParams} and adds them to the given {@link LogicModelModifiable}.
+ * Deserializes components and wires from the specified {@link LogicModelParams} and adds them to the given
+ * {@link LogicModelModifiable}.
*
* @author Fabian Stemmler
* @author Daniel Kirschten
/**
* Returns {@link LogicModelModifiable}, which describe the components and wires in the given {@link LogicModel}. <br>
- * Components are serialized in the following way: <br>
- * If a component is a <code>SubmodelComponent</code> which has been deserialized, and it has an
- * {@link DeserializedSubmodelComponent#idForSerializingOverride idForSerializingOverride} set (e.g. non-null; see
- * {@link SubmodelComponentSerializer#deserialize(LogicModelModifiable, SubmodelComponentParams, String, String, JsonElement)
- * SubmodelComponentSerializer.deserialize(...)}), this ID and the component's
- * {@link DeserializedSubmodelComponent#paramsForSerializingOverride paramsForSerializingOverride} are written.<br>
- * If this case doesn't apply (e.g. if the component is not a <code>SubmodelComponent</code>; or it is a <code>SubmodelComponent</code>,
- * but hasn't been deserialized; or it has no {@link DeserializedSubmodelComponent#idForSerializingOverride idForSerializingOverride}
- * set), the ID defined by <code>idGetter</code> and the params obtained by {@link ModelComponent#getParamsForSerializing() getParams()}
- * are written.
+ * Components are serialized using {@link ModelComponent#getIDForSerializing(IdentifyParams)} and
+ * {@link ModelComponent#getParamsForSerializingJSON(IdentifyParams)} <br>
*
* @author Fabian Stemmler
* @author Daniel Kirschten
ComponentParams compParams = new ComponentParams();
componentsParams.add(compParams);
compParams.pos = new Point(component.getPosX(), component.getPosY());
- DeserializedSubmodelComponent innerCompCasted;
- if (component instanceof DeserializedSubmodelComponent
- && (innerCompCasted = (DeserializedSubmodelComponent) component).idForSerializingOverride != null)
- {
- compParams.id = innerCompCasted.idForSerializingOverride;
- compParams.params = innerCompCasted.paramsForSerializingOverride;
- } else
- {
- compParams.id = component.getIDForSerializing(idParams);
- compParams.params = component.getParamsForSerializingJSON(idParams);
- }
+ compParams.id = component.getIDForSerializing(idParams);
+ compParams.params = component.getParamsForSerializingJSON(idParams);
compParams.name = component.name;
}
modelParams.components = componentsParams.toArray(ComponentParams[]::new);
}
/**
- * Like {@link #serialize(SubmodelComponent, IdentifierGetter)}, but instead of returning the generated {@link SubmodelComponentParams}
+ * Like {@link #serialize(SubmodelComponent, IdentifyParams)}, but instead of returning the generated {@link SubmodelComponentParams}
* they are written to a file at the given path.
*
* @author Daniel Kirschten
}
/**
- * {@link #serialize(SubmodelComponent, IdentifierGetter)} using a default {@link IdentifierGetter} (see <code>IdentifierGetter</code>'s
- * {@link IdentifierGetter#IdentifierGetter() default constructor})
+ * {@link #serialize(SubmodelComponent, IdentifyParams)} using the default {@link IdentifyParams} (see <code>IdentifyParams</code>'s
+ * {@link IdentifyParams#IdentifyParams() default constructor})
*
* @author Daniel Kirschten
*/
* When serializing a <code>SubmodelComponent</code>, it is undesired for every subcomponent to be serialized with its complete inner
* structure. Instead, these sub-<code>SubmodelComponent</code>s should be serialized with the ID and params which were used to
* determine the <code>SubmodelComponentParams</code> defining the sub-<code>SubmodelComponent</code>. Because of this, it is possible
- * to override the ID and params used in {@link #serialize(SubmodelComponent, IdentifierGetter) serialize(...)} to describe this
+ * to override the ID and params used in {@link #serialize(SubmodelComponent, IdentifyParams) serialize(...)} to describe this
* subcomponent. See there for details.
*
* @author Fabian Stemmler