- patch submitted by guitargeek

-includes:
*Text3d accessors - ablity to manipulate FONT objects through python
*update to Object.link - calls text_to_curve upon ob_font link for drawing
*update to constant.h - constant type checking define
*update to curve.c - clamp values on getters/setters
*clean up of Text3d module
This commit is contained in:
Joseph Gilbert 2005-03-19 03:24:00 +00:00
parent f61c5b1eec
commit cbbe236f92
6 changed files with 653 additions and 124 deletions

@ -82,20 +82,20 @@ static PyObject *Curve_getPathLen( BPy_Curve * self );
static PyObject *Curve_setPathLen( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getTotcol( BPy_Curve * self );
static PyObject *Curve_setTotcol( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getMode( BPy_Curve * self );
static PyObject *Curve_setMode( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getBevresol( BPy_Curve * self );
static PyObject *Curve_setBevresol( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getResolu( BPy_Curve * self );
static PyObject *Curve_setResolu( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getResolv( BPy_Curve * self );
static PyObject *Curve_setResolv( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getWidth( BPy_Curve * self );
static PyObject *Curve_setWidth( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getExt1( BPy_Curve * self );
static PyObject *Curve_setExt1( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getExt2( BPy_Curve * self );
static PyObject *Curve_setExt2( BPy_Curve * self, PyObject * args );
PyObject *Curve_getMode( BPy_Curve * self );
PyObject *Curve_setMode( BPy_Curve * self, PyObject * args );
PyObject *Curve_getBevresol( BPy_Curve * self );
PyObject *Curve_setBevresol( BPy_Curve * self, PyObject * args );
PyObject *Curve_getResolu( BPy_Curve * self );
PyObject *Curve_setResolu( BPy_Curve * self, PyObject * args );
PyObject *Curve_getResolv( BPy_Curve * self );
PyObject *Curve_setResolv( BPy_Curve * self, PyObject * args );
PyObject *Curve_getWidth( BPy_Curve * self );
PyObject *Curve_setWidth( BPy_Curve * self, PyObject * args );
PyObject *Curve_getExt1( BPy_Curve * self );
PyObject *Curve_setExt1( BPy_Curve * self, PyObject * args );
PyObject *Curve_getExt2( BPy_Curve * self );
PyObject *Curve_setExt2( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getControlPoint( BPy_Curve * self, PyObject * args );
static PyObject *Curve_setControlPoint( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getLoc( BPy_Curve * self );
@ -520,7 +520,7 @@ static PyObject *Curve_setTotcol( BPy_Curve * self, PyObject * args )
}
static PyObject *Curve_getMode( BPy_Curve * self )
PyObject *Curve_getMode( BPy_Curve * self )
{
PyObject *attr = PyInt_FromLong( ( long ) self->curve->flag );
@ -532,7 +532,7 @@ static PyObject *Curve_getMode( BPy_Curve * self )
}
static PyObject *Curve_setMode( BPy_Curve * self, PyObject * args )
PyObject *Curve_setMode( BPy_Curve * self, PyObject * args )
{
if( !PyArg_ParseTuple( args, "i", &( self->curve->flag ) ) )
@ -544,7 +544,7 @@ static PyObject *Curve_setMode( BPy_Curve * self, PyObject * args )
}
static PyObject *Curve_getBevresol( BPy_Curve * self )
PyObject *Curve_getBevresol( BPy_Curve * self )
{
PyObject *attr = PyInt_FromLong( ( long ) self->curve->bevresol );
@ -556,19 +556,24 @@ static PyObject *Curve_getBevresol( BPy_Curve * self )
}
static PyObject *Curve_setBevresol( BPy_Curve * self, PyObject * args )
PyObject *Curve_setBevresol( BPy_Curve * self, PyObject * args )
{
short value;
if( !PyArg_ParseTuple( args, "i", &( self->curve->bevresol ) ) )
if( !PyArg_ParseTuple( args, "h", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected int argument" ) );
"expected integer argument" ) );
Py_INCREF( Py_None );
return Py_None;
if(value > 10 || value < 0)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 10 and 0" ) );
self->curve->bevresol = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Curve_getResolu( BPy_Curve * self )
PyObject *Curve_getResolu( BPy_Curve * self )
{
PyObject *attr = PyInt_FromLong( ( long ) self->curve->resolu );
@ -580,20 +585,25 @@ static PyObject *Curve_getResolu( BPy_Curve * self )
}
static PyObject *Curve_setResolu( BPy_Curve * self, PyObject * args )
PyObject *Curve_setResolu( BPy_Curve * self, PyObject * args )
{
short value;
if( !PyArg_ParseTuple( args, "i", &( self->curve->resolu ) ) )
if( !PyArg_ParseTuple( args, "h", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected int argument" ) );
"expected integer argument" ) );
Py_INCREF( Py_None );
return Py_None;
if(value > 128 || value < 1)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 128 and 1" ) );
self->curve->resolu = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Curve_getResolv( BPy_Curve * self )
PyObject *Curve_getResolv( BPy_Curve * self )
{
PyObject *attr = PyInt_FromLong( ( long ) self->curve->resolv );
@ -605,20 +615,25 @@ static PyObject *Curve_getResolv( BPy_Curve * self )
}
static PyObject *Curve_setResolv( BPy_Curve * self, PyObject * args )
PyObject *Curve_setResolv( BPy_Curve * self, PyObject * args )
{
short value;
if( !PyArg_ParseTuple( args, "i", &( self->curve->resolv ) ) )
if( !PyArg_ParseTuple( args, "h", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected int argument" ) );
"expected integer argument" ) );
Py_INCREF( Py_None );
return Py_None;
if(value > 128 || value < 1)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 128 and 1" ) );
self->curve->resolv = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Curve_getWidth( BPy_Curve * self )
PyObject *Curve_getWidth( BPy_Curve * self )
{
PyObject *attr = PyFloat_FromDouble( ( double ) self->curve->width );
@ -630,19 +645,24 @@ static PyObject *Curve_getWidth( BPy_Curve * self )
}
static PyObject *Curve_setWidth( BPy_Curve * self, PyObject * args )
PyObject *Curve_setWidth( BPy_Curve * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &( self->curve->width ) ) )
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
"expected float argument" ) );
Py_INCREF( Py_None );
return Py_None;
if(value > 2.0f || value < 0.0f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 2.0 and 0.0" ) );
self->curve->width = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Curve_getExt1( BPy_Curve * self )
PyObject *Curve_getExt1( BPy_Curve * self )
{
PyObject *attr = PyFloat_FromDouble( ( double ) self->curve->ext1 );
@ -654,20 +674,25 @@ static PyObject *Curve_getExt1( BPy_Curve * self )
}
static PyObject *Curve_setExt1( BPy_Curve * self, PyObject * args )
PyObject *Curve_setExt1( BPy_Curve * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &( self->curve->ext1 ) ) )
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
"expected float argument" ) );
Py_INCREF( Py_None );
return Py_None;
if(value > 5.0f || value < 0.0f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 5.0 and 0.0" ) );
self->curve->ext1 = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Curve_getExt2( BPy_Curve * self )
PyObject *Curve_getExt2( BPy_Curve * self )
{
PyObject *attr = PyFloat_FromDouble( ( double ) self->curve->ext2 );
@ -679,15 +704,20 @@ static PyObject *Curve_getExt2( BPy_Curve * self )
}
static PyObject *Curve_setExt2( BPy_Curve * self, PyObject * args )
PyObject *Curve_setExt2( BPy_Curve * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &( self->curve->ext2 ) ) )
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
"expected float argument" ) );
Py_INCREF( Py_None );
return Py_None;
if(value > 2.0f || value < 0.0f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 2.0 and 0.0" ) );
self->curve->ext2 = value;
return EXPP_incr_ret( Py_None );
}

@ -57,4 +57,21 @@ PyObject *Curve_CreatePyObject( struct Curve * curve );
int Curve_CheckPyObject( PyObject * py_obj );
struct Curve *Curve_FromPyObject( PyObject * py_obj );
PyObject *Curve_getName( BPy_Curve * self );
PyObject *Curve_setName( BPy_Curve * self, PyObject * args );
PyObject *Curve_getMode( BPy_Curve * self );
PyObject *Curve_setMode( BPy_Curve * self, PyObject * args );
PyObject *Curve_getBevresol( BPy_Curve * self );
PyObject *Curve_setBevresol( BPy_Curve * self, PyObject * args );
PyObject *Curve_getResolu( BPy_Curve * self );
PyObject *Curve_setResolu( BPy_Curve * self, PyObject * args );
PyObject *Curve_getResolv( BPy_Curve * self );
PyObject *Curve_setResolv( BPy_Curve * self, PyObject * args );
PyObject *Curve_getExt1( BPy_Curve * self );
PyObject *Curve_setExt1( BPy_Curve * self, PyObject * args );
PyObject *Curve_getExt2( BPy_Curve * self );
PyObject *Curve_setExt2( BPy_Curve * self, PyObject * args );
PyObject *Curve_getWidth( BPy_Curve * self );
PyObject *Curve_setWidth( BPy_Curve * self, PyObject * args );
#endif /* EXPP_CURVE_H */

@ -1305,6 +1305,10 @@ static PyObject *Object_link( BPy_Object * self, PyObject * args )
EXPP_synchronizeMaterialLists( self->object );
}
//creates the curve for the text object
if (self->object->type == OB_FONT)
text_to_curve(self->object, 0);
id_us_plus( id );
if( oldid ) {
if( oldid->us > 0 ) {

@ -26,6 +26,7 @@
* This is a new part of Blender.
*
* Contributor(s): Joilnen Leite
* Johnny Matthews
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@ -33,63 +34,94 @@
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "DNA_vfont_types.h"
#include "MEM_guardedalloc.h"
#include "BKE_object.h"
#include "BDR_editobject.h"
#include "BKE_displist.h"
#include "MEM_guardedalloc.h"
#include "mydevice.h"
#include "blendef.h"
#include "Text3d.h"
#include "Curve.h"
#include "constant.h"
#include "Types.h"
#include "mydevice.h"
/*
fixme hackage warning:
this decl is copied from source/blender/src/editfont.c
it belongs in a .h file!
*/
VFont *get_builtin_font(void);
extern PyObject *Curve_getName( BPy_Text3d * self );
extern PyObject *Curve_setName( BPy_Text3d * self, PyObject * args );
//no prototypes declared in header files - external linkage outside of python
extern VFont *get_builtin_font(void);
extern void freedisplist(struct ListBase *lb);
/*****************************************************************************/
/* Python API function prototypes for the Effect module. */
/* Python API function prototypes for the Text3D module. */
/*****************************************************************************/
static PyObject *M_Text3d_New( PyObject * self, PyObject * args );
static PyObject *M_Text3d_Get( PyObject * self, PyObject * args );
/*****************************************************************************/
/* Python BPy_Text3d methods declarations: */
/* Python callback function prototypes for the Text3D module.
/*****************************************************************************/
/*PyObject *Text3d_getType(BPy_Text3d *self);*/
static PyObject *return_ModuleConstant( char *constant_name);
static PyObject *generate_ModuleIntConstant(char *name, int value);
/*****************************************************************************/
/* Python method structure definition for Blender.Text3d module: */
/*****************************************************************************/
struct PyMethodDef M_Text3d_methods[] = {
{"New", ( PyCFunction ) M_Text3d_New, METH_VARARGS, NULL},
{"Get", ( PyCFunction ) M_Text3d_Get, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python Text3d_Type callback function prototypes: */
/*****************************************************************************/
void Text3dDeAlloc( BPy_Text3d * msh );
/* int Text3dPrint (BPy_Text3d *msh, FILE *fp, int flags); */
int Text3dSetAttr( BPy_Text3d * msh, char *name, PyObject * v );
PyObject *Text3dGetAttr( BPy_Text3d * msh, char *name );
PyObject *Text3dRepr( BPy_Text3d * msh );
PyObject *Text3dCreatePyObject( Text3d *text3d );
int Text3dCheckPyObject( PyObject * py_obj );
struct Text3d *Text3dFromPyObject( PyObject * py_obj );
static void Text3dDeAlloc( BPy_Text3d * self );
static int Text3dSetAttr( BPy_Text3d * self, char *name, PyObject * value );
static PyObject *Text3dGetAttr( BPy_Text3d * self, char *name );
static PyObject *Text3dRepr( BPy_Text3d * self );
/*****************************************************************************/
/* Python BPy_Text3d methods declarations: */
/*****************************************************************************/
/*PyObject *Text3d_getType(BPy_Text3d *self);*/
static PyObject *Text3d_getName( BPy_Text3d * self );
static PyObject *Text3d_setName( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_setText( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getText( BPy_Text3d * self );
static PyObject *Text3d_getDrawMode( BPy_Text3d * self );
static PyObject *Text3d_setDrawMode( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getUVorco( BPy_Text3d * self );
static PyObject *Text3d_setUVorco( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getBevelAmount( BPy_Text3d * self );
static PyObject *Text3d_setBevelAmount( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getDefaultResolution( BPy_Text3d * self );
static PyObject *Text3d_setDefaultResolution( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getWidth( BPy_Text3d * self );
static PyObject *Text3d_setWidth( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getExtrudeDepth( BPy_Text3d * self );
static PyObject *Text3d_setExtrudeDepth( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getExtrudeBevelDepth( BPy_Text3d * self );
static PyObject *Text3d_setExtrudeBevelDepth( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getShear( BPy_Text3d * self );
static PyObject *Text3d_setShear( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getSize( BPy_Text3d * self );
static PyObject *Text3d_setSize( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getLineSeparation( BPy_Text3d * self );
static PyObject *Text3d_setLineSeparation( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getSpacing( BPy_Text3d * self );
static PyObject *Text3d_setSpacing( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getXoffset( BPy_Text3d * self );
static PyObject *Text3d_setXoffset( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getYoffset( BPy_Text3d * self );
static PyObject *Text3d_setYoffset( BPy_Text3d * self, PyObject * args );
static PyObject *Text3d_getAlignment( BPy_Text3d * self );
static PyObject *Text3d_setAlignment( BPy_Text3d * self, PyObject * args );
/*****************************************************************************/
/* Python BPy_Text3d methods table: */
/*****************************************************************************/
static char text2text3_doc[] = "(str) - set Text3d string";
char M_Text3D_doc[] = "The Blender Text3D module\n\n\
This module provides control over Text Curve objects in Blender.\n";
static PyMethodDef BPy_Text3d_methods[] = {
{"getName", ( PyCFunction ) Text3d_getName,
@ -99,8 +131,64 @@ static PyMethodDef BPy_Text3d_methods[] = {
{"setText", ( PyCFunction ) Text3d_setText,
METH_VARARGS, "() - Sets Text3d Data"},
{"getText", ( PyCFunction ) Text3d_getText,
METH_NOARGS, "() - Gets Text3d Data"},
{NULL, NULL, 0, NULL}
METH_NOARGS, "() - Gets Text3d Data"},
{"getDrawMode", ( PyCFunction ) Text3d_getDrawMode,
METH_NOARGS, "() - Return the font drawing mode"},
{"setDrawMode", ( PyCFunction ) Text3d_setDrawMode,
METH_VARARGS, "(int) - Set the font drawing mode"},
{"getUVorco", ( PyCFunction ) Text3d_getUVorco,
METH_NOARGS, "() - Return wether UV coords are used for Texture mapping"},
{"setUVorco", ( PyCFunction ) Text3d_setUVorco,
METH_VARARGS, "() - Set the font to use UV coords for Texture mapping"},
{"getBevelAmount", ( PyCFunction ) Text3d_getBevelAmount,
METH_NOARGS, "() - Return bevel resolution"},
{"setBevelAmount", ( PyCFunction ) Text3d_setBevelAmount,
METH_VARARGS, "() - Sets bevel resolution"},
{"getDefaultResolution", ( PyCFunction ) Text3d_getDefaultResolution,
METH_NOARGS, "() - Return Default text resolution"},
{"setDefaultResolution", ( PyCFunction ) Text3d_setDefaultResolution,
METH_VARARGS, "() - Sets Default text Resolution"},
{"getWidth", ( PyCFunction ) Text3d_getWidth,
METH_NOARGS, "() - Return curve width"},
{"setWidth", ( PyCFunction ) Text3d_setWidth,
METH_VARARGS, "(int) - Sets curve width"},
{"getExtrudeDepth", ( PyCFunction ) Text3d_getExtrudeDepth,
METH_NOARGS, "() - Gets Text3d ExtrudeDepth"},
{"setExtrudeDepth", ( PyCFunction ) Text3d_setExtrudeDepth,
METH_VARARGS, "() - Sets Text3d ExtrudeDepth"},
{"getExtrudeBevelDepth", ( PyCFunction ) Text3d_getExtrudeBevelDepth,
METH_NOARGS, "() - Gets Text3d ExtrudeBevelDepth"},
{"setExtrudeBevelDepth", ( PyCFunction ) Text3d_setExtrudeBevelDepth,
METH_VARARGS, "() - Sets Text3d ExtrudeBevelDepth"},
{"getShear", ( PyCFunction ) Text3d_getShear,
METH_NOARGS, "() - Gets Text3d Shear Data"},
{"setShear", ( PyCFunction ) Text3d_setShear,
METH_VARARGS, "() - Sets Text3d Shear Data"},
{"getSize", ( PyCFunction ) Text3d_getSize,
METH_NOARGS, "() - Gets Text3d Size Data"},
{"setSize", ( PyCFunction ) Text3d_setSize,
METH_VARARGS, "() - Sets Text3d Size Data"},
{"getLineSeparation", ( PyCFunction ) Text3d_getLineSeparation,
METH_NOARGS, "() - Gets Text3d LineSeparation Data"},
{"setLineSeparation", ( PyCFunction ) Text3d_setLineSeparation,
METH_VARARGS, "() - Sets Text3d LineSeparation Data"},
{"getSpacing", ( PyCFunction ) Text3d_getSpacing,
METH_NOARGS, "() - Gets Text3d letter spacing"},
{"setSpacing", ( PyCFunction ) Text3d_setSpacing,
METH_VARARGS, "() - Sets Text3d letter spacing"},
{"getXoffset", ( PyCFunction ) Text3d_getXoffset,
METH_NOARGS, "() - Gets Text3d Xoffset Data"},
{"setXoffset", ( PyCFunction ) Text3d_setXoffset,
METH_VARARGS, "() - Sets Text3d Xoffset Data"},
{"getYoffset", ( PyCFunction ) Text3d_getYoffset,
METH_NOARGS, "() - Gets Text3d Yoffset Data"},
{"setYoffset", ( PyCFunction ) Text3d_setYoffset,
METH_VARARGS, "() - Sets Text3d Yoffset Data"},
{"getAlignment", ( PyCFunction ) Text3d_getAlignment,
METH_NOARGS, "() - Gets Text3d Alignment Data"},
{"setAlignment", ( PyCFunction ) Text3d_setAlignment,
METH_VARARGS, "() - Sets Text3d Alignment Data"},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
@ -130,27 +218,6 @@ PyTypeObject Text3d_Type = {
0, /* tp_members */
};
/*****************************************************************************/
/* Python method structure definition for Blender.Text3d module: */
/*****************************************************************************/
struct PyMethodDef M_Text3d_methods[] = {
{"New", ( PyCFunction ) M_Text3d_New, METH_VARARGS, NULL},
{"Get", M_Text3d_Get, METH_VARARGS, NULL},
{"get", M_Text3d_Get, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python BPy_Text3d methods declarations: */
/* extern prototypes */
/*****************************************************************************/
/*static PyObject *Text2Text3d( BPy_Text3d * self, PyObject * args );*/ /*unused nor defined*/
extern void freedisplist(struct ListBase *lb);
extern VFont *get_builtin_font(void);
int Text3d_CheckPyObject( PyObject * py_obj );
struct Text3d *Text3d_FromPyObject( PyObject * py_obj );
/*
* Text3d_update( )
* method to update display list for a Curve.
@ -163,7 +230,6 @@ static PyObject *Text3d_update( BPy_Text3d * self )
return Py_None;
}
/*****************************************************************************/
/* Function: M_Text3d_New */
/* Python equivalent: Blender.Text3d.New */
@ -272,17 +338,51 @@ PyObject *M_Text3d_Get( PyObject * self, PyObject * args )
}
}
static PyObject *generate_ModuleIntConstant(char *name, int value)
{
PyObject *constant = M_constant_New();
constant_insert((BPy_constant*)constant,
"value", PyInt_FromLong(value));
constant_insert((BPy_constant*)constant,
"name", PyString_FromString(name));
Py_INCREF(constant);
return constant;
}
PyObject *Text3d_Init( void )
{
//module
PyObject *submodule;
//add module...
Text3d_Type.ob_type = &PyType_Type;
submodule = Py_InitModule3( "Blender.Text3d", M_Text3d_methods,
M_Text3D_doc);
//add constants to module...
PyModule_AddObject( submodule, "LEFT",
generate_ModuleIntConstant("Text3d.LEFT", CU_LEFT));
PyModule_AddObject( submodule, "MIDDLE",
generate_ModuleIntConstant("Text3d.MIDDLE", CU_MIDDLE));
PyModule_AddObject( submodule, "RIGHT",
generate_ModuleIntConstant("Text3d.RIGHT", CU_RIGHT));
PyModule_AddObject( submodule, "FLUSH",
generate_ModuleIntConstant("Text3d.FLUSH", CU_FLUSH));
PyModule_AddObject( submodule, "DRAW3D",
generate_ModuleIntConstant("Text3d.DRAW3D", CU_3D));
PyModule_AddObject( submodule, "DRAWFRONT",
generate_ModuleIntConstant("Text3d.DRAWFRONT", CU_FRONT));
PyModule_AddObject( submodule, "DRAWBACK",
generate_ModuleIntConstant("Text3d.DRAWBACK", CU_BACK));
PyModule_AddObject( submodule, "UVORCO",
generate_ModuleIntConstant("Text3d.UVORCO", CU_UV_ORCO));
submodule = Py_InitModule3( "Blender.Text3d", M_Text3d_methods, 0 );
return ( submodule );
}
void Text3dDeAlloc( BPy_Text3d * self )
static void Text3dDeAlloc( BPy_Text3d * self )
{
PyObject_DEL( self );
}
@ -293,9 +393,7 @@ void Text3dDeAlloc( BPy_Text3d * self )
/* the function that accesses BPy_Text3d "member variables" and */
/* methods. */
/*****************************************************************************/
PyObject *Text3dGetAttr( BPy_Text3d * self, char *name )
static PyObject *Text3dGetAttr( BPy_Text3d * self, char *name )
{
return Py_FindMethod( BPy_Text3d_methods, ( PyObject * ) self, name );
}
@ -305,8 +403,7 @@ PyObject *Text3dGetAttr( BPy_Text3d * self, char *name )
/* Description: This is a callback function for the BPy_Effect type. It */
/* sets Effect Data attributes (member variables). */
/*****************************************************************************/
int Text3dSetAttr( BPy_Text3d * self, char *name, PyObject * value )
static int Text3dSetAttr( BPy_Text3d * self, char *name, PyObject * value )
{
return 0; /* normal exit */
}
@ -317,12 +414,14 @@ int Text3dSetAttr( BPy_Text3d * self, char *name, PyObject * value )
/* builds a meaninful string to represent effcte objects. */
/*****************************************************************************/
PyObject *Text3dRepr( BPy_Text3d * self )
static PyObject *Text3dRepr( BPy_Text3d * self )
{
char *str = "";
return PyString_FromString( str );
}
int Text3d_CheckPyObject( PyObject * py_obj )
{
return ( py_obj->ob_type == &Text3d_Type );
@ -336,14 +435,34 @@ struct Text3d *Text3d_FromPyObject( PyObject * py_obj )
return ((struct Text3d*) blen_obj->curve );
}
static PyObject *return_ModuleConstant( char *constant_name){
PyObject *module = NULL, *dict = NULL, *constant = NULL;;
module = PyImport_AddModule("Blender.Text3d");
if(!module){ //null = error returning module
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"error encountered with returning module constant..." ) );
}
dict = PyModule_GetDict(module); //never fails
constant = PyDict_GetItemString(dict, constant_name);
if(!constant){ //null = key not found
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"error encountered with returning module constant..." ) );
}
return EXPP_incr_ret( constant );
}
static PyObject *Text3d_getName( BPy_Text3d * self )
{
return Curve_getName( self );
return Curve_getName( (BPy_Curve*)self );
}
static PyObject *Text3d_setName( BPy_Text3d * self, PyObject * args )
{
return Curve_setName( self,args );
return Curve_setName( (BPy_Curve*)self,args );
}
static PyObject *Text3d_setText( BPy_Text3d * self, PyObject * args )
@ -370,3 +489,366 @@ static PyObject *Text3d_getText( BPy_Text3d * self )
return Py_None;
}
static PyObject* Text3d_getDrawMode(BPy_Text3d* self)
{
PyObject *tuple = NULL;
int size = 0, pos = 0;
//get the tuple size
if(self->curve->flag & CU_3D)
size++;
if (self->curve->flag & CU_FRONT)
size++;
if (self->curve->flag & CU_BACK)
size++;
//generate tuple
tuple = PyTuple_New(size);
//load tuple
if(self->curve->flag & CU_3D){
PyTuple_SET_ITEM( tuple, pos, return_ModuleConstant("DRAW3D"));
pos++;
}
if (self->curve->flag & CU_FRONT){
PyTuple_SET_ITEM( tuple, pos, return_ModuleConstant("DRAWFRONT"));
pos++;
}
if (self->curve->flag & CU_BACK){
PyTuple_SET_ITEM( tuple, pos, return_ModuleConstant("DRAWBACK"));
pos++;
}
return tuple;
}
static PyObject* Text3d_setDrawMode(BPy_Text3d* self,PyObject* args)
{
PyObject *listObject = NULL;
int size, i;
short temp;
size = PySequence_Length(args);
if ( size == 1 ) {
listObject = PySequence_GetItem(args, 0);
if ( PySequence_Check(listObject) ) {
size = PySequence_Length(listObject);
}else{ //not a sequence but maybe a single constant
Py_INCREF(args);
listObject = args;
}
} else { //a list of objects (non-sequence)
Py_INCREF(args);
listObject = args;
}
if ( size > 3 || size < 1 ) {
//bad number of arguments
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"too many parameters - expects 1 - 3 constants" ) );
}
//clear bits
temp = self->curve->flag; //in case of failure
if(self->curve->flag & CU_3D)
self->curve->flag &= ~CU_3D;
if(self->curve->flag & CU_FRONT)
self->curve->flag &= ~CU_FRONT;
if(self->curve->flag & CU_BACK)
self->curve->flag &= ~CU_BACK;
//parse and set bits
for (i = 0; i < size; i++) {
PyObject *v;
BPy_constant *constant;
int value;
v = PySequence_GetItem(listObject, i);
if (v == NULL) { //unable to return item - null = failure
Py_DECREF(listObject);
self->curve->flag = temp;
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unable to parse list" ) );
}
if( !BPy_Constant_Check(v)){
Py_DECREF(listObject);
Py_DECREF(v);
self->curve->flag = temp;
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"bad argument types - expects module constants" ) );
}
value = PyInt_AS_LONG(PyDict_GetItemString(
((BPy_constant*)v)->dict, "value"));
self->curve->flag |= (short)value;
Py_DECREF(v);
}
Py_DECREF(listObject);
return EXPP_incr_ret( Py_None );
}
static PyObject* Text3d_getUVorco(BPy_Text3d* self)
{
if(self->curve->flag & CU_UV_ORCO)
return EXPP_incr_ret_True();
else
return EXPP_incr_ret_False();
}
static PyObject* Text3d_setUVorco(BPy_Text3d* self,PyObject* args)
{
int flag;
if( !PyArg_ParseTuple( args, "i", &flag ) )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected TRUE or FALSE (1 or 0)" );
if( flag < 0 || flag > 1 )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected TRUE or FALSE (1 or 0)" );
if( flag )
self->curve->flag |= CU_UV_ORCO;
else
self->curve->flag &= ~CU_UV_ORCO;
return EXPP_incr_ret( Py_None );
}
static PyObject* Text3d_getBevelAmount(BPy_Text3d* self)
{
return Curve_getBevresol((BPy_Curve*)self);
}
static PyObject* Text3d_setBevelAmount(BPy_Text3d* self,PyObject* args)
{
return Curve_setBevresol((BPy_Curve*)self,args);
}
static PyObject *Text3d_getDefaultResolution( BPy_Text3d * self )
{
return Curve_getResolu( (BPy_Curve*)self );
}
static PyObject *Text3d_setDefaultResolution( BPy_Text3d * self, PyObject * args )
{
return Curve_setResolu( (BPy_Curve*)self,args );
}
static PyObject *Text3d_getWidth( BPy_Text3d * self )
{
return Curve_getWidth( (BPy_Curve*)self );
}
static PyObject *Text3d_setWidth( BPy_Text3d * self, PyObject * args )
{
return Curve_setWidth( (BPy_Curve*)self,args );
}
static PyObject *Text3d_getExtrudeDepth( BPy_Text3d * self )
{
return Curve_getExt1( (BPy_Curve*)self );
}
static PyObject *Text3d_setExtrudeDepth( BPy_Text3d * self, PyObject * args )
{
return Curve_setExt1( (BPy_Curve*)self,args );
}
static PyObject *Text3d_getExtrudeBevelDepth( BPy_Text3d * self )
{
return Curve_getExt2( (BPy_Curve*)self );
}
static PyObject *Text3d_setExtrudeBevelDepth( BPy_Text3d * self, PyObject * args )
{
return Curve_setExt2( (BPy_Curve*)self,args );
}
static PyObject *Text3d_getShear( BPy_Text3d * self )
{
PyObject *attr = PyFloat_FromDouble( (double) self->curve->shear );
if( attr )
return attr;
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get Curve.shear attribute" ) );
}
static PyObject *Text3d_setShear( BPy_Text3d * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
if(value > 1.0f || value < -1.0f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 1.0 and -1.0" ) );
self->curve->shear = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Text3d_getSize( BPy_Text3d * self )
{
PyObject *attr = PyFloat_FromDouble( (double) self->curve->fsize );
if( attr )
return attr;
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get Curve.fsize attribute" ) );
}
static PyObject *Text3d_setSize( BPy_Text3d * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
if(value > 10.0f || value < 0.1f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 10.0 and 0.1" ) );
self->curve->fsize = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Text3d_getLineSeparation( BPy_Text3d * self )
{
PyObject *attr = PyFloat_FromDouble( (double) self->curve->linedist );
if( attr )
return attr;
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get Curve.linedist attribute" ) );
}
static PyObject *Text3d_setLineSeparation( BPy_Text3d * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
if(value > 10.0f || value < 0.0f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 10.0 and 0.0" ) );
self->curve->linedist = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Text3d_getSpacing( BPy_Text3d * self )
{
PyObject *attr = PyFloat_FromDouble( (double) self->curve->spacing );
if( attr )
return attr;
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get Curve.spacing attribute" ) );
}
static PyObject *Text3d_setSpacing( BPy_Text3d * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
if(value > 10.0f || value < 0.0f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 10.0 and 0.0" ) );
self->curve->spacing = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Text3d_getXoffset( BPy_Text3d * self )
{
PyObject *attr = PyFloat_FromDouble( (double) self->curve->xof );
if( attr )
return attr;
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get Curve.xof attribute" ) );
}
static PyObject *Text3d_setXoffset( BPy_Text3d * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
if(value > 50.0f || value < -50.0f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 50.0 and -50.0" ) );
self->curve->xof = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Text3d_getYoffset( BPy_Text3d * self )
{
PyObject *attr = PyFloat_FromDouble( (double) self->curve->yof );
if( attr )
return attr;
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get Curve.yof attribute" ) );
}
static PyObject *Text3d_setYoffset( BPy_Text3d * self, PyObject * args )
{
float value;
if( !PyArg_ParseTuple( args, "f", &value ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected float argument" ) );
if(value > 50.0f || value < -50.0f)
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"acceptable values are between 50.0 and -50.0" ) );
self->curve->yof = value;
return EXPP_incr_ret( Py_None );
}
static PyObject *Text3d_getAlignment( BPy_Text3d * self )
{
if(self->curve->spacemode == CU_LEFT){
return return_ModuleConstant("LEFT");
}else if (self->curve->spacemode == CU_MIDDLE){
return return_ModuleConstant("MIDDLE");
}else if (self->curve->spacemode == CU_RIGHT){
return return_ModuleConstant("RIGHT");
}else if (self->curve->spacemode == CU_FLUSH){
return return_ModuleConstant("FLUSH");
}
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get Curve.spacemode attribute" ) );
}
static PyObject *Text3d_setAlignment( BPy_Text3d * self, PyObject * args )
{
BPy_constant *constant;
int value;
if( !PyArg_ParseTuple( args, "O!", &constant_Type, &constant ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected module constant" ) );
value = PyInt_AS_LONG(PyDict_GetItemString(constant->dict, "value"));
self->curve->spacemode = (short)value;
return EXPP_incr_ret( Py_None );
}

@ -35,7 +35,6 @@
#include <Python.h>
#include <stdio.h>
#include <BLI_arithb.h>
#include <BLI_blenlib.h>
#include <BKE_main.h>
@ -43,27 +42,22 @@
#include <BKE_object.h>
#include <BKE_library.h>
#include <BKE_curve.h>
#include <DNA_curve_types.h>
#include"gen_utils.h"
extern PyTypeObject Text3d_Type;
int Text3d_CheckPyObject( PyObject * py_obj );
PyObject *Text3d_Init( void );
struct Text3d *Text3d_FromPyObject( PyObject * py_obj );
#define BPy_Text3d_Check(v) ((v)->ob_type==&Text3d_Type)
typedef Curve Text3d;
//prototypes
int Text3d_CheckPyObject( PyObject * py_obj );
PyObject *Text3d_Init( void );
struct Text3d *Text3d_FromPyObject( PyObject * py_obj );
/* Python BPy_Text3d structure definition */
typedef struct {
PyObject_HEAD /* required py macro */
Text3d * curve;
} BPy_Text3d;
#endif /* EXPP_TEXT3D_H */

@ -38,6 +38,8 @@
#include "gen_utils.h"
#define BPy_Constant_Check(v) ((v)->ob_type==&constant_Type)
/* Objects of <type 'constant'> are used inside many other Blender Python
* objects, so this header file must contain only 'public' declarations */