Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Tue, 15 May 2018 08:25:49 +0000 (10:25 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 15 May 2018 08:25:49 +0000 (10:25 +0200)
1  2 
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/curve/editcurve_add.c
source/blender/editors/include/ED_object.h
source/blender/editors/mesh/editmesh_add.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_modes.c
source/blender/editors/space_outliner/outliner_select.c
source/blender/editors/space_outliner/outliner_tools.c

@@@ -2725,8 -2720,9 +2725,9 @@@ static int mouse_anim_channels(bContex
                                        adt->flag |= ADT_UI_ACTIVE;
  
                                /* ensure we exit editmode on whatever object was active before to avoid getting stuck there - T48747 */
-                               if (ob != CTX_data_edit_object(C))
-                                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
 -                              if (ob != sce->obedit) {
++                              if (ob != CTX_data_edit_object(C)) {
+                                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
+                               }
  
                                notifierFlags |= (ND_ANIMCHAN | NA_SELECTED);
                        }
@@@ -122,15 -115,10 +122,14 @@@ void ED_object_parent(struct Object *ob
  enum {
        EM_FREEDATA         = (1 << 0),
        EM_WAITCURSOR       = (1 << 1),
-       EM_DO_UNDO          = (1 << 2),
        EM_IGNORE_LAYER     = (1 << 3),
 +      EM_NO_CONTEXT       = (1 << 4),
  };
 -void ED_object_editmode_exit_ex(struct Scene *scene, struct Object *obedit, int flag);
 +void ED_object_editmode_exit_ex(
-         struct bContext *C, struct Scene *scene, struct Object *obedit, int flag);
++        struct Scene *scene, struct Object *obedit, int flag);
  void ED_object_editmode_exit(struct bContext *C, int flag);
 +
 +void ED_object_editmode_enter_ex(struct Scene *scene, struct Object *ob, int flag);
  void ED_object_editmode_enter(struct bContext *C, int flag);
  bool ED_object_editmode_load(struct Object *obedit);
  
@@@ -77,11 -72,11 +77,11 @@@ static Object *make_prim_init
                obedit = ED_object_add_type(C, OB_MESH, idname, loc, rot, false, layer);
  
                /* create editmode */
-               ED_object_editmode_enter(C, EM_DO_UNDO | EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
+               ED_object_editmode_enter(C, EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
 -              *was_editmode = true;
 +              r_creation_data->was_editmode = true;
        }
  
 -      *dia = ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
 +      ED_object_new_primitive_matrix(C, obedit, loc, rot, r_creation_data->mat);
  
        return obedit;
  }
@@@ -424,24 -411,29 +424,25 @@@ Object *ED_object_add_type
        Object *ob;
  
        /* for as long scene has editmode... */
-       if (CTX_data_edit_object(C)) 
-               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);  /* freedata, and undo */
+       if (CTX_data_edit_object(C)) {
+               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
+       }
  
        /* deselects all, sets scene->basact */
 -      ob = BKE_object_add(bmain, scene, type, name);
 -      BASACT->lay = ob->lay = layer;
 +      ob = BKE_object_add(bmain, scene, view_layer, type, name);
        /* editor level activate, notifiers */
 -      ED_base_object_activate(C, BASACT);
 +      ED_object_base_activate(C, view_layer->basact);
  
        /* more editor stuff */
 -      ED_object_base_init_transform(C, BASACT, loc, rot);
 -
 -      /* Ignore collisions by default for non-mesh objects */
 -      if (type != OB_MESH) {
 -              ob->body_type = OB_BODY_TYPE_NO_COLLISION;
 -              ob->gameflag &= ~(OB_SENSOR | OB_RIGID_BODY | OB_SOFT_BODY | OB_COLLISION | OB_CHARACTER | OB_OCCLUDER | OB_DYNAMIC | OB_NAVMESH); /* copied from rna_object.c */
 -      }
 +      ED_object_base_init_transform(C, view_layer->basact, loc, rot);
  
 -      DAG_id_type_tag(bmain, ID_OB);
 -      DAG_relations_tag_update(bmain);
 -      if (ob->data) {
 -              ED_render_id_flush_update(bmain, ob->data);
 +      /* TODO(sergey): This is weird to manually tag objects for update, better to
 +       * use DEG_id_tag_update here perhaps.
 +       */
 +      DEG_id_type_tag(bmain, ID_OB);
 +      DEG_relations_tag_update(bmain);
 +      if (ob->data != NULL) {
 +              DEG_id_tag_update_ex(bmain, (ID *)ob->data, DEG_TAG_EDITORS_UPDATE);
        }
  
        if (enter_editmode)
@@@ -306,19 -482,10 +303,11 @@@ void ED_object_editmode_exit_ex(Scene *
                BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_OUTDATED);
  
                /* also flush ob recalc, doesn't take much overhead, but used for particles */
 -              DAG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA);
 +              DEG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA);
