use of org.eclipse.elk.core.math.ElkPadding in project lingua-franca by lf-lang.
the class LinguaFrancaStyleExtensions method applyOnEdgePysicalDelayStyle.
public void applyOnEdgePysicalDelayStyle(KLabel label, Colors parentBackgroundColor) {
if (_onEdgePysicalDelayLabelConfigurator == null) {
LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true);
configurator = configurator.withLabelTextRenderingProvider((KContainerRendering container, KLabel klabel) -> {
KText kText = _kRenderingFactory.createKText();
_kRenderingExtensions.setFontSize(kText, 8);
boldTextSelectionStyle(kText);
kText.setProperty(KlighdInternalProperties.MODEL_ELEMEMT, klabel.getProperty(KlighdInternalProperties.MODEL_ELEMEMT));
container.getChildren().add(kText);
return kText;
});
configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() {
@Override
public ElkPadding createDecoratorRendering(KContainerRendering container, KLabel label, LabelDecorationConfigurator.LayoutMode layoutMode) {
ElkPadding padding = new ElkPadding();
padding.left = 8;
padding.right = 16;
padding.bottom = Math.max(padding.bottom, 1);
KPolygon polygon = _kRenderingFactory.createKPolygon();
_kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f);
_kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f);
_kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.setBackground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
_kRenderingExtensions.setForeground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
container.getChildren().add(polygon);
KSpline kSpline = _kRenderingFactory.createKSpline();
_kRenderingExtensions.from(kSpline, LEFT, -0.66f, 0, BOTTOM, -0.5f, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, -0.5f, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 3, 0, BOTTOM, 8, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 5, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 5.5f, 0, BOTTOM, -1.5f, 0.5f);
container.getChildren().add(kSpline);
kSpline = _kRenderingFactory.createKSpline();
_kRenderingExtensions.from(kSpline, RIGHT, 15f, 0, BOTTOM, 3.5f, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 14f, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 11, 0, BOTTOM, -8, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 9, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 7, 0, BOTTOM, 8, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 4f, 0, BOTTOM, 2, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 1.5f, 0, BOTTOM, 0.5f, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 0.2f, 0, BOTTOM, -0.5f, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, -0.7f, 0, BOTTOM, -0.5f, 0.5f);
container.getChildren().add(kSpline);
polygon = _kRenderingFactory.createKPolygon();
_kRenderingExtensions.from(polygon, LEFT, 4, 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polygon, LEFT, 8, 0, TOP, 0, 0);
_kRenderingExtensions.to(polygon, RIGHT, 12, 0, TOP, 0, 0);
_kRenderingExtensions.to(polygon, RIGHT, 16, 0, BOTTOM, 0, 0);
_kRenderingExtensions.setBackground(polygon, Colors.WHITE);
_kRenderingExtensions.setForeground(polygon, Colors.WHITE);
container.getChildren().add(polygon);
KPolyline polyline = _kRenderingFactory.createKPolyline();
_kRenderingExtensions.from(polyline, LEFT, 4, 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polyline, LEFT, 8, 0, TOP, 0, 0);
container.getChildren().add(polyline);
polyline = _kRenderingFactory.createKPolyline();
_kRenderingExtensions.from(polyline, RIGHT, 16, 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polyline, RIGHT, 12, 0, TOP, 0, 0);
container.getChildren().add(polyline);
return padding;
}
});
_onEdgePysicalDelayLabelConfigurator = configurator;
}
label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor);
_onEdgePysicalDelayLabelConfigurator.applyTo(label);
}
use of org.eclipse.elk.core.math.ElkPadding in project lingua-franca by lf-lang.
the class LinguaFrancaStyleExtensions method applyOnEdgePysicalStyle.
public void applyOnEdgePysicalStyle(KLabel label, Colors parentBackgroundColor) {
if (_onEdgePysicalLabelConfigurator == null) {
LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true);
configurator = configurator.withLabelTextRenderingProvider((KContainerRendering container, KLabel klabel) -> {
KText kText = _kRenderingFactory.createKText();
_kRenderingExtensions.setInvisible(kText, true);
container.getChildren().add(kText);
return kText;
});
configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() {
@Override
public ElkPadding createDecoratorRendering(final KContainerRendering container, final KLabel label, final LabelDecorationConfigurator.LayoutMode layoutMode) {
ElkPadding padding = new ElkPadding();
padding.left = 3;
padding.right = 3;
padding.bottom = Math.max(padding.bottom, 1);
KPolygon polygon = _kRenderingFactory.createKPolygon();
_kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f);
_kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f);
_kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.setBackground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
_kRenderingExtensions.setForeground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
container.getChildren().add(polygon);
KSpline kSpline = _kRenderingFactory.createKSpline();
_kRenderingExtensions.from(kSpline, LEFT, (-0.66f), 0, BOTTOM, (-0.5f), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, (-0.5f), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.1f, BOTTOM, 8, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.2f, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.3f, BOTTOM, (-8), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.4f, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.45f, BOTTOM, 4f, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.5f, BOTTOM, 8, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.55f, BOTTOM, 4f, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.6f, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.65f, BOTTOM, (-4), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.7f, BOTTOM, (-8), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.8f, BOTTOM, (-4), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.9f, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, (-1), 1, BOTTOM, (-0.5f), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0.66f, 1, BOTTOM, (-0.5f), 0.5f);
container.getChildren().add(kSpline);
return padding;
}
});
_onEdgePysicalLabelConfigurator = configurator;
}
label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor);
_onEdgePysicalLabelConfigurator.applyTo(label);
}
use of org.eclipse.elk.core.math.ElkPadding in project lingua-franca by lf-lang.
the class LinguaFrancaSynthesis method transform.
// -------------------------------------------------------------------------
@Override
public KNode transform(final Model model) {
KNode rootNode = _kNodeExtensions.createNode();
try {
// Find main
Reactor main = IterableExtensions.findFirst(model.getReactors(), _utilityExtensions::isMainOrFederated);
if (main != null) {
ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter());
rootNode.getChildren().addAll(createReactorNode(reactorInstance, true, null, null, new HashMap<>()));
} else {
KNode messageNode = _kNodeExtensions.createNode();
_linguaFrancaShapeExtensions.addErrorMessage(messageNode, TEXT_NO_MAIN_REACTOR, null);
rootNode.getChildren().add(messageNode);
}
// Show all reactors
if (main == null || getBooleanValue(SHOW_ALL_REACTORS)) {
List<KNode> reactorNodes = new ArrayList<>();
for (Reactor reactor : model.getReactors()) {
if (reactor == main)
continue;
ReactorInstance reactorInstance = new ReactorInstance(reactor, new SynthesisErrorReporter(), new HashSet<>());
reactorNodes.addAll(createReactorNode(reactorInstance, main == null, HashBasedTable.<ReactorInstance, PortInstance, KPort>create(), HashBasedTable.<ReactorInstance, PortInstance, KPort>create(), new HashMap<>()));
}
if (!reactorNodes.isEmpty()) {
// To allow ordering, we need box layout but we also need layered layout for ports thus wrap all node
// TODO use rect packing in the future
reactorNodes.add(0, IterableExtensions.head(rootNode.getChildren()));
int index = 0;
for (KNode node : reactorNodes) {
if (node.getProperty(CoreOptions.COMMENT_BOX))
continue;
KNode child = _kNodeExtensions.createNode();
child.getChildren().add(node);
// Add comment nodes
for (KEdge edge : node.getIncomingEdges()) {
if (!edge.getSource().getProperty(CoreOptions.COMMENT_BOX))
continue;
child.getChildren().add(edge.getSource());
}
_kRenderingExtensions.addInvisibleContainerRendering(child);
setLayoutOption(child, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
setLayoutOption(child, CoreOptions.PADDING, new ElkPadding(0));
// Order!
setLayoutOption(child, CoreOptions.PRIORITY, reactorNodes.size() - index);
rootNode.getChildren().add(child);
index++;
}
setLayoutOption(rootNode, CoreOptions.ALGORITHM, BoxLayouterOptions.ALGORITHM_ID);
setLayoutOption(rootNode, CoreOptions.SPACING_NODE_NODE, 25.0);
}
}
} catch (Exception e) {
e.printStackTrace();
KNode messageNode = _kNodeExtensions.createNode();
_linguaFrancaShapeExtensions.addErrorMessage(messageNode, "Error in Diagram Synthesis", e.getClass().getSimpleName() + " occurred. Could not create diagram.");
rootNode.getChildren().add(messageNode);
}
return rootNode;
}
use of org.eclipse.elk.core.math.ElkPadding in project sirius-components by eclipse-sirius.
the class NodeLabelPositionProvider method getVerticalPosition.
private double getVerticalPosition(NodeLayoutData node, LabelLayoutData label) {
double y = 0d;
EnumSet<NodeLabelPlacement> nodeLabelPlacementSet = this.layoutConfigurator.configureByType(node.getNodeType()).getProperty(CoreOptions.NODE_LABELS_PLACEMENT);
ElkPadding nodeLabelsPadding = this.layoutConfigurator.configureByType(node.getNodeType()).getProperty(CoreOptions.NODE_LABELS_PADDING);
boolean outside = this.isOutside(nodeLabelPlacementSet);
double topPadding = 0d;
double bottomPadding = 0d;
if (nodeLabelsPadding == null) {
nodeLabelsPadding = CoreOptions.NODE_LABELS_PADDING.getDefault();
}
topPadding = nodeLabelsPadding.getTop();
bottomPadding = nodeLabelsPadding.getBottom();
for (NodeLabelPlacement nodeLabelPlacement : nodeLabelPlacementSet) {
switch(nodeLabelPlacement) {
case V_TOP:
if (outside) {
y = -(label.getTextBounds().getSize().getHeight()) - topPadding;
} else {
y = topPadding;
}
break;
case V_CENTER:
y = (node.getSize().getHeight() - label.getTextBounds().getSize().getHeight()) / 2;
break;
case V_BOTTOM:
if (outside) {
y = -(label.getTextBounds().getSize().getHeight());
} else {
y = node.getSize().getHeight() - label.getTextBounds().getSize().getHeight() - bottomPadding;
}
break;
default:
break;
}
}
return y;
}
use of org.eclipse.elk.core.math.ElkPadding in project sirius-components by eclipse-sirius.
the class LayoutConfiguratorRegistry method getDefaultLayoutConfigurator.
public ISiriusWebLayoutConfigurator getDefaultLayoutConfigurator() {
// @formatter:off
SiriusWebLayoutConfigurator configurator = new SiriusWebLayoutConfigurator();
configurator.configureByType(ELKDiagramConverter.DEFAULT_DIAGRAM_TYPE).setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID).setProperty(CoreOptions.HIERARCHY_HANDLING, HierarchyHandling.INCLUDE_CHILDREN).setProperty(LayeredOptions.LAYERING_STRATEGY, LayeringStrategy.NETWORK_SIMPLEX).setProperty(LayeredOptions.SPACING_NODE_NODE, SPACING_NODE_NODE).setProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, SPACING_NODE_NODE).setProperty(LayeredOptions.SPACING_EDGE_NODE, SPACING_NODE_EDGE).setProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, SPACING_NODE_EDGE);
configurator.configureByType(NodeType.NODE_RECTANGLE).setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.free()).setProperty(CoreOptions.NODE_SIZE_OPTIONS, EnumSet.of(SizeOptions.ASYMMETRICAL)).setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(LayoutOptionValues.MIN_WIDTH_CONSTRAINT, LayoutOptionValues.MIN_HEIGHT_CONSTRAINT)).setProperty(CoreOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter()).setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(MIN_WIDTH_CONSTRAINT, MIN_HEIGHT_CONSTRAINT)).setProperty(CoreOptions.PORT_BORDER_OFFSET, DEFAULT_PORT_BORDER_OFFSET).setProperty(CoreOptions.PORT_LABELS_PLACEMENT, PortLabelPlacement.outside());
configurator.configureByType(NodeType.NODE_LIST).setProperty(CoreOptions.ALGORITHM, FixedLayouterOptions.ALGORITHM_ID).setProperty(CoreOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter()).setProperty(CoreOptions.NODE_SIZE_FIXED_GRAPH_SIZE, true).setProperty(CoreOptions.PORT_BORDER_OFFSET, DEFAULT_PORT_BORDER_OFFSET);
configurator.configureByType(NodeType.NODE_LIST_ITEM).setProperty(CoreOptions.NO_LAYOUT, true).setProperty(CoreOptions.NODE_LABELS_PADDING, new ElkPadding(0d, 12d, 0d, 6d));
configurator.configureByType(NodeType.NODE_IMAGE).setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.MINIMUM_SIZE, SizeConstraint.PORT_LABELS, SizeConstraint.PORTS)).setProperty(CoreOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.outsideTopCenter()).setProperty(CoreOptions.PORT_BORDER_OFFSET, DEFAULT_PORT_BORDER_OFFSET);
// This image type does not match any diagram item. We add it to define the image size as constraint for the node image parent.
configurator.configureByType(ELKDiagramConverter.DEFAULT_IMAGE_TYPE).setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.fixed());
configurator.configure(ElkEdge.class).setProperty(CoreOptions.SPACING_EDGE_LABEL, 3d);
return configurator;
}
Aggregations