Search in sources :

Example 56 with BoundingBox

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

the class WiresConnector method getMagnetsWithMidPoint.

private WiresMagnet[] getMagnetsWithMidPoint(final WiresConnection headC, final WiresConnection tailC, final WiresShape headS, final WiresShape tailS, final BoundingBox headBox, final BoundingBox tailBox) {
    // make BB's of 1 Point2D, then we can reuse existing code.
    final Point2D pAfterHead = getLine().getPoint2DArray().get(1);
    final Point2D pBeforeTail = getLine().getPoint2DArray().get(getLine().getPoint2DArray().size() - 2);
    final BoundingBox firstBB = new BoundingBox(pAfterHead, pAfterHead);
    final BoundingBox lastBB = new BoundingBox(pBeforeTail, pBeforeTail);
    WiresMagnet headM;
    WiresMagnet tailM;
    if ((headBox != null) && !headBox.intersects(firstBB)) {
        final WiresMagnet[] magnets = getMagnetsNonOverlappedShapes(headS, null, headBox, firstBB);
        headM = magnets[0];
    } else {
        final WiresMagnet[] headMagnets = getMagnets(headC, headS);
        headM = getShortestMagnetToPoint(pAfterHead, headMagnets);
    }
    if ((tailBox != null) && !tailBox.intersects(lastBB)) {
        final WiresMagnet[] magnets = getMagnetsNonOverlappedShapes(null, tailS, lastBB, tailBox);
        tailM = magnets[1];
    } else {
        final WiresMagnet[] tailMagnets = getMagnets(tailC, tailS);
        tailM = getShortestMagnetToPoint(pAfterHead, tailMagnets);
    }
    return new WiresMagnet[] { headM, tailM };
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 57 with BoundingBox

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

the class WiresDockingControlImpl method getAdjust.

@Override
public Point2D getAdjust() {
    if (isEnabled() && (intersection != null)) {
        final WiresShape shape = getShape();
        final BoundingBox box = shape.getPath().getBoundingBox();
        // convert to local xy of the path
        final Point2D absLoc = getParent().getComputedLocation();
        final double newX = (absLoc.getX() + intersection.getX()) - (box.getWidth() / 2);
        final double newY = (absLoc.getY() + intersection.getY()) - (box.getHeight() / 2);
        return new Point2D(newX - initialPathLocation.getX(), newY - initialPathLocation.getY());
    }
    return new Point2D(0, 0);
}
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)

Example 58 with BoundingBox

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

the class WiresShapeControlImpl method onMove.

@Override
public boolean onMove(final double dx, final double dy) {
    if (isOutOfBounds(dx, dy)) {
        return true;
    }
    if (parentPickerControl.onMove(dx, dy)) {
        m_adjust = parentPickerControl.getAdjust();
        return true;
    }
    final Point2D dxy = new Point2D(dx, dy);
    final boolean isDockAdjust = (null != m_dockingAndControl) && m_dockingAndControl.onMove(dx, dy);
    if (isDockAdjust) {
        final Point2D dadjust = m_dockingAndControl.getAdjust();
        dxy.setX(dadjust.getX());
        dxy.setY(dadjust.getY());
    }
    final boolean isContAdjust = (null != m_containmentControl) && m_containmentControl.onMove(dx, dy);
    if (isContAdjust) {
        final Point2D cadjust = m_containmentControl.getAdjust();
        dxy.setX(cadjust.getX());
        dxy.setY(cadjust.getY());
    }
    final boolean isAlignDistroAdjust = (null != m_alignAndDistributeControl) && m_alignAndDistributeControl.isDraggable() && m_alignAndDistributeControl.dragAdjust(dxy);
    // Special adjustments.
    boolean adjust = true;
    if ((isDockAdjust || isContAdjust) && isAlignDistroAdjust && ((dxy.getX() != dx) || (dxy.getY() != dy))) {
        final BoundingBox box = getShape().getPath().getBoundingBox();
        final PickerPart part = getPicker().findShapeAt((int) (shapeBounds.getMinX() + dxy.getX() + (box.getWidth() / 2)), (int) (shapeBounds.getMinY() + dxy.getY() + (box.getHeight() / 2)));
        if ((part == null) || (part.getShapePart() != PickerPart.ShapePart.BORDER)) {
            dxy.setX(dx);
            dxy.setY(dy);
            adjust = false;
        }
    }
    // Cache the current adjust point.
    m_adjust = dxy;
    parentPickerControl.onMoveAdjusted(m_adjust);
    shapeUpdated(false);
    return adjust;
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) PickerPart(com.ait.lienzo.client.core.shape.wires.PickerPart)

Example 59 with BoundingBox

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

the class Geometry method getBoundingBoxOfCurve.

public static final BoundingBox getBoundingBoxOfCurve(final double computedLocationOffsetX, final double computedLocationOffsetY, final Point2DArray points) {
    if (null == points) {
        return null;
    }
    int size = points.size();
    if (size < 3) {
        return null;
    }
    double minx = Double.MAX_VALUE;
    double miny = Double.MAX_VALUE;
    double maxx = -Double.MAX_VALUE;
    double maxy = -Double.MAX_VALUE;
    final NFastDoubleArrayJSO xval = NFastDoubleArrayJSO.make();
    final NFastDoubleArrayJSO yval = NFastDoubleArrayJSO.make();
    for (int i = 0; i < size; i++) {
        final Point2D p = points.get(i);
        xval.push(p.getX());
        yval.push(p.getY());
    }
    final NFastDoubleArrayJSO inflections = getInflections(points, xval, yval);
    size = inflections.size();
    for (int i = 0; i < size; i++) {
        final double t = inflections.get(i);
        final double x = getValue(t, xval);
        final double y = getValue(t, yval);
        minx = Math.min(x, minx);
        maxx = Math.max(x, maxx);
        miny = Math.min(y, miny);
        maxy = Math.max(y, maxy);
    }
    return new BoundingBox(computedLocationOffsetX + minx, computedLocationOffsetY + miny, computedLocationOffsetX + maxx, computedLocationOffsetY + maxy);
}
Also used : NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO) Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 60 with BoundingBox

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

the class TextLineBreakWrap method drawString.

@Override
public void drawString(final Context2D context, final Attributes attr, final IDrawString drawCommand) {
    final String text = attr.getText();
    if ((text == null) || text.isEmpty()) {
        return;
    }
    final String[] lines = text.split("\\r?\\n");
    final BoundingBox bb = getBoundingBox();
    double xOffset = 0;
    switch(textAlignSupplier.get()) {
        case START:
        case LEFT:
            xOffset = 0;
            break;
        case CENTER:
            xOffset = bb.getWidth() / 2;
            break;
        case END:
        case RIGHT:
            xOffset = bb.getWidth();
            break;
    }
    for (int i = 0; i < lines.length; i++) {
        final String line = lines[i];
        drawCommand.draw(context, line, xOffset, i + 0.8);
    }
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

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