Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [GEF4] Rotation using wrong angle
[GEF4] Rotation using wrong angle [message #1732152] Fri, 13 May 2016 01:41 Go to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 90
Registered: July 2009
Location: Wellington, New Zealand

I have been following a thread [1] describing how to commit visual changes into the model, and have mostly got it working, apart from rotation.

I have a model object which essentially represents a rectangle of a certain size, which is at a certain location and rotation, so it stores the shape as a (gef4.geometry) Polygon by translating and rotating the rectangle. The model has three geometry properties: location (Point), rotation (Angle) and outline (Polygon).

The part uses the untransformed outline (i.e. at Point(0, 0) with rotation 0) to create the GeometyNode<Polygon> in createVisual(). It updates the visual with the current model location and rotation in doRefreshVisual():

Model model = getContent();
    Affine transform = getAdapter(FXTransformPolicy.TRANSFORM_PROVIDER_KEY).get();
    Point location = model.getLocation();
    Transform concat = Affine.translate(location.x, location.y).createConcatenation(Affine.rotate(model.getRotation().deg(), 0, 0));

So this all works fine for translation, but something strange is happening with rotation. I have two separate selection handles, for translation and rotation. The translation handle is rendered at the model location, whereas the rotation handle is offset at 32 pixels from the translation handle in the direction of the model's rotation.

I am using a class that is based on FXRotateSelectedOnHandleDragPolicy (see bug #493590 for why I can't subclass it), so I can modify that if need be. What's happening is that the selection handle rotates in the opposite direction to the visual - so if I move the mouse clockwise around the center of the part, the selection handle rotates CCW, but the part moves clockwise. I changed computeRotationAngleCW to return the opposite full of the calculated angle, and now the selection handle follows the mouse correctly, but the part rotates in the opposite direction. In either case, the transform that ends up being committed to the model has a different value.

I'm guessing that the FXRotateSelectedOnHandleDragPolicy makes some assumptions about the relationship between the selection handle and the part that don't hold for my case, but I can't work out what.

How should the policy be calculating the correct transform, and how do I update both the visual and the model to use the right value?


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: [GEF4] Rotation using wrong angle [message #1732420 is a reply to message #1732152] Tue, 17 May 2016 07:24 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 163
Registered: March 2015
Senior Member
Hi Colin,

it is difficult to get the transformations right, that's why the FXTransformPolicy is provided to manipulate transformations. The order in which the transformations are concatenated is important because it influences the result. When the rotation is applied first, the object is rotated around its origin and then translated to its location. But when the translation is applied first, the object is translated and then rotated around the origin which will further change its position. The FXRotateSelectedOnHandleDragPolicy sets up a series of (post-)transformations for each target part to achieve rotation around a pivot-point:

1) Translate by negative pivot point.
2) Rotate.
3) Translate by positive pivot point.

For each target part, the center of the layout-bounds is used as the pivot point.

In order to sync model and visualization, IContentPart#doRefreshVisual() and ITransformableContentPart#transformContent() must be coordinated, i.e. the transformations must be applied in the same order, and the angle must be interpreted in the same direction (clockwise (CW) vs. counter-clockwise (CCW)).

I presume that the selection handles are generated by the selection handle part factory of your application. Per default, selection handles are placed on the outside of a handle geometry that is provided as an adapter of the target part (for which handles are being created). Therefore, the handle positions are solely controlled by the handle geometry provider. In this case, the geometry should match the model geometry, i.e. the transformations must be interpreted correctly here, too, which should not be a problem when computing it from the visualization (GeometricOutlineProvider).

In order to give more sophisticated feedback I need to further understand the particular situation: How are the rotation handles generated? If a handle geometry provider is used, how does it compute the geometry?

PS: The issue regarding FXRotateSelectedOnHandleDragPolicy (bug #493590) has been resolved, therefore, subclassing should be possible now.

Best regards,

[Updated on: Tue, 17 May 2016 07:25]

Report message to a moderator

Re: [GEF4] Rotation using wrong angle [message #1732906 is a reply to message #1732420] Sun, 22 May 2016 21:20 Go to previous message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 90
Registered: July 2009
Location: Wellington, New Zealand

In the end I decided not to use FXTransformPolicy, largely because I don't want live updating of the visual during the drag. Instead I used an IFXOnDragPolicy which creates a feedback part to preview the rotation, so that the part only gets updated when the operation is committed. The feedback part can be updated directly by calculating the end angle in the drag() method, and I also move the selection handle at the same time.

Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Previous Topic:Creating parts
Next Topic:InfiniteCanvas scrollbars
Goto Forum:

Current Time: Sat Nov 17 22:29:26 GMT 2018

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

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

Back to the top