use of com.ait.lienzo.client.core.shape.wires.WiresConnection in project lienzo-core by ahome-it.
the class WiresConnectionControlImpl method onMoveStart.
@Override
public void onMoveStart(final double x, final double y) {
final Point2D points = getControlNode().getComputedLocation();
m_startX = points.getX();
m_startY = points.getY();
final ScratchPad scratch = m_manager.getLayer().getLayer().getScratchPad();
m_shapesBacking = BackingColorMapUtils.drawShapesToBacking(m_manager.getLayer().getChildShapes(), scratch, null, m_shape_color_map);
m_connector.getLine().getOverLayer().getContext().createImageData(m_shapesBacking);
final WiresConnection connection = getConnection();
m_initialAutoConnect = connection.isAutoConnection();
// set it to false while dragging
connection.setAutoConnection(false);
m_initial_magnet = connection.getMagnet();
if (null != m_initial_magnet) {
m_magnets = connection.getMagnet().getMagnets();
m_magnetsBacking = m_manager.getMagnetManager().drawMagnetsToBack(m_magnets, m_shape_color_map, m_magnet_color_map, scratch);
}
// always null when drag start and reset the offsets (they may already be 0)
connection.setMagnet(null);
connection.setXOffset(0);
connection.setYOffset(0);
final String colorKey = BackingColorMapUtils.findColorAtPoint(m_shapesBacking, (int) m_startX, (int) m_startY);
checkAllowAndShowMagnets(colorKey);
}
use of com.ait.lienzo.client.core.shape.wires.WiresConnection in project kie-wb-common by kiegroup.
the class WiresConnectorViewTest method testConnectMagnetsByLocation.
@Test
public void testConnectMagnetsByLocation() {
// Mocks for head stuff.
IControlHandleList headControlHandleList = new ControlHandleList(mock(Shape.class));
WiresMagnet headMagnet1 = mock(WiresMagnet.class);
when(headMagnet1.getX()).thenReturn(10d);
when(headMagnet1.getY()).thenReturn(20d);
when(headMagnet1.getIndex()).thenReturn(0);
IPrimitive ch1 = mock(IPrimitive.class);
when(ch1.getLocation()).thenReturn(new Point2D(10d, 20d));
when(headMagnet1.getControl()).thenReturn(ch1);
WiresMagnet headMagnet2 = mock(WiresMagnet.class);
when(headMagnet2.getX()).thenReturn(100d);
when(headMagnet2.getY()).thenReturn(200d);
IPrimitive ch2 = mock(IPrimitive.class);
when(ch2.getLocation()).thenReturn(new Point2D(100d, 200d));
when(headMagnet2.getControl()).thenReturn(ch2);
headControlHandleList.add(headMagnet1);
headControlHandleList.add(headMagnet2);
MagnetManager.Magnets headMagnets = mock(MagnetManager.Magnets.class);
when(headMagnets.getMagnets()).thenReturn(headControlHandleList);
Point2D headAbs = new Point2D(0, 0);
MagnetConnection headConnection = MagnetConnection.Builder.at(10, 20);
// Mocks for head tail.
IControlHandleList tailControlHandleList = new ControlHandleList(mock(Shape.class));
WiresMagnet tailMagnet1 = mock(WiresMagnet.class);
when(tailMagnet1.getX()).thenReturn(10d);
when(tailMagnet1.getY()).thenReturn(20d);
IPrimitive th1 = mock(IPrimitive.class);
when(th1.getLocation()).thenReturn(new Point2D(10d, 20d));
when(tailMagnet1.getControl()).thenReturn(th1);
WiresMagnet tailMagnet2 = mock(WiresMagnet.class);
when(tailMagnet2.getX()).thenReturn(100d);
when(tailMagnet2.getY()).thenReturn(200d);
when(tailMagnet2.getIndex()).thenReturn(2);
IPrimitive th2 = mock(IPrimitive.class);
when(th2.getLocation()).thenReturn(new Point2D(100d, 200d));
when(tailMagnet2.getControl()).thenReturn(th2);
tailControlHandleList.add(tailMagnet1);
tailControlHandleList.add(tailMagnet2);
MagnetManager.Magnets tailMagnets = mock(MagnetManager.Magnets.class);
when(tailMagnets.getMagnets()).thenReturn(tailControlHandleList);
Point2D tailAbs = new Point2D(0, 0);
MagnetConnection tailConnection = MagnetConnection.Builder.at(100, 200);
// Mocks both source/target actual connections.
WiresConnection headWiresConnection = mock(WiresConnection.class);
WiresConnection tailWiresConnection = mock(WiresConnection.class);
tested.setHeadConnection(headWiresConnection);
tested.setTailConnection(tailWiresConnection);
// Perform the connection.
tested.connect(headMagnets, headAbs, headConnection, tailMagnets, tailAbs, tailConnection);
// Verify it sets the right magnets (closest to the location):
verify(headWiresConnection, never()).setXOffset(anyDouble());
verify(headWiresConnection, never()).setYOffset(anyDouble());
verify(headWiresConnection, times(1)).setAutoConnection(eq(false));
verify(headWiresConnection, times(1)).setMagnet(eq(headMagnet1));
verify(tailWiresConnection, times(1)).setXOffset(eq(0d));
verify(tailWiresConnection, times(1)).setYOffset(eq(0d));
verify(tailWiresConnection, times(1)).setAutoConnection(eq(false));
verify(tailWiresConnection, times(1)).setMagnet(eq(tailMagnet2));
}
use of com.ait.lienzo.client.core.shape.wires.WiresConnection in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testMove.
@Test
@SuppressWarnings("unchecked")
public void testMove() throws Exception {
final WiresShapeView wiresShape = mock(WiresShapeView.class);
final WiresShapeView childWiresShape = mock(WiresShapeView.class);
final MagnetManager.Magnets magnets = mock(MagnetManager.Magnets.class);
final WiresMagnet magnet = mock(WiresMagnet.class);
final WiresConnection connection = mock(WiresConnection.class);
final NFastArrayList<WiresConnection> connections = new NFastArrayList<>(connection);
final WiresConnector connector = mock(WiresConnector.class);
final String connectorUUID = UUID.uuid();
final NFastArrayList<WiresShape> children = new NFastArrayList<>(childWiresShape);
final Group connectorGroup = mock(Group.class);
final Edge connectorEdge = mock(Edge.class);
final com.ait.lienzo.client.core.types.Point2D controlPointLienzo = new com.ait.lienzo.client.core.types.Point2D(100, 100);
final Point2DArray controlPointsLienzo = new Point2DArray(controlPointLienzo);
final ViewConnector viewConnector = mock(ViewConnector.class);
Group parentGroup = mock(Group.class);
BoundingBox parentBB = new BoundingBox(0, 0, 200, 200);
MultiPath head = mock(MultiPath.class);
MultiPath tail = mock(MultiPath.class);
when(childWiresShape.getMagnets()).thenReturn(magnets);
when(childWiresShape.getParent()).thenReturn(wiresShape);
when(wiresShape.getGroup()).thenReturn(parentGroup);
when(parentGroup.getBoundingBox()).thenReturn(parentBB);
when(wiresShape.getX()).thenReturn(0d);
when(wiresShape.getY()).thenReturn(0d);
when(magnets.size()).thenReturn(1);
when(magnets.getMagnet(0)).thenReturn(magnet);
when(magnet.getConnectionsSize()).thenReturn(connections.size());
when(magnet.getConnections()).thenReturn(connections);
when(connection.getConnector()).thenReturn(connector);
when(connector.getGroup()).thenReturn(connectorGroup);
when(connectorGroup.uuid()).thenReturn(connectorUUID);
when(connector.getControlPoints()).thenReturn(controlPointsLienzo);
when(connector.getHead()).thenReturn(head);
when(connector.getTail()).thenReturn(tail);
when(head.getLocation()).thenReturn(new com.ait.lienzo.client.core.types.Point2D(1, 1));
when(tail.getLocation()).thenReturn(new com.ait.lienzo.client.core.types.Point2D(2, 2));
when(wiresShape.getChildShapes()).thenReturn(children);
when(shape.getShapeView()).thenReturn(wiresShape);
when(graphIndex.getEdge(connectorUUID)).thenReturn(connectorEdge);
when(connectorEdge.getContent()).thenReturn(viewConnector);
when(connectorGroup.getUserData()).thenReturn(new WiresUtils.UserData(connectorUUID, ""));
tested.init(canvasHandler);
tested.register(element);
Point2D location = new Point2D(45d, 65.5d);
tested.move(new Element[] { element }, new Point2D[] { location });
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
ArgumentCaptor<ShapeLocationsChangedEvent> shapeLocationsChangedEventCaptor = forClass(ShapeLocationsChangedEvent.class);
verify(shapeLocationsChangedEvent, times(1)).fire(shapeLocationsChangedEventCaptor.capture());
assertTrue(shapeLocationsChangedEventCaptor.getValue() instanceof ShapeLocationsChangedEvent);
// assert parent node move
final CompositeCommand command = (CompositeCommand) commandArgumentCaptor.getValue();
UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) command.getCommands().get(0);
assertEquals(element, updateElementPositionCommand.getElement());
assertEquals(location, updateElementPositionCommand.getLocation());
}
use of com.ait.lienzo.client.core.shape.wires.WiresConnection in project kie-wb-common by kiegroup.
the class ConnectionAcceptorControlImplTest method testCreateConnections.
@Test
public void testCreateConnections() {
// New default connection for a graph element.
Element element = mock(Element.class);
View<?> content = mock(View.class);
Bounds bounds = Bounds.create(0d, 0d, 10d, 20d);
when(element.getContent()).thenReturn(content);
when(content.getBounds()).thenReturn(bounds);
MagnetConnection c1 = ConnectionAcceptorControlImpl.createConnection(element);
assertEquals(5, c1.getLocation().getX(), 0);
assertEquals(10, c1.getLocation().getY(), 0);
assertEquals(MagnetConnection.MAGNET_CENTER, c1.getMagnetIndex().getAsInt());
assertFalse(c1.isAuto());
// New default connection for wires.
WiresConnection wiresConnection = mock(WiresConnection.class);
when(wiresConnection.isAutoConnection()).thenReturn(true);
WiresMagnet wiresMagnet = mock(WiresMagnet.class);
when(wiresMagnet.getX()).thenReturn(122d);
when(wiresMagnet.getY()).thenReturn(543d);
when(wiresMagnet.getIndex()).thenReturn(7);
MagnetConnection c2 = (MagnetConnection) ConnectionAcceptorControlImpl.createConnection(wiresConnection, wiresMagnet);
assertEquals(122, c2.getLocation().getX(), 0);
assertEquals(543, c2.getLocation().getY(), 0);
assertEquals(7, c2.getMagnetIndex().getAsInt());
assertTrue(c2.isAuto());
// Asset connections to concrete locations, when no concrete magnets assigned.
when(wiresConnection.getPoint()).thenReturn(new Point2D(122d, 543d));
final Connection pointConnection = ConnectionAcceptorControlImpl.createConnection(wiresConnection, null);
assertEquals(122d, pointConnection.getLocation().getX(), 0);
assertEquals(543d, pointConnection.getLocation().getY(), 0);
// Connections (view magnets) can be nullified.
assertNull(ConnectionAcceptorControlImpl.createConnection(null));
assertNull(ConnectionAcceptorControlImpl.createConnection(null, null));
}
use of com.ait.lienzo.client.core.shape.wires.WiresConnection in project kie-wb-common by kiegroup.
the class WiresShapeView method consumeChildrenAndConnectors.
void consumeChildrenAndConnectors(final Consumer<IDrawable> primConsumer) {
// Move this shape.
primConsumer.accept(getContainer());
// Move child shapes.
final NFastArrayList<WiresShape> childShapes = getChildShapes();
if (null != childShapes) {
for (int i = 0; i < childShapes.size(); i++) {
final WiresShape shape = childShapes.get(i);
if (shape instanceof WiresShapeView) {
((WiresShapeView) shape).consumeChildrenAndConnectors(primConsumer);
} else {
primConsumer.accept(shape.getContainer());
}
}
}
// Move connectors.
if (null != getMagnets()) {
for (int i = 0; i < getMagnets().size(); i++) {
final WiresMagnet magnet = getMagnets().getMagnet(i);
final NFastArrayList<WiresConnection> connections = magnet.getConnections();
if (null != connections) {
for (int j = 0; j < connections.size(); j++) {
final WiresConnection connection = connections.get(j);
if (null != connection.getConnector()) {
primConsumer.accept(connection.getConnector().getGroup());
}
}
}
}
}
}
Aggregations