2

我正在编写一个绘制有限状态系统的 Eclipse 插件。由于它可能很大,我想附上一些现有的图形布局算法(例如分层布局、基于力的布局……),它们会自动优化系统可视化。

有没有办法集成我正在编写的插件(使用 GEF 编写),以便生成的编辑部分可以按照一些常见的图形布局算法放置在编辑器区域?

我发现了这篇有趣的文章,但它没有优化编辑部分的可视化,而是专注于绘制一个全新的图形。

到目前为止,我正在做的是添加以下代码(基于 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)trueGraphNode.getLocation()Point(0,0)

/**
 * 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来源:-[对我来说,我似乎无法使用热情图形库来完成这项工作。我错了吗?有其他选择吗?

任何帮助,将不胜感激 :)

4

1 回答 1

3

简而言之,Zest 并不直接支持这种场景。

但是,您可以为您编辑的部分构建一个内存表示,该表示可以使用 Zest 进行布局。在 Zest 1.0 中,您必须提供对 Graph Nodes 和 Graph 的翻译弧线手动关系;在Zest 2.0中,您只需提供一个 LayoutContext。Zest 2.0 尚未发布,但我似乎更容易处理这种情况。

附加想法:开源项目 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获取一些想法。

编辑:我查看了我电脑中的相关代码;我们设法通过以下方式让这种布局在 Zest 1.0 中工作:

  1. 每个节点都有一个 GraphNode,节点之间的每个弧都有一个 Connection。您可以将它们收集到两个不同的数组中;例如SimpleNode[] nodes; SimpleRelationship[] relationships;
  2. 实例化一个算法类,并根据需要设置可选参数。
  3. 致电algorithm.applyLayout(nodes, relationships, 0, 0, diagram.width, diagram.height, false, false)- 抱歉,没有可用的 Zest 1.0 安装来检查参数的确切含义;前两个是使用的节点和关系;然后接下来的四组画板;老实说,我不知道最后两个是为了什么。:D

进一步说明:Zest 使用节点和关系作为术语 - 用关系替换我之前的弧。

于 2012-01-16T21:34:50.517 回答