rename RNA_property_is_set() --> RNA_struct_property_is_set() in preperation to add...
[blender.git] / source / blender / editors / curve / editcurve.c
index 0a05086a3a45f8088669f282f7e8f0662bf2ee9a..aea6f5c43b6e0630d3c49ece88eea32bb7cd821f 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -690,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)
@@ -818,7 +816,7 @@ static void calc_shapeKeys(Object *obedit)
                                                        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;
@@ -834,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;
@@ -868,10 +866,10 @@ static void calc_shapeKeys(Object *obedit)
                                                        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;
@@ -892,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;
                                                        }
 
@@ -923,10 +921,10 @@ static void calc_shapeKeys(Object *obedit)
                                                                        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;
@@ -935,7 +933,7 @@ static void calc_shapeKeys(Object *obedit)
 
                                                                        if(apply_offset) {
                                                                                /* apply alfa offsets */
-                                                                               VECADD(fp, fp, ofs[i]);
+                                                                               add_v3_v3(fp, ofs[i]);
                                                                                ++i;
                                                                        }
 
@@ -943,7 +941,7 @@ static void calc_shapeKeys(Object *obedit)
                                                                } 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;
@@ -961,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;
                                                                }
 
@@ -1071,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);
                                        }
 
@@ -1102,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;
@@ -1142,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);
                }
 
@@ -2814,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;
@@ -2897,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;
@@ -3388,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;
@@ -3425,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;
@@ -3435,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;
@@ -3482,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;
@@ -4479,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;
@@ -4498,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;
@@ -4510,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));
@@ -4643,7 +4636,7 @@ 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];
@@ -4723,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 */
@@ -4744,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 */
@@ -5475,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;
@@ -5524,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= 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);
@@ -5598,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 */
@@ -5617,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 *********************/
@@ -6082,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) {
@@ -6196,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);
@@ -7077,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;
+}