Revision: 17130
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17130
Author:   jesterking
Date:     2008-10-20 14:33:31 +0200 (Mon, 20 Oct 2008)

Log Message:
-----------
=== Blender Python API ===

After some discussion with Campbell, changed the way cstruct sizeof is fetched.

Moved DataSize() to Blender.Types.CSizeof(Blendertype). Supported types return 
sizeof(data struct), otherwise -1.

To quickly check what types are supported:

import Blender.Types as bt
x = dir(bt)
for t in x:
        if t[0] != '_':
                s = 'bt.CSizeof(bt.' + t + ')'
                print t,"=", eval(s)

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Armature.c
    trunk/blender/source/blender/python/api2_2x/Material.c
    trunk/blender/source/blender/python/api2_2x/Mesh.c
    trunk/blender/source/blender/python/api2_2x/Object.c
    trunk/blender/source/blender/python/api2_2x/Types.c

Modified: trunk/blender/source/blender/python/api2_2x/Armature.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Armature.c      2008-10-20 
09:35:07 UTC (rev 17129)
+++ trunk/blender/source/blender/python/api2_2x/Armature.c      2008-10-20 
12:33:31 UTC (rev 17130)
@@ -1295,27 +1295,6 @@
        return (PyObject *)obj;
 }
 
-static PyObject *M_Armature_DataSize(PyObject * self, PyObject *args)
-{
-       int t = 0;
-       int ret = 0;
-       if( !PyArg_ParseTuple(args, "|i", &t))
-               return EXPP_ReturnPyObjError( PyExc_TypeError,
-                                               "expected nothing or an int as 
argument" );
-       
-       switch(t) {
-               case 0:
-                       ret = sizeof(struct bArmature);
-                       break;
-               default:
-                       ret = sizeof(struct Bone);
-                       break;
-       }
-       
-       return PyInt_FromLong(ret);
-}
-
-
 //-------------------MODULE METHODS DEFINITION-----------------------------
 
 static char M_Armature_Get_doc[] = "(name) - return the armature with the name 
'name', \
@@ -1324,12 +1303,9 @@
 
 static char M_Armature_New_doc[] = "(name) - return a new armature object.";
 
-static char M_Armature_DataSize_doc[] = "(type) - return sizeof of either 
Armature (0) or Bone (1).";
-
 struct PyMethodDef M_Armature_methods[] = {
        {"Get", M_Armature_Get, METH_VARARGS, M_Armature_Get_doc},
        {"New", M_Armature_New, METH_VARARGS, M_Armature_New_doc},
-       {"DataSize", M_Armature_DataSize, METH_VARARGS, 
M_Armature_DataSize_doc},
        {NULL, NULL, 0, NULL}
 };
 //------------------VISIBLE PROTOTYPE IMPLEMENTATION-----------------------

Modified: trunk/blender/source/blender/python/api2_2x/Material.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Material.c      2008-10-20 
09:35:07 UTC (rev 17129)
+++ trunk/blender/source/blender/python/api2_2x/Material.c      2008-10-20 
12:33:31 UTC (rev 17130)
@@ -207,7 +207,6 @@
 static PyObject *M_Material_New( PyObject * self, PyObject * args,
                                 PyObject * keywords );
 static PyObject *M_Material_Get( PyObject * self, PyObject * args );
-static PyObject *M_Material_DataSize(PyObject *unused);
 
 /*****************************************************************************/
 /* The following string definitions are used for documentation strings.  In  */
@@ -232,8 +231,6 @@
         M_Material_New_doc},
        {"Get", M_Material_Get, METH_VARARGS, M_Material_Get_doc},
        {"get", M_Material_Get, METH_VARARGS, M_Material_Get_doc},
-       {"DataSize", ( PyCFunction ) M_Material_DataSize, METH_NOARGS,
-               "Get sizeof() of Material"},
        {NULL, NULL, 0, NULL}
 };
 
@@ -338,12 +335,6 @@
        }
 }
 
-static PyObject *M_Material_DataSize(PyObject *unused)
-{
-       return PyInt_FromLong(sizeof(Material));
-}
-
-
 static PyObject *Material_ModesDict( void )
 {
        PyObject *Modes = PyConstant_New(  );

Modified: trunk/blender/source/blender/python/api2_2x/Mesh.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Mesh.c  2008-10-20 09:35:07 UTC 
(rev 17129)
+++ trunk/blender/source/blender/python/api2_2x/Mesh.c  2008-10-20 12:33:31 UTC 
(rev 17130)
@@ -8637,35 +8637,6 @@
        return PVert_CreatePyObject( &vert );
 }
 
