Blender V4.5
editcurve_pen.cc File Reference
#include "DNA_curve_types.h"
#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.h"
#include "BKE_context.hh"
#include "BKE_curve.hh"
#include "DEG_depsgraph.hh"
#include "WM_api.hh"
#include "ED_curve.hh"
#include "ED_screen.hh"
#include "ED_select_utils.hh"
#include "ED_view3d.hh"
#include "curve_intern.hh"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include <cfloat>

Go to the source code of this file.

Classes

struct  CutData
struct  MoveSegmentData
struct  CurvePenData

Macros

#define FOREACH_SELECTED_BEZT_BEGIN(bezt, nurbs)
#define FOREACH_SELECTED_BEZT_END
#define SEL_DIST_FACTOR   0.2f

Enumerations

enum  eClose_opt { OFF = 0 , ON_PRESS = 1 , ON_CLICK = 2 }
enum  {
  PEN_MODAL_FREE_ALIGN_TOGGLE = 1 , PEN_MODAL_MOVE_ADJACENT , PEN_MODAL_MOVE_ENTIRE , PEN_MODAL_LINK_HANDLES ,
  PEN_MODAL_LOCK_ANGLE
}

Functions

static void update_location_for_2d_curve (const ViewContext *vc, float location[3])
static void screenspace_to_worldspace (const ViewContext *vc, const float pos_2d[2], const float depth[3], float r_pos_3d[3])
static void screenspace_to_worldspace_int (const ViewContext *vc, const int pos_2d[2], const float depth[3], float r_pos_3d[3])
static bool worldspace_to_screenspace (const ViewContext *vc, const float pos_3d[3], float r_pos_2d[2])
static void move_bezt_by_displacement (BezTriple *bezt, const float disp_3d[3])
static void move_bezt_to_location (BezTriple *bezt, const float location[3])
static void remove_handle_movement_constraints (BezTriple *bezt, const bool f1, const bool f3)
static void move_bezt_handle_or_vertex_by_displacement (const ViewContext *vc, BezTriple *bezt, const int bezt_idx, const float disp_2d[2], const float distance, const bool link_handles, const bool lock_angle)
static void move_bp_to_location (const ViewContext *vc, BPoint *bp, const float mval[2])
static bool get_selected_center (const ListBase *nurbs, const bool mid_only, const bool bezt_only, float r_center[3])
static void move_all_selected_points (const ViewContext *vc, const wmEvent *event, CurvePenData *cpd, ListBase *nurbs, const bool bezt_only)
static int get_nurb_index (const ListBase *nurbs, const Nurb *nurb)
static void delete_nurb (Curve *cu, Nurb *nu)
static void delete_bezt_from_nurb (const BezTriple *bezt, Nurb *nu, EditNurb *editnurb)
static void delete_bp_from_nurb (const BPoint *bp, Nurb *nu, EditNurb *editnurb)
static bool get_closest_vertex_to_point_in_nurbs (const ViewContext *vc, const ListBase *nurbs, const float point[2], Nurb **r_nu, BezTriple **r_bezt, BPoint **r_bp, int *r_bezt_idx)
static void get_bezier_interpolated_point (const BezTriple *bezt1, const BezTriple *bezt2, const float parameter, float r_point[3])
static void calculate_new_bezier_point (const float point_prev[3], float handle_prev[3], float new_left_handle[3], float new_right_handle[3], float handle_next[3], const float point_next[3], const float parameter)
static bool is_cyclic (const Nurb *nu)
static void insert_bezt_to_nurb (Nurb *nu, const CutData *data, Curve *cu)
static void insert_bp_to_nurb (Nurb *nu, const CutData *data, Curve *cu)
static void get_updated_data_for_edge (const float point[2], const float point1[2], const float point2[2], const int point_idx, const int resolu_idx, float *r_min_dist, int *r_min_i, float *r_param)
static void update_cut_data_for_nurb (const ViewContext *vc, CutData *cd, Nurb *nu, const int resolu, const float point[2])
static bool update_cut_data_for_all_nurbs (const ViewContext *vc, const ListBase *nurbs, const float point[2], const float sel_dist, CutData *cd)
static CutData init_cut_data (const wmEvent *event)
static bool insert_point_to_segment (const ViewContext *vc, const wmEvent *event)
static void get_first_selected_point (Curve *cu, View3D *v3d, Nurb **r_nu, BezTriple **r_bezt, BPoint **r_bp)
static void extrude_vertices_from_selected_endpoints (EditNurb *editnurb, ListBase *nurbs, Curve *cu, const float disp_3d[3])
static void deselect_all_center_vertices (ListBase *nurbs)
static bool is_last_bezt (const Nurb *nu, const BezTriple *bezt)
static void extrude_points_from_selected_vertices (const ViewContext *vc, const wmEvent *event, const int extrude_handle)
static bool is_spline_nearby (ViewContext *vc, wmOperator *op, const wmEvent *event, const float sel_dist)
static void move_segment (const ViewContext *vc, MoveSegmentData *seg_data, const wmEvent *event)
static void toggle_bezt_free_align_handles (BezTriple *bezt)
static void toggle_sel_bezt_free_align_handles (ListBase *nurbs)
static bool delete_point_under_mouse (const ViewContext *vc, const wmEvent *event)
static void move_adjacent_handle (const ViewContext *vc, const wmEvent *event, ListBase *nurbs)
static bool make_cyclic_if_endpoints (const ViewContext *vc, Nurb *sel_nu, BezTriple *sel_bezt, BPoint *sel_bp)
static void init_selected_bezt_handles (ListBase *nurbs)
static void toggle_select_bezt (BezTriple *bezt, const int bezt_idx, Curve *cu, Nurb *nu)
static void toggle_select_bp (BPoint *bp, Curve *cu, Nurb *nu)
static void toggle_handle_types (BezTriple *bezt, int bezt_idx, CurvePenData *cpd)
static void cycle_handles (BezTriple *bezt)
wmKeyMapcurve_pen_modal_keymap (wmKeyConfig *keyconf)
static wmOperatorStatus curve_pen_modal (bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus curve_pen_invoke (bContext *C, wmOperator *op, const wmEvent *event)
void CURVE_OT_pen (wmOperatorType *ot)

Variables

static const EnumPropertyItem prop_handle_types []
static const EnumPropertyItem prop_close_spline_method []

Macro Definition Documentation

◆ FOREACH_SELECTED_BEZT_BEGIN

#define FOREACH_SELECTED_BEZT_BEGIN ( bezt,
nurbs )
Value:
LISTBASE_FOREACH (Nurb *, nu, nurbs) { \
if (nu->type == CU_BEZIER) { \
for (int i = 0; i < nu->pntsu; i++) { \
BezTriple *bezt = nu->bezt + i; \
if (BEZT_ISSEL_ANY(bezt) && !bezt->hide) {
#define LISTBASE_FOREACH(type, var, list)
@ CU_BEZIER
#define BEZT_ISSEL_ANY(bezt)
i
Definition text_draw.cc:230

Definition at line 38 of file editcurve_pen.cc.

Referenced by extrude_points_from_selected_vertices(), init_selected_bezt_handles(), move_adjacent_handle(), and toggle_sel_bezt_free_align_handles().

◆ FOREACH_SELECTED_BEZT_END

#define FOREACH_SELECTED_BEZT_END
Value:
} \
} \
} \
BKE_nurb_handles_calc(nu); \
} \
((void)0)

Definition at line 45 of file editcurve_pen.cc.

Referenced by extrude_points_from_selected_vertices(), init_selected_bezt_handles(), move_adjacent_handle(), and toggle_sel_bezt_free_align_handles().

◆ SEL_DIST_FACTOR

#define SEL_DIST_FACTOR   0.2f

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PEN_MODAL_FREE_ALIGN_TOGGLE 
PEN_MODAL_MOVE_ADJACENT 
PEN_MODAL_MOVE_ENTIRE 
PEN_MODAL_LINK_HANDLES 
PEN_MODAL_LOCK_ANGLE 

Definition at line 1498 of file editcurve_pen.cc.

◆ eClose_opt

enum eClose_opt
Enumerator
OFF 
ON_PRESS 
ON_CLICK 

Definition at line 130 of file editcurve_pen.cc.

Function Documentation

◆ calculate_new_bezier_point()

void calculate_new_bezier_point ( const float point_prev[3],
float handle_prev[3],
float new_left_handle[3],
float new_right_handle[3],
float handle_next[3],
const float point_next[3],
const float parameter )
static

Calculate handle positions of added and adjacent control points such that shape is preserved.

Definition at line 576 of file editcurve_pen.cc.

References calculate_new_bezier_point(), and interp_v3_v3v3().

Referenced by calculate_new_bezier_point(), and insert_bezt_to_nurb().

◆ CURVE_OT_pen()

◆ curve_pen_invoke()

◆ curve_pen_modal()

wmOperatorStatus curve_pen_modal ( bContext * C,
wmOperator * op,
const wmEvent * event )
static

Definition at line 1551 of file editcurve_pen.cc.

References CurvePenData::bezt, Nurb::bezt, MoveSegmentData::bezt_index, BKE_nurb_bezt_get_next(), BKE_nurb_handles_calc(), CurvePenData::bp, C, CurvePenData::changed, copy_v2_v2_int(), CTX_data_edit_object(), CTX_data_ensure_evaluated_depsgraph(), CU_BEZIER, curve_pen_modal(), wmOperator::customdata, cycle_handles(), Object::data, DEG_id_tag_update(), delete_point_under_mouse(), CurvePenData::dragging, ED_curve_deselect_all(), ED_curve_editnurb_select_pick(), ED_view3d_select_dist_px(), ED_view3d_viewcontext_init(), Curve::editnurb, ELEM, EVT_MODAL_MAP, extrude_points_from_selected_vertices(), CurvePenData::found_point, get_closest_vertex_to_point_in_nurbs(), init_selected_bezt_handles(), insert_point_to_segment(), is_cyclic(), ISMOUSE_MOTION, KM_DBL_CLICK, KM_RELEASE, KM_SHIFT, LEFTMOUSE, CurvePenData::link_handles, CurvePenData::lock_angle, make_cyclic_if_endpoints(), MEM_callocN(), MEM_freeN(), CurvePenData::move_adjacent, move_adjacent_handle(), move_all_selected_points(), CurvePenData::move_entire, move_segment(), CurvePenData::msd, ViewContext::mval, wmEvent::mval, NC_GEOM, ND_DATA, ND_SELECT, CurvePenData::new_point, CurvePenData::nu, MoveSegmentData::nu, EditNurb::nurbs, ViewContext::obedit, ON_CLICK, OPERATOR_FINISHED, OPERATOR_RUNNING_MODAL, PEN_MODAL_FREE_ALIGN_TOGGLE, PEN_MODAL_LINK_HANDLES, PEN_MODAL_LOCK_ANGLE, PEN_MODAL_MOVE_ADJACENT, PEN_MODAL_MOVE_ENTIRE, wmEvent::prev_press_xy, wmOperator::ptr, ret, RNA_boolean_get(), RNA_enum_get(), SEL_DIST_FACTOR, SEL_OP_SET, CurvePenData::select_multi, CurvePenData::selection_made, CurvePenData::spline_nearby, toggle_bezt_free_align_handles(), toggle_handle_types(), toggle_sel_bezt_free_align_handles(), toggle_select_bezt(), toggle_select_bp(), Nurb::type, wmEvent::type, wmEvent::val, WM_event_add_notifier(), and WM_event_drag_test().

Referenced by CURVE_OT_pen(), and curve_pen_modal().

◆ curve_pen_modal_keymap()

◆ cycle_handles()

void cycle_handles ( BezTriple * bezt)
static

Definition at line 1482 of file editcurve_pen.cc.

References cycle_handles(), BezTriple::h1, BezTriple::h2, HD_ALIGN, HD_AUTO, HD_FREE, and HD_VECT.

Referenced by curve_pen_modal(), and cycle_handles().

◆ delete_bezt_from_nurb()

◆ delete_bp_from_nurb()

◆ delete_nurb()

◆ delete_point_under_mouse()

◆ deselect_all_center_vertices()

void deselect_all_center_vertices ( ListBase * nurbs)
static

Deselect all vertices that are not endpoints.

Definition at line 1056 of file editcurve_pen.cc.

References BEZT_DESEL_ALL, CU_BEZIER, deselect_all_center_vertices(), i, is_cyclic(), LISTBASE_FOREACH, and SELECT.

Referenced by deselect_all_center_vertices(), and extrude_points_from_selected_vertices().

◆ extrude_points_from_selected_vertices()

◆ extrude_vertices_from_selected_endpoints()

◆ get_bezier_interpolated_point()

void get_bezier_interpolated_point ( const BezTriple * bezt1,
const BezTriple * bezt2,
const float parameter,
float r_point[3] )
static

Interpolate along the Bezier segment by a parameter (between 0 and 1) and get its location.

Definition at line 559 of file editcurve_pen.cc.

References get_bezier_interpolated_point(), interp_v3_v3v3(), and BezTriple::vec.

Referenced by get_bezier_interpolated_point(), insert_point_to_segment(), and move_segment().

◆ get_closest_vertex_to_point_in_nurbs()

bool get_closest_vertex_to_point_in_nurbs ( const ViewContext * vc,
const ListBase * nurbs,
const float point[2],
Nurb ** r_nu,
BezTriple ** r_bezt,
BPoint ** r_bp,
int * r_bezt_idx )
static

◆ get_first_selected_point()

void get_first_selected_point ( Curve * cu,
View3D * v3d,
Nurb ** r_nu,
BezTriple ** r_bezt,
BPoint ** r_bp )
static

Get the first selected point from the curve. If more than one selected point is found, define and return only the first detected nu.

Definition at line 886 of file editcurve_pen.cc.

References BEZT_ISSEL_ANY_HIDDENHANDLES, CU_BEZIER, Curve::editnurb, BPoint::f1, get_first_selected_point(), LISTBASE_FOREACH, EditNurb::nurbs, and SELECT.

Referenced by curve_pen_invoke(), and get_first_selected_point().

◆ get_nurb_index()

int get_nurb_index ( const ListBase * nurbs,
const Nurb * nurb )
static

Definition at line 430 of file editcurve_pen.cc.

References BLI_findindex(), and get_nurb_index().

Referenced by delete_nurb(), and get_nurb_index().

◆ get_selected_center()

bool get_selected_center ( const ListBase * nurbs,
const bool mid_only,
const bool bezt_only,
float r_center[3] )
static

Get the average position of selected points.

Parameters
mid_onlyUse only the middle point of the three points on a BezTriple.
bezt_onlyUse only points of Bezier splines.

Definition at line 313 of file editcurve_pen.cc.

References add_v3_v3(), BEZT_ISSEL_ANY, BEZT_ISSEL_IDX, CU_BEZIER, get_selected_center(), BezTriple::hide, i, LISTBASE_FOREACH, mul_v3_fl(), SELECT, BezTriple::vec, and zero_v3().

Referenced by extrude_points_from_selected_vertices(), get_selected_center(), and move_all_selected_points().

◆ get_updated_data_for_edge()

void get_updated_data_for_edge ( const float point[2],
const float point1[2],
const float point2[2],
const int point_idx,
const int resolu_idx,
float * r_min_dist,
int * r_min_i,
float * r_param )
static

Update r_min_dist, r_min_i, and r_param based on the edge and the external point.

Parameters
pointExternal point
point1One end of the edge
point2The other end of the edge
point_idxIndex of the control point out of the points on the Nurb
resolu_idxIndex of the edge on a Bezier segment (zero for non-Bezier edges)
r_min_distminimum distance from point to edge
r_min_iindex of closest point on Nurb
r_paramthe fraction along the edge at which the closest point lies

Definition at line 708 of file editcurve_pen.cc.

References angle_v2v2(), cos_v2v2v2(), dot_v2v2(), get_updated_data_for_edge(), len_v2(), sinf, and sub_v2_v2v2().

Referenced by get_updated_data_for_edge(), and update_cut_data_for_nurb().

◆ init_cut_data()

◆ init_selected_bezt_handles()

◆ insert_bezt_to_nurb()

◆ insert_bp_to_nurb()

◆ insert_point_to_segment()

◆ is_cyclic()

◆ is_last_bezt()

bool is_last_bezt ( const Nurb * nu,
const BezTriple * bezt )
static

Definition at line 1081 of file editcurve_pen.cc.

References Nurb::bezt, is_cyclic(), is_last_bezt(), and Nurb::pntsu.

Referenced by init_selected_bezt_handles(), and is_last_bezt().

◆ is_spline_nearby()

◆ make_cyclic_if_endpoints()

