Search in sources :

Example 1 with InternalRelationship

use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.

the class DirectedGraphLayoutAlgorithm method applyLayoutInternal.

@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
    HashMap mapping = new HashMap(entitiesToLayout.length);
    DirectedGraph graph = new DirectedGraph();
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode internalNode = entitiesToLayout[i];
        Node node = new Node(internalNode);
        node.setSize(new Dimension(10, 10));
        mapping.put(internalNode, node);
        graph.nodes.add(node);
    }
    for (int i = 0; i < relationshipsToConsider.length; i++) {
        InternalRelationship relationship = relationshipsToConsider[i];
        Node source = (Node) mapping.get(relationship.getSource());
        Node dest = (Node) mapping.get(relationship.getDestination());
        Edge edge = new Edge(relationship, source, dest);
        graph.edges.add(edge);
    }
    DirectedGraphLayout directedGraphLayout = new ExtendedDirectedGraphLayout();
    directedGraphLayout.visit(graph);
    for (Iterator iterator = graph.nodes.iterator(); iterator.hasNext(); ) {
        Node node = (Node) iterator.next();
        InternalNode internalNode = (InternalNode) node.data;
        // For horizontal layout transpose the x and y coordinates
        if ((layout_styles & SWT.HORIZONTAL) == SWT.HORIZONTAL) {
            internalNode.setInternalLocation(node.y, node.x);
        } else {
            internalNode.setInternalLocation(node.x, node.y);
        }
    }
    updateLayoutLocations(entitiesToLayout);
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) DirectedGraph(org.eclipse.draw2d.graph.DirectedGraph) DirectedGraphLayout(org.eclipse.draw2d.graph.DirectedGraphLayout) HashMap(java.util.HashMap) Node(org.eclipse.draw2d.graph.Node) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Iterator(java.util.Iterator) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Dimension(org.eclipse.draw2d.geometry.Dimension) Edge(org.eclipse.draw2d.graph.Edge)

Example 2 with InternalRelationship

use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.

the class SpringLayoutAlgorithm method preLayoutAlgorithm.

@Override
protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height) {
    // TODO: Filter out any non-wanted entities and relationships
    // super.applyLayout(entitiesToLayout, relationshipsToConsider, x, y,
    // width, height);
    // InternalNode[] a_entitiesToLayout = (InternalNode[]) entitiesToLayout.toArray(new InternalNode[entitiesToLayout.size()]);
    bounds = new DisplayIndependentRectangle(x, y, width, height);
    tempLocationsX = new double[entitiesToLayout.length];
    tempLocationsY = new double[entitiesToLayout.length];
    forcesX = new double[entitiesToLayout.length];
    forcesY = new double[entitiesToLayout.length];
    anchors = new boolean[entitiesToLayout.length];
    for (int i = 0; i < entitiesToLayout.length; i++) {
        anchors[i] = DEFAULT_ANCHOR;
    }
    for (int i = 0; i < relationshipsToConsider.length; i++) {
        InternalRelationship layoutRelationship = relationshipsToConsider[i];
        addRelation(layoutRelationship);
    }
    // do the calculations
    preCompute(entitiesToLayout);
    startTime = date.getTime();
}
Also used : DisplayIndependentRectangle(org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle) InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship)

Example 3 with InternalRelationship

use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.

the class AbstractLayoutAlgorithm method convertPositionsToCoords.

/**
 * Convert the positions from a percentage of bounds area to fixed
 * coordinates. NOTE: ALL OF THE POSITIONS OF NODES UNTIL NOW WERE FOR THE
 * CENTER OF THE NODE - Convert it to the left top corner.
 *
 * @param entitiesToLayout
 * @param relationships
 * @param realBounds
 */
private void convertPositionsToCoords(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, DisplayIndependentRectangle screenBounds) {
    // Adjust node positions and sizes
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode node = entitiesToLayout[i];
        double width = node.getInternalWidth() * screenBounds.width;
        double height = node.getInternalHeight() * screenBounds.height;
        DisplayIndependentPoint location = node.getInternalLocation().convertFromPercent(screenBounds);
        node.setInternalLocation(location.x - width / 2, location.y - height / 2);
        if (resizeEntitiesAfterLayout) {
            adjustNodeSizeAndPos(node, height, width);
        } else {
            node.setInternalSize(width, height);
        }
    }
    // Adjust bendpoint positions and shift based on source node size
    for (int i = 0; i < relationships.length; i++) {
        InternalRelationship rel = relationships[i];
        for (int j = 0; j < rel.getBendPoints().size(); j++) {
            BendPoint bp = (BendPoint) rel.getBendPoints().get(j);
            DisplayIndependentPoint fromPercent = bp.convertFromPercent(screenBounds);
            bp.setX(fromPercent.x);
            bp.setY(fromPercent.y);
        }
    }
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint)

