use of org.lflang.diagram.synthesis.util.SynthesisErrorReporter in project lingua-franca by lf-lang.
the class LinguaFrancaSynthesis method transform.
// -------------------------------------------------------------------------
@Override
public KNode transform(final Model model) {
KNode rootNode = _kNodeExtensions.createNode();
try {
// Find main
Reactor main = IterableExtensions.findFirst(model.getReactors(), _utilityExtensions::isMainOrFederated);
if (main != null) {
ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter());
rootNode.getChildren().addAll(createReactorNode(reactorInstance, true, null, null, new HashMap<>()));
} else {
KNode messageNode = _kNodeExtensions.createNode();
_linguaFrancaShapeExtensions.addErrorMessage(messageNode, TEXT_NO_MAIN_REACTOR, null);
rootNode.getChildren().add(messageNode);
}
// Show all reactors
if (main == null || getBooleanValue(SHOW_ALL_REACTORS)) {
List<KNode> reactorNodes = new ArrayList<>();
for (Reactor reactor : model.getReactors()) {
if (reactor == main)
continue;
ReactorInstance reactorInstance = new ReactorInstance(reactor, new SynthesisErrorReporter(), new HashSet<>());
reactorNodes.addAll(createReactorNode(reactorInstance, main == null, HashBasedTable.<ReactorInstance, PortInstance, KPort>create(), HashBasedTable.<ReactorInstance, PortInstance, KPort>create(), new HashMap<>()));
}
if (!reactorNodes.isEmpty()) {
// To allow ordering, we need box layout but we also need layered layout for ports thus wrap all node
// TODO use rect packing in the future
reactorNodes.add(0, IterableExtensions.head(rootNode.getChildren()));
int index = 0;
for (KNode node : reactorNodes) {
if (node.getProperty(CoreOptions.COMMENT_BOX))
continue;
KNode child = _kNodeExtensions.createNode();
child.getChildren().add(node);
// Add comment nodes
for (KEdge edge : node.getIncomingEdges()) {
if (!edge.getSource().getProperty(CoreOptions.COMMENT_BOX))
continue;
child.getChildren().add(edge.getSource());
}
_kRenderingExtensions.addInvisibleContainerRendering(child);
setLayoutOption(child, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
setLayoutOption(child, CoreOptions.PADDING, new ElkPadding(0));
// Order!
setLayoutOption(child, CoreOptions.PRIORITY, reactorNodes.size() - index);
rootNode.getChildren().add(child);
index++;
}
setLayoutOption(rootNode, CoreOptions.ALGORITHM, BoxLayouterOptions.ALGORITHM_ID);
setLayoutOption(rootNode, CoreOptions.SPACING_NODE_NODE, 25.0);
}
}
} catch (Exception e) {
e.printStackTrace();
KNode messageNode = _kNodeExtensions.createNode();
_linguaFrancaShapeExtensions.addErrorMessage(messageNode, "Error in Diagram Synthesis", e.getClass().getSimpleName() + " occurred. Could not create diagram.");
rootNode.getChildren().add(messageNode);
}
return rootNode;
}
Aggregations