use of de.cau.cs.kieler.klighd.kgraph.KPort in project lingua-franca by lf-lang.
the class LinguaFrancaSynthesis method addIOPort.
/**
* Translate an input/output into a port.
*/
private KPort addIOPort(KNode node, PortInstance lfPort, boolean input, boolean multiport, boolean bank) {
KPort port = _kPortExtensions.createPort();
node.getPorts().add(port);
associateWith(port, lfPort.getDefinition());
NamedInstanceUtil.linkInstance(port, lfPort);
_kPortExtensions.setPortSize(port, 6, 6);
if (input) {
// multiports are smaller by an offset at the right, hence compensate in inputs
double offset = multiport ? -3.4 : -3.3;
setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST);
setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset);
} else {
// multiports are smaller
double offset = multiport ? -2.6 : -3.3;
// compensate bank figure width
offset = bank ? offset - LinguaFrancaShapeExtensions.BANK_FIGURE_X_OFFSET_SUM : offset;
setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST);
setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset);
}
if (bank && !node.getProperty(REACTOR_HAS_BANK_PORT_OFFSET)) {
// compensate bank figure height
// https://github.com/eclipse/elk/issues/693
_utilityExtensions.getPortMarginsInitIfAbsent(node).add(new ElkMargin(0, 0, LinguaFrancaShapeExtensions.BANK_FIGURE_Y_OFFSET_SUM, 0));
// only once
node.setProperty(REACTOR_HAS_BANK_PORT_OFFSET, true);
}
_linguaFrancaShapeExtensions.addTrianglePort(port, multiport);
String label = lfPort.getName();
if (!getBooleanValue(SHOW_PORT_NAMES)) {
label = "";
}
if (getBooleanValue(SHOW_MULTIPORT_WIDTH)) {
if (lfPort.isMultiport()) {
label += (lfPort.getWidth() >= 0) ? "[" + lfPort.getWidth() + "]" : "[?]";
}
}
associateWith(_kLabelExtensions.addOutsidePortLabel(port, label, 8), lfPort.getDefinition());
return port;
}
use of de.cau.cs.kieler.klighd.kgraph.KPort in project lingua-franca by lf-lang.
the class LinguaFrancaShapeExtensions method addActionFigureAndPorts.
/**
* Creates the triangular action node with text and ports.
*/
public Pair<KPort, KPort> addActionFigureAndPorts(KNode node, String text) {
final float size = 18;
_kNodeExtensions.setMinimalNodeSize(node, size, size);
KPolygon figure = _kRenderingExtensions.addPolygon(node);
_kRenderingExtensions.setBackground(figure, Colors.WHITE);
_linguaFrancaStyleExtensions.boldLineSelectionStyle(figure);
List<KPosition> pointsToAdd = List.of(_kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, BOTTOM, 0, 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0));
figure.getPoints().addAll(pointsToAdd);
// Add text to the action figure
KText textToAdd = _kContainerRenderingExtensions.addText(figure, text);
_kRenderingExtensions.setFontSize(textToAdd, 8);
_linguaFrancaStyleExtensions.noSelectionStyle(textToAdd);
DiagramSyntheses.suppressSelectability(textToAdd);
_kRenderingExtensions.setPointPlacementData(textToAdd, _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, (size * 0.15f), 0.5f, _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, size, size);
// Add input port
KPort in = _kPortExtensions.createPort();
node.getPorts().add(in);
in.setSize(0, 0);
DiagramSyntheses.setLayoutOption(in, CoreOptions.PORT_SIDE, PortSide.WEST);
DiagramSyntheses.setLayoutOption(in, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4));
// Add output port
KPort out = _kPortExtensions.createPort();
node.getPorts().add(out);
DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_SIDE, PortSide.EAST);
DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4));
return new Pair<KPort, KPort>(in, out);
}
Aggregations