Hit-testing for overlapping figures in refreshVisuals() or elsewhere? [message #1384810] |
Mon, 02 June 2014 09:07 |
|
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 #1386667 is a reply to message #1386044] |
Thu, 19 June 2014 09:53 |
|
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!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02034 seconds