Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMaxime Curioni <maxime.curioni@gmail.com>2008-07-30 05:51:40 +0400
committerMaxime Curioni <maxime.curioni@gmail.com>2008-07-30 05:51:40 +0400
commita482f644242456ad6ddf0306e1b37d8855342103 (patch)
tree4d89fe22969b7970ce09f195d82261ac47544157 /source
parent7d5eaa674b70b13af3c67b2209fdfe32b6168e45 (diff)
soc-2008-mxcurioni: Tested SWIG-less environment more and understood why the former predicate methods were not working. As Stéphane had mentioned a few months ago, Freestyle uses SWIG directors to provide cross-language polymorphism. The API and the system I had provided did not support that feature and only implementations in C++ were supported. To correct the problem, after researching how directors are implemented in SWIG, I provided the same functionality. So far, I only provided the code for the UnaryPredicate1D class and it works. The implementation is in intern/python/Director.cpp and Operators.cpp. I will port the remaining directors tonight and continue to test it.
To prevent strokes from piling up after each render, I clear the canvas at each render now (as it should have been all along)
Diffstat (limited to 'source')
-rw-r--r--source/blender/freestyle/intern/app_blender/api.cpp1
-rw-r--r--source/blender/freestyle/intern/python/BPy_Convert.cpp9
-rw-r--r--source/blender/freestyle/intern/python/BPy_Convert.h4
-rw-r--r--source/blender/freestyle/intern/python/BPy_Operators.cpp6
-rw-r--r--source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp2
-rw-r--r--source/blender/freestyle/intern/python/Director.cpp12
-rw-r--r--source/blender/freestyle/intern/python/Director.h34
-rw-r--r--source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp2
-rwxr-xr-xsource/blender/freestyle/intern/stroke/Predicates1D.h21
-rw-r--r--source/blender/freestyle/style_modules_blender/freestyle_init.py6
-rwxr-xr-xsource/blender/freestyle/style_modules_blender/logical_operators.py12
11 files changed, 94 insertions, 15 deletions
diff --git a/source/blender/freestyle/intern/app_blender/api.cpp b/source/blender/freestyle/intern/app_blender/api.cpp
index 890c5097a63..7f5135a2655 100644
--- a/source/blender/freestyle/intern/app_blender/api.cpp
+++ b/source/blender/freestyle/intern/app_blender/api.cpp
@@ -42,6 +42,7 @@ extern "C" {
if( view == NULL )
view = new AppGLWidget;
+ controller->Clear();
controller->setView(view);
}
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp
index b541babd752..d7b6fa8bd33 100644
--- a/source/blender/freestyle/intern/python/BPy_Convert.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp
@@ -9,6 +9,7 @@
#include "Interface0D/CurvePoint/BPy_StrokeVertex.h"
#include "Interface0D/BPy_SVertex.h"
#include "Interface0D/BPy_ViewVertex.h"
+#include "BPy_Interface1D.h"
#include "Interface1D/BPy_FEdge.h"
#include "Interface1D/BPy_ViewEdge.h"
#include "BPy_Nature.h"
@@ -79,6 +80,14 @@ PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D ) {
return py_if0D;
}
+PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D ) {
+ PyObject *py_if1D = Interface1D_Type.tp_new( &Interface1D_Type, 0, 0 );
+ ((BPy_Interface1D *) py_if1D)->if1D = &if1D;
+
+ return py_if1D;
+}
+
+
PyObject * BPy_SVertex_from_SVertex( SVertex& sv ) {
PyObject *py_sv = SVertex_Type.tp_new( &SVertex_Type, 0, 0 );
((BPy_SVertex *) py_sv)->sv = new SVertex( sv );
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h
index 5b613b3c4c3..9e743f4b233 100644
--- a/source/blender/freestyle/intern/python/BPy_Convert.h
+++ b/source/blender/freestyle/intern/python/BPy_Convert.h
@@ -17,6 +17,9 @@ using namespace Geometry;
// Interface0D, Interface0DIteratorNested, Interface0DIterator
#include "../view_map/Interface0D.h"
+// Interface1D
+#include "../view_map/Interface1D.h"
+
// Material
#include "../scene_graph/Material.h"
@@ -71,6 +74,7 @@ PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewE
PyObject * BPy_FEdge_from_FEdge( FEdge& fe );
PyObject * BPy_Id_from_Id( Id& id );
PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
+PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D );
PyObject * BPy_IntegrationType_from_IntegrationType( int i );
PyObject * BPy_FrsMaterial_from_Material( Material& m );
PyObject * BPy_Nature_from_Nature( unsigned short n );
diff --git a/source/blender/freestyle/intern/python/BPy_Operators.cpp b/source/blender/freestyle/intern/python/BPy_Operators.cpp
index b0a8e7e3bd2..850b4cb5bad 100644
--- a/source/blender/freestyle/intern/python/BPy_Operators.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Operators.cpp
@@ -164,7 +164,11 @@ PyObject * Operators_select(BPy_Operators* self, PyObject *args)
Py_RETURN_NONE;
}
- Operators::select(*( ((BPy_UnaryPredicate1D *) obj)->up1D ));
+ UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *) obj)->up1D;
+ if( PyObject_HasAttrString( obj, "__call__") )
+ up1D->setPythonObject( obj );
+
+ Operators::select(*up1D);
Py_RETURN_NONE;
}
diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
index a13de77bbe9..14eb041c480 100644
--- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
+++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
@@ -215,7 +215,7 @@ PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args
if( if1D )
return PyBool_from_bool( self->up1D->operator()(*if1D) );
-
+
Py_RETURN_NONE;
}
diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp
new file mode 100644
index 00000000000..6acdc665a0c
--- /dev/null
+++ b/source/blender/freestyle/intern/python/Director.cpp
@@ -0,0 +1,12 @@
+#include "Director.h"
+
+#include "BPy_Convert.h"
+
+bool director_BPy_UnaryPredicate1D___call__( PyObject *py_up1D, Interface1D& if1D) {
+ cout << "Polymorphism works" << endl;
+
+ PyObject *method = PyObject_GetAttrString( py_up1D, "__call__");
+ PyObject *result = PyObject_CallFunction(method, "O", BPy_Interface1D_from_Interface1D(if1D) );
+
+ return bool_from_PyBool(result);
+}
diff --git a/source/blender/freestyle/intern/python/Director.h b/source/blender/freestyle/intern/python/Director.h
new file mode 100644
index 00000000000..7114b124ffb
--- /dev/null
+++ b/source/blender/freestyle/intern/python/Director.h
@@ -0,0 +1,34 @@
+#ifndef FREESTYLE_PYTHON_DIRECTOR
+# define FREESTYLE_PYTHON_DIRECTOR
+
+#include "../view_map/Interface1D.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////
+
+#include <Python.h>
+
+// SWIG directors
+// ----------------------------
+// ViewEdgeInternal::ViewEdgeIterator;
+// ChainingIterator;
+// ChainSilhouetteIterator;
+// ChainPredicateIterator;
+// UnaryPredicate0D;
+// UnaryPredicate1D;
+// BinaryPredicate1D;
+// StrokeShader;
+
+bool director_BPy_UnaryPredicate1D___call__( PyObject *py_up1D, Interface1D& if1D);
+
+///////////////////////////////////////////////////////////////////////////////////////////
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif // FREESTYLE_PYTHON_DIRECTOR
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
index 75526507493..4bfaab92a8e 100644
--- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
+++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
@@ -111,7 +111,7 @@ int ChainSilhouetteIterator___init__(BPy_ChainSilhouetteIterator *self, PyObject
{
PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0;
- if (!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) ))
+ if (!( PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3) ))
return -1;
if( obj1 && BPy_ChainSilhouetteIterator_Check(obj1) ) {
diff --git a/source/blender/freestyle/intern/stroke/Predicates1D.h b/source/blender/freestyle/intern/stroke/Predicates1D.h
index cf9a3283ae4..98148361bb7 100755
--- a/source/blender/freestyle/intern/stroke/Predicates1D.h
+++ b/source/blender/freestyle/intern/stroke/Predicates1D.h
@@ -36,6 +36,8 @@
# include "../view_map/Functions1D.h"
# include "AdvancedFunctions1D.h"
+# include "../python/Director.h"
+
//
// UnaryPredicate1D (base class for predicates in 1D)
//
@@ -52,8 +54,13 @@
class UnaryPredicate1D
{
public:
+
+ PyObject *py_up1D;
+
/*! Default constructor. */
- UnaryPredicate1D() {}
+ UnaryPredicate1D() {
+ py_up1D = 0;
+ }
/*! Destructor. */
virtual ~UnaryPredicate1D() {}
/*! Returns the string of the name
@@ -71,9 +78,17 @@ public:
* false otherwise.
*/
virtual bool operator()(Interface1D& inter) {
- cerr << "Warning: operator() not implemented" << endl;
- return false;
+
+ if( py_up1D ) {
+ return director_BPy_UnaryPredicate1D___call__(py_up1D, inter);
+ } else {
+ cerr << "Warning: operator() not implemented" << endl;
+ return false;
+ }
}
+
+ inline void setPythonObject(PyObject *_py_up1D) { py_up1D = _py_up1D; }
+
};
diff --git a/source/blender/freestyle/style_modules_blender/freestyle_init.py b/source/blender/freestyle/style_modules_blender/freestyle_init.py
index 8c45629bade..06b8f933114 100644
--- a/source/blender/freestyle/style_modules_blender/freestyle_init.py
+++ b/source/blender/freestyle/style_modules_blender/freestyle_init.py
@@ -49,16 +49,16 @@ class StrokeShader(Blender.Freestyle.StrokeShader):
pass
class UnaryFunction0D(Blender.Freestyle.UnaryFunction0D):
- pass
+ def __call__(*args): return Blender.Freestyle.UnaryFunction0D.__call__(*args)
class UnaryFunction1D(Blender.Freestyle.UnaryFunction1D):
- pass
+ def __call__(*args): return Blender.Freestyle.UnaryFunction1D.__call__(*args)
class UnaryPredicate0D(Blender.Freestyle.UnaryPredicate0D):
pass
class UnaryPredicate1D(Blender.Freestyle.UnaryPredicate1D):
- def __call__(*args): return Blender.Freestyle.UnaryPredicate1D.__call__(*args)
+ pass
class ViewMap(Blender.Freestyle.ViewMap):
pass
diff --git a/source/blender/freestyle/style_modules_blender/logical_operators.py b/source/blender/freestyle/style_modules_blender/logical_operators.py
index 75b486ef470..0ecf6623697 100755
--- a/source/blender/freestyle/style_modules_blender/logical_operators.py
+++ b/source/blender/freestyle/style_modules_blender/logical_operators.py
@@ -1,8 +1,8 @@
from freestyle_init import *
-class AndUP1D(ContourUP1D):
+class AndUP1D(UnaryPredicate1D):
def __init__(self, pred1, pred2):
- ContourUP1D.__init__(self)
+ UnaryPredicate1D.__init__(self)
self.__pred1 = pred1
self.__pred2 = pred2
@@ -12,9 +12,9 @@ class AndUP1D(ContourUP1D):
def __call__(self, inter):
return self.__pred1(inter) and self.__pred2(inter)
-class OrUP1D(ContourUP1D):
+class OrUP1D(UnaryPredicate1D):
def __init__(self, pred1, pred2):
- ContourUP1D.__init__(self)
+ UnaryPredicate1D.__init__(self)
self.__pred1 = pred1
self.__pred2 = pred2
@@ -24,9 +24,9 @@ class OrUP1D(ContourUP1D):
def __call__(self, inter):
return self.__pred1(inter) or self.__pred2(inter)
-class NotUP1D(ContourUP1D):
+class NotUP1D(UnaryPredicate1D):
def __init__(self, pred):
- ContourUP1D.__init__(self)
+ UnaryPredicate1D.__init__(self)
self.__pred = pred
def getName(self):