X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fsubmodels%2FSubmodelComponent.java;h=9388e2fb09fdc7e51ba8370f1b2c76e5700397f3;hb=8bed58cd47f4e53a0a83e066d38864aa6875502f;hp=4a2f46c147bf69ebd1505a2768bebe6a8c297a54;hpb=1f645882d229fc3d4081e4c5060559d75dc2cc24;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java index 4a2f46c1..9388e2fb 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java @@ -101,7 +101,12 @@ public abstract class SubmodelComponent extends ModelComponent public SubmodelComponent(LogicModelModifiable model, String name) { - super(model, name); + this(model, name, true); + } + + protected SubmodelComponent(LogicModelModifiable model, String name, boolean callInit) + { + super(model, name, false); this.submodelModifiable = new LogicModelModifiable(); this.submodel = submodelModifiable; this.submodelPins = new HashMap<>(); @@ -110,7 +115,7 @@ public abstract class SubmodelComponent extends ModelComponent 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; @@ -125,6 +130,9 @@ public abstract class SubmodelComponent extends ModelComponent model.removeRedrawHandlerChangedListener(redrawHandlerChangedListener); }); submodelModifiable.setRedrawHandler(model.getRedrawHandler()); + + if (callInit) + init(); } // pins @@ -159,7 +167,7 @@ public abstract class SubmodelComponent extends ModelComponent default: throw new IllegalArgumentException("Unknown enum constant: " + supermodelPin.usage); } - MovablePin submodelPin = new MovablePin(model, submodelInterface, name, supermodelPin.logicWidth, submodelPinUsage, + MovablePin submodelPin = new MovablePin(submodelModifiable, submodelInterface, name, supermodelPin.logicWidth, submodelPinUsage, supermodelPin.getRelX() / submodelScale, supermodelPin.getRelY() / submodelScale); submodelPin.addPinMovedListener(p -> @@ -421,14 +429,28 @@ public abstract class SubmodelComponent extends ModelComponent // 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); }