Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into let-inference
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Jul 12, 2022
2 parents 04d73d5 + 2f62939 commit 8062383
Show file tree
Hide file tree
Showing 31 changed files with 958 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis<Model> {
/** Synthesis category */
public static final SynthesisOption APPEARANCE = SynthesisOption.createCategory("Appearance", true);
public static final SynthesisOption EXPERIMENTAL = SynthesisOption.createCategory("Experimental", true);
public static final SynthesisOption LAYOUT = SynthesisOption.createCategory("Layout", false).setCategory(LinguaFrancaSynthesis.APPEARANCE);

/** Synthesis options */
public static final SynthesisOption SHOW_ALL_REACTORS = SynthesisOption.createCheckOption("All Reactors", false);
Expand All @@ -211,6 +212,8 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis<Model> {
public static final SynthesisOption SHOW_STATE_VARIABLES = SynthesisOption.createCheckOption("Reactor State Variables", false).setCategory(APPEARANCE);
public static final SynthesisOption REACTOR_BODY_TABLE_COLS = SynthesisOption.<Integer>createRangeOption("Reactor Parameter/Variable Columns", 1, 10, 1).setCategory(APPEARANCE);

public static final SynthesisOption SPACING = SynthesisOption.<Integer>createRangeOption("Spacing (%)", 0, 150, 5, 75).setCategory(LAYOUT);

/** Synthesis actions */
public static final DisplayedActionData COLLAPSE_ALL = DisplayedActionData.create(CollapseAllReactorsAction.ID, "Hide all Details");
public static final DisplayedActionData EXPAND_ALL = DisplayedActionData.create(ExpandAllReactorsAction.ID, "Show all Details");
Expand Down Expand Up @@ -240,8 +243,9 @@ public List<SynthesisOption> getDisplayedSynthesisOptions() {
REACTOR_PARAMETER_MODE,
SHOW_STATE_VARIABLES,
REACTOR_BODY_TABLE_COLS,
LayoutPostProcessing.LAYOUT_CATEGORY,
LayoutPostProcessing.MODEL_ORDER
LAYOUT,
LayoutPostProcessing.MODEL_ORDER,
SPACING
);
}

Expand Down Expand Up @@ -395,20 +399,7 @@ private Collection<KNode> createReactorNode(
allReactorNodes));
}
Iterables.addAll(nodes, createUserComments(reactor, node));
configureReactorNodeLayout(node);

// Additional layout adjustment for main node
setLayoutOption(node, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
setLayoutOption(node, CoreOptions.DIRECTION, Direction.RIGHT);
setLayoutOption(node, CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.MINIMUM_SIZE));
setLayoutOption(node, LayeredOptions.NODE_PLACEMENT_BK_FIXED_ALIGNMENT, FixedAlignment.BALANCED);
setLayoutOption(node, LayeredOptions.NODE_PLACEMENT_BK_EDGE_STRAIGHTENING, EdgeStraighteningStrategy.IMPROVE_STRAIGHTNESS);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE, LayeredOptions.SPACING_EDGE_NODE.getDefault() * 1.1f);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS.getDefault() * 1.1f);
if (!getBooleanValue(SHOW_HYPERLINKS)) {
setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(-1, 6, 6, 6));
setLayoutOption(node, LayeredOptions.SPACING_COMPONENT_COMPONENT, LayeredOptions.SPACING_COMPONENT_COMPONENT.getDefault() * 0.5f);
}
configureReactorNodeLayout(node, true);
_layoutPostProcessing.configureMainReactor(node);
} else {
ReactorInstance instance = reactorInstance;
Expand Down Expand Up @@ -582,7 +573,7 @@ private Collection<KNode> createReactorNode(
} else {
Iterables.addAll(nodes, createUserComments(reactor, node));
}
configureReactorNodeLayout(node);
configureReactorNodeLayout(node, false);
_layoutPostProcessing.configureReactor(node);
}

Expand All @@ -598,28 +589,54 @@ private Collection<KNode> createReactorNode(
return nodes;
}

private KNode configureReactorNodeLayout(KNode node) {
// Direction
public KNode configureReactorNodeLayout(KNode node, boolean main) {
// Set layered algorithm
setLayoutOption(node, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
// Left to right layout
setLayoutOption(node, CoreOptions.DIRECTION, Direction.RIGHT);
// Center free floating children
setLayoutOption(node, CoreOptions.CONTENT_ALIGNMENT, ContentAlignment.centerCenter());

// Balanced placement with straight long edges.
setLayoutOption(node, LayeredOptions.NODE_PLACEMENT_STRATEGY, NodePlacementStrategy.NETWORK_SIMPLEX);
// Do not shrink nodes below content
setLayoutOption(node, CoreOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.minimumSizeWithPorts());
setLayoutOption(node, CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.MINIMUM_SIZE, SizeConstraint.PORTS));

// Allows to freely shuffle ports on each side
setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE);
// Adjust port label spacing to be closer to edge but not overlap with port figure
setLayoutOption(node, CoreOptions.PORT_LABELS_PLACEMENT, EnumSet.of(PortLabelPlacement.ALWAYS_OTHER_SAME_SIDE, PortLabelPlacement.OUTSIDE, PortLabelPlacement.NEXT_TO_PORT_IF_POSSIBLE));
// TODO: Add PortLabelPlacement.NEXT_TO_PORT_IF_POSSIBLE back into the configuration, as soon as ELK provides a fix for LF issue #1273
setLayoutOption(node, CoreOptions.PORT_LABELS_PLACEMENT, EnumSet.of(PortLabelPlacement.ALWAYS_OTHER_SAME_SIDE, PortLabelPlacement.OUTSIDE));
setLayoutOption(node, CoreOptions.SPACING_LABEL_PORT_HORIZONTAL, 2.0);
setLayoutOption(node, CoreOptions.SPACING_LABEL_PORT_VERTICAL, -3.0);
// Balanced placement with straight long edges.
setLayoutOption(node, LayeredOptions.NODE_PLACEMENT_STRATEGY, NodePlacementStrategy.NETWORK_SIMPLEX);
if (!getBooleanValue(SHOW_HYPERLINKS)) {
setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(2, 6, 6, 6));
setLayoutOption(node, LayeredOptions.SPACING_NODE_NODE, LayeredOptions.SPACING_NODE_NODE.getDefault() * 0.75f);
setLayoutOption(node, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS.getDefault() * 0.75f);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE, LayeredOptions.SPACING_EDGE_NODE.getDefault() * 0.75f);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS.getDefault() * 0.75f);

