Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Hit-testing for overlapping figures in refreshVisuals() or elsewhere?
Hit-testing for overlapping figures in refreshVisuals() or elsewhere? [message #1384810] Mon, 02 June 2014 09:07 Go to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 104
Registered: October 2011
Location: Berlin, Germany
Senior Member

Disclaimer: Connected to this question on stackoverflow. This question here has a slightly different direction though, aksing for the *right place* to hit test.

In my GEF editor, I calculate the layout (i.e., position) for a given "NodeFigure" in its EditPart's refreshVisuals() method. E.g., a NodeFigure should be placed 100 pixels north of the smallest y coordinate of the NodeFigures to which it is connected via a Connection (layout is done via FreeformLayout on the diagram EditPart's ScalableFreeformLayeredPane through parent.setLayoutConstraint(this, figure, layout).)

-----------------------
| y = 100 (calculated) |
------------------------
  |                 |
-----------      -----------
| y = 230 |      | y = 200 |
-----------      -----------

This works fine. Now if I have a NodeFigure N4 with connections to N1 and N2, and a NodeFigure N5 with connections to N2 and N3, there is a possibility, depending on the width of N4 and N5, that the latter two overlap (the XX region in below sketch).

 ---------------------- 
 |    N4   |XX|  N5   |
 ----------------------
  |      \   /     |
------  ------   ------
| N1 |  | N2 |   | N3 |
------  ------   ------

I want to try and avoid this behaviour by hit-testing in refreshVisuals() if there is already a Figure at the calculated location. I've tried doing this by calling getFigure().getParent().findFigureAt(x,y), with a number of different x and y values, but findFigureAt() always returns null, and getViewer().findObjectAt() returns the underlying diagram EditPart, even when I can see in the editor that two NodeFigures clearly overlap, and at the coordinates I have tested.

Is this the wrong place to do hit-testing? Or am I just doing it completely wrong?
Re: Hit-testing for overlapping figures in refreshVisuals() or elsewhere? [message #1386044 is a reply to message #1384810] Fri, 13 June 2014 07:47 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
Does any of your figures introduce local coordinate systems. If so, you will have to properly transform coordinates (translateToParent, translateToAbsolute, translateFromParent, translateToRelative).
Re: Hit-testing for overlapping figures in refreshVisuals() or elsewhere? [message #1386667 is a reply to message #1386044] Thu, 19 June 2014 09:53 Go to previous messageGo to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 104
Registered: October 2011
Location: Berlin, Germany
Senior Member

Hi Alexander, thanks for your answer, and excuse the late reply.

None of my figures - I think - introduces local coordinate systems. The EditParts/Figures that this concerns are all direct children of the parent EditPart (lets call it "GraphEditPart"). Their x and y values are calculated inrelation to the bounds of sibling children they're connected to, and their constraints are set via the parent (parent.setLayoutConstraint(childEditPart, childFigure, layoutRectangle)... Pretty standard fare I think?

My problem seems to be that at the point I'm trying to hit-test within the bounds of a figure (say "NodeFigure") for already existing figures, the bounds of "NodeFigure" aren't available yet!

figure.getBounds() in the following - incomplete - refreshVisuals() snippet always returns Rectangle(0,0,0,0).
parent.setLayoutConstraint(this, figure, layout);
parent.refresh();
System.out.println(figure.getBounds());


Likewise, findFigureAt() on the parent always returns null in the following snippet.
Rectangle r = figure.getBounds();
System.out.println(parent.findFigureAt(r.getCenter()));
r = parent.getFigure().getLayoutManager().getConstraint(figure);
System.out.println(parent.findFigureAt(r.getCenter()));


And this even though I know that figure overlaps other figures (e.g., at getCenter()).

So in short, I guess I'm looking for a place to call findFigureAt() on the parent when its figure *does already "have"* the coordinates for all its children.

I'd be more than thankful for any hints!
Thanks!
Re: Hit-testing for overlapping figures in refreshVisuals() or elsewhere? [message #1397820 is a reply to message #1386667] Thu, 10 July 2014 07:48 Go to previous messageGo to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 104
Registered: October 2011
Location: Berlin, Germany
Senior Member

Dear forum and list, can anyone shed some light on this? I still haven't found a way to make this work.
Re: Hit-testing for overlapping figures in refreshVisuals() or elsewhere? [message #1403300 is a reply to message #1397820] Tue, 22 July 2014 18:28 Go to previous message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
I think refreshVisuals() probably is the right place to go. As it will probably be called several times, I suppose to simply guard your calculation so it is not performed until the bounds are actually assigned. Alternatively, you can also register a listener to figure to keep track of when bounds are actually assigned.

[Updated on: Tue, 22 July 2014 18:34]

Report message to a moderator

Previous Topic:Export a GEF diagram as a PNG
Next Topic:[ZEST] Program Speed
Goto Forum:
  


Current Time: Tue Mar 19 07:25:33 GMT 2024

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

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

Back to the top