Home » Modeling » Graphiti » creating a ChopboxAnchor on a nested polygon
creating a ChopboxAnchor on a nested polygon [message #789436] |
Fri, 03 February 2012 01:12 |
Josef Pohl Messages: 82 Registered: January 2012 |
Member |
|
|
Hi there again,
I have a new issue with creating connections to a polygon nested in an invisible rectangle. When I create a connection it anchors to the outer invisible rectangle and not to the polygon. It is a very similar situation as in the tutorial, in fact I believe I have faithfully replicated this feature setup. (See below)
When I re-ran the tutorial example everything seemed fine. The chop box was associated with the inner rectangle and made its connections there. Unfortunately not so with my parallelogram. Is there anything that I am obviously missing?
It seems to me that I need to create a container shape that is specific to the polygon and associate the chop box with that. However, then in the layout routine it is not clear what pictogram element the context would be picking up or is there a way to change my layout code so that I can still have the outer invisible rectangle be the "parent" (i.e. dictating the size for the addition ornaments, namely the diamond that is added from time to time.)?
Thanks in advance,
Joe
public PictogramElement add(IAddContext context) {
Strategy addedClass = (Strategy) context.getNewObject();
Diagram targetDiagram = (Diagram) context.getTargetContainer();
SafetyCase sc = (SafetyCase)targetDiagram.getLink().getBusinessObjects().get(0);
sc.getNode().add(addedClass);
// CONTAINER SHAPE
IPeCreateService peCreateService = Graphiti.getPeCreateService();
ContainerShape containerShape =
peCreateService.createContainerShape(targetDiagram, true);
// define a default size for the shape
int width = context.getWidth() <= 0 ? 100 : context.getWidth();
int height = context.getHeight() <= 0 ? 50 : context.getHeight();
IGaService gaService = Graphiti.getGaService();
Polygon p;
{
int offset = 0;
Rectangle invisible = gaService.createInvisibleRectangle(containerShape);
if(addedClass.isToBeDeveloped()){
System.out.println("Strat add offset????");
offset = UNDEVELOPED_OFFSET;
}
gaService.setLocationAndSize(invisible, context.getX(), context.getY(), width, height+offset);
int xy[] = new int[] {25,0,100,0,75,50,0,50};
// Polygon p = gaService.createPolygon(containerShape, xy);
p = gaService.createPolygon(invisible, xy);
p.setParentGraphicsAlgorithm(invisible);
p.setBackground(manageColor(CLASS_BACKGROUND));
p.setForeground(manageColor(CLASS_FOREGROUND));
p.setLineWidth(2);
Graphiti.getPeService().setPropertyValue(containerShape, "shape-type", "parallelogram");
gaService.setLocationAndSize(p, 0, 0, width, height);
// create link and wire it
link(containerShape, addedClass);
}
{
if(addedClass.isToBeDeveloped()){
Shape shape = peCreateService.createShape(containerShape, false);
int[] diamondXY = new int[] {10,0,20,10,10,20,0,10};
Polygon diamond = gaService.createPolygon(shape, diamondXY);
diamond.setBackground(manageColor(UNDEV_BACKGROUND));
diamond.setForeground(manageColor(UNDEV_FOREGROUND));
diamond.setLineWidth(2);
Graphiti.getPeService().setPropertyValue(shape, "shape-type", "diamond");
//gaService.setLocationAndSize(p, width/2, height, 10, 10);
gaService.setLocation(diamond, (width/2-10), (height));
link(shape, addedClass);
}
}
// SHAPE WITH TEXT
// ...............Elided text stuff
// add a chopbox anchor to the shape
ChopboxAnchor cpb = peCreateService.createChopboxAnchor(containerShape);
cpb.setReferencedGraphicsAlgorithm(p);
// call the layout feature
layoutPictogramElement(containerShape);
return containerShape;
}
public boolean layout(ILayoutContext context){
boolean anythingChanged = false;
boolean mDevelop = false;
ContainerShape containerShape =
(ContainerShape) context.getPictogramElement();
GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
PictogramElement pe = context.getPictogramElement();
EList<EObject> bOs = pe.getLink().getBusinessObjects();
Strategy s = (Strategy) bOs.get(0);
if (s.isToBeDeveloped()){
mDevelop = true;
}
// polygon is added first so will always be 0????
Polygon poly = (Polygon) containerGa.getGraphicsAlgorithmChildren().get(0);
// height
if (containerGa.getHeight() < MIN_HEIGHT) {
containerGa.setHeight(MIN_HEIGHT);
anythingChanged = true;
}
// width
if (containerGa.getWidth() < MIN_WIDTH) {
containerGa.setWidth(MIN_WIDTH);
anythingChanged = true;
}
resizePoly(poly,containerGa.getWidth(), containerGa.getHeight());
int containerWidth = containerGa.getWidth();
int containerHeight = containerGa.getHeight();
for (Shape shape : containerShape.getChildren()){
GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm();
IGaService gaService = Graphiti.getGaService();
IDimension size =
gaService.calculateSize(graphicsAlgorithm);
if (containerWidth != size.getWidth()) {
if (graphicsAlgorithm instanceof MultiText) {
MultiText mt = (MultiText) graphicsAlgorithm;
mt.setHeight(containerHeight - DESCRIPTION_OFFSET);
mt.setWidth(containerWidth);
anythingChanged = true;
} else if (graphicsAlgorithm instanceof Rectangle){
Rectangle rt = (Rectangle) graphicsAlgorithm;
rt.setHeight(containerHeight); //- UNDEVELOPED_OFFSET );
rt.setWidth(containerWidth);
} else if (graphicsAlgorithm instanceof Polygon){
Polygon pg = (Polygon) graphicsAlgorithm;
PictogramElement pge = pg.getPictogramElement();
if(Graphiti.getPeService().getPropertyValue(pge, "shape-type").equals("diamond")){
System.out.println("DIAMOND FOUND");
pg.setX(containerWidth/2 - UNDEVELOPED_OFFSET/2);
pg.setY(containerHeight - UNDEVELOPED_OFFSET);
}
} else if (graphicsAlgorithm instanceof Polyline) {
Polyline polyline = (Polyline) graphicsAlgorithm;
Point secondPoint = polyline.getPoints().get(1);
Point newSecondPoint =
gaService.createPoint(containerWidth, secondPoint.getY());
polyline.getPoints().set(1, newSecondPoint);
anythingChanged = true;
} else {
gaService.setWidth(graphicsAlgorithm,
containerWidth);
anythingChanged = true;
}
}
}
return anythingChanged;
}
|
|
| | | | | | | | | | | | | |
Re: creating a ChopboxAnchor on a nested polygon [message #823150 is a reply to message #820032] |
Sat, 17 March 2012 21:44 |
Josef Pohl Messages: 82 Registered: January 2012 |
Member |
|
|
Hi Michael,
Thank you so much for looking into this for me. I apologize it has taken me so long to get back to this.
Unfortunately, that still leaves the connection feature dangling below the bottom of the diamond as opposed to being connected to the polygon. The sides look great though!
I thought I would try and run with your idea and implement something similar:
int polyxy[] = new int[] {25,0,100,0,75,50,0,50};
int offset = 0;
Rectangle invisibleRect = gaService.createInvisibleRectangle(containerShape);
if(addedClass.isToBeDeveloped() || addedClass.isToBeInstantiated()){
offset = UNDEVELOPED_OFFSET;
}
gaService.setLocationAndSize(invisibleRect, context.getX(), context.getY(), width, height + offset);
// CREATE new shape for chop box
Shape shapePoly = peCreateService.createShape(containerShape,true);
Polygon invisible = gaService.createPolygon(shapePoly, polyxy);
invisible.setFilled(false
invisible.setLineVisible(false);
gaService.setLocationAndSize(invisible, 0, 0, width, height );
//invisible.setParentGraphicsAlgorithm(invisibleRect);
// VISIBLE POLYGON
Polygon p = gaService.createPolygon(invisibleRect, polyxy);
p.setStyle(StyleUtil.getStyleForNode(getDiagram()));
gaService.setLocationAndSize(p, 0, 0, width, height);
p.setParentGraphicsAlgorithm(invisibleRect);
//p.setParentGraphicsAlgorithm(invisible);
//invisible.setParentGraphicsAlgorithm(invisibleRect);
Graphiti.getPeService().setPropertyValue(containerShape, "shape-type", "parallelogram1");
Graphiti.getPeService().setPropertyValue(shapePoly, "shape-type", "parallelogram2");
// create link and wire it
link(containerShape, addedClass);
link(shapePoly, addedClass);
Unfortunately the "invisible" polygon does not render (I turned it to visible and made it bigger to test this) unless I set the parent GA to be invisibleRect. At that point though I get the following NPE.
!ENTRY org.eclipse.graphiti 4 0 2012-03-17 14:23:32.831
!MESSAGE refresh edit part problem
!STACK 0
java.lang.NullPointerException
at org.eclipse.draw2d.Figure.add(Figure.java:148)
at org.eclipse.draw2d.Figure.add(Figure.java:184)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addChildVisual(AbstractGraphicalEditPart.java:209)
at org.eclipse.graphiti.ui.internal.parts.ContainerShapeEditPart.addChildVisual(ContainerShapeEditPart.java:161)
at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:211)
at org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(AbstractEditPart.java:781)
at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refreshChildren(ShapeEditPart.java:635)
at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:726)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:644)
at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refresh(ShapeEditPart.java:555)
at org.eclipse.gef.editparts.AbstractEditPart.addNotify(AbstractEditPart.java:253)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addNotify(AbstractGraphicalEditPart.java:223)
at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:212)
at org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(AbstractEditPart.java:781)
at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refreshChildren(ShapeEditPart.java:635)
at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:726)
at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:644)
at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refresh(ShapeEditPart.java:555)
at org.eclipse.graphiti.ui.internal.parts.DiagramEditPart.refresh(DiagramEditPart.java:183)
...
But I am not certain where this is derived from exactly.
I'll use your solution for the moment and keep playing.
Thanks again,
Joe
|
|
|
Re: creating a ChopboxAnchor on a nested polygon [message #826008 is a reply to message #823150] |
Wed, 21 March 2012 14:32 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
It seems that you have a shape without an associated GA, that's usually the
cause of such a NPE.
How about defining the outer invisble polygon just the size that it covers
exactly all inner visible polygons?
Polygon invisiblePolygon = gaService.createPolygon(containerShape,
new int[] { 25, 0, 100, 0, 75,50, 50,50, 55,55, 50,60, 45,55, 50,50
,0,50 });
Michael
|
|
| | |
Goto Forum:
Current Time: Fri Apr 26 14:15:40 GMT 2024
Powered by FUDForum. Page generated in 0.04312 seconds
|