Skip to content

Commit

Permalink
Merge pull request #1241 from lf-lang/diagram-reset-symbols
Browse files Browse the repository at this point in the history
Adjust reset symbols in diagrams
  • Loading branch information
lhstrh authored Jul 1, 2022
2 parents 6e83beb + 63316f8 commit 2a8ef20
Showing 2 changed files with 179 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1140,7 +1140,7 @@ private String createReactorLabel(ReactorInstance reactorInstance) {
} else {
b.append(IterableExtensions.join(reactorInstance.parameters, "(", ", ", ")",
it -> {
return createParameterLabel(it, false);
return createParameterLabel(it);
}));
}
}
@@ -1157,18 +1157,14 @@ private void addParameterList(KContainerRendering container, List<ParameterInsta
}
_kContainerRenderingExtensions.setGridPlacement(container, cols);
for (ParameterInstance param : parameters) {
KText paramText = _kContainerRenderingExtensions.addText(container, createParameterLabel(param, true));
_kRenderingExtensions.setFontSize(paramText, 8);
_kRenderingExtensions.setHorizontalAlignment(paramText, HorizontalAlignment.LEFT);
_kRenderingExtensions.setSurroundingSpaceGrid(paramText, 2, 0, 0, 0);
var entry = _linguaFrancaShapeExtensions.addParameterEntry(
container, param.getDefinition(), createParameterLabel(param));
_kRenderingExtensions.setHorizontalAlignment(entry, HorizontalAlignment.LEFT);
}
}

