2.5
authorTon Roosendaal <ton@blender.org>
Mon, 26 Jan 2009 15:23:29 +0000 (15:23 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 26 Jan 2009 15:23:29 +0000 (15:23 +0000)
Added add-primitive for Curve objects.
Shift+A, works as usual in our outside editmode.

source/blender/editors/curve/curve_ops.c
source/blender/editors/curve/editcurve.c
source/blender/editors/include/ED_curve.h
source/blender/editors/object/object_edit.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/makesdna/DNA_curve_types.h

index ee7260606a5a564b6c4b6559412eb925a2d05528..4d60c2716ba20cc288d4a63d742ecd9f7a67e14d 100644 (file)
@@ -74,9 +74,9 @@ void ED_keymap_curve(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "FONT_OT_textedit", KM_TEXTINPUT, KM_ANY, KM_ANY, 0);
 
        /* only set in editmode curve, by space_view3d listener */
-//     keymap= WM_keymap_listbase(wm, "Curve", 0, 0);
+       keymap= WM_keymap_listbase(wm, "Curve", 0, 0);
        
-//     WM_keymap_add_item(keymap, "OBJECT_OT_de_select_all", AKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "OBJECT_OT_curve_add", AKEY, KM_PRESS, KM_SHIFT, 0);
 
 }
 
index 4d468fdd28b19e312de7cfd91d183f1468d587b3..075b10473923783040aca4b119d4be897f80d424 100644 (file)
@@ -4049,28 +4049,23 @@ int join_curve(Scene *scene, int type)
        return 1;
 }
 
