eclipse 插件 (gef) 和图形可视化 (zest)

2024-01-09

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

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

我找到了这个有趣的文章 http://www.vogella.de/articles/EclipseZest/article.html#zest_overview但它不是优化编辑部分的可视化,而是专注于绘制全新的图形。

到目前为止我正在做的是添加以下代码(基于 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(...) and completeGraph(...)。问题是:之后currGraph.setLayoutAlgorithm(..., true) that true意味着它应该应用算法并将对象按“正确”的顺序放置。此时(正如一些读者的建议),可以通过GraphNode.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() {
     ...
 }

in org.eclipse.zest.core.widgets.Graph来源:-[对我来说,我似乎无法使用 zest Graph 库来完成这项工作。我错了吗?还有其他选择吗?

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


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

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 Arcs Relations manually; in Zest 2.0 http://wiki.eclipse.org/index.php/Zest 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/热情/功能/ZestLayoutDiagramFeature.java 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一些想法。

EDIT:我在电脑中查看了相关代码;我们设法通过以下方式在 Zest 1.0 中实现此类布局:

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

eclipse 插件 (gef) 和图形可视化 (zest) 的相关文章

随机推荐