-static PyObject *M_Mesh_DataSize(PyObject * self, PyObject *args)
-{
-       int t = 0;
-       int ret = 0;
-       if( !PyArg_ParseTuple(args, "|i", &t))
-               return EXPP_ReturnPyObjError( PyExc_TypeError,
-                                               "expected nothing or an int as 
argument" );
-       
-       switch(t) {
-               case 0:
-                       ret = sizeof(Mesh);
-                       break;
-               case 1:
-                       ret = sizeof(MVert);
-                       break;
-               case 2:
-                       ret = sizeof(MEdge);
-                       break;
-               case 3:
-                       ret = sizeof(MFace);
-                       break;
-               default:
-                       ret = sizeof(Mesh);
-                       break;
-       }
-       
-       return PyInt_FromLong(ret);
-}
-
 static PyObject *M_Mesh_Modes( PyObject * self_unused, PyObject * args )
 {
        int modes = 0;
@@ -8697,8 +8668,6 @@
                "Create a new MVert"},
        {"Mode", (PyCFunction)M_Mesh_Modes, METH_VARARGS,
                "Get/set edit selection mode(s)"},
-       {"DataSize", (PyCFunction)M_Mesh_DataSize, METH_VARARGS,
-               "Get sizeof() of Mesh (0), MVert (1), MEdge (2) or MFace (3)"},
        {NULL, NULL, 0, NULL},
 };
 

Modified: trunk/blender/source/blender/python/api2_2x/Object.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Object.c        2008-10-20 
09:35:07 UTC (rev 17129)
+++ trunk/blender/source/blender/python/api2_2x/Object.c        2008-10-20 
12:33:31 UTC (rev 17130)
@@ -290,7 +290,6 @@
 PyObject *M_Object_Get( PyObject * self, PyObject * args );
 static PyObject *M_Object_GetSelected( PyObject * self );
 static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args, 
PyObject *kwd);
-static PyObject *M_Object_DataSize( PyObject * self );
 
 /* HELPER FUNCTION FOR PARENTING */
 static PyObject *internal_makeParent(Object *parent, PyObject *py_child, int 
partype, int noninverse, int fast, int v1, int v2, int v3, char *bonename);
@@ -319,9 +318,6 @@
 static char M_Object_Duplicate_doc[] =
        "(linked) - Duplicate all selected, visible objects in the current 
scene";
 
-static char M_Object_DataSize_doc[] = 
-       "() - return the sizeof(Object)";
-
 /*****************************************************************************/
 /* Python method structure definition for Blender.Object module:        */
 /*****************************************************************************/
@@ -334,8 +330,6 @@
         M_Object_GetSelected_doc},
        {"Duplicate", ( PyCFunction ) M_Object_Duplicate, METH_VARARGS | 
METH_KEYWORDS,
         M_Object_Duplicate_doc},
-       {"DataSize", ( PyCFunction ) M_Object_DataSize, METH_NOARGS,
-        M_Object_DataSize_doc},
        {NULL, NULL, 0, NULL}
 };
 
@@ -1042,12 +1036,6 @@
        Py_RETURN_NONE;
 }
 
-static PyObject *M_Object_DataSize(PyObject * self)
-{
-       return PyInt_FromLong(sizeof(Object));
-}
-
-
 /*****************************************************************************/
 /* Python BPy_Object methods:                                  */
 /*****************************************************************************/

Modified: trunk/blender/source/blender/python/api2_2x/Types.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Types.c 2008-10-20 09:35:07 UTC 
(rev 17129)
+++ trunk/blender/source/blender/python/api2_2x/Types.c 2008-10-20 12:33:31 UTC 
(rev 17130)
@@ -26,8 +26,10 @@
  * ***** END GPL LICENSE BLOCK *****
 */
 
-#include "Types.h" 
+#include "Types.h"
 #include "IDProp.h"
+#include "gen_utils.h"
+#include "BLI_blenlib.h"
 /* 
    stuff pasted from the old Types.h
    is only need here now
@@ -65,13 +67,133 @@
 extern PyTypeObject ThemeUI_Type;
 extern PyTypeObject TimeLine_Type;
 
+/* includes to get structs for CSizeof */
+#include "Armature.h"
+#include "Bone.h"
+#include "BezTriple.h"
+#include "Camera.h"
+#include "Constraint.h"
+#include "Curve.h"
+#include "CurNurb.h"
+#include "Draw.h"
+#include "Effect.h"
+#include "Ipo.h"
+#include "Ipocurve.h"
+#include "Key.h"
+#include "Lamp.h"
+#include "Lattice.h"
+#include "Library.h"
+#include "Mathutils.h"
+#include "Geometry.h"
+#include "Mesh.h"
+#include "Metaball.h"
+#include "Modifier.h"
+#include "NMesh.h"
+#include "Node.h"
+#include "Object.h"
+#include "Group.h"
+#include "Registry.h"
+#include "Scene.h"
+#include "Sound.h"
+#include "SurfNurb.h"
+#include "Sys.h"
+#include "Text.h"
+#include "Texture.h"
+#include "Window.h"
+#include "World.h"
+#include "Particle.h"
+
 char M_Types_doc[] = "The Blender Types module\n\n\
 This module is a dictionary of all Blender Python types";
 
