diff --git a/NEWS b/NEWS index 23204222e..fb8177c7a 100644 --- a/NEWS +++ b/NEWS @@ -126,6 +126,11 @@ New in spot 2.11.6.dev (not yet released) drop_false_edges=False argument to disable the historical behavior of ignoring edges labeled by False. + - Calling aut.highlight_state(s, None) or aut.highlight_edge(e, + None) may now be used to remove the highlighting color of some + given state or edge. Use aut.remove_highlight_states() or + aut.remove_highlight_edges() to remove all colors. (Issue #554.) + Bugs fixed: - tgba_determinize()'s use_simulation option would cause it to diff --git a/python/spot/impl.i b/python/spot/impl.i index e8160c362..e1dd7f296 100644 --- a/python/spot/impl.i +++ b/python/spot/impl.i @@ -407,6 +407,16 @@ namespace swig $result = SWIG_FromCharPtr($1->c_str()); } +%typemap(typecheck, precedence=2000) std::nullptr_t { + $1 = $input == Py_None; +} + +%typemap(in) std::nullptr_t { + if ($input != Py_None) + %argument_fail(SWIG_TypeError, "std::nullptr_t", $symname, $argnum); + $1 = nullptr; +} + // For some reason, Swig can convert [aut1,aut2,...] into // std::vector, but not into // std::vector. Let's fix that by using @@ -1037,6 +1047,21 @@ static void* ptr_for_bdddict(PyObject* obj) return self; } + twa* highlight_state(unsigned state, std::nullptr_t color) // color=None + { + (void) color; + if (std::map* hs = + self->get_named_prop>("highlight-states")) + hs->erase(state); + return self; + } + + twa* remove_highlight_states() + { + self->set_named_prop("highlight-states", nullptr); + return self; + } + twa* highlight_edge(unsigned edge, unsigned color) { auto ht = @@ -1049,6 +1074,21 @@ static void* ptr_for_bdddict(PyObject* obj) (*ht)[edge] = color; return self; } + + twa* highlight_edge(unsigned edge, std::nullptr_t color) // color=None + { + (void) color; + if (std::map* hs = + self->get_named_prop>("highlight-edges")) + hs->erase(edge); + return self; + } + + twa* remove_highlight_edges() + { + self->set_named_prop("highlight-edges", nullptr); + return self; + } } %extend spot::internal::state_out> { diff --git a/tests/python/highlighting.ipynb b/tests/python/highlighting.ipynb index a35f88334..6fe0856a1 100644 --- a/tests/python/highlighting.ipynb +++ b/tests/python/highlighting.ipynb @@ -247,7 +247,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bb720> >" + " *' at 0x7fe86e410bd0> >" ] }, "execution_count": 4, @@ -359,7 +359,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bbb40> >" + " *' at 0x7fe86e4110e0> >" ] }, "execution_count": 5, @@ -469,7 +469,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bb720> >" + " *' at 0x7fe86e410bd0> >" ] }, "execution_count": 6, @@ -549,6 +549,235 @@ "print(a.to_str('HOA', '1.1'))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Removing highlights" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Use `None` as the color to remove some specific highlights." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "[Büchi]\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "I->2\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "a & !c\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2->0\n", + "\n", + "\n", + "c\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->1\n", + "\n", + "\n", + "!a & b & !c\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->0\n", + "\n", + "\n", + "c\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "b & !c\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + " *' at 0x7fe86e411e30> >" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.highlight_state(0, None).highlight_edges([4, 2], None)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Or use `remove_highlight_states()` or `remove_highlight_edges()` to remove all highlights." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "[Büchi]\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "I->2\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "a & !c\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2->0\n", + "\n", + "\n", + "c\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->1\n", + "\n", + "\n", + "!a & b & !c\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->0\n", + "\n", + "\n", + "c\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "b & !c\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + " *' at 0x7fe86e411c50> >" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.remove_highlight_states().remove_highlight_edges()" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -562,7 +791,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -702,10 +931,10 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bba50> >" + " *' at 0x7fe86e4123a0> >" ] }, - "execution_count": 8, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -716,7 +945,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -741,7 +970,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -757,7 +986,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -897,10 +1126,10 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bba50> >" + " *' at 0x7fe86e4123a0> >" ] }, - "execution_count": 11, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -920,7 +1149,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -1235,7 +1464,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3dc8d0> >" + " *' at 0x7fe86e4121f0> >" ] }, "metadata": {}, @@ -1496,7 +1725,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ef60adc0> >" + " *' at 0x7fe86e410f90> >" ] }, "metadata": {}, @@ -1679,7 +1908,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ef60a7f0> >" + " *' at 0x7fe86e410ff0> >" ] }, "metadata": {}, @@ -1734,7 +1963,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -1796,7 +2025,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bbdb0> >" + " *' at 0x7fe86e413030> >" ] }, "metadata": {}, @@ -1851,7 +2080,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ef60b810> >" + " *' at 0x7fe86e412280> >" ] }, "metadata": {}, @@ -1866,7 +2095,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -1945,10 +2174,10 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bbc60> >" + " *' at 0x7fe86e412310> >" ] }, - "execution_count": 14, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -1959,7 +2188,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -1982,7 +2211,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -1995,7 +2224,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -2074,7 +2303,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bbc60> >" + " *' at 0x7fe86e412310> >" ] }, "metadata": {}, @@ -2139,7 +2368,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3bbdb0> >" + " *' at 0x7fe86e413030> >" ] }, "metadata": {}, @@ -2194,7 +2423,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ef60b810> >" + " *' at 0x7fe86e412280> >" ] }, "metadata": {}, @@ -2214,7 +2443,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -2420,7 +2649,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ef60a7f0> >" + " *' at 0x7fe86e413c00> >" ] }, "metadata": {}, @@ -2505,7 +2734,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ef60af10> >" + " *' at 0x7fe86e4109c0> >" ] }, "metadata": {}, @@ -2602,7 +2831,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ef60b840> >" + " *' at 0x7fe86e413bd0> >" ] }, "metadata": {}, @@ -2631,7 +2860,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -2771,10 +3000,10 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3dd860> >" + " *' at 0x7fe86e412b50> >" ] }, - "execution_count": 19, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -2799,7 +3028,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -2939,10 +3168,10 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3dd860> >" + " *' at 0x7fe86e412b50> >" ] }, - "execution_count": 20, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -2962,7 +3191,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -3102,7 +3331,7 @@ "\n" ], "text/plain": [ - " *' at 0x7fb7ec3dd860> >" + " *' at 0x7fe86e412b50> >" ] }, "metadata": {}, @@ -3336,7 +3565,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -3582,7 +3811,7 @@ "" ] }, - "execution_count": 22, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" }