-       
-               if (flag & EM_DO_UNDO)
-                       ED_undo_push(C, "Editmode");
  
-               if (C != NULL) {
-                       WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
-               }
-               else {
-                       WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
-               }
+               WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
  
 +
                obedit->mode &= ~OB_MODE_EDIT;
        }
  
@@@ -329,15 -496,37 +318,15 @@@ void ED_object_editmode_exit(bContext *
  {
        Scene *scene = CTX_data_scene(C);
        Object *obedit = CTX_data_edit_object(C);
-       ED_object_editmode_exit_ex(C, scene, obedit, flag);
+       ED_object_editmode_exit_ex(scene, obedit, flag);
  }
  
 -void ED_object_editmode_enter(bContext *C, int flag)
 +void ED_object_editmode_enter_ex(Scene *scene, Object *ob, int flag)
  {
 -      Scene *scene = CTX_data_scene(C);
 -      Base *base = NULL;
 -      Object *ob;
 -      ScrArea *sa = CTX_wm_area(C);
 -      View3D *v3d = NULL;
        bool ok = false;
  
 -      if (ID_IS_LINKED(scene)) return;
 -
 -      if (sa && sa->spacetype == SPACE_VIEW3D)
 -              v3d = sa->spacedata.first;
 -
 -      if ((flag & EM_IGNORE_LAYER) == 0) {
 -              base = CTX_data_active_base(C); /* active layer checked here for view3d */
 -
 -              if (base == NULL) return;
 -              else if (v3d && (base->lay & v3d->lay) == 0) return;
 -              else if (!v3d && (base->lay & scene->lay) == 0) return;
 -      }
 -      else {
 -              base = scene->basact;
 -      }
 -
 -      if (ELEM(NULL, base, base->object, base->object->data)) return;
 -
 -      ob = base->object;
 +      if (ELEM(NULL, ob, ob->data)) return;
 +      if (ID_IS_LINKED(ob)) return;
  
        /* this checks actual object->data, for cases when other scenes have it in editmode context */
        if (BKE_object_is_in_editmode(ob))
        }
  
        if (flag & EM_WAITCURSOR) waitcursor(0);
-       BLI_assert((flag & EM_DO_UNDO) == 0);
  }
  
-       ED_object_editmode_enter_ex(scene, ob, flag & ~EM_DO_UNDO);
-       if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
 +void ED_object_editmode_enter(bContext *C, int flag)
 +{
 +      Scene *scene = CTX_data_scene(C);
 +      ViewLayer *view_layer = CTX_data_view_layer(C);
 +      Object *ob;
 +
 +      if ((flag & EM_IGNORE_LAYER) == 0) {
 +              ob = CTX_data_active_object(C); /* active layer checked here for view3d */
 +      }
 +      else {
 +              ob = view_layer->basact->object;
 +      }
 +      if (ob == NULL) return;
 +      if (ID_IS_LINKED(ob)) return;
 +
++      ED_object_editmode_enter_ex(scene, ob, flag);
 +}
 +
  static int editmode_toggle_exec(bContext *C, wmOperator *op)
  {
 +      struct wmMsgBus *mbus = CTX_wm_message_bus(C);
        const int mode_flag = OB_MODE_EDIT;
        const bool is_mode_set = (CTX_data_edit_object(C) != NULL);
        Scene *scene =  CTX_data_scene(C);
  
        if (!is_mode_set) {
                ED_object_editmode_enter(C, EM_WAITCURSOR);
 +              if (obact->mode & mode_flag) {
 +                      FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
 +                      {
 +                              if ((ob != obact) && (ob->type == obact->type)) {
 +                                      ED_object_editmode_enter_ex(scene, ob, EM_WAITCURSOR | EM_NO_CONTEXT);
 +                              }
 +                      }
 +                      FOREACH_SELECTED_OBJECT_END;
 +              }
        }
        else {
-               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);  /* had EM_DO_UNDO but op flag calls undo too [#24685] */
+               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
 +              if ((obact->mode & mode_flag) == 0) {
 +                      FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
 +                      {
 +                              if ((ob != obact) && (ob->type == obact->type)) {
-                                       ED_object_editmode_exit_ex(NULL, scene, ob, EM_FREEDATA | EM_WAITCURSOR);
++                                      ED_object_editmode_exit_ex(scene, ob, EM_FREEDATA | EM_WAITCURSOR);
 +                              }
 +                      }
 +                      FOREACH_SELECTED_OBJECT_END;
 +              }
        }
 +      
        ED_space_image_uv_sculpt_update(CTX_wm_manager(C), scene);
  
 +      WM_msg_publish_rna_prop(mbus, &obact->id, obact, Object, mode);
 +
        return OPERATOR_FINISHED;
  }
  
