Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Problem with hover feedback geometry with GEF4.0.0RC2
Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733118] Tue, 24 May 2016 14:18 Go to next message
Xavier JACQUES is currently offline Xavier JACQUESFriend
Messages: 10
Registered: October 2015
Junior Member
Hello,

I'm trying to upgrade my application to GEF4.0.0 RC2.

I have a strange behavior with the hover feedback. Now (as you can see on the image) the hover feedback is translated to the 0,0 location of the canvas...

index.php/fa/26001/0/

I found the GEF4 code change causing this problem but I don't manage to understand the purpose of your change.

Previously in NodeUtils class you had line 345 this code that provides the geometry hover feedback, it was working fine for me
else if (visual instanceof GeometryNode) {
			return ((GeometryNode<?>) visual).getGeometry();
		}


Now it is
else if (visual instanceof GeometryNode) {
			GeometryNode<?> geometryNode = (GeometryNode<?>) visual;
			IGeometry geometry = geometryNode.getGeometry();
			if (geometry != null) {
				return geometry.getTransformed(new AffineTransform().translate(
						-geometryNode.getLayoutX(),
						-geometryNode.getLayoutY()));
			}


The layoutx and y of my nodes are not null so the hover feedback get translated to the 0,0 location of the canvas.
We don't set manually the layoutx and y, it is setted when we call the set Geometry function in GeometryNode.

We are really stuck with this issue, if you can maybe point us to a direction where to look at in the code or is it a bug?

Thank you.
  • Attachment: bug.png
    (Size: 7.99KB, Downloaded 492 times)
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733127 is a reply to message #1733118] Tue, 24 May 2016 08:49 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
As GeometryNode is now based on Region, its layout bounds are fixed to (0, 0, width, height). We interpret the position information within its Geometry as its layoutX, layoutY values, so literally speaking the geometry reflects the boundsInParent of the GeometryNode. The translation within NodeUtils has been added to compensate this (as it should retrieve a geometry within the local coordinate system of the given node, not its parent). It seems as if a translation (localToParent/parentToLocal) is missing in some place. How do you position your nodes?

Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733154 is a reply to message #1733118] Tue, 24 May 2016 13:02 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
Xavier, to illustrate this take a look at the following test code:

// Shape
javafx.scene.shape.Rectangle shape = new javafx.scene.shape.Rectangle(5, 10, 30, 40);
shape.setStroke(Color.RED);
shape.setStrokeWidth(3);
shape.setStrokeType(StrokeType.OUTSIDE);
shape.relocate(30, 40);
IGeometry geometricOutline = NodeUtils.getGeometricOutline(shape);
assertTrue(geometricOutline instanceof Rectangle);
// the geometry is returned in the local coordinates of the Shape (the
// stroke is outside), thus the X and Y values are preserved
assertEquals(new Rectangle(5, 10, 30, 40), geometricOutline);
// translating it into parent coordinates returns the relocate values
// including the stroke offset
assertEquals(new Rectangle(33, 43, 30, 40), NodeUtils.localToParent(shape, geometricOutline).getBounds());

// GeometryNode
GeometryNode<Rectangle> geometryNode = new GeometryNode<>();
geometryNode.setStroke(Color.RED);
geometryNode.setStrokeWidth(3);
geometryNode.setStrokeType(StrokeType.OUTSIDE);
geometryNode.setGeometry(new Rectangle(0, 0, 30, 40));
geometryNode.relocate(30, 40);
geometricOutline = NodeUtils.getGeometricOutline(geometryNode);
assertTrue(geometricOutline instanceof Rectangle);
// the geometric is returned in the local coordinates of the
// GeometryNode (as the stroke is outside the geometry but inside the
// GeometryNode the geometry is translated by the stroke offset)
assertEquals(new Rectangle(3, 3, 30, 40), geometricOutline);
// translating it into parent coordinates should provide the same values
// as in the Shape case, i.e. the relocate values including the stroke
// offset
assertEquals(new Rectangle(33, 43, 30, 40), NodeUtils.localToParent(geometryNode, geometricOutline).getBounds());


Prior to our change, the Geometry included its X and Y values in its layout bounds (similar to Shape). Now, as it extends Region, the layout bounds are fixed by (0,0). In parent coordinates nothing should have changed, but if a respective translation is missing, the layoutX, layoutY offset should be noticeable.
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733388 is a reply to message #1733118] Thu, 26 May 2016 23:56 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Xavier,

supplementary to Alexander's replies, you can check what geometry provider is used for hover feedback and how the hover feedback part factory transforms the provided geometry. In the Logo example, the GeometricOutlineProvider is used and the FXDefaultFeedbackPartFactory transforms the provided geometry from the local coordinate system of the target node into the coordinate system of the scene. Possibly, in your case, either the geometry provider does not return the geometry in local coordinates of the target node, or the transformation from local to scene coordinates within the factory is incorrect.

For debuggin purposes, you can output the target node and its local-to-scene-transformation within the factory, and you can output the provided geometry within FXHoverFeedbackPart#doRefreshVisual(), which should be in parent coordinates, as well as the feedback part visual's local-to-scene-transformation, which should reflect the translation.

Best regards,
Matthias
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733439 is a reply to message #1733388] Fri, 27 May 2016 13:47 Go to previous messageGo to next message
Xavier JACQUES is currently offline Xavier JACQUESFriend
Messages: 10
Registered: October 2015
Junior Member
Thank you for your answers.

Our problem comes when we are using Group as visual.
We have already overridden your GeometricOutlineProvider to make it work for Group, we put the outline in the first children of the group and our provider returns this geometry for the hover feedback.
I think the problem can come from interaction between group and its children we update directly, we will further investigate.
We have not so much time to analyse deeply the problem and ended up bypassing your NodeUtils for Group visuals.


Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733440 is a reply to message #1733439] Fri, 27 May 2016 13:49 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
I suppose the problem then is that the geometry that is inferred from the first child has to be translated into coordinates of the group, using something like NodeUtils.localToParent(firstChild, geometry).
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733499 is a reply to message #1733440] Sat, 28 May 2016 20:45 Go to previous messageGo to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

I have a pretty similar situation. I have around 40 different parts, most of which use a GeometryNode as the visual, but a handful use Group instead. The ones that use Group add an invisible GeometryNode with the model object's outline geometry, which is used by the geometry provider. After picking up these changes, I also had to add the localToParent conversion as Alexander says. Here is my geometry provider:

  public IGeometry get() {
    IVisualPart<Node, ? extends Node> adaptable = getAdaptable();
    if (adaptable instanceof TerrainPart<?, ?>) {
      TerrainPart<?, ?> part = (TerrainPart<?, ?>) adaptable;
      IGeometry outline = NodeUtils.getGeometricOutline(part.getGeometryOutline());
      if (part.isLocalGeometry()) {
        return outline;
      } else {
        return NodeUtils.localToParent(part.getGeometryOutline(), outline);
      }
    }
    return NodeUtils.getGeometricOutline(adaptable.getVisual());
  }


TerrainPart is the base class for all my different parts. The method getGeometryOutline() returns the GeometryNode to use for the outline - in the base base it is the part's visual, in the classes using group it is the invisible child. The isLocalGeometry() method is overridden in the Group parts to return false, so it does the conversion to parent coordinates. That all works nicely.


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733506 is a reply to message #1733499] Sat, 28 May 2016 23:18 Go to previous messageGo to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

Incidentally, this change also affects how you interpret mouse events in the part geometry. Previously, in my IFXOnClickPolicy and IFXOnDragPolicy classes, I was just using Node.sceneToLocal() to convert the mouse event sceneX() and sceneY() to a point that I could use in model coordinates. However, that will now always return a point in reference to the (0, 0) origin of the Region, so you need to do a two-step transform to get the point back into the parent coordinates of the GeometyNode. I added a method to my base TerrainPart, again using the getGeometryOutline() method to get the model's geometry, as follows:

  public Point sceneToLocal(double sceneX, double sceneY) {
    GeometryNode<?> outline = getGeometryOutline();
    Point local = NodeUtils.sceneToLocal(outline, new Point(sceneX, sceneY));
    return NodeUtils.localToParent(outline, local);
  }


Here's an example of this being used. This is an IFXOnDragPolicy that rotates a part, so I want to calculate the new angle of rotation from the current position of the mouse relative to the current location of the model object. Geometry.getAngleFrom() is a utility method of mine that returns the angle (as a clockwise rotation from the X-axis) from point A to point B. Obviously, those two points both need to refer to the same coordinate space for it to compute the angle correctly.

  public void drag(MouseEvent e, Dimension delta) {
    Point reference = targetPart.sceneToLocal(e.getSceneX(), e.getSceneY());
    Angle newAngle = Geometry.getAngleFrom(targetPart.getTerrain().getLocation(), reference);
    // update transaction policy with the new angle
  }


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733562 is a reply to message #1733506] Mon, 30 May 2016 07:39 Go to previous message
Xavier JACQUES is currently offline Xavier JACQUESFriend
Messages: 10
Registered: October 2015
Junior Member
Thank you so much for these very useful information.

It was the problem and your code example works nicely.
Previous Topic:[GEF4] GEF4/Zest graph in an SWT Composite?
Next Topic:Adjusted update site and drop file urls for Neon
Goto Forum:
  


Current Time: Fri Apr 19 04:04:00 GMT 2024

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

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

Back to the top