From: Daniel Kirschten Date: Sat, 22 Jun 2019 08:56:46 +0000 (+0200) Subject: Changed SubmodelComponent.addSubmodelInterface() interface X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=7fff8ff23871cf904cb95c92305e903fbba3d773;p=Mograsim.git Changed SubmodelComponent.addSubmodelInterface() interface --- diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java index 6055f1a7..0e23feba 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java @@ -6,11 +6,12 @@ import java.lang.reflect.InvocationTargetException; import java.util.Map; import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.SubmodelComponentParams.ComponentCompositionParams.InnerComponentParams; import net.mograsim.logic.ui.model.components.SubmodelComponentParams.ComponentCompositionParams; +import net.mograsim.logic.ui.model.components.SubmodelComponentParams.ComponentCompositionParams.InnerComponentParams; import net.mograsim.logic.ui.model.components.SubmodelComponentParams.InnerWireParams; import net.mograsim.logic.ui.model.components.SubmodelComponentParams.InterfacePinParams; import net.mograsim.logic.ui.model.wires.GUIWire; +import net.mograsim.logic.ui.model.wires.MovablePin; import net.mograsim.logic.ui.model.wires.WireCrossPoint; /** @@ -112,7 +113,8 @@ public final class GUICustomComponentCreator comp.setSize(params.width, params.height); for (InterfacePinParams iPinParams : params.interfacePins) { - comp.addSubmodelInterface(iPinParams.name, iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y); + comp.addSubmodelInterface( + new MovablePin(comp, iPinParams.name, iPinParams.logicWidth, iPinParams.location.x, iPinParams.location.y)); } return comp; } diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java index 7a7bb9d5..17fa8ab5 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java @@ -13,6 +13,7 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Font; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.ui.model.ViewModelModifiable; +import net.mograsim.logic.ui.model.wires.MovablePin; import net.mograsim.logic.ui.model.wires.Pin; public class SimpleRectangularSubmodelComponent extends SubmodelComponent @@ -69,7 +70,7 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent String pinName = newPinNames[i]; int oldPinIndex = pinNamesListThisSide.indexOf(pinName); if (oldPinIndex == -1) - super.addSubmodelInterface(pinName, logicWidth, relX, pinDistance / 2 + i * pinDistance); + super.addSubmodelInterface(new MovablePin(this, pinName, logicWidth, relX, pinDistance / 2 + i * pinDistance)); else getSupermodelMovablePin(pinName).setRelPos(relX, pinDistance / 2 + i * pinDistance); } @@ -108,8 +109,8 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent { String pinName = outputPinNames.get(i); textExtent = gc.textExtent(pinName); - gc.drawText(pinName, getPosX() + width - textExtent.x - pinNameMargin, getPosY() + i * pinDistance + (pinDistance - textExtent.y) / 2, - true); + gc.drawText(pinName, getPosX() + width - textExtent.x - pinNameMargin, + getPosY() + i * pinDistance + (pinDistance - textExtent.y) / 2, true); } gc.setFont(oldFont); } @@ -135,7 +136,7 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent } @Override - protected Pin addSubmodelInterface(String name, int logicWidth, double relX, double relY) + protected Pin addSubmodelInterface(MovablePin supermodelPin) { throw new UnsupportedOperationException( "Can't add submodel interfaces to a SimpleRectangularSubmodelComponent directly, call setInputPins / setOutputPins instead"); diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java index 6aad07f2..57560574 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java @@ -80,10 +80,13 @@ public abstract class SubmodelComponent extends GUIComponent /** * Returns the submodel pin. */ - protected Pin addSubmodelInterface(String name, int logicWidth, double relX, double relY) + protected Pin addSubmodelInterface(MovablePin supermodelPin) { - MovablePin submodelPin = new MovablePin(submodelInterface, name, logicWidth, relX / submodelScale, relY / submodelScale); - MovablePin supermodelPin = new MovablePin(this, name, logicWidth, relX, relY); + super.addPin(supermodelPin);// do this first to be fail-fast if the supermodel does not belong to this component + + String name = supermodelPin.name; + MovablePin submodelPin = new MovablePin(submodelInterface, name, supermodelPin.logicWidth, supermodelPin.getRelX() / submodelScale, + supermodelPin.getRelY() / submodelScale); submodelPin.addPinMovedListener(p -> { @@ -101,7 +104,6 @@ public abstract class SubmodelComponent extends GUIComponent }); submodelInterface.addPin(submodelPin); - super.addPin(supermodelPin); submodelPins.put(name, submodelPin); supermodelPins.put(name, supermodelPin);