// Configure spacing
if (!getBooleanValue(SHOW_HYPERLINKS)) { // Hyperlink version is more relaxed in terms of space
var factor = (double) getIntValue(SPACING) / 100;

setLayoutOption(node, LayeredOptions.SPACING_COMPONENT_COMPONENT, LayeredOptions.SPACING_COMPONENT_COMPONENT.getDefault() * factor);

setLayoutOption(node, LayeredOptions.SPACING_NODE_NODE, LayeredOptions.SPACING_NODE_NODE.getDefault() * factor);
setLayoutOption(node, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS.getDefault() * factor);

setLayoutOption(node, LayeredOptions.SPACING_PORT_PORT, LayeredOptions.SPACING_PORT_PORT.getDefault() * factor);

setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE, LayeredOptions.SPACING_EDGE_NODE.getDefault() * factor);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS.getDefault() * factor);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE, LayeredOptions.SPACING_EDGE_EDGE.getDefault() * factor);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS.getDefault() * factor);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE, LayeredOptions.SPACING_EDGE_EDGE.getDefault() * factor);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS.getDefault() * factor);
setLayoutOption(node, LayeredOptions.SPACING_EDGE_LABEL, LayeredOptions.SPACING_EDGE_LABEL.getDefault() * factor);

// Padding for sub graph
if (main) { // Special handing for main reactors
setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(-1, 6, 6, 6));
} else {
setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(2, 6, 6, 6));
}
}

return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@
***************/
package org.lflang.diagram.synthesis.action;

import java.util.WeakHashMap;

import org.lflang.diagram.synthesis.util.InterfaceDependenciesVisualization;
import org.lflang.diagram.synthesis.util.NamedInstanceUtil;
import org.lflang.generator.NamedInstance;
import org.lflang.generator.ReactorInstance;

import com.google.common.base.Preconditions;

import de.cau.cs.kieler.klighd.IAction;
import de.cau.cs.kieler.klighd.IViewer;
import de.cau.cs.kieler.klighd.SynthesisOption;
import de.cau.cs.kieler.klighd.ViewContext;
import de.cau.cs.kieler.klighd.kgraph.KNode;
import java.util.WeakHashMap;
import org.lflang.diagram.synthesis.util.InterfaceDependenciesVisualization;
import org.lflang.diagram.synthesis.util.NamedInstanceUtil;
import org.lflang.generator.NamedInstance;

/**
* Action for toggling collapse/expand state of reactors that memorizes the state and
Expand Down Expand Up @@ -108,7 +112,7 @@ public IAction.ActionResult execute(final IAction.ActionContext context) {
linkedInstance = NamedInstanceUtil.getLinkedInstance(node);
}

if (node == null) {
if (node == null || (linkedInstance instanceof ReactorInstance && ((ReactorInstance) linkedInstance).isMainOrFederated())) {
return IAction.ActionResult.createResult(false);
} else {
setExpansionState(node, linkedInstance, v, !v.isExpanded(node)); // toggle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
@ViewSynthesisShared
public class LayoutPostProcessing extends AbstractSynthesisExtensions {

/** The synthesis option category for layout options. */
public static final SynthesisOption LAYOUT_CATEGORY =
SynthesisOption.createCategory("Layout", false).setCategory(LinguaFrancaSynthesis.APPEARANCE);

/** Synthesis option to control the order of nodes and edges by model order. */
public static final String MODEL_ORDER_OPTION = "Model Order";
/** Uses semi-automatic layout. */
Expand All @@ -79,7 +75,7 @@ public class LayoutPostProcessing extends AbstractSynthesisExtensions {
SynthesisOption.createChoiceOption(
MODEL_ORDER_OPTION,
Arrays.asList(TIE_BREAKER, STRICT_REACTION_ONLY, STRICT, FULL_CONTROL),
STRICT_REACTION_ONLY).setCategory(LAYOUT_CATEGORY);
STRICT_REACTION_ONLY).setCategory(LinguaFrancaSynthesis.LAYOUT);

/**
* Comparator to sort KNodes based on the textual order of their linked instances.
Expand Down
Loading

0 comments on commit 8062383

Please sign in to comment.