1 #ifndef VCSN_ALGOS_DOT_HH
2 # define VCSN_ALGOS_DOT_HH
28 template <
typename Aut>
46 using super_t::super_t;
50 const char*
gray =
"color = DimGray";
79 " vcsn_context = \"" <<
aut_->context().vname() <<
"\"\n"
83 ?
"texmode = math, lblstyle = auto"
84 :
"arrowhead = vee, arrowsize = .6")
89 " d2toptions = \"--format tikz --tikzedgelabels"
90 " --graphstyle=automaton --crop --nominsize --autosize\"\n"
91 " d2tdocpreamble = \""
92 " \\usepackage{amssymb}"
93 " \\usetikzlibrary{arrows.meta, automata, bending}"
94 " \\tikzstyle{automaton}=[shorten >=1pt, pos=.4,"
95 " >={Stealth[bend,round]}, initial text=]"
96 " \\tikzstyle{named}=[rectangle, rounded corners]"
97 " \\tikzstyle{initial}=[initial by arrow]"
98 " \\tikzstyle{accepting}=[accepting by arrow]"
113 const std::string& kind,
const weight_t& w)
120 if (
ws_.show_one() || !
ws_.is_one(w))
122 bos_ <<
", " << kind <<
" text={";
134 bool has_attributes =
false;
137 has_attributes =
true;
144 if (
aut_->state_has_name(s))
146 bos_ <<
"label = \"";
148 aut_->print_state_name(s,
bos_,
"latex");
150 static bool debug = getenv(
"VCSN_DEBUG");
152 bos_ <<
" (" << s <<
')';
153 bos_ <<
"\", style = \"named";
158 sep =
"style = \"state, ";
159 if (
format_(sep,
"initial",
aut_->get_initial_weight(s)))
164 if (
format_(sep,
"accepting",
aut_->get_final_weight(s)))
171 if (
aut_->state_has_name(s))
173 has_attributes =
true;
174 bos_ <<
" [label = \"";
176 aut_->print_state_name(s,
bos_,
"text");
178 static bool debug = getenv(
"VCSN_DEBUG");
180 bos_ <<
" (" << s <<
')';
181 bos_ <<
"\", shape = box";
191 has_attributes =
true;
205 if (!
aut_->initial_transitions().empty()
206 || !
aut_->final_transitions().empty())
210 " node [shape = point, width = 0]\n";
240 if (!
aut_->states().empty())
245 ?
"texmode = math, style = state"
246 :
"shape = circle, style = rounded, width = 0.5")
248 for (
auto s :
aut_->states())
264 std::set<state_t> ds;
266 for (
auto t:
aut_->out(src))
267 ds.insert(
aut_->dst_of(t));
269 for (
auto t:
aut_->all_out(src))
270 ds.insert(
aut_->dst_of(t));
274 if (src ==
aut_->pre())
281 else if (dst ==
aut_->post())
295 std::ostringstream o;
299 if (!o.str().empty() || useless)
302 const char* sep =
"";
303 if (!o.str().empty())
306 bos_ <<
"label = \"" << o.str() <<
"\"";
322 boost::iostreams::flush(
bos_);
329 boost::iostreams::flush(
bos_);
338 detail::io::filtering_ostream
bos_;
342 template <
typename Aut>
344 dot(
const Aut& aut, std::ostream& out,
bool dot2tex =
false)
355 template <
typename Aut,
typename Ostream,
typename Bool>
359 return dot(aut->as<Aut>(), out, dot2tex);
363 (
const automaton& aut, std::ostream& out,
364 bool dot2tex) -> std::ostream&);
369 #endif // !VCSN_ALGOS_DOT_HH
void disable_()
Disable the escaping of backslashes.
bool format_(const std::string &sep, const std::string &kind, const weight_t &w)
Format a TikZ attribute.
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
std::ostream & print_entry_(state_t src, state_t dst, std::ostream &os, const std::string &fmt="text")
The labels and weights of transitions from src to dst.
states_t< Aut > useful_states(const Aut &a)
void enable_()
Enable the escaping of backslashes.
const weightset_t & ws_
Short-hand to the weightset.
states_t initials_()
The list of initial states, sorted.
weight_t_of< automaton_t > weight_t
std::ostream & dot(const automaton &aut, std::ostream &out, bool dot2tex)
Bridge.
std::unordered_set< state_t_of< Aut > > useful_
Useful states.
std::ostream & os_
Output stream.
transition_t_of< automaton_t > transition_t
Factor common bits in automaton formatting.
dotter(const automaton_t &aut, std::ostream &out, bool dot2tex=false)
bool dot2tex_
Whether to format for dot2tex.
std::ostream & operator()()
Print the automaton on the stream.
void print_epilogue_()
Finish the dot graph.
void print_prologue_()
Start the dot graph.
void print_state_(state_t s)
Pretty-print state s for both dot and dot2tex.
weightset_t_of< automaton_t > weightset_t
states_t finals_()
The list of final states, sorted.
Format an automaton into Dot.
const automaton_t & aut_
The automaton we have to output.
state_t_of< automaton_t > state_t
detail::io::filtering_ostream bos_
The output stream, with a backslashify filter.
std::ostream & dot(const Aut &aut, std::ostream &out, bool dot2tex=false)
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
void print_transitions_()
Print all the transitions.
void print_states_()
Print the states.