Search in sources :

Example 36 with Bound

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

the class ProcessPostConverter method postConvertSubProcess.

private void postConvertSubProcess(BpmnNode subProcess) {
    subProcess.getChildren().stream().filter(ProcessPostConverter::isSubProcess).forEach(this::postConvertSubProcess);
    List<BpmnNode> resizedChildren = context.getResizedChildren(subProcess);
    resizedChildren.forEach(resizedChild -> applyNodeResize(subProcess, resizedChild));
    if ((context.isCollapsed(subProcess) && subProcess.hasChildren()) || !resizedChildren.isEmpty()) {
        resizeSubProcess(subProcess);
    }
    if (context.isCollapsed(subProcess)) {
        Bound subProcessUl = subProcess.value().getContent().getBounds().getUpperLeft();
        // boundary elements are relative to the target node, translation is no applied for this elements.
        subProcess.getChildren().stream().filter(child -> !child.isDocked()).forEach(child -> translate(child, subProcessUl.getX(), subProcessUl.getY()));
        translate(subProcess.getEdges(), subProcessUl.getX(), subProcessUl.getY());
        context.setCollapsed(subProcess, false);
    }
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) BPMNBaseInfo(org.kie.workbench.common.stunner.bpmn.definition.BPMNBaseInfo) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) Point(org.eclipse.dd.dc.Point) HashMap(java.util.HashMap) Width(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.Width) Function(java.util.function.Function) AdHocSubprocess(org.kie.workbench.common.stunner.bpmn.definition.AdHocSubprocess) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) BPMNViewDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNViewDefinition) Name(org.kie.workbench.common.stunner.bpmn.definition.property.general.Name) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) MarshallingMessageKeys(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessageKeys) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge) Result(org.kie.workbench.common.stunner.bpmn.backend.converters.Result) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) EdgePropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EdgePropertyReader) Collection(java.util.Collection) Violation(org.kie.workbench.common.stunner.core.validation.Violation) Height(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.Height) Collectors(java.util.stream.Collectors) RectangleDimensionsSet(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.RectangleDimensionsSet) BaseSubprocess(org.kie.workbench.common.stunner.bpmn.definition.BaseSubprocess) List(java.util.List) Stream(java.util.stream.Stream) EventSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EventSubprocess) EmbeddedSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EmbeddedSubprocess) Optional(java.util.Optional) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Collections(java.util.Collections) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Node(org.kie.workbench.common.stunner.core.graph.Node) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound)

Example 37 with Bound

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

the class ProcessPostConverter method resizeSubProcess.

private void resizeSubProcess(BpmnNode subProcess) {
    if (subProcess.hasChildren()) {
        ViewPort viewPort = ViewPort.of(subProcess, true);
        double leftPadding = viewPort.getUpperLeftX();
        double topPadding = viewPort.getUpperLeftY();
        double width = viewPort.getLowerRightX() + leftPadding;
        double height = viewPort.getLowerRightY() + topPadding;
        Bounds subProcessBounds = subProcess.value().getContent().getBounds();
        Bound subProcessUl = subProcessBounds.getUpperLeft();
        Bound subProcessLr = subProcessBounds.getLowerRight();
        Bounds subProcessOriginalBounds = Bounds.create(subProcessUl.getX(), subProcessUl.getY(), subProcessLr.getX(), subProcessLr.getY());
        double originalWidth = subProcessBounds.getWidth();
        double originalHeight = subProcessBounds.getHeight();
        subProcessLr.setX(subProcessUl.getX() + width);
        subProcessLr.setY(subProcessUl.getY() + height);
        RectangleDimensionsSet subProcessRectangle = ((BaseSubprocess) subProcess.value().getContent().getDefinition()).getDimensionsSet();
        subProcessRectangle.setWidth(new Width(width));
        subProcessRectangle.setHeight(new Height(height));
        context.setResized(subProcess, true);
        double widthFactor = width / originalWidth;
        double heightFactor = height / originalHeight;
        // incoming connections has the target point relative to subProcess so they needs to be scaled.
        inEdges(subProcess.getParent(), subProcess).forEach(edge -> scale(edge.getTargetConnection().getLocation(), widthFactor, heightFactor));
        // outgoing connections has source point relative to the subProcess so they needs to be scaled.
        outEdges(subProcess.getParent(), subProcess).forEach(edge -> scale(edge.getSourceConnection().getLocation(), widthFactor, heightFactor));
        // boundary elements are relative to the target subProcess so they needs to be scaled.
        dockedNodes(subProcess.getParent(), subProcess).forEach(node -> scaleBoundaryEventPosition(node, subProcessOriginalBounds, subProcessBounds, widthFactor, heightFactor));
    }
}
Also used : BaseSubprocess(org.kie.workbench.common.stunner.bpmn.definition.BaseSubprocess) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) Height(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.Height) RectangleDimensionsSet(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.RectangleDimensionsSet) Width(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.Width)

