Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "GEF/GEF4/DOT"

< GEF‎ | GEF4
m
(DotAttributes)
 
(24 intermediate revisions by 3 users not shown)
Line 1: Line 1:
''Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in [http://wiki.eclipse.org/GEF/GEF4/DOT the original wiki page]''.
+
''Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in [http://wiki.eclipse.org/GEF/GEF4/DOT/User_Guide the original wiki page]''.
  
 
__NOTOC__
 
__NOTOC__
Line 8: Line 8:
 
* support for Graphviz-based generation of PDF-output for .dot files
 
* support for Graphviz-based generation of PDF-output for .dot files
 
* a [[GEF/GEF4/Zest | GEF4 Zest]]-based DOT Graph Viewer  
 
* a [[GEF/GEF4/Zest | GEF4 Zest]]-based DOT Graph Viewer  
* API to import/export DOT to/from [[GEF/GEF4/Graph | GEF4 Graph]] representations (which can be visualized with [[GEF/GEF4/Zest | GEF4 Zest]])
 
 
   
 
   
It is internally decomposed into two modules, namely [[#DOT|DOT]] and [[#DOT.UI|DOT.UI]]. There are also a couple of undeployed [[GEF/GEF4/DOT/Examples#Examples (undeployed)|DOT Examples]].
+
It is internally decomposed into two modules, namely [[#DOT|DOT]] and [[#DOT.UI|DOT.UI]]. There are also a couple of undeployed [[GEF/GEF4/DOT/Examples#Examples (undeployed)|DOT Examples]] that demonstrate usage of the (still internal) API. The user documentation is provided in terms of the [[GEF/GEF4/DOT/User Guide|GEF4 DOT User Guide]].
  
 
[[Image:GEF4-Components-DOT.png|600px]]
 
[[Image:GEF4-Components-DOT.png|600px]]
 
<small>This component was started as a [http://socghop.appspot.com/student_project/show/google/gsoc2009/eclipse/t124022230869 project] in the [[Google Summer of Code 2009]] by [[User:Steeg.netcologne.de|Fabian Steeg]], mentored by Ian Bull, for [[GEF Zest Visualization|Zest]]. It was initially included in Zest 2 and has finally been migrated to [[GEF/GEF4/DOT | GEF4 DOT]], being now based on [[GEF/GEF4/Graph | GEF4 Graph]], [[GEF/GEF4/Layout | GEF4 Layout]], and [[GEF/GEF4/Zest | GEF4 Zest]].</small>
 
  
 
----
 
----
  
== User Documentation ==
+
== DOT ==
  
This component adds a DOT editor and a ''DOT Graph'' view to the UI. The DOT editor can be used to edit [http://www.graphviz.org Graphviz] *.dot files, while the DOT Graph view allows to render them within Eclipse using [[GEF/GEF4/Zest | GEF4 Zest]], as well as to export them as PDF using the [http://www.graphviz.org/ Graphviz] native executable.  
+
*'''feature: org.eclipse.gef4.dot'''
 +
*'''bundle: org.eclipse.gef4.dot'''
  
Please note that the DOT editor and the [[GEF/GEF4/Zest | GEF4 Zest]]-based rendering of the DOT Graph view are currently still limited to support only a subset of the DOT language (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=454629 #454629], [https://bugs.eclipse.org/bugs/show_bug.cgi?id=321775 #321775], and [https://bugs.eclipse.org/bugs/show_bug.cgi?id=441352 #441352] for details).
+
The [[#DOT|DOT]] module of [[GEF/GEF4/DOT|GEF4 DOT]] realizes the serializer and parser for the 'DOT Editor' as well as import/export functionality used by the 'DOT Graph View' and the 'Sync Graphviz Export' end-user features, as outlined in the [[GEF/GEF4/DOT/User Guide | GEF4 DOT User Guide]]. It does not provide any public API (yet), but exposes its internal API (guarded by an x-friends directive).
  
=== DOT editor ===
+
<div id="DOT:Root"></div>
 +
=== {Root} ===  
  
The DOT editor is registered for *.dot files within the Eclipse Workbench UI. It is based on [https://www.eclipse.org/Xtext/ Xtext] and thus provides support for syntax coloring, content assist, and integrated validation, as well as a customized Outline view integration.
+
*'''package: org.eclipse.gef4.dot.internal'''
  
[[Image:DotEditor.png|892px]]
+
The [[#DOT:Root|{Root}]] package provides an importer ([[#DotImport|DotImport]]) and exporter ([[#DotExport|DotExport]]) between a Graphviz DOT and a related [[GEF/GEF4/Graph|GEF4 Graph]] representation. The imported or to be exported graph has to make use of the attributes defined in [[#DotAttributes|DotAttributes]].
  
The editor also provides a 'Sync Graphviz Export (PDF)' option (toggle button in the toolbar; using the default printer icon), which - if enabled - automatically stores a PDF file representing the saved state of the edited .dot file to the directory containing the .dot file, and opens it with the associated external PDF viewer, if one is available. The export relies on executing the native Graphviz dot binary. In this example, the export looks like this:
+
==== DotImport ====
 +
<code>DotImport</code> provides support for importing a Graphviz DOT into a [[GEF/GEF4/Graph|GEF4 Graph]] data model, using the attributes defined in [[#DotAttributes|DotAttributes]].
  
[[Image:DotZestM2Rendered.png|150px]]
+
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
 +
/* We can create Graphs based on Graphviz Dot files and strings */
 +
DotImport dotImport = new DotImport();
 +
Graph graph = dotImport.importDot("graph { 1--2 ; 1--3 }");
 +
Graph digraph = dotImport.importDot("digraph { 1->2 ; 1->3 }");
 +
</source>
  
=== DOT Graph view ===
+
Internally, <code>DotImport</code> is based on an [http://wiki.eclipse.org/Xtext Xtext]-based parser. It uses the generated Xtext switch API to dynamically create [[GEF/GEF4/Graph | GEF4 Graph]] graphs from the DOT abstract syntax tree (represented as an EMF model).
  
The DOT Graph view ('Window -> Show View -> Other... -> Visualization -> DOT Graph') can be used to visualize DOT graphs contained in *.dot files or embedded in other files, which are either explicitly loaded from the workspace, or synched with the .dot file currently being edited in the active DOT editor.
+
==== DotExport ====
 +
<code>DotExport</code> can be used to serialize a [[GEF/GEF4/Graph|GEF4 Graph]]-model, which uses the attributes defined in [[#DotAttributes|DotAttributes]] to a Graphviz DOT as follows:
  
The view draws the DOT graphs using [[GEF/GEF4/Zest | GEF4 Zest]] and allows for PDF export of the currently visualized Zest graph (based on the [http://www.graphviz.org/ Graphviz] executable).  
+
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
 +
/* Set up a directed graph with a single connection: */
 +
Graph graph = new Graph.Builder()
 +
.attr(DotAttributes._TYPE__G, DotAttributes._TYPE__G__GRAPH)
 +
.node("n1")
 +
.attr(DotAttributes._NAME__GNE, "1")
 +
.attr(DotAttributes.LABEL__GNE, "Node 1")
 +
.node("n2")
 +
.attr(DotAttributes._NAME__GNE, "2")
 +
.attr(DotAttributes.LABEL__GNE, "Node 2")
 +
.edge("n1", "n2")
 +
.attr(DotAttributes.LABEL__GNE, "A dotted edge")
 +
.attr(DotAttributes.STYLE__GNE, EdgeStyle.DOTTED.toString())
 +
.build();
  
For instance, consider a file with the .dot extension, containing the following DOT graph definition:
+
/* Export the graph to a DOT string or a DOT file: */
 +
System.out.println(new DotExport().exportDot(graph));
 +
</source>
  
digraph s{
+
Internally, <code>DotExport</code> is based on [https://www.eclipse.org/xtend/ Xtend] to keep its runtime dependencies minimal.
  n1[label="Node 1"]; n2[label="Node 2"];
+
  n1 -> n2[style=dotted label="A dotted edge"]
+
}
+
  
Loading it in the DOT Graph view will result in the following:
+
==== DotAttributes ====
 +
<code>DotAttributes</code> defines the (currently) supported [http://www.graphviz.org/doc/info/attrs.html Graphviz attributes]. It supports validation and parsing of all attribute values, using a dedicated attribute parser and validator where the attributes follow a specific grammar.
  
[[Image:GEF4-DOT-DotGraphView.png|642px]]
+
==== DotExecutableUtils ====
 +
<code>DotExecutableUtils</code> is a utility class that can be used to execute the native Graphviz DOT executable, which is internally used by the 'DOT Graph View'.
  
The DOT Graph view can be linked with the DOT editor to visualize the saved state of the currently edited .dot file (link mode):
+
In combination with [[#DotAttributes|DotAttributes]], <code>DotExecutableUtils</code> can e.g. be used to use the native Graphviz DOT executable for layout, as depicted in the [[GEF/GEF4/DOT/Examples#DotLayoutExample|DotLayoutExample]]:
  
[[Image:DotZestEditor.png|600px]]
+
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
 +
@Override
 +
public void applyLayout(boolean clean) {
 +
  // convert a Graph with LayoutAttributes (input model to ILayoutAlgorithm) into one with DotAttributes, which can be
 +
  // exported to a DOT string; keep track of converted nodes (as a side-effect)
 +
  final Map<Node, String> nodesToNameMap = new HashMap<>();
 +
  IAttributeCopier layout2DotAttributesConverter = new IAttributeCopier() {
 +
    int nodeIndex = 0;
  
It can further be used to display embedded DOT in other files, e.g. [http://fsteeg.wordpress.com/2010/01/07/visual-textual-documentation-with-dot-and-zest-in-eclipse/ in source code comments] or [http://fsteeg.wordpress.com/2010/02/07/diagrams-in-wiki-markup-with-mylyn-wikitext-dot-and-zest/ in wiki markup]:
+
    @Override
 +
    public void copy(IAttributeStore source, IAttributeStore target) {
 +
      if (source instanceof Node && target instanceof Node) {
 +
        // convert LayoutProperties#location to DotAttributes#pos (both refer to center locations)
 +
        Point location = LayoutProperties.getLocation((Node) source);
 +
        org.eclipse.gef4.dot.internal.parser.point.Point posParsed = PointFactory.eINSTANCE.createPoint();
 +
        posParsed.setX(location.x);
 +
        posParsed.setY(location.y);
 +
        DotAttributes.setPosParsed((Node) target, posParsed);
 +
        // provide unique names and keep track of the mapped nodes
 +
        DotAttributes._setName((Node) target, Integer.toString(++nodeIndex));
 +
        nodesToNameMap.put((Node) source, DotAttributes._getName((Node) target));
 +
      }
 +
    }
 +
  };
 +
  Graph dotGraph = new GraphCopier(layout2DotAttributesConverter).copy(context.getGraph());
  
[[Image:DotZestWikiText.png|600px]]
+
  // set graph type
 +
  DotAttributes._setType(dotGraph, DotAttributes._TYPE__G__DIGRAPH);
  
This provides a [[GEF/GEF4/Zest|GEF4 Zest]]-based DOT authoring environment. If a *.dot file or embedded DOT is edited, it will be visualized in the DOT Graph view, and can be exported as a PDF with Graphviz. At the same time the view provides a simple way to visualize *.dot file output of any kind of program, e.g. to visualize and debug internal data structures, results, etc: if a program running in Eclipse outputs any *.dot file in the workspace and the workspace is refreshed, the view will be updated with the corresponding Zest graph.
+
  // specify layout algorithm
 +
  DotAttributes.setLayout(dotGraph, Layout.CIRCO.toString());
  
----
+
  // export the dot string and call the dot executable to add layout info to it.
 +
  DotExport dotExport = new DotExport();
 +
  String dot = dotExport.exportDot(dotGraph);
 +
  File tmpFile = DotFileUtils.write(dot);
 +
  String[] dotResult = DotExecutableUtils.executeDot(new File(dotExecutablePath), true, tmpFile, null, null);
 +
  if (!dotResult[1].isEmpty()) {
 +
    System.err.println(dotResult[1]);
 +
  }
 +
  tmpFile.delete();
 +
  Graph layoutedDotGraph = new DotImport().importDot(dotResult[0]);
  
== DOT ==
+
  // transfer the DOT provided position information back to the input Graph
 
+
  for (Node target : context.getGraph().getNodes()) {
*'''feature: org.eclipse.gef4.dot'''
+
    String nodeName = nodesToNameMap.get(target);
*'''bundle: org.eclipse.gef4.dot'''
+
    for (Node source : layoutedDotGraph.getNodes()) {
 
+
      if (nodeName.equals(DotAttributes._getName(source))) {
The [[#DOT|DOT]] module of [[GEF/GEF4/DOT|GEF4 DOT]] provides support for importing ([[#DotImport|DotImport]]) and exporting ([[#DotExport|DotExport]]) Graphviz DOT to/from a [[GEF/GEF4/Graph|GEF4 Graph]]-based model. The [[GEF/GEF4/Graph|GEF4 Graph]]-based model uses Graphviz specific properties, which are defined in [[#DotProperties|DotProperties]].
+
        // convert back DotAttributes#pos to LayoutProperties#location
 
+
        org.eclipse.gef4.dot.internal.parser.point.Point posParsed = DotAttributes.getPosParsed(source);
<div id="DOT:Root"></div>
+
        LayoutProperties.setLocation(target, new Point(posParsed.getX(), posParsed.getY()));
=== {Root} ===
+
break;
 
+
      }
*'''package: org.eclipse.gef4.dot'''
+
    }
 
+
  }
The [[#DOT:Root|{Root}]] package provides an importer ([[#DotImport|DotImport]]) and exporter ([[#DotExport|DotExport]]) between a Graphviz DOT and a related [[GEF/GEF4/Graph|GEF4 Graph]] representation. The imported or to be exported graph has to make use of the  properties defined in [[#DotProperties|DotProperties]].
+
}
 
+
[[File:GEF4-DOT-root.png|818px]]
+
 
+
==== DotImport ====
+
<code>DotImport</code> provides support for importing a Graphviz DOT into a [[GEF/GEF4/Graph|GEF4 Graph]] data model, using the properties defined in [[#DotProperties|DotProperties]].
+
 
+
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
+
/* We can create Graphs based on Graphviz Dot files and strings */
+
Graph graph = new DotImport("graph { 1--2 ; 1--3 }").newGraphInstance();
+
Graph digraph = new DotImport("digraph { 1->2 ; 1->3 }").newGraphInstance();
+
+
/* We can also import Graphviz Dot files/string into an existing graph */
+
Graph.Builder graph2 = new Graph.Builder();
+
new DotImport("digraph{1->2}").into(graph2);
+
new DotImport("node[label=zested]; 2->3; 2->4").into(graph2);
+
new DotImport("edge[style=dashed]; 3->5; 4->6").into(graph2);
+
 
</source>
 
</source>
<small>The complete sample usage is available in the [http://git.eclipse.org/c/gef/org.eclipse.gef4.git/tree/org.eclipse.gef4.dot.examples/src/org/eclipse/gef4/dot/examples/ repository], more input samples can be found [http://git.eclipse.org/c/gef/org.eclipse.gef4.git/tree/org.eclipse.gef4.dot.tests/resources/ here].</small>
 
  
Internally, <code>DotImport</code> is based on an [http://wiki.eclipse.org/Xtext Xtext]-based parser. It uses the generated Xtext switch API to dynamically create [[GEF/GEF4/Graph | GEF4 Graph]] graphs from the DOT abstract syntax tree (represented as an EMF model).
+
----
  
==== DotExport ====
+
== DOT.UI ==
<code>DotExport</code> can be used to serialize a [[GEF/GEF4/Graph|GEF4 Graph]]-model, which uses the properties defined in [[#DotProperties|DotProperties]] to a Graphviz DOT as follows:
+
  
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
+
*'''feature: org.eclipse.gef4.dot.internal.ui'''
/* Create a directed graph, making use of DotProperties */
+
*'''bundle: org.eclipse.gef4.dot.internal.ui'''
Graph.Builder graph = new Graph.Builder();
+
Node node1 = new Node.Builder().attr(DotProperties.NODE_ID, "1").attr(DotProperties.NODE_LABEL, "Node 1").build();
+
Node node2 = new Node.Builder().attr(DotProperties.NODE_ID, "2").attr(DotProperties.NODE_LABEL, "Node 2").build();
+
Edge edge = new Edge.Builder(node1, node2).attr(DotProperties.EDGE_LABEL, "A dotted edge").attr(DotProperties.EDGE_STYLE, DotProperties.EDGE_STYLE_DOTTED).build();
+
graph.attr(DotProperties.GRAPH_TYPE, DotProperties.GRAPH_TYPE_DIRECTED.nodes(node1, node2).edges(edge);
+
  
/* Export the graph to a DOT string (or a DOT file) */
+
The [[#DOT.UI|DOT.UI]] module of [[GEF/GEF4/DOT|GEF4 DOT]] realizes the DOT editor as well as the DOT Graph View as end-user features, as outlined in the [[GEF/GEF4/DOT/User Guide | GEF4 DOT User Guide]]. It does not provide any public API (yet), but exposes its internal API (guarded by an x-friends directive).
DotExport dotExport = new DotExport(graph.build());
+
System.out.println(dotExport.toDotString());
+
</source>
+
  
Internally, <code>DotExport</code> is based on [http://wiki.eclipse.org/M2T-JET JET] to keep its runtime dependencies minimal.
+
<div id="DOT.UI:Root"></div>
 +
=== {Root} ===
  
==== DotProperties ====
+
*'''package: org.eclipse.gef4.dot.internal.ui'''
<code>DotProperties</code> defines the (currently) supported [http://www.graphviz.org/doc/info/attrs.html Graphviz attributes].
+
  
----
+
The [[#DOT.UI:Root|{Root}]] package provides [[GEF/GEF4/Common#IAttributeCopier|org.eclipse.gef4.common.attributes.IAttributeCopier]] implementations that can be used to transfer attributes defined by [[#DotAttributes|DotAttributes]] into those defined by [[GEF/GEF4/Zest#ZestProperties|org.eclipse.gef4.zest.fx.ZestProperties]].
  
== DOT.UI ==
+
==== Dot2ZestAttributesConverter, Zest2DotAttributesConverter ====
 +
<code>Dot2ZestAttributesConverter</code> and <code>Zest2DotAttributesConverter</code> are [[GEF/GEF4/Common#IAttributeCopier|org.eclipse.gef4.common.attributes.IAttributeCopier]] implementations that allow to convert between attributes defined by [[#DotAttributes|DotAttributes]] and [[GEF/GEF4/Zest#ZestProperties|org.eclipse.gef4.zest.fx.ZestProperties]]. This is internally used by the 'DOT Graph View' to render a DOT input based on [[GEF/GEF4/Zest|Zest]].
  
*'''feature: org.eclipse.gef4.dot.ui'''
+
==== DotBSplineInterpolator ====
*'''bundle: org.eclipse.gef4.dot.ui'''
+
The <code>DotBSplineInterpolator</code> is a specific [[GEF/GEF4/FX#IConnectionInterpolator|IConnectionInterpolator]] that can be used to properly render B-Splines as DOT specifies them for edge positions.
  
The [[#DOT.UI|DOT.UI]] module of [[GEF/GEF4/DOT|GEF4 DOT]] realizes the DOT editor as well as the DOT Graph viewer as end-user features. It does not provide any public API.
+
==== DotArrowShapeDecorations ====
 +
The <code>DotArrowShapeDecorations</code> utility class provides implementations for the different arrow shape edge decorations supported by DOT.
  
 
[[Category:GEF]]
 
[[Category:GEF]]

Latest revision as of 08:58, 28 May 2016

Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in the original wiki page.


Introduction

The GEF4 DOT component provides support for Graphviz DOT, in terms of

  • an Xtext-based .dot file editor
  • support for Graphviz-based generation of PDF-output for .dot files
  • a GEF4 Zest-based DOT Graph Viewer

It is internally decomposed into two modules, namely DOT and DOT.UI. There are also a couple of undeployed DOT Examples that demonstrate usage of the (still internal) API. The user documentation is provided in terms of the GEF4 DOT User Guide.

GEF4-Components-DOT.png


DOT

  • feature: org.eclipse.gef4.dot
  • bundle: org.eclipse.gef4.dot

The DOT module of GEF4 DOT realizes the serializer and parser for the 'DOT Editor' as well as import/export functionality used by the 'DOT Graph View' and the 'Sync Graphviz Export' end-user features, as outlined in the GEF4 DOT User Guide. It does not provide any public API (yet), but exposes its internal API (guarded by an x-friends directive).

{Root}

  • package: org.eclipse.gef4.dot.internal

The {Root} package provides an importer (DotImport) and exporter (DotExport) between a Graphviz DOT and a related GEF4 Graph representation. The imported or to be exported graph has to make use of the attributes defined in DotAttributes.

DotImport

DotImport provides support for importing a Graphviz DOT into a GEF4 Graph data model, using the attributes defined in DotAttributes.

/* We can create Graphs based on Graphviz Dot files and strings */
DotImport dotImport = new DotImport();
Graph graph = dotImport.importDot("graph { 1--2 ; 1--3 }");
Graph digraph = dotImport.importDot("digraph { 1->2 ; 1->3 }");

Internally, DotImport is based on an Xtext-based parser. It uses the generated Xtext switch API to dynamically create GEF4 Graph graphs from the DOT abstract syntax tree (represented as an EMF model).

DotExport

DotExport can be used to serialize a GEF4 Graph-model, which uses the attributes defined in DotAttributes to a Graphviz DOT as follows:

/* Set up a directed graph with a single connection: */
Graph graph = new Graph.Builder()
.attr(DotAttributes._TYPE__G, DotAttributes._TYPE__G__GRAPH)
.node("n1")
.attr(DotAttributes._NAME__GNE, "1")
.attr(DotAttributes.LABEL__GNE, "Node 1")
.node("n2")
.attr(DotAttributes._NAME__GNE, "2")
.attr(DotAttributes.LABEL__GNE, "Node 2")
.edge("n1", "n2")
.attr(DotAttributes.LABEL__GNE, "A dotted edge")
.attr(DotAttributes.STYLE__GNE, EdgeStyle.DOTTED.toString())
.build();
 
/* Export the graph to a DOT string or a DOT file: */
System.out.println(new DotExport().exportDot(graph));

Internally, DotExport is based on Xtend to keep its runtime dependencies minimal.

DotAttributes

DotAttributes defines the (currently) supported Graphviz attributes. It supports validation and parsing of all attribute values, using a dedicated attribute parser and validator where the attributes follow a specific grammar.

DotExecutableUtils

DotExecutableUtils is a utility class that can be used to execute the native Graphviz DOT executable, which is internally used by the 'DOT Graph View'.

In combination with DotAttributes, DotExecutableUtils can e.g. be used to use the native Graphviz DOT executable for layout, as depicted in the DotLayoutExample:

@Override
public void applyLayout(boolean clean) {
  // convert a Graph with LayoutAttributes (input model to ILayoutAlgorithm) into one with DotAttributes, which can be
  // exported to a DOT string; keep track of converted nodes (as a side-effect)
  final Map<Node, String> nodesToNameMap = new HashMap<>();
  IAttributeCopier layout2DotAttributesConverter = new IAttributeCopier() {
    int nodeIndex = 0;
 
    @Override
    public void copy(IAttributeStore source, IAttributeStore target) {
      if (source instanceof Node && target instanceof Node) {
        // convert LayoutProperties#location to DotAttributes#pos (both refer to center locations)
        Point location = LayoutProperties.getLocation((Node) source);
        org.eclipse.gef4.dot.internal.parser.point.Point posParsed = PointFactory.eINSTANCE.createPoint();
        posParsed.setX(location.x);
        posParsed.setY(location.y);
        DotAttributes.setPosParsed((Node) target, posParsed);
        // provide unique names and keep track of the mapped nodes
        DotAttributes._setName((Node) target, Integer.toString(++nodeIndex));
        nodesToNameMap.put((Node) source, DotAttributes._getName((Node) target));
      }
    }			
  };			 
  Graph dotGraph = new GraphCopier(layout2DotAttributesConverter).copy(context.getGraph());
 
  // set graph type
  DotAttributes._setType(dotGraph, DotAttributes._TYPE__G__DIGRAPH);
 
  // specify layout algorithm
  DotAttributes.setLayout(dotGraph, Layout.CIRCO.toString());
 
  // export the dot string and call the dot executable to add layout info to it.
  DotExport dotExport = new DotExport();
  String dot = dotExport.exportDot(dotGraph);
  File tmpFile = DotFileUtils.write(dot);
  String[] dotResult = DotExecutableUtils.executeDot(new File(dotExecutablePath), true, tmpFile, null, null);
  if (!dotResult[1].isEmpty()) {
    System.err.println(dotResult[1]);
  }
  tmpFile.delete();
  Graph layoutedDotGraph = new DotImport().importDot(dotResult[0]);
 
  // transfer the DOT provided position information back to the input Graph
  for (Node target : context.getGraph().getNodes()) {
    String nodeName = nodesToNameMap.get(target);
    for (Node source : layoutedDotGraph.getNodes()) {
      if (nodeName.equals(DotAttributes._getName(source))) {
        // convert back DotAttributes#pos to LayoutProperties#location
        org.eclipse.gef4.dot.internal.parser.point.Point posParsed = DotAttributes.getPosParsed(source);
        LayoutProperties.setLocation(target, new Point(posParsed.getX(), posParsed.getY()));
	break;
      }
    }
  }
}

DOT.UI

  • feature: org.eclipse.gef4.dot.internal.ui
  • bundle: org.eclipse.gef4.dot.internal.ui

The DOT.UI module of GEF4 DOT realizes the DOT editor as well as the DOT Graph View as end-user features, as outlined in the GEF4 DOT User Guide. It does not provide any public API (yet), but exposes its internal API (guarded by an x-friends directive).

{Root}

  • package: org.eclipse.gef4.dot.internal.ui

The {Root} package provides org.eclipse.gef4.common.attributes.IAttributeCopier implementations that can be used to transfer attributes defined by DotAttributes into those defined by org.eclipse.gef4.zest.fx.ZestProperties.

Dot2ZestAttributesConverter, Zest2DotAttributesConverter

Dot2ZestAttributesConverter and Zest2DotAttributesConverter are org.eclipse.gef4.common.attributes.IAttributeCopier implementations that allow to convert between attributes defined by DotAttributes and org.eclipse.gef4.zest.fx.ZestProperties. This is internally used by the 'DOT Graph View' to render a DOT input based on Zest.

DotBSplineInterpolator

The DotBSplineInterpolator is a specific IConnectionInterpolator that can be used to properly render B-Splines as DOT specifies them for edge positions.

DotArrowShapeDecorations

The DotArrowShapeDecorations utility class provides implementations for the different arrow shape edge decorations supported by DOT.

Back to the top