use of org.kie.dmn.model.api.dmndi.Point in project drools by kiegroup.
the class EdgeConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Edge abs = (Edge) parent;
for (Point pt : abs.getWaypoint()) {
writeChildrenNode(writer, context, pt, WAYPOINT);
}
}
use of org.kie.dmn.model.api.dmndi.Point in project kie-wb-common by kiegroup.
the class DMNMarshallerStandalone method setConnectionMagnets.
@SuppressWarnings("unchecked")
private void setConnectionMagnets(final Edge edge, final String dmnEdgeElementRef, final org.kie.dmn.model.api.Definitions dmnXml) {
final ViewConnector connectionContent = (ViewConnector) edge.getContent();
final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDiagram = findDMNDiagram(dmnXml);
Optional<DMNEdge> dmnEdge = Optional.empty();
if (dmnDiagram.isPresent()) {
dmnEdge = dmnDiagram.get().getDMNDiagramElement().stream().filter(DMNEdge.class::isInstance).map(DMNEdge.class::cast).filter(e -> e.getDmnElementRef().getLocalPart().equals(dmnEdgeElementRef)).findFirst();
}
if (dmnEdge.isPresent()) {
DMNEdge e = dmnEdge.get();
final Point source = e.getWaypoint().get(0);
final Node<View<?>, Edge> sourceNode = edge.getSourceNode();
if (null != sourceNode) {
setConnectionMagnet(sourceNode, source, connectionContent::setSourceConnection, isSourceAutoConnectionEdge(e));
}
final Point target = e.getWaypoint().get(e.getWaypoint().size() - 1);
final Node<View<?>, Edge> targetNode = edge.getTargetNode();
if (null != targetNode) {
setConnectionMagnet(targetNode, target, connectionContent::setTargetConnection, isTargetAutoConnectionEdge(e));
}
if (e.getWaypoint().size() > 2) {
connectionContent.setControlPoints(e.getWaypoint().subList(1, e.getWaypoint().size() - 1).stream().map(p -> ControlPoint.build(PointUtils.dmndiPointToPoint2D(p))).toArray(ControlPoint[]::new));
}
} else {
// Set the source connection, if any.
final Node sourceNode = edge.getSourceNode();
if (null != sourceNode) {
connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(sourceNode));
}
// Set the target connection, if any.
final Node targetNode = edge.getTargetNode();
if (null != targetNode) {
connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(targetNode));
}
}
}
use of org.kie.dmn.model.api.dmndi.Point in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testStunnerConstellationButtonCausingPoint2DbeingNull.
/**
* DROOLS-3184: If the "connection source/target location is null" assume it's the centre of the shape.
* [source/target location is null] If the connection was created from the Toolbox (i.e. add a InputData and then the Decision from it using the Decision toolbox icon).
* <p>
* This test re-create by hard-code the behavior of the Stunner framework "Toolbox" by instrumenting API calls to achieve the same behavior.
*/
@SuppressWarnings("unchecked")
@Test
public void testStunnerConstellationButtonCausingPoint2DbeingNull() throws IOException {
final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
/*NOP*/
};
Diagram diagram = createDiagram();
Graph g = diagram.getGraph();
Node diagramRoot = DMNMarshallerStandalone.findDMNDiagramRoot(g);
testAugmentWithNSPrefixes(((DMNDiagram) ((View<?>) diagramRoot.getContent()).getDefinition()).getDefinitions());
org.kie.dmn.model.api.InputData dmnInputData = new TInputData();
dmnInputData.setId("inputDataID");
dmnInputData.setName(dmnInputData.getId());
Node inputDataNode = new InputDataConverter(api.getFactoryManager()).nodeFromDMN(dmnInputData, hasComponentWidthsConsumer);
org.kie.dmn.model.api.Decision dmnDecision = new TDecision();
dmnDecision.setId("decisionID");
dmnDecision.setName(dmnDecision.getId());
Node decisionNode = new DecisionConverter(api.getFactoryManager()).nodeFromDMN(dmnDecision, hasComponentWidthsConsumer);
g.addNode(inputDataNode);
g.addNode(decisionNode);
View content = (View) decisionNode.getContent();
content.setBounds(org.kie.workbench.common.stunner.core.graph.content.Bounds.create(200, 200, 300, 250));
final String irID = "irID";
Edge myEdge = api.getFactoryManager().newElement(irID, DMNMarshallerStandalone.INFO_REQ_ID).asEdge();
myEdge.setSourceNode(inputDataNode);
myEdge.setTargetNode(decisionNode);
inputDataNode.getOutEdges().add(myEdge);
decisionNode.getInEdges().add(myEdge);
ViewConnector connectionContent = (ViewConnector) myEdge.getContent();
// DROOLS-3184: If the "connection source/target location is null" assume it's the centre of the shape.
// keep Stunner behavior of constellation button
connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(inputDataNode).setLocation(null).setAuto(true));
connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(decisionNode).setLocation(null).setAuto(true));
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, inputDataNode);
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, decisionNode);
DMNMarshallerStandalone m = getDMNMarshaller();
String output = m.marshall(diagram);
LOG.debug(output);
Definitions dmnDefinitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(output);
DMNEdge dmndiEdge = findEdgeByDMNI(dmnDefinitions.getDMNDI().getDMNDiagram().get(0), irID);
assertThat(dmndiEdge.getWaypoint()).hasSize(2);
Point wpSource = dmndiEdge.getWaypoint().get(0);
assertThat(wpSource.getX()).isEqualByComparingTo(50d);
assertThat(wpSource.getY()).isEqualByComparingTo(25d);
Point wpTarget = dmndiEdge.getWaypoint().get(1);
assertThat(wpTarget.getX()).isEqualByComparingTo(250d);
assertThat(wpTarget.getY()).isEqualByComparingTo(225d);
}
use of org.kie.dmn.model.api.dmndi.Point in project drools by kiegroup.
the class EdgeConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Edge abs = (Edge) parent;
for (Point pt : abs.getWaypoint()) {
writeChildrenNode(writer, context, pt, WAYPOINT);
}
}
use of org.kie.dmn.model.api.dmndi.Point in project drools by kiegroup.
the class PointConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);
Point abs = (Point) parent;
writer.addAttribute(X, FormatUtils.manageDouble(abs.getX()));
writer.addAttribute(Y, FormatUtils.manageDouble(abs.getY()));
}
Aggregations