diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-09-05 00:51:09 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-09-05 00:51:09 +0400 |
commit | 7df35db1b1364dcd81dd8247ad3707d40a78fd59 (patch) | |
tree | fb967409fddbb02ee70fbdfa1e404fae115a312e /source/blender/editors/object | |
parent | 5342f7930fb26855b92f337ace45f2ee51153957 (diff) |
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
Diffstat (limited to 'source/blender/editors/object')
-rw-r--r-- | source/blender/editors/object/editconstraint.c | 13 | ||||
-rw-r--r-- | source/blender/editors/object/editkey.c | 107 | ||||
-rw-r--r-- | source/blender/editors/object/editlattice.c | 9 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 55 | ||||
-rw-r--r-- | source/blender/editors/object/object_modifier.c | 52 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 80 |
6 files changed, 111 insertions, 205 deletions
diff --git a/source/blender/editors/object/editconstraint.c b/source/blender/editors/object/editconstraint.c index dc0442a5af9..c1b1062bfc4 100644 --- a/source/blender/editors/object/editconstraint.c +++ b/source/blender/editors/object/editconstraint.c @@ -825,7 +825,6 @@ void CONSTRAINT_OT_move_up (wmOperatorType *ot) static int pose_constraints_clear_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); /* free constraints for all selected bones */ @@ -836,7 +835,7 @@ static int pose_constraints_clear_exec(bContext *C, wmOperator *op) CTX_DATA_END; /* do updates */ - DAG_object_flush_update(scene, ob, OB_RECALC_OB); + DAG_id_flush_update(&ob->id, OB_RECALC_OB); WM_event_add_notifier(C, NC_OBJECT|ND_POSE|ND_CONSTRAINT|NA_REMOVED, ob); return OPERATOR_FINISHED; @@ -857,7 +856,6 @@ void POSE_OT_constraints_clear(wmOperatorType *ot) static int object_constraints_clear_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); /* do freeing */ @@ -865,7 +863,7 @@ static int object_constraints_clear_exec(bContext *C, wmOperator *op) free_constraints(&ob->constraints); /* do updates */ - DAG_object_flush_update(scene, ob, OB_RECALC_OB); + DAG_id_flush_update(&ob->id, OB_RECALC_OB); WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_REMOVED, ob); return OPERATOR_FINISHED; @@ -1138,10 +1136,10 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase if ((ob->type==OB_ARMATURE) && (pchan)) { ob->pose->flag |= POSE_RECALC; /* sort pose channels */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA|OB_RECALC_OB); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA|OB_RECALC_OB); } else - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* notifiers for updates */ WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, ob); @@ -1376,7 +1374,6 @@ void POSE_OT_ik_add(wmOperatorType *ot) /* remove IK constraints from selected bones */ static int pose_ik_clear_exec(bContext *C, wmOperator *op) { - Scene *scene = CTX_data_scene(C); Object *ob= CTX_data_active_object(C); /* only remove IK Constraints */ @@ -1397,7 +1394,7 @@ static int pose_ik_clear_exec(bContext *C, wmOperator *op) CTX_DATA_END; /* */ - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_REMOVED, ob); diff --git a/source/blender/editors/object/editkey.c b/source/blender/editors/object/editkey.c index 82194a4c3b4..2ec3edd846a 100644 --- a/source/blender/editors/object/editkey.c +++ b/source/blender/editors/object/editkey.c @@ -473,7 +473,7 @@ int ED_object_shape_key_remove(bContext *C, Scene *scene, Object *ob) free_libblock_us(&(bmain->key), key); } - DAG_object_flush_update(scene, OBACT, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); return 1; @@ -481,14 +481,18 @@ int ED_object_shape_key_remove(bContext *C, Scene *scene, Object *ob) /********************** shape key operators *********************/ +static int shape_key_poll(bContext *C) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + ID *data= (ob)? ob->data: NULL; + return (ob && !ob->id.lib && data && !data->lib); +} + static int shape_key_add_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - if(!ob) - return OPERATOR_CANCELLED; - ED_object_shape_key_add(C, scene, ob); return OPERATOR_FINISHED; @@ -501,6 +505,7 @@ void OBJECT_OT_shape_key_add(wmOperatorType *ot) ot->idname= "OBJECT_OT_shape_key_add"; /* api callbacks */ + ot->poll= shape_key_poll; ot->exec= shape_key_add_exec; /* flags */ @@ -509,12 +514,9 @@ void OBJECT_OT_shape_key_add(wmOperatorType *ot) static int shape_key_remove_exec(bContext *C, wmOperator *op) { - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - if(!ob) - return OPERATOR_CANCELLED; - if(!ED_object_shape_key_remove(C, scene, ob)) return OPERATOR_CANCELLED; @@ -528,97 +530,10 @@ void OBJECT_OT_shape_key_remove(wmOperatorType *ot) ot->idname= "OBJECT_OT_shape_key_remove"; /* api callbacks */ + ot->poll= shape_key_poll; ot->exec= shape_key_remove_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -void move_keys(Object *ob) -{ -#if 0 - /* XXX probably goes away entirely */ - Key *key; - KeyBlock *kb; - float div, dy, oldpos, vec[3], dvec[3]; - int afbreek=0, firsttime= 1; - unsigned short event = 0; - short mval[2], val, xo, yo; - char str[32]; - - if(G.sipo->blocktype!=ID_KE) return; - - if(G.sipo->ipo && G.sipo->ipo->id.lib) return; - if(G.sipo->editipo==NULL) return; - - key= ob_get_key(ob); - if(key==NULL) return; - - /* which kb is involved */ - kb= BLI_findlink(&key->block, ob->shapenr-1); - if(kb==NULL) return; - - oldpos= kb->pos; - - getmouseco_areawin(mval); - xo= mval[0]; - yo= mval[1]; - dvec[0]=dvec[1]=dvec[2]= 0.0; - - while(afbreek==0) { - getmouseco_areawin(mval); - if(mval[0]!=xo || mval[1]!=yo || firsttime) { - firsttime= 0; - - dy= (float)(mval[1]- yo); - - div= (float)(G.v2d->mask.ymax-G.v2d->mask.ymin); - dvec[1]+= (G.v2d->cur.ymax-G.v2d->cur.ymin)*(dy)/div; - - VECCOPY(vec, dvec); - - apply_keyb_grid(vec, 0.0, 1.0, 0.1, U.flag & USER_AUTOGRABGRID); - apply_keyb_grid(vec+1, 0.0, 1.0, 0.1, U.flag & USER_AUTOGRABGRID); - - kb->pos= oldpos+vec[1]; - - sprintf(str, "Y: %.3f ", vec[1]); - headerprint(str); - - xo= mval[0]; - yo= mval[1]; - - force_draw(0); - } - else BIF_wait_for_statechange(); - - while(qtest()) { - event= extern_qread(&val); - if(val) { - switch(event) { - case ESCKEY: - case LEFTMOUSE: - case SPACEKEY: - afbreek= 1; - break; - default: - arrows_move_cursor(event); - } - } - } - } - - if(event==ESCKEY) { - kb->pos= oldpos; - } - - sort_keys(key); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - - /* for boundbox */ - editipo_changed(G.sipo, 0); - - BIF_undo_push("Move Shapekey(s)"); -#endif -} - diff --git a/source/blender/editors/object/editlattice.c b/source/blender/editors/object/editlattice.c index 3e30efd635a..3ec1f3af014 100644 --- a/source/blender/editors/object/editlattice.c +++ b/source/blender/editors/object/editlattice.c @@ -203,7 +203,7 @@ int de_select_all_exec(bContext *C, wmOperator *op) else setflagsLatt(obedit, 1); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); return OPERATOR_FINISHED; } @@ -234,7 +234,6 @@ int make_regular_poll(bContext *C) int make_regular_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_edit_object(C); Lattice *lt; @@ -248,8 +247,8 @@ int make_regular_exec(bContext *C, wmOperator *op) resizelattice(lt, lt->pntsu, lt->pntsv, lt->pntsw, NULL); } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); return OPERATOR_FINISHED; } @@ -318,7 +317,7 @@ void mouse_lattice(bContext *C, short mval[2], int extend) else bp->f1 ^= SELECT; /* swap */ - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, vc.obedit); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit->data); } } diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index a5e92096ef9..53882ad8424 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -193,7 +193,7 @@ void ED_base_object_activate(bContext *C, Base *base) for(tbase=FIRSTBASE; tbase; tbase= tbase->next) { if(base!=tbase && (tbase->object->shapeflag & OB_SHAPE_TEMPLOCK)) { tbase->object->shapeflag &= ~OB_SHAPE_TEMPLOCK; - DAG_object_flush_update(scene, tbase->object, OB_RECALC_DATA); + DAG_id_flush_update(&tbase->object->id, OB_RECALC_DATA); } } WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene); @@ -343,7 +343,7 @@ static int object_add_mesh_exec(bContext *C, wmOperator *op) ED_object_enter_editmode(C, EM_DO_UNDO); newob = 1; } - else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA); + else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); switch(RNA_enum_get(op->ptr, "type")) { case 0: @@ -379,7 +379,7 @@ static int object_add_mesh_exec(bContext *C, wmOperator *op) ED_object_exit_editmode(C, EM_FREEDATA); } - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); return OPERATOR_FINISHED; } @@ -425,7 +425,7 @@ static int object_add_curve_exec(bContext *C, wmOperator *op) ED_object_enter_editmode(C, 0); newob = 1; } - else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA); + else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); obedit= CTX_data_edit_object(C); nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob); @@ -437,7 +437,7 @@ static int object_add_curve_exec(bContext *C, wmOperator *op) ED_object_exit_editmode(C, EM_FREEDATA); } - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); return OPERATOR_FINISHED; } @@ -500,7 +500,7 @@ static int object_add_surface_exec(bContext *C, wmOperator *op) ED_object_enter_editmode(C, 0); newob = 1; } - else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA); + else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); obedit= CTX_data_edit_object(C); nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob); @@ -512,7 +512,7 @@ static int object_add_surface_exec(bContext *C, wmOperator *op) ED_object_exit_editmode(C, EM_FREEDATA); } - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); return OPERATOR_FINISHED; } @@ -557,7 +557,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) ED_object_enter_editmode(C, 0); newob = 1; } - else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA); + else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); obedit= CTX_data_edit_object(C); elem= (MetaElem*)add_metaball_primitive(C, RNA_enum_get(op->ptr, "type"), newob); @@ -569,7 +569,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) ED_object_exit_editmode(C, EM_FREEDATA); } - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); return OPERATOR_FINISHED; } @@ -621,7 +621,7 @@ static int object_add_text_exec(bContext *C, wmOperator *op) if(U.flag & USER_ADD_EDITMODE) ED_object_enter_editmode(C, 0); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); return OPERATOR_FINISHED; } @@ -653,7 +653,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) ED_object_enter_editmode(C, 0); newob = 1; } - else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA); + else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); if(v3d) rv3d= CTX_wm_region(C)->regiondata; @@ -666,7 +666,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) ED_object_exit_editmode(C, EM_FREEDATA); } - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); return OPERATOR_FINISHED; } @@ -3034,7 +3034,7 @@ static int make_proxy_exec (bContext *C, wmOperator *op) /* depsgraph flushes are needed for the new data */ DAG_scene_sort(scene); - DAG_object_flush_update(scene, newob, OB_RECALC); + DAG_id_flush_update(&newob->id, OB_RECALC); WM_event_add_notifier(C, NC_OBJECT, NULL); } @@ -3543,7 +3543,7 @@ static int object_center_set_exec(bContext *C, wmOperator *op) recalc_editnormals(em); tot_change++; - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); + DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); BKE_mesh_end_editmesh(me, em); } } @@ -3735,7 +3735,7 @@ static int object_center_set_exec(bContext *C, wmOperator *op) tot_change++; if(obedit) { if (centermode==0) { - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); + DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); } break; } @@ -3884,7 +3884,7 @@ void ED_object_exit_editmode(bContext *C, int flag) scene->obedit= NULL; // XXX for context /* also flush ob recalc, doesn't take much overhead, but used for particles */ - DAG_object_flush_update(scene, obedit, OB_RECALC_OB|OB_RECALC_DATA); + DAG_id_flush_update(&obedit->id, OB_RECALC_OB|OB_RECALC_DATA); ED_undo_push(C, "Editmode"); @@ -3963,7 +3963,7 @@ void ED_object_enter_editmode(bContext *C, int flag) scene->obedit= ob; ED_armature_to_edit(ob); /* to ensure all goes in restposition and without striding */ - DAG_object_flush_update(scene, ob, OB_RECALC); + DAG_id_flush_update(&ob->id, OB_RECALC); WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_ARMATURE, scene); } @@ -3997,7 +3997,7 @@ void ED_object_enter_editmode(bContext *C, int flag) } if(ok) { - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } else { scene->obedit= NULL; // XXX for context @@ -4327,7 +4327,7 @@ void special_editmenu(Scene *scene, View3D *v3d) } } } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } else if(ob->mode & OB_MODE_VERTEX_PAINT) { Mesh *me= get_mesh(ob); @@ -4339,7 +4339,7 @@ void special_editmenu(Scene *scene, View3D *v3d) // XXX do_shared_vertexcol(me); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } } else if(ob->mode & OB_MODE_WEIGHT_PAINT) { @@ -4386,7 +4386,7 @@ void special_editmenu(Scene *scene, View3D *v3d) break; } - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); + DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); if(nr>0) waitcursor(0); #endif @@ -4809,7 +4809,7 @@ static void object_flip_subdivison_particles(Scene *scene, Object *ob, int *set, } } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } if(ob->dup_group && depth<=4) { @@ -6790,7 +6790,6 @@ void OBJECT_OT_join(wmOperatorType *ot) static int shade_smooth_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob; Curve *cu; Nurb *nu; @@ -6803,7 +6802,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) if(ob->type==OB_MESH) { mesh_set_smooth_flag(ob, !clear); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); done= 1; @@ -6817,7 +6816,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) nu= nu->next; } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); done= 1; @@ -6904,7 +6903,7 @@ void image_aspect(Scene *scene, View3D *v3d) else ob->size[1]= ob->size[0]*y/x; done= 1; - DAG_object_flush_update(scene, ob, OB_RECALC_OB); + DAG_id_flush_update(&ob->id, OB_RECALC_OB); } } if(done) break; @@ -7184,7 +7183,7 @@ void hookmenu(Scene *scene, View3D *v3d) Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); changed= 1; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } } else { float *curs = give_cursor(scene, v3d); @@ -7202,7 +7201,7 @@ void hookmenu(Scene *scene, View3D *v3d) Mat3MulVecfl(imat, hmd->cent); changed= 1; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } } } diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 96e485e5462..aecb778db06 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -119,7 +119,7 @@ int ED_object_modifier_add(ReportList *reports, Scene *scene, Object *ob, int ty DAG_scene_sort(scene); } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); return 1; } @@ -168,7 +168,7 @@ int ED_object_modifier_remove(ReportList *reports, Scene *scene, Object *ob, Mod BLI_remlink(&ob->modifiers, md); modifier_free(md); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); return 1; } @@ -376,7 +376,7 @@ int ED_object_modifier_apply(ReportList *reports, Scene *scene, Object *ob, Modi MEM_freeN(vertexCos); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } else { BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type"); @@ -408,7 +408,8 @@ int ED_object_modifier_copy(ReportList *reports, Object *ob, ModifierData *md) static int modifier_poll(bContext *C) { - return (CTX_data_pointer_get_type(C, "modifier", &RNA_Modifier).data != NULL); + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_Modifier); + return (ptr.data != NULL && !((ID*)ptr.id.data)->lib); } /************************ add modifier operator *********************/ @@ -518,7 +519,6 @@ void OBJECT_OT_modifier_remove(wmOperatorType *ot) static int modifier_move_up_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_Modifier); Object *ob= ptr.id.data; ModifierData *md= ptr.data; @@ -526,7 +526,7 @@ static int modifier_move_up_exec(bContext *C, wmOperator *op) if(!ED_object_modifier_move_up(op->reports, ob, md)) return OPERATOR_CANCELLED; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; @@ -550,7 +550,6 @@ void OBJECT_OT_modifier_move_up(wmOperatorType *ot) static int modifier_move_down_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_Modifier); Object *ob= ptr.id.data; ModifierData *md= ptr.data; @@ -558,7 +557,7 @@ static int modifier_move_down_exec(bContext *C, wmOperator *op) if(!ob || !md || !ED_object_modifier_move_down(op->reports, ob, md)) return OPERATOR_CANCELLED; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; @@ -590,7 +589,7 @@ static int modifier_apply_exec(bContext *C, wmOperator *op) if(!ob || !md || !ED_object_modifier_apply(op->reports, scene, ob, md)) return OPERATOR_CANCELLED; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; @@ -622,7 +621,7 @@ static int modifier_convert_exec(bContext *C, wmOperator *op) if(!ob || !md || !ED_object_modifier_convert(op->reports, scene, ob, md)) return OPERATOR_CANCELLED; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; @@ -646,7 +645,6 @@ void OBJECT_OT_modifier_convert(wmOperatorType *ot) static int modifier_copy_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_Modifier); Object *ob= ptr.id.data; ModifierData *md= ptr.data; @@ -654,7 +652,7 @@ static int modifier_copy_exec(bContext *C, wmOperator *op) if(!ob || !md || !ED_object_modifier_copy(op->reports, ob, md)) return OPERATOR_CANCELLED; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; @@ -718,8 +716,9 @@ static int multires_subdivide_exec(bContext *C, wmOperator *op) static int multires_subdivide_poll(bContext *C) { - return (CTX_data_pointer_get_type(C, "modifier", &RNA_MultiresModifier).data != NULL) && - CTX_data_edit_object(C) == NULL; + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_MultiresModifier); + ID *id= ptr.id.data; + return (ptr.data && id && !id->lib); } void OBJECT_OT_multires_subdivide(wmOperatorType *ot) @@ -739,7 +738,9 @@ void OBJECT_OT_multires_subdivide(wmOperatorType *ot) static int meshdeform_poll(bContext *C) { - return CTX_data_pointer_get_type(C, "modifier", &RNA_MeshDeformModifier).data != NULL; + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_MeshDeformModifier); + ID *id= ptr.id.data; + return (ptr.data && id && !id->lib); } static int meshdeform_bind_exec(bContext *C, wmOperator *op) @@ -864,12 +865,13 @@ static uiBlock *modifiers_add_menu(void *ob_v) static int hook_poll(bContext *C) { - return CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier).data != NULL; + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); + ID *id= ptr.id.data; + return (ptr.data && id && !id->lib); } static int hook_reset_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); Object *ob= ptr.id.data; HookModifierData *hmd= ptr.data; @@ -892,7 +894,7 @@ static int hook_reset_exec(bContext *C, wmOperator *op) } } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; @@ -925,7 +927,7 @@ static int hook_recenter_exec(bContext *C, wmOperator *op) VECSUB(hmd->cent, scene->cursor, ob->obmat[3]); Mat3MulVecfl(imat, hmd->cent); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; @@ -952,7 +954,7 @@ static int hook_select_exec(bContext *C, wmOperator *op) object_hook_select(ob, hmd); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); return OPERATOR_FINISHED; } @@ -972,7 +974,6 @@ void OBJECT_OT_hook_select(wmOperatorType *ot) static int hook_assign_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); Object *ob= ptr.id.data; HookModifierData *hmd= ptr.data; @@ -992,7 +993,7 @@ static int hook_assign_exec(bContext *C, wmOperator *op) hmd->indexar= indexar; hmd->totindex= tot; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; @@ -1015,19 +1016,20 @@ void OBJECT_OT_hook_assign(wmOperatorType *ot) static int explode_refresh_poll(bContext *C) { - return CTX_data_pointer_get_type(C, "modifier", &RNA_ExplodeModifier).data != NULL; + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_ExplodeModifier); + ID *id= ptr.id.data; + return (ptr.data && id && !id->lib); } static int explode_refresh_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_ExplodeModifier); Object *ob= ptr.id.data; ExplodeModifierData *emd= ptr.data; emd->flag |= eExplodeFlag_CalcFaces; - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 767a04d9170..1660160b56c 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1102,17 +1102,21 @@ void vgroup_operation_with_menu(Object *ob) /********************** vertex group operators *********************/ -static int vertex_group_add_exec(bContext *C, wmOperator *op) +static int vertex_group_poll(bContext *C) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - Scene *scene= CTX_data_scene(C); + ID *data= (ob)? ob->data: NULL; + return (ob && !ob->id.lib && data && !data->lib); +} - if(!ob) - return OPERATOR_CANCELLED; +static int vertex_group_add_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; add_defgroup(ob); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); return OPERATOR_FINISHED; } @@ -1124,6 +1128,7 @@ void OBJECT_OT_vertex_group_add(wmOperatorType *ot) ot->idname= "OBJECT_OT_vertex_group_add"; /* api callbacks */ + ot->poll= vertex_group_poll; ot->exec= vertex_group_add_exec; /* flags */ @@ -1135,18 +1140,16 @@ static int vertex_group_remove_exec(bContext *C, wmOperator *op) Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; Scene *scene= CTX_data_scene(C); - if(!ob) - return OPERATOR_CANCELLED; - if(scene->obedit == ob) { del_defgroup(ob); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); } else { del_defgroup_in_object_mode(ob); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); } + + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); return OPERATOR_FINISHED; } @@ -1158,6 +1161,7 @@ void OBJECT_OT_vertex_group_remove(wmOperatorType *ot) ot->idname= "OBJECT_OT_vertex_group_remove"; /* api callbacks */ + ot->poll= vertex_group_poll; ot->exec= vertex_group_remove_exec; /* flags */ @@ -1166,16 +1170,12 @@ void OBJECT_OT_vertex_group_remove(wmOperatorType *ot) static int vertex_group_assign_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); ToolSettings *ts= CTX_data_tool_settings(C); Object *ob= CTX_data_edit_object(C); - if(!ob) - return OPERATOR_CANCELLED; - assign_verts_defgroup(ob, ts->vgroup_weight); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); return OPERATOR_FINISHED; } @@ -1187,6 +1187,7 @@ void OBJECT_OT_vertex_group_assign(wmOperatorType *ot) ot->idname= "OBJECT_OT_vertex_group_assign"; /* api callbacks */ + ot->poll= vertex_group_poll; ot->exec= vertex_group_assign_exec; /* flags */ @@ -1195,15 +1196,11 @@ void OBJECT_OT_vertex_group_assign(wmOperatorType *ot) static int vertex_group_remove_from_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_edit_object(C); - if(!ob) - return OPERATOR_CANCELLED; - remove_verts_defgroup(ob, 0); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); return OPERATOR_FINISHED; } @@ -1215,6 +1212,7 @@ void OBJECT_OT_vertex_group_remove_from(wmOperatorType *ot) ot->idname= "OBJECT_OT_vertex_group_remove_from"; /* api callbacks */ + ot->poll= vertex_group_poll; ot->exec= vertex_group_remove_from_exec; /* flags */ @@ -1225,11 +1223,11 @@ static int vertex_group_select_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_edit_object(C); - if(!ob) + if(!ob || ob->id.lib) return OPERATOR_CANCELLED; - sel_verts_defgroup(ob, 1); /* runs countall() */ - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob); + sel_verts_defgroup(ob, 1); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); return OPERATOR_FINISHED; } @@ -1241,6 +1239,7 @@ void OBJECT_OT_vertex_group_select(wmOperatorType *ot) ot->idname= "OBJECT_OT_vertex_group_select"; /* api callbacks */ + ot->poll= vertex_group_poll; ot->exec= vertex_group_select_exec; /* flags */ @@ -1251,11 +1250,8 @@ static int vertex_group_deselect_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_edit_object(C); - if(!ob) - return OPERATOR_CANCELLED; - - sel_verts_defgroup(ob, 0); /* runs countall() */ - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob); + sel_verts_defgroup(ob, 0); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); return OPERATOR_FINISHED; } @@ -1267,6 +1263,7 @@ void OBJECT_OT_vertex_group_deselect(wmOperatorType *ot) ot->idname= "OBJECT_OT_vertex_group_deselect"; /* api callbacks */ + ot->poll= vertex_group_poll; ot->exec= vertex_group_deselect_exec; /* flags */ @@ -1275,15 +1272,12 @@ void OBJECT_OT_vertex_group_deselect(wmOperatorType *ot) static int vertex_group_copy_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - if(!ob) - return OPERATOR_CANCELLED; - duplicate_defgroup(ob); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); return OPERATOR_FINISHED; } @@ -1295,6 +1289,7 @@ void OBJECT_OT_vertex_group_copy(wmOperatorType *ot) ot->idname= "OBJECT_OT_vertex_group_copy"; /* api callbacks */ + ot->poll= vertex_group_poll; ot->exec= vertex_group_copy_exec; /* flags */ @@ -1308,9 +1303,6 @@ static int vertex_group_copy_to_linked_exec(bContext *C, wmOperator *op) Base *base; int retval= OPERATOR_CANCELLED; - if(!ob) - return retval; - for(base=scene->base.first; base; base= base->next) { if(base->object->type==ob->type) { if(base->object!=ob && base->object->data==ob->data) { @@ -1318,8 +1310,9 @@ static int vertex_group_copy_to_linked_exec(bContext *C, wmOperator *op) BLI_duplicatelist(&base->object->defbase, &ob->defbase); base->object->actdef= ob->actdef; - DAG_object_flush_update(scene, base->object, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, base->object); + DAG_id_flush_update(&base->object->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, base->object); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, base->object->data); retval = OPERATOR_FINISHED; } @@ -1336,6 +1329,7 @@ void OBJECT_OT_vertex_group_copy_to_linked(wmOperatorType *ot) ot->idname= "OBJECT_OT_vertex_group_copy_to_linked"; /* api callbacks */ + ot->poll= vertex_group_poll; ot->exec= vertex_group_copy_to_linked_exec; /* flags */ |