@@@ -545,54 -700,23 +532,54 @@@ static int posemode_exec(bContext *C, w
                }
        }
  
 -      if (ob->type == OB_ARMATURE) {
 -              if (ob == CTX_data_edit_object(C)) {
 -                      ED_object_editmode_exit(C, EM_FREEDATA);
 -                      is_mode_set = false;
 -              }
 +      if (obact->type != OB_ARMATURE) {
 +              return OPERATOR_PASS_THROUGH;
 +      }
 +
 +      if (obact == CTX_data_edit_object(C)) {
-               ED_object_editmode_exit(C, EM_FREEDATA | EM_DO_UNDO);
++              ED_object_editmode_exit(C, EM_FREEDATA);
 +              is_mode_set = false;
 +      }
  
 -              if (is_mode_set) {
 -                      ED_object_posemode_exit(C, ob);
 +      if (is_mode_set) {
 +              bool ok = ED_object_posemode_exit(C, obact);
 +              if (ok) {
 +                      struct Main *bmain = CTX_data_main(C);
 +                      ViewLayer *view_layer = CTX_data_view_layer(C);
 +                      FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
 +                      {
 +                              if ((ob != obact) &&
 +                                  (ob->type == OB_ARMATURE) &&
 +                                  (ob->mode & mode_flag))
 +                              {
 +                                      ED_object_posemode_exit_ex(bmain, ob);
 +                              }
 +                      }
 +                      FOREACH_SELECTED_OBJECT_END;
                }
 -              else {
 -                      ED_object_posemode_enter(C, ob);
 +      }
 +      else {
 +              bool ok = ED_object_posemode_enter(C, obact);
 +              if (ok) {
 +                      struct Main *bmain = CTX_data_main(C);
 +                      ViewLayer *view_layer = CTX_data_view_layer(C);
 +                      FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
 +                      {
 +                              if ((ob != obact) &&
 +                                  (ob->type == OB_ARMATURE) &&
 +                                  (ob->mode == OB_MODE_OBJECT) &&
 +                                  (!ID_IS_LINKED(ob)))
 +                              {
 +                                      ED_object_posemode_enter_ex(bmain, ob);
 +                              }
 +                      }
 +                      FOREACH_SELECTED_OBJECT_END;
                }
 -              
 -              return OPERATOR_FINISHED;
        }
 -      
 -      return OPERATOR_PASS_THROUGH;
 +
 +      WM_msg_publish_rna_prop(mbus, &obact->id, obact, Object, mode);
 +
 +      return OPERATOR_FINISHED;
  }
  
  void OBJECT_OT_posemode_toggle(wmOperatorType *ot) 
@@@ -156,81 -140,30 +156,81 @@@ void ED_object_mode_toggle(bContext *C
  /* Wrapper for operator  */
  void ED_object_mode_set(bContext *C, eObjectMode mode)
  {
 -#if 0
 +      wmWindowManager *wm = CTX_wm_manager(C);
 +      wm->op_undo_depth++;
 +      /* needed so we don't do undo pushes. */
 +      ED_object_mode_generic_enter(C, mode);
 +      wm->op_undo_depth--;
 +}
 +
 +/** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Generic Mode Enter/Exit
 + *
 + * Supports exiting a mode without it being in the current context.
 + * This could be done for entering modes too if it's needed.
 + *
 + * \{ */
 +
 +bool ED_object_mode_generic_enter(
 +        struct bContext *C, eObjectMode object_mode)
 +{
 +      Object *ob = CTX_data_active_object(C);
 +      if (ob == NULL) {
 +              return (object_mode == OB_MODE_OBJECT);
 +      }
 +      if (ob->mode == object_mode) {
 +              return true;
 +      }
        wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_mode_set", false);
        PointerRNA ptr;
 -
        WM_operator_properties_create_ptr(&ptr, ot);
 -      RNA_enum_set(&ptr, "mode", mode);
 -      RNA_boolean_set(&ptr, "toggle", false);
 -      WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &ptr);
 +      RNA_enum_set(&ptr, "mode", object_mode);
 +      WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr);
        WM_operator_properties_free(&ptr);
 -#else
 -      Object *ob = CTX_data_active_object(C);
 -      if (ob == NULL) {
 -              return;
 +      return (ob->mode == object_mode);
 +}
 +
 +/**
 + * Use for changing works-paces or changing active object.
 + * Caller can check #OB_MODE_ALL_MODE_DATA to test if this needs to be run.
 + */
 +static bool ed_object_mode_generic_exit_ex(
 +        struct Depsgraph *depsgraph,
 +        struct Scene *scene, struct Object *ob,
 +        bool only_test)
 +{
 +      if (ob->mode & OB_MODE_EDIT) {
 +              if (BKE_object_is_in_editmode(ob)) {
 +                      if (only_test) {
 +                              return true;
 +                      }
-                       ED_object_editmode_exit_ex(NULL, scene, ob, EM_FREEDATA);
++                      ED_object_editmode_exit_ex(scene, ob, EM_FREEDATA);
 +              }
        }
 -      if (ob->mode == mode) {
 -              /* pass */
 +      else if (ob->mode & OB_MODE_VERTEX_PAINT) {
 +              if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT)) {
 +                      if (only_test) {
 +                              return true;
 +                      }
 +                      ED_object_vpaintmode_exit_ex(ob);
 +              }
        }
 -      else if (mode != OB_MODE_OBJECT) {
 -              if (ob && (ob->mode & mode) == 0) {
 -                      /* needed so we don't do undo pushes. */
 -                      wmWindowManager *wm = CTX_wm_manager(C);
 -                      wm->op_undo_depth++;
 -                      ED_object_mode_toggle(C, mode);
 -                      wm->op_undo_depth--;
 +      else if (ob->mode & OB_MODE_WEIGHT_PAINT) {
 +              if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT)) {
 +                      if (only_test) {
 +                              return true;
 +                      }
 +                      ED_object_wpaintmode_exit_ex(ob);
 +              }
 +      }
 +      else if (ob->mode & OB_MODE_SCULPT) {
 +              if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_SCULPT)) {
 +                      if (only_test) {
 +                              return true;
 +                      }
 +                      ED_object_sculptmode_exit_ex(depsgraph, scene, ob);
                }
        }
        else {
@@@ -197,10 -239,10 +197,10 @@@ static eOLDrawState tree_element_set_ac
                        WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
                }
        }
--      
-       if (ob != OBEDIT_FROM_VIEW_LAYER(view_layer))
-               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
-               
 -      if (ob != scene->obedit)
++
++      if (ob != OBEDIT_FROM_VIEW_LAYER(view_layer)) {
+               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
 -              
++      }
        return OL_DRAWSEL_NORMAL;
  }
  
@@@ -584,10 -714,10 +584,10 @@@ static eOLDrawState tree_element_active
        }
  
        if (set != OL_SETSEL_NONE) {
 -              if (scene->obedit) {
 +              if (OBEDIT_FROM_VIEW_LAYER(view_layer)) {
-                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
+                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
                }
--              
++
                if (ob->mode & OB_MODE_POSE) {
                        ED_object_posemode_exit(C, ob);
                }
@@@ -407,10 -417,11 +407,10 @@@ static void object_delete_cb
                }
  
                // check also library later
 -              if (scene->obedit == base->object) {
 +              if (ob == CTX_data_edit_object(C)) {
-                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
+                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
                }
 -              
 -              ED_base_object_free_and_unlink(CTX_data_main(C), scene, base);
 +              ED_object_base_free_and_unlink(CTX_data_main(C), scene, ob);
                /* leave for ED_outliner_id_unref to handle */
  #if 0
                te->directdata = NULL;