Freestyle: Expose the Operators.reset() function to Python.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sun, 28 Sep 2014 02:05:19 +0000 (11:05 +0900)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sun, 28 Sep 2014 02:17:31 +0000 (11:17 +0900)
The Operators.reset function is exposed to the Freestyle Python API, which makes
it possible to combine multiple style modules into one file.

Differential revision: https://developer.blender.org/D802

Author: flokkievids (Folkert de Vries)

Reviewed by: kjym3 (Tamito Kajiyama)

source/blender/freestyle/intern/python/BPy_Operators.cpp
source/blender/freestyle/intern/stroke/Operators.cpp
source/blender/freestyle/intern/stroke/Operators.h

index 6beeafe0065add78002f06dadbd28a90d6beec1a..b96a62b85c41ec04122592d9cd8951896e29966a 100644 (file)
@@ -548,6 +548,29 @@ static PyObject *Operators_create(BPy_Operators *self, PyObject *args, PyObject
        Py_RETURN_NONE;
 }
 
+PyDoc_STRVAR(Operators_reset_doc,
+".. staticmethod:: reset(delete_strokes=True)\n"
+"\n"
+"   Resets the stroke selection (and therefore chaining, splitting, sorting and shading)\n"
+"\n"
+"   :arg delete_strokes: Delete the strokes that are currently stored\n"
+"   :type delete_strokes: bool\n");
+
+static PyObject *Operators_reset(BPy_Operators *self, PyObject *args, PyObject *kwds)
+{
+       static const char *kwlist[] = {"delete_strokes", NULL};
+       PyObject *obj1 = 0;
+       if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &PyBool_Type, &obj1)) {
+               // true is the default
+               Operators::reset(obj1 ? bool_from_PyBool(obj1) : true);
+       }
+       else {
+               PyErr_SetString(PyExc_RuntimeError, "Operators.reset() failed");
+               return NULL;
+       }
+       Py_RETURN_NONE;
+}
+
 PyDoc_STRVAR(Operators_get_viewedge_from_index_doc,
 ".. staticmethod:: get_viewedge_from_index(i)\n"
 "\n"
@@ -671,6 +694,7 @@ static PyMethodDef BPy_Operators_methods[] = {
                            Operators_recursive_split_doc},
        {"sort", (PyCFunction) Operators_sort, METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_sort_doc},
        {"create", (PyCFunction) Operators_create, METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_create_doc},
+       {"reset", (PyCFunction) Operators_reset, METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_reset_doc},
        {"get_viewedge_from_index", (PyCFunction) Operators_get_viewedge_from_index,
                                    METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_get_viewedge_from_index_doc},
        {"get_chain_from_index", (PyCFunction) Operators_get_chain_from_index, METH_VARARGS | METH_KEYWORDS | METH_STATIC,
index 427994f80f18a244cebb2528c7ed5a6afd771422..87ba34e8f42f222481f069cfb6856261a914b348 100644 (file)
@@ -1242,7 +1242,7 @@ error:
        return -1;
 }
 
-void Operators::reset()
+void Operators::reset(bool removeStrokes)
 {
        ViewMap *vm = ViewMap::getInstance();
        if (!vm) {
@@ -1253,11 +1253,7 @@ void Operators::reset()
        for (I1DContainer::iterator it = _current_chains_set.begin(); it != _current_chains_set.end(); ++it)
                delete *it;
        _current_chains_set.clear();
-#if 0
-       _current_view_edges_set.insert(_current_view_edges_set.begin(),
-       vm->ViewEdges().begin(),
-       vm->ViewEdges().end());
-#else
+
        ViewMap::viewedges_container& vedges = vm->ViewEdges();
        ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end();
        for (; ve != veend; ++ve) {
@@ -1265,9 +1261,9 @@ void Operators::reset()
                        continue;
                _current_view_edges_set.push_back(*ve);
        }
-#endif
        _current_set = &_current_view_edges_set;
-       _current_strokes_set.clear();
+       if (removeStrokes)
+               _current_strokes_set.clear();
 }
 
 } /* namespace Freestyle */
index 59ebec572460fc3a19625c906c0804c190df936e..c7b0e3f8b81f43603d660ec792359eebe0ccd957 100644 (file)
@@ -259,7 +259,7 @@ public:
                return &_current_strokes_set;
        }
 
-       static void reset();
+       static void reset(bool removeStrokes=true);
 
 private:
        Operators() {}