static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf) { Object *obedit = CTX_data_edit_object(C); ListBase *editnurb; Nurb *nu; bool newob = false; bool enter_editmode; unsigned int layer; float dia; float loc[3], rot[3]; float mat[4][4]; WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL)) return OPERATOR_CANCELLED; if (!isSurf) { /* adding curve */ if (obedit == NULL || obedit->type != OB_CURVE) { Curve *cu; obedit = ED_object_add_type(C, OB_CURVE, loc, rot, true, layer); newob = true; cu = (Curve *)obedit->data; cu->flag |= CU_DEFORM_FILL; if (type & CU_PRIM_PATH) cu->flag |= CU_PATH | CU_3D; } else { DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); } } else { /* adding surface */ if (obedit == NULL || obedit->type != OB_SURF) { obedit = ED_object_add_type(C, OB_SURF, loc, rot, true, layer); newob = true; } else { DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); } } /* rename here, the undo stack checks name for valid undo pushes */ if (newob) { if (obedit->type == OB_CURVE) { rename_id((ID *)obedit, get_curve_defname(type)); rename_id((ID *)obedit->data, get_curve_defname(type)); } else { rename_id((ID *)obedit, get_surf_defname(type)); rename_id((ID *)obedit->data, get_surf_defname(type)); } } /* ED_object_add_type doesnt do an undo, is needed for redo operator on primitive */ if (newob && enter_editmode) ED_undo_push(C, "Enter Editmode"); ED_object_new_primitive_matrix(C, obedit, loc, rot, mat); dia = RNA_float_get(op->ptr, "radius"); mul_mat3_m4_fl(mat, dia); nu = add_nurbs_primitive(C, obedit, mat, type, newob); editnurb = object_editcurve_get(obedit); BLI_addtail(editnurb, nu); /* userdef */ if (newob && !enter_editmode) { ED_object_editmode_exit(C, EM_FREEDATA); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); return OPERATOR_FINISHED; }
static int outliner_object_operation_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); SpaceOops *soops = CTX_wm_space_outliner(C); int event; const char *str = NULL; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; event = RNA_enum_get(op->ptr, "type"); if (event == OL_OP_SELECT) { Scene *sce = scene; // to be able to delete, scenes are set... outliner_do_object_operation(C, scene, soops, &soops->tree, object_select_cb); if (scene != sce) { ED_screen_set_scene(C, CTX_wm_screen(C), sce); } str = "Select Objects"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_SELECT_HIERARCHY) { Scene *sce = scene; // to be able to delete, scenes are set... outliner_do_object_operation(C, scene, soops, &soops->tree, object_select_hierarchy_cb); if (scene != sce) { ED_screen_set_scene(C, CTX_wm_screen(C), sce); } str = "Select Object Hierarchy"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_DESELECT) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_deselect_cb); str = "Deselect Objects"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_DELETE) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb); /* XXX: tree management normally happens from draw_outliner(), but when * you're clicking to fast on Delete object from context menu in * outliner several mouse events can be handled in one cycle without * handling notifiers/redraw which leads to deleting the same object twice. * cleanup tree here to prevent such cases. */ outliner_cleanup_tree(soops); DAG_relations_tag_update(bmain); str = "Delete Objects"; WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); } else if (event == OL_OP_DELETE_HIERARCHY) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_hierarchy_cb); /* XXX: See OL_OP_DELETE comment above. */ outliner_cleanup_tree(soops); DAG_relations_tag_update(bmain); str = "Delete Object Hierarchy"; WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); } else if (event == OL_OP_LOCALIZED) { /* disabled, see above enum (ton) */ outliner_do_object_operation(C, scene, soops, &soops->tree, id_local_cb); str = "Localized Objects"; } else if (event == OL_OP_TOGVIS) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb); str = "Toggle Visibility"; WM_event_add_notifier(C, NC_SCENE | ND_OB_VISIBLE, scene); } else if (event == OL_OP_TOGSEL) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb); str = "Toggle Selectability"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_TOGREN) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb); str = "Toggle Renderability"; WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene); } else if (event == OL_OP_RENAME) { outliner_do_object_operation(C, scene, soops, &soops->tree, item_rename_cb); str = "Rename Object"; } else { BLI_assert(0); return OPERATOR_CANCELLED; } ED_undo_push(C, str); return OPERATOR_FINISHED; }
static int outliner_data_operation_exec(bContext *C, wmOperator *op) { SpaceOops *soops = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; eOutliner_PropDataOps event; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; event = RNA_enum_get(op->ptr, "type"); set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); switch (datalevel) { case TSE_POSE_CHANNEL: { outliner_do_data_operation(soops, datalevel, event, &soops->tree, pchan_cb, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL); ED_undo_push(C, "PoseChannel operation"); } break; case TSE_BONE: { outliner_do_data_operation(soops, datalevel, event, &soops->tree, bone_cb, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL); ED_undo_push(C, "Bone operation"); } break; case TSE_EBONE: { outliner_do_data_operation(soops, datalevel, event, &soops->tree, ebone_cb, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL); ED_undo_push(C, "EditBone operation"); } break; case TSE_SEQUENCE: { Scene *scene = CTX_data_scene(C); outliner_do_data_operation(soops, datalevel, event, &soops->tree, sequence_cb, scene); } break; case TSE_GP_LAYER: { outliner_do_data_operation(soops, datalevel, event, &soops->tree, gp_layer_cb, NULL); WM_event_add_notifier(C, NC_GPENCIL | ND_DATA, NULL); ED_undo_push(C, "Grease Pencil Layer operation"); } break; case TSE_RNA_STRUCT: if (event == OL_DOP_SELECT_LINKED) { outliner_do_data_operation(soops, datalevel, event, &soops->tree, data_select_linked_cb, C); } break; default: BKE_report(op->reports, RPT_WARNING, "Not yet implemented"); break; } return OPERATOR_FINISHED; }
static int outliner_animdata_operation_exec(bContext *C, wmOperator *op) { SpaceOops *soops = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; eOutliner_AnimDataOps event; short updateDeps = 0; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; event = RNA_enum_get(op->ptr, "type"); set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); if (datalevel != TSE_ANIM_DATA) return OPERATOR_CANCELLED; /* perform the core operation */ switch (event) { case OUTLINER_ANIMOP_CLEAR_ADT: /* Remove Animation Data - this may remove the active action, in some cases... */ outliner_do_data_operation(soops, datalevel, event, &soops->tree, clear_animdata_cb, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Clear Animation Data"); break; case OUTLINER_ANIMOP_SET_ACT: /* delegate once again... */ WM_operator_name_call(C, "OUTLINER_OT_action_set", WM_OP_INVOKE_REGION_WIN, NULL); break; case OUTLINER_ANIMOP_CLEAR_ACT: /* clear active action - using standard rules */ outliner_do_data_operation(soops, datalevel, event, &soops->tree, unlinkact_animdata_cb, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Unlink action"); break; case OUTLINER_ANIMOP_REFRESH_DRV: outliner_do_data_operation(soops, datalevel, event, &soops->tree, refreshdrivers_animdata_cb, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL); //ED_undo_push(C, "Refresh Drivers"); /* no undo needed - shouldn't have any impact? */ updateDeps = 1; break; case OUTLINER_ANIMOP_CLEAR_DRV: outliner_do_data_operation(soops, datalevel, event, &soops->tree, cleardrivers_animdata_cb, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL); ED_undo_push(C, "Clear Drivers"); updateDeps = 1; break; default: // invalid break; } /* update dependencies */ if (updateDeps) { /* rebuild depsgraph for the new deps */ DAG_relations_tag_update(CTX_data_main(C)); } return OPERATOR_FINISHED; }
static int outliner_id_operation_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); SpaceOops *soops = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; eOutlinerIdOpTypes event; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); event = RNA_enum_get(op->ptr, "type"); switch (event) { case OUTLINER_IDOP_UNLINK: { /* unlink datablock from its parent */ switch (idlevel) { case ID_AC: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_action_cb); WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Unlink action"); break; case ID_MA: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_material_cb); WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, NULL); ED_undo_push(C, "Unlink material"); break; case ID_TE: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_texture_cb); WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, NULL); ED_undo_push(C, "Unlink texture"); break; case ID_WO: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_world_cb); WM_event_add_notifier(C, NC_SCENE | ND_WORLD, NULL); ED_undo_push(C, "Unlink world"); break; default: BKE_report(op->reports, RPT_WARNING, "Not yet implemented"); break; } break; } case OUTLINER_IDOP_LOCAL: { /* make local */ outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb); ED_undo_push(C, "Localized Data"); break; } case OUTLINER_IDOP_SINGLE: { /* make single user */ switch (idlevel) { case ID_AC: outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_action_cb); WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Single-User Action"); break; case ID_WO: outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_world_cb); WM_event_add_notifier(C, NC_SCENE | ND_WORLD, NULL); ED_undo_push(C, "Single-User World"); break; default: BKE_report(op->reports, RPT_WARNING, "Not yet implemented"); break; } break; } case OUTLINER_IDOP_FAKE_ADD: { /* set fake user */ outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_set_cb); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Add Fake User"); break; } case OUTLINER_IDOP_FAKE_CLEAR: { /* clear fake user */ outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_clear_cb); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Clear Fake User"); break; } case OUTLINER_IDOP_RENAME: { /* rename */ outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Rename"); break; } case OUTLINER_IDOP_SELECT_LINKED: outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_select_linked_cb); ED_undo_push(C, "Select"); break; default: // invalid - unhandled break; } /* wrong notifier still... */ WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); // XXX: this is just so that outliner is always up to date WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL); return OPERATOR_FINISHED; }
void ED_undo_push_op(bContext *C, wmOperator *op) { /* in future, get undo string info? */ ED_undo_push(C, op->type->name); }