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;
/**
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;
}
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
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);
}
{
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);
}
}
@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");
/**
* 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 ->
{
});
submodelInterface.addPin(submodelPin);
- super.addPin(supermodelPin);
submodelPins.put(name, submodelPin);
supermodelPins.put(name, supermodelPin);