Search in sources :

Example 1 with JSIBounds

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.

the class NodeConnector method getNodeFromPoint.

Optional<Node> getNodeFromPoint(final Point2D point, final List<NodeEntry> entries) {
    if (entries.size() == 1) {
        return Optional.of(entries.get(0).getNode());
    }
    final Map<Point2D, NodeEntry> entriesByPoint2D = new HashMap<>();
    for (final NodeEntry entry : entries) {
        final JSIBounds bounds = entry.getDmnShape().getBounds();
        final double centerX = bounds.getX() + (bounds.getWidth() / 2);
        final double centerY = bounds.getY() + (bounds.getHeight() / 2);
        entriesByPoint2D.put(new Point2D(centerX, centerY), entry);
    }
    final Point2D nearest = Collections.min(entriesByPoint2D.keySet(), (point1, point2) -> {
        final Double distance1 = point.distance(point1);
        final Double distance2 = point.distance(point2);
        return distance1.compareTo(distance2);
    });
    if (!isPointInsideNode(entriesByPoint2D.get(nearest), point)) {
        return Optional.empty();
    }
    return Optional.of(entriesByPoint2D.get(nearest).getNode());
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) HashMap(java.util.HashMap) JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds)

Example 2 with JSIBounds

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.

the class NodeConnector method getNode.

private Optional<Node> getNode(final NodeEntry decisionServiceEntry, final String internalDMNElementId, final Map<String, List<NodeEntry>> entriesById) {
    final JSIBounds decisionServiceBounds = decisionServiceEntry.getDmnShape().getBounds();
    for (final Map.Entry<String, List<NodeEntry>> entry : entriesById.entrySet()) {
        final String id = entry.getKey();
        final List<NodeEntry> entries = entry.getValue();
        if (id.contains(internalDMNElementId)) {
            for (final NodeEntry nodeEntry : entries) {
                final JSIBounds nodeBounds = nodeEntry.getDmnShape().getBounds();
                final boolean b = (nodeBounds.getX() + nodeBounds.getWidth()) < (decisionServiceBounds.getX() + decisionServiceBounds.getWidth());
                final boolean b1 = nodeBounds.getX() > decisionServiceBounds.getX();
                final boolean innerX = b1 && b;
                final boolean b2 = (nodeBounds.getY() + nodeBounds.getHeight()) < (decisionServiceBounds.getY() + decisionServiceBounds.getHeight());
                final boolean b3 = nodeBounds.getY() > decisionServiceBounds.getY();
                final boolean innerY = b2 && b3;
                if (innerX && innerY) {
                    return Optional.of(nodeEntry.getNode());
                }
            }
        }
    }
    return Optional.empty();
}
Also used : JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with JSIBounds

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.

the class NodeConnector method isPointInsideNode.

boolean isPointInsideNode(final NodeEntry node, final Point2D point) {
    final JSIBounds bounds = node.getDmnShape().getBounds();
    final double width = bounds.getX() + bounds.getWidth();
    final double height = bounds.getY() + bounds.getHeight();
    return point.getX() <= width + CENTRE_TOLERANCE && point.getX() >= bounds.getX() - CENTRE_TOLERANCE && point.getY() <= height + CENTRE_TOLERANCE && point.getY() >= bounds.getY() - CENTRE_TOLERANCE;
}
Also used : JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds)

Example 4 with JSIBounds

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.

the class NodeEntriesBuilder method makeStandardShape.

private JSIDMNShape makeStandardShape() {
    final JSIDMNShape jsidmnShape = new JSIDMNShape();
    final JSIBounds boundsParam = new JSIBounds();
    boundsParam.setX(0);
    boundsParam.setY(0);
    boundsParam.setWidth(100);
    boundsParam.setHeight(50);
    jsidmnShape.setBounds(boundsParam);
    return jsidmnShape;
}
Also used : JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape)

Example 5 with JSIBounds

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.

the class NodeConnectorTest method createNodeEntryWithBounds.

NodeEntry createNodeEntryWithBounds(final double x, final double y, final double width, final double height) {
    final NodeEntry nodeEntry = mock(NodeEntry.class);
    final JSIDMNShape shape = mock(JSIDMNShape.class);
    final JSIBounds bounds = mock(JSIBounds.class);
    when(bounds.getHeight()).thenReturn(height);
    when(bounds.getWidth()).thenReturn(width);
    when(bounds.getX()).thenReturn(x);
    when(bounds.getY()).thenReturn(y);
    when(nodeEntry.getDmnShape()).thenReturn(shape);
    when(shape.getBounds()).thenReturn(bounds);
    return nodeEntry;
}
Also used : JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape)

Aggregations

JSIBounds (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds)7 JSIDMNShape (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape)4 HashMap (java.util.HashMap)2 Point2D (com.ait.lienzo.client.core.types.Point2D)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)1 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)1 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)1 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)1 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)1 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)1 JSIPoint (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint)1 JSIDiagramElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement)1 JSITTextAnnotation (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation)1 JSIDMNDecisionServiceDividerLine (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDecisionServiceDividerLine)1 JSIDMNDiagram (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)1 JSIDMNEdge (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)1