Changeset View
Standalone View
source/blender/editors/util/ed_util.c
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_packedFile.h" | #include "BKE_packedFile.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_undo_system.h" | #include "BKE_undo_system.h" | ||||
| #include "BKE_workspace.h" | #include "BKE_workspace.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "DEG_depsgraph.h" | |||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "ED_buttons.h" | #include "ED_buttons.h" | ||||
| #include "ED_image.h" | #include "ED_image.h" | ||||
| #include "ED_mesh.h" | #include "ED_mesh.h" | ||||
| #include "ED_node.h" | #include "ED_node.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| #include "ED_outliner.h" | #include "ED_outliner.h" | ||||
| #include "ED_paint.h" | #include "ED_paint.h" | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | void ED_editors_init(bContext *C) | ||||
| /* Don't do undo pushes when calling an operator. */ | /* Don't do undo pushes when calling an operator. */ | ||||
| wm->op_undo_depth++; | wm->op_undo_depth++; | ||||
| /* toggle on modes for objects that were saved with these enabled. for | /* toggle on modes for objects that were saved with these enabled. for | ||||
| * e.g. linked objects we have to ensure that they are actually the | * e.g. linked objects we have to ensure that they are actually the | ||||
| * active object in this scene. */ | * active object in this scene. */ | ||||
| Object *obact = CTX_data_active_object(C); | Object *obact = CTX_data_active_object(C); | ||||
| if (obact != NULL) { | |||||
| for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { | for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { | ||||
| int mode = ob->mode; | int mode = ob->mode; | ||||
| if (mode == OB_MODE_OBJECT) { | if (mode == OB_MODE_OBJECT) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| else if (BKE_object_has_mode_data(ob, mode)) { | else if (BKE_object_has_mode_data(ob, mode)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| else if (ob->type == OB_GPENCIL) { | else if (ob->type == OB_GPENCIL) { | ||||
| /* For multi-edit mode we may already have mode data. | /* For multi-edit mode we may already have mode data. | ||||
| * (grease pencil does not need it) */ | * (grease pencil does not need it) */ | ||||
| continue; | continue; | ||||
| } | } | ||||
| ID *ob_data = ob->data; | ID *ob_data = ob->data; | ||||
| ob->mode = OB_MODE_OBJECT; | ob->mode = OB_MODE_OBJECT; | ||||
| if ((ob->type == obact->type) && !ID_IS_LINKED(ob) && !(ob_data && ID_IS_LINKED(ob_data))) { | DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); | ||||
| if (obact && (ob->type == obact->type) && !ID_IS_LINKED(ob) && | |||||
| !(ob_data && ID_IS_LINKED(ob_data))) { | |||||
| if (mode == OB_MODE_EDIT) { | if (mode == OB_MODE_EDIT) { | ||||
| ED_object_editmode_enter_ex(bmain, scene, ob, 0); | ED_object_editmode_enter_ex(bmain, scene, ob, 0); | ||||
| } | } | ||||
| else if (mode == OB_MODE_POSE) { | else if (mode == OB_MODE_POSE) { | ||||
| ED_object_posemode_enter_ex(bmain, ob); | ED_object_posemode_enter_ex(bmain, ob); | ||||
| } | } | ||||
| else if (mode & OB_MODE_ALL_SCULPT) { | else if (mode & OB_MODE_ALL_SCULPT) { | ||||
| if (obact == ob) { | if (obact == ob) { | ||||
| if (mode == OB_MODE_SCULPT) { | if (mode == OB_MODE_SCULPT) { | ||||
| ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, true, reports); | ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, true, reports); | ||||
| } | } | ||||
| else if (mode == OB_MODE_VERTEX_PAINT) { | else if (mode == OB_MODE_VERTEX_PAINT) { | ||||
| ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); | ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); | ||||
| } | } | ||||
| else if (mode == OB_MODE_WEIGHT_PAINT) { | else if (mode == OB_MODE_WEIGHT_PAINT) { | ||||
| ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); | ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
brecht: I think this else case needs the tag too?
It should be fine to always tag the object along… | |||||
Done Inline ActionsIt probably doesn't need. The active object tends to always work. But agree that always tagging is simple in this case. dfelinto: It probably doesn't need. The active object tends to always work. But agree that always tagging… | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Create data for non-active objects which need it for | /* Create data for non-active objects which need it for | ||||
| * mode-switching but don't yet support multi-editing. */ | * mode-switching but don't yet support multi-editing. */ | ||||
| if (mode & OB_MODE_ALL_SCULPT) { | if (mode & OB_MODE_ALL_SCULPT) { | ||||
| ob->mode = mode; | ob->mode = mode; | ||||
| BKE_object_sculpt_data_create(ob); | BKE_object_sculpt_data_create(ob); | ||||
| } | } | ||||
| } | } | ||||
Not Done Inline ActionsNothing changed but tag is needed? Or am i missing something? sergey: Nothing changed but tag is needed? Or am i missing something? | |||||
Done Inline ActionsWe run into this when (ob->type != obact->type). What changed in this case is that we set ob->mode = OB_MODE_OBJECT (line 136). dfelinto: We run into this when `(ob->type != obact->type)`. What changed in this case is that we set `ob… | |||||
| } | } | ||||
| else { | else { | ||||
| /* TODO(campbell): avoid operator calls. */ | /* TODO(campbell): avoid operator calls. */ | ||||
| if (obact == ob) { | if (obact == ob) { | ||||
| ED_object_mode_toggle(C, mode); | ED_object_mode_toggle(C, mode); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| /* image editor paint mode */ | /* image editor paint mode */ | ||||
| if (scene) { | if (scene) { | ||||
| ED_space_image_paint_update(bmain, wm, scene); | ED_space_image_paint_update(bmain, wm, scene); | ||||
Not Done Inline ActionsThe logic here is different than the case where an active object exists. It checks BKE_object_has_mode_data, (ob->type == OB_GPENCIL) and sets the object mode before the linked data check. I see no good reason why the existence of an active object should influence other objects like that, which was already an issue in the existing code. Probably it's best to just have a single loop over all objects, and do some obact == NULL checks inside the loop. brecht: The logic here is different than the case where an active object exists. It checks… | |||||
Done Inline ActionsAgree, will look into that. dfelinto: Agree, will look into that. | |||||
| } | } | ||||
| SWAP(int, reports->flag, reports_flag_prev); | SWAP(int, reports->flag, reports_flag_prev); | ||||
| wm->op_undo_depth--; | wm->op_undo_depth--; | ||||
| } | } | ||||
| /* frees all editmode stuff */ | /* frees all editmode stuff */ | ||||
| void ED_editors_exit(Main *bmain, bool do_undo_system) | void ED_editors_exit(Main *bmain, bool do_undo_system) | ||||
| ▲ Show 20 Lines • Show All 274 Lines • Show Last 20 Lines | |||||
I think this else case needs the tag too?
It should be fine to always tag the object along with ob->mode = OB_MODE_OBJECT; and not to worry about avoiding double tags.