Search in sources :

Example 1 with Point

use of org.eclipse.dd.dc.Point in project kie-wb-common by kiegroup.

the class SequenceFlowPropertyReader method getTargetPosition.

private Point2D getTargetPosition(String edgeId, String targetId) {
    BPMNEdge bpmnEdge = definitionResolver.getEdge(edgeId).get();
    Bounds targetBounds = definitionResolver.getShape(targetId).getBounds();
    List<Point> waypoint = bpmnEdge.getWaypoint();
    if (waypoint.size() > 2) {
        logger.warn("Waypoints should be either 0 or 2. Unexpected size: " + waypoint.size());
    }
    return waypoint.isEmpty() ? targetPosition(targetBounds) : offsetPosition(targetBounds, waypoint.get(waypoint.size() - 1));
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) Point(org.eclipse.dd.dc.Point) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 2 with Point

use of org.eclipse.dd.dc.Point in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallAssociation.

protected void marshallAssociation(Association association, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    Iterator<FeatureMap.Entry> iter = association.getAnyAttribute().iterator();
    boolean foundBrColor = false;
    while (iter.hasNext()) {
        FeatureMap.Entry entry = iter.next();
        if (entry.getEStructuralFeature().getName().equals("type")) {
            properties.put(TYPE, entry.getValue());
        }
        if (entry.getEStructuralFeature().getName().equals("bordercolor")) {
            properties.put(BORDERCOLOR, entry.getValue());
            foundBrColor = true;
        }
    }
    if (!foundBrColor) {
        properties.put("bordercolor", defaultSequenceflowColor);
    }
    putDocumentationProperty(association, properties);
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    if (association.getAssociationDirection().equals(AssociationDirection.ONE)) {
        generator.writeObjectField("id", "Association_Unidirectional");
    } else if (association.getAssociationDirection().equals(AssociationDirection.BOTH)) {
        generator.writeObjectField("id", "Association_Bidirectional");
    } else {
        generator.writeObjectField("id", "Association_Undirected");
    }
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    generator.writeStartObject();
    generator.writeObjectField("resourceId", association.getTargetRef().getId());
    generator.writeEndObject();
    generator.writeEndArray();
    Bounds sourceBounds = ((BPMNShape) findDiagramElement(plane, association.getSourceRef())).getBounds();
    Bounds targetBounds = null;
    float tbx = 0;
    float tby = 0;
    if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNShape) {
        targetBounds = ((BPMNShape) findDiagramElement(plane, association.getTargetRef())).getBounds();
    } else if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNEdge) {
        // connect it to first waypoint on edge
        List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association.getTargetRef())).getWaypoint();
        if (waypoints != null && waypoints.size() > 0) {
            tbx = waypoints.get(0).getX();
            tby = waypoints.get(0).getY();
        }
    }
    generator.writeArrayFieldStart("dockers");
    generator.writeStartObject();
    generator.writeObjectField("x", sourceBounds.getWidth() / 2);
    generator.writeObjectField("y", sourceBounds.getHeight() / 2);
    generator.writeEndObject();
    List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association)).getWaypoint();
    for (int i = 1; i < waypoints.size() - 1; i++) {
        Point waypoint = waypoints.get(i);
        generator.writeStartObject();
        generator.writeObjectField("x", waypoint.getX());
        generator.writeObjectField("y", waypoint.getY());
        generator.writeEndObject();
    }
    if (targetBounds != null) {
        generator.writeStartObject();
        // text annotations have to be treated specia
        if (association.getTargetRef() instanceof TextAnnotation) {
            generator.writeObjectField("x", 1);
            generator.writeObjectField("y", targetBounds.getHeight() / 2);
        } else {
            generator.writeObjectField("x", targetBounds.getWidth() / 2);
            generator.writeObjectField("y", targetBounds.getHeight() / 2);
        }
        generator.writeEndObject();
        generator.writeEndArray();
    } else {
        generator.writeStartObject();
        generator.writeObjectField("x", tbx);
        generator.writeObjectField("y", tby);
        generator.writeEndObject();
        generator.writeEndArray();
    }
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Point(org.eclipse.dd.dc.Point) LinkedHashMap(java.util.LinkedHashMap) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Entry(java.util.Map.Entry) DataObject(org.eclipse.bpmn2.DataObject) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 3 with Point

use of org.eclipse.dd.dc.Point in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method updateEdgeBoundsInLanes.

