Curves: save active point to file

Changed curve active point from pointer to index. Allows curve active point to be saved to file and retained between modes for free. Also some small optimisations by removing pointer look up code.

- Made active point access functions into BKE API calls.
- Fixes operators where curve de-selection resulted in unsel-active point.
- Split curve delete into 2 functions
This commit is contained in:
Kevin Mackay
2014-01-27 15:18:40 +11:00
committed by Campbell Barton
parent f91368d822
commit fbc7ab30ff
15 changed files with 444 additions and 473 deletions

View File

@@ -86,7 +86,14 @@ void BKE_curve_translate(struct Curve *cu, float offset[3], int do_keys);
void BKE_curve_material_index_remove(struct Curve *cu, int index);
void BKE_curve_material_index_clear(struct Curve *cu);
ListBase *BKE_curve_nurbs_get(struct Curve *cu);
ListBase *BKE_curve_nurbs_get(struct Curve *cu);
void BKE_curve_nurb_active_set(struct Curve *cu, struct Nurb *nu);
struct Nurb *BKE_curve_nurb_active_get(struct Curve *cu);
void *BKE_curve_vert_active_get(struct Curve *cu);
void BKE_curve_nurb_vert_active_set(struct Curve *cu, struct Nurb *nu, void *vert);
bool BKE_curve_nurb_vert_active_get(struct Curve *cu, struct Nurb **r_nu, void **r_vert);
void BKE_curve_nurb_vert_active_validate(struct Curve *cu);
float (*BKE_curve_nurbs_vertexCos_get(struct ListBase *lb, int *numVerts_r))[3];
void BK_curve_nurbs_vertexCos_apply(struct ListBase *lb, float (*vertexCos)[3]);

View File

@@ -224,7 +224,6 @@ Curve *BKE_curve_copy(Curve *cu)
cun->editnurb = NULL;
cun->editfont = NULL;
cun->lastsel = NULL;
#if 0 // XXX old animation system
/* single user ipo too */
@@ -3931,6 +3930,105 @@ ListBase *BKE_curve_nurbs_get(Curve *cu)
return &cu->nurb;
}
void BKE_curve_nurb_active_set(Curve *cu, Nurb *nu)
{
if (nu == NULL) {
cu->actnu = -1;
}
else {
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
cu->actnu = BLI_findindex(nurbs, nu);
}
}
Nurb *BKE_curve_nurb_active_get(Curve *cu)
{
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
return BLI_findlink(nurbs, cu->actnu);
}
/* Get active vert for curve */
void *BKE_curve_vert_active_get(Curve *cu)
{
Nurb *nu = NULL;
void *vert = NULL;
BKE_curve_nurb_vert_active_get(cu, &nu, &vert);
return vert;
}
/* Set active nurb and active vert for curve */
void BKE_curve_nurb_vert_active_set(Curve *cu, Nurb *nu, void *vert)
{
if (nu) {
BKE_curve_nurb_active_set(cu, nu);
if (nu->type == CU_BEZIER) {
BLI_assert(ARRAY_HAS_ITEM((BezTriple *)vert, nu->bezt, nu->pntsu));
cu->actvert = (BezTriple *)vert - nu->bezt;
}
else {
BLI_assert(ARRAY_HAS_ITEM((BPoint *)vert, nu->bp, nu->pntsu * nu->pntsv));
cu->actvert = (BPoint *)vert - nu->bp;
}
}
else {
cu->actnu = cu->actvert = CU_ACT_NONE;
}
}
/* Get points to active active nurb and active vert for curve */
bool BKE_curve_nurb_vert_active_get(Curve *cu, Nurb **r_nu, void **r_vert)
{
Nurb *nu = NULL;
void *vert = NULL;
if (cu->actvert != CU_ACT_NONE) {
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
nu = BLI_findlink(nurbs, cu->actnu);
if (nu) {
if (nu->type == CU_BEZIER) {
BLI_assert(nu->pntsu > cu->actvert);
vert = &nu->bezt[cu->actvert];
}
else {
BLI_assert((nu->pntsu * nu->pntsv) > cu->actvert);
vert = &nu->bp[cu->actvert];
}
}
/* get functions should never set! */
#if 0
else {
cu->actnu = cu->actvert = CU_ACT_NONE;
}
#endif
}
*r_nu = nu;
*r_vert = vert;
return (*r_vert != NULL);
}
void BKE_curve_nurb_vert_active_validate(Curve *cu)
{
Nurb *nu;
void *vert;
if (BKE_curve_nurb_vert_active_get(cu, &nu, &vert)) {
if (nu->type == CU_BEZIER) {
if ((((BezTriple *)vert)->f1 & SELECT) == 0) {
cu->actvert = CU_ACT_NONE;
}
}
else {
if ((((BPoint *)vert)->f1 & SELECT) == 0) {
cu->actvert = CU_ACT_NONE;
}
}
}
}
/* basic vertex data functions */
bool BKE_curve_minmax(Curve *cu, bool use_radius, float min[3], float max[3])

