soc-2008-mxcurioni: Tested SWIG-less environment more and understood why the former...
authorMaxime Curioni <maxime.curioni@gmail.com>
Wed, 30 Jul 2008 01:51:40 +0000 (01:51 +0000)
committerMaxime Curioni <maxime.curioni@gmail.com>
Wed, 30 Jul 2008 01:51:40 +0000 (01:51 +0000)
To prevent strokes from piling up after each render,  I clear the canvas at each render now (as it should have been all along)

source/blender/freestyle/intern/app_blender/api.cpp
source/blender/freestyle/intern/python/BPy_Convert.cpp
source/blender/freestyle/intern/python/BPy_Convert.h
source/blender/freestyle/intern/python/BPy_Operators.cpp
source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
source/blender/freestyle/intern/python/Director.cpp [new file with mode: 0644]
source/blender/freestyle/intern/python/Director.h [new file with mode: 0644]
source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
source/blender/freestyle/intern/stroke/Predicates1D.h
source/blender/freestyle/style_modules_blender/freestyle_init.py
source/blender/freestyle/style_modules_blender/logical_operators.py

index 890c5097a63fc574a8e892d3866693a571beb295..7f5135a2655df4620b58707dd53e834f2ec67499 100644 (file)
@@ -42,6 +42,7 @@ extern "C" {
                if( view == NULL )
                        view = new AppGLWidget;
                
+               controller->Clear();
                controller->setView(view);
        }
 
index b541babd7521575ade10110e91270b67b77b9cd8..d7b6fa8bd33e2696294b47edb5f1042c61f81774 100644 (file)
@@ -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 );
index 5b613b3c4c313c3750d76eb6fb2f2cd9a15bd834..9e743f4b233452ffa77a14a58f0c6f39b806bfbc 100644 (file)
@@ -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 );
index b0a8e7e3bd2f68c8b0376c081e4b306e5e7868bb..850b4cb5badb2f24044b3c0d8ef80eeb51df97ef 100644 (file)
@@ -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;
 }
index a13de77bbe9f76bd5f46a76e603bcc0e31cde822..14eb041c480456eabb1b2f1db40c7a95089d1a3c 100644 (file)
@@ -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 (file)
index 0000000..6acdc66
--- /dev/null
@@ -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 (file)
index 0000000..7114b12
--- /dev/null
@@ -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
index 755265074935def840d3992d8ec7d777494da85c..4bfaab92a8e4762d3818566397794c5e3862c2a7 100644 (file)
@@ -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)  ) { 
index cf9a3283ae4b27980bfff57c07ef1caf5c9f9401..98148361bb7c2392aa260d3d277f24b62e8779ac 100755 (executable)
@@ -36,6 +36,8 @@
 # include "../view_map/Functions1D.h"
 # include "AdvancedFunctions1D.h"
 
+# include  "../python/Director.h"
+
 //
 // UnaryPredicate1D (base class for predicates in 1D)
 //
 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; }
+
 };
 
 
index 8c45629badefee60fba8ab6dc53e815f4ab83043..06b8f9331145d22e3d1f4dff28d7f1d1a329b516 100644 (file)
@@ -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
index 75b486ef470016f6be7b85c34e1d23b934bd50ee..0ecf6623697abaff61f1a9ae1fb8d72378919aeb 100755 (executable)
@@ -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):