diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-02-13 20:37:01 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-02-13 20:37:01 +0300 |
commit | 47b9a44063fb3c98b3ca9cf8e5dff6ffa8136934 (patch) | |
tree | d3ae01207d51dd6858fc088f4bf293d101dd84ed /source/blender/editors/curve | |
parent | 62494990e6d31d0efedd1a21015edb67eb2f4f68 (diff) |
2.5: Curve edit mode add vertex and add menus now work. Also
fixed an issue where sublevel menus did not get right operator
context.
Diffstat (limited to 'source/blender/editors/curve')
-rw-r--r-- | source/blender/editors/curve/curve_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/curve/curve_ops.c | 30 | ||||
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 143 |
3 files changed, 31 insertions, 146 deletions
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h index cced4720cec..82e6b39196b 100644 --- a/source/blender/editors/curve/curve_intern.h +++ b/source/blender/editors/curve/curve_intern.h @@ -71,12 +71,8 @@ void CURVE_OT_duplicate(struct wmOperatorType *ot); void CURVE_OT_delete(struct wmOperatorType *ot); void CURVE_OT_set_smooth(struct wmOperatorType *ot); void CURVE_OT_clear_tilt(struct wmOperatorType *ot); -void CURVE_OT_add_surface_primitive(struct wmOperatorType *ot); -void CURVE_OT_add_curve_primitive(struct wmOperatorType *ot); void CURVE_OT_specials_menu(struct wmOperatorType *ot); -void CURVE_OT_add_menu(struct wmOperatorType *ot); - #endif /* ED_UTIL_INTERN_H */ diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index 30ddb226045..c7eed88023f 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -91,32 +91,6 @@ void CURVE_OT_specials_menu(wmOperatorType *ot) ot->poll= ED_operator_editsurfcurve; } -static int add_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - Object *obedit= CTX_data_edit_object(C); - uiMenuItem *head; - - head= uiPupMenuBegin("Add", 0); - if(obedit->type == OB_CURVE) - uiMenuItemsEnumO(head, "CURVE_OT_add_curve_primitive", "type"); - else - uiMenuItemsEnumO(head, "CURVE_OT_add_surface_primitive", "type"); - uiPupMenuEnd(C, head); - - return OPERATOR_CANCELLED; -} - -void CURVE_OT_add_menu(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Add Menu"; - ot->idname= "CURVE_OT_add_menu"; - - /* api clastbacks */ - ot->invoke= add_menu_invoke; - ot->poll= ED_operator_editsurfcurve; -} - /************************* registration ****************************/ void ED_operatortypes_curve(void) @@ -161,11 +135,7 @@ void ED_operatortypes_curve(void) WM_operatortype_append(CURVE_OT_extrude); WM_operatortype_append(CURVE_OT_toggle_cyclic); - WM_operatortype_append(CURVE_OT_add_menu); WM_operatortype_append(CURVE_OT_specials_menu); - - WM_operatortype_append(CURVE_OT_add_surface_primitive); - WM_operatortype_append(CURVE_OT_add_curve_primitive); } void ED_keymap_curve(wmWindowManager *wm) diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 848bec89a39..4ef642381f0 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -3258,16 +3258,15 @@ void CURVE_OT_spin(wmOperatorType *ot) /***************** add vertex operator **********************/ -static int addvert_Nurb(bContext *C, short mode) +static int addvert_Nurb(bContext *C, short mode, float location[3]) { Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); ListBase *editnurb= curve_get_editcurve(obedit); - View3D *v3d= CTX_wm_view3d(C); Nurb *nu; BezTriple *bezt, *newbezt = NULL; BPoint *bp, *newbp = NULL; - float *curs, mat[3][3],imat[3][3], temp[3]; + float mat[3][3],imat[3][3], temp[3]; Mat3CpyMat4(mat, obedit->obmat); Mat3Inv(imat,mat); @@ -3315,16 +3314,7 @@ static int addvert_Nurb(bContext *C, short mode) VECCOPY(newbezt->vec[2], bezt->vec[2]); } else { - if(v3d) { - curs= give_cursor(scene, v3d); - VECCOPY(newbezt->vec[1], curs); - } - else { - newbezt->vec[1][0]= 0.0f; - newbezt->vec[1][1]= 0.0f; - newbezt->vec[1][2]= 0.0f; - } - + VECCOPY(newbezt->vec[1], location); VecSubf(newbezt->vec[1],newbezt->vec[1], obedit->obmat[3]); Mat3MulVecfl(imat,newbezt->vec[1]); VecSubf(temp, newbezt->vec[1],temp); @@ -3370,16 +3360,7 @@ static int addvert_Nurb(bContext *C, short mode) VECCOPY(newbp->vec, bp->vec); } else { - if(v3d) { - curs= give_cursor(scene, v3d); - VECCOPY(newbp->vec, curs); - } - else { - newbp->vec[0]= 0.0f; - newbp->vec[1]= 0.0f; - newbp->vec[1]= 0.0f; - } - + VECCOPY(newbp->vec, location); VecSubf(newbp->vec, newbp->vec, obedit->obmat[3]); Mat3MulVecfl(imat,newbp->vec); newbp->vec[3]= 1.0; @@ -3399,14 +3380,30 @@ static int addvert_Nurb(bContext *C, short mode) static int add_vertex_exec(bContext *C, wmOperator *op) { - return addvert_Nurb(C, 0); + float location[3]; + + RNA_float_get_array(op->ptr, "location", location); + return addvert_Nurb(C, 0, location); } static int add_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event) { - // XXX doesn't work correct, old code was in mouse_cursor - // temporarly setting cursor, adding vertex and restoring cursor - return add_vertex_exec(C, 0); + RegionView3D *rv3d= CTX_wm_region_view3d(C); + ViewContext vc; + float location[3]; + short mval[2]; + + if(rv3d && !RNA_property_is_set(op->ptr, "location")) { + view3d_set_viewcontext(C, &vc); + + mval[0]= event->x - vc.ar->winrct.xmin; + mval[1]= event->y - vc.ar->winrct.ymin; + + view3d_get_view_aligned_coordinate(&vc, location, mval); + RNA_float_set_array(op->ptr, "location", location); + } + + return add_vertex_exec(C, op); } void CURVE_OT_add_vertex(wmOperatorType *ot) @@ -3422,6 +3419,9 @@ void CURVE_OT_add_vertex(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_float_vector(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Location to add new vertex at.", -1e4, 1e4); } /***************** extrude operator **********************/ @@ -3439,7 +3439,7 @@ static int extrude_exec(bContext *C, wmOperator *op) break; if(obedit->type==OB_CURVE || nu) { - addvert_Nurb(C, 'e'); + addvert_Nurb(C, 'e', NULL); } else { if(extrudeflagNurb(editnurb, 1)) { /* '1'= flag */ @@ -4722,7 +4722,7 @@ int join_curve(bContext *C, wmOperator *op, int type) return OPERATOR_FINISHED; } -/************ add primitive, internal + external ****************/ +/************ add primitive, used by object/ module ****************/ Nurb *addNurbprim(bContext *C, int type, int newname) { @@ -5022,7 +5022,7 @@ Nurb *addNurbprim(bContext *C, int type, int newname) rename_id((ID *)obedit->data, "SurfTube"); } - nu= addNurbprim(C, CU_NURBS|CU_2D|CU_PRIM_CIRCLE, 0); /* circle */ + nu= addNurbprim(C, CU_NURBS|CU_PRIM_CIRCLE, 0); /* circle */ nu->resolu= 4; nu->flag= CU_SMOOTH; BLI_addtail(editnurb, nu); /* temporal for extrude and translate */ @@ -5101,7 +5101,7 @@ Nurb *addNurbprim(bContext *C, int type, int newname) } xzproj= 1; - nu= addNurbprim(C, CU_NURBS|CU_2D|CU_PRIM_CIRCLE, 0); /* circle */ + nu= addNurbprim(C, CU_NURBS|CU_PRIM_CIRCLE, 0); /* circle */ xzproj= 0; nu->resolu= 4; nu->resolv= 4; @@ -5133,87 +5133,6 @@ Nurb *addNurbprim(bContext *C, int type, int newname) return nu; } -/***************** add curve primitive operator ********************/ - -static int add_curve_primitive_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - - addNurbprim(C, RNA_enum_get(op->ptr, "type"), 0); - - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, obedit); - - return OPERATOR_FINISHED; -} - -void CURVE_OT_add_curve_primitive(wmOperatorType *ot) -{ - static EnumPropertyItem type_items[]= { - {CU_PRIM_CURVE|CU_2D|CU_BEZIER, "BEZIER_CURVE", "Bezier Curve", ""}, - {CU_PRIM_CIRCLE|CU_2D|CU_BEZIER, "BEZIER_CIRCLE", "Bezier Circle", ""}, - {CU_PRIM_CURVE|CU_2D|CU_NURBS, "NURBS_CURVE", "NURBS Curve", ""}, - {CU_PRIM_CIRCLE|CU_2D|CU_NURBS, "NURBS_CIRCLE", "NURBS Circle", ""}, - {CU_PRIM_PATH|CU_2D|CU_NURBS, "PATH", "Path", ""}, - {0, NULL, NULL, NULL}}; - - /* identifiers */ - ot->name= "Add Curve Primitive"; - ot->idname= "CURVE_OT_add_curve_primitive"; - - /* api callbacks */ - ot->exec= add_curve_primitive_exec; - ot->poll= ED_operator_editcurve; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - - /* properties */ - RNA_def_enum(ot->srna, "type", type_items, CU_PRIM_CURVE|CU_2D|CU_BEZIER, "Type", "Type of primitive to add."); -} - -/***************** add surface primitive operator ********************/ - -static int add_surface_primitive_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - Object *obedit= CTX_data_edit_object(C); - - addNurbprim(C, RNA_enum_get(op->ptr, "type"), 0); - - DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, obedit); - - return OPERATOR_FINISHED; -} - -void CURVE_OT_add_surface_primitive(wmOperatorType *ot) -{ - static EnumPropertyItem type_items[]= { - {CU_PRIM_CURVE|CU_NURBS, "NURBS_CURVE", "NURBS Curve", ""}, - {CU_PRIM_CIRCLE|CU_NURBS, "NURBS_CIRCLE", "NURBS Circle", ""}, - {CU_PRIM_PATCH|CU_NURBS, "NURBS_SURFACE", "NURBS Surface", ""}, - {CU_PRIM_TUBE|CU_NURBS, "NURBS_TUBE", "NURBS Tube", ""}, - {CU_PRIM_SPHERE|CU_NURBS, "NURBS_SPHERE", "NURBS Sphere", ""}, - {CU_PRIM_DONUT|CU_NURBS, "NURBS_DONUT", "NURBS Donut", ""}, - {0, NULL, NULL, NULL}}; - - /* identifiers */ - ot->name= "Add Surface Primitive"; - ot->idname= "CURVE_OT_add_surface_primitive"; - - /* api callbacks */ - ot->exec= add_surface_primitive_exec; - ot->poll= ED_operator_editsurf; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - - /* properties */ - RNA_def_enum(ot->srna, "type", type_items, CU_PRIM_CURVE|CU_NURBS, "Type", "Type of primitive to add."); -} - /***************** clear tilt operator ********************/ static int clear_tilt_exec(bContext *C, wmOperator *op) |