Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_modes.c
| Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "ED_gpencil.h" | #include "ED_gpencil.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_transform_snap_object_context.h" | #include "ED_transform_snap_object_context.h" | ||||
| #include "ED_undo.h" | |||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "WM_toolsystem.h" | #include "WM_toolsystem.h" | ||||
| #include "ED_object.h" /* own include */ | #include "ED_object.h" /* own include */ | ||||
| #include "object_intern.h" | #include "object_intern.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | static bool object_switch_object_poll(bContext *C) | ||||
| if (!CTX_wm_region_view3d(C)) { | if (!CTX_wm_region_view3d(C)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| const Object *ob = CTX_data_active_object(C); | const Object *ob = CTX_data_active_object(C); | ||||
| return ob && (ob->mode & (OB_MODE_EDIT | OB_MODE_SCULPT)); | return ob && (ob->mode & (OB_MODE_EDIT | OB_MODE_SCULPT)); | ||||
| } | } | ||||
| static int object_switch_object_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) | static int object_switch_object_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| struct Main *bmain = CTX_data_main(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| struct SnapObjectContext *sctx = ED_transform_snap_object_context_create(scene, 0); | struct SnapObjectContext *sctx = ED_transform_snap_object_context_create(scene, 0); | ||||
| float global_normal[3], global_loc[3]; | float global_normal[3], global_loc[3]; | ||||
| float r_obmat[4][4]; | float r_obmat[4][4]; | ||||
| float mouse[2]; | float mouse[2]; | ||||
| Show All 31 Lines | static int object_switch_object_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| if (ob_dst == ob_src) { | if (ob_dst == ob_src) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| eObjectMode last_mode = (eObjectMode)ob_src->mode; | eObjectMode last_mode = (eObjectMode)ob_src->mode; | ||||
| if (!ED_object_mode_compat_test(ob_dst, last_mode)) { | if (!ED_object_mode_compat_test(ob_dst, last_mode)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ED_object_mode_generic_exit(bmain, depsgraph, scene, ob_src); | |||||
| if (!ED_object_mode_set_ex(C, OB_MODE_OBJECT, true, op->reports)) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| ED_undo_push(C, "Edit Mode"); | |||||
campbellbarton: Are you sure this is needed? `use_undo=true` in the command above. | |||||
| Object *ob_dst_orig = DEG_get_original_object(ob_dst); | Object *ob_dst_orig = DEG_get_original_object(ob_dst); | ||||
| Base *base = BKE_view_layer_base_find(view_layer, ob_dst_orig); | Base *base = BKE_view_layer_base_find(view_layer, ob_dst_orig); | ||||
| BKE_view_layer_base_deselect_all(view_layer); | BKE_view_layer_base_deselect_all(view_layer); | ||||
| BKE_view_layer_base_select_and_set_active(view_layer, base); | BKE_view_layer_base_select_and_set_active(view_layer, base); | ||||
| DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); | DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); | ||||
| ED_undo_push(C, "Change Active"); | |||||
campbellbartonUnsubmitted Done Inline ActionsThis should be noted as FIXME, multiple undo operations per operator isn't what users would expect and should eventually be resolved (grouped in some way for e.g.). campbellbarton: This should be noted as `FIXME`, multiple undo operations per operator isn't what users would… | |||||
| depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| ob_dst_orig = DEG_get_original_object(ob_dst); | ob_dst_orig = DEG_get_original_object(ob_dst); | ||||
| ED_object_mode_set(C, last_mode); | ED_object_mode_set_ex(C, last_mode, true, op->reports); | ||||
| /* Update the viewport rotation origin to the mouse cursor. */ | /* Update the viewport rotation origin to the mouse cursor. */ | ||||
| UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; | UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; | ||||
| copy_v3_v3(ups->average_stroke_accum, global_loc); | copy_v3_v3(ups->average_stroke_accum, global_loc); | ||||
| ups->average_stroke_counter = 1; | ups->average_stroke_counter = 1; | ||||
| ups->last_stroke_valid = true; | ups->last_stroke_valid = true; | ||||
| WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); | WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); | ||||
| Show All 10 Lines | void OBJECT_OT_switch_object(wmOperatorType *ot) | ||||
| ot->description = | ot->description = | ||||
| "Switches the active object and assigns the same mode to a new one under the mouse cursor, " | "Switches the active object and assigns the same mode to a new one under the mouse cursor, " | ||||
| "leaving the active mode in the current one"; | "leaving the active mode in the current one"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = object_switch_object_invoke; | ot->invoke = object_switch_object_invoke; | ||||
| ot->poll = object_switch_object_poll; | ot->poll = object_switch_object_poll; | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER; | ||||
campbellbartonUnsubmitted Done Inline ActionsShould note that undo pushes are handled by the operator. campbellbarton: Should note that undo pushes are handled by the operator. | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
Are you sure this is needed? use_undo=true in the command above.