diff --git a/source/blender/python/SConscript b/source/blender/python/SConscript index 0b7a62d44c0..656df1354d7 100644 --- a/source/blender/python/SConscript +++ b/source/blender/python/SConscript @@ -43,6 +43,7 @@ source_files = ['BPY_interface.c', 'api2_2x/World.c', 'api2_2x/Image.c', 'api2_2x/Text.c', + 'api2_2x/Text3d.c', 'api2_2x/Texture.c', 'api2_2x/Noise.c', 'api2_2x/charRGBA.c', diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c index ec0ba64e103..b677f09413e 100644 --- a/source/blender/python/api2_2x/Blender.c +++ b/source/blender/python/api2_2x/Blender.c @@ -543,6 +543,7 @@ void M_Blender_Init( void ) PyDict_SetItemString( dict, "BGL", BGL_Init( ) ); PyDict_SetItemString( dict, "Effect", Effect_Init( ) ); PyDict_SetItemString( dict, "Text", Text_Init( ) ); + PyDict_SetItemString( dict, "Text3d", Text3d_Init( ) ); PyDict_SetItemString( dict, "World", World_Init( ) ); PyDict_SetItemString( dict, "Texture", Texture_Init( ) ); PyDict_SetItemString( dict, "NMesh", NMesh_Init( ) ); diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c index fcfb5b171c8..aafcca16dfc 100644 --- a/source/blender/python/api2_2x/Curve.c +++ b/source/blender/python/api2_2x/Curve.c @@ -76,8 +76,8 @@ static PyObject *M_Curve_Get( PyObject * self, PyObject * args ); /*****************************************************************************/ /* Python BPy_Curve instance methods declarations: */ /*****************************************************************************/ -static PyObject *Curve_getName( BPy_Curve * self ); -static PyObject *Curve_setName( BPy_Curve * self, PyObject * args ); +PyObject *Curve_getName( BPy_Curve * self ); +PyObject *Curve_setName( BPy_Curve * self, PyObject * args ); static PyObject *Curve_getPathLen( BPy_Curve * self ); static PyObject *Curve_setPathLen( BPy_Curve * self, PyObject * args ); static PyObject *Curve_getTotcol( BPy_Curve * self ); @@ -446,7 +446,7 @@ PyObject *Curve_Init( void ) /*****************************************************************************/ -static PyObject *Curve_getName( BPy_Curve * self ) +PyObject *Curve_getName( BPy_Curve * self ) { PyObject *attr = PyString_FromString( self->curve->id.name + 2 ); @@ -457,7 +457,7 @@ static PyObject *Curve_getName( BPy_Curve * self ) "couldn't get Curve.name attribute" ) ); } -static PyObject *Curve_setName( BPy_Curve * self, PyObject * args ) +PyObject *Curve_setName( BPy_Curve * self, PyObject * args ) { char *name; char buf[50]; diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 5b59449c8ea..649b545ae57 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include "Ipo.h" @@ -150,7 +151,9 @@ static PyObject *Object_copyAllPropertiesTo( BPy_Object * self, static PyObject *Object_getScriptLinks( BPy_Object * self, PyObject * args ); static PyObject *Object_addScriptLink( BPy_Object * self, PyObject * args ); static PyObject *Object_clearScriptLinks( BPy_Object * self ); - +/* fixme: save for separate commit. 06-mar-05 +static PyObject *Object_setDupliVerts ( BPy_Object * self ); +*/ /*****************************************************************************/ /* Python BPy_Object methods table: */ /*****************************************************************************/ @@ -306,6 +309,12 @@ works only if self and the object specified are of the same type."}, {"clearScriptLinks", ( PyCFunction ) Object_clearScriptLinks, METH_NOARGS, "() - Delete all scriptlinks from this object."}, +#if 0 +/* fixme:save for separate commit. 6-mar-05 stivs */ + {"setDupliVerts", ( PyCFunction ) Object_setDupliVerts, + METH_NOARGS, + "() - setDupliVerts."}, +#endif {NULL, NULL, 0, NULL} }; @@ -370,7 +379,8 @@ PyObject *M_Object_New( PyObject * self, PyObject * args ) type = OB_CAMERA; else if( strcmp( str_type, "Curve" ) == 0 ) type = OB_CURVE; -/* else if (strcmp (str_type, "Text") == 0) type = OB_FONT; */ + else if (strcmp (str_type, "Text") == 0) + type = OB_FONT; /* else if (strcmp (str_type, "Ika") == 0) type = OB_IKA; */ else if( strcmp( str_type, "Lamp" ) == 0 ) type = OB_LAMP; @@ -1224,6 +1234,8 @@ static PyObject *Object_link( BPy_Object * self, PyObject * args ) data = ( void * ) Lattice_FromPyObject( py_data ); if( Metaball_CheckPyObject( py_data ) ) data = ( void * ) Metaball_FromPyObject( py_data ); + if( Text3d_CheckPyObject( py_data ) ) + data = ( void * ) Text3d_FromPyObject( py_data ); /* have we set data to something good? */ if( !data ) { @@ -1261,7 +1273,7 @@ static PyObject *Object_link( BPy_Object * self, PyObject * args ) } break; case ID_CU: - if( self->object->type != OB_CURVE ) { + if( self->object->type != OB_CURVE && self->object->type != OB_FONT ) { return ( EXPP_ReturnPyObjError( PyExc_AttributeError, "The 'link' object is incompatible with the base object" ) ); } @@ -2003,6 +2015,24 @@ static PyObject *Object_getScriptLinks( BPy_Object * self, PyObject * args ) return NULL; } +#if 0 + +/* fixme: save this for next commit 6-mar-05 stivs */ + +/**** + * Set dupliverts + * + ***/ + +static PyObject *Object_setDupliVerts ( BPy_Object * self ) { + Object *obj = self->object; + if (obj) { + obj->transflag|= (char)16; + } + return Py_None; +} +#endif + /*****************************************************************************/ /* Function: Object_CreatePyObject */ /* Description: This function will create a new BlenObject from an existing */ diff --git a/source/blender/python/api2_2x/Text3d.c b/source/blender/python/api2_2x/Text3d.c new file mode 100644 index 00000000000..695267ceaf8 --- /dev/null +++ b/source/blender/python/api2_2x/Text3d.c @@ -0,0 +1,356 @@ +/* + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Joilnen Leite + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_view3d_types.h" +#include "DNA_vfont_types.h" + +#include "BKE_object.h" +#include "BDR_editobject.h" + +#include "blendef.h" +#include "Text3d.h" + +#include "mydevice.h" + +extern PyObject *Curve_getName( BPy_Text3d * self ); +extern PyObject *Curve_setName( BPy_Text3d * self, PyObject * args ); + +/*****************************************************************************/ +/* Python API function prototypes for the Effect module. */ +/*****************************************************************************/ +static PyObject *M_Text3d_New( PyObject * self, PyObject * args ); +static PyObject *M_Text3d_Get( PyObject * self, PyObject * args ); + +/*****************************************************************************/ +/* Python BPy_Text3d methods declarations: */ +/*****************************************************************************/ +/*PyObject *Text3d_getType(BPy_Text3d *self);*/ + +/*****************************************************************************/ +/* Python Text3d_Type callback function prototypes: */ +/*****************************************************************************/ + +PyObject *Text3d_Init( void ); +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 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 ); + +/*****************************************************************************/ +/* Python BPy_Text3d methods table: */ +/*****************************************************************************/ +static char text2text3_doc[] = "(str) - set Text3d string"; + +static PyMethodDef BPy_Text3d_methods[] = { + {"getName", ( PyCFunction ) Text3d_getName, + METH_NOARGS, "() - Return Text3d Data name"}, + {"setName", ( PyCFunction ) Text3d_setName, + METH_VARARGS, "() - Sets Text3d Data name"}, + {"setText", ( PyCFunction ) Text3d_setText, + METH_VARARGS, "() - Sets Text3d Data"}, + {"getText", ( PyCFunction ) Text3d_getText, + METH_NOARGS, "() - Gets Text3d Data"}, + {NULL, NULL, 0, NULL} +}; + +/*****************************************************************************/ +/* Python Text3d_Type structure definition: */ +/*****************************************************************************/ +PyTypeObject Text3d_Type = { + PyObject_HEAD_INIT( NULL ) + 0, /* ob_size */ + "Text3d", /* tp_name */ + sizeof( BPy_Text3d ), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + ( destructor ) Text3dDeAlloc, /* tp_dealloc */ + 0, /* tp_print */ + ( getattrfunc ) Text3dGetAttr, /* tp_getattr */ + ( setattrfunc ) Text3dSetAttr, /* tp_setattr */ + 0, /* tp_compare */ + ( reprfunc ) Text3dRepr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_as_hash */ + 0, 0, 0, 0, 0, 0, + 0, /* tp_doc */ + 0, 0, 0, 0, 0, 0, + BPy_Text3d_methods, /* tp_methods */ + 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: */ +/*****************************************************************************/ +static PyObject *Text2Text3d( BPy_Text3d * self, PyObject * args ); + + +/* + * Text3d_update( ) + * method to update display list for a Curve. + */ +static PyObject *Text3d_update( BPy_Text3d * self ) +{ + freedisplist( &self->curve->disp ); + + Py_INCREF( Py_None ); + return Py_None; +} + + +/*****************************************************************************/ +/* Function: M_Text3d_New */ +/* Python equivalent: Blender.Text3d.New */ +/*****************************************************************************/ + +PyObject *M_Text3d_New( PyObject * self, PyObject * args ) +{ + char buf[24]; + char *name = NULL; + BPy_Text3d *pytext3d; /* for Curve Data object wrapper in Python */ + Text3d *bltext3d = 0; /* for actual Curve Data we create in Blender */ + + if( !PyArg_ParseTuple( args, "|s", &name ) ) + return ( EXPP_ReturnPyObjError + ( PyExc_AttributeError, + "expected string argument or no argument" ) ); + + bltext3d = add_curve( OB_FONT ); /* first create the Curve Data in Blender */ + bltext3d->vfont= get_builtin_font(); + bltext3d->vfont->id.us++; + bltext3d->str= MEM_mallocN(12, "str"); + strcpy(bltext3d->str, "Text"); + bltext3d->pos= 4; + + if( bltext3d == NULL ) /* bail out if add_curve() failed */ + return ( EXPP_ReturnPyObjError + ( PyExc_RuntimeError, + "couldn't create Curve Data in Blender" ) ); + + /* return user count to zero because add_curve() inc'd it */ + bltext3d->id.us = 0; + /* create python wrapper obj */ + pytext3d = ( BPy_Text3d * ) PyObject_NEW( BPy_Text3d, &Text3d_Type ); + + if( pytext3d == NULL ) + return ( EXPP_ReturnPyObjError + ( PyExc_MemoryError, + "couldn't create Curve Data object" ) ); + + pytext3d->curve = bltext3d; /* link Python curve wrapper to Blender Curve */ + if( name ) { + PyOS_snprintf( buf, sizeof( buf ), "%s", name ); + rename_id( &bltext3d->id, buf ); + } + Text3d_update ( pytext3d ); + return ( PyObject * ) pytext3d; +} + +PyObject *M_Text3d_Get( PyObject * self, PyObject * args ) +{ + char *name = NULL; + Text3d *curv_iter; + BPy_Text3d *wanted_curv; + + if( !PyArg_ParseTuple( args, "|s", &name ) ) /* expects nothing or a string */ + return ( EXPP_ReturnPyObjError( PyExc_AttributeError, + "expected string argument" ) ); + if( name ) { /*a name has been given */ + /* Use the name to search for the curve requested */ + wanted_curv = NULL; + curv_iter = G.main->curve.first; + + while( ( curv_iter ) && ( wanted_curv == NULL ) ) { + + if( strcmp( name, curv_iter->id.name + 2 ) == 0 ) { + wanted_curv = ( BPy_Text3d * ) + PyObject_NEW( BPy_Text3d, &Text3d_Type ); + if( wanted_curv ) + wanted_curv->curve = curv_iter; + } + + curv_iter = curv_iter->id.next; + } + + if( wanted_curv == NULL ) { /* Requested curve doesn't exist */ + char error_msg[64]; + PyOS_snprintf( error_msg, sizeof( error_msg ), + "Curve \"%s\" not found", name ); + return ( EXPP_ReturnPyObjError + ( PyExc_NameError, error_msg ) ); + } + + return ( PyObject * ) wanted_curv; + } /* end of if(name) */ + else { + /* no name has been given; return a list of all curves by name. */ + PyObject *curvlist; + + curv_iter = G.main->curve.first; + curvlist = PyList_New( 0 ); + + if( curvlist == NULL ) + return ( EXPP_ReturnPyObjError( PyExc_MemoryError, + "couldn't create PyList" ) ); + + while( curv_iter && curv_iter->vfont ) { + BPy_Text3d *found_text3d = + ( BPy_Text3d * ) PyObject_NEW( BPy_Text3d, + &Text3d_Type ); + found_text3d->curve = curv_iter; + PyList_Append( curvlist, ( PyObject * ) found_text3d ); + + curv_iter = curv_iter->id.next; + } + return ( curvlist ); + } +} + +PyObject *Text3d_Init( void ) +{ + PyObject *submodule; + + Text3d_Type.ob_type = &PyType_Type; + + submodule = Py_InitModule3( "Blender.Text3d", M_Text3d_methods, 0 ); + return ( submodule ); +} + +void Text3dDeAlloc( BPy_Text3d * self ) +{ + PyObject_DEL( self ); +} + +/*****************************************************************************/ +/* Function: Text3dGetAttr */ +/* Description: This is a callback function for the BPy_Text3d type. It is */ +/* the function that accesses BPy_Text3d "member variables" and */ +/* methods. */ +/*****************************************************************************/ + + +PyObject *Text3dGetAttr( BPy_Text3d * self, char *name ) +{ + return Py_FindMethod( BPy_Text3d_methods, ( PyObject * ) self, name ); +} + +/*****************************************************************************/ +/* Function: EffectSetAttr */ +/* 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 ) +{ + return 0; /* normal exit */ +} + +/*****************************************************************************/ +/* Function: Text3dRepr */ +/* Description: This is a callback function for the BPy_Effect type. It */ +/* builds a meaninful string to represent effcte objects. */ +/*****************************************************************************/ + +PyObject *Text3dRepr( BPy_Text3d * self ) +{ + char *str = ""; + return PyString_FromString( str ); +} + +int Text3d_CheckPyObject( PyObject * py_obj ) +{ + return ( py_obj->ob_type == &Text3d_Type ); +} + +struct Text3d *Text3d_FromPyObject( PyObject * py_obj ) +{ + BPy_Text3d *blen_obj; + + blen_obj = ( BPy_Text3d * ) py_obj; + return ((Text3d*) blen_obj->curve ); +} + +static PyObject *Text3d_getName( BPy_Text3d * self ) +{ + return Curve_getName( self ); +} + +static PyObject *Text3d_setName( BPy_Text3d * self, PyObject * args ) +{ + return Curve_setName( self,args ); +} + +static PyObject *Text3d_setText( BPy_Text3d * self, PyObject * args ) +{ + char *text; + if( !PyArg_ParseTuple( args, "s", &text ) ) + return ( EXPP_ReturnPyObjError( PyExc_AttributeError, + "expected string argument" ) ); + if (self) { + MEM_freeN (self->curve->str); + self->curve->str= MEM_mallocN (strlen (text)+1, "str"); + strcpy (self->curve->str, text); + self->curve->pos= strlen (text); + } + Py_INCREF( Py_None ); + return Py_None; +} + +static PyObject *Text3d_getText( BPy_Text3d * self ) +{ + if ( strlen(self->curve->str) ) + return PyString_FromString (self->curve->str); + else + return Py_None; +} + diff --git a/source/blender/python/api2_2x/Text3d.h b/source/blender/python/api2_2x/Text3d.h new file mode 100644 index 00000000000..dd42bb138d4 --- /dev/null +++ b/source/blender/python/api2_2x/Text3d.h @@ -0,0 +1,64 @@ +/* + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * This is a new part of Blender. + * + * Contributor(s): Joilnen Leite + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** +*/ + +#ifndef EXPP_TEXT3D_H +#define EXPP_TEXT3D_H + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include"gen_utils.h" + +extern PyTypeObject Text3d_Type; + +#define BPy_Text3d_Check(v) ((v)->ob_type==&Text3d_Type) +typedef Curve Text3d; + +/* Python BPy_Text3d structure definition */ +typedef struct { + PyObject_HEAD /* required py macro */ + Text3d * curve; +} BPy_Text3d; + + +#endif /* EXPP_TEXT3D_H */ + diff --git a/source/blender/python/api2_2x/Types.c b/source/blender/python/api2_2x/Types.c index 930ecc7c270..a4722c17c6e 100644 --- a/source/blender/python/api2_2x/Types.c +++ b/source/blender/python/api2_2x/Types.c @@ -74,6 +74,7 @@ void types_InitAll( void ) RenderData_Type.ob_type = &PyType_Type; Scene_Type.ob_type = &PyType_Type; Text_Type.ob_type = &PyType_Type; + Text3d_Type.ob_type = &PyType_Type; Texture_Type.ob_type = &PyType_Type; Wave_Type.ob_type = &PyType_Type; World_Type.ob_type = &PyType_Type; @@ -134,6 +135,7 @@ PyObject *Types_Init( void ) PyDict_SetItemString( dict, "ImageType", ( PyObject * ) & Image_Type ); PyDict_SetItemString( dict, "LampType", ( PyObject * ) & Lamp_Type ); PyDict_SetItemString( dict, "TextType", ( PyObject * ) & Text_Type ); + PyDict_SetItemString( dict, "Text3dType", ( PyObject * ) & Text3d_Type ); PyDict_SetItemString( dict, "MaterialType", ( PyObject * ) & Material_Type ); diff --git a/source/blender/python/api2_2x/Types.h b/source/blender/python/api2_2x/Types.h index a73a89a6cb1..86e2e5c5449 100644 --- a/source/blender/python/api2_2x/Types.h +++ b/source/blender/python/api2_2x/Types.h @@ -48,7 +48,7 @@ extern PyTypeObject NMFace_Type, NMVert_Type, NMCol_Type, NMesh_Type; extern PyTypeObject Object_Type; extern PyTypeObject Particle_Type; extern PyTypeObject Scene_Type, RenderData_Type; -extern PyTypeObject Text_Type, Texture_Type; +extern PyTypeObject Text_Type, Text3d_Type, Texture_Type; extern PyTypeObject Wave_Type, World_Type; extern PyTypeObject property_Type; extern PyTypeObject buffer_Type, constant_Type, euler_Type; diff --git a/source/blender/src/editfont.c b/source/blender/src/editfont.c index 99cf13d46f8..0a058c9c902 100644 --- a/source/blender/src/editfont.c +++ b/source/blender/src/editfont.c @@ -234,7 +234,7 @@ static int insert_into_textbuf(Curve *cu, char c) } -static VFont *get_builtin_font(void) +VFont *get_builtin_font(void) { VFont *vf;