how use Layout and Style

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

how use Layout and Style

Postby Raul Lorenzo » Sat Mar 04, 2006 9:51 am

I have this piece of code,

HierarchicDiagramLayouter organize=new HierarchicDiagramLayouter();
Application.getInstance().getProject().getDiagram(diagrama).layout(true,organize);

it works but the elements aren´t spaced well.
How would I have to do to layout automatically a diagram?
Raul Lorenzo
 
Posts Rating:

Re: how use Layout and Style

Postby Tomas Pugzlys » Mon Mar 06, 2006 5:25 am

Hello,

> it works but the elements aren´t spaced well.
You may pass layout options to DiagramPresentationElement.layout() method.

Open "Layout options" dialog to see what are possible layout options.
(click in the main menu Layout -> Layout options)

Here would be the example:
HierarchicLayouterOptionsGroup options = new
HierarchicLayouterOptionsGroup();
options.setMinimalShapeDistance(10);
options.setMinimalLinkDistance(10);

HierarchicDiagramLayouter organize=new HierarchicDiagramLayouter();
Application.getInstance().getProject().getDiagram(diagrama).layout(true,organize,
options);

> How would I have to do to layout automatically a diagram?
What do you mean by automatically?
You mean relayout diagram after every new element is drawn?

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363- IV, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple

nntp://news.nomagic.com/nomagic.products.magicdrawuml.openapi wrote:
> I have this piece of code,
>
> HierarchicDiagramLayouter organize=new HierarchicDiagramLayouter();
> Application.getInstance().getProject().getDiagram(diagrama).layout(true,organize);
>
> it works but the elements aren´t spaced well.
> How would I have to do to layout automatically a diagram?
>

Tomas Pugzlys
 
Posts Rating:

Re: how use Layout and Style

Postby Raul Lorenzo » Mon Mar 06, 2006 11:05 am

Tomas Pugzlys escribió:
> Hello,
>
>> it works but the elements aren´t spaced well.
> You may pass layout options to DiagramPresentationElement.layout() method.
>
> Open "Layout options" dialog to see what are possible layout options.
> (click in the main menu Layout -> Layout options)
>
> Here would be the example:
> HierarchicLayouterOptionsGroup options = new
> HierarchicLayouterOptionsGroup();
> options.setMinimalShapeDistance(10);
> options.setMinimalLinkDistance(10);
>
> HierarchicDiagramLayouter organize=new HierarchicDiagramLayouter();
> Application.getInstance().getProject().getDiagram(diagrama).layout(true,organize,
> options);
>
>> How would I have to do to layout automatically a diagram?
> What do you mean by automatically?
> You mean relayout diagram after every new element is drawn?
I mean setting a layout to work well, I think with this code helps me, I
don´t know about XXXXXXXLayouterOptionsGroup. Thanks
Raul Lorenzo
 
Posts Rating:

Re: how use Layout and Style

Postby Raul Lorenzo » Tue Mar 07, 2006 10:57 am

Tomas Pugzlys escribió:
> Hello,
>
>> it works but the elements aren´t spaced well.
> You may pass layout options to DiagramPresentationElement.layout() method.
>
> Open "Layout options" dialog to see what are possible layout options.
> (click in the main menu Layout -> Layout options)
>
> Here would be the example:
> HierarchicLayouterOptionsGroup options = new
> HierarchicLayouterOptionsGroup();
> options.setMinimalShapeDistance(10);
> options.setMinimalLinkDistance(10);
>
> HierarchicDiagramLayouter organize=new HierarchicDiagramLayouter();
> Application.getInstance().getProject().getDiagram(diagrama).layout(true,organize,
> options);
>
I tested the return value from method
Application.getInstance().getProject().getDiagram(diagrama).layout(true,organize,
options);
and its result is set to true, but the diagram still remains the same,
any object is organizated.

What am I doing wrong?

Thanks in advance for your help.
Raul Lorenzo
 
Posts Rating:

Re: how use Layout and Style

Postby Tomas Pugzlys » Wed Mar 08, 2006 1:46 am

Hello,

> I tested the return value from method
> getDiagram(diagrama).layout(true,organize,options);
> and its result is set to true, but the diagram still remains the same,
> any object is organizated.
>
> What am I doing wrong?

If you lay out the diagram for one time
and then without making changes layout for the second time
the result of layout method will be true
and the diagram will remain the same.

Layout was performed but changes are not visible.

Try moving several shapes and then layout.
Does the diagram still remain the same?

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363- IV, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple


Tomas Pugzlys
 
Posts Rating:

Re: how use Layout and Style

Postby Raul Lorenzo » Wed Mar 08, 2006 6:19 am

Hello,

Now, when I create a shape I use shape.sLocation(10,10) to locate all
the presentation elements (like you told me about moving the shapes).

I only call once the method to autoorganize the diagram, I call it at
the end of the process, when all elements are displayed. I attached the
diagram result. Note that if all shapes were in (10,10) then there
weren´t some organization like in jpg.

The diagram changed a bit from before. Before all usecase were
superposed, now 1 usecase is separated from others.

Any Idea?

I attached the code too.

Tomas Pugzlys escribió:
> Hello,
>
>> I tested the return value from method
>> getDiagram(diagrama).layout(true,organize,options);
>> and its result is set to true, but the diagram still remains the same,
>> any object is organizated.
>>
>> What am I doing wrong?
>
> If you lay out the diagram for one time
> and then without making changes layout for the second time
> the result of layout method will be true
> and the diagram will remain the same.
>
> Layout was performed but changes are not visible.
>
> Try moving several shapes and then layout.
> Does the diagram still remain the same?
>
> Regards,

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

Re: how use Layout and Style

Postby Tomas Pugzlys » Thu Mar 09, 2006 7:10 am

Hello,

I was able to reproduce your problem.

Ensure that diagram is opened and then perform layout.
The code is the following:
DiagramPresentationElement dpe = MD_project.getDiagram(diagrama);
dpe.close(); //test if this diagram close is needed
dpe.open();
if (dpe.layout(true,layout_jerarquica, options_jerarquica))
....

Hope this helps.

By the way I noticed that Crear_Presentacion_Elemento method
opens and closes session for every shape.
20 created shapes will result in 20 undo steps.

It is better for performance to create shapes in one session.

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363- IV, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple

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

Re: how use Layout and Style

Postby Raul Lorenzo » Thu Mar 09, 2006 9:50 am

Hello,

Thanks, I am sure this helps, It works!!!!
Why the diagram has to be open? I think, it shouldn´t be necesary....but
i don´t know how MagicDraw is implemented.....Anyway this workaround
simply helps me a lot.

Thanks about the observation of the performance, you are pointing me in
the right direction.

Thanks Again.

Tomas Pugzlys escribió:
> Hello,
>
> I was able to reproduce your problem.
>
> Ensure that diagram is opened and then perform layout.
> The code is the following:
> DiagramPresentationElement dpe = MD_project.getDiagram(diagrama);
> dpe.close(); //test if this diagram close is needed
> dpe.open();
> if (dpe.layout(true,layout_jerarquica, options_jerarquica))
> ....
>
> Hope this helps.
>
> By the way I noticed that Crear_Presentacion_Elemento method
> opens and closes session for every shape.
> 20 created shapes will result in 20 undo steps.
>
> It is better for performance to create shapes in one session.
>
> Regards,
You do not have the required permissions to view the files attached to this post.
Raul Lorenzo
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests