Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Tue, 11 Sep 2018 05:01:41 +0000 (15:01 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 11 Sep 2018 05:01:41 +0000 (15:01 +1000)
1  2 
source/blender/editors/transform/transform_orientations.c

index 2dcd11d89ffb08e33665bf4c3cc5f7a16da172fc,4122cf33bdbea6445d1f963ac2098ca6f7b1896d..2962c88c3520cb6aa5989f822545cd271c603ee6
@@@ -38,7 -38,6 +38,7 @@@
  #include "DNA_screen_types.h"
  #include "DNA_space_types.h"
  #include "DNA_view3d_types.h"
 +#include "DNA_workspace_types.h"
  
  #include "BLI_math.h"
  #include "BLI_listbase.h"
@@@ -53,8 -52,6 +53,8 @@@
  #include "BKE_report.h"
  #include "BKE_main.h"
  #include "BKE_screen.h"
 +#include "BKE_scene.h"
 +#include "BKE_workspace.h"
  
  #include "BLT_translation.h"
  
  
  void BIF_clearTransformOrientation(bContext *C)
  {
 +      Scene *scene = CTX_data_scene(C);
 +      ListBase *transform_orientations = &scene->transform_spaces;
        View3D *v3d = CTX_wm_view3d(C);
  
 -      ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
 -      BLI_freelistN(transform_spaces);
 +      BLI_freelistN(transform_orientations);
  
 -      // Need to loop over all view3d
 -      if (v3d && v3d->twmode >= V3D_MANIP_CUSTOM) {
 -              v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
 +      if (v3d && scene->orientation_type == V3D_MANIP_CUSTOM) {
 +              scene->orientation_type = V3D_MANIP_GLOBAL; /* fallback to global */
 +              scene->orientation_index_custom = -1;
        }
  }
  
@@@ -322,24 -318,23 +322,24 @@@ void BIF_createTransformOrientation(bCo
  TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3],
                                       const char *name, const bool overwrite)
  {
 -      ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
        TransformOrientation *ts = NULL;
 +      Scene *scene = CTX_data_scene(C);
 +      ListBase *transform_orientations = &scene->transform_spaces;
        char name_unique[sizeof(ts->name)];
  
        if (overwrite) {
 -              ts = findOrientationName(transform_spaces, name);
 +              ts = findOrientationName(transform_orientations, name);
        }
        else {
                BLI_strncpy(name_unique, name, sizeof(name_unique));
 -              uniqueOrientationName(transform_spaces, name_unique);
 +              uniqueOrientationName(transform_orientations, name_unique);
                name = name_unique;
        }
  
        /* if not, create a new one */
        if (ts == NULL) {
                ts = MEM_callocN(sizeof(TransformOrientation), "UserTransSpace from matrix");
 -              BLI_addtail(transform_spaces, ts);
 +              BLI_addtail(transform_orientations, ts);
                BLI_strncpy(ts->name, name, sizeof(ts->name));
        }
  
  
  void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target)
  {
 -      Scene *scene = CTX_data_scene(C);
 -      ListBase *transform_spaces = &scene->transform_spaces;
 -      const int i = BLI_findindex(transform_spaces, target);
 -
 -      if (i != -1) {
 -              Main *bmain = CTX_data_main(C);
 -              BKE_screen_view3d_main_twmode_remove(&bmain->screen, scene, i);
 -              BLI_freelinkN(transform_spaces, target);
 -      }
 +      BKE_scene_transform_orientation_remove(CTX_data_scene(C), target);
  }
  
  void BIF_removeTransformOrientationIndex(bContext *C, int index)
  {
 -      ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
 -      TransformOrientation *ts = BLI_findlink(transform_spaces, index);
 -
 -      if (ts) {
 -              BIF_removeTransformOrientation(C, ts);
 -      }
 +      TransformOrientation *target = BKE_scene_transform_orientation_find(CTX_data_scene(C), index);
 +      BIF_removeTransformOrientation(C, target);
  }
  
  void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target)
  {
 -      ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
 -      const int i = BLI_findindex(transform_spaces, target);
 +      Scene *scene = CTX_data_scene(C);
 +      int index = BKE_scene_transform_orientation_get_index(scene, target);
  
 -      if (i != -1) {
 -              View3D *v3d = CTX_wm_view3d(C);
 -              v3d->twmode = V3D_MANIP_CUSTOM + i;
 -      }
 +      BLI_assert(index != -1);
 +
 +      scene->orientation_type = V3D_MANIP_CUSTOM;
 +      scene->orientation_index_custom = index;
  }
  
 -void BIF_selectTransformOrientationValue(bContext *C, int orientation)
 +/**
 + * Activate a transform orientation in a 3D view based on an enum value.
 + *
 + * \param orientation: If this is #V3D_MANIP_CUSTOM or greater, the custom transform orientation
 + *                     with index \a orientation - #V3D_MANIP_CUSTOM gets activated.
 + */
 +void BIF_selectTransformOrientationValue(Scene *scene, int orientation)
  {
 -      View3D *v3d = CTX_wm_view3d(C);
 -      if (v3d) /* currently using generic poll */
 -              v3d->twmode = orientation;
 +      const bool is_custom = orientation >= V3D_MANIP_CUSTOM;
 +      scene->orientation_type = is_custom ? V3D_MANIP_CUSTOM : orientation;
 +      scene->orientation_index_custom = is_custom ? (orientation - V3D_MANIP_CUSTOM) : -1;
  }
  
  int BIF_countTransformOrientation(const bContext *C)
  {
 -      ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
 -      return BLI_listbase_count(transform_spaces);
 +      Scene *scene = CTX_data_scene(C);
 +      ListBase *transform_orientations = &scene->transform_spaces;
 +      return BLI_listbase_count(transform_orientations);
  }
  
 -bool applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name, int index)
 +bool applyTransformOrientation(const TransformOrientation *ts, float r_mat[3][3], char *r_name)
  {
 -      ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
 -      TransformOrientation *ts = BLI_findlink(transform_spaces, index);
 -
 -      BLI_assert(index >= 0);
 -
 -      if (ts) {
 -              if (r_name) {
 -                      BLI_strncpy(r_name, ts->name, MAX_NAME);
 -              }
 -
 -              copy_m3_m3(mat, ts->mat);
 -              return true;
 -      }
 -      else {
 -              /* invalid index, can happen sometimes */
 -              return false;
 +      if (r_name) {
 +              BLI_strncpy(r_name, ts->name, MAX_NAME);
        }
 +      copy_m3_m3(r_mat, ts->mat);
 +
 +      return true;
  }
  
  static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it)
