Search in sources :

Example 16 with Bounds

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

the class MigrationDiagramMarshallerTest method assertNodeEquals.

private void assertNodeEquals(Diagram<Graph, Metadata> oldDiagram, Diagram<Graph, Metadata> newDiagram, String fileName) {
    Map<String, Node<View, ?>> oldNodes = asNodeMap(oldDiagram.getGraph().nodes());
    Map<String, Node<View, ?>> newNodes = asNodeMap(newDiagram.getGraph().nodes());
    assertEquals(fileName + ": Number of nodes should match", oldNodes.size(), newNodes.size());
    for (Node<View, ?> o : oldNodes.values()) {
        Node<View, ?> n = newNodes.get(o.getUUID());
        View oldContent = o.getContent();
        View newContent = n.getContent();
        Bounds oldBounds = oldContent.getBounds();
        Bounds newBounds = newContent.getBounds();
        assertEquals(fileName + ": Bounds should match for " + o.getUUID(), oldBounds, newBounds);
        Object oldDefinition = oldContent.getDefinition();
        Object newDefinition = newContent.getDefinition();
        assertEquals(fileName + ": Definitions should match for " + o.getUUID(), oldDefinition, newDefinition);
    }
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Matchers.anyString(org.mockito.Matchers.anyString) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 17 with Bounds

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

the class BPMNDiagramMarshallerBase method assertNodeEquals.

private void assertNodeEquals(Diagram<Graph, Metadata> oldDiagram, Diagram<Graph, Metadata> newDiagram, String fileName) {
    Map<String, Node<View, ?>> oldNodes = asNodeMap(oldDiagram.getGraph().nodes());
    Map<String, Node<View, ?>> newNodes = asNodeMap(newDiagram.getGraph().nodes());
    assertEquals(fileName + ": Number of nodes should match", oldNodes.size(), newNodes.size());
    for (Node<View, ?> o : oldNodes.values()) {
        Node<View, ?> n = newNodes.get(o.getUUID());
        View oldContent = o.getContent();
        View newContent = n.getContent();
        Bounds oldBounds = oldContent.getBounds();
        Bounds newBounds = newContent.getBounds();
        assertEquals(fileName + ": Bounds should match for " + o.getUUID(), oldBounds, newBounds);
        Object oldDefinition = oldContent.getDefinition();
        Object newDefinition = newContent.getDefinition();
        assertEquals(fileName + ": Definitions should match for " + o.getUUID(), oldDefinition, newDefinition);
    }
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Matchers.anyString(org.mockito.Matchers.anyString) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 18 with Bounds

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

the class BPMNDiagramMarshallerTest 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();
    Bounds.Bound ul = bounds.getUpperLeft();
    Bounds.Bound lr = bounds.getLowerRight();
    assertEquals(305, ul.getX(), 0);
    assertEquals(300, ul.getY(), 0);
    assertEquals(335, lr.getX(), 0);
    assertEquals(330, 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) 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 19 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 20 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)

Aggregations

Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)34 View (org.kie.workbench.common.stunner.core.graph.content.view.View)18 Test (org.junit.Test)16 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)13 Node (org.kie.workbench.common.stunner.core.graph.Node)13 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 Graph (org.kie.workbench.common.stunner.core.graph.Graph)7 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)6 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)6 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)5 Ignore (org.junit.Ignore)4 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)4 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)4 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)4 Consumer (java.util.function.Consumer)2 Before (org.junit.Before)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)2 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)2 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)2