Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-05-10 16:37:18 +0000
committerHenrik Rentz-Reichert2012-05-10 16:37:18 +0000
commitbf0d690b86e9b4db18abe3eeb67451d99a173656 (patch)
tree3e5b193b36b5257d11968f1da6d58e350451bbcd
parentfcf67df200a81fd2f768649f1641781ff28a8530 (diff)
downloadorg.eclipse.etrice-bf0d690b86e9b4db18abe3eeb67451d99a173656.tar.gz
org.eclipse.etrice-bf0d690b86e9b4db18abe3eeb67451d99a173656.tar.xz
org.eclipse.etrice-bf0d690b86e9b4db18abe3eeb67451d99a173656.zip
[ui.behavior] using a position provider
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java101
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java184
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java30
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java11
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java114
5 files changed, 271 insertions, 169 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java
index a91af5453..bebad8736 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ChoicePoint;
import org.eclipse.etrice.core.room.RefinedState;
@@ -16,18 +15,8 @@ import org.eclipse.etrice.core.room.StateGraphItem;
import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.etrice.core.room.Transition;
import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.ui.behavior.DiagramAccess;
-import org.eclipse.etrice.ui.behavior.support.StateGraphSupport;
-import org.eclipse.etrice.ui.behavior.support.StateSupport;
-import org.eclipse.etrice.ui.behavior.support.SupportUtil;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.algorithms.styles.Point;
-import org.eclipse.graphiti.mm.algorithms.styles.StylesFactory;
-import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.mm.pictograms.Shape;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.services.ILinkService;
+import org.eclipse.etrice.ui.behavior.support.DefaultPositionProvider;
+import org.eclipse.etrice.ui.behavior.support.IPositionProvider;
public class StateGraphContext {
private ArrayList<StateGraphContext> children = new ArrayList<StateGraphContext>();
@@ -37,8 +26,7 @@ public class StateGraphContext {
private ArrayList<ChoicePoint> chPoints = new ArrayList<ChoicePoint>();
private ArrayList<TrPoint> trPoints = new ArrayList<TrPoint>();
private ArrayList<Transition> transitions = new ArrayList<Transition>();
- private HashMap<EObject, Point> obj2pos = null;
-
+ private IPositionProvider positionProvider;
private static HashMap<EObject, StateGraphContext> obj2ctx = new HashMap<EObject, StateGraphContext>();
public static StateGraphContext createContextTree(ActorClass ac) {
@@ -70,76 +58,11 @@ public class StateGraphContext {
}
}
- tree.obj2pos = new HashMap<EObject, Point>();
- mapPositions(ac.getBase(), ac.eResource().getResourceSet(), tree.obj2pos);
-
+ tree.positionProvider = new DefaultPositionProvider(ac);
makePositionsAvailableToChildrenContexts(tree);
return tree;
}
-
- /**
- * Propagate the position map to all children recursively
- *
- * @param tree
- */
- private static void makePositionsAvailableToChildrenContexts(StateGraphContext tree) {
- for (StateGraphContext child : tree.getChildren()) {
- child.obj2pos = tree.obj2pos;
- makePositionsAvailableToChildrenContexts(child);
- }
- }
-
- /**
- * Load base class diagrams recursively and put midpoint positions relative to boundary rectangle into map
- *
- * @param ac
- * @param obj2pos
- */
- private static void mapPositions(ActorClass ac, ResourceSet rs, HashMap<EObject, Point> obj2pos) {
- if (ac==null)
- return;
-
- Diagram diagram = new DiagramAccess().getDiagram(ac);
- if (diagram==null)
- return;
-
- ILinkService linkService = Graphiti.getLinkService();
- for (Shape sgShape : diagram.getChildren()) {
- // this is the level of StateGraphs
- if (sgShape instanceof ContainerShape) {
- for (Shape sgItemShape : ((ContainerShape)sgShape).getChildren()) {
- // this is the level of States, TrPoints and ChoicePoints
- EObject obj = linkService.getBusinessObjectForLinkedPictogramElement(sgItemShape);
- EObject ownObject = SupportUtil.getOwnObject(obj, rs);
- GraphicsAlgorithm ga = sgItemShape.getGraphicsAlgorithm();
- if (ownObject!=null && ga!=null) {
- Point pos = StylesFactory.eINSTANCE.createPoint();
- pos.setX(ga.getX() + ga.getWidth() /2 - StateGraphSupport.MARGIN);
- pos.setY(ga.getY() + ga.getHeight()/2 - StateGraphSupport.MARGIN);
- obj2pos.put(ownObject, pos);
- }
- if (sgItemShape instanceof ContainerShape) {
- for (Shape trPointShape : ((ContainerShape) sgShape).getChildren()) {
- // this is the level of entry/exit points located on states
- obj = linkService.getBusinessObjectForLinkedPictogramElement(trPointShape);
- ownObject = SupportUtil.getOwnObject(obj, rs);
- ga = trPointShape.getGraphicsAlgorithm();
- if (ownObject!=null && ga!=null) {
- Point pos = StylesFactory.eINSTANCE.createPoint();
- pos.setX(ga.getX() + ga.getWidth() /2 - StateSupport.MARGIN);
- pos.setY(ga.getY() + ga.getHeight()/2 - StateSupport.MARGIN);
- obj2pos.put(ownObject, pos);
- }
- }
- }
- }
- }
- }
-
- // recursion
- mapPositions(ac.getBase(), rs, obj2pos);
- }
private StateGraphContext(StateGraph sg) {
this.stateGraph = sg;
@@ -239,6 +162,18 @@ public class StateGraphContext {
}
}
}
+
+ /**
+ * Propagate the position map to all children recursively
+ *
+ * @param tree
+ */
+ private static void makePositionsAvailableToChildrenContexts(StateGraphContext tree) {
+ for (StateGraphContext child : tree.getChildren()) {
+ child.positionProvider = tree.positionProvider;
+ makePositionsAvailableToChildrenContexts(child);
+ }
+ }
public State getParentState() {
if (stateGraph.eContainer() instanceof State)
@@ -271,6 +206,10 @@ public class StateGraphContext {
return transitions;
}
+ public IPositionProvider getPositionProvider() {
+ return positionProvider;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java
new file mode 100644
index 000000000..303179935
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.support;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ChoicePoint;
+import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.StateGraphItem;
+import org.eclipse.etrice.core.room.StateGraphNode;
+import org.eclipse.etrice.core.room.TrPoint;
+import org.eclipse.etrice.ui.behavior.DiagramAccess;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.styles.Point;
+import org.eclipse.graphiti.mm.algorithms.styles.StylesFactory;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+
+/**
+ * @author Henrik Rentz-Reichert (initial contribution)
+ *
+ */
+public class DefaultPositionProvider implements IPositionProvider {
+
+ private static class Position {
+ double x;
+ double y;
+ }
+
+ private HashMap<String, Position> obj2pos = new HashMap<String, Position>();
+ private double scaleX;
+ private double scaleY;
+
+ public DefaultPositionProvider(ActorClass ac) {
+ mapPositions(ac.getBase());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.ui.behavior.support.IPositionProvider#setScale(double, double)
+ */
+ @Override
+ public void setScale(double sx, double sy) {
+ this.scaleX = sx;
+ this.scaleY = sy;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.ui.behavior.support.IPositionProvider#getPosition(org.eclipse.emf.ecore.EObject)
+ */
+ @Override
+ public Point getPosition(StateGraphNode obj) {
+ if (obj instanceof State) {
+
+ }
+ else if (obj instanceof TrPoint) {
+
+ }
+ else if (obj instanceof ChoicePoint) {
+
+ }
+
+ assert(false): "unexpected sub type";
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.ui.behavior.support.IPositionProvider#getPositions(java.util.List)
+ */
+ @Override
+ public <T extends StateGraphNode> List<Point> getPositions(List<T> items) {
+ ArrayList<Point> result = new ArrayList<Point>(items.size());
+
+ if (items.isEmpty())
+ return result;
+
+ int n = 0;
+ int idx = 0;
+ for (T item : items) {
+ Position pos = obj2pos.get(RoomNameProvider.getFullPath(item));
+ if (pos!=null) {
+ Point pt = StylesFactory.eINSTANCE.createPoint();
+ pt.setX((int) (pos.x * scaleX) + StateGraphSupport.MARGIN);
+ pt.setY((int) (pos.y * scaleY) + StateGraphSupport.MARGIN);
+ result.add(idx, pt);
+ }
+ else {
+ result.add(idx, null);
+ n++;
+ }
+ idx++;
+ }
+
+ int delta = (int) (scaleX/(n+1));
+ int pos = delta;
+
+ int h = StateGraphSupport.MARGIN;
+ if (items.get(0) instanceof State)
+ h = StateGraphSupport.MARGIN + StateGraphSupport.DEFAULT_SIZE_Y/4;
+ else if (items.get(0) instanceof ChoicePoint)
+ h = StateGraphSupport.MARGIN + StateGraphSupport.DEFAULT_SIZE_Y/2;
+ else if (items.get(0) instanceof TrPoint)
+ h = StateGraphSupport.MARGIN;
+ else {
+ assert(false): "unexpected sub type";
+ }
+
+ for (int i=0; i<items.size(); ++i) {
+ if (result.get(i)==null) {
+ Point pt = StylesFactory.eINSTANCE.createPoint();
+ pt.setX(pos);
+ pt.setY(h);
+ result.set(i, pt);
+
+ pos += delta;
+ }
+ idx++;
+ }
+
+ return result;
+ }
+
+ /**
+ * Load base class diagrams recursively and put midpoint positions relative to boundary rectangle into map.
+ *
+ * Positions are relative to the invisible rectangle. They are transformed to the border rectangle and normalized.
+ *
+ * @param ac
+ * @param obj2pos
+ */
+ private void mapPositions(ActorClass ac) {
+ if (ac==null)
+ return;
+
+ Diagram diagram = new DiagramAccess().getDiagram(ac);
+ if (diagram==null)
+ return;
+
+ ILinkService linkService = Graphiti.getLinkService();
+ for (Shape sgShape : diagram.getChildren()) {
+ // this is the level of StateGraphs
+ if (sgShape instanceof ContainerShape) {
+ GraphicsAlgorithm borderRect = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
+ double width = borderRect.getWidth();
+ double height = borderRect.getHeight();
+ for (Shape sgItemShape : ((ContainerShape)sgShape).getChildren()) {
+ // this is the level of States, TrPoints and ChoicePoints
+ EObject obj = linkService.getBusinessObjectForLinkedPictogramElement(sgItemShape);
+ if (obj instanceof StateGraphItem) {
+ GraphicsAlgorithm ga = sgItemShape.getGraphicsAlgorithm();
+ if (ga!=null) {
+ Position pos = new Position();
+ pos.x = (ga.getX() + ga.getWidth() /2 - StateGraphSupport.MARGIN) / width;
+ pos.y = (ga.getY() + ga.getHeight()/2 - StateGraphSupport.MARGIN) / height;
+ obj2pos.put(RoomNameProvider.getFullPath((StateGraphItem) obj), pos);
+ }
+ // Entry and Exit Points on State borders are treated by the insertion of the State
+ }
+ }
+ }
+ }
+
+ // recursion
+ mapPositions(ac.getBase());
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java
new file mode 100644
index 000000000..08cdb6669
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.support;
+
+import java.util.List;
+
+import org.eclipse.etrice.core.room.StateGraphNode;
+import org.eclipse.graphiti.mm.algorithms.styles.Point;
+
+/**
+ * @author Henrik Rentz-Reichert (initial contribution)
+ *
+ */
+public interface IPositionProvider {
+
+ public void setScale(double sx, double sy);
+
+ public <T extends StateGraphNode> List<Point> getPositions(List<T> items);
+ public Point getPosition(StateGraphNode node);
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
index 767cf61bf..860113365 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
@@ -376,8 +376,8 @@ public class StateGraphSupport {
@Override
public boolean update(IUpdateContext context) {
- ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(containerShape);
+ ContainerShape sgShape = (ContainerShape) context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(sgShape);
/*
if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
@@ -392,16 +392,15 @@ public class StateGraphSupport {
}
*/
StateGraph sg = (StateGraph) bo;
- ContainerShape shape = (ContainerShape) context.getPictogramElement();
if (context instanceof StateGraphUpdateContext) {
StateGraphContext ctx = ((StateGraphUpdateContext)context).getContext();
- SupportUtil.addMissingItems(sg, ctx, shape, fp);
+ //SupportUtil.updateStateGraph(sg, ctx, sgShape, fp);
}
- if (!shape.getChildren().isEmpty()) {
- Shape labelShape = shape.getChildren().get(0);
+ if (!sgShape.getChildren().isEmpty()) {
+ Shape labelShape = sgShape.getChildren().get(0);
GraphicsAlgorithm ga = labelShape.getGraphicsAlgorithm();
if (ga instanceof Text)
((Text)ga).setValue(RoomNameProvider.getStateGraphLabel(sg));
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java
index 752b0ddc7..5a537708c 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java
@@ -29,6 +29,7 @@ import org.eclipse.etrice.core.room.RoomFactory;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StateGraphItem;
+import org.eclipse.etrice.core.room.StateGraphNode;
import org.eclipse.etrice.core.room.StateTerminal;
import org.eclipse.etrice.core.room.SubStateTrPointTerminal;
import org.eclipse.etrice.core.room.TrPoint;
@@ -426,10 +427,13 @@ public class SupportUtil {
final HashMap<String, Anchor> node2anchor = new HashMap<String, Anchor>();
+ GraphicsAlgorithm borderRect = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
+ ctx.getPositionProvider().setScale(borderRect.getWidth(), borderRect.getHeight());
+
addInitialPointIff(ctx.getTransitions(), sgShape, fp, node2anchor);
- addTransitionPoints(ctx.getTrPoints(), sgShape, fp, node2anchor);
- addStates(ctx.getStates(), sgShape, fp, node2anchor);
- addChoicePoints(ctx.getChPoints(), sgShape, fp, node2anchor);
+ addStateGraphNodes(ctx.getTrPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor);
+ addStateGraphNodes(ctx.getStates(), ctx.getPositionProvider(), sgShape, fp, node2anchor);
+ addStateGraphNodes(ctx.getChPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor);
for (StateGraphContext sub : ctx.getChildren()) {
addStateGraph(sub, diagram, fp);
@@ -442,58 +446,61 @@ public class SupportUtil {
return sgShape;
}
- public static void addMissingItems(StateGraph sg, StateGraphContext ctx, ContainerShape shape, IFeatureProvider fp) {
+ public static void updateStateGraph(StateGraph sg, StateGraphContext ctx, ContainerShape sgShape, IFeatureProvider fp) {
HashMap<String, Anchor> node2anchor = new HashMap<String, Anchor>();
+ GraphicsAlgorithm borderRect = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
+ ctx.getPositionProvider().setScale(borderRect.getWidth(), borderRect.getHeight());
+
// states
{
- List<State> present = SupportUtil.getStates(shape, fp, node2anchor);
+ List<State> present = SupportUtil.getStates(sgShape, fp, node2anchor);
List<State> expected = ctx.getStates();
List<State> items = new ArrayList<State>();
for (State item : expected) {
if (!present.contains(item))
items.add(item);
}
- SupportUtil.addStates(items, shape, fp, node2anchor);
+ SupportUtil.addStateGraphNodes(items, ctx.getPositionProvider(), sgShape, fp, node2anchor);
}
// transition points
{
- List<TrPoint> present = SupportUtil.getTrPoints(sg, shape, fp, node2anchor);
+ List<TrPoint> present = SupportUtil.getTrPoints(sg, sgShape, fp, node2anchor);
List<TrPoint> expected = ctx.getTrPoints();
List<TrPoint> items = new ArrayList<TrPoint>();
for (TrPoint item : expected) {
if (!present.contains(item))
items.add(item);
}
- SupportUtil.addTransitionPoints(items, shape, fp, node2anchor);
+ SupportUtil.addStateGraphNodes(items, ctx.getPositionProvider(), sgShape, fp, node2anchor);
}
// choice points
{
- List<ChoicePoint> present = SupportUtil.getChoicePoints(shape, fp, node2anchor);
+ List<ChoicePoint> present = SupportUtil.getChoicePoints(sgShape, fp, node2anchor);
List<ChoicePoint> expected = ctx.getChPoints();
List<ChoicePoint> items = new ArrayList<ChoicePoint>();
for (ChoicePoint item : expected) {
if (!present.contains(item))
items.add(item);
}
- SupportUtil.addChoicePoints(items, shape, fp, node2anchor);
+ SupportUtil.addStateGraphNodes(items, ctx.getPositionProvider(), sgShape, fp, node2anchor);
}
- SupportUtil.getSubTpAnchors(shape, node2anchor);
+ SupportUtil.getSubTpAnchors(sgShape, node2anchor);
// transitions
{
- List<Transition> present = SupportUtil.getTransitions((Diagram) shape.eContainer(), fp);
+ List<Transition> present = SupportUtil.getTransitions((Diagram) sgShape.eContainer(), fp);
List<Transition> expected = ctx.getTransitions();
List<Transition> items = new ArrayList<Transition>();
for (Transition trans : expected) {
if (!present.contains(trans))
items.add(trans);
}
- SupportUtil.addTransitions(items, shape, fp, node2anchor);
+ SupportUtil.addTransitions(items, sgShape, fp, node2anchor);
}
}
@@ -520,89 +527,32 @@ public class SupportUtil {
}
}
- private static void addTransitionPoints(List<TrPoint> trps, ContainerShape sgShape, IFeatureProvider fp,
+ private static void addStateGraphNodes(List<? extends StateGraphNode> trps, IPositionProvider positionProvider, ContainerShape sgShape, IFeatureProvider fp,
HashMap<String, Anchor> node2anchor) {
- int width = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
- int n = trps.size();
- int delta = width/(n+1);
+ List<Point> positions = positionProvider.getPositions(trps);
- int pos = delta;
- for (TrPoint tp : trps) {
- addTrPoint(tp, sgShape, pos+StateSupport.MARGIN, fp, node2anchor);
- pos += delta;
+ int idx = 0;
+ for (StateGraphNode tp : trps) {
+ addStateGraphNode(tp, sgShape, positions.get(idx), fp, node2anchor);
+ ++idx;
}
}
- private static void addTrPoint(TrPoint tp, ContainerShape sgShape,
- int pos, IFeatureProvider fp, HashMap<String, Anchor> node2anchor) {
+ private static void addStateGraphNode(StateGraphNode tp, ContainerShape sgShape,
+ Point pos, IFeatureProvider fp, HashMap<String, Anchor> node2anchor) {
AddContext addContext = new AddContext();
addContext.setNewObject(tp);
addContext.setTargetContainer(sgShape);
- addContext.setX(pos);
- addContext.setY(0);
+ addContext.setX(pos.getX());
+ addContext.setY(pos.getY());
ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext);
- assert(!pe.getAnchors().isEmpty()): "transition point should have an anchor";
+ assert(pe!=null): tp.eClass().getName()+" should have been created";
+ assert(!pe.getAnchors().isEmpty()): tp.eClass().getName()+" should have an anchor";
node2anchor.put(getKey(tp, (StateGraph) tp.eContainer()), pe.getAnchors().get(0));
}
- private static void addStates(List<State> states, ContainerShape sgShape, IFeatureProvider fp,
- HashMap<String, Anchor> node2anchor) {
-
- int width = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
- int n = states.size();
- int delta = width/(n+1);
-
- int pos = delta;
- for (State s : states) {
- addState(s, sgShape, pos+StateSupport.MARGIN, fp, node2anchor);
- pos += delta;
- }
- }
-
- private static void addState(State s, ContainerShape sgShape,
- int pos, IFeatureProvider fp, HashMap<String, Anchor> node2anchor) {
- AddContext addContext = new AddContext();
- addContext.setNewObject(s);
- addContext.setTargetContainer(sgShape);
- addContext.setX(pos);
- addContext.setY(StateGraphSupport.DEFAULT_SIZE_Y/4);
-
- ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext);
- assert(pe!=null): "state should have been created";
- assert(!pe.getAnchors().isEmpty()): "state should have an anchor";
- node2anchor.put(getKey(s, null), pe.getAnchors().get(0));
- }
-
- private static void addChoicePoints(List<ChoicePoint> cps, ContainerShape sgShape, IFeatureProvider fp,
- HashMap<String, Anchor> node2anchor) {
-
- int width = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
- int n = cps.size();
- int delta = width/(n+1);
-
- int pos = delta;
- for (ChoicePoint cp : cps) {
- addChoicePoint(cp, sgShape, pos+ChoicePointSupport.ITEM_SIZE, fp, node2anchor);
- pos += delta;
- }
- }
-
- private static void addChoicePoint(ChoicePoint cp, ContainerShape sgShape,
- int pos, IFeatureProvider fp, HashMap<String, Anchor> node2anchor) {
- AddContext addContext = new AddContext();
- addContext.setNewObject(cp);
- addContext.setTargetContainer(sgShape);
- addContext.setX(pos);
- addContext.setY(StateGraphSupport.DEFAULT_SIZE_Y/2);
-
- ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext);
- assert(pe!=null): "choice point should have been created";
- assert(!pe.getAnchors().isEmpty()): "choice point should have an anchor";
- node2anchor.put(getKey(cp, null), pe.getAnchors().get(0));
- }
-
private static void addInitialPointIff(List<Transition> transitions, ContainerShape sgShape, IFeatureProvider fp,
HashMap<String, Anchor> node2anchor) {

Back to the top