rename RNA_property_is_set() --> RNA_struct_property_is_set() in preperation to add...
[blender.git] / source / blender / editors / curve / editcurve.c
index 1ab7acef8618b49e7211e6ecd2a25d548b38abd7..aea6f5c43b6e0630d3c49ece88eea32bb7cd821f 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -117,7 +115,7 @@ static float nurbcircle[8][2]= {
        {0.0,  1.0}, { 1.0,  1.0}, { 1.0, 0.0}, { 1.0, -1.0}
 };
 
-ListBase *curve_get_editcurve(Object *ob)
+ListBase *object_editcurve_get(Object *ob)
 {
        if(ob && ELEM(ob->type, OB_CURVE, OB_SURF)) {
                Curve *cu= ob->data;
@@ -134,7 +132,7 @@ static void set_actNurb(Object *obedit, Nurb *nu)
        if(nu==NULL)
                cu->actnu = -1;
        else {
-               ListBase *nurbs= ED_curve_editnurbs(cu);
+               ListBase *nurbs= curve_editnurbs(cu);
                cu->actnu = BLI_findindex(nurbs, nu);
        }
 }
@@ -142,7 +140,7 @@ static void set_actNurb(Object *obedit, Nurb *nu)
 static Nurb *get_actNurb(Object *obedit)
 {
        Curve *cu= obedit->data;
-       ListBase *nurbs= ED_curve_editnurbs(cu);
+       ListBase *nurbs= curve_editnurbs(cu);
 
        return BLI_findlink(nurbs, cu->actnu);
 }
@@ -268,7 +266,7 @@ static int isNurbsel_count(Curve *cu, Nurb *nu)
 
 void printknots(Object *obedit)
 {
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        int a, num;
 
@@ -302,11 +300,6 @@ static CVKeyIndex *init_cvKeyIndex(void *cv, int key_index, int nu_index, int pt
        return cvIndex;
 }
 
-static void free_cvKeyIndex(CVKeyIndex *pointIndex)
-{
-       MEM_freeN(pointIndex);
-}
-
 static void init_editNurb_keyIndex(EditNurb *editnurb, ListBase *origBase)
 {
        Nurb *nu= editnurb->nurbs.first;
@@ -358,15 +351,6 @@ static void init_editNurb_keyIndex(EditNurb *editnurb, ListBase *origBase)
        editnurb->keyindex= gh;
 }
 
-static void free_editNurb_keyIndex(EditNurb *editnurb)
-{
-       if (!editnurb->keyindex) {
-               return;
-       }
-       BLI_ghash_free(editnurb->keyindex, NULL, (GHashValFreeFP)free_cvKeyIndex);
-       editnurb->keyindex= NULL;
-}
-
 static CVKeyIndex *getCVKeyIndex(EditNurb *editnurb, void *cv)
 {
        return BLI_ghash_lookup(editnurb->keyindex, cv);
@@ -411,7 +395,7 @@ static void keyIndex_delCV(EditNurb *editnurb, void *cv)
                return;
        }
 
-       BLI_ghash_remove(editnurb->keyindex, cv, NULL, (GHashValFreeFP)free_cvKeyIndex);
+       BLI_ghash_remove(editnurb->keyindex, cv, NULL, (GHashValFreeFP)MEM_freeN);
 }
 
 static void keyIndex_delBezt(EditNurb *editnurb, BezTriple *bezt)
@@ -437,7 +421,7 @@ static void keyIndex_delNurb(EditNurb *editnurb, Nurb *nu)
                a= nu->pntsu;
 
                while (a--) {
-                       BLI_ghash_remove(editnurb->keyindex, bezt, NULL, (GHashValFreeFP)free_cvKeyIndex);
+                       BLI_ghash_remove(editnurb->keyindex, bezt, NULL, (GHashValFreeFP)MEM_freeN);
                        ++bezt;
                }
        } else {
@@ -445,7 +429,7 @@ static void keyIndex_delNurb(EditNurb *editnurb, Nurb *nu)
                a= nu->pntsu * nu->pntsv;
 
                while (a--) {
-                       BLI_ghash_remove(editnurb->keyindex, bp, NULL, (GHashValFreeFP)free_cvKeyIndex);
+                       BLI_ghash_remove(editnurb->keyindex, bp, NULL, (GHashValFreeFP)MEM_freeN);
                        ++bp;
                }
        }
@@ -704,8 +688,8 @@ static void key_to_bezt(float *key, BezTriple *basebezt, BezTriple *bezt)
 
 static void bezt_to_key(BezTriple *bezt, float *key)
 {
-        memcpy(key, bezt->vec, sizeof(float) * 9);
-        key[9] = bezt->alfa;
+       memcpy(key, bezt->vec, sizeof(float) * 9);
+       key[9] = bezt->alfa;
 }
 
 static void calc_keyHandles(ListBase *nurb, float *key)
