| 23 | } |
| 24 | |
| 25 | void |
| 26 | Monitor::GraphGenerator::draw () |
| 27 | { |
| 28 | // setup output file |
| 29 | if (gvOpt_.getDot() == "") { |
| 30 | throw "Null GvOpts. Can't open output file"; |
| 31 | } |
| 32 | |
| 33 | // TODO: check for errors and update status if error |
| 34 | fout.open(gvOpt_.getDot().c_str()); |
| 35 | |
| 36 | if (!fout) { |
| 37 | throw "Error opening file"; |
| 38 | } |
| 39 | |
| 40 | // erase old values |
| 41 | // currently, we only call draw once for an instance |
| 42 | // of graphgenerator, but this could change. |
| 43 | rMap_.clear(); |
| 44 | wMap_.clear(); |
| 45 | nMap_.clear(); |
| 46 | |
| 47 | while (!lifo_.empty()) { |
| 48 | lifo_.pop(); |
| 49 | } |
| 50 | |
| 51 | fout << "digraph OpenDDS {" << std::endl; |
| 52 | if (gvOpt_.lrLayout()) { |
| 53 | fout << " rankdir=LR;" << std::endl; |
| 54 | } |
| 55 | fout << " node [shape=record,height=.08,fontsize=11];" << std::endl; |
| 56 | |
| 57 | generate(root_); |
| 58 | |
| 59 | while (!lifo_.empty()) { |
| 60 | fout << lifo_.top(); |
| 61 | lifo_.pop(); |
| 62 | } |
| 63 | |
| 64 | connectNodes(); |
| 65 | |
| 66 | // close dot file and generate png |
| 67 | fout << "}" << std::endl; |
| 68 | |
| 69 | fout.close(); |
| 70 | |
| 71 | std::string cmd = gvOpt_.getBin(); |
| 72 | cmd += " -Tpng "; |
| 73 | cmd += gvOpt_.getDot(); |
| 74 | cmd += " > "; |
| 75 | cmd += gvOpt_.getPng(); |
| 76 | int ret = system(cmd.c_str()); |
| 77 | |
| 78 | if (ret == -1) { |
| 79 | throw "Error converting dot file to png."; |
| 80 | } |
| 81 | |
| 82 | } |