Search in sources :

Example 6 with Direction

use of com.ait.lienzo.shared.core.types.Direction 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)

Example 7 with Direction

use of com.ait.lienzo.shared.core.types.Direction in project lienzo-core by ahome-it.

the class WiresConnector method updateForCenterConnection.

public static void updateForCenterConnection(final WiresConnector connector, final WiresConnection connection, final int pointIndex) {
    if ((connection.getMagnet() != null) && (connection.getMagnet().getIndex() == 0)) {
        final MultiPath path = connection.getMagnet().getMagnets().getWiresShape().getPath();
        final BoundingBox box = path.getBoundingBox();
        final Point2D c = Geometry.findCenter(box);
        Point2D intersectPoint = Geometry.getPathIntersect(connection, path, c, pointIndex);
        if (null == intersectPoint) {
            intersectPoint = new Point2D();
        }
        final Direction d = MagnetManager.getDirection(intersectPoint, box);
        final Point2D loc = path.getComputedLocation().copy();
        connection.setXOffset(intersectPoint.getX() - c.getX());
        connection.setYOffset(intersectPoint.getY() - c.getY());
        if (connector.getHeadConnection() == connection) {
            connector.getLine().setHeadDirection(d);
        } else {
            connector.getLine().setTailDirection(d);
        }
        connection.move(loc.getX() + c.getX(), loc.getY() + c.getY());
    }
}
Also used : MultiPath(com.ait.lienzo.client.core.shape.MultiPath) Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Direction(com.ait.lienzo.shared.core.types.Direction)

Example 8 with Direction

use of com.ait.lienzo.shared.core.types.Direction in project kie-wb-common by kiegroup.

the class FixedLayoutGridTest method testGrid2.

@Test
public void testGrid2() {
    final double size = 10.5;
    final double padding = 3.5;
    final Direction direction = Direction.EAST;
    final int rows = 4;
    final int cols = 1;
    tested = new FixedLayoutGrid(padding, size, direction, rows, cols);
    assertEquals(size, tested.getIconSize(), 0);
    assertEquals(padding, tested.getPadding(), 0);
    assertEquals(direction, tested.getTowards());
    assertEquals(rows, tested.getRows());
    assertEquals(cols, tested.getCols());
    final List<Point2D> expectedPoints = new ArrayList<>();
    tested.iterator().forEachRemaining(expectedPoints::add);
    assertEquals(4, expectedPoints.size());
    assertEquals(new Point2D(0d, -14d), expectedPoints.get(0));
    assertEquals(new Point2D(0d, -28d), expectedPoints.get(1));
    assertEquals(new Point2D(0d, -42d), expectedPoints.get(2));
    assertEquals(new Point2D(0d, -56d), expectedPoints.get(3));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

Example 9 with Direction

use of com.ait.lienzo.shared.core.types.Direction in project kie-wb-common by kiegroup.

the class FixedLayoutGridTest method testGridExceedBounds.

@Test(expected = NoSuchElementException.class)
public void testGridExceedBounds() {
    final double size = 10.5;
    final double padding = 3.5;
    final Direction direction = Direction.EAST;
    final int rows = 4;
    final int cols = 1;
    tested = new FixedLayoutGrid(padding, size, direction, rows, cols);
    final Iterator<Point2D> points = tested.iterator();
    final List<Point2D> expectedPoints = new ArrayList<>();
    points.forEachRemaining(expectedPoints::add);
    assertFalse(points.hasNext());
    points.next();
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

Example 10 with Direction

use of com.ait.lienzo.shared.core.types.Direction 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)

Aggregations

Point2D (com.ait.lienzo.client.core.types.Point2D)12 Direction (com.ait.lienzo.shared.core.types.Direction)12 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)5 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)4 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)1 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)1 PathPartList (com.ait.lienzo.client.core.types.PathPartList)1 HashSet (java.util.HashSet)1