Example 38 with Bound

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

the class BPMNDirectDiagramMarshallerTest method testUnmarshallBoundaryEvents.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallBoundaryEvents() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_BOUNDARY_EVENTS);
    // Basic assertions.
    assertEquals("Boundary Event", diagram.getMetadata().getTitle());
    assertDiagram(diagram, 6);
    // Assert than the intermediate event is connected using a dock connector,
    // so boundary to the task.
    Node event = diagram.getGraph().getNode("_CB178D55-8DC2-4CAA-8C42-4F5028D4A1F6");
    List<Edge> inEdges = event.getInEdges();
    boolean foundDockConector = false;
    for (Edge e : inEdges) {
        if (e.getContent() instanceof Dock) {
            foundDockConector = true;
        }
    }
    assertTrue(foundDockConector);
    // Assert relative position for the docked node.
    Bounds bounds = ((View) event.getContent()).getBounds();
    Bound ul = bounds.getUpperLeft();
    Bound lr = bounds.getLowerRight();
    assertEquals(57, ul.getX(), 0);
    assertEquals(70, ul.getY(), 0);
    assertEquals(113, lr.getX(), 0);
    assertEquals(126, lr.getY(), 0);
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 39 with Bound

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

the class BPMNDirectDiagramMarshallerTest method testUnmarshallNotBoundaryEvents.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallNotBoundaryEvents() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_NOT_BOUNDARY_EVENTS);
    assertEquals("Not Boundary Event", diagram.getMetadata().getTitle());
    assertDiagram(diagram, 6);
    // Assert than the intermediate event is connected using a view connector,
    // so not boundary to the task ( not docked ).
    Node event = diagram.getGraph().getNode("_CB178D55-8DC2-4CAA-8C42-4F5028D4A1F6");
    List<Edge> inEdges = event.getInEdges();
    boolean foundViewConnector = false;
    for (Edge e : inEdges) {
        if (e.getContent() instanceof ViewConnector) {
            foundViewConnector = true;
        }
    }
    assertTrue(foundViewConnector);
    // Assert absolute position as the node is not docked.
    Bounds bounds = ((View) event.getContent()).getBounds();
    Bound ul = bounds.getUpperLeft();
    Bound lr = bounds.getLowerRight();
    assertEquals(305, ul.getX(), 0);
    assertEquals(300, ul.getY(), 0);
    assertEquals(361, lr.getX(), 0);
    assertEquals(356, lr.getY(), 0);
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 40 with Bound

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

the class BPMNDirectDiagramMarshallerTest method testUnmarshallEvaluation.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallEvaluation() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_EVALUATION);
    assertDiagram(diagram, 8);
    assertEquals("Evaluation", diagram.getMetadata().getTitle());
    Node<? extends View, ?> task1 = diagram.getGraph().getNode("_88233779-B395-4B8C-A086-9EF43698426C");
    Node<? extends View, ?> task2 = diagram.getGraph().getNode("_AE5BF0DC-B720-4FDE-9499-5ED89D41FB1A");
    Node<? extends View, ?> task3 = diagram.getGraph().getNode("_6063D302-9D81-4C86-920B-E808A45377C2");
    assertTrue(task1.getContent().getDefinition() instanceof UserTask);
    assertTrue(task2.getContent().getDefinition() instanceof UserTask);
    assertTrue(task3.getContent().getDefinition() instanceof UserTask);
    // Assert bounds.
    Bounds task1Bounds = task1.getContent().getBounds();
    Bound task1ULBound = task1Bounds.getUpperLeft();
    Bound task1LRBound = task1Bounds.getLowerRight();
    assertEquals(648d, task1ULBound.getX(), 0);
    assertEquals(149d, task1ULBound.getY(), 0);
    assertEquals(784d, task1LRBound.getX(), 0);
    assertEquals(197d, task1LRBound.getY(), 0);
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) Test(org.junit.Test)

Aggregations

Bound (org.kie.workbench.common.stunner.core.graph.content.Bound)40 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)24 View (org.kie.workbench.common.stunner.core.graph.content.view.View)22 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)12 Test (org.junit.Test)10 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)9 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)7 List (java.util.List)6 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)6 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)5 ArrayList (java.util.ArrayList)4 Optional (java.util.Optional)4 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)4 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)4 Graph (org.kie.workbench.common.stunner.core.graph.Graph)4 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3