Commit 438d56a1 authored by Eyrak Paen-Rochlitz's avatar Eyrak Paen-Rochlitz
Browse files

[ui.structure] Simplify inheriting actor positioning

- Inherited actor diagrams always take the layout of the base diagram
- On open/update, diagram will be resized to base diagram size if
smaller than base diagram
- No scaling of base actor elements will be done during resize/layout
parent e55c4def
......@@ -212,25 +212,27 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
}
private ContainerShape createStructureClass(StructureClass sc, IPositionProvider positionProvider){
PosAndSize pos = positionProvider == null ? null : positionProvider.getDiagramPosition();
AddContext addContext = new AddContext();
addContext.setNewObject(sc);
addContext.setTargetContainer(getDiagram());
addContext.setX(StructureClassSupport.MARGIN);
addContext.setY(StructureClassSupport.MARGIN);
if (pos != null) {
addContext.setWidth(pos.getW()-2*StructureClassSupport.MARGIN);
addContext.setHeight(pos.getH()-2*StructureClassSupport.MARGIN);
}
ContainerShape scShape = (ContainerShape) getFeatureProvider().addIfPossible(addContext);
if(positionProvider != null){
PosAndSize pos = positionProvider.getDiagramPosition();
if(pos != null){
GraphicsAlgorithm ga = scShape.getGraphicsAlgorithm();
if(pos != null){
ga.setX(pos.getX());
ga.setY(pos.getY());
if(pos.getW() > 0)
ga.setWidth(pos.getW());
if(pos.getH() > 0)
ga.setHeight(pos.getH());
}
ga.setX(pos.getX());
ga.setY(pos.getY());
if(pos.getW() > 0)
ga.setWidth(pos.getW());
if(pos.getH() > 0)
ga.setHeight(pos.getH());
}
return scShape;
......
......@@ -20,7 +20,9 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.RoomPackage;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.commands.RoomOpeningHelper;
import org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase;
import org.eclipse.etrice.ui.common.base.support.BaseToolBehaviorProvider;
......@@ -372,7 +374,8 @@ public class StructureClassSupport {
ContainerShape containerShape = (ContainerShape)context.getShape();
StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(containerShape);
for (Shape childShape : containerShape.getChildren()) {
if (isOnInterface(sc, getBusinessObjectForPictogramElement(childShape)))
Object childBo = getBusinessObjectForPictogramElement(childShape);
if (!isInherited(sc, childBo) && isOnInterface(sc, childBo))
continue;
GraphicsAlgorithm ga = childShape.getGraphicsAlgorithm();
......@@ -407,7 +410,8 @@ public class StructureClassSupport {
double sy = (context.getHeight()-2*MARGIN)/(double)ga.getHeight();
for (Shape childShape : containerShape.getChildren()) {
if (isOnInterface(sc, getBusinessObjectForPictogramElement(childShape))) {
Object childBo = getBusinessObjectForPictogramElement(childShape);
if (!isInherited(sc, childBo) && isOnInterface(sc, childBo)) {
ga = childShape.getGraphicsAlgorithm();
ga.setX((int) (ga.getX()*sx));
ga.setY((int) (ga.getY()*sy));
......@@ -417,6 +421,18 @@ public class StructureClassSupport {
}
super.resizeShape(context);
}
private boolean isInherited(StructureClass sc, Object childBo) {
if (EObject.class.isInstance(childBo) && RoomPackage.eINSTANCE.getActorClass().isInstance(sc)) {
RoomHelpers helpers = SupportUtil.getInstance().getRoomHelpers();
ActorClass acOfChild = helpers.getActorClass((EObject)childBo);
ActorClass acLocal = (ActorClass)sc;
if (!acOfChild.equals(acLocal) && helpers.isKindOf(acLocal, acOfChild)) {
return true;
}
}
return false;
}
private boolean isOnInterface(StructureClass sc, Object childBo) {
boolean onInterface = false;
......
......@@ -34,6 +34,7 @@ import org.eclipse.etrice.ui.structure.support.feature.ShapeUpdateFeature;
import org.eclipse.etrice.ui.structure.support.provider.ConnectionProvider;
import org.eclipse.etrice.ui.structure.support.provider.DefaultPositionProvider;
import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider;
import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider.PosAndSize;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.context.IUpdateContext;
......@@ -68,8 +69,22 @@ public class StructureClassUpdate extends ShapeUpdateFeature {
if(context instanceof PositionUpdateContext){
positionProvider = ((PositionUpdateContext)context).getPositionProvider();
GraphicsAlgorithm invRect = containerShape.getGraphicsAlgorithm();
GraphicsAlgorithm innerRect = containerShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
positionProvider = positionProvider.setNewParent(sc, DiagramUtil.getPosAndSize(invRect), DiagramUtil.getPosAndSize(innerRect));
GraphicsAlgorithm innerRect0 = invRect.getGraphicsAlgorithmChildren().get(0);
GraphicsAlgorithm innerRect1 = invRect.getGraphicsAlgorithmChildren().get(1);
positionProvider = positionProvider.setNewParent(sc, DiagramUtil.getPosAndSize(invRect), DiagramUtil.getPosAndSize(innerRect0));
PosAndSize refPos = positionProvider.getDiagramPosition();
if (refPos != null) {
if (refPos.getW() > invRect.getWidth()) {
invRect.setWidth(refPos.getW());
innerRect0.setWidth(refPos.getW() - 2*StructureClassSupport.MARGIN);
innerRect1.setWidth(refPos.getW() - 2*StructureClassSupport.MARGIN);
}
if (refPos.getH() > invRect.getHeight()) {
invRect.setHeight(refPos.getH());
innerRect0.setHeight(refPos.getH() - 2*StructureClassSupport.MARGIN);
innerRect1.setHeight(refPos.getH() - 2*StructureClassSupport.MARGIN);
}
}
}
ConnectionProvider connectionProvider = new ConnectionProvider(getFeatureProvider());
......
......@@ -15,6 +15,7 @@
package org.eclipse.etrice.ui.structure.support.provider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
......@@ -26,9 +27,7 @@ import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.LayerConnection;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.ui.structure.DiagramAccess;
import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport;
import org.eclipse.etrice.ui.structure.support.DiagramUtil;
import org.eclipse.etrice.ui.structure.support.InterfaceItemSupport;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.algorithms.styles.Point;
......@@ -43,35 +42,25 @@ import org.eclipse.graphiti.services.ILinkService;
public class SuperDiagramPositionProvider implements IPositionProvider {
private class Position {
double x;
double y;
double sx = -1;
double sy = -1;
}
private class Parent {
EObject bo;
String key;
PosAndSize inv, inner;
}
private PosAndSize superDiagramPosition;
private HashMap<String, Position> obj2pos;
private HashMap<String, Position> obj2text;
private HashMap<String, ArrayList<Position>> obj2bendpoints;
private HashMap<String, PosAndSize> obj2pos;
private HashMap<String, Pos> obj2text;
private HashMap<String, ArrayList<Pos>> obj2bendpoints;
private Parent parent;
private SuperDiagramPositionProvider(){ }
public SuperDiagramPositionProvider(StructureClass sc) {
obj2pos = new HashMap<String, Position>();
obj2text = new HashMap<String, Position>();
obj2bendpoints = new HashMap<String, ArrayList<Position>>();
obj2pos = new HashMap<String, PosAndSize>();
obj2text = new HashMap<String, Pos>();
obj2bendpoints = new HashMap<String, ArrayList<Pos>>();
// defaults
parent = new Parent();
parent.bo = sc;
parent.key = getKey(sc);
// parent.inv & parent.inner at mapPositions()
......@@ -91,10 +80,7 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
pp.superDiagramPosition = this.superDiagramPosition;
Parent newParent = new Parent();
newParent.bo = parent;
newParent.key = getKey(parent);
newParent.inv = invisibleRect;
newParent.inner = innerRect;
pp.parent = newParent;
......@@ -114,58 +100,22 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
@Override
public PosAndSize getPosition(EObject bo) {
Position pos = obj2pos.get(getKey(bo));
if (pos==null)
return null;
boolean fixedSize = false;
int width = 0, height = 0;
if(bo instanceof InterfaceItem){
if(parent.bo instanceof ActorContainerRef)
width = height = 2*InterfaceItemSupport.MARGIN_SMALL;
else
width = height = 2*InterfaceItemSupport.MARGIN;
fixedSize = true;
} else if(bo instanceof ActorContainerRef){
int margin = ActorContainerRefSupport.MARGIN;
width = (int) (pos.sx * parent.inner.getW()) + 2*margin;
height = (int) (pos.sy * parent.inner.getH()) + 2*margin;
}
return new PosAndSize(
(int) (pos.x * parent.inner.getW()) - width/2 + parent.inner.getX(),
(int) (pos.y * parent.inner.getH()) - height/2 + parent.inner.getY(),
(fixedSize)?-1:width,
(fixedSize)?-1:height);
PosAndSize pos = obj2pos.get(getKey(bo));
return pos;
}
@Override
public Pos getConnectionText(EObject obj) {
Position pos = obj2text.get(getKey(obj));
if(pos == null)
return null;
return new Pos(
(int) (pos.x * parent.inner.getW()) + parent.inner.getX() + parent.inv.getX(),
(int) (pos.y * parent.inner.getH()) + parent.inner.getY() + parent.inv.getY());
Pos pos = obj2text.get(getKey(obj));
return pos;
}
@Override
public List<Pos> getConnectionBendpoints(EObject obj) {
ArrayList<Pos> result = new ArrayList<Pos>();
ArrayList<Position> list = obj2bendpoints.get(getKey(obj));
if(list == null)
return result;
for (Position p : list) {
Pos pos = new Pos(
(int) (p.x * parent.inner.getW()) + parent.inner.getX() + parent.inv.getX(),
(int) (p.y * parent.inner.getH()) + parent.inner.getY() + parent.inv.getY());
result.add(pos);
}
return result;
ArrayList<Pos> list = obj2bendpoints.get(getKey(obj));
return (list == null || list.isEmpty())
? Collections.emptyList()
: new ArrayList<Pos>(list);
}
private void mapPositions(ActorClass ac) {
......@@ -183,13 +133,7 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
return;
PosAndSize acInv = DiagramUtil.getPosAndSize(acShape.getGraphicsAlgorithm());
PosAndSize acInner = DiagramUtil.getPosAndSize(acShape.getGraphicsAlgorithm()
.getGraphicsAlgorithmChildren().get(0));
superDiagramPosition = acInv;
// default
parent.inv = acInv;
parent.inner = acInner;
// refs & interface items
for (Shape shape : acShape.getChildren()) {
......@@ -199,29 +143,16 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
if (obj instanceof ActorContainerRef || obj instanceof InterfaceItem) {
PosAndSize objInv = DiagramUtil.getPosAndSize(shape.getGraphicsAlgorithm());
PosAndSize objInner = DiagramUtil.getPosAndSize(shape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0));
Position pos = new Position();
pos.x = (double)(objInv.getX() - acInner.getX() + objInv.getW()/2) / acInner.getW();
pos.y = (double)(objInv.getY() - acInner.getY() + objInv.getH()/2) / acInner.getH();
pos.sx = (double)(objInner.getW()) / acInner.getW();
pos.sy = (double)(objInner.getH()) / acInner.getH();
obj2pos.put(getKey(obj), pos);
obj2pos.put(getKey(obj), objInv);
// refs interface items
if (obj instanceof ActorContainerRef){
for(Shape child : ((ContainerShape)shape).getChildren()){
EObject childBo = linkService.getBusinessObjectForLinkedPictogramElement(child);
if(!(childBo instanceof InterfaceItem))
continue;
PosAndSize ifInv = DiagramUtil.getPosAndSize(child.getGraphicsAlgorithm());
Position p = new Position();
p.x = (double)(ifInv.getX() - objInner.getX() + ifInv.getW()/2) / objInner.getW();
p.y = (double)(ifInv.getY() - objInner.getY() + ifInv.getH()/2) / objInner.getH();
obj2pos.put(getKey(obj)+getKey(childBo), p);
obj2pos.put(getKey(obj)+getKey(childBo), ifInv);
}
}
}
......@@ -238,20 +169,16 @@ public class SuperDiagramPositionProvider implements IPositionProvider {
ConnectionDecorator cd = conn.getConnectionDecorators().get(1);
if (cd.getGraphicsAlgorithm() instanceof Text) {
GraphicsAlgorithm ga = cd.getGraphicsAlgorithm();
Position pos = new Position();
pos.x = (double)(ga.getX() - acInv.getX() - acInner.getX()) / acInner.getW();
pos.y = (double)(ga.getY() - acInv.getY() - acInner.getY()) / acInner.getH();
Pos pos = new Pos(ga.getX(), ga.getY());
obj2text.put(getKey(obj), pos);
}
}
// bend points
if (conn instanceof FreeFormConnection) {
ArrayList<Position> points = new ArrayList<Position>();
ArrayList<Pos> points = new ArrayList<Pos>();
for (Point bp : ((FreeFormConnection) conn).getBendpoints()) {
Position pos = new Position();
pos.x = (double)(bp.getX() - acInv.getX() - acInner.getX()) / acInner.getW();
pos.y = (double)(bp.getY() - acInv.getY() - acInner.getY()) / acInner.getH();
Pos pos = new Pos(bp.getX(), bp.getY());
points.add(pos);
}
if(!points.isEmpty())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment