Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Strange Polygon Behaviour
Strange Polygon Behaviour [message #734409] Fri, 07 October 2011 16:33 Go to next message
steven reinisch is currently offline steven reinischFriend
Messages: 33
Registered: July 2009
hi folks,

if I add a polygon to a diagram, the polygon cannot be moved correctly. If I select the corresponding shape, move it, and release the mouse, the shape is not positioned at the point where I release the mouse. Instead, the shape "jumps" to a lower than its original position. If I use a plain rectangle, everything works fine.

Here is my add feature for the shape:

public class AddConditionalNodeFeature extends AbstractAddShapeFeature{
    public PictogramElement add(IAddContext context) {
        ConditionalNode addedConditionalNode = (ConditionalNode) context.getNewObject();
	Diagram targetDiagram = (Diagram) context.getTargetContainer();

	IPeCreateService peCreateService = Graphiti.getPeCreateService();
	ContainerShape containerShape    = peCreateService.createContainerShape(targetDiagram, true);
        IGaService gaService = Graphiti.getGaService();
	Polygon polygon = this.createPolygon(containerShape);
        gaService.setLocation(polygon, context.getX(), context.getY());
        link(containerShape, addedConditionalNode);
        return containerShape;

    private Polygon createPolygon(ContainerShape containerShape){
		List<Point> points = new ArrayList<Point>(4);
		Point p1 = Graphiti.getGaService().createPoint(60, 100);
		Point p2 = Graphiti.getGaService().createPoint(80, 120);
		Point p3 = Graphiti.getGaService().createPoint(60, 140);
		Point p4 = Graphiti.getGaService().createPoint(40, 120);
		Polygon p = Graphiti.getGaService().createPolygon(containerShape, points);
		return p; 

I am using version 0.8.1.v20110912-1027.

What is the reason for this strange behavior?


Re: Strange Polygon Behaviour [message #734439 is a reply to message #734409] Fri, 07 October 2011 19:15 Go to previous messageGo to next message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 188
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
This strange behaviour might be a bug, but your shape definition is also strange to me. Apart from using a ContainerShape where a plain Shape would seem enough, you are defining a polygon with coordinates shifted from the reference location (origin of the shape) (100px of 'top padding' and 40px of 'right padding'). Just change it to

		Point p1 = Graphiti.getGaService().createPoint(20, 0);
		Point p2 = Graphiti.getGaService().createPoint(40, 20);
		Point p3 = Graphiti.getGaService().createPoint(20, 40);
		Point p4 = Graphiti.getGaService().createPoint(0, 20);

and it will work as expected. The problem is that, depending on how the clickable-drageable area and how the final placement is computed (do we take into account the "full" shape with its 'padding' or just the polygon?) the behaviour can be incosistent to the user. In this case, when dragging the shape, the user only sees the square, but when the final placement is computed in

PointList pointList = toAbsoluteDraw2dPoints(polygon.getPoints(), polygonLocation);

the location of the polygon is assumed to be the origin of the shape and the 'paddings' are added...

[Updated on: Fri, 07 October 2011 19:17]

Report message to a moderator

Re: Strange Polygon Behaviour [message #734462 is a reply to message #734439] Fri, 07 October 2011 21:16 Go to previous message
steven reinisch is currently offline steven reinischFriend
Messages: 33
Registered: July 2009
thanks Hernan! Now it works.


Previous Topic:Graphiti service release 0.7.2 is available for download
Next Topic:Plans on Graphiti future?
Goto Forum:

Current Time: Tue Nov 24 18:19:19 GMT 2020

Powered by FUDForum. Page generated in 0.01664 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top