2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19323...
[blender.git] / source / blender / editors / curve / editcurve.c
index 830d36dcfd88df20ec5eb3347d820b34346115a5..72806a79c50d18f512d328caa3148c87e3ffd6d5 100644 (file)
@@ -652,7 +652,7 @@ static int deleteflagNurb(bContext *C, wmOperator *op, int flag)
                                nu->bp= newbp;
                                clamp_nurb_order_v(nu);
 
-                               makeknots(nu, 2, nu->flagv>>1);
+                               makeknots(nu, 2);
                        }
                        else {
                                /* is the nurb in V direction selected */
@@ -698,7 +698,7 @@ static int deleteflagNurb(bContext *C, wmOperator *op, int flag)
                                                nu->pntsu= newu;
                                                clamp_nurb_order_u(nu);
                                        }
-                                       makeknots(nu, 1, nu->flagu>>1);
+                                       makeknots(nu, 1);
                                }
                        }
                }
@@ -746,7 +746,7 @@ static short extrudeflagNurb(ListBase *editnurb, int flag)
 
                                nu->pntsv= 2;
                                nu->orderv= 2;
-                               makeknots(nu, 2, nu->flagv>>1);
+                               makeknots(nu, 2);
                        }
                }
                else {
@@ -789,7 +789,7 @@ static short extrudeflagNurb(ListBase *editnurb, int flag)
                                        MEM_freeN(nu->bp);
                                        nu->bp= newbp;
                                        nu->pntsv++;
-                                       makeknots(nu, 2, nu->flagv>>1);
+                                       makeknots(nu, 2);
                                }
                                else if(v==0 || v== nu->pntsu-1) {          /* collumn in v-direction selected */
                                        ok= 1;
@@ -816,7 +816,7 @@ static short extrudeflagNurb(ListBase *editnurb, int flag)
                                        MEM_freeN(nu->bp);
                                        nu->bp= newbp;
                                        nu->pntsu++;
-                                       makeknots(nu, 1, nu->flagu>>1);
+                                       makeknots(nu, 1);
                                }
                        }
                }
@@ -911,7 +911,7 @@ static void adduplicateflagNurb(Object *obedit, short flag)
 
                                        /* knots */
                                        newnu->knotsu= NULL;
-                                       makeknots(newnu, 1, newnu->flagu>>1);
+                                       makeknots(newnu, 1);
                                }
                                bp++;
                        }
@@ -975,14 +975,14 @@ static void adduplicateflagNurb(Object *obedit, short flag)
                                                if(nu->pntsu==newnu->pntsu && nu->knotsu) {
                                                        newnu->knotsu= MEM_dupallocN( nu->knotsu );
                                                } else {
-                                                       makeknots(newnu, 1, newnu->flagu>>1);
+                                                       makeknots(newnu, 1);
                                                }
                                        }
                                        if (check_valid_nurb_v(newnu)) {
                                                if(nu->pntsv==newnu->pntsv && nu->knotsv) {
                                                        newnu->knotsv= MEM_dupallocN( nu->knotsv );
                                                } else {
-                                                       makeknots(newnu, 2, newnu->flagv>>1);
+                                                       makeknots(newnu, 2);
                                                }
                                        }
                                }
@@ -1061,18 +1061,17 @@ static int set_weight_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void CURVE_OT_set_weight(wmOperatorType *ot)
+void CURVE_OT_spline_weight_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Curve Weight";
-       ot->idname= "CURVE_OT_set_weight";
+       ot->idname= "CURVE_OT_spline_weight_set";
        
        /* api callbacks */
        ot->exec= set_weight_exec;
+       ot->invoke= WM_operator_redo;
        ot->poll= ED_operator_editsurfcurve;
 
-       // XXX invoke popup?
-
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
@@ -1113,18 +1112,17 @@ static int set_radius_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void CURVE_OT_set_radius(wmOperatorType *ot)
+void CURVE_OT_radius_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Curve Radius";
-       ot->idname= "CURVE_OT_set_radius";
+       ot->idname= "CURVE_OT_radius_set";
        
        /* api callbacks */
        ot->exec= set_radius_exec;
+       ot->invoke= WM_operator_redo;
        ot->poll= ED_operator_editsurfcurve;
 
