Search in sources :

Example 86 with Bounds

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));
    }
}
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 87 with Bounds

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);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds)

Example 88 with Bounds

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);
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds)

Example 89 with 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);
}
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 90 with Bounds

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);
    });
}
Also used : EventGateway(org.kie.workbench.common.stunner.bpmn.definition.EventGateway) Arrays(java.util.Arrays) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) ReusableSubprocessTaskExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.task.ReusableSubprocessTaskExecutionSet) EndErrorEvent(org.kie.workbench.common.stunner.bpmn.definition.EndErrorEvent) Edge(org.kie.workbench.common.stunner.core.graph.Edge) TimerSettings(org.kie.workbench.common.stunner.bpmn.definition.property.event.timer.TimerSettings) SimulationSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationSet) StartTimerEvent(org.kie.workbench.common.stunner.bpmn.definition.StartTimerEvent) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) GenericServiceTaskValue(org.kie.workbench.common.stunner.bpmn.definition.property.service.GenericServiceTaskValue) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) Matcher(java.util.regex.Matcher) BasePropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.BasePropertyWriter) GenericServiceTask(org.kie.workbench.common.stunner.bpmn.definition.GenericServiceTask) EndTerminateEvent(org.kie.workbench.common.stunner.bpmn.definition.EndTerminateEvent) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) BPMNTestDefinitionFactory(org.kie.workbench.common.stunner.bpmn.BPMNTestDefinitionFactory) WorkItemDefinitionMockRegistry(org.kie.workbench.common.stunner.bpmn.WorkItemDefinitionMockRegistry) NotificationValue(org.kie.workbench.common.stunner.bpmn.definition.property.notification.NotificationValue) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) StartConditionalEvent(org.kie.workbench.common.stunner.bpmn.definition.StartConditionalEvent) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) BaseReusableSubprocessTaskExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.task.BaseReusableSubprocessTaskExecutionSet) Stream(java.util.stream.Stream) EmbeddedSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EmbeddedSubprocess) GlobalVariables(org.kie.workbench.common.stunner.bpmn.definition.property.diagram.GlobalVariables) Assert.assertFalse(org.junit.Assert.assertFalse) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) NoneTask(org.kie.workbench.common.stunner.bpmn.definition.NoneTask) ViewConnectorImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnectorImpl) InputOutputSpecification(org.eclipse.bpmn2.InputOutputSpecification) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) DeclarationList(org.kie.workbench.common.stunner.bpmn.backend.converters.customproperties.DeclarationList) NotificationsInfo(org.kie.workbench.common.stunner.bpmn.definition.property.notification.NotificationsInfo) Mockito.mock(org.mockito.Mockito.mock) StartCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.StartCompensationEvent) StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) BPMNGeneralSet(org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) Mock(org.mockito.Mock) BusinessRuleTask(org.kie.workbench.common.stunner.bpmn.definition.BusinessRuleTask) RunWith(org.junit.runner.RunWith) MessageRef(org.kie.workbench.common.stunner.bpmn.definition.property.event.message.MessageRef) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) AdHocSubprocess(org.kie.workbench.common.stunner.bpmn.definition.AdHocSubprocess) ArrayList(java.util.ArrayList) DataInput(org.eclipse.bpmn2.DataInput) Property(org.eclipse.bpmn2.Property) IntermediateEscalationEventThrowing(org.kie.workbench.common.stunner.bpmn.definition.IntermediateEscalationEventThrowing) ProcessData(org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessData) EndCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndCompensationEvent) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) IntermediateSignalEventCatching(org.kie.workbench.common.stunner.bpmn.definition.IntermediateSignalEventCatching) Before(org.junit.Before) MetaDataType(org.jboss.drools.MetaDataType) AssignmentsInfo(org.kie.workbench.common.stunner.bpmn.definition.property.dataio.AssignmentsInfo) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) EndMessageEvent(org.kie.workbench.common.stunner.bpmn.definition.EndMessageEvent) EndSignalEvent(org.kie.workbench.common.stunner.bpmn.definition.EndSignalEvent) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) IntermediateEscalationEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateEscalationEvent) Assert.assertTrue(org.junit.Assert.assertTrue) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Test(org.junit.Test) Association(org.kie.workbench.common.stunner.bpmn.definition.Association) InterruptingErrorEventExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.event.error.InterruptingErrorEventExecutionSet) Graph(org.kie.workbench.common.stunner.core.graph.Graph) IntermediateMessageEventThrowing(org.kie.workbench.common.stunner.bpmn.definition.IntermediateMessageEventThrowing) Assert.assertNull(org.junit.Assert.assertNull) SignalRef(org.kie.workbench.common.stunner.bpmn.definition.property.event.signal.SignalRef) WorkItemDefinitionRegistry(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinitionRegistry) IsInterrupting(org.kie.workbench.common.stunner.bpmn.definition.property.event.IsInterrupting) MultipleInstanceSubprocess(org.kie.workbench.common.stunner.bpmn.definition.MultipleInstanceSubprocess) ReassignmentsInfo(org.kie.workbench.common.stunner.bpmn.definition.property.reassignment.ReassignmentsInfo) FlowElement(org.eclipse.bpmn2.FlowElement) ReassignmentValue(org.kie.workbench.common.stunner.bpmn.definition.property.reassignment.ReassignmentValue) Assert.assertEquals(org.junit.Assert.assertEquals) RootElement(org.eclipse.bpmn2.RootElement) IntermediateCompensationEventThrowing(org.kie.workbench.common.stunner.bpmn.definition.IntermediateCompensationEventThrowing) IntermediateErrorEventCatching(org.kie.workbench.common.stunner.bpmn.definition.IntermediateErrorEventCatching) WorkItemDefinitionLookupService(org.kie.workbench.common.stunner.bpmn.workitem.service.WorkItemDefinitionLookupService) StartSignalEvent(org.kie.workbench.common.stunner.bpmn.definition.StartSignalEvent) UserTaskExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.task.UserTaskExecutionSet) Activity(org.eclipse.bpmn2.Activity) IntermediateCompensationEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateCompensationEvent) CustomTask(org.kie.workbench.common.stunner.bpmn.workitem.CustomTask) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutput(org.eclipse.bpmn2.DataOutput) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) Assert.fail(org.junit.Assert.fail) Assertions.assertDiagram(org.kie.workbench.common.stunner.bpmn.backend.service.diagram.Assertions.assertDiagram) EStructuralFeatureImpl(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) StartErrorEvent(org.kie.workbench.common.stunner.bpmn.definition.StartErrorEvent) ExclusiveGateway(org.kie.workbench.common.stunner.bpmn.definition.ExclusiveGateway) Collectors(java.util.stream.Collectors) TaskTypes(org.kie.workbench.common.stunner.bpmn.definition.property.task.TaskTypes) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) List(java.util.List) DiagramSet(org.kie.workbench.common.stunner.bpmn.definition.property.diagram.DiagramSet) BPMNDefinitionSet(org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet) Optional(java.util.Optional) IntermediateTimerEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateTimerEvent) StartMessageEvent(org.kie.workbench.common.stunner.bpmn.definition.StartMessageEvent) Pattern(java.util.regex.Pattern) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Node(org.kie.workbench.common.stunner.core.graph.Node) DataIOSet(org.kie.workbench.common.stunner.bpmn.definition.property.dataio.DataIOSet) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) EndEscalationEvent(org.kie.workbench.common.stunner.bpmn.definition.EndEscalationEvent) IntermediateConditionalEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateConditionalEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) StunnerTestingGraphAPI(org.kie.workbench.common.stunner.core.StunnerTestingGraphAPI) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) Assertions.assertDocumentation(org.kie.workbench.common.stunner.bpmn.backend.service.diagram.Assertions.assertDocumentation) Element(org.kie.workbench.common.stunner.core.graph.Element) IntermediateSignalEventThrowing(org.kie.workbench.common.stunner.bpmn.definition.IntermediateSignalEventThrowing) ReusableSubprocess(org.kie.workbench.common.stunner.bpmn.definition.ReusableSubprocess) Definitions(org.eclipse.bpmn2.Definitions) CancellingTimerEventExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.event.timer.CancellingTimerEventExecutionSet) BPMNDirectDiagramMarshaller(org.kie.workbench.common.stunner.bpmn.backend.BPMNDirectDiagramMarshaller) VariableDeclaration(org.kie.workbench.common.stunner.bpmn.backend.converters.customproperties.VariableDeclaration) Process(org.eclipse.bpmn2.Process) Iterator(java.util.Iterator) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) ParsedAssignmentsInfo(org.kie.workbench.common.stunner.bpmn.backend.converters.customproperties.ParsedAssignmentsInfo) Assert.assertNotNull(org.junit.Assert.assertNotNull) DataTypeCacheServer(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.processes.DataTypeCacheServer) InclusiveGateway(org.kie.workbench.common.stunner.bpmn.definition.InclusiveGateway) StunnerTestingGraphBackendAPI(org.kie.workbench.common.stunner.core.backend.StunnerTestingGraphBackendAPI) Mockito.when(org.mockito.Mockito.when) AdHocSubprocessTaskExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.task.AdHocSubprocessTaskExecutionSet) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) EventSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EventSubprocess) StartEscalationEvent(org.kie.workbench.common.stunner.bpmn.definition.StartEscalationEvent) ProcessVariables(org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessVariables) IntermediateMessageEventCatching(org.kie.workbench.common.stunner.bpmn.definition.IntermediateMessageEventCatching) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) EndNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.EndNoneEvent) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)95 Test (org.junit.Test)42 View (org.kie.workbench.common.stunner.core.graph.content.view.View)34 Bound (org.kie.workbench.common.stunner.core.graph.content.Bound)26 Node (org.kie.workbench.common.stunner.core.graph.Node)24 Edge (org.kie.workbench.common.stunner.core.graph.Edge)20 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)20 Graph (org.kie.workbench.common.stunner.core.graph.Graph)9 ArrayList (java.util.ArrayList)8 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)7 HasBounds (org.kie.workbench.common.stunner.core.graph.content.HasBounds)7 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)7 Dock (org.kie.workbench.common.stunner.core.graph.content.relationship.Dock)6 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)6 Before (org.junit.Before)5 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)5 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)5 List (java.util.List)4 Ignore (org.junit.Ignore)4 Lane (org.kie.workbench.common.stunner.bpmn.definition.Lane)4