py/rna functions for adding and removing curve data.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 23 Mar 2010 14:58:36 +0000 (14:58 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 23 Mar 2010 14:58:36 +0000 (14:58 +0000)
(commit 27666 by Campbell from render25 branch)

source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/RNA_types.h
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_object.c

index 9ccab8394e952c0841a22acd30b69c9874bf8b58..6adad6aa92cb1d13d912ab92cc5c56886da3b8ef 100644 (file)
@@ -73,6 +73,8 @@ extern EnumPropertyItem unpack_method_items[];
 
 extern EnumPropertyItem object_type_items[];
 
+extern EnumPropertyItem object_type_curve_items[];
+
 extern EnumPropertyItem space_type_items[];
 
 extern EnumPropertyItem keymap_propvalue_items[];
index 77eff6ad4c51f6c2ce4db41f1877a70de6d8dadc..e09bd19774c07f152042979eb0cd3aadfc84891e 100644 (file)
@@ -340,6 +340,7 @@ typedef struct ExtensionRNA {
 #define MainActions Main
 #define MainGroups Main
 #define MainTextures Main
+#define MainCurves Main
 
 #ifdef __cplusplus
 }
index 9433294fdd3976882955b59481261a78da9bc649..690b671c31816cd3366f80fd729a1ec13eb81b6e 100644 (file)
@@ -54,6 +54,7 @@
 
 #include "DNA_armature_types.h"
 #include "DNA_camera_types.h"
+#include "DNA_curve_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
@@ -243,6 +244,20 @@ void rna_Main_images_remove(Main *bmain, ReportList *reports, Image *image)
        /* XXX python now has invalid pointer? */
 }
 
+Curve *rna_Main_curves_new(Main *bmain, char* name, int type)
+{
+       Curve *cu= add_curve(name, type);
+       cu->id.us--;
+       return cu;
+}
+void rna_Main_curves_remove(Main *bmain, ReportList *reports, struct Curve *cu)
+{
+       if(ID_REAL_USERS(cu) <= 0)
+               free_libblock(&bmain->curve, cu);
+       else
+               BKE_reportf(reports, RPT_ERROR, "Curve \"%s\" must have zero users to be removed, found %d.", cu->id.name+2, ID_REAL_USERS(cu));
+}
+
 Tex *rna_Main_textures_new(Main *bmain, char* name)
 {
        Tex *tex= add_texture(name);
@@ -508,7 +523,7 @@ void RNA_def_main_screens(BlenderRNA *brna, PropertyRNA *cprop)
 }
 void RNA_def_main_window_managers(BlenderRNA *brna, PropertyRNA *cprop)
 {
-
+    
 }
 void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop)
 {
@@ -552,7 +567,29 @@ void RNA_def_main_lattices(BlenderRNA *brna, PropertyRNA *cprop)
 }
 void RNA_def_main_curves(BlenderRNA *brna, PropertyRNA *cprop)
 {
+       StructRNA *srna;
+       FunctionRNA *func;
+       PropertyRNA *parm;
+
+       RNA_def_property_srna(cprop, "MainCurves");
+       srna= RNA_def_struct(brna, "MainCurves", NULL);
+       RNA_def_struct_ui_text(srna, "Main Curves", "Collection of curves");
 
+       func= RNA_def_function(srna, "new", "rna_Main_curves_new");
+       RNA_def_function_ui_description(func, "Add a new curve to the main database");
+       parm= RNA_def_string(func, "name", "Curve", 0, "", "New name for the datablock.");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm= RNA_def_enum(func, "type", object_type_curve_items, 0, "Type", "The type of curve object to add");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       /* return type */
+       parm= RNA_def_pointer(func, "curve", "Curve", "", "New curve datablock.");
+       RNA_def_function_return(func, parm);
+
+       func= RNA_def_function(srna, "remove", "rna_Main_curves_remove");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
+       RNA_def_function_ui_description(func, "Remove a curve from the current blendfile.");
+       parm= RNA_def_pointer(func, "curve", "Curve", "", "Curve to remove.");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
 }
 void RNA_def_main_metaballs(BlenderRNA *brna, PropertyRNA *cprop)
 {
index 8fd2528e2bed2b576d89ddab267932f820612d22..b0fd3eb58e2d84895b8cc6cdb0876a70adc67b80 100644 (file)
@@ -76,12 +76,17 @@ static EnumPropertyItem collision_bounds_items[] = {
        //{OB_DYN_MESH, "DYNAMIC_MESH", 0, "Dynamic Mesh", ""},
        {0, NULL, 0, NULL, NULL}};
 
+/* used for 2 enums */
+#define OBTYPE_CU_CURVE {OB_CURVE, "CURVE", 0, "Curve", ""}
+#define OBTYPE_CU_SURF {OB_SURF, "SURFACE", 0, "Surface", ""}
+#define OBTYPE_CU_TEXT {OB_FONT, "TEXT", 0, "Text", ""}
+    
 EnumPropertyItem object_type_items[] = {
        {OB_MESH, "MESH", 0, "Mesh", ""},
-       {OB_CURVE, "CURVE", 0, "Curve", ""},
-       {OB_SURF, "SURFACE", 0, "Surface", ""},
+       OBTYPE_CU_CURVE,
+       OBTYPE_CU_SURF,
        {OB_MBALL, "META", 0, "Meta", ""},
-       {OB_FONT, "TEXT", 0, "Text", ""},
+       OBTYPE_CU_TEXT,
        {0, "", 0, NULL, NULL},
        {OB_ARMATURE, "ARMATURE", 0, "Armature", ""},
        {OB_LATTICE, "LATTICE", 0, "Lattice", ""},
@@ -91,6 +96,12 @@ EnumPropertyItem object_type_items[] = {
        {OB_LAMP, "LAMP", 0, "Lamp", ""},
        {0, NULL, 0, NULL, NULL}};
 
+EnumPropertyItem object_type_curve_items[] = {
+       OBTYPE_CU_CURVE,
+       OBTYPE_CU_SURF,
+       OBTYPE_CU_TEXT,
+       {0, NULL, 0, NULL, NULL}};
+    
 #ifdef RNA_RUNTIME
 
 #include "BLI_math.h"