@@ -780,7 +764,7 @@ static void calc_shapeKeys(Object *obedit)
 
        /* are there keys? */
        if(cu->key) {
-               int a, i, j;
+               int a, i;
                EditNurb *editnurb= cu->editnurb;
                KeyBlock *currkey;
                KeyBlock *actkey= BLI_findlink(&cu->key->block, editnurb->shapenr-1);
@@ -804,7 +788,6 @@ static void calc_shapeKeys(Object *obedit)
                        }
 
                        if(act_is_basis) { /* active key is a base */
-                               int j;
                                int totvec= 0;
 
                                /* Calculate needed memory to store offset */
@@ -831,8 +814,9 @@ static void calc_shapeKeys(Object *obedit)
                                                        oldbezt= getKeyIndexOrig_bezt(editnurb, bezt);
 
                                                        if (oldbezt) {
+                                                               int j;
                                                                for (j= 0; j < 3; ++j) {
-                                                                       VECSUB(ofs[i], bezt->vec[j], oldbezt->vec[j]);
+                                                                       sub_v3_v3v3(ofs[i], bezt->vec[j], oldbezt->vec[j]);
                                                                        i++;
                                                                }
                                                                ofs[i++][0]= bezt->alfa - oldbezt->alfa;
@@ -848,7 +832,7 @@ static void calc_shapeKeys(Object *obedit)
                                                while(a--) {
                                                        oldbp= getKeyIndexOrig_bp(editnurb, bp);
                                                        if (oldbp) {
-                                                               VECSUB(ofs[i], bp->vec, oldbp->vec);
+                                                               sub_v3_v3v3(ofs[i], bp->vec, oldbp->vec);
                                                                ofs[i+1][0]= bp->alfa - oldbp->alfa;
                                                        }
                                                        i += 2;
@@ -878,13 +862,14 @@ static void calc_shapeKeys(Object *obedit)
                                                bezt= nu->bezt;
                                                a= nu->pntsu;
                                                while(a--) {
+                                                       int j;
                                                        oldbezt= getKeyIndexOrig_bezt(editnurb, bezt);
 
                                                        for (j= 0; j < 3; ++j, ++i) {
-                                                               VECCOPY(fp, bezt->vec[j]);
+                                                               copy_v3_v3(fp, bezt->vec[j]);
 
                                                                if (restore && oldbezt) {
-                                                                       VECCOPY(bezt->vec[j], oldbezt->vec[j]);
+                                                                       copy_v3_v3(bezt->vec[j], oldbezt->vec[j]);
                                                                }
 
                                                                fp+= 3;
@@ -905,12 +890,12 @@ static void calc_shapeKeys(Object *obedit)
                                                while(a--) {
                                                        oldbp= getKeyIndexOrig_bp(editnurb, bp);
 
-                                                       VECCOPY(fp, bp->vec);
+                                                       copy_v3_v3(fp, bp->vec);
 
                                                        fp[3]= bp->alfa;
 
                                                        if(restore && oldbp) {
-                                                               VECCOPY(bp->vec, oldbp->vec);
+                                                               copy_v3_v3(bp->vec, oldbp->vec);
                                                                bp->alfa= oldbp->alfa;
                                                        }
 
@@ -932,13 +917,14 @@ static void calc_shapeKeys(Object *obedit)
                                                        while(a--) {
                                                                index= getKeyIndexOrig_keyIndex(editnurb, bezt);
                                                                if (index >= 0) {
+                                                                       int j;
                                                                        curofp= ofp + index;
 
                                                                        for (j= 0; j < 3; ++j, ++i) {
-                                                                               VECCOPY(fp, curofp);
+                                                                               copy_v3_v3(fp, curofp);
 
                                                                                if(apply_offset) {
-                                                                                       VECADD(fp, fp, ofs[i]);
+                                                                                       add_v3_v3(fp, ofs[i]);
                                                                                }
 
                                                                                fp+= 3; curofp+= 3;
@@ -947,14 +933,15 @@ static void calc_shapeKeys(Object *obedit)
 
                                                                        if(apply_offset) {
                                                                                /* apply alfa offsets */
-                                                                               VECADD(fp, fp, ofs[i]);
+                                                                               add_v3_v3(fp, ofs[i]);
                                                                                ++i;
                                                                        }
 
-                                                                       fp+= 3; curofp+= 3;     /* alphas */
+                                                                       fp+= 3; /* alphas */
                                                                } else {
+                                                                       int j;
                                                                        for (j= 0; j < 3; ++j, ++i) {
-                                                                               VECCOPY(fp, bezt->vec[j]);
+                                                                               copy_v3_v3(fp, bezt->vec[j]);
                                                                                fp+= 3;
                                                                        }
                                                                        fp[0]= bezt->alfa;
@@ -972,15 +959,15 @@ static void calc_shapeKeys(Object *obedit)
 
                                                                if (index >= 0) {
                                                                        curofp= ofp + index;
-                                                                       VECCOPY(fp, curofp);
+                                                                       copy_v3_v3(fp, curofp);
                                                                        fp[3]= curofp[3];
 
                                                                        if(apply_offset) {
-                                                                               VECADD(fp, fp, ofs[i]);
+                                                                               add_v3_v3(fp, ofs[i]);
                                                                                fp[3]+=ofs[i+1][0];
                                                                        }
                                                                } else {
-                                                                       VECCOPY(fp, bp->vec);
+                                                                       copy_v3_v3(fp, bp->vec);
                                                                        fp[3]= bp->alfa;
                                                                }
 
@@ -1082,17 +1069,17 @@ static void curve_rename_fcurves(Object *obedit, ListBase *orig_curves)
                        while (a--) {
                                keyIndex= getCVKeyIndex(editnurb, bezt);
                                if(keyIndex) {
-                                       sprintf(rna_path, "splines[%d].bezier_points[%d]", nu_index, pt_index);
-                                       sprintf(orig_rna_path, "splines[%d].bezier_points[%d]", keyIndex->nu_index, keyIndex->pt_index);
+                                       BLI_snprintf(rna_path, sizeof(rna_path), "splines[%d].bezier_points[%d]", nu_index, pt_index);
+                                       BLI_snprintf(orig_rna_path, sizeof(orig_rna_path), "splines[%d].bezier_points[%d]", keyIndex->nu_index, keyIndex->pt_index);
 
                                        if(keyIndex->switched) {
                                                char handle_path[64], orig_handle_path[64];
-                                               sprintf(orig_handle_path, "%s.handle_left", orig_rna_path);
-                                               sprintf(handle_path, "%s.handle_right", rna_path);
+                                               BLI_snprintf(orig_handle_path, sizeof(orig_rna_path), "%s.handle_left", orig_rna_path);
+                                               BLI_snprintf(handle_path, sizeof(rna_path), "%s.handle_right", rna_path);
                                                fcurve_path_rename(ad, orig_handle_path, handle_path, orig_curves, &curves);
 
-                                               sprintf(orig_handle_path, "%s.handle_right", orig_rna_path);
-                                               sprintf(handle_path, "%s.handle_left", rna_path);
+                                               BLI_snprintf(orig_handle_path, sizeof(orig_rna_path), "%s.handle_right", orig_rna_path);
+                                               BLI_snprintf(handle_path, sizeof(rna_path), "%s.handle_left", rna_path);
                                                fcurve_path_rename(ad, orig_handle_path, handle_path, orig_curves, &curves);
                                        }
 
@@ -1113,8 +1100,8 @@ static void curve_rename_fcurves(Object *obedit, ListBase *orig_curves)
                        while (a--) {
                                keyIndex= getCVKeyIndex(editnurb, bp);
                                if(keyIndex) {
-                                       sprintf(rna_path, "splines[%d].points[%d]", nu_index, pt_index);
-                                       sprintf(orig_rna_path, "splines[%d].points[%d]", keyIndex->nu_index, keyIndex->pt_index);
+                                       BLI_snprintf(rna_path, sizeof(rna_path), "splines[%d].points[%d]", nu_index, pt_index);
+                                       BLI_snprintf(orig_rna_path, sizeof(orig_rna_path), "splines[%d].points[%d]", keyIndex->nu_index, keyIndex->pt_index);
                                        fcurve_path_rename(ad, orig_rna_path, rna_path, orig_curves, &curves);
 
                                        keyIndex->nu_index= nu_index;
@@ -1153,8 +1140,8 @@ static void curve_rename_fcurves(Object *obedit, ListBase *orig_curves)
                }
 
                if(keyIndex) {
-                       sprintf(rna_path, "splines[%d]", nu_index);
-                       sprintf(orig_rna_path, "splines[%d]", keyIndex->nu_index);
+                       BLI_snprintf(rna_path, sizeof(rna_path), "splines[%d]", nu_index);
+                       BLI_snprintf(orig_rna_path, sizeof(orig_rna_path), "splines[%d]", keyIndex->nu_index);
                        fcurve_path_rename(ad, orig_rna_path, rna_path, orig_curves, &curves);
                }
 
@@ -1195,7 +1182,7 @@ int ED_curve_updateAnimPaths(Object *obedit)
 /* load editNurb in object */
 void load_editNurb(Object *obedit)
 {
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
 
        if(obedit==NULL) return;
 
@@ -1234,7 +1221,6 @@ void make_editNurb(Object *obedit)
        Nurb *nu, *newnu, *nu_act= NULL;
        KeyBlock *actkey;
 
-       if(obedit==NULL) return;
 
        set_actNurb(obedit, NULL);
 
@@ -1249,7 +1235,7 @@ void make_editNurb(Object *obedit)
 
                if(editnurb) {
                        freeNurblist(&editnurb->nurbs);
-                       free_editNurb_keyIndex(editnurb);
+                       free_curve_editNurb_keyIndex(editnurb);
                        editnurb->keyindex= NULL;
                } else {
                        editnurb= MEM_callocN(sizeof(EditNurb), "editnurb");
@@ -1281,16 +1267,6 @@ void make_editNurb(Object *obedit)
        }
 }
 
-void free_curve_editNurb (Curve *cu)
-{
-       if(cu->editnurb) {
-               freeNurblist(&cu->editnurb->nurbs);
-               free_editNurb_keyIndex(cu->editnurb);
-               MEM_freeN(cu->editnurb);
-               cu->editnurb= NULL;
-       }
-}
-
 void free_editNurb(Object *obedit)
 {
        Curve *cu= obedit->data;
@@ -1300,7 +1276,7 @@ void free_editNurb(Object *obedit)
 
 void CU_deselect_all(Object *obedit)
 {
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
 
        if (editnurb) {
                selectend_nurb(obedit, FIRST, 0, DESELECT); /* set first control points as unselected */
@@ -1310,7 +1286,7 @@ void CU_deselect_all(Object *obedit)
 
 void CU_select_all(Object *obedit)
 {
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
 
        if (editnurb) {
                selectend_nurb(obedit, FIRST, 0, SELECT); /* set first control points as unselected */
@@ -1320,7 +1296,7 @@ void CU_select_all(Object *obedit)
 
 void CU_select_swap(Object *obedit)
 {
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
 
        if (editnurb) {
                Curve *cu= obedit->data;
@@ -1376,7 +1352,7 @@ static int separate_exec(bContext *C, wmOperator *op)
        oldedit= oldcu->editnurb;
 
        if(oldcu->key) {
-               BKE_report(op->reports, RPT_ERROR, "Can't separate a curve with vertex keys.");
+               BKE_report(op->reports, RPT_ERROR, "Can't separate a curve with vertex keys");
                return OPERATOR_CANCELLED;
        }
 
@@ -1395,7 +1371,7 @@ static int separate_exec(bContext *C, wmOperator *op)
        make_editNurb(newob);
        newedit= newcu->editnurb;
        freeNurblist(&newedit->nurbs);
-       free_editNurb_keyIndex(newedit);
+       free_curve_editNurb_keyIndex(newedit);
 
        /* 3. move over parts from old object */
        for(nu= oldedit->nurbs.first; nu; nu=nu1) {
@@ -1586,12 +1562,12 @@ static int deleteflagNurb(bContext *C, wmOperator *UNUSED(op), int flag)
 {
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu, *next;
        BPoint *bp, *bpn, *newbp;
        int a, b, newu, newv, sel;
 
-       if(obedit && obedit->type==OB_SURF);
+       if(obedit->type==OB_SURF);
        else return OPERATOR_CANCELLED;
 
        cu->lastsel= NULL;
@@ -1833,7 +1809,7 @@ static short extrudeflagNurb(EditNurb *editnurb, int flag)
 
 static void adduplicateflagNurb(Object *obedit, short flag)
 {
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu, *newnu;
        BezTriple *bezt, *bezt1;
        BPoint *bp, *bp1;
@@ -2049,7 +2025,7 @@ void CURVE_OT_switch_direction(wmOperatorType *ot)
 static int set_goal_weight_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BezTriple *bezt;
        BPoint *bp;
@@ -2101,7 +2077,7 @@ void CURVE_OT_spline_weight_set(wmOperatorType *ot)
 static int set_radius_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BezTriple *bezt;
        BPoint *bp;
@@ -2153,7 +2129,7 @@ void CURVE_OT_radius_set(wmOperatorType *ot)
 static int smooth_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BezTriple *bezt, *beztOrig;
        BPoint *bp, *bpOrig;
@@ -2226,7 +2202,7 @@ void CURVE_OT_smooth(wmOperatorType *ot)
 static int smooth_radius_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BezTriple *bezt;
        BPoint *bp;
@@ -2398,7 +2374,7 @@ static void select_adjacent_cp(ListBase *editnurb, short next, short cont, short
        BezTriple *bezt;
        BPoint *bp;
        int a;
-       short lastsel= 0, sel=0;
+       short lastsel= 0;
        
        if(next==0) return;
        
@@ -2410,13 +2386,12 @@ static void select_adjacent_cp(ListBase *editnurb, short next, short cont, short
                        if(next < 0) bezt= (nu->bezt + (a-1));
                        while(a--) {
                                if(a-abs(next) < 0) break;
-                               sel= 0;
                                if((lastsel==0) && (bezt->hide==0) && ((bezt->f2 & SELECT) || (selstatus==0))) {
                                        bezt+=next;
                                        if(!(bezt->f2 & SELECT) || (selstatus==0)) {
-                                               sel= select_beztriple(bezt, selstatus, 1, VISIBLE);     
+                                               short sel= select_beztriple(bezt, selstatus, 1, VISIBLE);
                                                if((sel==1) && (cont==0)) lastsel= 1;
-                                       }                                                       
+                                       }
                                }
                                else {
                                        bezt+=next;
@@ -2432,11 +2407,10 @@ static void select_adjacent_cp(ListBase *editnurb, short next, short cont, short
                        if(next < 0) bp= (nu->bp + (a-1));
                        while(a--) {
                                if(a-abs(next) < 0) break;
-                               sel=0;
                                if((lastsel==0) && (bp->hide==0) && ((bp->f1 & SELECT) || (selstatus==0))) {
                                        bp+=next;
                                        if(!(bp->f1 & SELECT) || (selstatus==0)) {
-                                               sel= select_bpoint(bp, selstatus, 1, VISIBLE);
+                                               short sel= select_bpoint(bp, selstatus, 1, VISIBLE);
                                                if((sel==1) && (cont==0)) lastsel= 1;
                                        }                       
                                }
@@ -2459,13 +2433,12 @@ static void select_adjacent_cp(ListBase *editnurb, short next, short cont, short
 /* selstatus: selection status in case doswap is false                             */
 void selectend_nurb(Object *obedit, short selfirst, short doswap, short selstatus)
 {
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BPoint *bp;
        BezTriple *bezt;
        Curve *cu;
        int a;
-       short sel;
 
        if(obedit==NULL) return;
 
@@ -2473,7 +2446,6 @@ void selectend_nurb(Object *obedit, short selfirst, short doswap, short selstatu
        cu->lastsel= NULL;
 
        for(nu= editnurb->first; nu; nu= nu->next) {
-               sel= 0;
                if(nu->type == CU_BEZIER) {
                        a= nu->pntsu;
                        
@@ -2486,6 +2458,7 @@ void selectend_nurb(Object *obedit, short selfirst, short doswap, short selstatu
                        }
                        
                        while(a--) {
+                               short sel;
                                if(doswap) sel= swap_selection_beztriple(bezt);
                                else sel= select_beztriple(bezt, selstatus, 1, VISIBLE);
                                
@@ -2505,6 +2478,7 @@ void selectend_nurb(Object *obedit, short selfirst, short doswap, short selstatu
 
                        while(a--) {
                                if (bp->hide == 0) {
+                                       short sel;
                                        if(doswap) sel= swap_selection_bpoint(bp);
                                        else sel= select_bpoint(bp, selstatus, 1, VISIBLE);
                                        
@@ -2601,7 +2575,7 @@ static short nurb_has_selected_cps(ListBase *editnurb)
 static int de_select_all_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        int action = RNA_enum_get(op->ptr, "action");
 
        if (action == SEL_TOGGLE) {
@@ -2650,7 +2624,7 @@ static int hide_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BPoint *bp;
        BezTriple *bezt;
@@ -2715,7 +2689,7 @@ void CURVE_OT_hide(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
-       RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected.");
+       RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected");
 }
 
 /********************** reveal operator *********************/
@@ -2723,7 +2697,7 @@ void CURVE_OT_hide(wmOperatorType *ot)
 static int reveal_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BPoint *bp;
        BezTriple *bezt;
@@ -2781,7 +2755,7 @@ static int select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BPoint *bp;
        BezTriple *bezt;
@@ -2838,12 +2812,7 @@ void CURVE_OT_select_inverse(wmOperatorType *ot)
 /** Divide the line segments associated with the currently selected
  * curve nodes (Bezier or NURB). If there are no valid segment
  * selections within the current selection, nothing happens.
- *
- * @deffunc subdividenurb subdivideNurb(void)
- * @return Nothing
- * @param  None
-*/
-
+ */
 static void subdividenurb(Object *obedit, int number_cuts)
 {
        Curve *cu= obedit->data;
@@ -2921,14 +2890,14 @@ static void subdividenurb(Object *obedit, int number_cuts)
                                                        interp_v3_v3v3(vec+12, vec+3, vec+6, factor);
 
                                                        /* change handle of prev beztn */
-                                                       VECCOPY((beztn-1)->vec[2], vec);
+                                                       copy_v3_v3((beztn-1)->vec[2], vec);
                                                        /* new point */
-                                                       VECCOPY(beztn->vec[0], vec+9);
+                                                       copy_v3_v3(beztn->vec[0], vec+9);
                                                        interp_v3_v3v3(beztn->vec[1], vec+9, vec+12, factor);
-                                                       VECCOPY(beztn->vec[2], vec+12);
+                                                       copy_v3_v3(beztn->vec[2], vec+12);
                                                        /* handle of next bezt */
-                                                       if(a==0 && i == number_cuts - 1 && (nu->flagu & CU_NURB_CYCLIC)) {VECCOPY(beztnew->vec[0], vec+6);}
-                                                       else {VECCOPY(bezt->vec[0], vec+6);}
+                                                       if(a==0 && i == number_cuts - 1 && (nu->flagu & CU_NURB_CYCLIC)) {copy_v3_v3(beztnew->vec[0], vec+6);}
+                                                       else {copy_v3_v3(bezt->vec[0], vec+6);}
 
                                                        beztn->radius = (prevbezt->radius + bezt->radius)/2;
                                                        beztn->weight = (prevbezt->weight + bezt->weight)/2;
@@ -3310,7 +3279,7 @@ static void findnearestNurbvert__doClosest(void *userData, Nurb *nu, BPoint *bp,
        }
 }
 
-static short findnearestNurbvert(ViewContext *vc, short sel, int mval[2], Nurb **nurb, BezTriple **bezt, BPoint **bp)
+static short findnearestNurbvert(ViewContext *vc, short sel, const int mval[2], Nurb **nurb, BezTriple **bezt, BPoint **bp)
 {
                /* sel==1: selected gets a disadvantage */
                /* in nurb and bezt or bp the nearest is written */
@@ -3412,7 +3381,7 @@ static int convertspline(short type, Nurb *nu)
                        a= nr;
                        bp= nu->bp;
                        while(a--) {
-                               VECCOPY(bezt->vec[1], bp->vec);
+                               copy_v3_v3(bezt->vec[1], bp->vec);
                                bezt->f1=bezt->f2=bezt->f3= bp->f1;
                                bezt->h1= bezt->h2= HD_VECT;
                                bezt->weight= bp->weight;
@@ -3430,7 +3399,6 @@ static int convertspline(short type, Nurb *nu)
                        nu->type = CU_NURBS;
                        nu->orderu= 4;
                        nu->flagu &= CU_NURB_CYCLIC; /* disable all flags except for cyclic */
-                       nu->flagu |= CU_NURB_BEZIER;
                        nurbs_knot_calc_u(nu);
                        a= nu->pntsu*nu->pntsv;
                        bp= nu->bp;
@@ -3450,7 +3418,7 @@ static int convertspline(short type, Nurb *nu)
                        while(a--) {
                                if(type==CU_POLY && bezt->h1==HD_VECT && bezt->h2==HD_VECT) {
                                        /* vector handle becomes 1 poly vertice */
-                                       VECCOPY(bp->vec, bezt->vec[1]);
+                                       copy_v3_v3(bp->vec, bezt->vec[1]);
                                        bp->vec[3]= 1.0;
                                        bp->f1= bezt->f2;
                                        nr-= 2;
@@ -3460,7 +3428,7 @@ static int convertspline(short type, Nurb *nu)
                                }
                                else {
                                        for(c=0;c<3;c++) {
-                                               VECCOPY(bp->vec, bezt->vec[c]);
+                                               copy_v3_v3(bp->vec, bezt->vec[c]);
                                                bp->vec[3]= 1.0;
                                                if(c==0) bp->f1= bezt->f1;
                                                else if(c==1) bp->f1= bezt->f2;
@@ -3507,13 +3475,13 @@ static int convertspline(short type, Nurb *nu)
                                a= nr;
                                bp= nu->bp;
                                while(a--) {
-                                       VECCOPY(bezt->vec[0], bp->vec);
+                                       copy_v3_v3(bezt->vec[0], bp->vec);
                                        bezt->f1= bp->f1;
                                        bp++;
-                                       VECCOPY(bezt->vec[1], bp->vec);
+                                       copy_v3_v3(bezt->vec[1], bp->vec);
                                        bezt->f2= bp->f1;
                                        bp++;
-                                       VECCOPY(bezt->vec[2], bp->vec);
+                                       copy_v3_v3(bezt->vec[2], bp->vec);
                                        bezt->f3= bp->f1;
                                        bezt->radius= bp->radius;
                                        bezt->weight= bp->weight;
@@ -3533,10 +3501,15 @@ static int convertspline(short type, Nurb *nu)
        return 0;
 }
 
+void ED_nurb_set_spline_type(Nurb *nu, int type)
+{
+       convertspline(type, nu);
+}
+
 static int set_spline_type_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        int changed=0, type= RNA_enum_get(op->ptr, "type");
 
@@ -3600,7 +3573,7 @@ void CURVE_OT_spline_type_set(wmOperatorType *ot)
 static int set_handle_type_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
 
        sethandlesNurb(editnurb, RNA_enum_get(op->ptr, "type"));
 
@@ -3922,7 +3895,7 @@ static void merge_2_nurb(wmOperator *op, ListBase *editnurb, Nurb *nu1, Nurb *nu
 static int merge_nurb(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        NurbSort *nus1, *nus2;
        int ok= 1;
        
@@ -3930,7 +3903,7 @@ static int merge_nurb(bContext *C, wmOperator *op)
        
        if(nsortbase.first == nsortbase.last) {
                BLI_freelistN(&nsortbase);
-               BKE_report(op->reports, RPT_ERROR, "Too few selections to merge.");
+               BKE_report(op->reports, RPT_ERROR, "Too few selections to merge");
                return OPERATOR_CANCELLED;
        }
        
@@ -3978,7 +3951,7 @@ static int make_segment_exec(bContext *C, wmOperator *op)
        /* joins 2 curves */
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
-       ListBase *nubase= curve_get_editcurve(obedit);
+       ListBase *nubase= object_editcurve_get(obedit);
        Nurb *nu, *nu1=NULL, *nu2=NULL;
        BPoint *bp;
        float *fp, offset;
@@ -4170,11 +4143,11 @@ void CURVE_OT_make_segment(wmOperatorType *ot)
 
 /***************** pick select from 3d view **********************/
 
-int mouse_nurb(bContext *C, const short mval[2], int extend)
+int mouse_nurb(bContext *C, const int mval[2], int extend)
 {
        Object *obedit= CTX_data_edit_object(C); 
        Curve *cu= obedit->data;
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        ViewContext vc;
        Nurb *nu;
        BezTriple *bezt=NULL;
@@ -4258,7 +4231,7 @@ int mouse_nurb(bContext *C, const short mval[2], int extend)
 static int spin_nurb(float viewmat[][4], Object *obedit, float *axis, float *cent)
 {
        Curve *cu= (Curve*)obedit->data;
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        float si,phi,n[3],q[4],cmat[3][3],tmat[3][3],imat[3][3];
        float bmat[3][3], rotmat[3][3], scalemat1[3][3], scalemat2[3][3];
@@ -4499,7 +4472,7 @@ static int addvert_Nurb(bContext *C, short mode, float location[3])
                                (BezTriple*)MEM_callocN((nu->pntsu+1) * sizeof(BezTriple), "addvert_Nurb");
                        ED_curve_beztcpy(editnurb, newbezt, nu->bezt, nu->pntsu);
                        *(newbezt+nu->pntsu)= *bezt;
-                       VECCOPY(temp, bezt->vec[1]);
+                       copy_v3_v3(temp, bezt->vec[1]);
                        MEM_freeN(nu->bezt);
                        nu->bezt= newbezt;
                        newbezt+= nu->pntsu;
@@ -4518,7 +4491,7 @@ static int addvert_Nurb(bContext *C, short mode, float location[3])
                        BEZ_SEL(newbezt);
                        cu->lastsel= newbezt;
                        newbezt->h2= newbezt->h1;
-                       VECCOPY(temp, bezt->vec[1]);
+                       copy_v3_v3(temp, bezt->vec[1]);
                        MEM_freeN(nu->bezt);
                        nu->bezt= newbezt;
                        bezt= newbezt+1;
@@ -4530,7 +4503,7 @@ static int addvert_Nurb(bContext *C, short mode, float location[3])
                        *newbezt= *bezt;
                        BEZ_SEL(newbezt);
                        newbezt->h2= newbezt->h1;
-                       VECCOPY(temp, bezt->vec[1]);
+                       copy_v3_v3(temp, bezt->vec[1]);
 
                        newnu= (Nurb*)MEM_mallocN(sizeof(Nurb), "addvert_Nurb newnu");
                        memcpy(newnu, nu, sizeof(Nurb));
@@ -4663,11 +4636,10 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        RegionView3D *rv3d= CTX_wm_region_view3d(C);
 
-       if(rv3d && !RNA_property_is_set(op->ptr, "location")) {
+       if(rv3d && !RNA_struct_property_is_set(op->ptr, "location")) {
                Curve *cu;
                ViewContext vc;
                float location[3];
-               short mval[2];
 
                Nurb *nu;
                BezTriple *bezt;
@@ -4689,10 +4661,7 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        copy_v3_v3(location, give_cursor(vc.scene, vc.v3d));
                }
 
-               mval[0]= event->x - vc.ar->winrct.xmin;
-               mval[1]= event->y - vc.ar->winrct.ymin;
-               
-               view3d_get_view_aligned_coordinate(&vc, location, mval, TRUE);
+               view3d_get_view_aligned_coordinate(&vc, location, event->mval, TRUE);
                RNA_float_set_array(op->ptr, "location", location);
        }
 
@@ -4714,7 +4683,7 @@ void CURVE_OT_vertex_add(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       RNA_def_float_vector_xyz(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Location to add new vertex at.", -1e4, 1e4);
+       RNA_def_float_vector_xyz(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Location to add new vertex at", -1e4, 1e4);
 }
 
 /***************** extrude operator **********************/
@@ -4747,18 +4716,6 @@ static int extrude_exec(bContext *C, wmOperator *UNUSED(op))
        return OPERATOR_FINISHED;
 }
 
-static int extrude_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
-{
-       if(extrude_exec(C, op) == OPERATOR_FINISHED) {
-               RNA_enum_set(op->ptr, "mode", TFM_TRANSLATION);
-               WM_operator_name_call(C, "TRANSFORM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
-
-               return OPERATOR_FINISHED;
-       }
-
-       return OPERATOR_CANCELLED;
-}
-
 void CURVE_OT_extrude(wmOperatorType *ot)
 {
        /* identifiers */
@@ -4768,7 +4725,6 @@ void CURVE_OT_extrude(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= extrude_exec;
-       ot->invoke= extrude_invoke;
        ot->poll= ED_operator_editsurfcurve;
 
        /* flags */
@@ -4784,7 +4740,7 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BezTriple *bezt;
        BPoint *bp;
@@ -4861,7 +4817,7 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
 static int toggle_cyclic_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        uiPopupMenu *pup;
        uiLayout *layout;
        Nurb *nu;
@@ -4904,7 +4860,7 @@ void CURVE_OT_cyclic_toggle(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to make surface cyclic in.");
+       RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to make surface cyclic in");
 }
 
 /***************** select linked operator ******************/
@@ -4988,21 +4944,18 @@ void CURVE_OT_select_linked(wmOperatorType *ot)
 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;
+       int a, deselect;
 
        deselect= RNA_boolean_get(op->ptr, "deselect");
-       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);
+       findnearestNurbvert(&vc, 1, event->mval, &nu, &bezt, &bp);
 
        if(bezt) {
                a= nu->pntsu;
@@ -5042,7 +4995,7 @@ void CURVE_OT_select_linked_pick(wmOperatorType *ot)
        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_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect linked control points rather than selecting them");
 }
 
 /***************** select row operator **********************/
@@ -5051,7 +5004,7 @@ static int select_row_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        static BPoint *last= NULL;
        static int direction=0;
        Nurb *nu;
@@ -5125,7 +5078,7 @@ void CURVE_OT_select_row(wmOperatorType *ot)
 static int select_next_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        
        select_adjacent_cp(editnurb, 1, 0, SELECT);
        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
@@ -5152,7 +5105,7 @@ void CURVE_OT_select_next(wmOperatorType *ot)
 static int select_previous_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        
        select_adjacent_cp(editnurb, -1, 0, SELECT);
        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
@@ -5179,7 +5132,7 @@ void CURVE_OT_select_previous(wmOperatorType *ot)
 static int select_more_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BPoint *bp, *tempbp;
        int a;
@@ -5267,7 +5220,7 @@ void CURVE_OT_select_more(wmOperatorType *ot)
 static int select_less_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BPoint *bp;
        BezTriple *bezt;
@@ -5459,7 +5412,7 @@ static void selectrandom_curve(ListBase *editnurb, float randfac)
 static int select_random_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
 
        if(!RNA_boolean_get(op->ptr, "extend"))
                CU_deselect_all(obedit);
@@ -5485,8 +5438,8 @@ void CURVE_OT_select_random(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of elements to select randomly.", 0.f, 100.0f);
-       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first.");
+       RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of elements to select randomly", 0.f, 100.0f);
+       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first");
 }
 
 /********************* every nth number of point *******************/
@@ -5502,6 +5455,24 @@ static int point_on_nurb(Nurb *nu, void *point)
        }
 }
 
+static Nurb *get_lastsel_nurb(Curve *cu)
+{
+       ListBase *nubase= curve_editnurbs(cu);
+       Nurb *nu= nubase->first;
+
+       if(!cu->lastsel)
+               return NULL;
+
+       while (nu) {
+               if (point_on_nurb(nu, cu->lastsel))
+                       return nu;
+
+               nu= nu->next;
+       }
+
+       return NULL;
+}
+
 static void select_nth_bezt(Nurb *nu, BezTriple *bezt, int nth)
 {
        int a, start;
@@ -5551,21 +5522,11 @@ static void select_nth_bp(Nurb *nu, BPoint *bp, int nth)
 int CU_select_nth(Object *obedit, int nth)
 {
        Curve *cu= (Curve*)obedit->data;
-       ListBase *nubase= ED_curve_editnurbs(cu);
        Nurb *nu;
-       int ok=0;
-
-       /* Search nurb to which selected point belongs to */
-       nu= nubase->first;
-       while (nu) {
-               if (point_on_nurb(nu, cu->lastsel)) {
-                       ok= 1;
-                       break;
-               }
-               nu= nu->next;
-       }
 
-       if (!ok) return 0;
+       nu= get_lastsel_nurb(cu);
+       if (!nu)
+               return 0;
 
        if (nu->bezt) {
                select_nth_bezt(nu, cu->lastsel, nth);
@@ -5625,16 +5586,6 @@ static int duplicate_exec(bContext *C, wmOperator *UNUSED(op))
        return OPERATOR_FINISHED;
 }
 
-static int duplicate_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
-{
-       duplicate_exec(C, op);
-
-       RNA_enum_set(op->ptr, "mode", TFM_TRANSLATION);
-       WM_operator_name_call(C, "TRANSFORM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
-
-       return OPERATOR_FINISHED;
-}
-
 void CURVE_OT_duplicate(wmOperatorType *ot)
 {
        /* identifiers */
@@ -5644,14 +5595,10 @@ void CURVE_OT_duplicate(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= duplicate_exec;
-       ot->invoke= duplicate_invoke;
        ot->poll= ED_operator_editsurfcurve;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
-       /* to give to transform */
-       RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
 }
 
 /********************** delete operator *********************/
@@ -5662,7 +5609,7 @@ static int delete_exec(bContext *C, wmOperator *op)
        Curve *cu= obedit->data;
        EditNurb *editnurb= cu->editnurb;
        ListBase *nubase= &editnurb->nurbs;
-       Nurb *nu, *next, *nu1;
+       Nurb *nu, *nu1;
        BezTriple *bezt, *bezt1, *bezt2;
        BPoint *bp, *bp1, *bp2;
        int a, cut= 0, type= RNA_enum_get(op->ptr, "type");
@@ -5687,6 +5634,7 @@ static int delete_exec(bContext *C, wmOperator *op)
 
        if(type==0) {
                /* first loop, can we remove entire pieces? */
+               Nurb *next;
                nu= nubase->first;
                while(nu) {
                        next= nu->next;
@@ -5803,6 +5751,7 @@ static int delete_exec(bContext *C, wmOperator *op)
                                                clamp_nurb_order_u(nu);
                                        }*/
                                }
+                               clamp_nurb_order_u(nu);
                                nurbs_knot_calc_u(nu);
                        }
                        nu= next;
@@ -5815,7 +5764,6 @@ static int delete_exec(bContext *C, wmOperator *op)
                nu1= NULL;
                nuindex= 0;
                for(nu= nubase->first; nu; nu= nu->next) {
-                       next= nu->next;
                        if(nu->type == CU_BEZIER) {
                                bezt= nu->bezt;
                                for(a=0; a<nu->pntsu-1; a++) {
@@ -5952,7 +5900,14 @@ static int delete_exec(bContext *C, wmOperator *op)
                                        MEM_freeN(nu1->bp);
                                        nu1->bp= bp;
                                        nu1->pntsu= a;
+                                       nu1->knotsu= NULL;
                                        nu->pntsu= cut+1;
+
+                                       clamp_nurb_order_u(nu);
+                                       nurbs_knot_calc_u(nu);
+
+                                       clamp_nurb_order_u(nu1);
+                                       nurbs_knot_calc_u(nu1);
                                }
                        }
                }
@@ -6017,7 +5972,7 @@ void CURVE_OT_delete(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "Which elements to delete.");
+       RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "Which elements to delete");
 }
 
 /********************** shade smooth/flat operator *********************/
@@ -6025,7 +5980,7 @@ void CURVE_OT_delete(wmOperatorType *ot)
 static int shade_smooth_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        int clear= (strcmp(op->idname, "CURVE_OT_shade_flat") == 0);
        
@@ -6101,7 +6056,7 @@ int join_curve_exec(bContext *C, wmOperator *UNUSED(op))
                        
                                if(cu->nurb.first) {
                                        /* watch it: switch order here really goes wrong */
-                                       mul_m4_m4m4(cmat, base->object->obmat, imat);
+                                       mult_m4_m4m4(cmat, imat, base->object->obmat);
                                        
                                        nu= cu->nurb.first;
                                        while(nu) {
@@ -6119,6 +6074,7 @@ int join_curve_exec(bContext *C, wmOperator *UNUSED(op))
                                                                mul_m4_v3(cmat, bezt->vec[2]);
                                                                bezt++;
                                                        }
+                                                       calchandlesNurb(newnu);
                                                }
                                                if( (bp= newnu->bp) ) {
                                                        a= newnu->pntsu*nu->pntsv;
@@ -6196,7 +6152,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob)
 {
        static int xzproj= 0;   /* this function calls itself... */
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        View3D *v3d= CTX_wm_view3d(C);
        RegionView3D *rv3d= ED_view3d_context_rv3d(C);
        Nurb *nu = NULL;
@@ -6214,7 +6170,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob)
 
        if(rv3d) {
                copy_m4_m4(viewmat, rv3d->viewmat);
-               VECCOPY(zvec, rv3d->viewinv[2]);
+               copy_v3_v3(zvec, rv3d->viewinv[2]);
        }
 
        setflagsNurb(editnurb, 0);
@@ -6543,17 +6499,20 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob)
                BLI_assert(!"invalid nurbs type");
                return NULL;
        }
-       
-       /* always do: */
-       nu->flag |= CU_SMOOTH;
-       
-       test2DNurb(nu);
-       
+
+       BLI_assert(nu != NULL);
+
+       if(nu) { /* should always be set */
+               nu->flag |= CU_SMOOTH;
+
+               test2DNurb(nu);
+       }
+
        return nu;
 }
 
-static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf) {
-       
+static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
+{
        Object *obedit= CTX_data_edit_object(C);
        ListBase *editnurb;
        Nurb *nu;
@@ -6609,7 +6568,7 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
        ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
 
        nu= add_nurbs_primitive(C, mat, type, newob);
-       editnurb= curve_get_editcurve(obedit);
+       editnurb= object_editcurve_get(obedit);
        BLI_addtail(editnurb, nu);
 
        /* userdef */
@@ -6622,11 +6581,13 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
        return OPERATOR_FINISHED;
 }
 
-static int curve_prim_add(bContext *C, wmOperator *op, int type) {
+static int curve_prim_add(bContext *C, wmOperator *op, int type)
+{
        return curvesurf_prim_add(C, op, type, 0);
 }
 
-static int surf_prim_add(bContext *C, wmOperator *op, int type) {
+static int surf_prim_add(bContext *C, wmOperator *op, int type)
+{
        return curvesurf_prim_add(C, op, type, 1);
 }
 
@@ -6892,7 +6853,7 @@ static int clear_tilt_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        Curve *cu= obedit->data;
-       ListBase *editnurb= curve_get_editcurve(obedit);
+       ListBase *editnurb= object_editcurve_get(obedit);
        Nurb *nu;
        BezTriple *bezt;
        BPoint *bp;
@@ -6962,7 +6923,7 @@ static void undoCurve_to_editCurve(void *ucu, void *obe)
        Curve *cu= (Curve*)obedit->data;
        UndoCurve *undoCurve= ucu;
        ListBase *undobase= &undoCurve->nubase;
-       ListBase *editbase= ED_curve_editnurbs(cu);
+       ListBase *editbase= curve_editnurbs(cu);
        Nurb *nu, *newnu;
        EditNurb *editnurb= cu->editnurb;
        void *lastsel= NULL;
@@ -6971,7 +6932,7 @@ static void undoCurve_to_editCurve(void *ucu, void *obe)
        freeNurblist(editbase);
 
        if (undoCurve->undoIndex) {
-               BLI_ghash_free(editnurb->keyindex, NULL, (GHashValFreeFP)free_cvKeyIndex);
+               BLI_ghash_free(editnurb->keyindex, NULL, (GHashValFreeFP)MEM_freeN);
                editnurb->keyindex= dupli_keyIndexHash(undoCurve->undoIndex);
        }
 
@@ -7010,7 +6971,7 @@ static void *editCurve_to_undoCurve(void *obe)
 {
        Object *obedit= obe;
        Curve *cu= (Curve*)obedit->data;
-       ListBase *nubase= ED_curve_editnurbs(cu);
+       ListBase *nubase= curve_editnurbs(cu);
        UndoCurve *undoCurve;
        EditNurb *editnurb= cu->editnurb, tmpEditnurb;
        Nurb *nu, *newnu;
@@ -7059,7 +7020,7 @@ static void free_undoCurve(void *ucv)
        freeNurblist(&undoCurve->nubase);
 
        if(undoCurve->undoIndex)
-               BLI_ghash_free(undoCurve->undoIndex, NULL, (GHashValFreeFP)free_cvKeyIndex);
+               BLI_ghash_free(undoCurve->undoIndex, NULL, (GHashValFreeFP)MEM_freeN);
 
        free_fcurves(&undoCurve->fcurves);
        free_fcurves(&undoCurve->drivers);
@@ -7079,15 +7040,6 @@ void undo_push_curve(bContext *C, const char *name)
        undo_editmode_push(C, name, get_data, free_undoCurve, undoCurve_to_editCurve, editCurve_to_undoCurve, NULL);
 }
 
-/* Get list of nurbs from editnurbs structure */
-ListBase *ED_curve_editnurbs(Curve *cu)
-{
-       if (cu->editnurb) {
-               return &cu->editnurb->nurbs;
-       }
-
-       return NULL;
-}
 void ED_curve_beztcpy(EditNurb *editnurb, BezTriple *dst, BezTriple *src, int count)
 {
        memcpy(dst, src, count*sizeof(BezTriple));
@@ -7099,3 +7051,24 @@ void ED_curve_bpcpy(EditNurb *editnurb, BPoint *dst, BPoint *src, int count)
        memcpy(dst, src, count*sizeof(BPoint));
        keyIndex_updateBP(editnurb, src, dst, count);
 }
+
+int ED_curve_actSelection(Curve *cu, float center[3])
+{
+       Nurb *nu= get_lastsel_nurb(cu);
+
+       if(!nu)
+               return 0;
+
+       if(nu->bezt) {
+               BezTriple *bezt= cu->lastsel;
+
+               copy_v3_v3(center, bezt->vec[1]);
+       }
+       else {
+               BPoint *bp= cu->lastsel;
+
+               copy_v3_v3(center, bp->vec);
+       }
+
+       return 1;
+}