-struct PyMethodDef Null_methods[] = { {NULL, NULL, 0, NULL} };
+static PyObject *Types_CSizeof(PyObject * self, PyObject *o)
+{
+       int ret = 0;
+       char type[32];
 
+       if(o) {
+               sprintf(type, "%s", PyString_AsString(PyObject_Str(o)));
 
+               if(BLI_streq(type, "<type 'Blender Action'>")==1) {
+                       ret = sizeof(struct bAction);
+               } else if (BLI_streq(type, "<type 'Armature'>")==1) {
+                       ret = sizeof(struct bArmature);
+               } else if (BLI_streq(type, "<type 'BezTriple'>")==1) {
+                       ret = sizeof(struct BezTriple);
+               } else if (BLI_streq(type, "<type 'Bone'>")==1) {
+                       ret = sizeof(struct Bone);
+               } else if (BLI_streq(type, "<type 'Blender Camera'>")==1) {
+                       ret = sizeof(struct Camera);
+               } else if (BLI_streq(type, "<type 'CurNurb'>")==1) {
+                       ret = sizeof(struct Nurb);
+               } else if (BLI_streq(type, "<type 'Curve'>")==1) {
+                       ret = sizeof(struct Curve);
+               } else if (BLI_streq(type, "<type 'Blender Group'>")==1) {
+                       ret = sizeof(struct Group);
+               } else if (BLI_streq(type, "<type 'Blender IDProperty'>")==1) {
+                       ret = sizeof(struct IDProperty);
+               } else if (BLI_streq(type, "<type 'Blender Image'>")==1) {
+                       ret = sizeof(struct Image);
+               } else if (BLI_streq(type, "<type 'Blender Ipo'>")==1) {
+                       ret = sizeof(struct Ipo);
+               } else if (BLI_streq(type, "<type 'IpoCurve'>")==1) {
+                       ret = sizeof(struct IpoCurve);
+               } else if (BLI_streq(type, "<type 'Blender Lamp'>")==1) {
+                       ret = sizeof(struct Lamp);
+               } else if (BLI_streq(type, "<type 'Blender Lattice'>")==1) {
+                       ret = sizeof(struct Lattice);
+               } else if (BLI_streq(type, "<type 'Blender MCol'>")==1) {
+                       ret = sizeof(struct MCol);
+               } else if (BLI_streq(type, "<type 'Blender MEdge'>")==1) {
+                       ret = sizeof(struct MEdge);
+               } else if (BLI_streq(type, "<type 'Blender MFace'>")==1) {
+                       ret = sizeof(struct MFace);
+               } else if (BLI_streq(type, "<type 'Blender MTex'>")==1) {
+                       ret = sizeof(struct MTex);
+               } else if (BLI_streq(type, "<type 'Blender MVert'>")==1) {
+                       ret = sizeof(struct MVert);
+               } else if (BLI_streq(type, "<type 'Blender Material'>")==1) {
+                       ret = sizeof(struct Material);
+               } else if (BLI_streq(type, "<type 'Blender Mesh'>")==1) {
+                       ret = sizeof(struct Mesh);
+               } else if (BLI_streq(type, "<type 'Blender Metaball'>")==1) {
+                       ret = sizeof(struct MetaBall);
+               } else if (BLI_streq(type, "<type 'Blender.Modifiers'>")==1) {
+                       ret = sizeof(struct ModifierData);
+               } else if (BLI_streq(type, "<type 'Blender Modifier'>")==1) {
+                       ret = sizeof(struct ModifierData);
+               } else if (BLI_streq(type, "<type 'Blender Object'>")==1) {
+                       ret = sizeof(struct Object);
+               } else if (BLI_streq(type, "<type 'Pose'>")==1) {
+                       ret = sizeof(struct bPose);
+               } else if (BLI_streq(type, "<type 'Blender RenderData'>")==1) {
+                       ret = sizeof(struct RenderData);
+               } else if (BLI_streq(type, "<type 'Scene'>")==1) {
+                       ret = sizeof(struct Scene);
+               } else if (BLI_streq(type, "<type 'SurfNurb'>")==1) {
+                       ret = sizeof(struct Nurb);
+               } else if (BLI_streq(type, "<type 'Text3d'>")==1) {
+                       ret = sizeof(struct Curve);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to