X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fsubmodels%2FSimpleRectangularSubmodelComponent.java;h=ef567e9241cb5844d4530de4d43c21ed6a349142;hb=8bed58cd47f4e53a0a83e066d38864aa6875502f;hp=530f0789c3310bb7ff6bfa770e42ced0c4c8d2a2;hpb=b5d8c2d71e27350ea7c9314e40df5bb0584271cd;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java index 530f0789..ef567e92 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SimpleRectangularSubmodelComponent.java @@ -5,33 +5,24 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.function.Function; -import org.eclipse.swt.graphics.Color; - -import com.google.gson.JsonObject; - -import net.haspamelodica.swt.helper.gcs.GeneralGC; -import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; -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.wires.MovablePin; import net.mograsim.logic.model.model.wires.Pin; -import net.mograsim.logic.model.serializing.SubmodelComponentParams; -import net.mograsim.logic.model.serializing.snippets.Renderer; -import net.mograsim.logic.model.serializing.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer; -import net.mograsim.logic.model.serializing.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer.SimpleRectangularLikeParams; -import net.mograsim.preferences.Preferences; +import net.mograsim.logic.model.model.wires.PinUsage; +import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer; +import net.mograsim.logic.model.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer; +import net.mograsim.logic.model.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer.SimpleRectangularLikeParams; public class SimpleRectangularSubmodelComponent extends SubmodelComponent { - private static final double width = 35; - private static final double pinDistance = 10; - private static final double pinNameMargin = .5; - private static final double labelFontHeight = 5; - private static final double pinNameFontHeight = 3.5; + public static final double width = 35; + public static final double pinDistance = 10; + public static final double pinNameMargin = .5; + public static final double labelFontHeight = 5; + public static final double pinNameFontHeight = 3.5; - private final String label; + public final String label; protected final int logicWidth; private final List inputPinNames; @@ -39,16 +30,19 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent private final List outputPinNames; private final List outputPinNamesUnmodifiable; - private Renderer symbolRenderer; - - public SimpleRectangularSubmodelComponent(ViewModelModifiable model, int logicWidth, String label) + public SimpleRectangularSubmodelComponent(LogicModelModifiable model, int logicWidth, String label) { this(model, logicWidth, label, null); } - public SimpleRectangularSubmodelComponent(ViewModelModifiable model, int logicWidth, String label, String name) + public SimpleRectangularSubmodelComponent(LogicModelModifiable model, int logicWidth, String label, String name) + { + this(model, logicWidth, label, name, true); + } + + protected SimpleRectangularSubmodelComponent(LogicModelModifiable model, int logicWidth, String label, String name, boolean callInit) { - super(model, name); + super(model, name, false); this.label = label; this.logicWidth = logicWidth; this.inputPinNames = new ArrayList<>(); @@ -59,23 +53,28 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent SimpleRectangularLikeParams rendererParams = new SimpleRectangularLikeParams(); rendererParams.centerText = label; rendererParams.centerTextHeight = labelFontHeight; - rendererParams.horizontalComponentCenter = getWidth() / 2; + rendererParams.horizontalComponentCenter = width / 2; rendererParams.pinLabelHeight = pinNameFontHeight; rendererParams.pinLabelMargin = pinNameMargin; - symbolRenderer = new SimpleRectangularLikeSymbolRenderer(this, rendererParams); + setSymbolRenderer(new SimpleRectangularLikeSymbolRenderer(this, rendererParams)); + setOutlineRenderer(new DefaultOutlineRenderer(this)); + + if (callInit) + init(); } protected void setInputPins(String... pinNames) { - setIOPins(0, inputPinNames, outputPinNames, pinNames); + setIOPins(0, inputPinNames, outputPinNames, PinUsage.INPUT, pinNames); } protected void setOutputPins(String... pinNames) { - setIOPins(width, outputPinNames, inputPinNames, pinNames); + setIOPins(width, outputPinNames, inputPinNames, PinUsage.OUTPUT, pinNames); } - private void setIOPins(double relX, List pinNamesListThisSide, List pinNamesListOtherSide, String... newPinNames) + private void setIOPins(double relX, List pinNamesListThisSide, List pinNamesListOtherSide, PinUsage usage, + String... newPinNames) { int inputCount = newPinNames.length; List newPinNamesList = Arrays.asList(newPinNames); @@ -90,7 +89,8 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent String pinName = newPinNames[i]; int oldPinIndex = pinNamesListThisSide.indexOf(pinName); if (oldPinIndex == -1) - super.addSubmodelInterface(new MovablePin(this, pinName, logicWidth, relX, pinDistance / 2 + i * pinDistance)); + super.addSubmodelInterface( + new MovablePin(model, this, pinName, logicWidth, usage, relX, pinDistance / 2 + i * pinDistance)); else getSupermodelMovablePin(pinName).setRelPos(relX, pinDistance / 2 + i * pinDistance); } @@ -111,38 +111,6 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent return outputPinNamesUnmodifiable; } - @Override - protected void renderSymbol(GeneralGC gc, Rectangle visibleRegion) - { - symbolRenderer.render(gc, visibleRegion); - } - - @Override - protected void renderOutline(GeneralGC gc, Rectangle visibleRegion) - { - Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground"); - if (foreground != null) - gc.setForeground(foreground); - gc.drawRectangle(getBounds()); - } - - // serializing - - @Override - public SubmodelComponentParams calculateParams(Function getIdentifier) - { - SubmodelComponentParams params = super.calculateParams(getIdentifier); - JsonObject symbolRendererParams = new JsonObject(); - symbolRendererParams.addProperty("centerText", label); - symbolRendererParams.addProperty("horizontalComponentCenter", getWidth() / 2); - symbolRendererParams.addProperty("centerTextHeight", labelFontHeight); - symbolRendererParams.addProperty("pinLabelHeight", pinNameFontHeight); - symbolRendererParams.addProperty("pinLabelMargin", pinNameMargin); - params.symbolRendererSnippetID = "SimpleRectangularLikeSymbolRenderer"; - params.symbolRendererParams = symbolRendererParams; - return params; - } - @Override protected Pin addSubmodelInterface(MovablePin supermodelPin) {