[Bf-blender-cvs] [c900cd3] master: Freestyle: Expose the Operators.reset() function to Python.

Tamito Kajiyama noreply at git.blender.org
Sun Sep 28 04:17:42 CEST 2014


Commit: c900cd3bd8ab060f34e303ae6da7edf6994223d9
Author: Tamito Kajiyama
Date:   Sun Sep 28 11:05:19 2014 +0900
Branches: master
https://developer.blender.org/rBc900cd3bd8ab060f34e303ae6da7edf6994223d9

Freestyle: Expose the Operators.reset() function to Python.

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)

===================================================================

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

===================================================================

diff --git a/source/blender/freestyle/intern/python/BPy_Operators.cpp b/source/blender/freestyle/intern/python/BPy_Operators.cpp
index 6beeafe..b96a62b 100644
--- a/source/blender/freestyle/intern/python/BPy_Operators.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Operators.cpp
@@ -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,
diff --git a/source/blender/freestyle/intern/stroke/Operators.cpp b/source/blender/freestyle/intern/stroke/Operators.cpp
index 427994f..87ba34e 100644
--- a/source/blender/freestyle/intern/stroke/Operators.cpp
+++ b/source/blender/freestyle/intern/stroke/Operators.cpp
@@ -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 */
diff --git a/source/blender/freestyle/intern/stroke/Operators.h b/source/blender/freestyle/intern/stroke/Operators.h
index 59ebec5..c7b0e3f 100644
--- a/source/blender/freestyle/intern/stroke/Operators.h
+++ b/source/blender/freestyle/intern/stroke/Operators.h
@@ -259,7 +259,7 @@ public:
 		return &_current_strokes_set;
 	}
 
-	static void reset();
+	static void reset(bool removeStrokes=true);
 
 private:
 	Operators() {}




More information about the Bf-blender-cvs mailing list