Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Using Zest LayoutAlgorithm in Graphiti
Using Zest LayoutAlgorithm in Graphiti [message #757201] Wed, 16 November 2011 23:45 Go to next message
Patrick Talbot is currently offline Patrick Talbot
Messages: 36
Registered: November 2011
Member
I am new to Graphiti and like it a lot so far.

Please excuse me if this topic was already addressed somewhere, I couldn't find anything though in the tutorial nor on this forum...

I would like to use Zest's LayoutAlgorithm in an auto layout Feature in Graphiti.

I've seen the FAQ about integrating an arbitrary automatic layouter and have tested the TutorialLayoutDiagramFeature, but I'm unsure how this relates to Zest LayoutAlgorithmn.

Will I have to create an offscreen GraphViewer and layout my elements there, getting back the coordinates to feed the Graphiti Diagram? Or is there any way to use LayoutAlgorithmn directly in Graphiti?

Has anyone here ever achieved something like that and if so, could you tell me more?
Any pointers will be greatly appreciated!

Thanks in advance,
-Patrick
Re: Using Zest LayoutAlgorithm in Graphiti [message #757698 is a reply to message #757201] Mon, 21 November 2011 04:44 Go to previous messageGo to next message
Joerg Reichert is currently offline Joerg Reichert
Messages: 78
Registered: July 2009
Location: Leipzig
Member
Hi Patrick,

I think you have to map
* the org.eclipse.graphiti.mm.pictograms.Diagram to org.to the org.eclipse.draw2d.graph.CompoundDirectedGraph, like shown in the TutorialLayoutDiagramFeature.java
* map the org.eclipse.draw2d.graph.CompoundDirectedGraph to org.eclipse.zest.core.widgets.Graph
* org.eclipse.draw2d.graph.Node -> org.eclipse.zest.core.widgets.GraphNode
* org.eclipse.draw2d.graph.Edge -> org.eclipse.zest.core.widgets.GraphConnection
* apply the Zest layout algorithm, e.g.

graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);


* map the org.eclipse.zest.core.widgets.Graph back to org.eclipse.draw2d.graph.CompoundDirectedGraph
* map the org.eclipse.draw2d.graph.CompoundDirectedGraph back to org.eclipse.graphiti.mm.pictograms.Diagram

I think you can even skip the mapping to CompoundDirectedGraph and map the Diagram directly to Graph, as org.eclipse.zest.core.widgets.GraphNode has a method getLocation() : Point, where you can map the coordinates.

http://wiki.eclipse.org/GEF_Zest_Visualization

Regards,
Joerg


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: Using Zest LayoutAlgorithm in Graphiti [message #757789 is a reply to message #757698] Mon, 21 November 2011 12:09 Go to previous messageGo to next message
Patrick Talbot is currently offline Patrick Talbot
Messages: 36
Registered: November 2011
Member
Thanks for your reply Joerg!

In the end I did it a little bit differently, using the LayoutAlgorithmn applyLayout method directly. This works very nicely though.

See attached my implementation in case others are interested.

Best,
-Patrick
Re: Using Zest LayoutAlgorithm in Graphiti [message #758573 is a reply to message #757789] Wed, 23 November 2011 12:56 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

Hi Patrick!

This looks promising. I will try to use your layout feature in my current project, and if it is like I expect, I would like to add it to the Spray project.

~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Using Zest LayoutAlgorithm in Graphiti [message #758628 is a reply to message #758573] Wed, 23 November 2011 18:41 Go to previous message
Patrick Talbot is currently offline Patrick Talbot
Messages: 36
Registered: November 2011
Member
No problem, go ahead.

You will probably have to add some check of instanceof Connection: in my case I'm using FreeFormConnection so I didn't code for ManhattanConnection, but it should be easy to change.
Previous Topic:Best practice for own Shapes?
Next Topic:Text foreground color always red?
Goto Forum:
  


Current Time: Fri Aug 29 06:23:25 EDT 2014

Powered by FUDForum. Page generated in 0.02963 seconds