use of org.eclipse.elk.graph.ElkGraphElement in project elk by eclipse.
the class LayoutConfigurationManager method createConfigurator.
/**
* Create a layout configurator and initialize it with the option values from the given layout
* configuration store provider.
*/
public <T> LayoutConfigurator createConfigurator(final LayoutMapping layoutMapping) {
LayoutConfigurator result = new LayoutConfigurator();
if (configProvider != null) {
configureElement(layoutMapping.getLayoutGraph(), layoutMapping, result);
Iterator<ElkGraphElement> allElements = Iterators.filter(layoutMapping.getLayoutGraph().eAllContents(), ElkGraphElement.class);
while (allElements.hasNext()) {
ElkGraphElement element = allElements.next();
configureElement(element, layoutMapping, result);
}
}
return result;
}
use of org.eclipse.elk.graph.ElkGraphElement 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.graph.ElkGraphElement in project elk by eclipse.
the class ElkUtil method printElementPath.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DEBUGGING
/**
* Print information on the given graph element to the given string builder.
*/
public static void printElementPath(final ElkGraphElement element, final StringBuilder builder) {
// Print the containing element
if (element.eContainer() instanceof ElkGraphElement) {
printElementPath((ElkGraphElement) element.eContainer(), builder);
builder.append(" > ");
} else {
builder.append("Root ");
}
// Print the class name
String className = element.eClass().getName();
if (className.startsWith("Elk")) {
// CHECKSTYLEOFF MagicNumber
builder.append(className.substring(3));
// CHECKSTYLEON MagicNumber
} else {
builder.append(className);
}
// Print the identifier if present
String identifier = element.getIdentifier();
if (!Strings.isNullOrEmpty(identifier)) {
builder.append(' ').append(identifier);
return;
}
// Print the label if present
if (element instanceof ElkLabel) {
String text = ((ElkLabel) element).getText();
if (!Strings.isNullOrEmpty(text)) {
builder.append(' ').append(text);
return;
}
}
for (ElkLabel label : element.getLabels()) {
String text = label.getText();
if (!Strings.isNullOrEmpty(text)) {
builder.append(' ').append(text);
return;
}
}
// If it's an edge and no identifier nor label is present, print source and target
if (element instanceof ElkEdge) {
ElkEdge edge = (ElkEdge) element;
if (edge.isConnected()) {
builder.append(" (");
ListIterator<ElkConnectableShape> sourceIter = edge.getSources().listIterator();
while (sourceIter.hasNext()) {
if (sourceIter.nextIndex() > 0) {
builder.append(", ");
}
printElementPath(sourceIter.next(), builder);
}
builder.append(" -> ");
ListIterator<ElkConnectableShape> targetIter = edge.getTargets().listIterator();
while (targetIter.hasNext()) {
if (targetIter.nextIndex() > 0) {
builder.append(", ");
}
printElementPath(targetIter.next(), builder);
}
builder.append(")");
}
}
}
use of org.eclipse.elk.graph.ElkGraphElement in project elk by eclipse.
the class GmfLayoutEditPolicy method addLabelLayout.
/**
* Adds an edge label layout to the given command.
*
* @param command
* command to which the edge label layout shall be added
* @param klabel
* label with layout data
* @param labelEditPart
* edit part to which layout is applied
* @param scale
* scale factor for coordinates
*/
private void addLabelLayout(final GmfLayoutCommand command, final ElkLabel klabel, final GraphicalEditPart labelEditPart, final double scale) {
ElkGraphElement parent = klabel.getParent();
// node and port labels are processed separately
if (parent instanceof ElkNode || parent instanceof ElkPort) {
View view = (View) labelEditPart.getModel();
int xpos = (int) (klabel.getX() * scale);
int ypos = (int) (klabel.getY() * scale);
Object oldx = ViewUtil.getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X());
Object oldy = ViewUtil.getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y());
if (oldx == null || oldy == null || xpos != (Integer) oldx || ypos != (Integer) oldy) {
command.addShapeLayout(view, new Point(xpos, ypos), null);
}
return;
} else if (parent instanceof ElkEdge) {
// calculate direct new location of the label
Rectangle targetBounds = new Rectangle(labelEditPart.getFigure().getBounds());
targetBounds.x = (int) (klabel.getX() * scale);
targetBounds.y = (int) (klabel.getY() * scale);
ConnectionEditPart connectionEditPart = (ConnectionEditPart) labelEditPart.getParent();
PointList bendPoints = getBendPoints((ElkEdge) parent, connectionEditPart.getFigure(), scale);
EObject modelElement = connectionEditPart.getNotationView().getElement();
EdgeLabelPlacement labelPlacement = klabel.getProperty(CoreOptions.EDGE_LABELS_PLACEMENT);
// the list of bend points must be reversed
if (modelElement instanceof EReference && labelPlacement == EdgeLabelPlacement.TAIL) {
bendPoints = bendPoints.getCopy();
bendPoints.reverse();
}
// get the referencePoint for the label
int fromEnd, keyPoint = ConnectionLocator.MIDDLE;
if (labelEditPart instanceof LabelEditPart) {
keyPoint = ((LabelEditPart) labelEditPart).getKeyPoint();
}
switch(keyPoint) {
case ConnectionLocator.SOURCE:
fromEnd = SOURCE_LOCATION;
break;
case ConnectionLocator.TARGET:
fromEnd = TARGET_LOCATION;
break;
default:
fromEnd = MIDDLE_LOCATION;
break;
}
Point refPoint = PointListUtilities.calculatePointRelativeToLine(bendPoints, 0, fromEnd, true);
// get the new relative location
Point normalPoint = offsetFromRelativeCoordinate(targetBounds, bendPoints, refPoint);
if (normalPoint != null) {
command.addShapeLayout((View) labelEditPart.getModel(), normalPoint, null);
}
}
}
use of org.eclipse.elk.graph.ElkGraphElement in project elk by eclipse.
the class GraphIdentifierGenerator method assertAllIdsUnique.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Uniqueness
private GraphIdentifierGenerator assertAllIdsUnique(final EObject element) {
Set<String> knownIds = Sets.newHashSet();
Iterator<ElkGraphElement> elementIt = Iterators.filter(element.eAllContents(), ElkGraphElement.class);
while (elementIt.hasNext()) {
ElkGraphElement e = elementIt.next();
while (knownIds.contains(e.getIdentifier())) {
String newId = e.getIdentifier() + "_g" + fourDigitPaddedRandomNumber();
e.setIdentifier(newId);
}
knownIds.add(e.getIdentifier());
}
return this;
}
Aggregations