use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class AbstractNodeBuilder method afterNodeBuild.
@SuppressWarnings("unchecked")
protected void afterNodeBuild(final BuilderContext context, final T node) {
// Outgoing connections.
if (outgoingResourceIds != null && !outgoingResourceIds.isEmpty()) {
for (String outgoingNodeId : outgoingResourceIds) {
GraphObjectBuilder<?, ?> outgoingBuilder = getBuilder(context, outgoingNodeId);
if (outgoingBuilder == null) {
throw new RuntimeException("No outgoing edge builder for " + outgoingNodeId);
}
final List<Command<GraphCommandExecutionContext, RuleViolation>> commands = new LinkedList<>();
// If outgoing element it's a node means that it's docked.
if (outgoingBuilder instanceof AbstractNodeBuilder) {
// Command - Create the docked node.
Node docked = (Node) outgoingBuilder.build(context);
commands.add(context.getCommandFactory().addDockedNode(node, docked));
// Obtain docked position and use those for the docked node.
final List<Double[]> dockers = ((AbstractNodeBuilder) outgoingBuilder).dockers;
if (!dockers.isEmpty()) {
// TODO: Use not only first docker coordinates?
Double[] dCoords = dockers.get(0);
double x = dCoords[0];
double y = dCoords[1];
commands.add(context.getCommandFactory().updatePosition(docked, new Point2D(x, y)));
}
} else {
// Create the outgoing edge.
AbstractEdgeBuilder edgeBuilder = (AbstractEdgeBuilder) outgoingBuilder;
Edge edge = (Edge) edgeBuilder.build(context);
if (edge != null) {
// Command - Execute the graph command to set the node as the edge connection's source..
Double[] sourceDocker = null;
final List<Double[]> dockers = ((AbstractEdgeBuilder) outgoingBuilder).dockers;
if (dockers != null && dockers.size() > 1) {
sourceDocker = dockers.get(0);
}
Connection sourceConnection = null;
if (null != sourceDocker) {
sourceConnection = MagnetConnection.Builder.at(sourceDocker[0], sourceDocker[1]).setAuto(edgeBuilder.isSourceAutoConnection());
}
commands.add(context.getCommandFactory().setSourceNode(node, edge, sourceConnection));
}
}
if (!commands.isEmpty()) {
for (Command<GraphCommandExecutionContext, RuleViolation> command : commands) {
doExecuteCommand(context, command);
}
}
}
}
// Children connections.
if (childNodeIds != null && !childNodeIds.isEmpty()) {
for (String childNodeId : childNodeIds) {
GraphObjectBuilder<?, ?> childNodeBuilder = getBuilder(context, childNodeId);
if (childNodeBuilder == null) {
throw new RuntimeException("No child node builder for " + childNodeId);
}
Command<GraphCommandExecutionContext, RuleViolation> command = null;
if (childNodeBuilder instanceof NodeObjectBuilder) {
// Command - Create the child node and the parent-child relationship.
Node childNode = (Node) childNodeBuilder.build(context);
command = context.getCommandFactory().addChildNode(node, childNode);
}
if (null != command) {
doExecuteCommand(context, command);
}
}
}
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D 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);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class BPMNGraphFactoryImplTest method testBuild.
@Test
@SuppressWarnings("unchecked")
public void testBuild() {
final Node diagramNode = mock(Node.class);
final Node startEventNode = mock(Node.class);
when(factoryManager.newElement(anyString(), eq(BPMNDiagramImpl.class))).thenReturn(diagramNode);
when(factoryManager.newElement(anyString(), eq(StartNoneEvent.class))).thenReturn(startEventNode);
final Graph<DefinitionSet, Node> graph = tested.build("uuid1", "defSetId");
assertNotNull(graph);
assertEquals("uuid1", graph.getUUID());
assertEquals(1, graph.getLabels().size());
assertTrue(graph.getLabels().contains("defSetId"));
final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
verify(graphCommandFactory, times(1)).addNode(eq(diagramNode));
verify(graphCommandFactory, times(1)).addChildNode(eq(diagramNode), eq(startEventNode), eq(new Point2D(BPMNGraphFactoryImpl.START_X, BPMNGraphFactoryImpl.START_Y)));
verify(graphCommandManager, times(1)).execute(any(GraphCommandExecutionContext.class), commandCaptor.capture());
final Command command = commandCaptor.getValue();
assertTrue(command instanceof CompositeCommand);
final CompositeCommand compositeCommand = (CompositeCommand) command;
assertEquals(2, compositeCommand.size());
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class SequenceFlowPropertyWriter method setWaypoints.
private void setWaypoints(ViewConnector<? extends BPMNViewDefinition> connector) {
BPMNEdge bpmnEdge = di.createBPMNEdge();
bpmnEdge.setBpmnElement(sequenceFlow);
Point2D sourcePt = connector.getSourceConnection().get().getLocation();
Point2D targetPt = connector.getTargetConnection().get().getLocation();
org.eclipse.dd.dc.Point sourcePoint = dc.createPoint();
sourcePoint.setX(source.getShape().getBounds().getX() + (float) sourcePt.getX());
sourcePoint.setY(source.getShape().getBounds().getY() + (float) sourcePt.getY());
org.eclipse.dd.dc.Point targetPoint = dc.createPoint();
targetPoint.setX(target.getShape().getBounds().getX() + (float) targetPt.getX());
targetPoint.setY(target.getShape().getBounds().getY() + (float) targetPt.getY());
bpmnEdge.getWaypoint().add(sourcePoint);
bpmnEdge.getWaypoint().add(targetPoint);
this.bpmnEdge = bpmnEdge;
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class CanvasLayoutUtilsTest method getNextFromRoot.
// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextFromRoot() {
Node node1 = mock(Node.class);
Bounds boundsNode1 = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(300d, 200d));
View viewNode1 = mock(View.class);
when(node1.getContent()).thenReturn(viewNode1);
when(viewNode1.getBounds()).thenReturn(boundsNode1);
Node node2 = mock(Node.class);
Bounds boundsNode2 = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(300d, 200d));
View viewNode2 = mock(View.class);
when(node2.getContent()).thenReturn(viewNode2);
when(viewNode2.getBounds()).thenReturn(boundsNode2);
Node nodeRoot = mock(Node.class);
double rootWidth = 40d;
double rootHeight = 40d;
Bounds rootBounds = new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(rootWidth, rootHeight));
View rootView = mock(View.class);
when(nodeRoot.getContent()).thenReturn(rootView);
when(rootView.getBounds()).thenReturn(rootBounds);
List<Node> nodes = new ArrayList<>();
List<Edge> edges = new ArrayList<>();
Edge edge = mock(Edge.class);
edges.add(edge);
when(nodeRoot.getOutEdges()).thenReturn(edges);
when(edge.getTargetNode()).thenReturn(node1);
when(nodeRoot.getContent()).thenReturn(rootView);
nodes.add(nodeRoot);
when(graph.nodes()).thenReturn(nodes);
when(node2.getInEdges()).thenReturn(edges);
when(nodeRoot.asNode()).thenReturn(nodeRoot);
Point2D next = canvasLayoutUtils.getNext(canvasHandler, nodeRoot, node2);
assertTrue(next.getX() > rootWidth);
assertTrue(next.getY() > NEW_NODE_HEIGHT);
}
Aggregations