diff options
author | Jayant Gupta | 2014-06-01 20:49:16 +0000 |
---|---|---|
committer | Jayant Gupta | 2014-06-05 06:32:18 +0000 |
commit | afe75c5565ecdb66f4feaf1487b4a2f124f5ffd2 (patch) | |
tree | 8b5e30985fb6d1bb9231969ef2bf0fb3d451e5fb | |
parent | 43973e0a96610e859727d62542df758f0bb7daee (diff) | |
download | org.eclipse.etrice-afe75c5565ecdb66f4feaf1487b4a2f124f5ffd2.tar.gz org.eclipse.etrice-afe75c5565ecdb66f4feaf1487b4a2f124f5ffd2.tar.xz org.eclipse.etrice-afe75c5565ecdb66f4feaf1487b4a2f124f5ffd2.zip |
[ui.layout] Improvements in KIELER Layout
1. Fixes Bug 402888: misplaced ports after auto-layout
https://bugs.eclipse.org/402888
2. Fixes Bug 403097: misplaced SPP after auto layout
https://bugs.eclipse.org/403097
3. Fixes Bug 403033: misplaced transition points after auto-layout
https://bugs.eclipse.org/403033
4. Fixes use of insets in setting diagram elements positions.
5. Improves label dependent heuristics for actor size.
Change-Id: If3e0c1843deb424d5758ffa4e30ccde6ccb30a1b
Signed-off-by: Jayant Gupta <gsocjayant@gmail.com>
4 files changed, 78 insertions, 18 deletions
diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java index d2eca0848..9efa85fd8 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java @@ -18,7 +18,6 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.etrice.core.room.State; import org.eclipse.etrice.ui.behavior.support.TrPointSupport; import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.impl.LayoutContext; import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; import org.eclipse.graphiti.mm.algorithms.Text; import org.eclipse.graphiti.mm.algorithms.styles.Orientation; @@ -54,9 +53,6 @@ public class BehaviorLayoutCommand extends ETriceLayoutCommand { protected void applyNodeLayout(KNode knode, PictogramElement pelem) { setCalculatedPositionAndSize(knode, knode.getParent(), (ContainerShape) pelem); - - getFeatureProvider().layoutIfPossible(new LayoutContext(pelem)); - }; /** @@ -87,9 +83,6 @@ public class BehaviorLayoutCommand extends ETriceLayoutCommand { Text label = (Text) (shape.getChildren().get(0).getGraphicsAlgorithm()); adjustLabel(label, ga.getX(), ga.getY(), ga.getWidth(), margin, size); - - getFeatureProvider().layoutIfPossible(new LayoutContext(shape)); - } /** diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java index aeab7bb3d..62ef94afa 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java @@ -548,20 +548,27 @@ public abstract class ETriceDiagramLayoutManager extends Shape shape) { // get label width and height for the node + // these would be added to the node width and height float labelWidth = 0.0f; float labelHeight = 0.0f; if (!node.getLabels().isEmpty()) { KShapeLayout labelLayout = node.getLabels().get(0) .getData(KShapeLayout.class); - labelWidth = labelLayout.getWidth(); - labelHeight = labelLayout.getHeight(); + // halh of the label width is taken to avoid too much widening of + // node due to labels + labelWidth = labelLayout.getWidth() * 0.5f; } + Dimension defaultSize = getDefaultSize(shape); + float ratio = (float) defaultSize.height() / defaultSize.width(); + // label height is not the original label height but the increase is + // node height due to label; it is in ratio with the increase in label + // width. + labelHeight = ratio * labelWidth; + VolatileLayoutConfig staticConfig = mapping .getProperty(KimlGraphitiUtil.STATIC_CONFIG); - - Dimension defaultSize = getDefaultSize(shape); staticConfig.setValue(LayoutOptions.MIN_WIDTH, node, LayoutContext.GRAPH_ELEM, defaultSize.width() + labelWidth); staticConfig.setValue(LayoutOptions.MIN_HEIGHT, node, diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceLayoutCommand.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceLayoutCommand.java index c49940a70..26b0048cf 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceLayoutCommand.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceLayoutCommand.java @@ -13,12 +13,15 @@ package org.eclipse.etrice.ui.layout; +import java.util.LinkedList; import java.util.List; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.graphiti.features.IFeatureProvider; +import org.eclipse.graphiti.features.context.impl.LayoutContext; import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; import org.eclipse.graphiti.mm.algorithms.styles.Point; +import org.eclipse.graphiti.mm.pictograms.Anchor; import org.eclipse.graphiti.mm.pictograms.ContainerShape; import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; import org.eclipse.graphiti.mm.pictograms.PictogramElement; @@ -31,9 +34,11 @@ import de.cau.cs.kieler.core.kgraph.KNode; import de.cau.cs.kieler.core.kgraph.KPort; import de.cau.cs.kieler.core.math.KVector; import de.cau.cs.kieler.core.math.KVectorChain; +import de.cau.cs.kieler.core.util.Pair; import de.cau.cs.kieler.kiml.graphiti.GraphitiLayoutCommand; import de.cau.cs.kieler.kiml.klayoutdata.KInsets; import de.cau.cs.kieler.kiml.klayoutdata.KShapeLayout; +import de.cau.cs.kieler.kiml.klayoutdata.impl.KShapeLayoutImpl; /** * An abstract class to support creation of commands for applying the result of @@ -44,12 +49,73 @@ import de.cau.cs.kieler.kiml.klayoutdata.KShapeLayout; */ public abstract class ETriceLayoutCommand extends GraphitiLayoutCommand { + /** list of graph elements(nodes & ports) and pictogram elements to layout. */ + private List<Pair<KGraphElement, PictogramElement>> elements = + new LinkedList<Pair<KGraphElement, PictogramElement>>(); + public ETriceLayoutCommand(TransactionalEditingDomain domain, IFeatureProvider thefeatureProvider) { super(domain, thefeatureProvider); } /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + public void add(KGraphElement graphElement, + PictogramElement pictogramElement) { + + super.add(graphElement, pictogramElement); + + // Prepare a local list of modified nodes and ports. + // This list is used in doExecute() method below. + if (graphElement instanceof KPort || graphElement instanceof KNode) { + KShapeLayoutImpl shapeLayout = graphElement + .getData(KShapeLayoutImpl.class); + if (shapeLayout.isModified()) { + elements.add(new Pair<KGraphElement, PictogramElement>( + graphElement, pictogramElement)); + } + } + } + + /** + * {@inheritDoc} + * + * @author jayant + */ + @Override + protected void doExecute() { + super.doExecute(); + + /* + * Re-layout diagram elements according to eTrice after performing + * complete KIELER Layout. + * + * Note: This operation needs to be carried after completing the KIELER + * layout since eTrice positioning depend not only on current diagram + * element but also on the parameters of its parent element. + */ + for (Pair<KGraphElement, PictogramElement> entry : elements) { + KGraphElement element = entry.getFirst(); + if (element instanceof KPort) { + PictogramElement pelem = ((Anchor) entry.getSecond()) + .getParent(); + getFeatureProvider().layoutIfPossible(new LayoutContext(pelem)); + } else if (element instanceof KNode) { + PictogramElement pelem = entry.getSecond(); + getFeatureProvider().layoutIfPossible(new LayoutContext(pelem)); + } + } + + // refresh the diagram editor after re-placement by eTrice. + getFeatureProvider().getDiagramTypeProvider().getDiagramBehavior() + .refresh(); + } + + /** * {@inheritDoc} Also responsible for the layout of internal ports in eTrice * (which are considered as KNodes) * @@ -129,7 +195,7 @@ public abstract class ETriceLayoutCommand extends GraphitiLayoutCommand { .getProperty(INVIS_INSETS); if (parentInsets != null) { xpos += parentInsets.getLeft(); - ypos += parentInsets.getRight(); + ypos += parentInsets.getTop(); } } diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureLayoutCommand.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureLayoutCommand.java index 14e9c9e3d..72b7a8526 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureLayoutCommand.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/StructureLayoutCommand.java @@ -19,7 +19,6 @@ import org.eclipse.etrice.core.room.ActorContainerRef; import org.eclipse.etrice.core.room.InterfaceItem; import org.eclipse.etrice.ui.structure.support.InterfaceItemSupport; import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.impl.LayoutContext; import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; import org.eclipse.graphiti.mm.algorithms.Text; import org.eclipse.graphiti.mm.algorithms.styles.Orientation; @@ -63,9 +62,6 @@ public class StructureLayoutCommand extends ETriceLayoutCommand { // adjust label for internal port adjustLabelForPort((ContainerShape) pelem); } - - getFeatureProvider().layoutIfPossible(new LayoutContext(pelem)); - }; /** @@ -82,8 +78,6 @@ public class StructureLayoutCommand extends ETriceLayoutCommand { // adjust label for this (boundary)port adjustLabelForPort(shape); - - getFeatureProvider().layoutIfPossible(new LayoutContext(shape)); } /** |