10 #include <vcsn/dyn/fwd.hh> 28 template <Automaton Aut>
47 using super_t::super_t;
51 const char*
gray =
"color = DimGray";
59 #if defined __GNUC__ && ! defined __clang__ 62 # pragma GCC diagnostic push 63 # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" 66 #if defined __GNUC__ && ! defined __clang__ 67 # pragma GCC diagnostic pop 87 auto style = conf[style_name];
88 while (style.is_valid(
"inherits"))
90 auto parent = style[
"inherits"].str();
92 style.remove(
"inherits");
93 style.merge(conf[parent]);
96 get_config()[
"dot"][
"styles"][style_name] = style;
106 " vcsn_context = \"";
115 bos_ <<
"texmode = math, lblstyle = auto";
118 auto style_name =
get_config()[
"dot"][
"default-style"].str();
119 auto conf =
get_style(style_name)[
"edge"];
120 auto keys = conf.
keys();
121 bos_ << keys[0] <<
" = " << conf[keys[0]].str();
122 for (
size_t i = 1; i < keys.size(); i++)
124 bos_ <<
", " << keys[i] <<
" = " << conf[keys[i]].str();
127 bos_ <<
"]\n" << std::flush;
131 " d2toptions = \"--format tikz --tikzedgelabels" 132 " --graphstyle=automaton --crop --nominsize --autosize\"\n" 133 " d2tdocpreamble = \"" 134 " \\usepackage{amssymb}" 135 " \\usetikzlibrary{arrows.meta, automata, bending}" 136 " \\tikzstyle{automaton}=[shorten >=1pt, pos=.4," 137 " >={Stealth[bend,round]}, initial text=]" 138 " \\tikzstyle{named}=[rectangle, rounded corners]" 139 " \\tikzstyle{initial}=[initial by arrow]" 140 " \\tikzstyle{accepting}=[accepting by arrow]" 156 const std::string& kind,
const weight_t& w)
163 if (
ws_.show_one() || !
ws_.is_one(w))
165 bos_ <<
", " << kind <<
" text={";
177 bool has_attributes =
false;
180 has_attributes =
true;
187 if (
aut_->state_has_name(s))
189 bos_ <<
"label = \"";
193 static bool debug = getenv(
"VCSN_DEBUG");
195 bos_ <<
" (" << s <<
')';
196 bos_ <<
"\", style = \"named";
201 sep =
"style = \"state, ";
202 if (
print_(sep,
"initial",
aut_->get_initial_weight(s)))
207 if (
print_(sep,
"accepting",
aut_->get_final_weight(s)))
214 if (
aut_->state_has_name(s))
216 has_attributes =
true;
217 bos_ <<
" [label = \"";
225 static bool debug = getenv(
"VCSN_DEBUG");
227 bos_ <<
" (" << s <<
')';
228 bos_ <<
"\", shape = box";
233 std::ostringstream oss;
235 float len = oss.str().size();
236 float width = 0.5f + 0.1f * (len / 2);
237 bos_ <<
", fixedsize = true" 238 <<
", width = " << width;
241 if (
aut_->is_lazy(s))
248 has_attributes =
true;
250 bos_ <<
"style = dashed";
260 has_attributes =
true;
279 " node [shape = point, width = 0]\n";
309 if (!
aut_->states().empty())
315 bos_ <<
"texmode = math, style = state";
318 auto style_name =
get_config()[
"dot"][
"default-style"].str();
319 auto conf =
get_style(style_name)[
"node"];
320 auto keys = conf.
keys();
321 bos_ << keys[0] <<
" = " << conf[keys[0]].str();
322 for (
size_t i = 1; i < keys.size(); i++)
324 bos_ <<
", " << keys[i] <<
" = " << conf[keys[i]].str();
328 for (
auto s :
aut_->states())
343 if (src ==
aut_->pre())
351 if (dst ==
aut_->post())
361 if (!e.empty() || useless)
364 const char* sep =
"";
367 bos_ <<
"label = \"";
385 auto dsts = std::map<state_t, polynomial_t>{};
386 for (
auto src :
aut_->all_states())
387 if (!
aut_->is_lazy(src)
395 ps_.new_weight(dsts[
aut_->dst_of(t)],
396 aut_->label_of(t),
aut_->weight_of(t));
397 for (
const auto& p: dsts)
405 boost::iostreams::flush(
bos_);
412 boost::iostreams::flush(
bos_);
417 detail::io::filtering_ostream
bos_;
433 template <Automaton Aut>
436 bool mathjax =
false)
std::ostream & dot(const Aut &aut, std::ostream &out=std::cout, format fmt={}, bool mathjax=false)
Print an automaton in Graphviz's Dot format.
void print_transitions_(const state_t src, const state_t dst, const polynomial_t &entry)
Print the transitions between state src and state dst.
dot_impl(const automaton_t &aut, std::ostream &out, format fmt, bool mathjax)
const polynomialset_t ps_
Short-hand to the polynomialset used to print the entries.
std::unordered_set< state_t_of< Aut > > useful_
Useful states, without evaluating the lazy states.
std::string to_string(direction d)
Conversion to string.
bool print_(const std::string &sep, const std::string &kind, const weight_t &w)
Print a TikZ attribute.
void print_epilogue_()
Finish the dot graph.
typename polynomialset_t::value_t polynomial_t
void disable_()
Disable the escaping of backslashes.
The class returned by [] operators.
states_t finals_()
The list of final states, sorted.
format format_
Format for labels and weights.
An input/output format for valuesets.
Factor common bits in automaton formatting.
void print_states_()
Print the states.
detail::config & get_config()
Get the configuration singleton.
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
config::config_value get_style(const std::string &style_name)
const weightset_t & ws_
Short-hand to the weightset.
states_t< Aut > useful_states(const Aut &a, bool strict=true)
The set of useful states, including possibly pre() and post().
void print_state_(state_t s)
Pretty-print state s.
std::ostream & operator()()
Print the automaton on the stream.
Format an automaton into Dot.
bool dot2tex_
Whether we need dot2tex formatting.
auto final_transitions(const Aut &aut) -> decltype(aut->all_in(aut->post()))
Indexes of transitions from (visible) final states.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
detail::io::filtering_ostream bos_
The output stream, with a backslashify filter.
states_t initials_()
The list of initial states, sorted.
automaton_t aut_
The automaton we have to output.
state_t_of< automaton_t > state_t
void print_prologue_()
Start the dot graph.
weightset_t_of< automaton_t > weightset_t
Print as plain (ASCII) text, escaped.
void enable_()
Enable the escaping of backslashes.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
std::vector< std::string > keys() const
void print_transitions_()
Print all the transitions, sorted by src state, then dst state.
transition_t_of< automaton_t > transition_t
weight_t_of< automaton_t > weight_t
std::ostream & os_
Output stream.
Print as a parsable type string.
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.