@@@ -481,16 -492,8 +481,16 @@@ void initTransformOrientation(bContext 
                                unit_m3(t->spacemtx);
                        }
                        break;
 -              default: /* V3D_MANIP_CUSTOM */
 -                      if (applyTransformOrientation(C, t->spacemtx, t->spacename, t->current_orientation - V3D_MANIP_CUSTOM)) {
 +              case V3D_MANIP_CURSOR:
 +              {
 +                      BLI_strncpy(t->spacename, IFACE_("cursor"), sizeof(t->spacename));
 +                      ED_view3d_cursor3d_calc_mat3(t->scene, CTX_wm_view3d(C), t->spacemtx);
 +                      break;
 +              }
 +              case V3D_MANIP_CUSTOM:
 +                      BLI_strncpy(t->spacename, t->custom_orientation->name, sizeof(t->spacename));
 +
 +                      if (applyTransformOrientation(t->custom_orientation, t->spacemtx, t->spacename)) {
                                /* pass */
                        }
                        else {
@@@ -583,10 -586,10 +583,10 @@@ static unsigned int bm_mesh_faces_selec
  
  int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3], const short around)
  {
 -      Scene *scene = CTX_data_scene(C);
 +      ViewLayer *view_layer = CTX_data_view_layer(C);
        Object *obedit = CTX_data_edit_object(C);
        Base *base;
 -      Object *ob = OBACT;
 +      Object *ob = OBACT(view_layer);
        int result = ORIENTATION_NONE;
        const bool activeOnly = (around == V3D_AROUND_ACTIVE);
  
                                                }
                                        }
  
-                                       result = ORIENTATION_EDGE;
+                                       result = is_zero_v3(plane) ? ORIENTATION_VERT : ORIENTATION_EDGE;
                                }
                                else if (em->bm->totvertsel > 3) {
                                        BMIter iter;
        }
        else {
                /* we need the one selected object, if its not active */
 -              View3D *v3d = CTX_wm_view3d(C);
 -              ob = OBACT;
 -              if (ob && (ob->flag & SELECT)) {
 +              base = BASACT(view_layer);
 +              ob = OBACT(view_layer);
 +              if (base && ((base->flag & BASE_SELECTED) != 0)) {
                        /* pass */
                }
                else {
                        /* first selected */
                        ob = NULL;
 -                      for (base = scene->base.first; base; base = base->next) {
 -                              if (TESTBASELIB(v3d, base)) {
 +                      for (base = view_layer->object_bases.first; base; base = base->next) {
 +                              if (TESTBASELIB(base)) {
                                        ob = base->object;
                                        break;
                                }
@@@ -1122,9 -1125,6 +1122,9 @@@ void ED_getTransformOrientationMatrix(c
                                type = ORIENTATION_NONE;
                        }
                        break;
 +              default:
 +                      BLI_assert(type == ORIENTATION_NONE);
 +                      break;
        }
  
        if (type == ORIENTATION_NONE) {