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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2006-08-15 15:24:08 +0400
committerCampbell Barton <ideasman42@gmail.com>2006-08-15 15:24:08 +0400
commit8e7095a464a4f35186a31069c7d02c5bf8748327 (patch)
treee3680a39c822c6181165683ca1890aaef9af4fd9 /source
parent2fc1f4ac426a1cde79d6357c9ff21c6a57533ce5 (diff)
Added __copy__ to armature, material, curve, group
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/api2_2x/Armature.c15
-rw-r--r--source/blender/python/api2_2x/Curve.c37
-rwxr-xr-xsource/blender/python/api2_2x/Group.c78
-rw-r--r--source/blender/python/api2_2x/Material.c26
4 files changed, 132 insertions, 24 deletions
diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c
index bae9b1b0db4..ff18c755956 100644
--- a/source/blender/python/api2_2x/Armature.c
+++ b/source/blender/python/api2_2x/Armature.c
@@ -474,6 +474,7 @@ AttributeError:
return EXPP_objError(PyExc_AttributeError, "%s%s",
sArmatureBadArgs, "The armature cannot be placed manually in editmode before you call makeEditable()!");
}
+
//------------------------Armature.update()
//This is a bit ugly because you need an object link to do this
static PyObject *Armature_update(BPy_Armature *self)
@@ -500,6 +501,18 @@ AttributeError:
return EXPP_objError(PyExc_AttributeError, "%s%s",
sArmatureBadArgs, "The armature must be linked to an object before you can save changes!");
}
+
+//------------------------Armature.__copy__()
+static PyObject *Armature_copy(BPy_Armature *self)
+{
+ PyObject *py_armature = NULL;
+ bArmature *bl_armature;
+ bl_armature= copy_armature(self->armature);
+ bl_armature->id.us= 0;
+ py_armature= PyArmature_FromArmature( bl_armature );
+ return py_armature;
+}
+
//------------------ATTRIBUTE IMPLEMENTATION---------------------------
//------------------------Armature.autoIK (getter)
static PyObject *Armature_getAutoIK(BPy_Armature *self, void *closure)
@@ -953,6 +966,8 @@ static PyMethodDef BPy_Armature_methods[] = {
"() - Unlocks the ability to modify armature bones"},
{"update", (PyCFunction) Armature_update, METH_NOARGS,
"() - Rebuilds the armature based on changes to bones since the last call to makeEditable"},
+ {"__copy__", (PyCFunction) Armature_copy, METH_NOARGS,
+ "() - Return a copy of the armature."},
{NULL, NULL, 0, NULL}
};
//------------------------tp_getset
diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c
index c17bbe5789a..5fbb2ad15bc 100644
--- a/source/blender/python/api2_2x/Curve.c
+++ b/source/blender/python/api2_2x/Curve.c
@@ -113,6 +113,7 @@ static PyObject *Curve_setBevOb( BPy_Curve * self, PyObject * args );
static PyObject *Curve_getTaperOb( BPy_Curve * self );
static PyObject *Curve_setTaperOb( BPy_Curve * self, PyObject * args );
+static PyObject *Curve_copy( BPy_Curve * self );
static PyObject *Curve_getIter( BPy_Curve * self );
static PyObject *Curve_iterNext( BPy_Curve * self );
@@ -226,6 +227,8 @@ Sets a control point "},
"() - returns Taper Object assigned to this Curve"},
{"setTaperOb", ( PyCFunction ) Curve_setTaperOb, METH_VARARGS,
"() - assign a Taper Object to this Curve"},
+ {"__copy__", ( PyCFunction ) Curve_copy, METH_NOARGS,
+ "() - make a copy of this curve data"},
{NULL, NULL, 0, NULL}
};
@@ -1385,6 +1388,40 @@ PyObject *Curve_setTaperOb( BPy_Curve * self, PyObject * args )
return EXPP_incr_ret( Py_None );
}
+/*****************************************************************************/
+/* Function: Curve_copy */
+/* Description: Return a copy of this curve data. */
+/*****************************************************************************/
+
+PyObject *Curve_copy( BPy_Curve * self )
+{
+ BPy_Curve *pycurve; /* for Curve Data object wrapper in Python */
+ Curve *blcurve = 0; /* for actual Curve Data we create in Blender */
+
+ /* copies the data */
+ blcurve = copy_curve( self->curve ); /* first create the Curve Data in Blender */
+
+ if( blcurve == 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 */
+ blcurve->id.us = 0;
+
+ /* create python wrapper obj */
+ pycurve = ( BPy_Curve * ) PyObject_NEW( BPy_Curve, &Curve_Type );
+
+ if( pycurve == NULL )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_MemoryError,
+ "couldn't create Curve Data object" ) );
+
+ pycurve->curve = blcurve; /* link Python curve wrapper to Blender Curve */
+ return ( PyObject * ) pycurve;
+}
+
+
/*
* Curve_getIter
*
diff --git a/source/blender/python/api2_2x/Group.c b/source/blender/python/api2_2x/Group.c
index 075730432a7..6cf10ce40ec 100755
--- a/source/blender/python/api2_2x/Group.c
+++ b/source/blender/python/api2_2x/Group.c
@@ -1,3 +1,5 @@
+#include "MEM_guardedalloc.h"
+
#include "Group.h" /* This must come first */
#include "DNA_group_types.h"
@@ -24,47 +26,74 @@ static PyObject *M_Group_New( PyObject * self, PyObject * args );
PyObject *M_Group_Get( PyObject * self, PyObject * args );
PyObject *M_Group_Unlink( PyObject * self, PyObject * args );
-/*****************************************************************************/
-/* The following string definitions are used for documentation strings. */
-/* In Python these will be written to the console when doing a */
-/* Blender.Group.__doc__ */
-/*****************************************************************************/
-char M_Group_doc[] = "The Blender Group module\n\n\
-This module provides access to **Group Data** in Blender.\n";
-
-char M_Group_New_doc[] =
- "(name) Add a new empty group";
-
-char M_Group_Get_doc[] =
- "(name) - return the group with the name 'name', returns None if not\
- found.\n\
- If 'name' is not specified, it returns a list of all groups.";
-
-char M_Group_Unlink_doc[] =
-"(group) - Unlink (delete) this group from Blender.";
/*****************************************************************************/
/* Python method structure definition for Blender.Object module: */
/*****************************************************************************/
struct PyMethodDef M_Group_methods[] = {
{"New", ( PyCFunction ) M_Group_New, METH_VARARGS,
- M_Group_New_doc},
+ "(name) Add a new empty group"},
{"Get", ( PyCFunction ) M_Group_Get, METH_VARARGS,
- M_Group_Get_doc},
+"(name) - return the group with the name 'name',\
+returns None if notfound.\nIf 'name' is not specified, it returns a list of all groups."},
{"Unlink", ( PyCFunction ) M_Group_Unlink, METH_VARARGS,
- M_Group_Unlink_doc},
+ "(group) - Unlink (delete) this group from Blender."},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python BPy_Group methods table: */
/*****************************************************************************/
+static PyObject *BPy_Group_copy( BPy_Group * self );
+
static PyMethodDef BPy_Group_methods[] = {
/* name, method, flags, doc */
+ {"__copy__", ( PyCFunction ) BPy_Group_copy, METH_VARARGS,
+ "() - Return a copy of the group containing the same objects."},
{NULL, NULL, 0, NULL}
};
+static PyObject *BPy_Group_copy( BPy_Group * self )
+{
+
+ if( !(self->group) ) {
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "Blender Group was deleted!" );
+ } else {
+ BPy_Group *py_group; /* for Group Data object wrapper in Python */
+ struct Group *bl_group;
+ GroupObject *group_ob, *group_ob_new; /* Group object, copied and added to the groups */
+
+ bl_group= add_group();
+
+ if( bl_group ) /* now create the wrapper grp in Python */
+ py_group = ( BPy_Group * ) Group_CreatePyObject( bl_group );
+ else
+ return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't create Group Data in Blender" ) );
+
+ rename_id( &bl_group->id, self->group->id.name + 2 );
+
+
+ /* user count be incremented in Group_CreatePyObject */
+ bl_group->id.us = 0;
+
+ /* Now add the objects to the group */
+ group_ob= self->group->gobject.first;
+ while(group_ob) {
+ /* save time by not using */
+ group_ob_new= MEM_callocN(sizeof(GroupObject), "groupobject");
+ group_ob_new->ob= group_ob->ob;
+ BLI_addtail( &bl_group->gobject, group_ob_new);
+ group_ob= group_ob->next;
+ }
+
+ return ( PyObject * ) py_group;
+ }
+}
+
+
/************************************************************************
*
* Python BPy_Object attributes
@@ -457,10 +486,11 @@ PyObject *Group_Init( void )
return NULL;
submodule = Py_InitModule3( "Blender.Group", M_Group_methods,
- M_Group_doc );
+ "The Blender Group module\n\n\
+This module provides access to **Group Data** in Blender.\n" );
- //Add SUBMODULES to the module
- //PyDict_SetItemString(dict, "Constraint", Constraint_Init()); //creates a *new* module
+ /*Add SUBMODULES to the module*/
+ /*PyDict_SetItemString(dict, "Constraint", Constraint_Init()); //creates a *new* module*/
return submodule;
}
diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c
index 600d5f71440..6a9670f90f7 100644
--- a/source/blender/python/api2_2x/Material.c
+++ b/source/blender/python/api2_2x/Material.c
@@ -597,6 +597,7 @@ static PyObject *Material_addScriptLink(BPy_Material * self, PyObject * args );
static PyObject *Material_clearScriptLinks(BPy_Material *self, PyObject *args);
static PyObject *Material_insertIpoKey( BPy_Material * self, PyObject * args );
+static PyObject *Material_copy( BPy_Material * self );
/*****************************************************************************/
@@ -820,6 +821,8 @@ static PyMethodDef BPy_Material_methods[] = {
{"clearScriptLinks", ( PyCFunction ) Material_clearScriptLinks, METH_VARARGS,
"() - Delete all scriptlinks from this material.\n"
"([s1<,s2,s3...>]) - Delete specified scriptlinks from this material."},
+ {"__copy__", ( PyCFunction ) Material_copy, METH_NOARGS,
+ "() - Return a copy of the material."},
{NULL, NULL, 0, NULL}
};
@@ -2473,6 +2476,29 @@ static PyObject *Material_getScriptLinks( BPy_Material * self,
return NULL;
}
+/* mat.__copy__ */
+static PyObject *Material_copy( BPy_Material * self )
+{
+ BPy_Material *pymat; /* for Material Data object wrapper in Python */
+ Material *blmat; /* for actual Material Data we create in Blender */
+
+ blmat = copy_material( self->material ); /* first copy the Material Data in Blender */
+
+ if( blmat ) /* now create the wrapper obj in Python */
+ pymat = ( BPy_Material * ) Material_CreatePyObject( blmat );
+ else
+ return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't create Material Data in Blender" ) );
+
+ blmat->id.us = 0; /* was incref'ed by add_material() above */
+
+ if( pymat == NULL )
+ return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create Material Data object" ) );
+
+ return ( PyObject * ) pymat;
+}
+
/*****************************************************************************/
/* Function: Material_repr */
/* Description: This is a callback function for the BPy_Material type. It */