Search in sources :

Example 31 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class SelectionManager method getItemsInBoundingBox.

public void getItemsInBoundingBox(final BoundingBox selectionBox) {
    m_selected.setSelectionGroup(true);
    final BoundingBox box = m_selected.getBoundingBox();
    BoundingBox nodeBox = null;
    final List<WiresShape> shapesList = new ArrayList<>();
    final List<WiresShape> toBeRemoved = new ArrayList<>();
    final Map<String, WiresShape> shapesMap = new HashMap<>();
    final Map<String, BoundingBox> uuidMap = new HashMap<>();
    // first build a map of all shapes that intersect with teh selection rectangle. Nested shapes will be used later.
    for (final WiresShape shape : m_wiresManager.getShapesMap().values()) {
        if (shape.getDockedTo() != null) {
            // docked items cannot be added to a selection, only their parent they are docked to
            continue;
        }
        nodeBox = shape.getContainer().getComputedBoundingPoints().getBoundingBox();
        if (selectionBox.intersects(nodeBox)) {
            shapesList.add(shape);
            shapesMap.put(shape.getContainer().uuid(), shape);
            uuidMap.put(shape.getContainer().uuid(), nodeBox);
        }
    }
    // add to removal list any shape whose parent is also in the selection
    for (final WiresShape shape : shapesMap.values()) {
        if ((null != shape.getParent()) && shapesMap.containsKey(shape.getParent().getContainer().uuid())) {
            // can't remove yet, as it may have selected children itself, which will also need to be removed
            toBeRemoved.add(shape);
        }
    }
    // now the list is built, safely remove the shapes
    for (final WiresShape shape : toBeRemoved) {
        shapesMap.remove(shape.getContainer().uuid());
    }
    for (final WiresShape shape : shapesMap.values()) {
        nodeBox = uuidMap.get(shape.getContainer().uuid());
        m_selected.add(shape);
        box.add(nodeBox);
    }
    for (final WiresConnector connector : m_wiresManager.getConnectorList()) {
        final boolean externallyConnected = isExternallyConnected(connector);
        final Point2DArray points = new Point2DArray();
        final Point2D loc = getSelectionShape().getLocation();
        final BoundingBox boundingBox = getSelectionShape().getBoundingBox();
        points.push(loc.getX(), loc.getY());
        points.push(loc.getX() + boundingBox.getWidth(), loc.getY());
        points.push(loc.getX() + boundingBox.getWidth(), loc.getY() + boundingBox.getHeight());
        points.push(loc.getX(), loc.getY() + boundingBox.getHeight());
        nodeBox = connector.getGroup().getComputedBoundingPoints().getBoundingBox();
        if (selectionBox.contains(nodeBox)) {
            addConnector(connector, externallyConnected, box, nodeBox);
        } else {
            Point2DArray intersections = Geometry.getIntersectPolyLinePath(points, connector.getLine().getPathPartList(), true);
            if ((intersections != null) && (intersections.size() > 0)) {
                addConnector(connector, externallyConnected, box, nodeBox);
            } else {
                // the above checked the line, also check the head and tail.
                // head is rotated around an offset with also set. The reverse of this must be applied to the
                // selection rectangle, to ensure thinsg are all in the same space,  for intersection to work
                MultiPath path = connector.getHead();
                Transform xfrm = new Transform();
                xfrm.translate(path.getOffset().getX(), path.getOffset().getY());
                xfrm.rotate(0 - path.getRotation());
                xfrm.translate(0 - path.getX(), 0 - path.getY());
                xfrm.translate(0 - path.getOffset().getX(), 0 - path.getOffset().getY());
                Point2DArray transformedPoints = points.copy();
                for (final Point2D p : transformedPoints) {
                    xfrm.transform(p, p);
                }
                intersections = Geometry.getIntersectPolyLinePath(transformedPoints, connector.getHead().getActualPathPartListArray().get(0), true);
                if ((intersections != null) && (intersections.size() > 0)) {
                    addConnector(connector, externallyConnected, box, nodeBox);
                } else {
                    // tail is rotated around an offset with also set. The reverse of this must be applied to the
                    // selection rectangle, to ensure thinsg are all in the same space,  for intersection to work
                    path = connector.getTail();
                    xfrm = new Transform();
                    xfrm.translate(path.getOffset().getX(), path.getOffset().getY());
                    xfrm.rotate(0 - path.getRotation());
                    xfrm.translate(0 - path.getX(), 0 - path.getY());
                    xfrm.translate(0 - path.getOffset().getX(), 0 - path.getOffset().getY());
                    transformedPoints = points.copy();
                    for (final Point2D p : transformedPoints) {
                        xfrm.transform(p, p);
                    }
                    intersections = Geometry.getIntersectPolyLinePath(transformedPoints, connector.getTail().getActualPathPartListArray().get(0), true);
                    if ((intersections != null) && (intersections.size() > 0)) {
                        addConnector(connector, externallyConnected, box, nodeBox);
                    }
                }
            }
        }
    }
}
Also used : MultiPath(com.ait.lienzo.client.core.shape.MultiPath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NFastArrayList(com.ait.tooling.nativetools.client.collection.NFastArrayList) Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Transform(com.ait.lienzo.client.core.types.Transform)

Example 32 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class WiresConnector method updateHeadTailForRefreshedConnector.

public static boolean updateHeadTailForRefreshedConnector(final WiresConnector c) {
    // Iterate each refreshed line and get the new points for the decorators
    if (c.getLine().getPathPartList().size() < 1) {
        // only do this for lines that have had refresh called
        final AbstractDirectionalMultiPointShape<?> line = c.getLine();
        if (c.isSpecialConnection() && (line.getPathPartList().size() == 0)) {
            // if getPathPartList is empty, it was refreshed due to a point change
            c.updateForSpecialConnections(false);
        }
        final boolean prepared = line.isPathPartListPrepared(c.getLine().getAttributes());
        if (!prepared) {
            return true;
        }
        final Point2DArray points = line.getPoint2DArray();
        Point2D p0 = points.get(0);
        Point2D p1 = line.getHeadOffsetPoint();
        final Point2DArray headPoints = new Point2DArray(p1, p0);
        c.getHeadDecorator().draw(headPoints);
        p0 = points.get(points.size() - 1);
        p1 = line.getTailOffsetPoint();
        final Point2DArray tailPoints = new Point2DArray(p1, p0);
        c.getTailDecorator().draw(tailPoints);
    }
    return false;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Example 33 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class WiresMagnetsControlImpl method shapeChanged.

@Override
public void shapeChanged() {
    final IControlHandleList controlHandles = null != getMagnets() ? getMagnets().getMagnets() : null;
    if ((null == controlHandles) || controlHandles.isEmpty()) {
        return;
    }
    final Direction[] cardinals = controlHandles.size() == 9 ? EIGHT_CARDINALS : FOUR_CARDINALS;
    final Point2DArray points = MagnetManager.getWiresIntersectionPoints(shape, cardinals);
    final int size = controlHandles.size() <= points.size() ? controlHandles.size() : points.size();
    for (int i = 0; i < size; i++) {
        final Point2D p = points.get(i);
        final WiresMagnet m = (WiresMagnet) controlHandles.getHandle(i);
        m.setRx(p.getX()).setRy(p.getY());
    }
    shapeMoved();
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) WiresMagnet(com.ait.lienzo.client.core.shape.wires.WiresMagnet) Direction(com.ait.lienzo.shared.core.types.Direction) IControlHandleList(com.ait.lienzo.client.core.shape.wires.IControlHandleList)

Example 34 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class WiresShapeControlHandleList method getControlPointsArray.

private Point2DArray getControlPointsArray() {
    final Point2DArray result = new Point2DArray();
    for (int i = 0; i < POINTS_SIZE; i++) {
        final IPrimitive<?> control = m_ctrls.getHandle(i).getControl();
        result.push(new Point2D(control.getX(), control.getY()));
    }
    return result;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Example 35 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Geometry method getCanvasArcToPoints.

/**
 * Canvas arcTo's have a variable center, as points a, b and c form two lines from the same point at a tangent to the arc's cirlce.
 * This returns the arcTo arc start, center and end points.
 *
 * @param p0
 * @param p1
 * @param r
 * @return
 */
public static final Point2DArray getCanvasArcToPoints(final Point2D p0, final Point2D p1, final Point2D p2, final double r) {
    // see tangents drawn from same point to a circle
    // http://www.mathcaptain.com/geometry/tangent-of-a-circle.html
    final double a0 = getAngleBetweenTwoLines(p0, p1, p2) / 2;
    final double ln = getLengthFromASA(RADIANS_90 - a0, r, a0);
    Point2D dv = p1.sub(p0);
    Point2D dx = dv.unit();
    Point2D dl = dx.mul(ln);
    // ps is arc start point
    final Point2D ps = p1.sub(dl);
    dv = p1.sub(p2);
    dx = dv.unit();
    dl = dx.mul(ln);
    // ep is arc end point
    final Point2D pe = p1.sub(dl);
    // this gets the direction as a unit, from p1 to the center
    final Point2D midPoint = new Point2D((ps.getX() + pe.getX()) / 2, (ps.getY() + pe.getY()) / 2);
    dx = midPoint.sub(p1).unit();
    final Point2D pc = p1.add(dx.mul(distance(r, ln)));
    return new Point2DArray(ps, pc, pe);
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Aggregations

Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)47 Point2D (com.ait.lienzo.client.core.types.Point2D)37 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)6 HashSet (java.util.HashSet)6 Set (java.util.Set)5 Direction (com.ait.lienzo.shared.core.types.Direction)4 IControlHandle (com.ait.lienzo.client.core.shape.wires.IControlHandle)3 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)3 PathPartList (com.ait.lienzo.client.core.types.PathPartList)3 Attributes (com.ait.lienzo.client.core.shape.Attributes)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)2 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)2 DashArray (com.ait.lienzo.client.core.types.DashArray)2 Transform (com.ait.lienzo.client.core.types.Transform)2 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)2 Test (org.junit.Test)2 Group (com.ait.lienzo.client.core.shape.Group)1 Line (com.ait.lienzo.client.core.shape.Line)1 Node (com.ait.lienzo.client.core.shape.Node)1 OrthogonalPolyLine (com.ait.lienzo.client.core.shape.OrthogonalPolyLine)1