Search in sources :

Example 46 with Bounds

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

the class GraphBoundsIndexerImpl method getNodeAbsoluteCoordinates.

private double[] getNodeAbsoluteCoordinates(final Node node, final double parentX, final double parentY) {
    final View content = (View) node.getContent();
    final Bounds bounds = content.getBounds();
    final Bound ulBound = bounds.getUpperLeft();
    final Bound lrBound = bounds.getLowerRight();
    final double ulX = ulBound.getX() + parentX;
    final double ulY = ulBound.getY() + parentY;
    final double lrX = lrBound.getX() + parentX;
    final double lrY = lrBound.getY() + parentY;
    return new double[] { ulX, ulY, lrX, lrY };
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 47 with Bounds

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

the class ClientBPMNDocumentationServiceTest method createNode.

private Node createNode(Object content) {
    NodeImpl node = new NodeImpl(UUID.uuid());
    node.setContent(new ViewImpl<>(content, new Bounds(new Bound(0d, 0d), new Bound(1d, 1d))));
    return node;
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound)

Example 48 with Bounds

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

the class ElementParser method initialize.

@Override
@SuppressWarnings("unchecked")
public void initialize(final Context context) {
    this.context = context;
    Object definition = element.getContent().getDefinition();
    // Resource id field.
    super.addParser(new StringFieldParser("resourceId", element.getUUID()));
    // Properties array.
    Object def = element.getContent().getDefinition();
    Set<?> properties = context.getDefinitionManager().adapters().forDefinition().getProperties(def);
    ObjectParser propertiesParser = new ObjectParser("properties");
    super.addParser(propertiesParser);
    if (null != properties && !properties.isEmpty()) {
        for (Object property : properties) {
            PropertyAdapter propertyAdapter = context.getDefinitionManager().adapters().registry().getPropertyAdapter(property.getClass());
            PropertyType propertyType = propertyAdapter.getType(property);
            String oryxPropId = context.getOryxManager().getMappingsManager().getOryxPropertyId(def.getClass(), property.getClass());
            Object value = propertyAdapter.getValue(property);
            String valueStr = value != null ? context.getOryxManager().getPropertyManager().serialize(property, propertyType, value) : "";
            propertiesParser.addParser(new StringFieldParser(oryxPropId, valueStr));
        }
    }
    // Custom extended prpoerties, if any.
    parseExtendedProperties(propertiesParser);
    // Stencil id field.
    String defId = context.getOryxManager().getMappingsManager().getOryxDefinitionId(definition);
    super.addParser(new ObjectParser("stencil").addParser(new StringFieldParser("id", defId)));
    // Bounds.
    Bounds.Bound ul = element.getContent().getBounds().getUpperLeft();
    Bounds.Bound lr = element.getContent().getBounds().getLowerRight();
    parseBounds(ul, lr);
}
Also used : ObjectParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) PropertyAdapter(org.kie.workbench.common.stunner.core.definition.adapter.PropertyAdapter) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType) StringFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser)

Example 49 with Bounds

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

the class GraphBuilder method translate.

/**
 * Move node into a new coordinate system with origin in newOrigin.
 * <p>
 * E.g., assume origin is currently (0,0), and consider node at (10,11).
 * If we move node into a new coordinate system where the origin is in (3, 4)
 * then the new coordinates for node are: (10-3, 11-4) = (7,7)
 */
private void translate(Node<? extends View, ?> node, Bounds.Bound newOrigin) {
    logger.debug("Translating {} into constraints {}", node.getContent().getBounds(), newOrigin);
    Bounds childBounds = node.getContent().getBounds();
    double constrainedX = childBounds.getUpperLeft().getX() - newOrigin.getX();
    double constrainedY = childBounds.getUpperLeft().getY() - newOrigin.getY();
    Point2D coords = Point2D.create(constrainedX, constrainedY);
    updatePosition(node, coords);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds)

Example 50 with Bounds

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

the class BPMNDiagramMarshallerTest 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();
    Bounds.Bound task1ULBound = task1Bounds.getUpperLeft();
    Bounds.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) Test(org.junit.Test)

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