troubles with setBounds on PresentationElements in SwimlaneCell

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

troubles with setBounds on PresentationElements in SwimlaneCell

Postby bertrand.gregoire » Mon Apr 02, 2007 3:15 am

Hello!

I'm trying to copy graphically an ActivityDiagram using the OpenApi.

It seems to me that a PresentationElements' bounds are linked
to the edge of the swimlaneCell, however the relative position is not
correct:

I used the method "getBounds" of the "original element" and "setBounds"
on the "copy element" (with argument: bounds of the "origin element").

I then call the method "boundsChanged()" in order to force a refresh of
the copied element... resulting in a copied element not placed at the
expected place in my Activity Diagram (i.e. like 2cm to the right of the
expected place).

I see that there are other methods with bounds but don't find their
description in Open Api. Is there a way to get the correct relative
position in the swimlaneCell?

Thanks for help,
Bertrand.
bertrand.gregoire
 
Posts Rating:

Re: troubles with setBounds on PresentationElements in SwimlaneCell

Postby Mindaugas Genutis » Mon Apr 02, 2007 5:25 am

Hello Bertrand,

> I'm trying to copy graphically an ActivityDiagram using the OpenApi.
>
> It seems to me that a PresentationElements' bounds are linked
> to the edge of the swimlaneCell, however the relative position is not
> correct:
>
> I used the method "getBounds" of the "original element" and "setBounds"
> on the "copy element" (with argument: bounds of the "origin element").
>
> I then call the method "boundsChanged()" in order to force a refresh of
> the copied element... resulting in a copied element not placed at the
> expected place in my Activity Diagram (i.e. like 2cm to the right of the
> expected place).
>
> I see that there are other methods with bounds but don't find their
> description in Open Api. Is there a way to get the correct relative
> position in the swimlaneCell?

getBounds() and other bound methods deal only with absolute diagram
coordinates, relative bounds are not stored anywhere. Of course, for
convenience they can be calculated at runtime and you may do it in your code
if it is necessary.

Could you print to the console the bounds of all your original elements
before copy and the bounds of your resulting elements after copy? Does your
copy code fail only for elements inside swimlane cell?

Best regards,
--
Mindaugas Genutis
Programmer
OMG-Certified UML Professional
No Magic Lithuanian Development Center
P.O. box 2166, Lt-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
E-mail: mindaugas.genutis
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple

Mindaugas Genutis
 
Posts Rating:

Re: troubles with setBounds on PresentationElements in SwimlaneCell

Postby bertrand.gregoire » Tue Apr 03, 2007 3:29 am

Hi Mindaugas,


Thanks for your answer.
I have tested the position after the copy of presentation element.


The initial code to set bounds to the copy element was :

shp_elt.setBounds(bounds);
shp_elt.boundsChanged();
System.out.println("KO: bounds origin = " + elementOrigin.getBounds() +
" - bounds copied = " + shp_elt.getBounds() + " - element = " +
elementOrigin.getHumanName());



As this code doesn't give the good position, I have added the following
workaround after the above code... that gets the right position set to
the copied element.

