[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21710] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/python: * Introspection-based automatic type conversion from a generic C++ object
Tamito Kajiyama
rd6t-kjym at asahi-net.or.jp
Mon Jul 20 01:17:30 CEST 2009
Revision: 21710
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21710
Author: kjym3
Date: 2009-07-20 01:17:30 +0200 (Mon, 20 Jul 2009)
Log Message:
-----------
* Introspection-based automatic type conversion from a generic C++ object
to a specific Python object. The conversion takes place in the following
places.
- Interface0DIterator_getObject (BPy_Interface0DIterator.cpp)
- Director_BPy_BinaryPredicate1D___call__ (Director.cpp)
- Director_BPy_UnaryPredicate1D___call__ (Director.cpp)
- SVertex_viewvertex (BPy_SVertex.cpp)
- BPy_FEdge_from_FEdge (BPy_Convert.cpp)
This is a tentative list and more conversions are expected to be added.
* Added the following two converter functions to BPy_Convert.{cpp,h}:
- BPy_NonTVertex_from_NonTVertex_ptr
- BPy_TVertex_from_TVertex_ptr
Modified Paths:
--------------
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp 2009-07-19 23:03:26 UTC (rev 21709)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp 2009-07-19 23:17:30 UTC (rev 21710)
@@ -9,11 +9,15 @@
#include "Interface0D/CurvePoint/BPy_StrokeVertex.h"
#include "Interface0D/BPy_SVertex.h"
#include "Interface0D/BPy_ViewVertex.h"
+#include "Interface0D/ViewVertex/BPy_NonTVertex.h"
+#include "Interface0D/ViewVertex/BPy_TVertex.h"
#include "BPy_Interface1D.h"
#include "Interface1D/BPy_FEdge.h"
#include "Interface1D/BPy_Stroke.h"
#include "Interface1D/BPy_ViewEdge.h"
#include "Interface1D/Curve/BPy_Chain.h"
+#include "Interface1D/FEdge/BPy_FEdgeSharp.h"
+#include "Interface1D/FEdge/BPy_FEdgeSmooth.h"
#include "BPy_Nature.h"
#include "BPy_MediumType.h"
#include "BPy_SShape.h"
@@ -102,9 +106,22 @@
}
PyObject * BPy_FEdge_from_FEdge( FEdge& fe ) {
- PyObject *py_fe = FEdge_Type.tp_new( &FEdge_Type, 0, 0 );
- ((BPy_FEdge *) py_fe)->fe = new FEdge( fe );
- ((BPy_FEdge *) py_fe)->py_if1D.if1D = ((BPy_FEdge *) py_fe)->fe;
+ PyObject *py_fe;
+ if (typeid(fe) == typeid(FEdgeSharp)) {
+ py_fe = FEdgeSharp_Type.tp_new( &FEdgeSharp_Type, 0, 0 );
+ ((BPy_FEdgeSharp *) py_fe)->fes = new FEdgeSharp( dynamic_cast<FEdgeSharp&>(fe) );
+ ((BPy_FEdgeSharp *) py_fe)->py_fe.fe = ((BPy_FEdgeSharp *) py_fe)->fes;
+ ((BPy_FEdgeSharp *) py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSharp *) py_fe)->fes;
+ } else if (typeid(fe) == typeid(FEdgeSmooth)) {
+ py_fe = FEdgeSmooth_Type.tp_new( &FEdgeSmooth_Type, 0, 0 );
+ ((BPy_FEdgeSmooth *) py_fe)->fes = new FEdgeSmooth( dynamic_cast<FEdgeSmooth&>(fe) );
+ ((BPy_FEdgeSmooth *) py_fe)->py_fe.fe = ((BPy_FEdgeSmooth *) py_fe)->fes;
+ ((BPy_FEdgeSmooth *) py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSmooth *) py_fe)->fes;
+ } else {
+ py_fe = FEdge_Type.tp_new( &FEdge_Type, 0, 0 );
+ ((BPy_FEdge *) py_fe)->fe = new FEdge( fe );
+ ((BPy_FEdge *) py_fe)->py_if1D.if1D = ((BPy_FEdge *) py_fe)->fe;
+ }
return py_fe;
}
@@ -162,6 +179,24 @@
return py_vv;
}
+PyObject * BPy_NonTVertex_from_NonTVertex_ptr( NonTVertex *ntv ) {
+ PyObject *py_ntv = NonTVertex_Type.tp_new( &NonTVertex_Type, 0, 0 );
+ ((BPy_NonTVertex *) py_ntv)->ntv = ntv;
+ ((BPy_NonTVertex *) py_ntv)->py_vv.vv = ((BPy_NonTVertex *) py_ntv)->ntv;
+ ((BPy_NonTVertex *) py_ntv)->py_vv.py_if0D.if0D = ((BPy_NonTVertex *) py_ntv)->ntv;
+
+ return py_ntv;
+}
+
+PyObject * BPy_TVertex_from_TVertex_ptr( TVertex *tv ) {
+ PyObject *py_tv = TVertex_Type.tp_new( &TVertex_Type, 0, 0 );
+ ((BPy_TVertex *) py_tv)->tv = tv;
+ ((BPy_TVertex *) py_tv)->py_vv.vv = ((BPy_TVertex *) py_tv)->tv;
+ ((BPy_TVertex *) py_tv)->py_vv.py_if0D.if0D = ((BPy_TVertex *) py_tv)->tv;
+
+ return py_tv;
+}
+
PyObject * BPy_BBox_from_BBox( BBox< Vec3r > &bb ) {
PyObject *py_bb = BBox_Type.tp_new( &BBox_Type, 0, 0 );
((BPy_BBox *) py_bb)->bb = new BBox< Vec3r >( bb );
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h 2009-07-19 23:03:26 UTC (rev 21709)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h 2009-07-19 23:17:30 UTC (rev 21710)
@@ -90,6 +90,8 @@
PyObject * BPy_StrokeVertex_from_StrokeVertex_ptr( StrokeVertex *sv );
PyObject * BPy_SVertex_from_SVertex_ptr( SVertex *sv );
PyObject * BPy_ViewVertex_from_ViewVertex_ptr( ViewVertex *vv );
+PyObject * BPy_NonTVertex_from_NonTVertex_ptr( NonTVertex *ntv );
+PyObject * BPy_TVertex_from_TVertex_ptr( TVertex *tv );
PyObject * BPy_ViewEdge_from_ViewEdge_ptr( ViewEdge *ve );
PyObject * BPy_Chain_from_Chain_ptr( Chain* c );
PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs );
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp 2009-07-19 23:03:26 UTC (rev 21709)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp 2009-07-19 23:17:30 UTC (rev 21710)
@@ -59,8 +59,21 @@
// BinaryPredicate1D: __call__
int Director_BPy_BinaryPredicate1D___call__( PyObject *obj, Interface1D& i1, Interface1D& i2) {
- PyObject *arg1 = BPy_Interface1D_from_Interface1D(i1);
- PyObject *arg2 = BPy_Interface1D_from_Interface1D(i2);
+ PyObject *arg1, *arg2;
+ if (typeid(i1) == typeid(ViewEdge)) {
+ arg1 = BPy_ViewEdge_from_ViewEdge_ptr(dynamic_cast<ViewEdge*>(&i1));
+ arg2 = BPy_ViewEdge_from_ViewEdge_ptr(dynamic_cast<ViewEdge*>(&i2));
+ } else if (typeid(i1) == typeid(Chain)) {
+ arg1 = BPy_Chain_from_Chain_ptr(dynamic_cast<Chain*>(&i1));
+ arg2 = BPy_Chain_from_Chain_ptr(dynamic_cast<Chain*>(&i2));
+ } else if (typeid(i1) == typeid(Stroke)) {
+ arg1 = BPy_Stroke_from_Stroke_ptr(dynamic_cast<Stroke*>(&i1));
+ arg2 = BPy_Stroke_from_Stroke_ptr(dynamic_cast<Stroke*>(&i2));
+ } else {
+ cerr << "Warning: cast to " + i1.getExactTypeName() + " not implemented" << endl;
+ arg1 = BPy_Interface1D_from_Interface1D(i1);
+ arg2 = BPy_Interface1D_from_Interface1D(i2);
+ }
PyObject *result = PyObject_CallMethod( obj, "__call__", "OO", arg1, arg2 );
Py_DECREF(arg1);
Py_DECREF(arg2);
@@ -87,7 +100,17 @@
// UnaryPredicate1D: __call__
int Director_BPy_UnaryPredicate1D___call__( PyObject *obj, Interface1D& if1D) {
- PyObject *arg = BPy_Interface1D_from_Interface1D(if1D);
+ PyObject *arg;
+ if (typeid(if1D) == typeid(ViewEdge)) {
+ arg = BPy_ViewEdge_from_ViewEdge_ptr(dynamic_cast<ViewEdge*>(&if1D));
+ } else if (typeid(if1D) == typeid(Chain)) {
+ arg = BPy_Chain_from_Chain_ptr(dynamic_cast<Chain*>(&if1D));
+ } else if (typeid(if1D) == typeid(Stroke)) {
+ arg = BPy_Stroke_from_Stroke_ptr(dynamic_cast<Stroke*>(&if1D));
+ } else {
+ cerr << "Warning: cast to " + if1D.getExactTypeName() + " not implemented" << endl;
+ arg = BPy_Interface1D_from_Interface1D(if1D);
+ }
PyObject *result = PyObject_CallMethod( obj, "__call__", "O", arg );
Py_DECREF(arg);
if (!result)
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp 2009-07-19 23:03:26 UTC (rev 21709)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp 2009-07-19 23:17:30 UTC (rev 21710)
@@ -181,7 +181,13 @@
}
PyObject * SVertex_viewvertex( BPy_SVertex *self ) {
- return BPy_ViewVertex_from_ViewVertex_ptr( self->sv->viewvertex() );
+ ViewVertex *vv = self->sv->viewvertex();
+ if (!vv)
+ Py_RETURN_NONE;
+ if (typeid(*vv) == typeid(NonTVertex))
+ return BPy_NonTVertex_from_NonTVertex_ptr( dynamic_cast<NonTVertex*>(vv) );
+ else
+ return BPy_TVertex_from_TVertex_ptr( dynamic_cast<TVertex*>(vv) );
}
PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) {
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp 2009-07-19 23:03:26 UTC (rev 21709)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp 2009-07-19 23:17:30 UTC (rev 21710)
@@ -135,9 +135,25 @@
return PyFloat_FromDouble( self->if0D_it->u() );
}
-PyObject * Interface0DIterator_getObject(BPy_Interface0DIterator *self) {
- return BPy_Interface0D_from_Interface0D( self->if0D_it->operator*() );
-}
+PyObject * Interface0DIterator_getObject(BPy_Interface0DIterator *self) {
+ Interface0D &if0D = self->if0D_it->operator*();
+ if (typeid(if0D) == typeid(CurvePoint)) {
+ return BPy_CurvePoint_from_CurvePoint_ptr(dynamic_cast<CurvePoint*>(&if0D));
+ } else if (typeid(if0D) == typeid(StrokeVertex)) {
+ return BPy_StrokeVertex_from_StrokeVertex_ptr(dynamic_cast<StrokeVertex*>(&if0D));
+ } else if (typeid(if0D) == typeid(SVertex)) {
+ return BPy_SVertex_from_SVertex_ptr(dynamic_cast<SVertex*>(&if0D));
+ } else if (typeid(if0D) == typeid(ViewVertex)) {
+ return BPy_ViewVertex_from_ViewVertex_ptr(dynamic_cast<ViewVertex*>(&if0D));
+ } else if (typeid(if0D) == typeid(NonTVertex)) {
+ return BPy_NonTVertex_from_NonTVertex_ptr(dynamic_cast<NonTVertex*>(&if0D));
+ } else if (typeid(if0D) == typeid(TVertex)) {
+ return BPy_TVertex_from_TVertex_ptr(dynamic_cast<TVertex*>(&if0D));
+ } else {
+ cerr << "Warning: cast to " << if0D.getExactTypeName() << " not implemented" << endl;
+ return BPy_Interface0D_from_Interface0D(if0D);
+ }
+}
///////////////////////////////////////////////////////////////////////////////////////////
More information about the Bf-blender-cvs
mailing list