Search in sources :

Example 16 with Point2DArray

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

the class WiresConnectorControlImpl method destroyControlPoint.

@Override
public void destroyControlPoint(final IPrimitive<?> control) {
    if (m_connector.getPointHandles().size() <= 2) {
        m_wiresManager.deregister(m_connector);
        return;
    }
    IControlHandle selected = null;
    for (final IControlHandle handle : m_connector.getPointHandles()) {
        if (handle.getControl() == control) {
            selected = handle;
            break;
        }
    }
    if (null == selected) {
        return;
    }
    final Point2DArray oldPoints = m_connector.getLine().getPoint2DArray();
    final Point2DArray newPoints = new Point2DArray();
    final Point2D selectedPoint2D = selected.getControl().getLocation();
    for (int i = 0; i < oldPoints.size(); i++) {
        final Point2D current = oldPoints.get(i);
        if (!current.equals(selectedPoint2D)) {
            newPoints.push(current);
        }
    }
    m_connector.getLine().setPoint2DArray(newPoints);
    destroyPointHandles();
    showPointHandles();
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) IControlHandle(com.ait.lienzo.client.core.shape.wires.IControlHandle)

Example 17 with Point2DArray

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

the class WiresConnectorControlImpl method addControlPoint.

@Override
public void addControlPoint(final double x, final double y) {
    hideControlPoints();
    final Point2DArray oldPoints = m_connector.getLine().getPoint2DArray();
    final int pointIndex = getIndexForSelectedSegment(m_connector, (int) x, (int) y, oldPoints);
    if (pointIndex > 0) {
        final Point2D point = new Point2D(x, y);
        final Point2DArray newPoints = new Point2DArray();
        newPoints.push(oldPoints.get(0));
        for (int i = 1; i < pointIndex; i++) {
            newPoints.push(oldPoints.get(i));
        }
        newPoints.push(point);
        for (int i = pointIndex; i < oldPoints.size(); i++) {
            newPoints.push(oldPoints.get(i));
        }
        m_connector.getLine().setPoint2DArray(newPoints);
    }
    showPointHandles();
    m_connector.getLine().getLayer().batch();
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Example 18 with Point2DArray

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

the class WiresConnectorControlImpl method reset.

/*
     ***************** CONTROL POINTS **********************************
     */
@Override
public void reset() {
    if (null != m_startPoints) {
        final IControlHandleList handles = m_connector.getPointHandles();
        final Point2DArray points = m_connector.getLine().getPoint2DArray();
        for (int i = 0, j = 0; i < handles.size(); i++, j += 2) {
            final double px = m_startPoints.get(j);
            final double py = m_startPoints.get(j + 1);
            final IControlHandle h = handles.getHandle(i);
            final IPrimitive<?> prim = h.getControl();
            prim.setX(px);
            prim.setY(py);
            final Point2D point = points.get(i);
            point.setX(px);
            point.setY(py);
        }
    }
    m_connector.getLine().refresh();
    m_wiresManager.getLayer().getLayer().batch();
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) IControlHandle(com.ait.lienzo.client.core.shape.wires.IControlHandle) IControlHandleList(com.ait.lienzo.client.core.shape.wires.IControlHandleList)

Example 19 with Point2DArray

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

the class WiresConnectorControlImpl method move.

/**
 * See class javadocs to explain why we have these booleans
 */
@Override
public void move(final double dx, final double dy, final boolean midPointsOnly, final boolean moveLinePoints) {
    final IControlHandleList handles = m_connector.getPointHandles();
    int start = 0;
    int end = handles.size();
    if (midPointsOnly) {
        if (m_connector.getHeadConnection().getMagnet() != null) {
            start++;
        }
        if (m_connector.getTailConnection().getMagnet() != null) {
            end--;
        }
    }
    final Point2DArray points = m_connector.getLine().getPoint2DArray();
    for (int i = start, j = (start == 0) ? start : 2; i < end; i++, j += 2) {
        if (moveLinePoints) {
            final Point2D p = points.get(i);
            p.setX(m_startPoints.get(j) + dx);
            p.setY(m_startPoints.get(j + 1) + dy);
        }
        final IControlHandle h = handles.getHandle(i);
        final IPrimitive<?> prim = h.getControl();
        prim.setX(m_startPoints.get(j) + dx);
        prim.setY(m_startPoints.get(j + 1) + dy);
    }
    if (moveLinePoints) {
        m_connector.getLine().refresh();
    }
    m_wiresManager.getLayer().getLayer().batch();
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) IControlHandle(com.ait.lienzo.client.core.shape.wires.IControlHandle) IControlHandleList(com.ait.lienzo.client.core.shape.wires.IControlHandleList)

Example 20 with Point2DArray

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

the class MagnetManager method createMagnets.

/**
 * Right now it only works with provided FOUR or EIGHT cardinals, anything else will break WiresConnector autoconnection
 *
 * @param wiresShape
 * @param requestedCardinals
 * @return
 */
public Magnets createMagnets(final WiresShape wiresShape, final Direction[] requestedCardinals) {
    final IPrimitive<?> primTarget = wiresShape.getGroup();
    final Point2DArray points = getWiresIntersectionPoints(wiresShape, requestedCardinals);
    final ControlHandleList list = new ControlHandleList(primTarget);
    final BoundingBox box = wiresShape.getPath().getBoundingBox();
    final Point2D primLoc = primTarget.getComputedLocation();
    final Magnets magnets = new Magnets(this, list, wiresShape);
    int i = 0;
    for (final Point2D p : points) {
        final double mx = primLoc.getX() + p.getX();
        final double my = primLoc.getY() + p.getY();
        final WiresMagnet m = new WiresMagnet(magnets, null, i++, p.getX(), p.getY(), getControlPrimitive(mx, my), true);
        final Direction d = getDirection(p, box);
        m.setDirection(d);
        list.add(m);
    }
    final String uuid = primTarget.uuid();
    m_magnetRegistry.put(uuid, magnets);
    wiresShape.setMagnets(magnets);
    return magnets;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Direction(com.ait.lienzo.shared.core.types.Direction)

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