diff options
author | Maxime Curioni <maxime.curioni@gmail.com> | 2008-07-29 09:45:16 +0400 |
---|---|---|
committer | Maxime Curioni <maxime.curioni@gmail.com> | 2008-07-29 09:45:16 +0400 |
commit | db6388e0f2b1e03ff280615fb96b93c565c9b22a (patch) | |
tree | 3a538b4464fb6b9d6bef5df129027970f37f08c8 /source/blender/freestyle/intern/python/BPy_Convert.cpp | |
parent | e4677c409dcad94e96b2ae765422f91e0b0dd9fd (diff) |
soc-2008-mxcurioni: finished porting the Freestyle API. All of the original classes, except EdgeModifier and TimestampModifier (which aren't even ported via SWIG), are available under the Blender.Freestyle module. Testing of the porting will now begin to make sure the SWIG-less system works as the original.
Quite a few modifications were made to finish the API:
- Freestyle's SConscript was modified to catch all files within the intern/python directory, allowing integration of future shaders implemented in C++.
- the Operators class was ported, with a special care of making its methods static (using the METH_STATIC flag in the tp_methods method definitions)
- all of the type-checking functions [ BPy_[class name]_Check(obj) ] were changed to allow subclasses to be seen as that type too: instead on looking at the ob_type value, the PyObject_IsInstance function is used.
- all of the iterators can now retrieve the object pointed to by the operator, using the getObject() method. A directedViewEdge pair is returned as a list of the two elements in the pair.
- all of the style modules were copied to a style_modules_blender/ folder and were modified to use Freestyle as a Blender's submodule. IntegrationType and MediumType was also integrated (for example, changing MEAN to IntegrationType.MEAN).
Testing now begins. If everything works correctly, I'll move on to lib3ds removal right away.
Diffstat (limited to 'source/blender/freestyle/intern/python/BPy_Convert.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/BPy_Convert.cpp | 130 |
1 files changed, 108 insertions, 22 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index 042d4b7bef0..b541babd752 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -5,20 +5,29 @@ #include "BPy_Id.h" #include "BPy_IntegrationType.h" #include "BPy_Interface0D.h" +#include "Interface0D/BPy_CurvePoint.cpp" #include "Interface0D/CurvePoint/BPy_StrokeVertex.h" #include "Interface0D/BPy_SVertex.h" #include "Interface0D/BPy_ViewVertex.h" #include "Interface1D/BPy_FEdge.h" #include "Interface1D/BPy_ViewEdge.h" -#include "Iterator/BPy_Interface0DIterator.h" -#include "Iterator/BPy_orientedViewEdgeIterator.h" -#include "Iterator/BPy_StrokeVertexIterator.h" #include "BPy_Nature.h" #include "BPy_MediumType.h" #include "BPy_SShape.h" #include "BPy_StrokeAttribute.h" #include "BPy_ViewShape.h" +#include "Iterator/BPy_AdjacencyIterator.h" +#include "Iterator/BPy_ChainPredicateIterator.h" +#include "Iterator/BPy_ChainSilhouetteIterator.h" +#include "Iterator/BPy_ChainingIterator.h" +#include "Iterator/BPy_CurvePointIterator.h" +#include "Iterator/BPy_Interface0DIterator.h" +#include "Iterator/BPy_SVertexIterator.h" +#include "Iterator/BPy_StrokeVertexIterator.h" +#include "Iterator/BPy_ViewEdgeIterator.h" +#include "Iterator/BPy_orientedViewEdgeIterator.h" + #ifdef __cplusplus extern "C" { #endif @@ -161,11 +170,62 @@ PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs ) { return py_vs; } -PyObject * BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ViewVertexInternal::orientedViewEdgeIterator& ove_it ) { - PyObject *py_ove_it = orientedViewEdgeIterator_Type.tp_new( &orientedViewEdgeIterator_Type, 0, 0 ); - ((BPy_orientedViewEdgeIterator *) py_ove_it)->ove_it = new ViewVertexInternal::orientedViewEdgeIterator( ove_it ); +PyObject * BPy_FrsMaterial_from_Material( Material& m ){ + PyObject *py_m = FrsMaterial_Type.tp_new( &FrsMaterial_Type, 0, 0 ); + ((BPy_FrsMaterial*) py_m)->m = new Material( m ); - return py_ove_it; + return py_m; +} + +PyObject * BPy_IntegrationType_from_IntegrationType( int i ) { + PyObject *py_it = IntegrationType_Type.tp_new( &IntegrationType_Type, 0, 0 ); + + PyObject *args = PyTuple_New(1); + PyTuple_SetItem( args, 0, PyInt_FromLong(i) ); + IntegrationType_Type.tp_init( py_it, args, 0 ); + Py_DECREF(args); + + return py_it; +} + +PyObject * BPy_CurvePoint_from_CurvePoint( CurvePoint& cp ) { + PyObject *py_cp = CurvePoint_Type.tp_new( &CurvePoint_Type, 0, 0 ); + ((BPy_CurvePoint*) py_cp)->cp = new CurvePoint( cp ); + + return py_cp; +} + +PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewEdge& dve ) { + PyObject *py_dve = PyList_New(2); + + PyList_SetItem( py_dve, 0, BPy_ViewEdge_from_ViewEdge(*(dve.first)) ); + PyList_SetItem( py_dve, 1, PyBool_from_bool(dve.second) ); + + return py_dve; +} + + +//============================== +// Constants +//============================== + +IntegrationType IntegrationType_from_BPy_IntegrationType( PyObject* obj ) { + return static_cast<IntegrationType>( PyInt_AsLong(obj) ); +} + +Stroke::MediumType MediumType_from_BPy_MediumType( PyObject* obj ) { + return static_cast<Stroke::MediumType>( PyInt_AsLong(obj) ); +} + +//============================== +// Iterators +//============================== + +PyObject * BPy_AdjacencyIterator_from_AdjacencyIterator( AdjacencyIterator& a_it ) { + PyObject *py_a_it = AdjacencyIterator_Type.tp_new( &AdjacencyIterator_Type, 0, 0 ); + ((BPy_AdjacencyIterator *) py_a_it)->a_it = new AdjacencyIterator( a_it ); + + return py_a_it; } PyObject * BPy_Interface0DIterator_from_Interface0DIterator( Interface0DIterator& if0D_it ) { @@ -175,6 +235,13 @@ PyObject * BPy_Interface0DIterator_from_Interface0DIterator( Interface0DIterator return py_if0D_it; } +PyObject * BPy_CurvePointIterator_from_CurvePointIterator( CurveInternal::CurvePointIterator& cp_it ) { + PyObject *py_cp_it = CurvePointIterator_Type.tp_new( &CurvePointIterator_Type, 0, 0 ); + ((BPy_CurvePointIterator*) py_cp_it)->cp_it = new CurveInternal::CurvePointIterator( cp_it ); + + return py_cp_it; +} + PyObject * BPy_StrokeVertexIterator_from_StrokeVertexIterator( StrokeInternal::StrokeVertexIterator& sv_it) { PyObject *py_sv_it = StrokeVertexIterator_Type.tp_new( &StrokeVertexIterator_Type, 0, 0 ); ((BPy_StrokeVertexIterator*) py_sv_it)->sv_it = new StrokeInternal::StrokeVertexIterator( sv_it ); @@ -182,33 +249,52 @@ PyObject * BPy_StrokeVertexIterator_from_StrokeVertexIterator( StrokeInternal::S return py_sv_it; } -PyObject * BPy_FrsMaterial_from_Material( Material& m ){ - PyObject *py_m = FrsMaterial_Type.tp_new( &FrsMaterial_Type, 0, 0 ); - ((BPy_FrsMaterial*) py_m)->m = new Material( m ); +PyObject * BPy_SVertexIterator_from_SVertexIterator( ViewEdgeInternal::SVertexIterator& sv_it ) { + PyObject *py_sv_it = SVertexIterator_Type.tp_new( &SVertexIterator_Type, 0, 0 ); + ((BPy_SVertexIterator*) py_sv_it)->sv_it = new ViewEdgeInternal::SVertexIterator( sv_it ); - return py_m; + return py_sv_it; } -PyObject * BPy_IntegrationType_from_IntegrationType( int i ) { - PyObject *py_it = IntegrationType_Type.tp_new( &IntegrationType_Type, 0, 0 ); +PyObject * BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ViewVertexInternal::orientedViewEdgeIterator& ove_it ) { + PyObject *py_ove_it = orientedViewEdgeIterator_Type.tp_new( &orientedViewEdgeIterator_Type, 0, 0 ); + ((BPy_orientedViewEdgeIterator *) py_ove_it)->ove_it = new ViewVertexInternal::orientedViewEdgeIterator( ove_it ); - PyObject *args = PyTuple_New(1); - PyTuple_SetItem( args, 0, PyInt_FromLong(i) ); - IntegrationType_Type.tp_init( py_it, args, 0 ); - Py_DECREF(args); + return py_ove_it; +} - return py_it; +PyObject * BPy_ViewEdgeIterator_from_ViewEdgeIterator( ViewEdgeInternal::ViewEdgeIterator& ve_it ) { + PyObject *py_ve_it = ViewEdgeIterator_Type.tp_new( &ViewEdgeIterator_Type, 0, 0 ); + ((BPy_ViewEdgeIterator*) py_ve_it)->ve_it = new ViewEdgeInternal::ViewEdgeIterator( ve_it ); + + return py_ve_it; } -IntegrationType IntegrationType_from_BPy_IntegrationType( PyObject* obj ) { - return static_cast<IntegrationType>( PyInt_AsLong(obj) ); +PyObject * BPy_ChainingIterator_from_ChainingIterator( ChainingIterator& c_it ) { + PyObject *py_c_it = ChainingIterator_Type.tp_new( &ChainingIterator_Type, 0, 0 ); + ((BPy_ChainingIterator*) py_c_it)->c_it = new ChainingIterator( c_it ); + + return py_c_it; } -Stroke::MediumType MediumType_from_BPy_MediumType( PyObject* obj ) { - return static_cast<Stroke::MediumType>( PyInt_AsLong(obj) ); +PyObject * BPy_ChainPredicateIterator_from_ChainPredicateIterator( ChainPredicateIterator& cp_it ) { + PyObject *py_cp_it = ChainPredicateIterator_Type.tp_new( &ChainPredicateIterator_Type, 0, 0 ); + ((BPy_ChainPredicateIterator*) py_cp_it)->cp_it = new ChainPredicateIterator( cp_it ); + + return py_cp_it; +} + +PyObject * BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator( ChainSilhouetteIterator& cs_it ) { + PyObject *py_cs_it = ChainSilhouetteIterator_Type.tp_new( &ChainSilhouetteIterator_Type, 0, 0 ); + ((BPy_ChainSilhouetteIterator*) py_cs_it)->cs_it = new ChainSilhouetteIterator( cs_it ); + + return py_cs_it; } + + + /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus |