Commit: 40f4343679b2df5c0ae4dc361542f3be5b0f66d7
Author: Campbell Barton
Date:   Mon Dec 3 21:20:05 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB40f4343679b2df5c0ae4dc361542f3be5b0f66d7

3D View: remove non tool-system ruler

There was duplicate code for the ruler being accessed
as a tool and an operator.

Remove the modal operator code in favor of tool access.

===================================================================

M       source/blender/editors/space_view3d/CMakeLists.txt
M       source/blender/editors/space_view3d/view3d_ops.c
D       source/blender/editors/space_view3d/view3d_ruler.c

===================================================================

diff --git a/source/blender/editors/space_view3d/CMakeLists.txt 
b/source/blender/editors/space_view3d/CMakeLists.txt
index 0d30d623b8d..44089734e83 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -66,7 +66,6 @@ set(SRC
        view3d_gizmo_preselect_type.c
        view3d_ops.c
        view3d_project.c
-       view3d_ruler.c
        view3d_select.c
        view3d_snap.c
        view3d_toolbar.c
diff --git a/source/blender/editors/space_view3d/view3d_ops.c 
b/source/blender/editors/space_view3d/view3d_ops.c
index 7e4f04feaef..46a00ffeacf 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -209,7 +209,6 @@ void view3d_operatortypes(void)
        WM_operatortype_append(VIEW3D_OT_fly);
        WM_operatortype_append(VIEW3D_OT_walk);
        WM_operatortype_append(VIEW3D_OT_navigate);
-       WM_operatortype_append(VIEW3D_OT_ruler);
        WM_operatortype_append(VIEW3D_OT_copybuffer);
        WM_operatortype_append(VIEW3D_OT_pastebuffer);
 
diff --git a/source/blender/editors/space_view3d/view3d_ruler.c 
b/source/blender/editors/space_view3d/view3d_ruler.c
deleted file mode 100644
index 208f147f943..00000000000
--- a/source/blender/editors/space_view3d/view3d_ruler.c
+++ /dev/null
@@ -1,1123 +0,0 @@
-/*
- * ***** 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): Campbell Barton
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_view3d/view3d_ruler.c
- *  \ingroup spview3d
- */
-
-/* defines VIEW3D_OT_ruler modal operator */
-
-#include "DNA_meshdata_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_object_types.h"
-#include "DNA_gpencil_types.h"
-#include "DNA_brush_types.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-
-#include "BLT_translation.h"
-
-#include "BKE_context.h"
-#include "BKE_gpencil.h"
-#include "BKE_main.h"
-#include "BKE_material.h"
-#include "BKE_unit.h"
-
-#include "BIF_gl.h"
-
-#include "GPU_immediate.h"
-#include "GPU_immediate_util.h"
-#include "GPU_state.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "ED_gpencil.h"
-#include "ED_screen.h"
-#include "ED_view3d.h"
-#include "ED_transform_snap_object_context.h"
-#include "ED_space_api.h"
-
-#include "BLF_api.h"
-#include "BIF_glutil.h"
-
-#include "UI_resources.h"
-#include "UI_interface.h"
-
-#include "view3d_intern.h"  /* own include */
-
-#define MVAL_MAX_PX_DIST 12.0f
-
-
-/* -------------------------------------------------------------------- */
-/* Ruler Item (we can have many) */
-enum {
-       RULERITEM_USE_ANGLE = (1 << 0),  /* use protractor */
-       RULERITEM_USE_RAYCAST = (1 << 1)
-};
-
-enum {
-       RULERITEM_DIRECTION_IN = 0,
-       RULERITEM_DIRECTION_OUT
-};
-
-/* keep smaller then selection, since we may want click elsewhere without 
selecting a ruler */
-#define RULER_PICK_DIST 12.0f
-#define RULER_PICK_DIST_SQ (RULER_PICK_DIST * RULER_PICK_DIST)
-
-typedef struct RulerItem {
-       struct RulerItem *next, *prev;
-
-       /* worldspace coords, middle being optional */
-       float co[3][3];
-
-       /* selected coord */
-       char  co_index; /* 0 -> 2*/
-
-       int   flag;
-       int   raycast_dir;  /* RULER_DIRECTION_* */
-} RulerItem;
-
-
-/* -------------------------------------------------------------------- */
-/* Ruler Info (one per session) */
-
-enum {
-       RULER_STATE_NORMAL = 0,
-       RULER_STATE_DRAG
-};
-
-enum {
-       RULER_SNAP_OK = (1 << 0),
-};
-
-typedef struct RulerInfo {
-       ListBase items;
-       int      item_active;
-       int flag;
-       int snap_flag;
-       int state;
-       float drag_start_co[3];
-
-       struct SnapObjectContext *snap_context;
-
-       /* wm state */
-       wmWindow *win;
-       ScrArea *sa;
-       void *draw_handle_pixel;
-       ARegion *ar;  /* re-assigned every modal update */
-} RulerInfo;
-
-/* -------------------------------------------------------------------- */
-/* local functions */
-static RulerItem *ruler_item_add(RulerInfo *ruler_info)
-{
-       RulerItem *ruler_item = MEM_callocN(sizeof(RulerItem), "RulerItem");
-       BLI_addtail(&ruler_info->items, ruler_item);
-       return ruler_item;
-}
-
-static void ruler_item_remove(RulerInfo *ruler_info, RulerItem *ruler_item)
-{
-       BLI_remlink(&ruler_info->items, ruler_item);
-
-       MEM_freeN(ruler_item);
-}
-
-static RulerItem *ruler_item_active_get(RulerInfo *ruler_info)
-{
-       return BLI_findlink(&ruler_info->items, ruler_info->item_active);
-}
-
-static void ruler_item_active_set(RulerInfo *ruler_info, RulerItem *ruler_item)
-{
-       ruler_info->item_active = BLI_findindex(&ruler_info->items, ruler_item);
-}
-
-static void ruler_item_as_string(RulerItem *ruler_item, UnitSettings *unit,
-                                 char *numstr, size_t numstr_size, int prec)
-{
-
-       if (ruler_item->flag & RULERITEM_USE_ANGLE) {
-               const float ruler_angle = angle_v3v3v3(ruler_item->co[0],
-                                                      ruler_item->co[1],
-                                                      ruler_item->co[2]);
-
-               if (unit->system == USER_UNIT_NONE) {
-                       BLI_snprintf(numstr, numstr_size, "%.*f°", prec, 
RAD2DEGF(ruler_angle));
-               }
-               else {
-                       bUnit_AsString2(
-                               numstr, numstr_size, (double)ruler_angle,
-                               prec, B_UNIT_ROTATION, unit, false);
-               }
-       }
-       else {
-               const float ruler_len = len_v3v3(ruler_item->co[0],
-                                                ruler_item->co[2]);
-
-               if (unit->system == USER_UNIT_NONE) {
-                       BLI_snprintf(numstr, numstr_size, "%.*f", prec, 
ruler_len);
-               }
-               else {
-                       bUnit_AsString2(
-                               numstr, numstr_size, (double)(ruler_len * 
unit->scale_length),
-                               prec, B_UNIT_LENGTH, unit, false);
-               }
-       }
-
-}
-
-static bool view3d_ruler_pick(RulerInfo *ruler_info, const float mval[2],
-                              RulerItem **r_ruler_item, int *r_co_index)
-{
-       ARegion *ar = ruler_info->ar;
-       RulerItem *ruler_item;
-
-       float dist_best = RULER_PICK_DIST_SQ;
-       RulerItem *ruler_item_best = NULL;
-       int co_index_best = -1;
-
-       for (ruler_item = ruler_info->items.first; ruler_item; ruler_item = 
ruler_item->next) {
-               float co_ss[3][2];
-               float dist;
-               int j;
-
-               /* should these be checked? - ok for now not to */
-               for (j = 0; j < 3; j++) {
-                       ED_view3d_project_float_global(ar, ruler_item->co[j], 
co_ss[j], V3D_PROJ_TEST_NOP);
-               }
-
-               if (ruler_item->flag & RULERITEM_USE_ANGLE) {
-                       dist = min_ff(dist_squared_to_line_segment_v2(mval, 
co_ss[0], co_ss[1]),
-                                     dist_squared_to_line_segment_v2(mval, 
co_ss[1], co_ss[2]));
-                       if (dist < dist_best) {
-                               dist_best = dist;
-                               ruler_item_best = ruler_item;
-
-                               {
-                                       const float dist_points[3] = {
-                                           len_squared_v2v2(co_ss[0], mval),
-                                           len_squared_v2v2(co_ss[1], mval),
-                                           len_squared_v2v2(co_ss[2], mval),
-                                       };
-                                       if (min_fff(UNPACK3(dist_points)) < 
RULER_PICK_DIST_SQ) {
-                                               co_index_best = 
min_axis_v3(dist_points);
-                                       }
-                                       else {
-                                               co_index_best = -1;
-                                       }
-                               }
-                       }
-               }
-               else {
-                       dist = dist_squared_to_line_segment_v2(mval, co_ss[0], 
co_ss[2]);
-                       if (dist < dist_best) {
-                               dist_best = dist;
-                               ruler_item_best = ruler_item;
-
-                               {
-                                       const float dist_points[2] = {
-                                           len_squared_v2v2(co_ss[0], mval),
-                                           len_squared_v2v2(co_ss[2], mval),
-                                       };
-                                       if (min_ff(UNPACK2(dist_points)) < 
RULER_PICK_DIST_SQ) {
-                                               co_index_best = (dist_points[0] 
< dist_points[1]) ? 0 : 2;
-                                       }
-                                       else {
-                                               co_index_best = -1;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       if (ruler_item_best) {
-               *r_ruler_item = ruler_item_best;
-               *r_co_index = co_index_best;
-               return true;
-       }
-       else {
-               *r_ruler_item = NULL;
-               *r_co_index = -1;
-               return false;
-       }
-}
-
-/**
- * Ensure the 'snap_context' is only cached while dragging,
- * needed since the user may toggle modes between tool use.
- */
-static void ruler_state_set(bContext *C, RulerInfo *ruler_info, int state)
-{
-       Main *bmain = CTX_data_main(C);
-       if (state == ruler_info->state) {
-               return;
-       }
-
-       /* always remove */
-       if (ruler_info->snap_context) {
-               
ED_transform_snap_object_context_destroy(ruler_info->snap_context);
-               ruler_info->snap_context = NULL;
-       }
-
-       if (state == RULER_STATE_NORMAL) {
-               /* pass */
-       }
-       else if (state == RULER_STATE_DRAG) {
-               ruler_info->snap_context = 
ED_transform_snap_object_context_create_view3d(
-                       bmain, CTX_data_scene(C), CTX_data_depsgraph(C), 0,
-                       ruler_info->ar, CTX_wm_view3d(C));
-       }
-       else {
-               BLI_assert(0);
-       }
-
-       ruler_info->state = state;
-}
-
-#define RULER_ID "RulerData3D"
-static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info)
-{
-       Main *bmain = CTX_data_main(C);
-       Scene *scene = CTX_data_scene(C);
-
-       bGPDlayer *gpl;
-       bGPDframe *gpf;
-       bGPDstroke *gps;
-       RulerItem *ruler_item;
-       const char *ruler_name = RULER_ID;
-       bool changed = false;
-
-       /* FIXME: This needs to be reviewed. Should it keep being done like 
this? */
-       if (scene->gpd == NULL) {
-               scene->gpd = BKE_gpencil_data_addnew(bmain, "Annotations");
-       }
-       bGPdata *gpd = scene->gpd;
-
-       gpl = BLI_findstring(&gpd->layers, ruler_name, offsetof(bGPDlayer, 
info));
-       if (gpl == NULL) {
-               gpl = BKE_gpencil_layer_addnew(gpd, ruler_name, false);
-               copy_v4_v4(gpl->color, U.gpencil_new_layer_col);
-               gpl->thickness = 1;
-               gpl->flag |= GP_LAYER_HIDE;
-       }
-
-       gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_NEW);
-       BKE_gpencil_free_strokes(gpf);
-
-       for (ruler_item = ruler_info->items.first; ruler_item; ruler_item = 
ruler_item->next) {
-               bGPDspoint *pt;
-               int j;
-
-               /* allocate memory for a new stroke */
-               gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");


@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to