Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Fri, 2 Mar 2018 03:46:21 +0000 (14:46 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 2 Mar 2018 03:46:21 +0000 (14:46 +1100)
1  2 
source/blender/editors/animation/keyframing.c
source/blender/editors/armature/pose_edit.c
source/blender/editors/include/ED_object.h
source/blender/editors/object/CMakeLists.txt
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_modes.c
source/blender/editors/util/ed_util.c

index 3e04c8ccc8ee42726e9cf92cb90b18630579b562,91b931028144339f41548c5dcfd954117d77ccc0..6c53d24ef8ce3c45888ab73a30539a340a4374c6
@@@ -217,6 -196,11 +214,10 @@@ void undo_push_lattice(struct bContext 
  
  void ED_lattice_flags_set(struct Object *obedit, int flag);
  
 -/* object_modes.c */
+ bool ED_object_mode_compat_test(const struct Object *ob, eObjectMode mode);
 -bool ED_object_mode_compat_set(struct bContext *C, struct Object *ob, eObjectMode mode, struct ReportList *reports);
++bool ED_object_mode_compat_set(struct bContext *C, struct WorkSpace *workspace, eObjectMode mode, struct ReportList *reports);
+ void ED_object_mode_toggle(struct bContext *C, eObjectMode mode);
  /* object_modifier.c */
  enum {
        MODIFIER_APPLY_DATA = 1,
index ec81cdfdf69164b4c965f86e891b47d58717d14e,84808817b94be36ade06b936cfa262bb0baec3dc..db646472af539518a5f1200725c5cfdfb48acb2c
@@@ -365,10 -552,10 +365,10 @@@ void ED_object_editmode_enter(bContext 
  
        /* note, when switching scenes the object can have editmode data but
         * not be scene->obedit: bug 22954, this avoids calling self eternally */
 -      if ((ob->restore_mode & OB_MODE_EDIT) == 0)
 -              ED_object_mode_toggle(C, ob->mode);
 +      if ((workspace->object_mode_restore & OB_MODE_EDIT) == 0)
-               ED_object_toggle_modes(C, workspace->object_mode);
++              ED_object_mode_toggle(C, workspace->object_mode);
  
 -      ob->mode = OB_MODE_EDIT;
 +      workspace->object_mode = OB_MODE_EDIT;
  
        if (ob->type == OB_MESH) {
                BMEditMesh *em;
@@@ -1617,34 -1709,31 +1531,34 @@@ static int object_mode_set_exec(bContex
                }
        }
        
-       if (!ob || !object_mode_compat_test(ob, mode))
+       if (!ob || !ED_object_mode_compat_test(ob, mode))
                return OPERATOR_PASS_THROUGH;
  
 -      if (ob->mode != mode) {
 +      if (workspace->object_mode != mode) {
                /* we should be able to remove this call, each operator calls  */
 -              ED_object_mode_compat_set(C, ob, mode, op->reports);
 +              ED_object_mode_compat_set(C, workspace, mode, op->reports);
        }
  
        /* Exit current mode if it's not the mode we're setting */
 -      if (mode != OB_MODE_OBJECT && (ob->mode != mode || toggle)) {
 +      if (mode != OB_MODE_OBJECT && (workspace->object_mode != mode || toggle)) {
                /* Enter new mode */
-               ED_object_toggle_modes(C, mode);
+               ED_object_mode_toggle(C, mode);
        }
  
        if (toggle) {
                /* Special case for Object mode! */
 -              if (mode == OB_MODE_OBJECT && restore_mode == OB_MODE_OBJECT && ob->restore_mode != OB_MODE_OBJECT) {
 -                      ED_object_mode_toggle(C, ob->restore_mode);
 +              if ((mode == OB_MODE_OBJECT) &&
 +                  (restore_mode == OB_MODE_OBJECT) &&
 +                  (workspace->object_mode_restore != OB_MODE_OBJECT))
 +              {
-                       ED_object_toggle_modes(C, workspace->object_mode_restore);
++                      ED_object_mode_toggle(C, workspace->object_mode_restore);
                }
 -              else if (ob->mode == mode) {
 +              else if (workspace->object_mode == mode) {
                        /* For toggling, store old mode so we know what to go back to */
 -                      ob->restore_mode = restore_mode;
 +                      workspace->object_mode_restore = restore_mode;
                }
 -              else if (ob->restore_mode != OB_MODE_OBJECT && ob->restore_mode != mode) {
 -                      ED_object_mode_toggle(C, ob->restore_mode);
 +              else if (!ELEM(workspace->object_mode_restore, mode, OB_MODE_OBJECT)) {
-                       ED_object_toggle_modes(C, workspace->object_mode_restore);
++                      ED_object_mode_toggle(C, workspace->object_mode_restore);
                }
        }
  
index 0000000000000000000000000000000000000000,fda342f8a4d0eb32bb8d2623fb0283b33e3559eb..3dd496336ce24442a55034bb866beb7dea850788
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,138 +1,140 @@@
 -
+ /*
+  * ***** BEGIN GPL LICENSE BLOCK *****
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software Foundation,
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  *
+  * Contributor(s): Blender Foundation, 2002-2008 full recode
+  *
+  * ***** END GPL LICENSE BLOCK *****
+  */
+ /** \file blender/editors/object/object_modes.c
+  *  \ingroup edobj
+  *
+  * General utils to handle mode switching,
+  * actual mode switching logic is per-object type.
+  */
+ #include "DNA_object_types.h"
+ #include "DNA_scene_types.h"
++#include "DNA_workspace_types.h"
+ #include "BLI_utildefines.h"
+ #include "BKE_context.h"
+ #include "BKE_report.h"
+ #include "WM_api.h"
+ #include "WM_types.h"
+ #include "ED_object.h"
+ static const char *object_mode_op_string(eObjectMode mode)
+ {
+       if (mode & OB_MODE_EDIT)
+               return "OBJECT_OT_editmode_toggle";
+       if (mode == OB_MODE_SCULPT)
+               return "SCULPT_OT_sculptmode_toggle";
+       if (mode == OB_MODE_VERTEX_PAINT)
+               return "PAINT_OT_vertex_paint_toggle";
+       if (mode == OB_MODE_WEIGHT_PAINT)
+               return "PAINT_OT_weight_paint_toggle";
+       if (mode == OB_MODE_TEXTURE_PAINT)
+               return "PAINT_OT_texture_paint_toggle";
+       if (mode == OB_MODE_PARTICLE_EDIT)
+               return "PARTICLE_OT_particle_edit_toggle";
+       if (mode == OB_MODE_POSE)
+               return "OBJECT_OT_posemode_toggle";
+       if (mode == OB_MODE_GPENCIL)
+               return "GPENCIL_OT_editmode_toggle";
+       return NULL;
+ }
+ /**
+  * Checks the mode to be set is compatible with the object
+  * should be made into a generic function
+  */
+ bool ED_object_mode_compat_test(const Object *ob, eObjectMode mode)
+ {
+       if (ob) {
+               if (mode == OB_MODE_OBJECT)
+                       return true;
+               else if (mode == OB_MODE_GPENCIL)
+                       return true; /* XXX: assume this is the case for now... */
+               switch (ob->type) {
+                       case OB_MESH:
+                               if (mode & (OB_MODE_EDIT | OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT |
+                                           OB_MODE_TEXTURE_PAINT | OB_MODE_PARTICLE_EDIT))
+                               {
+                                       return true;
+                               }
+                               break;
+                       case OB_CURVE:
+                       case OB_SURF:
+                       case OB_FONT:
+                       case OB_MBALL:
+                               if (mode & (OB_MODE_EDIT))
+                                       return true;
+                               break;
+                       case OB_LATTICE:
+                               if (mode & (OB_MODE_EDIT | OB_MODE_WEIGHT_PAINT))
+                                       return true;
+                               break;
+                       case OB_ARMATURE:
+                               if (mode & (OB_MODE_EDIT | OB_MODE_POSE))
+                                       return true;
+                               break;
+               }
+       }
+       return false;
+ }
 -bool ED_object_mode_compat_set(bContext *C, Object *ob, eObjectMode mode, ReportList *reports)
+ /**
+  * Sets the mode to a compatible state (use before entering the mode).
+  *
+  * This is so each mode's exec function can call
+  */
 -      if (!ELEM(ob->mode, mode, OB_MODE_OBJECT)) {
 -              const char *opstring = object_mode_op_string(ob->mode);
++bool ED_object_mode_compat_set(bContext *C, WorkSpace *workspace, eObjectMode mode, ReportList *reports)
+ {
+       bool ok;
 -              ok = ELEM(ob->mode, mode, OB_MODE_OBJECT);
++      if (!ELEM(workspace->object_mode, mode, OB_MODE_OBJECT)) {
++              const char *opstring = object_mode_op_string(workspace->object_mode);
++
+               WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
++              ok = ELEM(workspace->object_mode, mode, OB_MODE_OBJECT);
+               if (!ok) {
+                       wmOperatorType *ot = WM_operatortype_find(opstring, false);
+                       BKE_reportf(reports, RPT_ERROR, "Unable to execute '%s', error changing modes", ot->name);
+               }
+       }
+       else {
+               ok = true;
+       }
+       return ok;
+ }
+ void ED_object_mode_toggle(bContext *C, eObjectMode mode)
+ {
+       if (mode != OB_MODE_OBJECT) {
+               const char *opstring = object_mode_op_string(mode);
++
+               if (opstring) {
+                       WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
+               }
+       }
+ }
index 562ba2c42b331956acbbf30c8e8ce7efabf2d541,57ff8b6db01d17dd3f46f2aca3a558e1d96d39e1..7a5b8bfbda1bdc227727f2234385953fbaa6ae7f
@@@ -103,33 -98,16 +103,33 @@@ void ED_editors_init(bContext *C
        /* 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
         * active object in this scene. */
 -      for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -              int mode = ob->mode;
 -
 -              if (!ELEM(mode, OB_MODE_OBJECT, OB_MODE_POSE)) {
 -                      ob->mode = OB_MODE_OBJECT;
 -                      data = ob->data;
 -
 -                      if (ob == obact && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data)))
 -                              ED_object_mode_toggle(C, mode);
 +      {
 +              wmWindow *win_orig = CTX_wm_window(C);
 +              CTX_wm_window_set(C, NULL);
 +              for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +                      WorkSpace *workspace = WM_window_get_active_workspace(win);
 +                      Scene *scene = WM_window_get_active_scene(win);
 +                      ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
 +                      Object *obact = view_layer ? OBACT(view_layer) : NULL;
 +                      eObjectMode object_mode = workspace->object_mode;
 +                      workspace->object_mode = OB_MODE_OBJECT;
 +                      if (view_layer && obact) {
 +                              const ID *data = obact->data;
 +                              if (!ELEM(object_mode, OB_MODE_OBJECT, OB_MODE_POSE)) {
 +                                      if (!ID_IS_LINKED(obact) && !(data && ID_IS_LINKED(data))) {
 +                                              CTX_wm_window_set(C, win);
-                                               ED_object_toggle_modes(C, object_mode);
++                                              ED_object_mode_toggle(C, object_mode);
 +                                              CTX_wm_window_set(C, NULL);
 +                                      }
 +                              }
 +                              else if (object_mode == OB_MODE_POSE) {
 +                                      if (!ID_IS_LINKED(obact) && (obact->type == OB_ARMATURE)) {
 +                                              workspace->object_mode = object_mode;
 +                                      }
 +                              }
 +                      }
                }
 +              CTX_wm_window_set(C, win_orig);
        }
  
        /* image editor paint mode */