17 #ifndef AWALI_ALGOS_DOT_HH
18 # define AWALI_ALGOS_DOT_HH
28 namespace awali {
namespace sttc {
40 template <
typename Aut>
56 using super_type::super_type;
60 const char* gray =
"color = DimGray";
64 bool dot2tex,
bool print_history,
bool horizontal=
true)
76 const std::string& kind,
const weight_t& w)
83 if (ws_.show_one() || !ws_.is_one(w))
85 os_ <<
", " << kind <<
" text={";
86 ws_.print(w, os_) <<
'}';
106 aut_->print_state_name(s, os_,
"latex");
107 static bool debug = getenv(
"AWALI_DEBUG");
109 os_ <<
" (" << s <<
')';
110 os_ <<
"\", style = \"named";
113 if (
format(sep,
"initial", aut_->get_initial_weight(s)))
118 if (
format(sep,
"accepting", aut_->get_final_weight(s)))
125 os_ <<
" [label = \"";
127 aut_->print_state_history(s, os_);
129 aut_->print_state_name(s, os_,
"text");
130 static bool debug = getenv(
"AWALI_DEBUG");
132 os_ <<
" (" << s <<
')';
133 os_ <<
"\", shape = box, style = rounded]";
144 " vcsn_context = \"" << aut_->context().vname() <<
"\"\n";
146 os_ <<
" rankdir = LR\n";
150 " d2toptions = \"--format tikz --tikzedgelabels --graphstyle=automaton --crop --nominsize --autosize\"\n"
151 " d2tdocpreamble = \""
152 " \\usepackage{amssymb}"
153 " \\usetikzlibrary{arrows, automata}"
154 " \\tikzstyle{automaton}=[shorten >=1pt, pos=.4, >=stealth', initial text=]"
155 " \\tikzstyle{named}=[rectangle, rounded corners]"
156 " \\tikzstyle{initial}=[initial by arrow]"
157 " \\tikzstyle{accepting}=[accepting by arrow]"
162 if (!aut_->initial_transitions().empty()
163 || !aut_->final_transitions().empty())
167 " node [shape = point, width = 0]\n";
168 for (
auto s : initials_())
173 for (
auto s : finals_())
191 if (!aut_->states().empty())
196 ?
"texmode = math, style = state"
199 for (
auto s : aut_->states())
203 if (useful.find(s)==useful.end())
204 os_ <<
" [" << gray <<
']';
210 os_ <<
" edge [texmode = math, lblstyle = auto]\n";
211 for (
auto src :
dot2tex_ ? aut_->states() : aut_->all_states())
214 std::set<state_t> ds;
216 for (
auto t: aut_->out(src))
217 ds.insert(aut_->dst_of(t));
219 for (
auto t: aut_->all_out(src))
220 ds.insert(aut_->dst_of(t));
224 if (src == aut_->pre())
227 os_ <<
" -> " << dst;
229 else if (dst == aut_->post())
231 os_ << src <<
" -> ";
236 os_ << src <<
" -> " << dst;
238 std::string s = format_entry_(src, dst,
240 bool useless = useful.find(src)==useful.end()
241 || useful.find(dst)==useful.end();
242 if (!s.empty() || useless)
245 const char* sep =
"";
268 template <
typename Aut>
270 dot(
const Aut& aut, std::ostream& out,
bool dot2tex =
false,
bool keep_history =
true,
bool horizontal =
true)
Format an automaton into Dot.
Definition: dot.hh:42
void print_state_(state_t s)
Pretty-print state s for both dot and dot2tex.
Definition: dot.hh:94
bool print_history_
Definition: dot.hh:263
bool format(const std::string &sep, const std::string &kind, const weight_t &w)
Format a TikZ attribute.
Definition: dot.hh:75
bool horizontal_
Definition: dot.hh:264
dotter(const automaton_t &aut, std::ostream &out, bool dot2tex, bool print_history, bool horizontal=true)
Definition: dot.hh:63
std::ostream & operator()()
Definition: dot.hh:137
bool dot2tex_
Whether to format for dot2tex.
Definition: dot.hh:262
Factor common bits in automaton formatting.
Definition: grail.hh:43
std::string format_entry_(state_t src, state_t dst, const std::string &fmt="text")
The labels and weights of transitions from src to dst.
Definition: grail.hh:88
const automaton_t & aut_
The automaton we have to output.
Definition: grail.hh:154
states_t finals_()
The list of final states, sorted.
Definition: grail.hh:144
weight_t_of< automaton_t > weight_t
Definition: grail.hh:62
Aut automaton_t
Definition: grail.hh:45
const weightset_t & ws_
Short-hand to the weightset.
Definition: grail.hh:160
std::ostream & os_
Output stream.
Definition: grail.hh:156
states_t initials_()
The list of initial states, sorted.
Definition: grail.hh:134
weightset_t_of< automaton_t > weightset_t
Definition: grail.hh:61
std::ostream & str_escape(std::ostream &os, const int c)
Definition: escape.hh:30
std::set< state_t > useful_states(const Aut &aut, bool include_pre_post=false)
List of useful states.
Definition: accessible.hh:131
std::ostream & dot(const Aut &aut, std::ostream &out, bool dot2tex=false, bool keep_history=true, bool horizontal=true)
Definition: dot.hh:270
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21