问题描述
我正在编写一个绘制有限状态系统的eclipse插件.由于它可能很大,因此我想附加一些现有的图形布局算法(例如,层次布局,基于力的布局等),以自动优化系统可视化效果.
i'm writing an eclipse plugin that draws a finite state system. since it may be large, i'd like to attach some existing graph layout algorithm (e.g. hierarchical layout, force-based layout, ...) that automatically optimize the system visualization.
是否有一种方法可以集成我正在编写的插件(使用GEF编写),以便可以按照某些常见的图形布局算法将生成的编辑部分放置在编辑器区域中?
is there a way to integrate the plugin i'm writing (written using GEF) so that generated edit parts could be place on the editor area following some of the common graph layout algorithms?
我找到了有趣的文章,但是没有优化编辑零件可视化,它着重于绘制一个全新的图形.
i've found this interesting article but instead of optimizing edit parts visualization, it focuses on drawing a completely new graph.
到目前为止,我正在做的是添加以下代码(基于Zest 1)
so far what I'm doing is adding the following code (based on Zest 1)
private static void createNewGraph(String autName) {
Shell tmpShell = new Shell();
currGraph = new Graph(tmpShell, SWT.NONE);
mapStateAndNodes = new HashMap<State, GraphNode>();
}
private static void addGraphNode(State currState)
{
GraphNode newNode = new GraphNode(currGraph, SWT.NONE, currState.getName());
mapStateAndNodes.put(currState, newNode);
}
private static void addGraphConnection(Transition currTrans)
{
GraphNode source = mapStateAndNodes.get(currTrans.getOrigState());
GraphNode dest = mapStateAndNodes.get(currTrans.getDestState());
GraphConnection newConn = new GraphConnection(currGraph, SWT.NONE, source, dest);
}
private static void completeGraph()
{
currGraph.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
}
在构建模型时,我还调用了createNewGraph(...)
,addGraphNode(...)
,addGraphConnection(...)
和completeGraph(...)
.问题是:在currGraph.setLayoutAlgorithm(..., true)
之后,true
表示应应用算法并将对象按正确"的顺序放置.此时(如某些读者所建议),可以通过GraphNode.getLocation()
方法提取计算出的坐标.不幸的是,在设置布局并应用它之后,所有状态都将Point(0,0)
作为其位置.我也发现了这个评论:
and while building my model, I also call createNewGraph(...)
, addGraphNode(...)
, addGraphConnection(...)
and completeGraph(...)
. the problem is: after currGraph.setLayoutAlgorithm(..., true)
that true
means it should apply the algorithm and place the objects in the "right" order. at this point (as suggested from some reader), it is possible to extract the computed coordinates through a GraphNode.getLocation()
method. unfortunately after setting a layout and applying it, all the states have Point(0,0)
as their location. i also found this comment:
/**
* Runs the layout on this graph. It uses the reveal listener to run the
* layout only if the view is visible. Otherwise it will be deferred until
* after the view is available.
*/
public void applyLayout() {
...
}
在org.eclipse.zest.core.widgets.Graph
来源中的
:-[对我来说,我似乎无法使用zest图形库来完成这项工作.我错了吗?有其他选择吗?
in org.eclipse.zest.core.widgets.Graph
sources :-[ to me it seems i cannot use zest Graph library to do this job. am i wrong? are there any alternatives?
任何帮助将不胜感激:)
any help would be appreciated :)
推荐答案
简而言之,Zest不直接支持此方案.
In short, Zest does not support this scenario directly.
但是,您可以构建内存中的表示形式,以编辑可以使用Zest进行布局的零件.在Zest 1.0中,您必须手动提供对图节点和图关系的转换;在 Zest 2.0 中,您只需提供LayoutContext. Zest 2.0尚未发布,但对我来说似乎更容易处理这种情况.
However, you can build an in-memory representation of you edit parts that can be layouted using Zest. In Zest 1.0 you have to provide a translation to Graph Nodes and Graph Relations manually; in Zest 2.0 you only have to provide a LayoutContext. Zest 2.0 is not released yet, but it seems easier for me to handle this scenario.
其他想法:开源项目Spray支持Graphiti图的Zest布局(Graphiti扩展了GEF-也许有些想法可以重用).请参阅以下代码文件: http://code.google.com/a/eclipselabs.org/p/spray/source/browse/plugins /org.eclipselabs.spray.runtime.graphiti.zest/src/org/eclipselabs/spray/runtime/graphiti/zest/features/ZestLayoutDiagramFeature.java 中的一些想法.
Additional idea: the open source project Spray support Zest layouting for Graphiti graphs (Graphiti extends GEF - maybe there are some ideas that can be reused). See the following code file: http://code.google.com/a/eclipselabs.org/p/spray/source/browse/plugins/org.eclipselabs.spray.runtime.graphiti.zest/src/org/eclipselabs/spray/runtime/graphiti/zest/features/ZestLayoutDiagramFeature.java for some ideas.
编辑:我在计算机上查看了相关代码;我们设法通过以下方式使这种布局在Zest 1.0中工作:
I looked into a related code in my computer; we managed to get such layouting to work in Zest 1.0 the following way:
- 每个节点都有一个GraphNode,节点之间的每个弧都有一个Connection.您可以将它们收集到两个不同的阵列中.例如
SimpleNode[] nodes; SimpleRelationship[] relationships;
- 实例化算法类,并根据需要设置可选参数.
- 致电
algorithm.applyLayout(nodes, relationships, 0, 0, diagram.width, diagram.height, false, false)
-抱歉,没有可用的Zest 1.0安装程序来检查参数的确切含义;前两个是使用的节点和关系;然后接下来的四套绘图板;老实说,我不知道最后两个是做什么的. :D
- Have a single GraphNode for each node, and a Connection for each arc between the nodes. You can collect them into two different arrays; e.g.
SimpleNode[] nodes; SimpleRelationship[] relationships;
- Instantiate an algorithm class, and set your optional parameters as you like.
- Call
algorithm.applyLayout(nodes, relationships, 0, 0, diagram.width, diagram.height, false, false)
- sorry, don't have an available Zest 1.0 installation to check the exact meanings of the parameters; the first two are the nodes and relationships used; then the next four sets the drawing board; and I honestly have no idea what are the final two for. :D
进一步说明:Zest使用节点和关系作为术语-用关系替换我以前的弧.
Further clarification: Zest uses nodes and relations as a terminology - replace my previous arc with relation.
这篇关于eclipse插件(gef)和图形可视化(zest)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!