Applying patch #24822: Select linked for curves as for meshes, CTRL + L version

With some own changes:
- Select pick moved to invoke()
- Used editsurfcurve_region_view3d as poll function for this operator
  due to ogl dependency

Thanks to Elia Sarti (vekoon)!
This commit is contained in:
2010-11-21 18:50:53 +00:00
parent d016f52c21
commit e006d187f4
5 changed files with 102 additions and 29 deletions

View File

@@ -106,6 +106,7 @@ void CURVE_OT_de_select_last(struct wmOperatorType *ot);
void CURVE_OT_select_all(struct wmOperatorType *ot);
void CURVE_OT_select_inverse(struct wmOperatorType *ot);
void CURVE_OT_select_linked(struct wmOperatorType *ot);
void CURVE_OT_select_linked_pick(struct wmOperatorType *ot);
void CURVE_OT_select_row(struct wmOperatorType *ot);
void CURVE_OT_select_next(struct wmOperatorType *ot);
void CURVE_OT_select_previous(struct wmOperatorType *ot);

View File

@@ -117,6 +117,7 @@ void ED_operatortypes_curve(void)
WM_operatortype_append(CURVE_OT_select_all);
WM_operatortype_append(CURVE_OT_select_inverse);
WM_operatortype_append(CURVE_OT_select_linked);
WM_operatortype_append(CURVE_OT_select_linked_pick);
WM_operatortype_append(CURVE_OT_select_row);
WM_operatortype_append(CURVE_OT_select_next);
WM_operatortype_append(CURVE_OT_select_previous);
@@ -201,8 +202,9 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CURVE_OT_select_row", RKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "CURVE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "CURVE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
WM_keymap_add_item(keymap, "CURVE_OT_separate", PKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "CURVE_OT_extrude", EKEY, KM_PRESS, 0, 0);

View File

@@ -4457,24 +4457,99 @@ void CURVE_OT_cyclic_toggle(wmOperatorType *ot)
/***************** select linked operator ******************/
static int select_linked_exec(bContext *C, wmOperator *op)
static int select_linked_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *obedit= CTX_data_edit_object(C);
RegionView3D *rv3d= ED_view3d_context_rv3d(C);
Curve *cu= (Curve*)obedit->data;
EditNurb *editnurb= cu->editnurb;
ListBase *nurbs= &editnurb->nurbs;
Nurb *nu;
BezTriple *bezt;
BPoint *bp;
int a;
for(nu= nurbs->first; nu; nu= nu->next) {
if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
if( (bezt->f1 & SELECT) || (bezt->f2 & SELECT) || (bezt->f3 & SELECT) ) {
a= nu->pntsu;
bezt= nu->bezt;
while(a--) {
select_beztriple(bezt, SELECT, 1, VISIBLE);
bezt++;
}
break;
}
bezt++;
}
}
else {
bp= nu->bp;
a= nu->pntsu*nu->pntsv;
while(a--) {
if( bp->f1 & 1 ) {
a= nu->pntsu*nu->pntsv;
bp= nu->bp;
while(a--) {
select_bpoint(bp, SELECT, 1, VISIBLE);
bp++;
}
break;
}
bp++;
}
}
}
WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
return OPERATOR_FINISHED;
}
static int select_linked_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
return select_linked_exec(C, op);
}
void CURVE_OT_select_linked(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Linked All";
ot->idname= "CURVE_OT_select_linked";
/* api callbacks */
ot->exec= select_linked_exec;
ot->invoke= select_linked_invoke;
ot->poll= ED_operator_editsurfcurve;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
}
/***************** select linked pick operator ******************/
static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
Object *obedit= CTX_data_edit_object(C);
ARegion *ar= CTX_wm_region(C);
ViewContext vc;
Nurb *nu;
BezTriple *bezt;
BPoint *bp;
int a, location[2], deselect;
if(!rv3d)
return OPERATOR_CANCELLED;
deselect= RNA_boolean_get(op->ptr, "deselect");
RNA_int_get_array(op->ptr, "location", location);
location[0]= event->x - ar->winrct.xmin;
location[1]= event->y - ar->winrct.ymin;
view3d_operator_needs_opengl(C);
view3d_set_viewcontext(C, &vc);
findnearestNurbvert(&vc, 1, location, &nu, &bezt, &bp);
if(bezt) {
@@ -4497,39 +4572,25 @@ static int select_linked_exec(bContext *C, wmOperator *op)
}
WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
return OPERATOR_FINISHED;
}
static int select_linked_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
ARegion *ar= CTX_wm_region(C);
int location[2];
location[0]= event->x - ar->winrct.xmin;
location[1]= event->y - ar->winrct.ymin;
RNA_int_set_array(op->ptr, "location", location);
return select_linked_exec(C, op);
}
void CURVE_OT_select_linked(wmOperatorType *ot)
void CURVE_OT_select_linked_pick(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Linked";
ot->idname= "CURVE_OT_select_linked";
ot->idname= "CURVE_OT_select_linked_pick";
/* api callbacks */
ot->exec= select_linked_exec;
ot->invoke= select_linked_invoke;
ot->poll= ED_operator_editsurfcurve;
ot->invoke= select_linked_pick_invoke;
ot->poll= ED_operator_editsurfcurve_region_view3d;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect linked control points rather than selecting them.");
RNA_def_int_vector(ot->srna, "location", 2, NULL, 0, INT_MAX, "Location", "", 0, 16384);
}
/***************** select row operator **********************/

View File

@@ -156,6 +156,7 @@ int ED_operator_editarmature(struct bContext *C);
int ED_operator_editcurve(struct bContext *C);
int ED_operator_editsurf(struct bContext *C);
int ED_operator_editsurfcurve(struct bContext *C);
int ED_operator_editsurfcurve_region_view3d(struct bContext *C);
int ED_operator_editfont(struct bContext *C);
int ED_operator_editlattice(struct bContext *C);
int ED_operator_editmball(struct bContext *C);

View File

@@ -364,6 +364,14 @@ int ED_operator_editsurfcurve(bContext *C)
return 0;
}
int ED_operator_editsurfcurve_region_view3d(bContext *C)
{
if(ED_operator_editsurfcurve(C) && CTX_wm_region_view3d(C))
return 1;
CTX_wm_operator_poll_msg_set(C, "expected a view3d region & editcurve");
return 0;
}
int ED_operator_editcurve(bContext *C)
{