use of org.kie.workbench.common.stunner.core.graph.content.Bounds 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.Bounds in project kie-wb-common by kiegroup.
the class BoundaryEventPropertyReader method computeBounds.
@Override
protected Bounds computeBounds(final org.eclipse.dd.dc.Bounds bounds) {
final Point2D docker = getDockerInfo();
double x = 0;
double y = 0;
if (docker.getX() != 0 && docker.getY() != 0) {
x = docker.getX() * resolutionFactor;
y = docker.getY() * resolutionFactor;
} else if (event.getAttachedToRef() != null) {
// when the node was generated in other tool than Stunner/jBPM designer the dockerInfo attribute don't exists
// and we need to use attachedToRef activity position to calculate the bounded event relative coordinates.
String activityId = event.getAttachedToRef().getId();
org.eclipse.dd.dc.Bounds activityBounds = definitionResolver.getShape(activityId).getBounds();
x = bounds.getX() * resolutionFactor - activityBounds.getX() * resolutionFactor;
y = bounds.getY() * resolutionFactor - activityBounds.getY() * resolutionFactor;
// if required adjust the event relative position according with the positioning supported by Stunner.
if (x < -WIDTH / 2) {
x = -WIDTH / 2;
} else if (x > (activityBounds.getWidth() * resolutionFactor) - WIDTH / 2) {
x = activityBounds.getWidth() * resolutionFactor - WIDTH / 2;
}
if (y < -HEIGHT / 2) {
y = -HEIGHT / 2;
} else if (y > (activityBounds.getHeight() * resolutionFactor) - HEIGHT / 2) {
y = activityBounds.getHeight() * resolutionFactor - HEIGHT / 2;
}
}
return Bounds.create(x, y, x + WIDTH, y + HEIGHT);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class LocationControlImpl method ensureDragConstraints.
@SuppressWarnings("unchecked")
private static void ensureDragConstraints(final AbstractCanvas<?> canvas, final ShapeView shapeView) {
final Bounds bounds = canvas.getView().getPanel().getLocationConstraints();
ShapeUtils.enforceLocationConstraints(shapeView, bounds);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds 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.Bounds in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method assertContains.
@SuppressWarnings("unchecked")
private static void assertContains(Node<View<? extends Definition>, ?> container, List<String> containedNodes) {
List<Node> children = GraphUtils.getChildNodes(container).stream().filter(child -> containedNodes.contains(child.getUUID())).collect(Collectors.toList());
Bounds containerBounds = container.getContent().getBounds();
Point2D containerAbsolutePosition = GraphUtils.getComputedPosition(container);
Bounds containerAbsoluteBounds = Bounds.create(containerAbsolutePosition.getX(), containerAbsolutePosition.getY(), containerAbsolutePosition.getX() + containerBounds.getWidth(), containerAbsolutePosition.getY() + containerBounds.getHeight());
assertEquals(containedNodes.size(), children.size());
children.forEach(child -> {
Bounds relativeBounds = ((View) child.getContent()).getBounds();
Point2D absolutePosition = GraphUtils.getComputedPosition(child);
Bounds absoluteBounds = Bounds.create(absolutePosition.getX(), absolutePosition.getY(), absolutePosition.getX() + relativeBounds.getWidth(), absolutePosition.getY() + relativeBounds.getHeight());
assertContains(containerAbsoluteBounds, absoluteBounds);
});
}
Aggregations