X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FSimpleRectangularSubmodelComponent.java;h=f537eec220296ec27940a7bbc2a22bbe33548367;hb=6074b5904dc7a1c2e4ba37976f37b8b4ad524de5;hp=e2af6f1a0819b1b225a7456e233718a81a01d3dc;hpb=c1a8e2103a1a79039163ad2e414c0650f8cee3ea;p=Mograsim.git 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 e2af6f1a..f537eec2 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 @@ -2,19 +2,24 @@ package net.mograsim.logic.ui.model.components; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import net.haspamelodica.swt.helper.gcs.GeneralGC; 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.components.ComponentParams.InnerComponentParams; +import net.mograsim.logic.ui.model.components.ComponentParams.InnerPinParams; +import net.mograsim.logic.ui.model.components.ComponentParams.InnerWireParams; +import net.mograsim.logic.ui.model.wires.GUIWire; import net.mograsim.logic.ui.model.wires.Pin; public class SimpleRectangularSubmodelComponent extends SubmodelComponent { private static final double width = 35; private static final double pinDistance = 10; - private static final double minHeight = 25; private static final double fontHeight = 5; private final String label; @@ -104,7 +109,7 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent } @Override - protected void renderSymbol(GeneralGC gc) + protected void renderSymbol(GeneralGC gc, Rectangle visibleRegion) { double posX = getBounds().x; double posY = getBounds().y; @@ -118,8 +123,60 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent } @Override - protected void renderOutline(GeneralGC gc) + protected void renderOutline(GeneralGC gc, Rectangle visibleRegion) { gc.drawRectangle(getBounds()); } + + public ComponentParams calculateParams() + { + ComponentParams params = new ComponentParams(); + params.displayName = label; + params.inputCount = inputSupermodelPins.size(); + params.outputCount = outputSubmodelPins.size(); + params.logicWidth = logicWidth; + params.innerScale = getSubmodelScale(); + + List compList = submodelModifiable.getComponents(); + Iterator componentIt = compList.iterator(); + componentIt.next(); // Skip inner SubmodelInterface + InnerComponentParams[] comps = new InnerComponentParams[compList.size() - 1]; + int i = 0; + while (componentIt.hasNext()) + { + GUIComponent component = componentIt.next(); + InnerComponentParams inner = new InnerComponentParams(); + comps[i] = inner; + inner.logicWidth = component.getPins().get(0).logicWidth; // This could be done a little more elegantly + Rectangle bounds = component.getBounds(); + inner.pos = new Point(bounds.x, bounds.y); + if (component instanceof GUICustomComponent) + inner.type = "file:" + ((GUICustomComponent) component).getPath(); + else + inner.type = "class:" + component.getClass().getCanonicalName(); + i++; + } + params.subComps = comps; + + List wireList = submodelModifiable.getWires(); + InnerWireParams wires[] = new InnerWireParams[wireList.size()]; + i = 0; + for (GUIWire wire : wireList) + { + InnerWireParams inner = new InnerWireParams(); + wires[i] = inner; + InnerPinParams pin1Params = new InnerPinParams(), pin2Params = new InnerPinParams(); + + pin1Params.pinIndex = wire.getPin1().component.getPins().indexOf(wire.getPin1()); + pin1Params.compId = compList.indexOf(wire.getPin1().component); + pin2Params.pinIndex = wire.getPin2().component.getPins().indexOf(wire.getPin2()); + pin2Params.compId = compList.indexOf(wire.getPin2().component); + inner.pin1 = pin1Params; + inner.pin2 = pin2Params; + inner.path = wire.getPath(); + i++; + } + params.innerWires = wires; + return params; + } } \ No newline at end of file