10 #include <vcsn/dyn/fwd.hh>
27 template <Automaton Aut>
46 using super_t::super_t;
50 const char*
gray =
"color = DimGray";
58 #if defined __GNUC__ && ! defined __clang__
61 # pragma GCC diagnostic push
62 # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
65 #if defined __GNUC__ && ! defined __clang__
66 # pragma GCC diagnostic pop
97 ?
"texmode = math, lblstyle = auto"
98 :
"arrowhead = vee, arrowsize = .6")
103 " d2toptions = \"--format tikz --tikzedgelabels"
104 " --graphstyle=automaton --crop --nominsize --autosize\"\n"
105 " d2tdocpreamble = \""
106 " \\usepackage{amssymb}"
107 " \\usetikzlibrary{arrows.meta, automata, bending}"
108 " \\tikzstyle{automaton}=[shorten >=1pt, pos=.4,"
109 " >={Stealth[bend,round]}, initial text=]"
110 " \\tikzstyle{named}=[rectangle, rounded corners]"
111 " \\tikzstyle{initial}=[initial by arrow]"
112 " \\tikzstyle{accepting}=[accepting by arrow]"
128 const std::string& kind,
const weight_t& w)
135 if (
ws_.show_one() || !
ws_.is_one(w))
137 bos_ <<
", " << kind <<
" text={";
149 bool has_attributes =
false;
152 has_attributes =
true;
159 if (
aut_->state_has_name(s))
161 bos_ <<
"label = \"";
165 static bool debug = getenv(
"VCSN_DEBUG");
167 bos_ <<
" (" << s <<
')';
168 bos_ <<
"\", style = \"named";
173 sep =
"style = \"state, ";
174 if (
print_(sep,
"initial",
aut_->get_initial_weight(s)))
179 if (
print_(sep,
"accepting",
aut_->get_final_weight(s)))
186 if (
aut_->state_has_name(s))
188 has_attributes =
true;
189 bos_ <<
" [label = \"";
197 static bool debug = getenv(
"VCSN_DEBUG");
199 bos_ <<
" (" << s <<
')';
200 bos_ <<
"\", shape = box";
204 std::ostringstream oss;
206 size_t len = oss.str().size();
207 float width = 0.5f + 0.1f * (len / 2);
208 bos_ <<
", fixedsize = true"
209 <<
", width = " << width;
212 if (
aut_->is_lazy(s))
219 has_attributes =
true;
221 bos_ <<
"style = dashed";
231 has_attributes =
true;
250 " node [shape = point, width = 0]\n";
280 if (!
aut_->states().empty())
285 ?
"texmode = math, style = state"
286 :
"shape = circle, style = rounded, width = 0.5")
288 for (
auto s :
aut_->states())
303 if (src ==
aut_->pre())
311 if (dst ==
aut_->post())
321 if (!e.empty() || useless)
324 const char* sep =
"";
327 bos_ <<
"label = \"";
345 auto dsts = std::map<state_t, polynomial_t>{};
346 for (
auto src :
aut_->all_states())
347 if (!
aut_->is_lazy(src)
355 ps_.new_weight(dsts[
aut_->dst_of(t)],
356 aut_->label_of(t),
aut_->weight_of(t));
357 for (
const auto& p: dsts)
365 boost::iostreams::flush(
bos_);
372 boost::iostreams::flush(
bos_);
377 detail::io::filtering_ostream
bos_;
393 template <Automaton Aut>
396 bool mathjax =
false)
399 detail::dot_impl<Aut>
dot{aut,
out, fmt, mathjax};
state_t_of< automaton_t > state_t
Print as a parsable type string.
weightset_t_of< automaton_t > weightset_t
states_t< Aut > useful_states(const Aut &a, bool strict=true)
The set of useful states, including possibly pre() and post().
void print_transitions_()
Print all the transitions, sorted by src state, then dst state.
dot_impl(const automaton_t &aut, std::ostream &out, format fmt, bool mathjax)
transition_t_of< automaton_t > transition_t
An input/output format for valuesets.
std::ostream & os_
Output stream.
auto final_transitions(const Aut &aut) -> decltype(aut->all_in(aut->post()))
Indexes of transitions from (visible) final states.
void print_epilogue_()
Finish the dot graph.
void print_transitions_(const state_t src, const state_t dst, const polynomial_t &entry)
Print the transitions between state src and state dst.
typename polynomialset_t::value_t polynomial_t
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
void print_prologue_()
Start the dot graph.
weight_t_of< automaton_t > weight_t
void print_state_(state_t s)
Pretty-print state s.
void enable_()
Enable the escaping of backslashes.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
bool print_(const std::string &sep, const std::string &kind, const weight_t &w)
Print a TikZ attribute.
Factor common bits in automaton formatting.
const polynomialset_t ps_
Short-hand to the polynomialset used to print the entries.
void print_states_()
Print the states.
Print as plain (ASCII) text, escaped.
automaton_t aut_
The automaton we have to output.
void disable_()
Disable the escaping of backslashes.
std::ostream & dot(const Aut &aut, std::ostream &out=std::cout, format fmt={}, bool mathjax=false)
Print an automaton in Graphviz's Dot format.
std::ostream & operator()()
Print the automaton on the stream.
Format an automaton into Dot.
states_t initials_()
The list of initial states, sorted.
std::string to_string(direction d)
Conversion to string.
std::unordered_set< state_t_of< Aut > > useful_
Useful states, without evaluating the lazy states.
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
states_t finals_()
The list of final states, sorted.
bool dot2tex_
Whether we need dot2tex formatting.
format format_
Format for labels and weights.
const weightset_t & ws_
Short-hand to the weightset.
detail::io::filtering_ostream bos_
The output stream, with a backslashify filter.