Rectangle rect = shp_elt.getBounds();
rect.setBounds(elementOrigin.getBounds());
shp_elt.setBounds(rect);
shp_elt.boundsChanged();
System.out.println("OK: bounds copied = " + shp_elt.getBounds() + " -
element = " + elementOrigin.getHumanName());




generated logs : (You can observe that there is a problem with the X
position on the lines beginning with KO... while fixed on the lines with
OK.)

KO: bounds origin = java.awt.Rectangle[x=120,y=264,width=0,height=44] -
bounds copied = java.awt.Rectangle[x=131,y=264,width=33,height=44] -
element = Flot d'Objet
OK: bounds copied = java.awt.Rectangle[x=120,y=264,width=33,height=44] -
element = Flot d'Objet

KO: bounds origin = java.awt.Rectangle[x=345,y=468,width=0,height=12] -
bounds copied = java.awt.Rectangle[x=341,y=468,width=16,height=12] -
element = Flot d'Objet
OK: bounds copied = java.awt.Rectangle[x=345,y=468,width=16,height=12] -
element = Flot d'Objet

KO: bounds origin = java.awt.Rectangle[x=370,y=648,width=169,height=43]
- bounds copied = java.awt.Rectangle[x=363,y=648,width=176,height=43] -
element = Flot de Contrôle
OK: bounds copied = java.awt.Rectangle[x=370,y=648,width=176,height=43]
- element = Flot de Contrôle



Any hint/explanation is welcome on copying these bounds in a clear
manner, as I'd hate to keep this workaround in my code.

Thanks for your help,
Bertrand (and colleagues ;)



Mindaugas Genutis a écrit :
> Hello Bertrand,
>
>
> getBounds() and other bound methods deal only with absolute diagram
> coordinates, relative bounds are not stored anywhere. Of course, for
> convenience they can be calculated at runtime and you may do it in your code
> if it is necessary.
>
> Could you print to the console the bounds of all your original elements
> before copy and the bounds of your resulting elements after copy? Does your
> copy code fail only for elements inside swimlane cell?
>
> Best regards,
> --
> Mindaugas Genutis
bertrand.gregoire
 
Posts Rating:

Re: troubles with setBounds on PresentationElements in SwimlaneCell

Postby bertrand.gregoire » Tue Apr 03, 2007 3:36 am

<added first line of code, for the sake of clarity>


Hi Mindaugas,


Thanks for your answer.
I have tested the position after the copy of presentation element.


The initial code to set bounds to the copy element was :

Rectangle bounds = elementOrigin.getBounds();
shp_elt.setBounds(bounds);
shp_elt.boundsChanged();
System.out.println("KO: bounds origin = " + elementOrigin.getBounds() +
" - bounds copied = " + shp_elt.getBounds() + " - element = " +
elementOrigin.getHumanName());



As this code doesn't give the good position, I have added the following
workaround after the above code... that gets the right position set to
the copied element.

Rectangle rect = shp_elt.getBounds();
rect.setBounds(elementOrigin.getBounds());
shp_elt.setBounds(rect);
shp_elt.boundsChanged();
System.out.println("OK: bounds copied = " + shp_elt.getBounds() + " -
element = " + elementOrigin.getHumanName());




generated logs : (You can observe that there is a problem with the X
position on the lines beginning with KO... while fixed on the lines with
OK.)

KO: bounds origin = java.awt.Rectangle[x=120,y=264,width=0,height=44] -
bounds copied = java.awt.Rectangle[x=131,y=264,width=33,height=44] -
element = Flot d'Objet
OK: bounds copied = java.awt.Rectangle[x=120,y=264,width=33,height=44] -
element = Flot d'Objet

KO: bounds origin = java.awt.Rectangle[x=345,y=468,width=0,height=12] -
bounds copied = java.awt.Rectangle[x=341,y=468,width=16,height=12] -
element = Flot d'Objet
OK: bounds copied = java.awt.Rectangle[x=345,y=468,width=16,height=12] -
element = Flot d'Objet

KO: bounds origin = java.awt.Rectangle[x=370,y=648,width=169,height=43]
- bounds copied = java.awt.Rectangle[x=363,y=648,width=176,height=43] -
element = Flot de Contrôle
OK: bounds copied = java.awt.Rectangle[x=370,y=648,width=176,height=43]
- element = Flot de Contrôle



Any hint/explanation is welcome on copying these bounds in a clear
manner, as I'd hate to keep this workaround in my code.

Thanks for your help,
Bertrand (and colleagues ;)



Mindaugas Genutis a écrit :
> Hello Bertrand,
>
>
> getBounds() and other bound methods deal only with absolute diagram
> coordinates, relative bounds are not stored anywhere. Of course, for
> convenience they can be calculated at runtime and you may do it in
your code
> if it is necessary.
>
> Could you print to the console the bounds of all your original elements
> before copy and the bounds of your resulting elements after copy?
Does your
> copy code fail only for elements inside swimlane cell?
>
> Best regards,
> --
> Mindaugas Genutis
bertrand.gregoire
 
Posts Rating:

Re: troubles with setBounds on PresentationElements in SwimlaneCell

Postby Mindaugas Genutis » Tue Apr 03, 2007 4:33 am

Hello Bertrand,

First of all you don't have to call boundsChanged() method each time you set
bounds for a shape. Changes on the diagram will be visible without calling
boundsChanged(). Event firing and symbol update will be done inside the
setBounds() method.

boundsChanged() should be used when the bounds of an element change and
after undo the bounds should be restored. I guess this is not your case,
because you are setting bounds for newly created elements.

>From your logs I can see that you are having problems with relationships
(control and object flows), not shapes. After you copy shapes, you should
copy relationship connection points with PathElement.setClientPoint() and
PathElement.setSupplierPoint().

Unfortunately, we did not expose copy paste management code through open
api, because it is very complicated. I do not want to discourage you in your
task, but I don't think your copy paste will work in all cases.

Best regards,
--
Mindaugas Genutis
Programmer
OMG-Certified UML Professional
No Magic Lithuanian Development Center
P.O. box 2166, Lt-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
E-mail: mindaugas.genutis
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple

Mindaugas Genutis
 
Posts Rating:

Re: troubles with setBounds on PresentationElements in SwimlaneCell

Postby bertrand.gregoire » Wed Apr 04, 2007 1:54 am

Thanks for the highlight and explanations.

Actually we're not trying to have a full copy of AD in "all cases" but
just for a few elements (namely activities, complex activities with
input pins, control & object flows, transitions with their guards and
route... all within swimlanes)... so I hope we'll get a "not too bad
result", even if not perfect.

B.


Mindaugas Genutis a écrit :
>
>>From your logs I can see that you are having problems with relationships
> (control and object flows), not shapes. After you copy shapes, you should
> copy relationship connection points with PathElement.setClientPoint() and
> PathElement.setSupplierPoint().
>
> Unfortunately, we did not expose copy paste management code through open
> api, because it is very complicated. I do not want to discourage you in your
> task, but I don't think your copy paste will work in all cases.
bertrand.gregoire
 
Posts Rating:

Re: troubles with setBounds on PresentationElements in SwimlaneCell

Postby bertrand.gregoire » Wed Apr 04, 2007 2:02 am

I did not pay attention to the fact that all logs in former mail were
all objectflows or controlflows... so I send you other examples ranging
over merges, joins, forks and object flows... of which none is
satisfactorily copied.



KO : bounds origin = java.awt.Rectangle[x=314,y=305,width=30,height=15]
- bounds copied = java.awt.Rectangle[x=332,y=305,width=30,height=15] -
element = Noeud de Décision merge
KO : bounds origin = java.awt.Rectangle[x=370,y=244,width=0,height=27] -
bounds copied = java.awt.Rectangle[x=385,y=244,width=4,height=27] -
element = Flot d'Objet
KO : bounds origin = java.awt.Rectangle[x=307,y=461,width=42,height=7] -
bounds copied = java.awt.Rectangle[x=332,y=461,width=42,height=7] -
element = Noeud de Bifurcation fork
KO : bounds origin = java.awt.Rectangle[x=289,y=320,width=40,height=20]
- bounds copied = java.awt.Rectangle[x=321,y=312,width=27,height=28] -
element = Flot d'Objet
KO : bounds origin = java.awt.Rectangle[x=287,y=691,width=143,height=24]
- bounds copied = java.awt.Rectangle[x=332,y=691,width=143,height=24] -
element = Action d'Appel de Comportement shortcut merge
KO : bounds origin = java.awt.Rectangle[x=455,y=601,width=82,height=24]
- bounds copied = java.awt.Rectangle[x=519,y=601,width=82,height=24] -
element = Action d'Appel de Comportement join4



Another problem I am facing relates to the width of the swimlaneCells.
In fact, the printed coordinates of the copy are the same as the
original swimlaneCells but in the view, it does not display the same way.

I attach a sample (MD12) project, just in case it's easier to get my
point: in "Patterns/patternWithcomplexFlow" , you can find the original
activity diagram, in "test-main/call pattern-patternWithComplexFlow",
you will find the copy.

Any hint on displaying the copied swimlane with same width as orignal
would be welcome too.

Thanks for your help,
B.




Mindaugas Genutis a écrit :

> From your logs I can see that you are having problems with relationships
> (control and object flows), not shapes.
You do not have the required permissions to view the files attached to this post.
bertrand.gregoire
 
Posts Rating:

Re: troubles with setBounds on PresentationElements in SwimlaneCell

Postby Mindaugas Genutis » Wed Apr 11, 2007 4:43 am

Hello,

> I did not pay attention to the fact that all logs in former mail were
> all objectflows or controlflows... so I send you other examples ranging
> over merges, joins, forks and object flows... of which none is
> satisfactorily copied.

I can see from the log file that the "x" coordinate is moved to the right.
The diagrams you are copying have many elements. I recommend you to try to
localize the problem. Try to find the smallest case which is not working.
For example, try to copy a diagram with a single decision node.

> Another problem I am facing relates to the width of the swimlaneCells.
> In fact, the printed coordinates of the copy are the same as the
> original swimlaneCells but in the view, it does not display the same way.
>
> I attach a sample (MD12) project, just in case it's easier to get my
> point: in "Patterns/patternWithcomplexFlow" , you can find the original
> activity diagram, in "test-main/call pattern-patternWithComplexFlow",
> you will find the copy.

I have opened your project and compared the two mentioned diagrams. I see
that in your original diagram relationships have rectilinear style and in
the copy they are oblique. Coordinate changes might appear when diagram
layouter layouts your relationships.

Best regards,
--
Mindaugas Genutis
Programmer
OMG-Certified UML Professional
No Magic Lithuanian Development Center
P.O. box 2166, Lt-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
E-mail: mindaugas.genutis
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple

You do not have the required permissions to view the files attached to this post.
Mindaugas Genutis
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests