Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Draw2d - Problems translating absolute/relative coordinates
Draw2d - Problems translating absolute/relative coordinates [message #141634] Tue, 06 July 2004 09:06 Go to next message
Alexander NyÃ?en is currently offline Alexander NyÃ?enFriend
Messages: 38
Registered: July 2009
Member
Hallo,

I got some strange effects, when translating absolute to relative
coordinates and vice versa using the translateToAbsolute() and
translateToRelative() methods of the Figure class. I am not sure, whether I
do not understand the meaning of the two methods right, or if they are not
implemented correctly.
When I looked at the implementations of the two methods I find it somewhat
strange, how the recursion is implemented. For example,
translateToAbsolute(Translatable t) is implemented the following way:

public final void translateToAbsolute(Translatable t) {
if (getParent() != null) {
getParent().translateToParent(t);
getParent().translateToAbsolute(t);
}
}

Shouldn't it be done like this (calling translateToParent on this rather
then on the parent)?:

public final void translateToAbsolute(Translatable t) {
if (getParent() != null) {
translateToParent(t);
getParent().translateToAbsolute(t);
}
}

Same holds for translateToRelative(Translatable t) in my opinion. Shouldn't
it be:

public final void translateToRelative(Translatable t) {
if (getParent() != null) {
getParent().translateToRelative(t);
translateFromParent(t);
}
}

rather than:

public final void translateToRelative(Translatable t) {
if (getParent() != null) {
getParent().translateToRelative(t);
getParent().translateFromParent(t);
}
}

Is this a bug or do I not clearly understand what the methods intention is?
Any comments?

Greetings,
Alexander


PS: Here is the source code of all 4 translation methods of the Figure
class:

public void translateFromParent(Translatable t) {
if (useLocalCoordinates())
t.performTranslate(
-getBounds().x - getInsets().left,
-getBounds().y - getInsets().top);
}

public final void translateToAbsolute(Translatable t) {
if (getParent() != null) {
getParent().translateToParent(t);
getParent().translateToAbsolute(t);
}
}

public void translateToParent(Translatable t) {
if (useLocalCoordinates())
t.performTranslate(
getBounds().x + getInsets().left,
getBounds().y + getInsets().top);
}

public final void translateToRelative(Translatable t) {
if (getParent() != null) {
getParent().translateToRelative(t);
getParent().translateFromParent(t);
}
}
Re: Draw2d - Problems translating absolute/relative coordinates [message #141671 is a reply to message #141634] Tue, 06 July 2004 14:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

The "exemplary" use case is to take a figure's bounds, and then use that
same figure to translate (a copy of) the bounds to absolute coordinates. So
a figure's bounds are coordinates within its parent, not itself.

"Alexander Ny
Re: Draw2d - Problems translating absolute/relative coordinates [message #141699 is a reply to message #141634] Tue, 06 July 2004 15:49 Go to previous messageGo to next message
Alexander NyÃ?en is currently offline Alexander NyÃ?enFriend
Messages: 38
Registered: July 2009
Member
Hallo,

the implementation of the translate methods does indeed not seem to be the
problem. I now figured out, why I get so strange translation results.
The problem is that I call the translate methods from the refreshVisuals()
method of my EditPart. However, when I start my Editor and refreshVisuals()
is called the first time on my EditParts, the figures are not yet painted,
so that the bounds of the figures are not yet initialized (they are all
(0,0,64,36) by default) and so any translation done there has wrong results
(as it relies on the bounds of the figure).

Does anyone know, where I would best call refreshVisuals() on my EditParts
when starting the Editor, so that the bounds of the figures are already
initialized and I got correct translation results?

Greetings,
Alexander

"Alexander Ny
Re: Draw2d - Problems translating absolute/relative coordinates [message #141778 is a reply to message #141699] Tue, 06 July 2004 18:10 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
What are you trying to do? The point of calling refreshVisuals() is so that
it can set constraint, update values, etc., that will affect the figure's
look/layout. The figure lays out if necessary after refreshVisuals() is
invoked. If you are doing something that requires that the figures already
be laid out properly when refreshVisuals() is invoked, it is possible that
it doesn't belong in that method.

"Alexander Ny
Re: Draw2d - Problems translating absolute/relative coordinates [message #141874 is a reply to message #141778] Wed, 07 July 2004 07:00 Go to previous messageGo to next message
Alexander NyÃ?en is currently offline Alexander NyÃ?enFriend
Messages: 38
Registered: July 2009
Member
What I want to do is to store all graphical information (and thereby
naturally also the position) of my diagrams in absolute coordinates.
Therefore to set the constraint for my figure (at its parent), I have to
retrieve the stored absolute coordinates and translate them to relative
coordinates (relative to the parent figure), if the parent figure uses local
coordinates, so I can set the layout constraint by calling .

I thought, the place to do so would be the refreshVisuals() method, as there
I have to set the constraint for my figure. This works fine, if the figure
is already painted (and I move it or drop new child figures to it), but not,
when I load my models and the refreshVisuals() get called before the figures
are painted.

Greetings,
Alexander


"Pratik Shah" <ppshah@us.ibm.com> schrieb im Newsbeitrag
news:ccepsq$2m3$1@eclipse.org...
> What are you trying to do? The point of calling refreshVisuals() is so
that
> it can set constraint, update values, etc., that will affect the figure's
> look/layout. The figure lays out if necessary after refreshVisuals() is
> invoked. If you are doing something that requires that the figures
already
> be laid out properly when refreshVisuals() is invoked, it is possible that
> it doesn't belong in that method.
>
> "Alexander Ny
Re: Draw2d - Problems translating absolute/relative coordinates [message #142503 is a reply to message #141874] Mon, 12 July 2004 18:09 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

You'd be better off using your own XYLayout which uses absolute instead of
relative constraints. It's easier to do things the same way in draw2d that
they are in your model.

"Alexander Ny
Previous Topic:No wrap on palette entry
Next Topic:acyclic compound directed graph
Goto Forum:
  


Current Time: Fri Apr 26 16:58:54 GMT 2024

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

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

Back to the top