-
-
-Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
-/* type: &8= 2D;  0=poly,1 bez, 4 nurb
- * stype:   0: 2/4 points curve
- *         1: 8 points circle
- *         2: 4x4 patch Nurb
- *         3: tube 4:sphere 5:donut
- *             6: 5 points,  5th order straight line (for anim path) 
- */
+Nurb *addNurbprim(bContext *C, int type, int newname)
 {
-       Object *obedit= scene->obedit; // XXX
+       static int xzproj= 0;   /* this function calls itself... */
+       Scene *scene= CTX_data_scene(C);
+       Object *obedit= CTX_data_edit_object(C);
        ListBase *editnurb= curve_get_editcurve(obedit);
-       View3D *v3d= NULL; // XXX
-       RegionView3D *rv3d= NULL; // XXX
-       static int xzproj= 0;
+       View3D *v3d= CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        Nurb *nu = NULL;
        BezTriple *bezt;
        BPoint *bp;
        float *curs, cent[3],vec[3],imat[3][3],mat[3][3];
        float fac,cmat[3][3], grid;
-       int a, b;
+       int a, b, cutype, stype;
+       
+       cutype= type & CU_TYPE; // poly, bezier, nurbs, etc
+       stype= type & CU_PRIMITIVE;
        
        if (v3d)        grid = v3d->grid;
        else            grid = 1.0;
@@ -4085,7 +4080,7 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                cent[1]-= obedit->obmat[3][1];
                cent[2]-= obedit->obmat[3][2];
                
-               if (v3d) {
+               if (rv3d) {
                        if ( !(newname) || U.flag & USER_ADD_VIEWALIGNED) 
                                Mat3CpyMat4(imat, rv3d->viewmat);
                        else Mat3One(imat);
@@ -4096,11 +4091,11 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                setflagsNurb(editnurb, 0);
        }
        else {
-               Mat3One(imat);
-               cent[0]= cent[1]= cent[2]= 0.0;
+               return NULL;
        }
        
-       if (ELEM5(stype, 0, 1, 2, 4, 6)) {
+       /* these types call this function to return a Nurb */
+       if (stype!=CU_PRIM_TUBE && stype!=CU_PRIM_DONUT) {
                nu = (Nurb*)MEM_callocN(sizeof(Nurb), "addNurbprim");
                nu->type= type;
                nu->resolu= 4;
@@ -4108,13 +4103,13 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
        }
 
        switch(stype) {
-       case 0: /* curve */
+       case CU_PRIM_CURVE:     /* curve */
                nu->resolu= 12; /* set as 4 above */
                if(newname) {
                        rename_id((ID *)obedit, "Curve");
                        rename_id((ID *)obedit->data, "Curve");
                }
-               if((type & 7)==CU_BEZIER) {
+               if(cutype==CU_BEZIER) {
                        nu->pntsu= 2;
                        nu->bezt =
                                (BezTriple*)MEM_callocN(2 * sizeof(BezTriple), "addNurbprim1");
@@ -4175,14 +4170,14 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                        bp= nu->bp;
                        for(a=0;a<4;a++, bp++) Mat3MulVecfl(imat,bp->vec);
 
-                       if((type & 7)==4) {
+                       if(cutype==CU_NURBS) {
                                nu->knotsu= 0;  /* makeknots allocates */
                                makeknots(nu, 1, nu->flagu>>1);
                        }
 
                }
                break;
-       case 6: /* 5 point path */
+       case CU_PRIM_PATH:      /* 5 point path */
                nu->pntsu= 5;
                nu->pntsv= 1;
                nu->orderu= 5;
@@ -4210,19 +4205,19 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                bp= nu->bp;
                for(a=0;a<5;a++, bp++) Mat3MulVecfl(imat,bp->vec);
 
-               if((type & 7)==4) {
+               if(cutype==CU_NURBS) {
                        nu->knotsu= 0;  /* makeknots allocates */
                        makeknots(nu, 1, nu->flagu>>1);
                }
 
                break;
-       case 1: /* circle */
+       case CU_PRIM_CIRCLE:    /* circle */
                nu->resolu= 12; /* set as 4 above */
                if(newname) {
                        rename_id((ID *)obedit, "CurveCircle");
                        rename_id((ID *)obedit->data, "CurveCircle");
                }
-               if((type & 7)==CU_BEZIER) {
+               if(cutype==CU_BEZIER) {
                        nu->pntsu= 4;
                        nu->bezt= callocstructN(BezTriple, 4, "addNurbprim1");
                        nu->flagu= CU_CYCLIC;
@@ -4269,7 +4264,7 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
 
                        calchandlesNurb(nu);
                }
-               else if( (type & 7)==CU_NURBS ) {  /* nurb */
+               else if( cutype==CU_NURBS ) {  /* nurb */
                        nu->pntsu= 8;
                        nu->pntsv= 1;
                        nu->orderu= 4;
@@ -4300,8 +4295,8 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                        makeknots(nu, 1, nu->flagu>>1);
                }
                break;
-       case 2: /* 4x4 patch */
-               if( (type & 7)==CU_NURBS ) {  /* nurb */
+       case CU_PRIM_PATCH:     /* 4x4 patch */
+               if( cutype==CU_NURBS ) {  /* nurb */
                        if(newname) {
                                rename_id((ID *)obedit, "Surf");
                                rename_id((ID *)obedit->data, "Surf");
@@ -4338,14 +4333,14 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                        makeknots(nu, 2, nu->flagv>>1);
                }
                break;
-       case 3: /* tube */
-               if( (type & 7)==CU_NURBS ) {
+       case CU_PRIM_TUBE:      /* tube */
+               if( cutype==CU_NURBS ) {
                        if(newname) {
                                rename_id((ID *)obedit, "SurfTube");
                                rename_id((ID *)obedit->data, "SurfTube");
                        }
 
-                       nu= addNurbprim(scene, 4, 1, newname);  /* circle */
+                       nu= addNurbprim(C, CU_NURBS|CU_2D|CU_PRIM_CIRCLE, 0);  /* circle */
                        nu->resolu= 4;
                        nu->flag= CU_SMOOTH;
                        BLI_addtail(editnurb, nu); /* temporal for extrude and translate */
@@ -4369,8 +4364,8 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                        }
                }
                break;
-       case 4: /* sphere */
-               if( (type & 7)==CU_NURBS ) {
+       case CU_PRIM_SPHERE:    /* sphere */
+               if( cutype==CU_NURBS ) {
                        if(newname) {
                                rename_id((ID *)obedit, "SurfSphere");
                                rename_id((ID *)obedit->data, "SurfSphere");
@@ -4416,15 +4411,15 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                        BLI_remlink(editnurb, nu);
                }
                break;
-       case 5: /* donut */
-               if( (type & 7)==CU_NURBS ) {
+       case CU_PRIM_DONUT:     /* donut */
+               if( cutype==CU_NURBS ) {
                        if(newname) {
                                rename_id((ID *)obedit, "SurfDonut");
                                rename_id((ID *)obedit->data, "SurfDonut");
                        }
 
                        xzproj= 1;
-                       nu= addNurbprim(scene, 4, 1, newname);  /* circle */
+                       nu= addNurbprim(C, CU_NURBS|CU_2D|CU_PRIM_CIRCLE, 0);  /* circle */
                        xzproj= 0;
                        nu->resolu= 4;
                        nu->resolv= 4;
@@ -4492,110 +4487,6 @@ void default_curve_ipo(Scene *scene, Curve *cu)
 #endif // XXX old animation system
 }
 
-void add_primitiveCurve(Scene *scene, int stype)
-{
-       Object *obedit= scene->obedit; // XXX
-       ListBase *editnurb= curve_get_editcurve(obedit);
-       View3D *v3d= NULL; // XXX
-       Nurb *nu;
-       Curve *cu;
-       int type, newname= 0;
-
-       if(v3d==0) return;
-       if(scene->id.lib) return;
-
-       if(stype>=10 && stype<20) type= CU_2D+1;
-       else if(stype>=20 && stype<30) type= CU_2D+2;
-       else if(stype>=30 && stype<40) type= CU_2D+3;
-       else if(stype>=40 && stype<50) {
-               if(stype==46) type= 4;
-               else type= CU_2D+4;
-       }
-       else type= CU_2D;
-
-// XXX check_editmode(OB_CURVE);
-       
-       /* if no obedit: new object and enter editmode */
-       if(obedit==NULL) {
-// XXX         add_object_draw(OB_CURVE);
-               ED_object_base_init_from_view(NULL, BASACT); // NULL is C
-               obedit= BASACT->object;
-               
-               where_is_object(scene, obedit);
-               
-               make_editNurb(obedit);
-               newname= 1;
-               
-               cu= obedit->data;
-               if(stype==46) {
-                       cu->flag |= (CU_3D+CU_PATH);
-                       
-                       default_curve_ipo(scene, cu);
-               }
-       }
-       else {
-               cu= obedit->data;
-       }
-
-       if(cu->flag & CU_3D) type &= ~CU_2D;
-
-       stype= (stype % 10);
-       
-       nu= addNurbprim(scene, type, stype, newname);   /* 2D */
-       
-       BLI_addtail(editnurb, nu);
-       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-
-       /* if a new object was created, it stores it in Curve, for reload original data and undo */
-       if ( !(newname) || U.flag & USER_ADD_EDITMODE) {
-               if(newname) load_editNurb(obedit);
-       } else {
-               // XXX
-               ED_object_exit_editmode(NULL, EM_FREEDATA|EM_WAITCURSOR);
-       }
-       
-       BIF_undo_push("Add Curve");
-}
-
-void add_primitiveNurb(Scene *scene, int type)
-{
-       Object *obedit= scene->obedit; // XXX
-       ListBase *editnurb= curve_get_editcurve(obedit);
-       Nurb *nu;
-       int newname= 0;
-       
-       if(scene->id.lib) return;
-
-// XXX check_editmode(OB_SURF);
-
-       /* if no obedit: new object and enter editmode */
-       if(obedit==0) {
-// XXX         add_object_draw(OB_SURF);
-               ED_object_base_init_from_view(NULL, BASACT); // NULL is C
-                obedit= BASACT->object;
-               
-               where_is_object(scene, obedit);
-               
-               make_editNurb(obedit);
-               newname= 1;
-       }
-
-       nu= addNurbprim(scene, 4, type, newname);
-       BLI_addtail(editnurb,nu);
-       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-
-       /* if a new object was created, it stores it in Curve, for reload original data and undo */
-       if ( !(newname) || U.flag & USER_ADD_EDITMODE) {
-               if(newname) load_editNurb(obedit);
-       } else {
-               // XXX
-               ED_object_exit_editmode(NULL, EM_FREEDATA|EM_WAITCURSOR);
-       }
-       
-       BIF_undo_push("Add Surface");
-}
-
-
 
 void clear_tilt(Scene *scene)
 {
index 076f82c0a70265010788a29a3f9f68015bfb7446..29411e2cc9173efd7d1f20e1ecc080ba68a01921 100644 (file)
@@ -50,6 +50,8 @@ void  free_editNurb   (struct Object *obedit);
 
 void   mouse_nurb              (struct bContext *C, short mval[2], int extend);
 
+struct Nurb *addNurbprim(struct bContext *C, int type, int newname);
+
 /* editfont.h */
 void   undo_push_font  (struct bContext *C, char *name);
 void   make_editText   (struct Object *obedit);
index dc94d61b940261935f949ab552a16f1e8ab5ece3..9b421cd7b8eecacb837c911caaef03a4901464bf 100644 (file)
@@ -284,15 +284,16 @@ void add_object_draw(Scene *scene, View3D *v3d, int type) /* for toolbox or menu
        /* keep here to get things compile, remove later */
 }
 
-static int object_add_exec(bContext *C, wmOperator *op)
+/* for object add primitive operators */
+static Object *object_add_type(bContext *C, int type)
 {
        Scene *scene= CTX_data_scene(C);
        Object *ob;
-       int type= RNA_int_get(op->ptr, "type");
        
-       /* hrms, this is editor level operator */
+       /* XXX hrms, this is editor level operator, remove? */
        ED_view3d_exit_paint_modes(C);
        
+       /* for as long scene has editmode... */
        if (CTX_data_edit_object(C)) 
                ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
        
@@ -306,6 +307,14 @@ static int object_add_exec(bContext *C, wmOperator *op)
        
        DAG_scene_sort(scene);
        
+       return ob;
+}
+
+/* for object add operator */
+static int object_add_exec(bContext *C, wmOperator *op)
+{
+       object_add_type(C, RNA_int_get(op->ptr, "type"));
+       
        return OPERATOR_FINISHED;
 }
 
@@ -346,13 +355,14 @@ static int object_add_mesh_exec(bContext *C, wmOperator *op)
        Object *obedit= CTX_data_edit_object(C);
        int newob= 0;
        
-       if(obedit==NULL) {
-               RNA_enum_set(op->ptr, "type", OB_MESH);
-               object_add_exec(C, op);
+       if(obedit==NULL || obedit->type!=OB_MESH) {
+               object_add_type(C, OB_MESH);
                ED_object_enter_editmode(C, 0);
                newob = 1;
        }
-       switch(RNA_enum_get(op->ptr, "primtype")) {
+       else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);
+
+       switch(RNA_enum_get(op->ptr, "type")) {
                case 0:
                        WM_operator_name_call(C, "MESH_OT_add_primitive_plane", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
@@ -386,19 +396,11 @@ static int object_add_mesh_exec(bContext *C, wmOperator *op)
                ED_object_exit_editmode(C, EM_FREEDATA);
        }
        
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+       
        return OPERATOR_FINISHED;
 }
 
-static int object_add_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       uiMenuItem *head= uiMenuBegin("Add Mesh");
-       
-       uiMenuItemsEnumO(head, "OBJECT_OT_mesh_add", "primtype");
-       uiMenuEnd(C, head);
-
-       /* this operator is only for a menu, not used further */
-       return OPERATOR_CANCELLED;
-}
 
 void OBJECT_OT_mesh_add(wmOperatorType *ot)
 {
@@ -407,38 +409,48 @@ void OBJECT_OT_mesh_add(wmOperatorType *ot)
        ot->idname= "OBJECT_OT_mesh_add";
        
        /* api callbacks */
-       ot->invoke= object_add_mesh_invoke;
+       ot->invoke= WM_menu_invoke;
        ot->exec= object_add_mesh_exec;
        
        ot->poll= ED_operator_scene_editable;
        ot->flag= OPTYPE_REGISTER;
        
-       RNA_def_enum(ot->srna, "type", prop_object_types, 0, "Type", "");
-       RNA_def_enum(ot->srna, "primtype", prop_mesh_types, 0, "Primitive", "");
+       RNA_def_enum(ot->srna, "type", prop_mesh_types, 0, "Primitive", "");
 }
 
 static EnumPropertyItem prop_curve_types[] = {
-       {0, "BEZCUVE", "Bezier Curve", ""},
-       {1, "BEZCIRCLE", "Bezier Circle", ""},
-       {2, "NURBSCUVE", "Nurbs Curve", ""},
-       {3, "NURBSCIRCLE", "Nurbs Circle", ""},
+       {CU_BEZIER|CU_2D|CU_PRIM_CURVE, "BEZCURVE", "Bezier Curve", ""},
+       {CU_BEZIER|CU_2D|CU_PRIM_CIRCLE, "BEZCIRCLE", "Bezier Circle", ""},
+       {CU_NURBS|CU_2D|CU_PRIM_CURVE, "NURBSCUVE", "NURBS Curve", ""},
+       {CU_NURBS|CU_2D|CU_PRIM_CIRCLE, "NURBSCIRCLE", "NURBS Circle", ""},
+       {CU_NURBS|CU_2D|CU_PRIM_PATH, "PATH", "Path", ""},
        {0, NULL, NULL, NULL}
 };
 
 static int object_add_curve_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
+       ListBase *editnurb;
+       Nurb *nu;
+       int newob= 0;
        
-       if(obedit==NULL) {
-               RNA_enum_set(op->ptr, "type", OB_MESH);
-               object_add_exec(C, op);
+       if(obedit==NULL || obedit->type!=OB_CURVE) {
+               object_add_type(C, OB_CURVE);
                ED_object_enter_editmode(C, 0);
+               newob = 1;
        }
-       switch(RNA_enum_get(op->ptr, "primtype")) {
-               
-               
-       }
+       else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);
+       
+       nu= addNurbprim(C, RNA_enum_get(op->ptr, "type"), newob);
+       editnurb= curve_get_editcurve(CTX_data_edit_object(C));
+       BLI_addtail(editnurb, nu);
+       
        /* userdef */
+       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+               ED_object_exit_editmode(C, EM_FREEDATA);
+       }
+       
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
        return OPERATOR_FINISHED;
 }
@@ -450,12 +462,13 @@ void OBJECT_OT_curve_add(wmOperatorType *ot)
        ot->idname= "OBJECT_OT_curve_add";
        
        /* api callbacks */
+       ot->invoke= WM_menu_invoke;
        ot->exec= object_add_curve_exec;
        
        ot->poll= ED_operator_scene_editable;
        ot->flag= OPTYPE_REGISTER;
        
-       RNA_def_enum(ot->srna, "primtype", prop_curve_types, 0, "Type", "");
+       RNA_def_enum(ot->srna, "type", prop_curve_types, 0, "Primitive", "");
 }
 
 
@@ -463,8 +476,8 @@ static int object_add_primitive_invoke(bContext *C, wmOperator *op, wmEvent *eve
 {
        uiMenuItem *head= uiMenuBegin("Add Object");
        
-       uiMenuLevelEnumO(head, "OBJECT_OT_mesh_add", "primtype");
-       uiMenuLevelEnumO(head, "OBJECT_OT_curve_add", "primtype");
+       uiMenuLevelEnumO(head, "OBJECT_OT_mesh_add", "type");
+       uiMenuLevelEnumO(head, "OBJECT_OT_curve_add", "type");
        uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_SURF);
        uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_MBALL);
        uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_CAMERA);
index 9ce9f8a244d57fa8f3e73fc218bb701b3ba43519..a2d948447b6571a83eb3f6bfef074aa59fab82f0 100644 (file)
@@ -250,6 +250,12 @@ static void view3d_modal_keymaps(wmWindowManager *wm, ARegion *ar, int stype)
        else
                WM_event_remove_keymap_handler(&ar->handlers, keymap);
 
+       keymap= WM_keymap_listbase(wm, "Curve", 0, 0);
+       if(stype==NS_EDITMODE_CURVE)
+               WM_event_add_keymap_handler(&ar->handlers, keymap);
+       else
+               WM_event_remove_keymap_handler(&ar->handlers, keymap);
+       
        /* editfont keymap swallows all... */
        keymap= WM_keymap_listbase(wm, "Font", 0, 0);
        if(stype==NS_EDITMODE_TEXT)
index 992b8907ba7af693a777a91e9a3aaecc84b8d6b1..6a88e76deca548ed3eab59d71c6f9574160bc816 100644 (file)
@@ -237,8 +237,26 @@ typedef struct Curve {
 #define CU_BSPLINE             2
 #define CU_CARDINAL            3
 #define CU_NURBS               4
+#define CU_TYPE                        7
+
 #define CU_2D                  8
 
+               /* only for adding */
+#define CU_PRIMITIVE   0xF00
+
+               /* 2 or 4 points */
+#define CU_PRIM_CURVE  0x100
+               /* 8 points circle */
+#define CU_PRIM_CIRCLE 0x200
+               /* 4x4 patch Nurb */
+#define CU_PRIM_PATCH  0x300
+#define CU_PRIM_TUBE   0x400
+#define CU_PRIM_SPHERE 0x500
+#define CU_PRIM_DONUT  0x600
+               /* 5 points,  5th order straight line (for anim path) */
+#define CU_PRIM_PATH   0x700
+
+
 /* flagu flagv (nurb) */
 #define CU_CYCLIC              1