35 case '!':
return ", shape = doubleoctagon";
36 case '?':
return ", shape = doublecircle";
41 string GetNodeCode(
const string& condition,
bool with_root_id) {
43 string real_condition = condition;
44 if (condition[0] ==
'!' || condition[0] ==
'?') {
45 real_condition = condition.substr(1);
49 size_t pos = real_condition.find(
"- ");
50 if (pos != string::npos) {
51 real_condition = real_condition.substr(pos + 2);
55 return " [label = \"" + real_condition +
"\"" +
GetShape(condition[0]) +
"];\n";
61 std::vector<std::string>& links,
66 os << std::string(tab,
'\t') <<
"node" <<
id.get();
70 vector<uint> actions = n->data.actions();
72 for (
size_t i = 1; i < actions.size(); ++i) {
73 os <<
"," << actions[i];
76 os <<
" - " << n->data.next;
78 os <<
"\", shape = box];\n";
84 if (printed_node.find(n->left) == printed_node.end()) {
86 printed_node[n->left] =
id.next();
87 os << string(tab,
'\t') <<
"node" << printed_node[n] <<
" -> node" << printed_node[n->left] <<
" [label=\"0\"];\n";
92 ss <<
"node" << printed_node[n] <<
" -> node" << printed_node[n->left] <<
" [label=\"0\", style=dotted];\n";
93 links.push_back(ss.str());
96 if (printed_node.find(n->right) == printed_node.end()) {
98 printed_node[n->right] =
id.next();
99 os << string(tab,
'\t') <<
"node" << printed_node[n] <<
" -> node" << printed_node[n->right] <<
" [label=\"1\"];\n";
103 std::stringstream ss;
104 ss <<
"node" << printed_node[n] <<
" -> node" << printed_node[n->right] <<
" [label=\"1\", style=dotted];\n";
105 links.push_back(ss.str());
112 os <<
"digraph dag{\n"
115 "\tsubgraph tree{\n";
118 std::map<BinaryDrag<conact>::node*,
size_t> printed_node;
119 std::vector<std::string> links;
121 for (
size_t i = 0; i < bd.
roots_.size(); ++i) {
122 string tmp = bd.
roots_[i]->data.condition;
124 bd.
roots_[i]->data.condition =
"!" + tmp;
127 bd.
roots_[i]->data.condition =
"?" + to_string(i) +
" - " + tmp;
129 printed_node[bd.
roots_[i]] =
id.next();
131 bd.
roots_[i]->data.condition = tmp;
135 for (
size_t i = 0; i < links.size(); ++i) {
146 #ifdef GRAPHGEN_WINDOWS
150 #ifdef GRAPHGEN_LINUX
154 if (dot_call.length() == 0) {
155 throw std::runtime_error(
"Error in generating graph output: Unsupported operating system for using dot module of graphviz (Linux and Windows only).");
158 if(output_path !=
""){
159 dot_call +=
" -o \"" + output_path +
"\"";
165 string GetDotCallString(
const filesystem::path& code_path, filesystem::path output_path =
"") {
177 std::cout <<
"Drawing DAG: " << base_filename <<
".. ";
181 ofstream os(code_path);
184 std::cout <<
"Unable to generate " << code_path <<
", stopped\n";
192 std::cout <<
"Unable to generate " + pdf_path.string() +
", stopped\n";
198 std::cout <<
"done\n";
201 if (delete_dotcode) {
202 remove(code_path.string().c_str());
A BinaryDrag is the GRAPHGEN implementation of a Binary Directed Rooted Acyclic Graph (DRAG in short)
std::vector< node * > roots_
bool DrawDagOnFile(const string &base_filename, const BinaryDrag< conact > &t, DrawDagFlags flags)
void GenerateDotCodeForDag(std::ostream &os, const BinaryDrag< conact > &bd, bool with_next, bool with_root_id)
string GetNodeCode(const string &condition, bool with_root_id)
string GetDotCallString(const std::string &code_path, const std::string &output_path="")
void GenerateDotCodeForDagRec(std::ostream &os, BinaryDrag< conact >::node *n, std::map< BinaryDrag< conact >::node *, size_t > &printed_node, std::vector< std::string > &links, nodeid &id, bool with_next, bool with_root_id, int tab)
bool DrawForestOnFile(const string &output_file, const LineForestHandler &lfh, DrawDagFlags flags)
DrawDagFlags
Flags for the DrawDagOnFile function.
@ DELETE_DOTCODE
Whether to delete or not the dot code used to draw the drag.
@ WITH_ROOT_ID
Whether to print root id or not.
@ WITH_NEXT
Whether to print next tree indexes inside leaves or not.
@ VERBOSE
Whether to display output messages or not.
std::string dot_background_color_
std::filesystem::path GetDotCodePath(const std::string &out_base_name)
std::filesystem::path GetDotOutPath(const std::string &out_base_name)
std::string dot_output_format_
Generates all the forests needed to handle one line of the image.
std::vector< BinaryDrag< conact > > end_forests_