bool make_cyclic_if_endpoints ( const ViewContext * vc,
Nurb * sel_nu,
BezTriple * sel_bezt,
BPoint * sel_bp )
static

◆ move_adjacent_handle()

◆ move_all_selected_points()

◆ move_bezt_by_displacement()

void move_bezt_by_displacement ( BezTriple * bezt,
const float disp_3d[3] )
static

◆ move_bezt_handle_or_vertex_by_displacement()

void move_bezt_handle_or_vertex_by_displacement ( const ViewContext * vc,
BezTriple * bezt,
const int bezt_idx,
const float disp_2d[2],
const float distance,
const bool link_handles,
const bool lock_angle )
static

◆ move_bezt_to_location()

void move_bezt_to_location ( BezTriple * bezt,
const float location[3] )
static

Move entire control point to given worldspace location.

Definition at line 224 of file editcurve_pen.cc.

References move_bezt_by_displacement(), move_bezt_to_location(), sub_v3_v3v3(), and BezTriple::vec.

Referenced by move_bezt_handle_or_vertex_by_displacement(), and move_bezt_to_location().

◆ move_bp_to_location()

void move_bp_to_location ( const ViewContext * vc,
BPoint * bp,
const float mval[2] )
static

◆ move_segment()

◆ remove_handle_movement_constraints()

void remove_handle_movement_constraints ( BezTriple * bezt,
const bool f1,
const bool f3 )
static

Alter handle types to allow free movement (Set handles to #FREE or #ALIGN).

Definition at line 234 of file editcurve_pen.cc.

References BezTriple::h1, BezTriple::h2, HD_ALIGN, HD_AUTO, HD_FREE, HD_VECT, and remove_handle_movement_constraints().

Referenced by move_all_selected_points(), move_segment(), and remove_handle_movement_constraints().

◆ screenspace_to_worldspace()

void screenspace_to_worldspace ( const ViewContext * vc,
const float pos_2d[2],
const float depth[3],
float r_pos_3d[3] )
static

◆ screenspace_to_worldspace_int()

void screenspace_to_worldspace_int ( const ViewContext * vc,
const int pos_2d[2],
const float depth[3],
float r_pos_3d[3] )
static

◆ toggle_bezt_free_align_handles()

void toggle_bezt_free_align_handles ( BezTriple * bezt)
static

◆ toggle_handle_types()

void toggle_handle_types ( BezTriple * bezt,
int bezt_idx,
CurvePenData * cpd )
static

◆ toggle_sel_bezt_free_align_handles()

void toggle_sel_bezt_free_align_handles ( ListBase * nurbs)
static

◆ toggle_select_bezt()

void toggle_select_bezt ( BezTriple * bezt,
const int bezt_idx,
Curve * cu,
Nurb * nu )
static

◆ toggle_select_bp()

void toggle_select_bp ( BPoint * bp,
Curve * cu,
Nurb * nu )
static

◆ update_cut_data_for_all_nurbs()

bool update_cut_data_for_all_nurbs ( const ViewContext * vc,
const ListBase * nurbs,
const float point[2],
const float sel_dist,
CutData * cd )
static

◆ update_cut_data_for_nurb()

◆ update_location_for_2d_curve()

◆ worldspace_to_screenspace()

Variable Documentation

◆ prop_close_spline_method

const EnumPropertyItem prop_close_spline_method[]
static
Initial value:
= {
{OFF, "OFF", 0, "None", ""},
{ON_PRESS, "ON_PRESS", 0, "On Press", "Move handles after closing the spline"},
{ON_CLICK, "ON_CLICK", 0, "On Click", "Spline closes on release if not dragged"},
{0, nullptr, 0, nullptr, nullptr},
}
@ ON_PRESS
@ ON_CLICK
@ OFF

Definition at line 136 of file editcurve_pen.cc.

Referenced by CURVE_OT_pen().

◆ prop_handle_types

const EnumPropertyItem prop_handle_types[]
static
Initial value:
= {
{HD_AUTO, "AUTO", 0, "Auto", ""},
{HD_VECT, "VECTOR", 0, "Vector", ""},
{0, nullptr, 0, nullptr, nullptr},
}
@ HD_VECT
@ HD_AUTO

Definition at line 124 of file editcurve_pen.cc.

Referenced by CURVE_OT_pen().