Search in sources :

Example 16 with BoundingBox

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

the class WiresConnectorControlImpl method getIndexForSelectedSegment.

public static int getIndexForSelectedSegment(final WiresConnector connector, final int mouseX, final int mouseY, final Point2DArray oldPoints) {
    final NFastStringMap<Integer> colorMap = new NFastStringMap<>();
    final AbstractDirectionalMultiPointShape<?> line = connector.getLine();
    final ScratchPad scratch = line.getScratchPad();
    scratch.clear();
    final PathPartList path = line.getPathPartList();
    int pointsIndex = 1;
    String color = MagnetManager.m_c_rotor.next();
    colorMap.put(color, pointsIndex);
    final Context2D ctx = scratch.getContext();
    final double strokeWidth = line.getStrokeWidth();
    ctx.setStrokeWidth(strokeWidth);
    final Point2D absolutePos = connector.getLine().getComputedLocation();
    final double offsetX = absolutePos.getX();
    final double offsetY = absolutePos.getY();
    Point2D pathStart = new Point2D(offsetX, offsetY);
    Point2D segmentStart = pathStart;
    for (int i = 0; i < path.size(); i++) {
        final PathPartEntryJSO entry = path.get(i);
        NFastDoubleArrayJSO points = entry.getPoints();
        switch(entry.getCommand()) {
            case PathPartEntryJSO.MOVETO_ABSOLUTE:
                {
                    final double x0 = points.get(0) + offsetX;
                    final double y0 = points.get(1) + offsetY;
                    final Point2D m = new Point2D(x0, y0);
                    if (i == 0) {
                        // this is position is needed, if we close the path.
                        pathStart = m;
                    }
                    segmentStart = m;
                    break;
                }
            case PathPartEntryJSO.LINETO_ABSOLUTE:
                {
                    points = entry.getPoints();
                    final double x0 = points.get(0) + offsetX;
                    final double y0 = points.get(1) + offsetY;
                    final Point2D end = new Point2D(x0, y0);
                    if (oldPoints.get(pointsIndex).equals(segmentStart)) {
                        pointsIndex++;
                        color = MagnetManager.m_c_rotor.next();
                        colorMap.put(color, pointsIndex);
                    }
                    ctx.setStrokeColor(color);
                    ctx.beginPath();
                    ctx.moveTo(segmentStart.getX(), segmentStart.getY());
                    ctx.lineTo(x0, y0);
                    ctx.stroke();
                    segmentStart = end;
                    break;
                }
            case PathPartEntryJSO.CLOSE_PATH_PART:
                {
                    final double x0 = pathStart.getX() + offsetX;
                    final double y0 = pathStart.getY() + offsetY;
                    final Point2D end = new Point2D(x0, y0);
                    if (oldPoints.get(pointsIndex).equals(segmentStart)) {
                        pointsIndex++;
                        color = MagnetManager.m_c_rotor.next();
                        colorMap.put(color, pointsIndex);
                    }
                    ctx.setStrokeColor(color);
                    ctx.beginPath();
                    ctx.moveTo(segmentStart.getX(), segmentStart.getY());
                    ctx.lineTo(x0, y0);
                    ctx.stroke();
                    segmentStart = end;
                    break;
                }
            case PathPartEntryJSO.CANVAS_ARCTO_ABSOLUTE:
                {
                    points = entry.getPoints();
                    final double x0 = points.get(0) + offsetX;
                    final double y0 = points.get(1) + offsetY;
                    final Point2D p0 = new Point2D(x0, y0);
                    final double x1 = points.get(2) + offsetX;
                    final double y1 = points.get(3) + offsetY;
                    final double r = points.get(4);
                    final Point2D p1 = new Point2D(x1, y1);
                    final Point2D end = p1;
                    if (p0.equals(oldPoints.get(pointsIndex))) {
                        pointsIndex++;
                        color = MagnetManager.m_c_rotor.next();
                        colorMap.put(color, pointsIndex);
                    }
                    ctx.setStrokeColor(color);
                    ctx.beginPath();
                    ctx.moveTo(segmentStart.getX(), segmentStart.getY());
                    ctx.arcTo(x0, y0, x1, y1, r);
                    ctx.stroke();
                    segmentStart = end;
                    break;
                }
        }
    }
    final BoundingBox box = connector.getLine().getBoundingBox();
    // Keep the ImageData small by clipping just the visible line area
    // But remember the mouse must be offset for this clipped area.
    final int sx = (int) (box.getX() - strokeWidth - offsetX);
    final int sy = (int) (box.getY() - strokeWidth - offsetY);
    final ImageData backing = ctx.getImageData(sx, sy, (int) (box.getWidth() + strokeWidth + strokeWidth), (int) (box.getHeight() + strokeWidth + strokeWidth));
    color = BackingColorMapUtils.findColorAtPoint(backing, mouseX - sx, mouseY - sy);
    return null != color ? colorMap.get(color) : -1;
}
Also used : NFastStringMap(com.ait.tooling.nativetools.client.collection.NFastStringMap) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) PathPartEntryJSO(com.ait.lienzo.client.core.types.PathPartEntryJSO) NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO) Context2D(com.ait.lienzo.client.core.Context2D) Point2D(com.ait.lienzo.client.core.types.Point2D) ImageData(com.ait.lienzo.client.core.types.ImageData) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) PathPartList(com.ait.lienzo.client.core.types.PathPartList)

