From 11228cb4031c8e0a324d2ffa4463e2fb272f517c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 23 Aug 2010 00:57:19 +0000 Subject: rna: move metaball.active_element to metaball.elements.active added rna funcs... elem = metaball.elements.new() metaball.elements.remove(elem) --- source/blender/blenkernel/BKE_mball.h | 1 + source/blender/blenkernel/intern/mball.c | 49 ++++++++++ source/blender/editors/metaball/mball_edit.c | 51 +--------- source/blender/editors/object/object_add.c | 4 +- source/blender/makesrna/intern/rna_curve.c | 1 - source/blender/makesrna/intern/rna_meta.c | 104 +++++++++++++++++---- .../makesrna/rna_cleanup/rna_properties.txt | 3 +- 7 files changed, 143 insertions(+), 70 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h index 8d7d205e847..7fa4fc1a05e 100644 --- a/source/blender/blenkernel/BKE_mball.h +++ b/source/blender/blenkernel/BKE_mball.h @@ -162,6 +162,7 @@ void free_mball(struct MetaBall *mb); struct MetaBall *add_mball(char *name); struct MetaBall *copy_mball(struct MetaBall *mb); void make_local_mball(struct MetaBall *mb); +struct MetaElem *add_metaball_element(struct MetaBall *mb, const int type); void tex_space_mball(struct Object *ob); float *make_orco_mball(struct Object *ob, struct ListBase *dispbase); void copy_mball_properties(struct Scene *scene, struct Object *active_object); diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index e35d8bce886..e6f38e04d76 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -176,6 +176,55 @@ void make_local_mball(MetaBall *mb) } } } + +/* most simple meta-element adding function + * dont do context menipulation here (rna uses) */ +MetaElem *add_metaball_element(MetaBall *mb, const int type) +{ + MetaElem *ml= MEM_callocN(sizeof(MetaElem), "metaelem"); + + unit_qt(ml->quat); + + ml->rad= 2.0; + ml->s= 2.0; + ml->flag= MB_SCALE_RAD; + + switch(type) { + case MB_BALL: + ml->type = MB_BALL; + ml->expx= ml->expy= ml->expz= 1.0; + + break; + case MB_TUBE: + ml->type = MB_TUBE; + ml->expx= ml->expy= ml->expz= 1.0; + + break; + case MB_PLANE: + ml->type = MB_PLANE; + ml->expx= ml->expy= ml->expz= 1.0; + + break; + case MB_ELIPSOID: + ml->type = MB_ELIPSOID; + ml->expx= 1.2f; + ml->expy= 0.8f; + ml->expz= 1.0; + + break; + case MB_CUBE: + ml->type = MB_CUBE; + ml->expx= ml->expy= ml->expz= 1.0; + + break; + default: + break; + } + + BLI_addtail(&mb->elems, ml); + + return ml; +} /** Compute bounding box of all MetaElems/MetaBalls. * * Bounding box is computed from polygonized surface. Object *ob is diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index b59a0d3aaaf..80cea4eea1c 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -45,6 +45,7 @@ #include "BKE_depsgraph.h" #include "BKE_context.h" +#include "BKE_mball.h" #include "ED_screen.h" #include "ED_view3d.h" @@ -102,54 +103,12 @@ MetaElem *add_metaball_primitive(bContext *C, float mat[4][4], int type, int new ml->flag &= ~SELECT; ml= ml->next; } - - ml= MEM_callocN(sizeof(MetaElem), "metaelem"); - - ml->x= mat[3][0]; - ml->y= mat[3][1]; - ml->z= mat[3][2]; - ml->quat[0]= 1.0; - ml->quat[1]= 0.0; - ml->quat[2]= 0.0; - ml->quat[3]= 0.0; - ml->rad= 2.0; - ml->s= 2.0; - ml->flag= SELECT | MB_SCALE_RAD; - - switch(type) { - case MB_BALL: - ml->type = MB_BALL; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_TUBE: - ml->type = MB_TUBE; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_PLANE: - ml->type = MB_PLANE; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_ELIPSOID: - ml->type = MB_ELIPSOID; - ml->expx= 1.2f; - ml->expy= 0.8f; - ml->expz= 1.0; - - break; - case MB_CUBE: - ml->type = MB_CUBE; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - default: - break; - } + ml= add_metaball_element(mball, type); + copy_v3_v3(&ml->x, mat[3]); + + ml->flag |= SELECT; mball->lastelem= ml; - return ml; } diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index e60f9db79f6..d3debc84bdd 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -523,9 +523,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) ED_object_new_primitive_matrix(C, obedit, loc, rot, mat); elem= (MetaElem*)add_metaball_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob); - mball= (MetaBall*)obedit->data; - BLI_addtail(mball->editelems, elem); - + /* userdef */ if (newob && !enter_editmode) { ED_object_exit_editmode(C, EM_FREEDATA); diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c index cfca29aaa83..4995a50fff6 100644 --- a/source/blender/makesrna/intern/rna_curve.c +++ b/source/blender/makesrna/intern/rna_curve.c @@ -482,7 +482,6 @@ static Nurb *rna_Curve_spline_new(Curve *cu, int type) static void rna_Curve_spline_remove(Curve *cu, ReportList *reports, Nurb *nu) { - /* todo, check we're in the list */ int found= 0; ListBase *nurbs= BKE_curve_nurbs(cu); diff --git a/source/blender/makesrna/intern/rna_meta.c b/source/blender/makesrna/intern/rna_meta.c index 0de8455bdb7..59fff17b1ea 100644 --- a/source/blender/makesrna/intern/rna_meta.c +++ b/source/blender/makesrna/intern/rna_meta.c @@ -35,6 +35,8 @@ #include "BLI_math.h" +#include "MEM_guardedalloc.h" + #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -89,28 +91,66 @@ static void rna_MetaBall_update_data(Main *bmain, Scene *scene, PointerRNA *ptr) MetaBall *mb= ptr->id.data; Object *ob; - for(ob=bmain->object.first; ob; ob= ob->id.next) - if(ob->data == mb) - copy_mball_properties(scene, ob); + /* cheating way for importers to avoid slow updates */ + if(mb->id.us > 0) { + for(ob=bmain->object.first; ob; ob= ob->id.next) + if(ob->data == mb) + copy_mball_properties(scene, ob); + + DAG_id_flush_update(&mb->id, OB_RECALC_DATA); + WM_main_add_notifier(NC_GEOM|ND_DATA, mb); + } +} + +static MetaElem *rna_MetaBall_elements_new(MetaBall *mb, int type) +{ + MetaElem *ml= add_metaball_element(mb, type); + + /* cheating way for importers to avoid slow updates */ + if(mb->id.us > 0) { + DAG_id_flush_update(&mb->id, OB_RECALC_DATA); + WM_main_add_notifier(NC_GEOM|ND_DATA, &mb->id); + } - DAG_id_flush_update(&mb->id, OB_RECALC_DATA); - WM_main_add_notifier(NC_GEOM|ND_DATA, mb); + return ml; +} + +static void rna_MetaBall_elements_remove(MetaBall *mb, ReportList *reports, MetaElem *ml) +{ + int found= 0; + + found= BLI_remlink_safe(&mb->elems, ml); + + if(!found) { + BKE_reportf(reports, RPT_ERROR, "MetaBall \"%s\" does not contain spline given", mb->id.name+2); + return; + } + + MEM_freeN(ml); + /* invalidate pointer!, no can do */ + + /* cheating way for importers to avoid slow updates */ + if(mb->id.us > 0) { + DAG_id_flush_update(&mb->id, OB_RECALC_DATA); + WM_main_add_notifier(NC_GEOM|ND_DATA, &mb->id); + } } #else +static EnumPropertyItem metaelem_type_items[] = { + {MB_BALL, "BALL", ICON_META_BALL, "Ball", ""}, + {MB_TUBE, "TUBE", ICON_META_TUBE, "Tube", ""}, + {MB_PLANE, "PLANE", ICON_META_PLANE, "Plane", ""}, + {MB_ELIPSOID, "ELLIPSOID", ICON_META_ELLIPSOID, "Ellipsoid", ""}, // NOTE: typo at original definition! + {MB_CUBE, "CUBE", ICON_META_CUBE, "Cube", ""}, + {0, NULL, 0, NULL, NULL}}; + static void rna_def_metaelement(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - static EnumPropertyItem prop_type_items[] = { - {MB_BALL, "BALL", ICON_META_BALL, "Ball", ""}, - {MB_TUBE, "TUBE", ICON_META_TUBE, "Tube", ""}, - {MB_PLANE, "PLANE", ICON_META_PLANE, "Plane", ""}, - {MB_ELIPSOID, "ELLIPSOID", ICON_META_ELLIPSOID, "Ellipsoid", ""}, // NOTE: typo at original definition! - {MB_CUBE, "CUBE", ICON_META_CUBE, "Cube", ""}, - {0, NULL, 0, NULL, NULL}}; - + srna= RNA_def_struct(brna, "MetaElement", NULL); RNA_def_struct_sdna(srna, "MetaElem"); RNA_def_struct_ui_text(srna, "Meta Element", "Blobby element in a MetaBall datablock"); @@ -118,7 +158,7 @@ static void rna_def_metaelement(BlenderRNA *brna) /* enums */ prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_items(prop, prop_type_items); + RNA_def_property_enum_items(prop, metaelem_type_items); RNA_def_property_ui_text(prop, "Type", "Metaball types"); RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); @@ -176,6 +216,37 @@ static void rna_def_metaelement(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); } +/* mball.elements */ +static void rna_def_metaball_elements(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + PropertyRNA *prop; + + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "MetaBallElements"); + srna= RNA_def_struct(brna, "MetaBallElements", NULL); + RNA_def_struct_sdna(srna, "MetaBall"); + RNA_def_struct_ui_text(srna, "Meta Elements", "Collection of metaball elements"); + + func= RNA_def_function(srna, "new", "rna_MetaBall_elements_new"); + RNA_def_function_ui_description(func, "Add a new spline to the curve."); + parm= RNA_def_enum(func, "type", metaelem_type_items, MB_BALL, "", "type for the new meta element."); + parm= RNA_def_pointer(func, "element", "MetaElement", "", "The newly created metaelement."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "remove", "rna_MetaBall_elements_remove"); + RNA_def_function_ui_description(func, "Remove a spline from a curve."); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm= RNA_def_pointer(func, "element", "MetaElement", "", "The element to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "lastelem"); + RNA_def_property_ui_text(prop, "Active Element", "Last selected element"); +} + static void rna_def_metaball(BlenderRNA *brna) { StructRNA *srna; @@ -195,11 +266,8 @@ static void rna_def_metaball(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "elems", NULL); RNA_def_property_struct_type(prop, "MetaElement"); RNA_def_property_ui_text(prop, "Elements", "Meta elements"); + rna_def_metaball_elements(brna, prop); - prop= RNA_def_property(srna, "active_element", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "lastelem"); - RNA_def_property_ui_text(prop, "Last selected element.", "Last selected element"); - /* enums */ prop= RNA_def_property(srna, "update_method", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "flag"); diff --git a/source/blender/makesrna/rna_cleanup/rna_properties.txt b/source/blender/makesrna/rna_cleanup/rna_properties.txt index b319ce15ba1..87e0021bd5c 100644 --- a/source/blender/makesrna/rna_cleanup/rna_properties.txt +++ b/source/blender/makesrna/rna_cleanup/rna_properties.txt @@ -620,7 +620,7 @@ #+ * CurveMapping.curves -> curves: collection, "(read-only)" #CurveMapping.use_clip -> use_clip: boolean "Force the curve view to fit a defined boundary" #+ * CurveMapping.white_level -> white_level: float[3] "For RGB curves, the color that white is mapped to" -#TODO MOVE TO COLLECTION * CurveSplines.active -> active: pointer "Active curve spline" +#+ * CurveSplines.active -> active: pointer "Active curve spline" #DopeSheet.filter_group -> filter_group: pointer "Group that included Object should be a member of" #DopeSheet.show_armatures -> show_armatures: boolean "Include visualization of Armature related Animation data" #DopeSheet.show_cameras -> show_cameras: boolean "Include visualization of Camera related Animation data" @@ -1476,7 +1476,6 @@ #+ * ID|Mesh.uv_textures -> uv_textures: collection, "(read-only)" #+ * ID|Mesh.vertex_colors -> vertex_colors: collection, "(read-only)" #ID|Mesh.vertices -> vertices: collection, "(read-only) Vertices of the mesh" -#TODO MOVE TO ELEMENTS * ID|MetaBall.active_element -> active_element: pointer, "(read-only) Last selected element" #+ * ID|MetaBall.animation_data -> animation_data: pointer, "(read-only) Animation data for this datablock" #+ * ID|MetaBall.elements -> elements: collection, "(read-only) Meta elements" #+ * ID|MetaBall.materials -> materials: collection, "(read-only)" -- cgit v1.2.3