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