-       // XXX invoke popup?
-
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
@@ -1595,11 +1593,11 @@ static int de_select_all_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void CURVE_OT_de_select_all(wmOperatorType *ot)
+void CURVE_OT_select_all_toggle(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Select or Deselect All";
-       ot->idname= "CURVE_OT_de_select_all";
+       ot->idname= "CURVE_OT_select_all_toggle";
        
        /* api callbacks */
        ot->exec= de_select_all_exec;
@@ -1741,7 +1739,7 @@ void CURVE_OT_reveal(wmOperatorType *ot)
 
 /********************** select invert operator *********************/
 
-static int select_inverse_exec(bContext *C, wmOperator *op)
+static int select_invert_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
        ListBase *editnurb= curve_get_editcurve(obedit);
@@ -1780,14 +1778,14 @@ static int select_inverse_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;       
 }
 
-void CURVE_OT_select_inverse(wmOperatorType *ot)
+void CURVE_OT_select_invert(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select Inverse";
-       ot->idname= "CURVE_OT_select_inverse";
+       ot->name= "Select Invert";
+       ot->idname= "CURVE_OT_select_invert";
        
        /* api callbacks */
-       ot->exec= select_inverse_exec;
+       ot->exec= select_invert_exec;
        ot->poll= ED_operator_editsurfcurve;
        
        /* flags */
@@ -1964,8 +1962,8 @@ static int subdivide_exec(bContext *C, wmOperator *op)
                                nu->bp= bpnew;
                                nu->pntsu+= amount;
 
-                               if(nu->type & 4) {
-                                       makeknots(nu, 1, nu->flagu>>1);
+                               if(nu->type & CU_NURBS) {
+                                       makeknots(nu, 1);
                                }
                        }
                } /* End of 'else if(nu->pntsv==1)' */
@@ -2076,8 +2074,8 @@ static int subdivide_exec(bContext *C, wmOperator *op)
                                nu->bp= bpnew;
                                nu->pntsu= 2*nu->pntsu-1;
                                nu->pntsv= 2*nu->pntsv-1;
-                               makeknots(nu, 1, nu->flagu>>1);
-                               makeknots(nu, 2, nu->flagv>>1);
+                               makeknots(nu, 1);
+                               makeknots(nu, 2);
                        } /* End of 'if(sel== nu->pntsu*nu->pntsv)' (subdivide entire NURB) */
                        else {
                                /* subdivide in v direction? */
@@ -2120,7 +2118,7 @@ static int subdivide_exec(bContext *C, wmOperator *op)
                                        MEM_freeN(nu->bp);
                                        nu->bp= bpnew;
                                        nu->pntsv+= sel;
-                                       makeknots(nu, 2, nu->flagv>>1);
+                                       makeknots(nu, 2);
                                }
                                else {
                                        /* or in u direction? */
@@ -2160,7 +2158,7 @@ static int subdivide_exec(bContext *C, wmOperator *op)
                                                MEM_freeN(nu->bp);
                                                nu->bp= bpnew;
                                                nu->pntsu+= sel;
-                                               makeknots(nu, 1, nu->flagu>>1); /* shift knots
+                                               makeknots(nu, 1); /* shift knots
                                                      forward */
                                        }
                                }
@@ -2318,7 +2316,7 @@ static int convertspline(short type, Nurb *nu)
        BPoint *bp;
        int a, c, nr;
 
-       if((nu->type & 7)==0) {         /* Poly */
+       if((nu->type & 7)==CU_POLY) {
                if(type==CU_BEZIER) {                       /* to Bezier with vecthandles  */
                        nr= nu->pntsu;
                        bezt =
@@ -2339,16 +2337,16 @@ static int convertspline(short type, Nurb *nu)
                        nu->bp= 0;
                        nu->pntsu= nr;
                        nu->type &= ~7;
-                       nu->type |= 1;
+                       nu->type |= CU_BEZIER;
                        calchandlesNurb(nu);
                }
                else if(type==CU_NURBS) {
                        nu->type &= ~7;
-                       nu->type+= 4;
+                       nu->type |= CU_NURBS;
                        nu->orderu= 4;
                        nu->flagu &= CU_CYCLIC; /* disable all flags except for cyclic */
                        nu->flagu += 4;
-                       makeknots(nu, 1, nu->flagu>>1);
+                       makeknots(nu, 1);
                        a= nu->pntsu*nu->pntsv;
                        bp= nu->bp;
                        while(a--) {
@@ -2402,7 +2400,7 @@ static int convertspline(short type, Nurb *nu)
                        if(type== 4) {
                                nu->flagu &= CU_CYCLIC; /* disable all flags except for cyclic */
                                nu->flagu += 4;
-                               makeknots(nu, 1, nu->flagu>>1);
+                               makeknots(nu, 1);
                        }
                }
        }
@@ -2444,7 +2442,7 @@ static int convertspline(short type, Nurb *nu)
                                nu->knotsu= NULL;
                                nu->pntsu= nr;
                                nu->type &= ~7;
-                               nu->type+= 1;
+                               nu->type |= CU_BEZIER;
                        }
                }
        }
