-
Notifications
You must be signed in to change notification settings - Fork 0
Export Plug‐in
The File Writer interface allows reading the internal graph representation and write either the circuit description into a file, or output the visualisation in a file for further use.
Default export plug-in is SvgExporter.
The only method that should be overridden to wrote a file writer is:
void exportGraph(const QString& filename, const Elve::SharedEGraph& eg) override;
whose prototype is self-explanatory: a path and an ExtendedGraph are given and the side effect of the method should be that a file with given name is created with format-specific data in it.
If new plugin folder and files were created using the corresponding template (see Writing Plug ins) method implementation should look like this:
void ExporterName::exportGraph(const QString& filename, const SharedEGraph& eg) {
//HERE you are free to write the graph to given filename in any way you want
//Note that you could even pass arbitrary string as filename from CLI and do whatever you want, including sending graph to another software for example
}
Exporter implementation could widely vary depending on the target file format. However, beeing aware of the graph available data and interfaces is essential (given that you export logic data) so it's recommended to take a look at the Elve::Graph and Elve::ExtendedGraph documentations.
Here is an example of Graph traversal:
using value = NodesByID::value_type;
for(const value& p : eg->graph()->nodes()) {
const Node& node = p.second;
//Iterate through each nodes
for(const Node::Connexion& c : node.fanIn()) {
//Get fan-in connexions (could reference same nodes multiple times)
}
for(const Node::Connexion& c : node.fanOut()) {
//Get fan-out connexions (could reference same nodes multiple times)
}
for(const Node* ancestor : node.ancestors()) {
//Access ancestors (no duplicates)
}
for(const Node* child : node.children()) {
//Access children (no duplicates)
}
}
Of course, STL iterators higher order functions could be used to express your serializer.
Many approaches are possible, for example, the sample SVG-Exporter uses the QGraphicsScene to directly output SVG using Qt primitives. But the user is free to choose how to output result.
A useful method of the Elve::FileExporterPlugin interface is:
/**
* @brief get the graph scene, ensuring that it is created
* @param eg
* @return a valid QGraphicsScene, nullptr if something went wrong
*/
QGraphicsScene* sceneForGraph(const SharedEGraph& eg);
Which ensure a Qt's QGraphicsScene is loaded (if possible) and returns it.
Please note that one could also use directly pieces of information available through Elve::ExtendedGraph, such as NodePositions, to output a graphical file, although this could be by far less trivial.
The use file writer plug-ins their shared libraries (.so, .dll, .dynlib) must be placed in:
<elve_root>/plugins/loaders
they are then available through the File->Export menu and through the CLI by issuing commands of this form:
save_<plugin_cli_name> <filepath>
Using CLI or GUI is fully equivalent, as the GUI button will construct the commands and issue them.
ELVE is developed and maintained by the Processor Architecture Lab, EPFL.
You can contact us at elve@groupes.epfl.ch.