Search in sources :

Example 6 with ControlPoint

use of org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint in project kie-wb-common by kiegroup.

the class WiresConnectorViewTest method testAddControlPoint.

@Test
public void testAddControlPoint() {
    Point2D point1 = point2DArray.get(1);
    Point2D point2 = point2DArray.get(2);
    Point2D point3 = point2DArray.get(3);
    when(wiresConnectorControl.addControlPoint(point1.getX(), point1.getY())).thenReturn(1);
    when(wiresConnectorControl.addControlPoint(point2.getX(), point2.getY())).thenReturn(2);
    when(wiresConnectorControl.addControlPoint(point3.getX(), point3.getY())).thenReturn(3);
    ControlPoint controlPoint1 = new ControlPointImpl(point1.getX(), point1.getY());
    ControlPoint controlPoint2 = new ControlPointImpl(point2.getX(), point2.getY());
    ControlPoint controlPoint3 = new ControlPointImpl(point3.getX(), point3.getY());
    // without index
    List<ControlPoint> addedControlPoint = tested.addControlPoint(controlPoint1, controlPoint2);
    addedControlPoint.addAll(tested.addControlPoint(controlPoint3));
    InOrder addControlPointOrder = inOrder(wiresConnectorControl);
    addControlPointOrder.verify(wiresConnectorControl).addControlPoint(point1.getX(), point1.getY());
    addControlPointOrder.verify(wiresConnectorControl).addControlPoint(point2.getX(), point2.getY());
    addControlPointOrder.verify(wiresConnectorControl).addControlPoint(point3.getX(), point3.getY());
    assertEquals(addedControlPoint.get(0).getIndex(), 1, 0);
    assertEquals(addedControlPoint.get(1).getIndex(), 2, 0);
    assertEquals(addedControlPoint.get(2).getIndex(), 3, 0);
    // now with index
    addedControlPoint = tested.addControlPoint(controlPoint1, controlPoint2, controlPoint3);
    addControlPointOrder = inOrder(wiresConnectorControl);
    addControlPointOrder.verify(wiresConnectorControl).addControlPointToLine(controlPoint1.getLocation().getX(), controlPoint1.getLocation().getY(), controlPoint1.getIndex());
    addControlPointOrder.verify(wiresConnectorControl).addControlPointToLine(controlPoint2.getLocation().getX(), controlPoint2.getLocation().getY(), controlPoint2.getIndex());
    addControlPointOrder.verify(wiresConnectorControl).addControlPointToLine(controlPoint3.getLocation().getX(), controlPoint3.getLocation().getY(), controlPoint3.getIndex());
    assertEquals(addedControlPoint.get(0).getIndex(), 1, 0);
    assertEquals(addedControlPoint.get(1).getIndex(), 2, 0);
    assertEquals(addedControlPoint.get(2).getIndex(), 3, 0);
}
Also used : InOrder(org.mockito.InOrder) Point2D(com.ait.lienzo.client.core.types.Point2D) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) Test(org.junit.Test)

Example 7 with ControlPoint

use of org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint in project kie-wb-common by kiegroup.

the class AbstractEdgeBuilder method buildControlPoints.

private void buildControlPoints(BuilderContext context, T edge, GraphCommandFactory commandFactory) {
    if (dockers.size() > 2) {
        Counter indexCounter = new Counter(0);
        ControlPoint[] controlPoints = dockers.subList(1, dockers.size() - 1).stream().sequential().map(docker -> (docker.length == 2 ? new Point2D(docker[0], docker[1]) : null)).filter(Objects::nonNull).map(point -> new ControlPointImpl(point, indexCounter.increment())).toArray(ControlPoint[]::new);
        CommandResult<RuleViolation> addControlPointsResult = context.execute(commandFactory.addControlPoint(edge, controlPoints));
        if (hasErrors(addControlPointsResult)) {
            throw new RuntimeException("Error building BPMN graph. Command 'AddControlPointCommand' execution failed." + addControlPointsResult);
        }
    }
}
Also used : AddControlPointCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddControlPointCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) BPMNDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNDefinition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) MutableIndex(org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex) Collectors(java.util.stream.Collectors) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Objects(java.util.Objects) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) CommandUtils(org.kie.workbench.common.stunner.core.command.util.CommandUtils) Bpmn2OryxManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager) Counter(org.kie.workbench.common.stunner.core.util.Counter) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SetConnectionTargetNodeCommand) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Node(org.kie.workbench.common.stunner.core.graph.Node) Counter(org.kie.workbench.common.stunner.core.util.Counter) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Objects(java.util.Objects) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 8 with ControlPoint

use of org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint in project kie-wb-common by kiegroup.

the class EdgeParser method initialize.

@SuppressWarnings("unchecked")
@Override
public void initialize(final Context context) {
    super.initialize(context);
    String outNodeId = element.getTargetNode() != null ? element.getTargetNode().getUUID() : null;
    // Outgoing.
    if (null != outNodeId) {
        ArrayParser outgoingParser = new ArrayParser("outgoing");
        outgoingParser.addParser(new ObjectParser("").addParser(new StringFieldParser("resourceId", outNodeId)));
        super.addParser(outgoingParser);
    }
    // Use dockers
    ArrayParser dockersParser = new ArrayParser("dockers");
    ViewConnector viewConnector = (ViewConnector) element.getContent();
    // insert source
    dockersParser.addParser(createDockerObjectParser(viewConnector.getSourceConnection()));
    // inserting ControlPoints
    viewConnector.getControlPoints().stream().sequential().map(ControlPoint::getLocation).map(this::createDockerObjectParser).forEach(dockersParser::addParser);
    // insert target
    dockersParser.addParser(createDockerObjectParser(viewConnector.getTargetConnection()));
    super.addParser(dockersParser);
}
Also used : ObjectParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) ArrayParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ArrayParser) StringFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser)

Example 9 with ControlPoint

use of org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint in project kie-wb-common by kiegroup.

the class WiresConnectorViewTest method testGetShapeControlPoints.

@Test
public void testGetShapeControlPoints() {
    List<ControlPoint> controlPoints = tested.getShapeControlPoints();
    for (int i = 1; i < controlPoints.size() - 1; i++) {
        ControlPoint controlPoint = controlPoints.get(i);
        Point2D point = point2DArray.get(i);
        assertEquals(controlPoint.getLocation().getX(), point.getX(), 0);
        assertEquals(controlPoint.getLocation().getY(), point.getY(), 0);
        assertEquals(controlPoint.getIndex().intValue(), i);
    }
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) Test(org.junit.Test)

Aggregations

ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)9 ControlPointImpl (org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl)4 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)3 Point2D (com.ait.lienzo.client.core.types.Point2D)2 Objects (java.util.Objects)2 Test (org.junit.Test)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)2 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 Bpmn2OryxManager (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager)1 ArrayParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ArrayParser)1 ObjectParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser)1 StringFieldParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser)1 BPMNDefinition (org.kie.workbench.common.stunner.bpmn.definition.BPMNDefinition)1 FactoryManager (org.kie.workbench.common.stunner.core.api.FactoryManager)1 CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 CanvasViolationImpl (org.kie.workbench.common.stunner.core.client.command.CanvasViolationImpl)1 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)1