Search in sources :

Example 26 with Point2D

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

the class CanvasLayoutUtils method getNextPositionFromParent.

private Point2D getNextPositionFromParent(final Point2D rootNodeCoordinates, final Point2D offset, final Element parentNode, final double rootNodeHeight, final double rootNodeWidth, final double nodeWidth) {
    final Point2D nextPosition = getNextPositionWithOffset(rootNodeCoordinates, offset);
    final double[] parentNodeSize = GraphUtils.getNodeSize((View) parentNode.getContent());
    final Point2D parentPosition = GraphUtils.getPosition((View) parentNode.getContent());
    double newPositionToCheckX = (rootNodeCoordinates.getX() + rootNodeWidth + PADDING_X + nodeWidth);
    double parentPositionToCheckX = parentNodeSize[0] + parentPosition.getX();
    if (newPositionToCheckX > parentPositionToCheckX) {
        nextPosition.setX(parentPosition.getX() + PADDING_X);
        nextPosition.setY(rootNodeCoordinates.getY() + rootNodeHeight + PADDING_Y + offset.getY());
    }
    return nextPosition;
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D)

Example 27 with Point2D

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

the class CanvasLayoutUtils method getNext.

@SuppressWarnings("unchecked")
public Point2D getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) {
    final double[] rootBounds = getBoundCoordinates(root.getContent());
    final double[] rootSize = GraphUtils.getNodeSize(root.getContent());
    final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent());
    Point2D[] offset = { new Point2D(PADDING_X, 0) };
    Point2D[] parentOffset = { new Point2D(0, 0) };
    double[] maxNodeY = { 0 };
    if (root.getOutEdges().size() > 0) {
        root.getOutEdges().stream().filter(e -> e.getContent() instanceof ViewConnector).filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)).forEach(n -> {
            final Node<View<?>, Edge> node = n.getTargetNode();
            final Point2D nodePos = GraphUtils.getPosition(node.getContent());
            final Point2D rootPos = GraphUtils.getPosition(root.getContent());
            if (nodePos.getY() > maxNodeY[0]) {
                maxNodeY[0] = nodePos.getY();
                final double[] nodeSize = GraphUtils.getNodeSize(node.getContent());
                offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY());
            }
        });
        offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y);
    } else {
        offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2);
    }
    offset[0].setX(offset[0].getX() + PADDING_X);
    final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY());
    final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]);
    return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Violation(org.kie.workbench.common.stunner.core.validation.Violation) GraphBoundsIndexer(org.kie.workbench.common.stunner.core.graph.processing.index.bounds.GraphBoundsIndexer) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) NodeContainmentContext(org.kie.workbench.common.stunner.core.rule.context.NodeContainmentContext) Graph(org.kie.workbench.common.stunner.core.graph.Graph) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Dependent(javax.enterprise.context.Dependent) Element(org.kie.workbench.common.stunner.core.graph.Element) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 28 with Point2D

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

the class LienzoTextTooltipTest method testShow.

@Test
public void testShow() {
    tested.show("content1", new Point2D(200d, 100d));
    final ArgumentCaptor<com.ait.lienzo.client.core.types.Point2D> pointCaptor = ArgumentCaptor.forClass(com.ait.lienzo.client.core.types.Point2D.class);
    verify(primitiveTooltip, times(1)).show(eq("content1"), pointCaptor.capture(), eq(PrimitiveTooltip.Direction.WEST));
    final com.ait.lienzo.client.core.types.Point2D point = pointCaptor.getValue();
    assertEquals(200d, point.getX(), 0);
    assertEquals(100d, point.getY(), 0);
    verify(primitiveTooltip, never()).hide();
    verify(primitiveTooltip, never()).remove();
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Test(org.junit.Test)

Example 29 with Point2D

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

the class AbstractEdgeBuilder method buildControlPoints.

private void buildControlPoints(BuilderContext context, T edge, GraphCommandFactory commandFactory) {
    if (dockers.size() > 2) {
        Counter indexCounter = new Counter(0);
        ControlPoint[] controlPoints = dockers.subList(1, dockers.size() - 1).stream().sequential().map(docker -> (docker.length == 2 ? new Point2D(docker[0], docker[1]) : null)).filter(Objects::nonNull).map(point -> new ControlPointImpl(point, indexCounter.increment())).toArray(ControlPoint[]::new);
        CommandResult<RuleViolation> addControlPointsResult = context.execute(commandFactory.addControlPoint(edge, controlPoints));
        if (hasErrors(addControlPointsResult)) {
            throw new RuntimeException("Error building BPMN graph. Command 'AddControlPointCommand' execution failed." + addControlPointsResult);
        }
    }
}
Also used : AddControlPointCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddControlPointCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) BPMNDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNDefinition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) MutableIndex(org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex) Collectors(java.util.stream.Collectors) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Objects(java.util.Objects) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) CommandUtils(org.kie.workbench.common.stunner.core.command.util.CommandUtils) Bpmn2OryxManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager) Counter(org.kie.workbench.common.stunner.core.util.Counter) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SetConnectionTargetNodeCommand) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Node(org.kie.workbench.common.stunner.core.graph.Node) Counter(org.kie.workbench.common.stunner.core.util.Counter) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Objects(java.util.Objects) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 30 with Point2D

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

the class CaseManagementCanvasCommandFactoryTest method checkUpdatePositionCommandType.

@Test
public void checkUpdatePositionCommandType() {
    // Checks the command is a specific sub-class for Case Management
    final CanvasCommand<AbstractCanvasHandler> command = factory.updatePosition(child, new Point2D(0.0, 0.0));
    assertNotNull(command);
    assertTrue(command instanceof CaseManagementUpdatePositionCommand);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Test(org.junit.Test)

Aggregations

Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)55 Test (org.junit.Test)25 Edge (org.kie.workbench.common.stunner.core.graph.Edge)18 View (org.kie.workbench.common.stunner.core.graph.content.view.View)17 Node (org.kie.workbench.common.stunner.core.graph.Node)15 Command (org.kie.workbench.common.stunner.core.command.Command)10 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)10 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)10 Before (org.junit.Before)9 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)7 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)6 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)6 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)5 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)5 Ignore (org.junit.Ignore)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)3 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)3 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)3 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)3