use of org.eclipse.elk.alg.graphviz.dot.dot.Graph in project elk by eclipse.
the class DotExporter method transform.
/**
* Transforms the KGraph instance to a Dot instance using the given command.
*
* @param transData the transformation data instance
*/
public void transform(final IDotTransformationData<ElkNode, GraphvizModel> transData) {
BiMap<String, ElkGraphElement> graphElems = HashBiMap.create();
transData.setProperty(GRAPH_ELEMS, graphElems);
ElkNode elkgraph = transData.getSourceGraph();
GraphvizModel graphvizModel = DotFactory.eINSTANCE.createGraphvizModel();
Graph graph = DotFactory.eINSTANCE.createGraph();
graph.setType(GraphType.DIGRAPH);
graphvizModel.getGraphs().add(graph);
transformNodes(elkgraph, graph.getStatements(), new KVector(), transData);
transformEdges(elkgraph, graph.getStatements(), transData);
transData.getTargetGraphs().add(graphvizModel);
}
use of org.eclipse.elk.alg.graphviz.dot.dot.Graph in project elk by eclipse.
the class DotExporter method transferLayout.
/**
* Applies the layout information attached to the given Dot instance to the KGraph instance
* using the mapping created by a previous call to {@code transform}. Has to be called after a
* call to {@code transform}.
*
* @param transData the transformation data instance
*/
public void transferLayout(final IDotTransformationData<ElkNode, GraphvizModel> transData) {
ElkPadding padding = transData.getSourceGraph().getProperty(CoreOptions.PADDING);
Graph graph = transData.getTargetGraphs().get(0).getGraphs().get(0);
// process nodes and subgraphs
KVector baseOffset = new KVector();
applyLayout(transData.getSourceGraph(), graph.getStatements(), baseOffset, padding, transData);
// finally process the edges
LinkedList<Statement> statements = new LinkedList<Statement>(graph.getStatements());
KVector edgeOffset = baseOffset.add(padding.getLeft(), padding.getTop());
while (!statements.isEmpty()) {
Statement statement = statements.removeFirst();
if (statement instanceof EdgeStatement) {
applyEdgeLayout((EdgeStatement) statement, edgeOffset, transData);
} else if (statement instanceof Subgraph) {
statements.addAll(((Subgraph) statement).getStatements());
}
}
}
use of org.eclipse.elk.alg.graphviz.dot.dot.Graph in project elk by eclipse.
the class DotImporter method transform.
/**
* Transform the GraphViz model into a KGraph.
*
* @param transData
* the transformation data instance that holds the source graph and is enriched with
* the new target graphs
*/
public void transform(final IDotTransformationData<GraphvizModel, ElkNode> transData) {
for (Graph graph : transData.getSourceGraph().getGraphs()) {
ElkNode parent = ElkGraphUtil.createGraph();
Map<String, ElkNode> nodeIdMap = Maps.newHashMap();
transData.setProperty(NODE_ID_MAP, nodeIdMap);
Map<Pair<ElkNode, String>, ElkPort> portIdMap = Maps.newHashMap();
transData.setProperty(PORT_ID_MAP, portIdMap);
transform(graph.getStatements(), parent, transData, new MapPropertyHolder(), new MapPropertyHolder());
transData.getTargetGraphs().add(parent);
parent.setProperty(PROP_GRAPH, graph);
}
}
use of org.eclipse.elk.alg.graphviz.dot.dot.Graph in project elk by eclipse.
the class AbstractGraphvizDotSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == DotPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case DotPackage.ATTRIBUTE:
if (rule == grammarAccess.getStatementRule() || rule == grammarAccess.getAttributeRule()) {
sequence_Attribute(context, (Attribute) semanticObject);
return;
} else if (rule == grammarAccess.getListAttributeRule()) {
sequence_ListAttribute(context, (Attribute) semanticObject);
return;
} else
break;
case DotPackage.ATTRIBUTE_STATEMENT:
sequence_AttributeStatement(context, (AttributeStatement) semanticObject);
return;
case DotPackage.EDGE_STATEMENT:
sequence_EdgeStatement(context, (EdgeStatement) semanticObject);
return;
case DotPackage.EDGE_TARGET:
sequence_EdgeTarget(context, (EdgeTarget) semanticObject);
return;
case DotPackage.GRAPH:
sequence_Graph(context, (Graph) semanticObject);
return;
case DotPackage.GRAPHVIZ_MODEL:
sequence_GraphvizModel(context, (GraphvizModel) semanticObject);
return;
case DotPackage.NODE:
sequence_Node(context, (Node) semanticObject);
return;
case DotPackage.NODE_STATEMENT:
sequence_NodeStatement(context, (NodeStatement) semanticObject);
return;
case DotPackage.PORT:
sequence_Port(context, (Port) semanticObject);
return;
case DotPackage.SUBGRAPH:
sequence_Subgraph(context, (Subgraph) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations