Blender  V3.3
editcurve_query.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include "DNA_object_types.h"
9 #include "DNA_scene_types.h"
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_listbase.h"
14 #include "BLI_math.h"
15 
16 #include "BKE_curve.h"
17 #include "BKE_fcurve.h"
18 #include "BKE_layer.h"
19 
20 #include "DEG_depsgraph.h"
21 #include "DEG_depsgraph_build.h"
22 
23 #include "ED_curve.h"
24 #include "ED_view3d.h"
25 
26 #include "curve_intern.h"
27 
28 /* -------------------------------------------------------------------- */
32 static void ED_curve_pick_vert__do_closest(void *userData,
33  Nurb *nu,
34  BPoint *bp,
35  BezTriple *bezt,
36  int beztindex,
37  bool handles_visible,
38  const float screen_co[2])
39 {
40  struct {
41  BPoint *bp;
42  BezTriple *bezt;
43  Nurb *nurb;
44  float dist;
45  int hpoint, select;
46  float mval_fl[2];
47  bool is_changed;
48  } *data = userData;
49 
50  uint8_t flag;
51  float dist_test;
52 
53  if (bp) {
54  flag = bp->f1;
55  }
56  else {
57  BLI_assert(handles_visible || beztindex == 1);
58 
59  if (beztindex == 0) {
60  flag = bezt->f1;
61  }
62  else if (beztindex == 1) {
63  flag = bezt->f2;
64  }
65  else {
66  flag = bezt->f3;
67  }
68  }
69 
70  dist_test = len_manhattan_v2v2(data->mval_fl, screen_co);
71  if ((flag & SELECT) == data->select) {
72  dist_test += 5.0f;
73  }
74  if (bezt && beztindex == 1) {
75  dist_test += 3.0f; /* middle points get a small disadvantage */
76  }
77 
78  if (dist_test < data->dist) {
79  data->dist = dist_test;
80 
81  data->bp = bp;
82  data->bezt = bezt;
83  data->nurb = nu;
84  data->hpoint = bezt ? beztindex : 0;
85  data->is_changed = true;
86  }
87 
88  UNUSED_VARS_NDEBUG(handles_visible);
89 }
90 
92  short sel,
93  const int dist_px,
94  Nurb **r_nurb,
95  BezTriple **r_bezt,
96  BPoint **r_bp,
97  short *r_handle,
98  Base **r_base)
99 {
100  /* (sel == 1): selected gets a disadvantage */
101  /* in nurb and bezt or bp the nearest is written */
102  /* return 0 1 2: handlepunt */
103  struct {
104  BPoint *bp;
105  BezTriple *bezt;
106  Nurb *nurb;
107  float dist;
108  int hpoint, select;
109  float mval_fl[2];
110  bool is_changed;
111  } data = {NULL};
112 
113  data.dist = dist_px;
114  data.hpoint = 0;
115  data.select = sel;
116  data.mval_fl[0] = vc->mval[0];
117  data.mval_fl[1] = vc->mval[1];
118 
119  uint bases_len;
121  vc->view_layer, vc->v3d, &bases_len);
122  for (uint base_index = 0; base_index < bases_len; base_index++) {
123  Base *base = bases[base_index];
124  data.is_changed = false;
125 
129 
130  if (r_base && data.is_changed) {
131  *r_base = base;
132  }
133  }
134  MEM_freeN(bases);
135 
136  *r_nurb = data.nurb;
137  *r_bezt = data.bezt;
138  *r_bp = data.bp;
139 
140  if (r_handle) {
141  *r_handle = data.hpoint;
142  }
143 
144  return (data.bezt || data.bp);
145 }
146 
148  short sel,
149  Nurb **r_nurb,
150  BezTriple **r_bezt,
151  BPoint **r_bp,
152  short *r_handle,
153  Base **r_base)
154 {
155  return ED_curve_pick_vert_ex(
156  vc, sel, ED_view3d_select_dist_px(), r_nurb, r_bezt, r_bp, r_handle, r_base);
157 }
158 
161 /* -------------------------------------------------------------------- */
166  Curve *cu, View3D *v3d, Nurb **r_nu, BezTriple **r_bezt, BPoint **r_bp)
167 {
168  /* In nu and (bezt or bp) selected are written if there's 1 sel. */
169  /* If more points selected in 1 spline: return only nu, bezt and bp are 0. */
170  ListBase *editnurb = &cu->editnurb->nurbs;
171  BezTriple *bezt1;
172  BPoint *bp1;
173  int a;
174 
175  *r_nu = NULL;
176  *r_bezt = NULL;
177  *r_bp = NULL;
178 
179  LISTBASE_FOREACH (Nurb *, nu1, editnurb) {
180  if (nu1->type == CU_BEZIER) {
181  bezt1 = nu1->bezt;
182  a = nu1->pntsu;
183  while (a--) {
184  if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt1)) {
185  if (!ELEM(*r_nu, NULL, nu1)) {
186  *r_nu = NULL;
187  *r_bp = NULL;
188  *r_bezt = NULL;
189  return;
190  }
191 
192  if (*r_bezt || *r_bp) {
193  *r_bp = NULL;
194  *r_bezt = NULL;
195  }
196  else {
197  *r_bezt = bezt1;
198  *r_nu = nu1;
199  }
200  }
201  bezt1++;
202  }
203  }
204  else {
205  bp1 = nu1->bp;
206  a = nu1->pntsu * nu1->pntsv;
207  while (a--) {
208  if (bp1->f1 & SELECT) {
209  if (!ELEM(*r_nu, NULL, nu1)) {
210  *r_bp = NULL;
211  *r_bezt = NULL;
212  *r_nu = NULL;
213  return;
214  }
215 
216  if (*r_bezt || *r_bp) {
217  *r_bp = NULL;
218  *r_bezt = NULL;
219  }
220  else {
221  *r_bp = bp1;
222  *r_nu = nu1;
223  }
224  }
225  bp1++;
226  }
227  }
228  }
229 }
230 
232 {
233  Nurb *nu = NULL;
234  void *vert = NULL;
235 
236  if (!BKE_curve_nurb_vert_active_get(cu, &nu, &vert)) {
237  return false;
238  }
239 
240  if (nu->type == CU_BEZIER) {
241  BezTriple *bezt = (BezTriple *)vert;
242  copy_v3_v3(center, bezt->vec[1]);
243  }
244  else {
245  BPoint *bp = (BPoint *)vert;
246  copy_v3_v3(center, bp->vec);
247  }
248 
249  return true;
250 }
251 
bool BKE_curve_nurb_vert_active_get(struct Curve *cu, struct Nurb **r_nu, void **r_vert)
Definition: curve.cc:5049
#define BKE_view_layer_array_from_bases_in_edit_mode_unique_data(view_layer, v3d, r_len)
Definition: BKE_layer.h:546
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float len_manhattan_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
@ CU_BEZIER
#define BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)
Object is a sort of wrapper for general info.
void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact)
#define V3D_PROJ_TEST_CLIP_DEFAULT
Definition: ED_view3d.h:264
void nurbs_foreachScreenVert(struct ViewContext *vc, void(*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt, int beztindex, bool handle_visible, const float screen_co[2]), void *userData, eV3DProjTest clip_flag)
void ED_view3d_init_mats_rv3d(const struct Object *ob, struct RegionView3D *rv3d)
Definition: space_view3d.c:166
float ED_view3d_select_dist_px(void)
NSNotificationCenter * center
Read Guarded memory(de)allocation.
__forceinline const avxb select(const avxb &m, const avxb &t, const avxb &f)
Definition: avxb.h:154
#define SELECT
void ED_curve_nurb_vert_selected_find(Curve *cu, View3D *v3d, Nurb **r_nu, BezTriple **r_bezt, BPoint **r_bp)
bool ED_curve_pick_vert(ViewContext *vc, short sel, Nurb **r_nurb, BezTriple **r_bezt, BPoint **r_bp, short *r_handle, Base **r_base)
bool ED_curve_pick_vert_ex(ViewContext *vc, short sel, const int dist_px, Nurb **r_nurb, BezTriple **r_bezt, BPoint **r_bp, short *r_handle, Base **r_base)
bool ED_curve_active_center(Curve *cu, float center[3])
static void ED_curve_pick_vert__do_closest(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, bool handles_visible, const float screen_co[2])
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
static unsigned a[3]
Definition: RandGen.cpp:78
unsigned char uint8_t
Definition: stdint.h:78
uint8_t f1
float vec[4]
struct Object * object
uint8_t f3
float vec[3][3]
uint8_t f1
uint8_t f2
EditNurb * editnurb
ListBase nurbs
short type
int mval[2]
Definition: ED_view3d.h:74
struct ViewLayer * view_layer
Definition: ED_view3d.h:66
struct Object * obedit
Definition: ED_view3d.h:68
struct View3D * v3d
Definition: ED_view3d.h:70
struct RegionView3D * rv3d
Definition: ED_view3d.h:72