@@ -2476,7 +2474,7 @@ static int set_spline_type_exec(bContext *C, wmOperator *op)
        return (changed)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
 }
 
-void CURVE_OT_set_spline_type(wmOperatorType *ot)
+void CURVE_OT_spline_type_set(wmOperatorType *ot)
 {
        static EnumPropertyItem type_items[]= {
                {CU_POLY, "POLY", "Poly", ""},
@@ -2488,7 +2486,7 @@ void CURVE_OT_set_spline_type(wmOperatorType *ot)
 
        /* identifiers */
        ot->name= "Set Spline Type";
-       ot->idname= "CURVE_OT_set_spline_type";
+       ot->idname= "CURVE_OT_spline_type_set";
        
        /* api callbacks */
        ot->exec= set_spline_type_exec;
@@ -2517,7 +2515,7 @@ static int set_handle_type_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void CURVE_OT_set_handle_type(wmOperatorType *ot)
+void CURVE_OT_handle_type_set(wmOperatorType *ot)
 {
        static EnumPropertyItem type_items[]= {
                {1, "AUTOMATIC", "Automatic", ""},
@@ -2529,7 +2527,7 @@ void CURVE_OT_set_handle_type(wmOperatorType *ot)
 
        /* identifiers */
        ot->name= "Set Handle Type";
-       ot->idname= "CURVE_OT_set_handle_type";
+       ot->idname= "CURVE_OT_handle_type_set";
        
        /* api callbacks */
        ot->exec= set_handle_type_exec;
@@ -2805,12 +2803,12 @@ static void merge_2_nurb(wmOperator *op, ListBase *editnurb, Nurb *nu1, Nurb *nu
                }
        }
 
-       if((nu1->type & 7)==4) {
+       if((nu1->type & 7)==CU_NURBS) {
                /* merge knots */
-               makeknots(nu1, 1, nu1->flagu>>1);
+               makeknots(nu1, 1);
        
                /* make knots, for merged curved for example */
-               makeknots(nu1, 2, nu1->flagv>>1);
+               makeknots(nu1, 2);
        }
        
        MEM_freeN(temp);
@@ -2993,9 +2991,9 @@ static int make_segment_exec(bContext *C, wmOperator *op)
                                BLI_remlink(editnurb, nu2);
 
                                /* now join the knots */
-                               if((nu1->type & 7)==4) {
+                               if((nu1->type & 7)==CU_NURBS) {
                                        if(nu1->knotsu==NULL) {
-                                               makeknots(nu1, 1, nu1->flagu>>1);
+                                               makeknots(nu1, 1);
                                        }
                                        else {
                                                fp= MEM_mallocN(sizeof(float)*KNOTSU(nu1), "addsegment3");
@@ -3218,7 +3216,7 @@ static int spin_nurb(bContext *C, Scene *scene, Object *obedit, float *dvec, sho
                        if(isNurbsel(nu)) {
                                nu->orderv= 4;
                                nu->flagv |= CU_CYCLIC;
-                               makeknots(nu, 2, nu->flagv>>1);
+                               makeknots(nu, 2);
                        }
                }
        }
@@ -3354,7 +3352,7 @@ static int addvert_Nurb(bContext *C, short mode, float location[3])
                if(bp) {
                        nu->pntsu++;
                        
-                       makeknots(nu, 1, nu->flagu>>1);
+                       makeknots(nu, 1);
                        
                        if(mode=='e') {
                                VECCOPY(newbp->vec, bp->vec);
@@ -3406,11 +3404,11 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event)
        return add_vertex_exec(C, op);
 }
 
-void CURVE_OT_add_vertex(wmOperatorType *ot)
+void CURVE_OT_vertex_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Vertex";
-       ot->idname= "CURVE_OT_add_vertex";
+       ot->idname= "CURVE_OT_vertex_add";
        
        /* api callbacks */
        ot->exec= add_vertex_exec;
@@ -3490,18 +3488,16 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
        Nurb *nu;
        BezTriple *bezt;
        BPoint *bp;
-       float *fp;
-       int a, b, direction= RNA_enum_get(op->ptr, "direction");
+       int a, direction= RNA_enum_get(op->ptr, "direction");
 
        for(nu= editnurb->first; nu; nu= nu->next) {
                if( nu->pntsu>1 || nu->pntsv>1) {
-                       if( (nu->type & 7)==0 ) {
+                       if( (nu->type & 7)==CU_POLY ) {
                                a= nu->pntsu;
                                bp= nu->bp;
                                while(a--) {
                                        if( bp->f1 & SELECT ) {
-                                               if(nu->flagu & CU_CYCLIC) nu->flagu &= ~CU_CYCLIC;
-                                               else nu->flagu |= CU_CYCLIC;
+                                               nu->flagu ^= CU_CYCLIC;
                                                break;
                                        }
                                        bp++;
@@ -3512,8 +3508,7 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
                                bezt= nu->bezt;
                                while(a--) {
                                        if( BEZSELECTED_HIDDENHANDLES(bezt) ) {
-                                               if(nu->flagu & CU_CYCLIC) nu->flagu &= ~CU_CYCLIC;
-                                               else nu->flagu |= CU_CYCLIC;
+                                               nu->flagu ^= CU_CYCLIC;
                                                break;
                                        }
                                        bezt++;
@@ -3526,19 +3521,8 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
                                        bp= nu->bp;
                                        while(a--) {
                                                if( bp->f1 & SELECT ) {
-                                                       if(nu->flagu & CU_CYCLIC) nu->flagu &= ~CU_CYCLIC;
-                                                       else {
-                                                               nu->flagu |= CU_CYCLIC;
-                                                               nu->flagu &= ~2;        /* endpoint flag, fixme */
-                                                               fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
-                                                               b= (nu->orderu+nu->pntsu);
-                                                               memcpy(fp, nu->knotsu, sizeof(float)*b);
-                                                               MEM_freeN(nu->knotsu);
-                                                               nu->knotsu= fp;
-                                                       
-                                                               makeknots(nu, 1, 0);    /* 1==u  0==uniform */
-                                                       
-                                                       }
+                                                       nu->flagu ^= CU_CYCLIC;
+                                                       makeknots(nu, 1);       /* 1==u  type is ignored for cyclic curves */
                                                        break;
                                                }
                                                bp++;
@@ -3552,38 +3536,12 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
        
                                        if( bp->f1 & SELECT) {
                                                if(direction==0 && nu->pntsu>1) {
-                                                       if(nu->flagu & CU_CYCLIC) nu->flagu &= ~CU_CYCLIC;
-                                                       else {
-                                                               nu->flagu |= CU_CYCLIC;
-                                                               if (check_valid_nurb_u(nu)) {
-                                                                       fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
-                                                                       b= (nu->orderu+nu->pntsu);
-                                                                       if (nu->knotsu) { /* null if check_valid_nurb_u failed before but is valid now */
-                                                                               memcpy(fp, nu->knotsu, sizeof(float)*b);
-                                                                               MEM_freeN(nu->knotsu);
-                                                                       }
-                                                                       nu->knotsu= fp;
-                                                               
-                                                                       makeknots(nu, 1, 0);    /* 1==u  0==uniform */
-                                                               }
-                                                       }
+                                                       nu->flagu ^= CU_CYCLIC;
+                                                       makeknots(nu, 1);   /* 1==u  type is ignored for cyclic curves */
                                                }
                                                if(direction==1 && nu->pntsv>1) {
-                                                       if(nu->flagv & 1) nu->flagv--;
-                                                       else {
-                                                               nu->flagv++;
-                                                               if (check_valid_nurb_v(nu)) {
-                                                                       fp= MEM_mallocN(sizeof(float)*KNOTSV(nu), "makecyclicN");
-                                                                       b= (nu->orderv+nu->pntsv);
-                                                                       if (nu->knotsv) { /* null if check_valid_nurb_v failed before but is valid now */
-                                                                               memcpy(fp, nu->knotsv, sizeof(float)*b);
-                                                                               MEM_freeN(nu->knotsv);
-                                                                       }
-                                                                       nu->knotsv= fp;
-                                                               
-                                                                       makeknots(nu, 2, 0);    /* 2==v  0==uniform */
-                                                               }
-                                                       }
+                                                       nu->flagv ^= CU_CYCLIC;
+                                                       makeknots(nu, 2);   /* 2==v  type is ignored for cyclic curves */
                                                }
                                                break;
                                        }
@@ -3621,7 +3579,7 @@ static int toggle_cyclic_invoke(bContext *C, wmOperator *op, wmEvent *event)
        return toggle_cyclic_exec(C, op);
 }
 
-void CURVE_OT_toggle_cyclic(wmOperatorType *ot)
+void CURVE_OT_cyclic_toggle(wmOperatorType *ot)
 {
        static EnumPropertyItem direction_items[]= {
                {0, "CYCLIC_U", "Cyclic U", ""},
@@ -3630,7 +3588,7 @@ void CURVE_OT_toggle_cyclic(wmOperatorType *ot)
 
        /* identifiers */
        ot->name= "Toggle Cyclic";
-       ot->idname= "CURVE_OT_toggle_cyclic";
+       ot->idname= "CURVE_OT_cyclic_toggle";
        
        /* api callbacks */
        ot->exec= toggle_cyclic_exec;
@@ -4187,9 +4145,8 @@ void CURVE_OT_select_random(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= select_random_exec;
+       ot->invoke= WM_operator_redo;
        ot->poll= ED_operator_editsurfcurve;
-       
-       // XXX invoke popup?
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -4222,9 +4179,8 @@ void CURVE_OT_select_every_nth(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= select_every_nth_exec;
+       ot->invoke= WM_operator_redo;
        ot->poll= ED_operator_editsurfcurve;
-
-       // XXX invoke popup?
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -4393,7 +4349,7 @@ static int delete_exec(bContext *C, wmOperator *op)
                                                clamp_nurb_order_u(nu);
                                        }*/
                                }
-                               makeknots(nu, 1, nu->flagu>>1);
+                               makeknots(nu, 1);
                        }
                        nu= next;
                }
@@ -4617,11 +4573,11 @@ static int set_smooth_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void CURVE_OT_set_smooth(wmOperatorType *ot)
+void CURVE_OT_smooth_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Smooth";
-       ot->idname= "CURVE_OT_set_smooth";
+       ot->idname= "CURVE_OT_smooth_set";
        
        /* api callbacks */
        ot->exec= set_smooth_exec;
@@ -4854,7 +4810,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname)
 
                        if(cutype==CU_NURBS) {
                                nu->knotsu= 0;  /* makeknots allocates */
-                               makeknots(nu, 1, nu->flagu>>1);
+                               makeknots(nu, 1);
                        }
 
                }
@@ -4889,7 +4845,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname)
 
                if(cutype==CU_NURBS) {
                        nu->knotsu= 0;  /* makeknots allocates */
-                       makeknots(nu, 1, nu->flagu>>1);
+                       makeknots(nu, 1);
                }
 
                break;
@@ -4974,7 +4930,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname)
                                bp++;
                        }
 
-                       makeknots(nu, 1, nu->flagu>>1);
+                       makeknots(nu, 1);
                }
                break;
        case CU_PRIM_PATCH:     /* 4x4 patch */
@@ -5011,8 +4967,8 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname)
                                }
                        }
 
-                       makeknots(nu, 1, nu->flagu>>1);
-                       makeknots(nu, 2, nu->flagv>>1);
+                       makeknots(nu, 1);
+                       makeknots(nu, 2);
                }
                break;
        case CU_PRIM_TUBE:      /* tube */
@@ -5074,7 +5030,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname)
                                bp++;
                        }
                        nu->flagu= 4;
-                       makeknots(nu, 1, nu->flagu>>1);
+                       makeknots(nu, 1);
 
                        BLI_addtail(editnurb, nu); /* temporal for spin */
                        if(newname && (U.flag & USER_ADD_VIEWALIGNED) == 0)
@@ -5082,7 +5038,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname)
                        else
                                spin_nurb(C, scene, obedit, 0, 0);
 
-                       makeknots(nu, 2, nu->flagv>>1);
+                       makeknots(nu, 2);
 
                        a= nu->pntsu*nu->pntsv;
                        bp= nu->bp;
@@ -5169,11 +5125,11 @@ static int clear_tilt_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void CURVE_OT_clear_tilt(wmOperatorType *ot)
+void CURVE_OT_tilt_clear(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Clear Tilt";
-       ot->idname= "CURVE_OT_clear_tilt";
+       ot->idname= "CURVE_OT_tilt_clear";
        
        /* api callbacks */
        ot->exec= clear_tilt_exec;