public void updateEdgeBoundsInLanes(Definitions def, BPMNPlane plane, BPMNEdge edge, BaseElement ele) {
    if (ele instanceof SequenceFlow) {
        SequenceFlow sq = (SequenceFlow) ele;
        // update the source and target on BPMNEdge
        if (sq.getSourceRef() != null) {
            edge.setSourceElement(getBPMNShapeForElement(sq.getSourceRef(), plane));
        }
        if (sq.getTargetRef() != null) {
            edge.setTargetElement(getBPMNShapeForElement(sq.getTargetRef(), plane));
        }
        List<RootElement> rootElements = def.getRootElements();
        for (RootElement root : rootElements) {
            if (root instanceof Process) {
                Process process = (Process) root;
                if (sq.getSourceRef() != null && sq.getTargetRef() != null) {
                    if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
                        for (LaneSet ls : process.getLaneSets()) {
                            for (Lane newLane : ls.getLanes()) {
                                List<FlowNode> laneFlowNodes = newLane.getFlowNodeRefs();
                                Bounds laneBounds = getBoundsForElement(newLane, plane);
                                for (FlowNode newFlowNode : laneFlowNodes) {
                                    if (newFlowNode.getId().equals(sq.getSourceRef().getId())) {
                                        List<DiagramElement> diagramElements = plane.getPlaneElement();
                                        for (DiagramElement dia : diagramElements) {
                                            if (dia instanceof BPMNShape) {
                                                BPMNShape shape = (BPMNShape) dia;
                                                if (shape.getBpmnElement().getId().equals(sq.getSourceRef().getId())) {
                                                    Bounds eleBounds = shape.getBounds();
                                                    List<Point> edgePoints = edge.getWaypoint();
                                                    if (edgePoints != null && edgePoints.size() > 1) {
                                                        if (eleBounds != null) {
                                                            Point first = edgePoints.get(0);
                                                            first.setX(first.getX() + laneBounds.getX());
                                                            first.setY(first.getY() + laneBounds.getY());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else if (newFlowNode.getId().equals(sq.getTargetRef().getId())) {
                                        List<DiagramElement> diagramElements = plane.getPlaneElement();
                                        for (DiagramElement dia : diagramElements) {
                                            if (dia instanceof BPMNShape) {
                                                BPMNShape shape = (BPMNShape) dia;
                                                if (shape.getBpmnElement().getId().equals(sq.getTargetRef().getId())) {
                                                    Bounds eleBounds = shape.getBounds();
                                                    List<Point> edgePoints = edge.getWaypoint();
                                                    if (edgePoints != null && edgePoints.size() > 1) {
                                                        if (eleBounds != null) {
                                                            Point last = edgePoints.get(edgePoints.size() - 1);
                                                            last.setX(last.getX() + laneBounds.getX());
                                                            last.setY(last.getY() + laneBounds.getY());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SequenceFlow(org.eclipse.bpmn2.SequenceFlow) Bounds(org.eclipse.dd.dc.Bounds) Lane(org.eclipse.bpmn2.Lane) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) LaneSet(org.eclipse.bpmn2.LaneSet) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) DiagramElement(org.eclipse.dd.di.DiagramElement) RootElement(org.eclipse.bpmn2.RootElement) ArrayList(java.util.ArrayList) List(java.util.List) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 4 with Point

use of org.eclipse.dd.dc.Point in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method createBpmnEdgeForSequenceFlow.

private void createBpmnEdgeForSequenceFlow(BpmnDiFactory factory, BPMNPlane plane, SequenceFlow sequenceFlow) {
    BPMNEdge edge = factory.createBPMNEdge();
    edge.setBpmnElement(sequenceFlow);
    DcFactory dcFactory = DcFactory.eINSTANCE;
    Point point = dcFactory.createPoint();
    List<Point> dockers = _dockers.get(sequenceFlow.getId());
    if (sequenceFlow.getSourceRef() != null) {
        Bounds sourceBounds = _bounds.get(sequenceFlow.getSourceRef().getId());
        // Test for valid docker with X and Y  > -1, created by EdgeParser
        if (dockers != null && dockers.size() > 0 && dockers.get(0).getX() > -1 && dockers.get(0).getY() > -1) {
            // First docker is connection to Source
            point.setX(sourceBounds.getX() + dockers.get(0).getX());
            point.setY(sourceBounds.getY() + dockers.get(0).getY());
        } else {
            // Default is right middle of Source
            point.setX(sourceBounds.getX() + sourceBounds.getWidth());
            point.setY(sourceBounds.getY() + (sourceBounds.getHeight() / 2));
        }
    }
    edge.getWaypoint().add(point);
    for (int i = 1; i < dockers.size() - 1; i++) {
        edge.getWaypoint().add(dockers.get(i));
    }
    point = dcFactory.createPoint();
    if (sequenceFlow.getTargetRef() != null) {
        Bounds targetBounds = _bounds.get(sequenceFlow.getTargetRef().getId());
        // Test for valid docker with X and Y  > -1, created by EdgeParser
        if (dockers != null && dockers.size() > 1 && dockers.get(dockers.size() - 1).getX() > -1 && dockers.get(dockers.size() - 1).getY() > -1) {
            // Last docker is connection to Target
            point.setX(targetBounds.getX() + dockers.get(dockers.size() - 1).getX());
            point.setY(targetBounds.getY() + dockers.get(dockers.size() - 1).getY());
        } else {
            // Default is left middle of Target
            point.setX(targetBounds.getX());
            point.setY(targetBounds.getY() + (targetBounds.getHeight() / 2));
        }
    }
    edge.getWaypoint().add(point);
    plane.getPlaneElement().add(edge);
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) Point(org.eclipse.dd.dc.Point) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge) DcFactory(org.eclipse.dd.dc.DcFactory) Point(org.eclipse.dd.dc.Point)

Example 5 with Point

use of org.eclipse.dd.dc.Point in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method updateEdgeBoundsInContainers.

public void updateEdgeBoundsInContainers(FlowElementsContainer container, SequenceFlow sq, BPMNPlane plane, BPMNEdge edge) {
    for (FlowElement fele : container.getFlowElements()) {
        // dont do this if its on process level
        if (!(container instanceof Process)) {
            if (fele.getId().equals(sq.getSourceRef().getId())) {
                Bounds sourceBounds = getBoundsForElement(sq.getSourceRef(), plane);
                List<Point> edgePoints = edge.getWaypoint();
                if (edgePoints != null && edgePoints.size() > 1) {
                    if (sourceBounds != null) {
                        Point first = edgePoints.get(0);
                        first.setX(first.getX() + getBoundsForElement(container, plane).getX() + (sourceBounds.getWidth() / 2));
                        first.setY(first.getY() + getBoundsForElement(container, plane).getY());
                    }
                }
            } else if (fele.getId().equals(sq.getTargetRef().getId())) {
                Bounds targetBounds = getBoundsForElement(sq.getTargetRef(), plane);
                List<Point> edgePoints = edge.getWaypoint();
                if (edgePoints != null && edgePoints.size() > 1) {
                    if (targetBounds != null) {
                        Point last = edgePoints.get(edgePoints.size() - 1);
                        last.setX(last.getX() + getBoundsForElement(container, plane).getX() - (targetBounds.getWidth() / 2));
                        last.setY(last.getY() + getBoundsForElement(container, plane).getY());
                    }
                }
            }
        }
        if (fele instanceof FlowElementsContainer) {
            updateEdgeBoundsInContainers((FlowElementsContainer) fele, sq, plane, edge);
        }
    }
}
Also used : FlowElement(org.eclipse.bpmn2.FlowElement) Bounds(org.eclipse.dd.dc.Bounds) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) ArrayList(java.util.ArrayList) List(java.util.List) Point(org.eclipse.dd.dc.Point)

Aggregations

Point (org.eclipse.dd.dc.Point)11 Bounds (org.eclipse.dd.dc.Bounds)10 BPMNEdge (org.eclipse.bpmn2.di.BPMNEdge)7 ArrayList (java.util.ArrayList)5 List (java.util.List)4 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)4 DataObject (org.eclipse.bpmn2.DataObject)4 Process (org.eclipse.bpmn2.Process)4 SubProcess (org.eclipse.bpmn2.SubProcess)4 BPMNShape (org.eclipse.bpmn2.di.BPMNShape)4 Entry (java.util.Map.Entry)3 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)3 TextAnnotation (org.eclipse.bpmn2.TextAnnotation)3 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)3 LinkedHashMap (java.util.LinkedHashMap)2 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)2 FlowElement (org.eclipse.bpmn2.FlowElement)2 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)2 FlowNode (org.eclipse.bpmn2.FlowNode)2 Lane (org.eclipse.bpmn2.Lane)2