Blender V5.0
view3d_gizmo_ruler.cc File Reference
#include "BLI_listbase.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.hh"
#include "BLI_math_matrix_types.hh"
#include "BLI_math_rotation.h"
#include "BLI_math_vector_types.hh"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "BKE_context.hh"
#include "BKE_gpencil_legacy.h"
#include "BKE_layer.hh"
#include "BKE_report.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "BKE_unit.hh"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_object_types.h"
#include "DNA_view3d_types.h"
#include "ED_gizmo_library.hh"
#include "ED_gizmo_utils.hh"
#include "ED_screen.hh"
#include "ED_transform.hh"
#include "ED_transform_snap_object_context.hh"
#include "ED_view3d.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "MEM_guardedalloc.h"
#include "RNA_access.hh"
#include "WM_api.hh"
#include "WM_toolsystem.hh"
#include "WM_types.hh"
#include "DEG_depsgraph_query.hh"
#include "view3d_intern.hh"
#include "GPU_immediate.hh"
#include "GPU_immediate_util.hh"
#include "GPU_matrix.hh"
#include "GPU_state.hh"
#include "BLF_api.hh"

Go to the source code of this file.

Classes

struct  RulerInfo
struct  RulerItem
struct  RulerInteraction

Macros

#define USE_AXIS_CONSTRAINTS
#define MVAL_MAX_PX_DIST   12.0f
#define RULER_PICK_DIST   12.0f
#define RULER_PICK_DIST_SQ   (RULER_PICK_DIST * RULER_PICK_DIST)
#define PART_LINE   0xff

Typedefs

using float2
using float2x2
using float3
using float3x2
using float3x3
using float4

Enumerations

enum  { RULERITEM_USE_ANGLE = (1 << 0) , RULERITEM_USE_ANGLE_ACTIVE = (1 << 1) }
enum  { RULER_STATE_NORMAL = 0 , RULER_STATE_DRAG }
enum  { CONSTRAIN_AXIS_NONE = -1 , CONSTRAIN_AXIS_X = 0 , CONSTRAIN_AXIS_Y = 1 , CONSTRAIN_AXIS_Z = 2 }
enum  { CONSTRAIN_MODE_OFF = 0 , CONSTRAIN_MODE_1 = 1 , CONSTRAIN_MODE_2 = 2 }

Functions

Internal Ruler Utilities
static RulerItemruler_item_add (wmGizmoGroup *gzgroup)
static void ruler_item_remove (bContext *C, wmGizmoGroup *gzgroup, RulerItem *ruler_item)
static void ruler_item_as_string (RulerItem *ruler_item, const UnitSettings &unit, char *numstr, size_t numstr_size, int prec)
static bool view3d_ruler_pick (wmGizmoGroup *gzgroup, RulerItem *ruler_item, const float2 mval, int *r_co_index)
static void ruler_state_set (RulerInfo *ruler_info, int state)
static void view3d_ruler_item_project (RulerInfo *ruler_info, float3 &r_co, const int xy[2])
static bool view3d_ruler_item_mousemove (const bContext *C, Depsgraph *depsgraph, RulerInfo *ruler_info, RulerItem *ruler_item, const int mval[2], const bool do_thickness, const bool do_snap)
static bool gizmo_ruler_check_for_operator (const wmGizmoGroup *gzgroup)
Ruler Item Gizmo Type
static void gizmo_ruler_draw (const bContext *C, wmGizmo *gz)
static int gizmo_ruler_test_select (bContext *, wmGizmo *gz, const int mval[2])
static wmOperatorStatus gizmo_ruler_modal (bContext *C, wmGizmo *gz, const wmEvent *event, eWM_GizmoFlagTweak tweak_flag)
static wmOperatorStatus gizmo_ruler_invoke (bContext *C, wmGizmo *gz, const wmEvent *event)
static void gizmo_ruler_exit (bContext *C, wmGizmo *gz, const bool cancel)
static int gizmo_ruler_cursor_get (wmGizmo *gz)
void VIEW3D_GT_ruler_item (wmGizmoType *gzt)
Ruler Gizmo Group
static void WIDGETGROUP_ruler_setup (const bContext *C, wmGizmoGroup *gzgroup)
void VIEW3D_GGT_ruler (wmGizmoGroupType *gzgt)
Add Ruler Operator
static bool view3d_ruler_poll (bContext *C)
static wmOperatorStatus view3d_ruler_add_invoke (bContext *C, wmOperator *op, const wmEvent *event)
void VIEW3D_OT_ruler_add (wmOperatorType *ot)
Remove Ruler Operator
static wmOperatorStatus view3d_ruler_remove_invoke (bContext *C, wmOperator *op, const wmEvent *)
void VIEW3D_OT_ruler_remove (wmOperatorType *ot)

Variables

static const char * view3d_gzgt_ruler_id = "VIEW3D_GGT_ruler"

Ruler/Grease Pencil Conversion

#define RULER_ID   "RulerData3D"
static bGPDlayerview3d_ruler_layer_get (bGPdata *gpd)
static RulerItemgzgroup_ruler_item_first_get (wmGizmoGroup *gzgroup)
static void view3d_ruler_gpencil_ensure (bContext *C)
static bool view3d_ruler_to_gpencil (bContext *C, wmGizmoGroup *gzgroup)
static bool view3d_ruler_from_gpencil (const bContext *C, wmGizmoGroup *gzgroup)
void ED_view3d_gizmo_ruler_remove_by_gpencil_layer (bContext *C, bGPDlayer *gpl)

Macro Definition Documentation

◆ MVAL_MAX_PX_DIST

#define MVAL_MAX_PX_DIST   12.0f

Definition at line 74 of file view3d_gizmo_ruler.cc.

◆ PART_LINE

#define PART_LINE   0xff

◆ RULER_ID

#define RULER_ID   "RulerData3D"

Definition at line 508 of file view3d_gizmo_ruler.cc.

Referenced by view3d_ruler_to_gpencil().

◆ RULER_PICK_DIST

#define RULER_PICK_DIST   12.0f

Definition at line 87 of file view3d_gizmo_ruler.cc.

◆ RULER_PICK_DIST_SQ

#define RULER_PICK_DIST_SQ   (RULER_PICK_DIST * RULER_PICK_DIST)

Definition at line 88 of file view3d_gizmo_ruler.cc.

Referenced by view3d_ruler_pick().

◆ USE_AXIS_CONSTRAINTS

#define USE_AXIS_CONSTRAINTS

Supporting transform features could be removed if the actual transform system is used. Keep the option open since each transform feature is duplicating logic.

Definition at line 70 of file view3d_gizmo_ruler.cc.

Typedef Documentation

◆ float2

Definition at line 618 of file BLI_math_vector_types.hh.

◆ float2x2

Definition at line 1004 of file BLI_math_matrix_types.hh.

◆ float3

Definition at line 619 of file BLI_math_vector_types.hh.

◆ float3x2

Definition at line 1007 of file BLI_math_matrix_types.hh.

◆ float3x3

Definition at line 1008 of file BLI_math_matrix_types.hh.

◆ float4

Definition at line 620 of file BLI_math_vector_types.hh.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
CONSTRAIN_AXIS_NONE 
CONSTRAIN_AXIS_X 
CONSTRAIN_AXIS_Y 
CONSTRAIN_AXIS_Z 

Definition at line 103 of file view3d_gizmo_ruler.cc.

◆ anonymous enum

anonymous enum
Enumerator
RULERITEM_USE_ANGLE 

Use protractor.

RULERITEM_USE_ANGLE_ACTIVE 

Protractor vertex is selected (deleting removes it).

Definition at line 79 of file view3d_gizmo_ruler.cc.

◆ anonymous enum

anonymous enum

Constraining modes. Off / Scene orientation / Global (or Local if Scene orientation is Global).

Enumerator
CONSTRAIN_MODE_OFF 
CONSTRAIN_MODE_1 
CONSTRAIN_MODE_2 

Definition at line 114 of file view3d_gizmo_ruler.cc.

◆ anonymous enum

anonymous enum
Enumerator
RULER_STATE_NORMAL 
RULER_STATE_DRAG 

Definition at line 96 of file view3d_gizmo_ruler.cc.

Function Documentation

◆ ED_view3d_gizmo_ruler_remove_by_gpencil_layer()

◆ gizmo_ruler_check_for_operator()

bool gizmo_ruler_check_for_operator ( const wmGizmoGroup * gzgroup)
static

When the gizmo-group has been created immediately before running an operator to manipulate rulers, it's possible the new gizmo-group has not yet been initialized. in 3.0 this happened because left-click drag would both select and add a new ruler, significantly increasing the likelihood of this happening. Workaround this crash by checking the gizmo's custom-data has not been cleared. The key-map has also been modified not to trigger this bug, see #95591.

Definition at line 477 of file view3d_gizmo_ruler.cc.

References wmGizmoGroup::customdata.

Referenced by view3d_ruler_add_invoke(), and view3d_ruler_remove_invoke().

◆ gizmo_ruler_cursor_get()

int gizmo_ruler_cursor_get ( wmGizmo * gz)
static

◆ gizmo_ruler_draw()

void gizmo_ruler_draw ( const bContext * C,
wmGizmo * gz )
static

Definition at line 683 of file view3d_gizmo_ruler.cc.

References angle(), angle_normalized_v3v3(), axis_angle_to_quat(), BLF_color3ubv(), BLF_disable(), BLF_draw(), BLF_enable(), blf_mono_font, BLF_position(), BLF_ROTATION, BLF_rotation(), BLF_size(), BLF_width_and_height(), C, RulerItem::co, col, copy_v3_fl(), blender::math::cross(), CTX_data_scene(), wmGizmoGroup::customdata, blender::math::distance(), ED_view3d_pixel_size_no_ui_scale(), ED_view3d_project_float_global(), fabs(), RulerItem::flag, GPU_blend(), GPU_BLEND_ALPHA, GPU_BLEND_NONE, GPU_line_smooth(), GPU_line_width(), GPU_matrix_identity_set(), GPU_matrix_pop(), GPU_matrix_pop_projection(), GPU_matrix_projection_set, GPU_matrix_push(), GPU_matrix_push_projection(), GPU_matrix_set, GPU_PRIM_LINE_STRIP, GPU_PRIM_LINES, GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR, GPU_SHADER_3D_UNIFORM_COLOR, GPU_vertformat_attr_add(), GPU_viewport_size_get_f(), immBegin(), immBindBuiltinProgram(), immEnd(), immRectf(), immUnbindProgram(), immUniform1f(), immUniform1i(), immUniform2f(), immUniform4f(), immUniform4fv(), immUniformColor3fv(), immUniformColor3ubv(), immUniformColor4fv(), immVertex2f(), immVertex2fv(), immVertex3fv(), immVertexFormat(), RulerInfo::item_active, len, len_v2v2(), min_fff(), mul_qt_v3(), blender::math::normalize(), normalize_v2(), wmGizmo::parent_gzgroup, RulerInfo::region, ARegion::regiondata, ruler_item_as_string(), RULERITEM_USE_ANGLE, RULERITEM_USE_ANGLE_ACTIVE, status, sub_v2_v2v2(), TH_TEXT, TH_WIRE, UI_GetThemeColor3ubv(), UI_SCALE_FAC, Scene::unit, V3D_PROJ_RET_OK, V3D_PROJ_TEST_CLIP_NEAR, RegionView3D::viewmat, RegionView3D::winmat, and wmOrtho2_region_pixelspace().

Referenced by VIEW3D_GT_ruler_item().

◆ gizmo_ruler_exit()

◆ gizmo_ruler_invoke()

◆ gizmo_ruler_modal()

◆ gizmo_ruler_test_select()

int gizmo_ruler_test_select ( bContext * ,
wmGizmo * gz,
const int mval[2] )
static

◆ gzgroup_ruler_item_first_get()

◆ ruler_item_add()

◆ ruler_item_as_string()

◆ ruler_item_remove()

◆ ruler_state_set()

void ruler_state_set ( RulerInfo * ruler_info,
int state )
static

Ensure the 'snap_context' is only cached while dragging, needed since the user may toggle modes between tool use.

