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
diff options
context:
space:
mode:
authorMaxime Curioni <maxime.curioni@gmail.com>2008-07-31 12:50:12 +0400
committerMaxime Curioni <maxime.curioni@gmail.com>2008-07-31 12:50:12 +0400
commit3010f2b753f2397256861816504b8e7d697632db (patch)
treecee975b7fc574c43be0d462447c87056c4bdfc6b /source/blender/freestyle/intern/stroke
parenta482f644242456ad6ddf0306e1b37d8855342103 (diff)
soc-2008-mxcurioni: the native Python system now supports cross-language polymorphism for the following classes: BinaryPredicate0D (__call__), BinaryPredicate1D (__call__), UnaryPredicate0D (__call__), UnaryPredicate1D (__call__), StrokeShader (shade), ChainingIterator (init, traverse).
Other methods could easily be supported in the future. The method now works as planned for the contour style. For style modules with Python shaders, there still is a problem that I will fix right away.
Diffstat (limited to 'source/blender/freestyle/intern/stroke')
-rwxr-xr-xsource/blender/freestyle/intern/stroke/ChainingIterators.h38
-rwxr-xr-xsource/blender/freestyle/intern/stroke/Predicates0D.h34
-rwxr-xr-xsource/blender/freestyle/intern/stroke/Predicates1D.h31
-rwxr-xr-xsource/blender/freestyle/intern/stroke/Stroke.h1
-rwxr-xr-xsource/blender/freestyle/intern/stroke/StrokeShader.h15
5 files changed, 94 insertions, 25 deletions
diff --git a/source/blender/freestyle/intern/stroke/ChainingIterators.h b/source/blender/freestyle/intern/stroke/ChainingIterators.h
index b01c895d89a..1f33f99db67 100755
--- a/source/blender/freestyle/intern/stroke/ChainingIterators.h
+++ b/source/blender/freestyle/intern/stroke/ChainingIterators.h
@@ -36,6 +36,8 @@
#include "../system/Iterator.h" //soc
+# include "../python/Director.h"
+
//using namespace ViewEdgeInternal;
//
@@ -135,6 +137,9 @@ protected:
bool _increment; //true if we're currently incrementing, false when decrementing
public:
+
+ PyObject *py_c_it;
+
/*! Builds a Chaining Iterator from the first ViewEdge used for iteration
* and its orientation.
* \param iRestrictToSelection
@@ -154,6 +159,7 @@ public:
_restrictToSelection = iRestrictToSelection;
_restrictToUnvisited = iRestrictToUnvisited;
_increment = true;
+ py_c_it = 0;
}
/*! Copy constructor */
@@ -162,6 +168,7 @@ public:
_restrictToSelection = brother._restrictToSelection;
_restrictToUnvisited = brother._restrictToUnvisited;
_increment = brother._increment;
+ py_c_it = brother.py_c_it;
}
/*! Returns the string "ChainingIterator" */
@@ -176,7 +183,16 @@ public:
* history information that you
* might want to keep.
*/
- virtual void init(){}
+ virtual void init() {
+ string name( py_c_it ? PyString_AsString(PyObject_CallMethod(py_c_it, "getExactTypeName", "")) : getExactTypeName() );
+
+ if( py_c_it && PyObject_HasAttrString(py_c_it, "init") ) {
+ Director_BPy_ChainingIterator_init( py_c_it );
+ } else {
+ cerr << "Warning: " << name << " method init() not implemented" << endl;
+ }
+
+ }
/*! This method iterates over the potential next
* ViewEdges and returns the one that will be
@@ -190,10 +206,16 @@ public:
* rules by only iterating over the valid ViewEdges.
*/
virtual ViewEdge * traverse(const AdjacencyIterator &it){
- cerr << "Warning: the traverse method was not defined" << endl;
- return 0;
+ string name( py_c_it ? PyString_AsString(PyObject_CallMethod(py_c_it, "getExactTypeName", "")) : getExactTypeName() );
+
+ if( py_c_it && PyObject_HasAttrString(py_c_it, "traverse") ) {
+ return Director_BPy_ChainingIterator_traverse(py_c_it, const_cast<AdjacencyIterator &>(it) );
+ } else {
+ cerr << "Warning: the " << name << " traverse method was not defined" << endl;
+ return 0;
+ }
}
-
+
/* accessors */
/*! Returns true if the orientation of the current ViewEdge
* corresponds to its natural orientation
@@ -274,6 +296,8 @@ public:
*/
virtual ViewEdge * traverse(const AdjacencyIterator& it);
+ /*! Inits the iterator context */
+ virtual void init() {}
};
//
@@ -368,7 +392,11 @@ public:
* followed next.
* When reaching the end of a chain, 0 is returned.
*/
- virtual ViewEdge * traverse(const AdjacencyIterator &it);
+ virtual ViewEdge * traverse(const AdjacencyIterator &it);
+
+ /*! Inits the iterator context */
+ virtual void init() {}
+
};
#endif // CHAININGITERATORS_H
diff --git a/source/blender/freestyle/intern/stroke/Predicates0D.h b/source/blender/freestyle/intern/stroke/Predicates0D.h
index 4c2dfacdf98..0318c1742ec 100755
--- a/source/blender/freestyle/intern/stroke/Predicates0D.h
+++ b/source/blender/freestyle/intern/stroke/Predicates0D.h
@@ -32,6 +32,8 @@
# include "../view_map/Functions0D.h"
+# include "../python/Director.h"
+
//
// UnaryPredicate0D (base class for predicates in 0D)
//
@@ -48,8 +50,11 @@
class UnaryPredicate0D
{
public:
+
+ PyObject *py_up0D;
+
/*! Default constructor. */
- UnaryPredicate0D() {}
+ UnaryPredicate0D() { py_up0D = 0; }
/*! Destructor. */
virtual ~UnaryPredicate0D() {}
/*! Returns the string of the name
@@ -68,9 +73,16 @@ public:
* false otherwise.
*/
virtual bool operator()(Interface0DIterator& it) {
- cerr << "Warning: operator() not implemented" << endl;
- return false;
+ string name( py_up0D ? PyString_AsString(PyObject_CallMethod(py_up0D, "getName", "")) : getName() );
+
+ if( py_up0D && PyObject_HasAttrString(py_up0D, "__call__") ) {
+ return Director_BPy_UnaryPredicate0D___call__(py_up0D, it);
+ } else {
+ cerr << "Warning: " << name << " operator() not implemented" << endl;
+ return false;
+ }
}
+
};
@@ -88,8 +100,11 @@ public:
class BinaryPredicate0D
{
public:
+
+ PyObject *py_bp0D;
+
/*! Default constructor. */
- BinaryPredicate0D() {}
+ BinaryPredicate0D() { py_bp0D = 0; }
/*! Destructor. */
virtual ~BinaryPredicate0D() {}
/*! Returns the string of the name of the
@@ -108,9 +123,16 @@ public:
* \return true or false.
*/
virtual bool operator()(Interface0D& inter1, Interface0D& inter2) {
- cerr << "Warning: operator() not implemented" << endl;
- return false;
+ string name( py_bp0D ? PyString_AsString(PyObject_CallMethod(py_bp0D, "getName", "")) : getName() );
+
+ if( py_bp0D && PyObject_HasAttrString(py_bp0D, "__call__") ) {
+ return Director_BPy_BinaryPredicate0D___call__(py_bp0D, inter1, inter2);
+ } else {
+ cerr << "Warning: " << name << " operator() not implemented" << endl;
+ return false;
+ }
}
+
};
diff --git a/source/blender/freestyle/intern/stroke/Predicates1D.h b/source/blender/freestyle/intern/stroke/Predicates1D.h
index 98148361bb7..8c6f5a9bfa4 100755
--- a/source/blender/freestyle/intern/stroke/Predicates1D.h
+++ b/source/blender/freestyle/intern/stroke/Predicates1D.h
@@ -58,9 +58,7 @@ public:
PyObject *py_up1D;
/*! Default constructor. */
- UnaryPredicate1D() {
- py_up1D = 0;
- }
+ UnaryPredicate1D() { py_up1D = 0; }
/*! Destructor. */
virtual ~UnaryPredicate1D() {}
/*! Returns the string of the name
@@ -78,17 +76,16 @@ public:
* false otherwise.
*/
virtual bool operator()(Interface1D& inter) {
+ string name( py_up1D ? PyString_AsString(PyObject_CallMethod(py_up1D, "getName", "")) : getName() );
- if( py_up1D ) {
- return director_BPy_UnaryPredicate1D___call__(py_up1D, inter);
+ if( py_up1D && PyObject_HasAttrString(py_up1D, "__call__")) {
+ return Director_BPy_UnaryPredicate1D___call__(py_up1D, inter);
} else {
- cerr << "Warning: operator() not implemented" << endl;
- return false;
+ cerr << "Warning: " << name << " operator() not implemented" << endl;
+ return false;
}
}
- inline void setPythonObject(PyObject *_py_up1D) { py_up1D = _py_up1D; }
-
};
@@ -106,8 +103,11 @@ public:
class BinaryPredicate1D
{
public:
+
+ PyObject *py_bp1D;
+
/*! Default constructor. */
- BinaryPredicate1D() {}
+ BinaryPredicate1D() { py_bp1D = 0; }
/*! Destructor. */
virtual ~BinaryPredicate1D() {}
/*! Returns the string of the name of the
@@ -125,9 +125,16 @@ public:
* \return true or false.
*/
virtual bool operator()(Interface1D& inter1, Interface1D& inter2) {
- cerr << "Warning: operator() not implemented" << endl;
- return false;
+ string name( py_bp1D ? PyString_AsString(PyObject_CallMethod(py_bp1D, "getName", "")) : getName() );
+
+ if( py_bp1D && py_bp1D && PyObject_HasAttrString(py_bp1D, "__call__") ) {
+ return Director_BPy_BinaryPredicate1D___call__(py_bp1D, inter1, inter2);
+ } else {
+ cerr << "Warning: " << name << " operator() not implemented" << endl;
+ return false;
+ }
}
+
};
diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h
index 8e4e5e24a2c..3df57341e5f 100755
--- a/source/blender/freestyle/intern/stroke/Stroke.h
+++ b/source/blender/freestyle/intern/stroke/Stroke.h
@@ -38,6 +38,7 @@
# include "../view_map/Interface1D.h"
# include "../system/StringUtils.h"
+
//
// StrokeAttribute
//
diff --git a/source/blender/freestyle/intern/stroke/StrokeShader.h b/source/blender/freestyle/intern/stroke/StrokeShader.h
index fa1289f6e0f..f92895564d8 100755
--- a/source/blender/freestyle/intern/stroke/StrokeShader.h
+++ b/source/blender/freestyle/intern/stroke/StrokeShader.h
@@ -33,6 +33,8 @@
# include <iostream>
# include <vector>
+# include "../python/Director.h"
+
//
// StrokeShader base class
//
@@ -69,8 +71,11 @@ class Stroke;
class LIB_STROKE_EXPORT StrokeShader
{
public:
+
+ PyObject *py_ss;
+
/*! Default constructor. */
- StrokeShader() {}
+ StrokeShader() { py_ss = 0; }
/*! Destructor. */
virtual ~StrokeShader() {}
/*! Returns the string corresponding to the
@@ -111,7 +116,13 @@ public:
* as Color, Thickness, Geometry...)
*/
virtual void shade(Stroke& ioStroke) const {
- cerr << "Warning: method shade() not implemented" << endl;
+ string name( py_ss ? PyString_AsString(PyObject_CallMethod(py_ss, "getName", "")) : getName() );
+
+ if( py_ss && PyObject_HasAttrString(py_ss, "shade") ) {
+ return Director_BPy_StrokeShader_shade(py_ss, ioStroke);
+ } else {
+ cerr << "Warning: " << name << " method shade() not implemented" << endl;
+ }
}
};