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;
}
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());
}
}
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));
}
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();
}
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();
}
Aggregations