Example 17 with BoundingBox

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

the class WiresShapeLocationControlImpl method onMoveStart.

@Override
public void onMoveStart(final double x, final double y) {
    m_delta = new Point2D(0, 0);
    shapeResetLocation = getShape().getLocation();
    shapeInitialLocation = getShape().getComputedLocation();
    m_mouseStartX = x;
    m_mouseStartY = y;
    final Point2D absShapeLoc = m_shape.getPath().getComputedLocation();
    final BoundingBox box = m_shape.getPath().getBoundingBox();
    m_shapeStartCenterX = absShapeLoc.getX() + (box.getWidth() / 2);
    m_shapeStartCenterY = absShapeLoc.getY() + (box.getHeight() / 2);
    m_startDocked = false;
    final WiresContainer parent = m_shape.getParent();
    if ((parent != null) && (parent instanceof WiresShape)) {
        if (m_shape.getDockedTo() != null) {
            m_startDocked = true;
        }
    }
}
Also used : WiresShape(com.ait.lienzo.client.core.shape.wires.WiresShape) Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) WiresContainer(com.ait.lienzo.client.core.shape.wires.WiresContainer)

Example 18 with BoundingBox

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

the class WiresLayoutContainer method initializeChild.

private void initializeChild(final ChildEntry entry, final IPrimitive<?> child) {
    // Initial coordinates.
    final BoundingBox bb = child.getBoundingBox();
    final double[] c = getChildRelativeCoordinates(bb);
    // Size relative attribute.
    final Layout layout = entry.layout;
    final double w = bb.getWidth();
    final double h = bb.getHeight();
    final double cs = (Layout.TOP.equals(layout) || Layout.BOTTOM.equals(layout)) ? h : w;
    entry.initial_coords = new Point2D(c[0], c[1]);
    entry.initial_size_attr = cs;
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 19 with BoundingBox

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

the class WiresShapeControlHandleList method refresh.

void refresh() {
    final BoundingBox bbox = getPath().getBoundingBox();
    resize(null, null, bbox.getWidth(), bbox.getHeight(), true);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 20 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox 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

BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)79 Point2D (com.ait.lienzo.client.core.types.Point2D)24 Test (org.junit.Test)16 ScratchPad (com.ait.lienzo.client.core.util.ScratchPad)8 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)7 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)7 Context2D (com.ait.lienzo.client.core.Context2D)6 ArrayList (java.util.ArrayList)6 Direction (com.ait.lienzo.shared.core.types.Direction)5 Group (com.ait.lienzo.client.core.shape.Group)4 WiresShape (com.ait.lienzo.client.core.shape.wires.WiresShape)4 Text (com.ait.lienzo.client.core.shape.Text)3 Transform (com.ait.lienzo.client.core.types.Transform)3 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)3 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)3 MultiPathDecorator (com.ait.lienzo.client.core.shape.MultiPathDecorator)2 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)2 WiresConnector (com.ait.lienzo.client.core.shape.wires.WiresConnector)2 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)2 BoundingPoints (com.ait.lienzo.client.core.types.BoundingPoints)2