[1653] | 1 | #include "graphviz.hpp" |
---|
| 2 | #include "workflow_graph.hpp" |
---|
| 3 | |
---|
| 4 | namespace xios |
---|
| 5 | { |
---|
| 6 | |
---|
| 7 | CGraphviz::CGraphviz() |
---|
| 8 | { } |
---|
| 9 | |
---|
| 10 | /*! |
---|
| 11 | * |
---|
| 12 | */ |
---|
| 13 | void CGraphviz::buildStaticWorkflowGraph() |
---|
| 14 | TRY |
---|
| 15 | { |
---|
| 16 | if (!CWorkflowGraph::mapFieldToFilters.empty()) |
---|
| 17 | { |
---|
| 18 | CWorkflowGraph::buildStaticWorkflow(); |
---|
| 19 | |
---|
| 20 | typedef boost::property<boost::edge_name_t, std::string> EdgeProperty; |
---|
| 21 | typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeProperty> Graph; |
---|
| 22 | |
---|
| 23 | // Input 1: nodes (=filters) |
---|
| 24 | vector<StdString>& nodes = CWorkflowGraph::filters; |
---|
| 25 | const int nbNodes = nodes.size(); |
---|
| 26 | |
---|
| 27 | // Input 2: edges (=fields) |
---|
| 28 | vector<StdString>& edges = CWorkflowGraph::fields; |
---|
| 29 | |
---|
| 30 | // Input 3: nodes to edges connectivity |
---|
| 31 | vector<pair<int, int> >& nodesToEdges = CWorkflowGraph::fieldsToFilters; |
---|
| 32 | const int nbEdges = nodesToEdges.size(); |
---|
| 33 | |
---|
| 34 | // Declare a graph object, adding the edges and edge properties |
---|
| 35 | Graph g(nbNodes); |
---|
| 36 | for (int j = 0; j < nbEdges; ++j) |
---|
| 37 | { |
---|
| 38 | graph_traits<Graph>::edge_descriptor e; |
---|
| 39 | bool inserted; |
---|
| 40 | boost::tie(e, inserted) = boost::add_edge(nodesToEdges[j].first, nodesToEdges[j].second, edges[j], g); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | std::for_each(vertices(g).first, vertices(g).second, exercise_vertex<Graph>(g)); |
---|
| 44 | |
---|
| 45 | std::map<std::string,std::string> graph_attr, vertex_attr, edge_attr; |
---|
| 46 | graph_attr["size"] = "5,5"; |
---|
| 47 | graph_attr["rankdir"] = "LR"; |
---|
| 48 | graph_attr["ratio"] = "fill"; |
---|
| 49 | vertex_attr["shape"] = "record"; |
---|
| 50 | vertex_attr["width"] = "2.2"; |
---|
| 51 | vertex_attr["fontsize"] = "16"; |
---|
| 52 | |
---|
| 53 | const std::string filename = "graph.dot"; |
---|
| 54 | std::ofstream file (filename.c_str()); |
---|
| 55 | |
---|
| 56 | boost::write_graphviz(file, g, |
---|
| 57 | boost::make_label_writer(&nodes[0]), |
---|
| 58 | boost::make_label_writer(get(edge_name, g)), |
---|
| 59 | boost::make_graph_attributes_writer(graph_attr, vertex_attr, edge_attr)); |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | CATCH |
---|
| 63 | } |
---|