replace ELEM8(gs, ID_ME, ID_CU, ID_MB, ID_LT, ID_LA, ID_CA, ID_TXT, ID_SPK) with macro: OB_DATA_SUPPORT_ID()

This commit is contained in:
2012-08-12 14:57:19 +00:00
parent 82688e61fc
commit 32254596d4
6 changed files with 29 additions and 8 deletions

View 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;

View 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);

View 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)

View 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

View 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;

View 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;