python: highlighting functions for edges and states

* python/spot/impl.i (highlight_state, highlight_edge): New function.
* python/spot/__init__.py (highlight_states, highlight_edges): New
functions.
* spot/twaalgos/dot.cc: Add a '#' option.
* spot/taalgos/dot.cc: Ignore '#'.
* tests/python/highlighting.ipynb: New file to illustrate everything.
* tests/Makefile.am, doc/org/tut.org: Add it.
This commit is contained in:
Alexandre Duret-Lutz 2016-02-05 17:29:30 +01:00
parent be4418257e
commit 23c2cbf46a
7 changed files with 393 additions and 2 deletions

View file

@ -147,6 +147,15 @@ class twa:
from IPython.display import SVG
return SVG(self._repr_svg_(opt))
def highlight_states(self, states, color):
for state in states:
self.highlight_state(state, color)
return self
def highlight_edges(self, edges, color):
for edge in edges:
self.highlight_edge(edge, color)
return self
@_extend(twa)
class twa:

View file

@ -546,6 +546,32 @@ namespace std {
{
return self->get_named_prop<std::vector<std::string>>("state-names");
}
twa* highlight_state(unsigned state, unsigned color)
{
auto hs =
self->get_named_prop<std::map<unsigned, unsigned>>("highlight-states");
if (!hs)
{
hs = new std::map<unsigned, unsigned>;
self->set_named_prop("highlight-states", hs);
}
(*hs)[state] = color;
return self;
}
twa* highlight_edge(unsigned edge, unsigned color)
{
auto ht =
self->get_named_prop<std::map<unsigned, unsigned>>("highlight-edges");
if (!ht)
{
ht = new std::map<unsigned, unsigned>;
self->set_named_prop("highlight-edges", ht);
}
(*ht)[edge] = color;
return self;
}
}