Search in sources :

Example 1 with BendPoint

use of org.eclipse.zest.layouts.dataStructures.BendPoint 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 2 with BendPoint

use of org.eclipse.zest.layouts.dataStructures.BendPoint 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 3 with BendPoint

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

the class AbstractLayoutAlgorithm method updateBendPoints.

/**
 * Update external bend points from the internal bendpoints list. Save the
 * source and destination points for later use in scaling and translating
 * @param relationshipsToConsider
 */
protected void updateBendPoints(InternalRelationship[] relationshipsToConsider) {
    for (int i = 0; i < relationshipsToConsider.length; i++) {
        InternalRelationship relationship = relationshipsToConsider[i];
        List bendPoints = relationship.getBendPoints();
        if (bendPoints.size() > 0) {
            // We will assume that source/dest coordinates are for center of node
            BendPoint[] externalBendPoints = new BendPoint[bendPoints.size() + 2];
            InternalNode sourceNode = relationship.getSource();
            externalBendPoints[0] = new BendPoint(sourceNode.getInternalX(), sourceNode.getInternalY());
            InternalNode destNode = relationship.getDestination();
            externalBendPoints[externalBendPoints.length - 1] = new BendPoint(destNode.getInternalX(), destNode.getInternalY());
            for (int j = 0; j < bendPoints.size(); j++) {
                BendPoint bp = (BendPoint) bendPoints.get(j);
                externalBendPoints[j + 1] = new BendPoint(bp.x, bp.y, bp.getIsControlPoint());
            }
            relationship.getLayoutRelationship().setBendPoints(externalBendPoints);
        }
    }
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) ArrayList(java.util.ArrayList) List(java.util.List) 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)

Aggregations

BasicEntityConstraint (org.eclipse.zest.layouts.constraints.BasicEntityConstraint)3 BendPoint (org.eclipse.zest.layouts.dataStructures.BendPoint)3 DisplayIndependentPoint (org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)3 InternalNode (org.eclipse.zest.layouts.dataStructures.InternalNode)3 InternalRelationship (org.eclipse.zest.layouts.dataStructures.InternalRelationship)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1