Example 4 with InternalRelationship

use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.

the class AbstractLayoutAlgorithm method convertPositionsToPercentage.

/**
 * Convert all node positions into a percentage of the screen. If includeNodeSize
 * is true then this also updates the node's internal size.
 * @param entitiesToLayout
 */
private void convertPositionsToPercentage(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, DisplayIndependentRectangle layoutBounds, boolean includeNodeSize) {
    // Adjust node positions and sizes
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode node = entitiesToLayout[i];
        DisplayIndependentPoint location = node.getInternalLocation().convertToPercent(layoutBounds);
        node.setInternalLocation(location.x, location.y);
        if (includeNodeSize) {
            // adjust node sizes
            double width = node.getInternalWidth() / layoutBounds.width;
            double height = node.getInternalHeight() / layoutBounds.height;
            node.setInternalSize(width, height);
        }
    }
    // Adjust bendpoint positions
    for (int i = 0; i < relationships.length; i++) {
        InternalRelationship rel = relationships[i];
        for (int j = 0; j < rel.getBendPoints().size(); j++) {
            BendPoint bp = (BendPoint) rel.getBendPoints().get(j);
            DisplayIndependentPoint toPercent = bp.convertToPercent(layoutBounds);
            bp.setX(toPercent.x);
            bp.setY(toPercent.y);
        }
    }
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint)

Example 5 with InternalRelationship

use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.

the class AbstractLayoutAlgorithm method updateRelationships.

/**
 * Updates the given array of relationships checking if any need to be removed or added.
 * Also updates the original array of relationships.
 * @param relationships the current relationships
 * @return the update relationships array
 */
protected InternalRelationship[] updateRelationships(InternalRelationship[] relationships) {
    if ((relationshipsToRemove.size() > 0) || (relationshipsToAdd.size() > 0)) {
        List internalRelsList = new ArrayList(Arrays.asList(relationships));
        // remove relationships
        if (relationshipsToRemove.size() > 0) {
            for (Iterator iter = relationshipsToRemove.iterator(); iter.hasNext(); ) {
                LayoutRelationship relation = (LayoutRelationship) iter.next();
                if (relation.getLayoutInformation() != null) {
                    internalRelsList.remove(relation.getLayoutInformation());
                }
            }
        }
        // Also remove from _internalRelationships
        ArrayList updatedRelationships = new ArrayList(internalRelationships.length - relationshipsToRemove.size() + relationshipsToAdd.size());
        for (int i = 0; i < internalRelationships.length; i++) {
            InternalRelationship relation = internalRelationships[i];
            if (relationshipsToRemove.contains(relation.getLayoutRelationship())) {
                relationshipsToRemove.remove(relation.getLayoutRelationship());
            } else {
                updatedRelationships.add(relation);
            }
        }
        relationshipsToRemove.clear();
        // add relationships
        if (relationshipsToAdd.size() > 0) {
            LayoutRelationship[] relsArray = new LayoutRelationship[relationshipsToAdd.size()];
            relsArray = (LayoutRelationship[]) relationshipsToAdd.toArray(relsArray);
            InternalRelationship[] newRelationships = createInternalRelationships(relsArray);
            for (int i = 0; i < newRelationships.length; i++) {
                internalRelsList.add(newRelationships[i]);
                updatedRelationships.add(newRelationships[i]);
            }
        }
        relationshipsToAdd.clear();
        relationships = new InternalRelationship[internalRelsList.size()];
        relationships = (InternalRelationship[]) internalRelsList.toArray(relationships);
        internalRelationships = new InternalRelationship[updatedRelationships.size()];
        internalRelationships = (InternalRelationship[]) updatedRelationships.toArray(internalRelationships);
    }
    return relationships;
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship)

Aggregations

InternalRelationship (org.eclipse.zest.layouts.dataStructures.InternalRelationship)11 InternalNode (org.eclipse.zest.layouts.dataStructures.InternalNode)9 Iterator (java.util.Iterator)5 BasicEntityConstraint (org.eclipse.zest.layouts.constraints.BasicEntityConstraint)5 BendPoint (org.eclipse.zest.layouts.dataStructures.BendPoint)5 DisplayIndependentPoint (org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)3 List (java.util.List)3 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 DirectedGraph (org.eclipse.draw2d.graph.DirectedGraph)1 DirectedGraphLayout (org.eclipse.draw2d.graph.DirectedGraphLayout)1 Edge (org.eclipse.draw2d.graph.Edge)1 Node (org.eclipse.draw2d.graph.Node)1 DisplayIndependentRectangle (org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle)1