Definition at line 300 of file view3d_gizmo_ruler.cc.

References BLI_assert, RulerInfo::drag_state_prev, RulerInfo::gizmo, RulerInfo::prop_prevpoint, wmGizmo::ptr, RNA_property_float_set_array(), RULER_STATE_DRAG, RULER_STATE_NORMAL, RulerInfo::snap_data, RulerInfo::state, state, WM_GIZMO_DRAW_VALUE, and WM_gizmo_set_flag().

Referenced by gizmo_ruler_exit(), and gizmo_ruler_invoke().

◆ VIEW3D_GGT_ruler()

◆ VIEW3D_GT_ruler_item()

◆ VIEW3D_OT_ruler_add()

void VIEW3D_OT_ruler_add ( wmOperatorType * ot)

◆ VIEW3D_OT_ruler_remove()

void VIEW3D_OT_ruler_remove ( wmOperatorType * ot)

◆ view3d_ruler_add_invoke()

◆ view3d_ruler_from_gpencil()

◆ view3d_ruler_gpencil_ensure()

◆ view3d_ruler_item_mousemove()

bool view3d_ruler_item_mousemove ( const bContext * C,
Depsgraph * depsgraph,
RulerInfo * ruler_info,
RulerItem * ruler_item,
const int mval[2],
const bool do_thickness,
const bool do_snap )
static

Use for mouse-move events.

Definition at line 336 of file view3d_gizmo_ruler.cc.

References RulerInfo::area, BKE_scene_orientation_get_index(), BKE_view_layer_active_object_get(), BKE_view_layer_synced_ensure(), BLI_assert, C, blender::ed::transform::calc_orientation_from_type_ex(), RulerItem::co, RulerInteraction::co_index, RulerInfo::constrain_axis, RulerInfo::constrain_mode, CONSTRAIN_MODE_2, CONSTRAIN_MODE_OFF, DEG_get_input_scene(), DEG_get_input_view_layer(), depsgraph, RulerInteraction::drag_start_co, ED_gizmotypes_snap_3d_context_ensure(), ED_gizmotypes_snap_3d_data_get(), ED_gizmotypes_snap_3d_is_enabled(), blender::ed::transform::SnapObjectParams::edit_mode_type, ListBase::first, RulerItem::flag, float, RulerInfo::gizmo, RulerItem::gz, i, wmGizmo::interaction_data, blender::math::invert(), MVAL_MAX_PX_DIST, OBEDIT_FROM_OBACT, RulerInfo::prop_prevpoint, RulerInfo::prop_snap_source_type, blender::MatBase< T, NumCol, NumRow, Alignment >::ptr(), wmGizmo::ptr, RulerInfo::region, ARegion::regiondata, RNA_property_enum_set(), RNA_property_float_set_array(), RULERITEM_USE_ANGLE, SCE_ORIENT_DEFAULT, SCE_SNAP_TARGET_ALL, SCE_SNAP_TO_FACE, RulerInfo::snap_data, blender::ed::transform::SNAP_GEOM_CAGE, blender::ed::transform::snap_object_project_ray(), blender::ed::transform::snap_object_project_view3d(), blender::ed::transform::SnapObjectParams::snap_target_select, RulerItem::snap_type, ScrArea::spacedata, Scene::toolsettings, ToolSettings::transform_pivot_point, U, V3D_ORIENT_GLOBAL, V3D_ORIENT_LOCAL, and view3d_ruler_item_project().

Referenced by gizmo_ruler_invoke(), gizmo_ruler_modal(), and view3d_ruler_add_invoke().

◆ view3d_ruler_item_project()

void view3d_ruler_item_project ( RulerInfo * ruler_info,
float3 & r_co,
const int xy[2] )
static

◆ view3d_ruler_layer_get()

◆ view3d_ruler_pick()

◆ view3d_ruler_poll()

◆ view3d_ruler_remove_invoke()

◆ view3d_ruler_to_gpencil()

◆ WIDGETGROUP_ruler_setup()

Variable Documentation

◆ view3d_gzgt_ruler_id

const char* view3d_gzgt_ruler_id = "VIEW3D_GGT_ruler"
static