private String createParameterLabel(ParameterInstance param, boolean bullet) {
private String createParameterLabel(ParameterInstance param) {
StringBuilder b = new StringBuilder();
if (bullet) {
b.append("\u2009\u2219\u2009\u2009"); // aligned spacing with state variables
}
b.append(param.getName());
String t = param.type.toOriginalText();
if (!StringExtensions.isNullOrEmpty(t)) {
@@ -1192,25 +1188,14 @@ public void addStateVariableList(KContainerRendering container, List<StateVar> v
}
_kContainerRenderingExtensions.setGridPlacement(container, cols);
for (var variable : variables) {
KText varText = _kContainerRenderingExtensions.addText(container, createStateVariableLabel(variable, true));
_kRenderingExtensions.setFontSize(varText, 8);
_kRenderingExtensions.setHorizontalAlignment(varText, HorizontalAlignment.LEFT);
_kRenderingExtensions.setSurroundingSpaceGrid(varText, 2, 0, 0, 0);
associateWith(varText, variable);
var entry = _linguaFrancaShapeExtensions.addStateEntry(
container, variable, createStateVariableLabel(variable), variable.isReset());
_kRenderingExtensions.setHorizontalAlignment(entry, HorizontalAlignment.LEFT);
}
}

private String createStateVariableLabel(StateVar variable, boolean bullet) {
private String createStateVariableLabel(StateVar variable) {
StringBuilder b = new StringBuilder();
if (bullet) {
b.append("\u229a");
// Reset marker
if (variable.isReset()) {
b.append("\u1d63\u200a");
} else {
b.append("\u2009\u2009");
}
}
b.append(variable.getName());
if (variable.getType() != null) {
var t = InferredType.fromAST(variable.getType());
Original file line number Diff line number Diff line change
@@ -24,6 +24,34 @@
***************/
package org.lflang.diagram.synthesis.styles;

import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX.LEFT;
import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX.RIGHT;
import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY.BOTTOM;
import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY.TOP;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.core.options.PortSide;
import org.eclipse.elk.graph.properties.Property;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.lflang.ASTUtils;
import org.lflang.diagram.synthesis.AbstractSynthesisExtensions;
import org.lflang.diagram.synthesis.LinguaFrancaSynthesis;
import org.lflang.diagram.synthesis.util.UtilityExtensions;
import org.lflang.generator.ReactionInstance;
import org.lflang.generator.ReactorInstance;
import org.lflang.generator.TimerInstance;
import org.lflang.lf.Parameter;
import org.lflang.lf.StateVar;

import de.cau.cs.kieler.klighd.KlighdConstants;
import de.cau.cs.kieler.klighd.kgraph.KEdge;
import de.cau.cs.kieler.klighd.kgraph.KNode;
@@ -56,30 +84,9 @@
import de.cau.cs.kieler.klighd.krendering.extensions.KPolylineExtensions;
import de.cau.cs.kieler.klighd.krendering.extensions.KPortExtensions;
import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions;
import de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.core.options.PortSide;
import org.eclipse.elk.graph.properties.Property;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.lflang.ASTUtils;
import org.lflang.diagram.synthesis.AbstractSynthesisExtensions;
import org.lflang.diagram.synthesis.LinguaFrancaSynthesis;
import org.lflang.diagram.synthesis.postprocessor.ReactionPortAdjustment;
import org.lflang.diagram.synthesis.util.UtilityExtensions;
import org.lflang.generator.ReactionInstance;
import org.lflang.generator.ReactorInstance;
import org.lflang.generator.TimerInstance;
import de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX;
import de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY;
import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX.*;
import static de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY.*;
import de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses;

/**
* Extension class that provides shapes and figures for the Lingua France diagram synthesis.
@@ -595,16 +602,39 @@ public KEllipse addResetFigure(KNode node) {
_linguaFrancaStyleExtensions.noSelectionStyle(figure);
_linguaFrancaStyleExtensions.boldLineSelectionStyle(figure);

KEllipse inner = _kContainerRenderingExtensions.addEllipse(figure);
_kRenderingExtensions.setSurroundingSpace(inner, 2.5f, 0);
_kRenderingExtensions.setLineWidth(inner, 1);
_kRenderingExtensions.setBackground(inner, Colors.WHITE);
_linguaFrancaStyleExtensions.noSelectionStyle(inner);

KText text = _kContainerRenderingExtensions.addText(inner, "R");
_kRenderingExtensions.setFontSize(text, 6);
_kRenderingExtensions.setFontBold(text, true);
_linguaFrancaStyleExtensions.boldTextSelectionStyle(text);
KEllipse resetCircle = _kContainerRenderingExtensions.addEllipse(figure);
_kRenderingExtensions.setSurroundingSpace(resetCircle, 3f, 0);
_kRenderingExtensions.setLineWidth(resetCircle, 1.5f);
_kRenderingExtensions.setBackground(resetCircle, Colors.WHITE);
_linguaFrancaStyleExtensions.noSelectionStyle(resetCircle);

var resetCycleGap = _kContainerRenderingExtensions.addPolygon(resetCircle);
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0, 0, PositionReferenceY.TOP, 0.0f, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 1.1f, 0, PositionReferenceY.BOTTOM, 0, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 1.1f, 0, PositionReferenceY.BOTTOM, 0, 0));
_kRenderingExtensions.setLineWidth(resetCycleGap, 0.3f);
_kRenderingExtensions.setForeground(resetCycleGap, Colors.WHITE);
_kRenderingExtensions.setBackground(resetCycleGap, Colors.WHITE);
_linguaFrancaStyleExtensions.noSelectionStyle(resetCycleGap);
_kRenderingExtensions.setPointPlacementData(resetCycleGap,
_kRenderingExtensions.LEFT, -2, 0.5f,
_kRenderingExtensions.TOP, 1.5f, 0,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 4.0f, 3.0f);

var resetArrow = _kContainerRenderingExtensions.addPolygon(resetCircle);
resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0.1f));
resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0.0f, 0.3f, PositionReferenceY.BOTTOM, 0, 0));
resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0.0f, 0, PositionReferenceY.TOP, 0.0f, 0.0f));
_kRenderingExtensions.setLineWidth(resetArrow, 0.3f);
_kRenderingExtensions.setBackground(resetArrow, Colors.BLACK);
_linguaFrancaStyleExtensions.noSelectionStyle(resetArrow);
_kRenderingExtensions.setPointPlacementData(resetArrow,
_kRenderingExtensions.LEFT, 1.0f, 0.5f,
_kRenderingExtensions.TOP, 1.8f, 0,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 3.2f, 3.2f);

return figure;
}
@@ -827,5 +857,112 @@ public KPolyline addCommentPolyline(KEdge edge) {
_kRenderingExtensions.setLineStyle(polyline, LineStyle.DOT);
return polyline;
}

public KContainerRendering addParameterEntry(KContainerRendering parent, Parameter associate, String text) {
KRectangle container = _kContainerRenderingExtensions.addRectangle(parent);
_kRenderingExtensions.setInvisible(container, true);

var ktext = _kContainerRenderingExtensions.addText(container, text);
_kRenderingExtensions.setFontSize(ktext, 8);
_kRenderingExtensions.setPointPlacementData(ktext,
_kRenderingExtensions.LEFT, 10, 0,
_kRenderingExtensions.TOP, 0, 0.5f,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 0, 0);
associateWith(ktext, associate);

var dot = _kContainerRenderingExtensions.addEllipse(container);
_kRenderingExtensions.setLineWidth(dot, 1);
_linguaFrancaStyleExtensions.noSelectionStyle(dot);
_kRenderingExtensions.setPointPlacementData(dot,
_kRenderingExtensions.LEFT, 2, 0,
_kRenderingExtensions.TOP, 0, 0.5f,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 5, 5);

return container;
}


public KContainerRendering addStateEntry(KContainerRendering parent, StateVar associate, String text, boolean reset) {
KRectangle container = _kContainerRenderingExtensions.addRectangle(parent);
_kRenderingExtensions.setInvisible(container, true);

var ktext = _kContainerRenderingExtensions.addText(container, text);
_kRenderingExtensions.setFontSize(ktext, 8);
_kRenderingExtensions.setPointPlacementData(ktext,
_kRenderingExtensions.LEFT, 10, 0,
_kRenderingExtensions.TOP, 0, 0.5f,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 0, 0);
associateWith(ktext, associate);

KEllipse outerCircle;

if (reset) {
outerCircle = _kContainerRenderingExtensions.addEllipse(container);
_kRenderingExtensions.setLineWidth(outerCircle, 0.9f);
_kRenderingExtensions.setBackground(outerCircle, Colors.WHITE);
_linguaFrancaStyleExtensions.noSelectionStyle(outerCircle);
_kRenderingExtensions.setPointPlacementData(outerCircle,
_kRenderingExtensions.LEFT, 1.5f, 0,
_kRenderingExtensions.TOP, 0, 0.5f,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 6.3f, 6.3f);

var resetCycleGap = _kContainerRenderingExtensions.addPolygon(outerCircle);
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.26f, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0.2f, PositionReferenceY.TOP, 0.1f, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0.5f, PositionReferenceY.TOP, 0.0f, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0, 0.2f, PositionReferenceY.TOP, 0.1f, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0, 0, PositionReferenceY.TOP, 0.26f, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0.5f, 0, PositionReferenceY.BOTTOM, 0, 0));
resetCycleGap.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0.5f, 0, PositionReferenceY.BOTTOM, 0, 0));
_kRenderingExtensions.setLineWidth(resetCycleGap, 0.3f);
_kRenderingExtensions.setForeground(resetCycleGap, Colors.WHITE);
_kRenderingExtensions.setBackground(resetCycleGap, Colors.WHITE);
_linguaFrancaStyleExtensions.noSelectionStyle(resetCycleGap);
_kRenderingExtensions.setPointPlacementData(resetCycleGap,
_kRenderingExtensions.LEFT, -1.2f, 0.5f,
_kRenderingExtensions.TOP, 0.75f, 0,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 2.5f, 1.3f);

var resetArrow = _kContainerRenderingExtensions.addPolygon(outerCircle);
resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0, 0, PositionReferenceY.TOP, 0.0f, 0.1f));
resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.LEFT, 0.0f, 0.3f, PositionReferenceY.BOTTOM, 0, 0));
resetArrow.getPoints().add(_kRenderingExtensions.createKPosition(PositionReferenceX.RIGHT, 0.0f, 0, PositionReferenceY.TOP, 0.0f, 0.0f));
_kRenderingExtensions.setLineWidth(resetArrow, 0.3f);
_kRenderingExtensions.setBackground(resetArrow, Colors.BLACK);
_linguaFrancaStyleExtensions.noSelectionStyle(resetArrow);
_kRenderingExtensions.setPointPlacementData(resetArrow,
_kRenderingExtensions.LEFT, 0.8f, 0.5f,
_kRenderingExtensions.TOP, 1.1f, 0,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 1.5f, 1.5f);
} else {
outerCircle = _kContainerRenderingExtensions.addEllipse(container);
_kRenderingExtensions.setLineWidth(outerCircle, 1);
_kRenderingExtensions.setBackground(outerCircle, Colors.WHITE);
_linguaFrancaStyleExtensions.noSelectionStyle(outerCircle);
_kRenderingExtensions.setPointPlacementData(outerCircle,
_kRenderingExtensions.LEFT, 1.5f, 0,
_kRenderingExtensions.TOP, 0, 0.5f,
_kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_CENTRAL,
0, 0, 6, 6);
}

var innerDot = _kContainerRenderingExtensions.addEllipse(outerCircle);
_kRenderingExtensions.setLineWidth(innerDot, 0.5f);
_kRenderingExtensions.setBackground(innerDot, Colors.BLACK);
_linguaFrancaStyleExtensions.noSelectionStyle(innerDot);
_kRenderingExtensions.setPointPlacementData(innerDot,
_kRenderingExtensions.LEFT, 0, 0.5f,
_kRenderingExtensions.TOP, 0, 0.5f,
_kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL,
0, 0, 2.5f, 2.5f);

return container;
}

}
}

0 comments on commit 2a8ef20

Please sign in to comment.