replace ELEM8(gs, ID_ME, ID_CU, ID_MB, ID_LT, ID_LA, ID_CA, ID_TXT, ID_SPK) with...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 12 Aug 2012 14:57:19 +0000 (14:57 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 12 Aug 2012 14:57:19 +0000 (14:57 +0000)
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/material.c
source/blender/editors/object/object_select.c
source/blender/makesdna/DNA_object_types.h
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_object.c

index 87ebc597ecd6ff16d3b15e442c23bd3adc297d99..b22e24e15d4af9c6df486067706ee1b1444836bb 100644 (file)
@@ -2596,7 +2596,8 @@ static void dag_id_flush_update(Scene *sce, ID *id)
        if (id) {
                idtype = GS(id->name);
 
-               if (ELEM8(idtype, ID_ME, ID_CU, ID_MB, ID_LA, ID_LT, ID_CA, ID_AR, ID_SPK)) {
+
+               if (OB_DATA_SUPPORT_ID(idtype)) {
                        for (obt = bmain->object.first; obt; obt = obt->id.next) {
                                if (!(ob && obt == ob) && obt->data == id) {
                                        obt->recalc |= OB_RECALC_DATA;
index f97dd2f859dd412e1cd79862f0bdc122e7392653..f888cf60a2457bdd1886c689c1d84e7972bfc0d3 100644 (file)
@@ -494,6 +494,9 @@ short *give_totcolp(Object *ob)
 /* same as above but for ID's */
 Material ***give_matarar_id(ID *id)
 {
+       /* ensure we don't try get materials from non-obdata */
+       BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
+
        switch (GS(id->name)) {
                case ID_ME:
                        return &(((Mesh *)id)->mat);
@@ -510,6 +513,9 @@ Material ***give_matarar_id(ID *id)
 
 short *give_totcolp_id(ID *id)
 {
+       /* ensure we don't try get materials from non-obdata */
+       BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
+
        switch (GS(id->name)) {
                case ID_ME:
                        return &(((Mesh *)id)->totcol);
@@ -526,6 +532,9 @@ short *give_totcolp_id(ID *id)
 
 static void data_delete_material_index_id(ID *id, short index)
 {
+       /* ensure we don't try get materials from non-obdata */
+       BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
+
        switch (GS(id->name)) {
                case ID_ME:
                        BKE_mesh_delete_material_index((Mesh *)id, index);
index ac3210348de62924b364287fdf5c98323760ca14..ff7728d4f68d422c8e8364a4e7118a9b9afa3136 100644 (file)
@@ -388,21 +388,22 @@ static int object_select_all_by_library_obdata(bContext *C, Library *lib)
 
 void ED_object_select_linked_by_id(bContext *C, ID *id)
 {
-       int gs = GS(id->name);
+       int idtype = GS(id->name);
        int changed = FALSE;
 
-       if (ELEM8(gs, ID_ME, ID_CU, ID_MB, ID_LT, ID_LA, ID_CA, ID_TXT, ID_SPK)) {
+       if (OB_DATA_SUPPORT_ID(idtype)) {
                changed = object_select_all_by_obdata(C, id);
        }
-       else if (gs == ID_MA) {
+       else if (idtype == ID_MA) {
                changed = object_select_all_by_material_texture(C, FALSE, (Material *)id, NULL);
        }
-       else if (gs == ID_LI) {
+       else if (idtype == ID_LI) {
                changed = object_select_all_by_library(C, (Library *) id);
        }
 
-       if (changed)
+       if (changed) {
                WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
+       }
 }
 
 static int object_select_linked_exec(bContext *C, wmOperator *op)
index 3da6d0fc99d5a8cca8e16a03a8346e01a41dfa1a..597103a78df6b0a08d4f710991671d445a09363a 100644 (file)
@@ -343,6 +343,10 @@ typedef struct DupliObject {
 #define OB_TYPE_SUPPORT_EDITMODE(_type) \
        (ELEM7(_type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE))
 
+/* is this ID type used as object data */
+#define OB_DATA_SUPPORT_ID(_id_type) \
+       (ELEM8(_id_type, ID_ME, ID_CU, ID_MB, ID_LA, ID_SPK, ID_CA, ID_LT, ID_AR))
+
 /* partype: first 4 bits: type */
 #define PARTYPE                        15
 #define PAROBJECT              0
index c702972b3b71dfc2be3eae2c1ee45a2385c5031b..59eae3259b4a4c9cdc34d4873e3674540eafe95a 100644 (file)
@@ -140,6 +140,7 @@ Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, const cha
        Object *ob;
        int type = OB_EMPTY;
        if (data) {
+               /* keep in sync with OB_DATA_SUPPORT_ID() macro */
                switch (GS(data->name)) {
                        case ID_ME:
                                type = OB_MESH;
index 7aedbf40eba6d1df6fac011a48c125071cb3e47b..9770b51654c77eaff65732a293e87337a9f23f96 100644 (file)
@@ -355,10 +355,14 @@ static void rna_Object_data_set(PointerRNA *ptr, PointerRNA value)
                set_mesh(ob, (Mesh *)id);
        }
        else {
-               if (ob->data)
+               if (ob->data) {
                        id_us_min((ID *)ob->data);
-               if (id)
+               }
+               if (id) {
+                       /* no need to type-check here ID. this is done in the _typef() function */
+                       BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
                        id_us_plus(id);
+               }
 
                ob->data = id;
                test_object_materials(id);
@@ -374,6 +378,7 @@ static StructRNA *rna_Object_data_typef(PointerRNA *ptr)
 {
        Object *ob = (Object *)ptr->data;
 
+       /* keep in sync with OB_DATA_SUPPORT_ID() macro */
        switch (ob->type) {
                case OB_EMPTY: return &RNA_Image;
                case OB_MESH: return &RNA_Mesh;