View File

@@ -3388,7 +3388,6 @@ static void direct_link_curve(FileData *fd, Curve *cu)
}
cu->editnurb = NULL;
cu->lastsel = NULL;
cu->editfont = NULL;
for (nu = cu->nurb.first; nu; nu = nu->next) {

File diff suppressed because it is too large Load Diff

View File

@@ -459,7 +459,7 @@ Nurb *add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4], int type
if (nu) { /* should always be set */
nu->flag |= CU_SMOOTH;
cu->actnu = BLI_countlist(editnurb);
cu->lastsel = NULL;
cu->actvert = CU_ACT_NONE;
BKE_nurb_test2D(nu);
}

View File

@@ -51,10 +51,10 @@ void ED_operatormacros_curve(void);
void ED_keymap_curve(struct wmKeyConfig *keyconf);
/* editcurve.c */
void ED_curve_transform(struct Curve *cv, float mat[4][4]);
void CU_deselect_all(struct Object *obedit);
void CU_select_all(struct Object *obedit);
void CU_select_swap(struct Object *obedit);
void ED_curve_transform(struct Curve *cu, float mat[4][4]);
void ED_curve_deselect_all(struct EditNurb *editnurb);
void ED_curve_select_all(struct EditNurb *editnurb);
void ED_curve_select_swap(struct EditNurb *editnurb, bool hide_handles);
void undo_push_curve(struct bContext *C, const char *name);
@@ -80,7 +80,7 @@ void free_editText(struct Object *obedit);
void ED_text_to_object(struct bContext *C, struct Text *text, int split_lines);
int CU_select_nth(struct Object *obedit, int nth);
bool ED_curve_select_nth(struct Curve *cu, int nth);
void ED_curve_beztcpy(struct EditNurb *editnurb, struct BezTriple *dst, struct BezTriple *src, int count);
void ED_curve_bpcpy(struct EditNurb *editnurb, struct BPoint *dst, struct BPoint *src, int count);
@@ -88,10 +88,9 @@ struct Nurb *ED_curve_nurbcpy(struct Nurb *src, int count);
int ED_curve_updateAnimPaths(struct Curve *cu);
int ED_curve_actSelection(struct Curve *cu, float center[3]);
bool ED_curve_active_center(struct Curve *cu, float center[3]);
/* debug only */
void printknots(struct Object *obedit);
#endif /* __ED_CURVE_H__ */

View File

@@ -124,7 +124,7 @@ enum {
TH_HANDLE_SEL_AUTOCLAMP,
TH_ACTIVE_SPLINE,
TH_LASTSEL_POINT,
TH_ACTIVE_VERT, /* equivalent of TH_EDITMESH_ACTIVE for splines */
TH_SYNTAX_B,
TH_SYNTAX_V,

View File

@@ -372,7 +372,7 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
cp = ts->nurb_sel_vline; break;
case TH_ACTIVE_SPLINE:
cp = ts->act_spline; break;
case TH_LASTSEL_POINT:
case TH_ACTIVE_VERT:
cp = ts->lastsel_point; break;
case TH_HANDLE_FREE:
cp = ts->handle_free; break;

View File

@@ -498,15 +498,17 @@ static int effector_add_exec(bContext *C, wmOperator *op)
type = RNA_enum_get(op->ptr, "type");
if (type == PFIELD_GUIDE) {
Curve *cu;
ob = ED_object_add_type(C, OB_CURVE, loc, rot, FALSE, layer);
if (!ob)
return OPERATOR_CANCELLED;
rename_id(&ob->id, CTX_DATA_(BLF_I18NCONTEXT_ID_OBJECT, "CurveGuide"));
((Curve *)ob->data)->flag |= CU_PATH | CU_3D;
cu = ob->data;
cu->flag |= CU_PATH | CU_3D;
ED_object_editmode_enter(C, 0);
ED_object_new_primitive_matrix(C, ob, loc, rot, mat, FALSE);
BLI_addtail(object_editcurve_get(ob), add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, 1));
BLI_addtail(&cu->editnurb->nurbs, add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, 1));
if (!enter_editmode)
ED_object_editmode_exit(C, EM_FREEDATA);
}

View File

@@ -1854,7 +1854,7 @@ static void lattice_draw_verts(Lattice *lt, DispList *dl, BPoint *actbp, short s
if (bp->hide == 0) {
/* check for active BPoint and ensure selected */
if ((bp == actbp) && (bp->f1 & SELECT)) {
UI_ThemeColor(TH_LASTSEL_POINT);
UI_ThemeColor(TH_ACTIVE_VERT);
bglVertex3fv(dl ? co : bp->vec);
UI_ThemeColor(color);
}
@@ -5358,7 +5358,7 @@ static void drawhandlesN_active(Nurb *nu)
glLineWidth(1);
}
static void drawvertsN(Nurb *nu, const char sel, const bool hide_handles, void *lastsel)
static void drawvertsN(Nurb *nu, const char sel, const bool hide_handles, const void *vert)
{
BezTriple *bezt;
BPoint *bp;
@@ -5383,8 +5383,8 @@ static void drawvertsN(Nurb *nu, const char sel, const bool hide_handles, void *
a = nu->pntsu;
while (a--) {
if (bezt->hide == 0) {
if (sel == 1 && bezt == lastsel) {
UI_ThemeColor(TH_LASTSEL_POINT);
if (sel == 1 && bezt == vert) {
UI_ThemeColor(TH_ACTIVE_VERT);
bglVertex3fv(bezt->vec[1]);
if (!hide_handles) {
@@ -5411,8 +5411,8 @@ static void drawvertsN(Nurb *nu, const char sel, const bool hide_handles, void *
a = nu->pntsu * nu->pntsv;
while (a--) {
if (bp->hide == 0) {
if (bp == lastsel) {
UI_ThemeColor(TH_LASTSEL_POINT);
if (bp == vert) {
UI_ThemeColor(TH_ACTIVE_VERT);
bglVertex3fv(bp->vec);
UI_ThemeColor(color);
}
@@ -5621,6 +5621,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
Curve *cu = ob->data;
Nurb *nu;
BevList *bl;
const void *vert = BKE_curve_vert_active_get(cu);
const bool hide_handles = (cu->drawflag & CU_HIDE_HANDLES) != 0;
int index;
unsigned char wire_col[3];
@@ -5700,7 +5701,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
if (v3d->zbuf) glDepthFunc(GL_ALWAYS);
for (nu = nurb; nu; nu = nu->next) {
drawvertsN(nu, 1, hide_handles, cu->lastsel);
drawvertsN(nu, 1, hide_handles, vert);
}
if (v3d->zbuf) glDepthFunc(GL_LEQUAL);

View File

@@ -62,6 +62,7 @@
#include "BKE_armature.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_depsgraph.h"
#include "BKE_mball.h"
#include "BKE_mesh.h"
@@ -537,7 +538,6 @@ static void do_lasso_select_curve__doSelect(void *userData, Nurb *UNUSED(nu), BP
if (BLI_lasso_is_point_inside(data->mcords, data->moves, screen_co[0], screen_co[1], IS_CLIPPED)) {
if (bp) {
bp->f1 = data->select ? (bp->f1 | SELECT) : (bp->f1 & ~SELECT);
if (bp == cu->lastsel && !(bp->f1 & SELECT)) cu->lastsel = NULL;
}
else {
if (cu->drawflag & CU_HIDE_HANDLES) {
@@ -555,8 +555,6 @@ static void do_lasso_select_curve__doSelect(void *userData, Nurb *UNUSED(nu), BP
bezt->f3 = data->select ? (bezt->f3 | SELECT) : (bezt->f3 & ~SELECT);
}
}
if (bezt == cu->lastsel && !(bezt->f2 & SELECT)) cu->lastsel = NULL;
}
}
}
@@ -571,10 +569,11 @@ static void do_lasso_select_curve(ViewContext *vc, const int mcords[][2], short
view3d_userdata_lassoselect_init(&data, vc, &rect, mcords, moves, select);
if (extend == false && select)
CU_deselect_all(vc->obedit);
ED_curve_deselect_all(vc->obedit->data);
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
nurbs_foreachScreenVert(vc, do_lasso_select_curve__doSelect, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
BKE_curve_nurb_vert_active_validate(vc->obedit->data);
}
static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, const float screen_co[2])
@@ -1710,7 +1709,6 @@ static void do_nurbs_box_select__doSelect(void *userData, Nurb *UNUSED(nu), BPoi
if (BLI_rctf_isect_pt_v(data->rect_fl, screen_co)) {
if (bp) {
bp->f1 = data->select ? (bp->f1 | SELECT) : (bp->f1 & ~SELECT);
if (bp == cu->lastsel && !(bp->f1 & SELECT)) cu->lastsel = NULL;
}
else {
if (cu->drawflag & CU_HIDE_HANDLES) {
@@ -1728,8 +1726,6 @@ static void do_nurbs_box_select__doSelect(void *userData, Nurb *UNUSED(nu), BPoi
bezt->f3 = data->select ? (bezt->f3 | SELECT) : (bezt->f3 & ~SELECT);
}
}
if (bezt == cu->lastsel && !(bezt->f2 & SELECT)) cu->lastsel = NULL;
}
}
}
@@ -1740,10 +1736,11 @@ static int do_nurbs_box_select(ViewContext *vc, rcti *rect, bool select, bool ex
view3d_userdata_boxselect_init(&data, vc, rect, select);
if (extend == false && select)
CU_deselect_all(vc->obedit);
ED_curve_deselect_all(vc->obedit->data);
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
nurbs_foreachScreenVert(vc, do_nurbs_box_select__doSelect, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
BKE_curve_nurb_vert_active_validate(vc->obedit->data);
return OPERATOR_FINISHED;
}
@@ -2474,8 +2471,6 @@ static void nurbscurve_circle_doSelect(void *userData, Nurb *UNUSED(nu), BPoint
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
if (bp) {
bp->f1 = data->select ? (bp->f1 | SELECT) : (bp->f1 & ~SELECT);
if (bp == cu->lastsel && !(bp->f1 & SELECT)) cu->lastsel = NULL;
}
else {
if (cu->drawflag & CU_HIDE_HANDLES) {
@@ -2493,8 +2488,6 @@ static void nurbscurve_circle_doSelect(void *userData, Nurb *UNUSED(nu), BPoint
bezt->f3 = data->select ? (bezt->f3 | SELECT) : (bezt->f3 & ~SELECT);
}
}
if (bezt == cu->lastsel && !(bezt->f2 & SELECT)) cu->lastsel = NULL;
}
}
}
@@ -2506,6 +2499,7 @@ static void nurbscurve_circle_select(ViewContext *vc, const bool select, const i
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
nurbs_foreachScreenVert(vc, nurbscurve_circle_doSelect, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
BKE_curve_nurb_vert_active_validate(vc->obedit->data);
}

View File

@@ -1667,7 +1667,7 @@ void calculateCenter(TransInfo *t)
float center[3];
Curve *cu = (Curve *)t->obedit->data;
if (ED_curve_actSelection(cu, center)) {
if (ED_curve_active_center(cu, center)) {
copy_v3_v3(t->center, center);
calculateCenter2D(t);
break;

View File

@@ -397,7 +397,7 @@ int calc_manipulator_stats(const bContext *C)
Curve *cu = obedit->data;
float center[3];
if (v3d->around == V3D_ACTIVE && ED_curve_actSelection(cu, center)) {
if (v3d->around == V3D_ACTIVE && ED_curve_active_center(cu, center)) {
calc_tw_center(scene, center);
totsel++;
}

View File

@@ -705,27 +705,15 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
} /* end editmesh */
else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
Curve *cu = obedit->data;
Nurb *nu;
BezTriple *bezt;
Nurb *nu = NULL;
BezTriple *bezt = NULL;
int a;
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
if (activeOnly && cu->lastsel) {
for (nu = nurbs->first; nu; nu = nu->next) {
if (nu->type == CU_BEZIER) {
if (ARRAY_HAS_ITEM((BezTriple *)cu->lastsel, nu->bezt, nu->pntsu)) {
bezt = cu->lastsel;
BKE_nurb_bezt_calc_normal(nu, bezt, normal);
BKE_nurb_bezt_calc_plane(nu, bezt, plane);
break;
}
}
else {
if (ARRAY_HAS_ITEM((BPoint *)cu->lastsel, nu->bp, nu->pntsu)) {
/* do nothing */
break;
}
}
if (activeOnly && BKE_curve_nurb_vert_active_get(cu, &nu, (void *)&bezt)) {
if (nu->type == CU_BEZIER) {
BKE_nurb_bezt_calc_normal(nu, bezt, normal);
BKE_nurb_bezt_calc_plane(nu, bezt, plane);
}
}
else {

View File

@@ -209,9 +209,10 @@ typedef struct Curve {
/* edit, index in nurb list */
int actnu;
/* edit, last selected point */
void *lastsel;
/* edit, index in active nurb (BPoint or BezTriple) */
int actvert;
char pad[4];
/* font part */
short lines;
@@ -248,7 +249,7 @@ typedef struct Curve {
float ctime; /* current evaltime - for use by Objects parented to curves */
float bevfac1, bevfac2;
char pad[4];
char pad2[4];
} Curve;
/* **************** CURVE ********************* */
@@ -325,6 +326,8 @@ typedef struct Curve {
#define CU_NURB_ENDPOINT 2
#define CU_NURB_BEZIER 4
#define CU_ACT_NONE -1
/* *************** BEZTRIPLE **************** */
/* h1 h2 (beztriple) */