import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
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
{
+ public static String kLabel = "label", kInCount = "input_count", kOutCount = "output_count", kLogicWidth = "logic_width";
+
private static final double width = 35;
private static final double pinDistance = 10;
private static final double fontHeight = 5;
else if (oldInputCount < inputCount)
for (int i = oldInputCount; i < inputCount; i++)
{
- Pin submodelPin = addSubmodelInterface(logicWidth, 0, pinDistance / 2 + i * pinDistance);
+ // TODO pin names
+ Pin submodelPin = addSubmodelInterface("Input pin #" + i, logicWidth, 0, pinDistance / 2 + i * pinDistance);
inputSubmodelPins.add(submodelPin);
inputSupermodelPins.add(getSupermodelPin(submodelPin));
}
else if (oldOutputCount < outputCount)
for (int i = oldOutputCount; i < outputCount; i++)
{
- Pin submodelPin = addSubmodelInterface(logicWidth, width, pinDistance / 2 + i * pinDistance);
+ // TODO pin names
+ Pin submodelPin = addSubmodelInterface("Output pin #" + i, logicWidth, width, pinDistance / 2 + i * pinDistance);
outputSubmodelPins.add(submodelPin);
outputSupermodelPins.add(getSupermodelPin(submodelPin));
}
Point textExtent = gc.textExtent(label);
gc.drawText(label, posX + (getBounds().width - textExtent.x) / 2, posY + (getBounds().height - textExtent.y) / 2, true);
gc.setFont(oldFont);
+ // TODO draw pin names
}
@Override
gc.drawRectangle(getBounds());
}
- public ComponentParams calculateParams()
+ @Override
+ public SubmodelComponentParams calculateParams()
{
- ComponentParams params = new ComponentParams();
- params.displayName = label;
- params.inputCount = inputSupermodelPins.size();
- params.outputCount = outputSubmodelPins.size();
- params.logicWidth = logicWidth;
- params.innerScale = getSubmodelScale();
-
- List<GUIComponent> compList = submodelModifiable.getComponents();
- Iterator<GUIComponent> 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<GUIWire> 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;
+ SubmodelComponentParams ret = super.calculateParams();
+ ret.type = SimpleRectangularSubmodelComponent.class.getSimpleName();
+ Map<String, Object> m = new TreeMap<>();
+ m.put(kLabel, label);
+ m.put(kInCount, inputSupermodelPins.size());
+ m.put(kOutCount, outputSupermodelPins.size());
+ m.put(kLogicWidth, logicWidth);
+ ret.specialized = m;
+ return ret;
}
}
\ No newline at end of file