merge with trunk at r31523
[blender.git] / source / blender / editors / space_view3d / view3d_snap.c
index 328f78d4f279ec2382d86f20541b917a7ac849cd..48e38c6c419aa54d0ef3537c25225525ae83b203 100644 (file)
 #include "DNA_scene_types.h"
 #include "DNA_space_types.h"
 #include "DNA_view3d_types.h"
+#include "DNA_object_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_editVert.h"
 #include "BLI_linklist.h"
 
-#include "BKE_action.h"
-#include "BKE_anim.h"
-#include "BKE_context.h"
 #include "BKE_armature.h"
+#include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_displist.h"
-#include "BKE_global.h"
 #include "BKE_lattice.h"
-#include "BKE_mesh.h"
-#include "BKE_modifier.h"
+#include "BKE_main.h"
 #include "BKE_object.h"
-#include "BKE_utildefines.h"
 #include "BKE_tessmesh.h"
 
 #include "WM_api.h"
@@ -81,6 +75,7 @@
 #include "ED_mesh.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
+#include "ED_curve.h" /* for ED_curve_editnurbs */
 
 #include "view3d_intern.h"
 
@@ -115,8 +110,9 @@ static void special_transvert_update(Scene *scene, Object *obedit)
                }
                else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
                        Curve *cu= obedit->data;
-                       Nurb *nu= cu->editnurb->first;
-                       
+                       ListBase *nurbs= ED_curve_editnurbs(cu);
+                       Nurb *nu= nurbs->first;
+
                        while(nu) {
                                test2DNurb(nu);
                                testhandlesNurb(nu); /* test for bezier too */
@@ -164,8 +160,8 @@ static void special_transvert_update(Scene *scene, Object *obedit)
                else if(obedit->type==OB_LATTICE) {
                        Lattice *lt= obedit->data;
                        
-                       if(lt->editlatt->flag & LT_OUTSIDE) 
-                               outside_lattice(lt->editlatt);
+                       if(lt->editlatt->latt->flag & LT_OUTSIDE)
+                               outside_lattice(lt->editlatt->latt);
                }
        }
 }
@@ -321,8 +317,9 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode)
        else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
                Curve *cu= obedit->data;
                int totmalloc= 0;
-               
-               for(nu= cu->editnurb->first; nu; nu= nu->next) {
+               ListBase *nurbs= ED_curve_editnurbs(cu);
+
+               for(nu= nurbs->first; nu; nu= nu->next) {
                        if((nu->type & 7)==CU_BEZIER)
                                totmalloc += 3*nu->pntsu;
                        else
@@ -330,7 +327,7 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode)
                }
                tv=transvmain= MEM_callocN(totmalloc*sizeof(TransVert), "maketransverts curve");
 
-               nu= cu->editnurb->first;
+               nu= nurbs->first;
                while(nu) {
                        if((nu->type & 7)==CU_BEZIER) {
                                a= nu->pntsu;
@@ -395,7 +392,7 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode)
                while(ml) {
                        if(ml->flag & SELECT) {
                                tv->loc= &ml->x;
-                               VECCOPY(tv->oldloc, tv->loc);
+                               copy_v3_v3(tv->oldloc, tv->loc);
                                tv->val= &(ml->rad);
                                tv->oldval= ml->rad;
                                tv->flag= 1;
@@ -408,16 +405,16 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode)
        else if(obedit->type==OB_LATTICE) {
                Lattice *lt= obedit->data;
                
-               bp= lt->editlatt->def;
+               bp= lt->editlatt->latt->def;
                
-               a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
+               a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
                
                tv=transvmain= MEM_callocN(a*sizeof(TransVert), "maketransverts curve");
                
                while(a--) {
                        if((mode & 1) || (bp->f1 & SELECT)) {
                                if(bp->hide==0) {
-                                       VECCOPY(tv->oldloc, bp->vec);
+                                       copy_v3_v3(tv->oldloc, bp->vec);
                                        tv->loc= bp->vec;
                                        tv->flag= bp->f1 & SELECT;
                                        tv++;
@@ -433,23 +430,16 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode)
        total= 0.0;
        for(a=0; a<tottrans; a++, tv++) {
                if(tv->flag & SELECT) {
-                       centroid[0]+= tv->oldloc[0];
-                       centroid[1]+= tv->oldloc[1];
-                       centroid[2]+= tv->oldloc[2];
+                       add_v3_v3(centroid, tv->oldloc);
                        total+= 1.0;
                        DO_MINMAX(tv->oldloc, min, max);
                }
        }
        if(total!=0.0) {
-               centroid[0]/= total;
-               centroid[1]/= total;
-               centroid[2]/= total;
+               mul_v3_fl(centroid, 1.0f/total);
        }
 
-       center[0]= (min[0]+max[0])/2.0;
-       center[1]= (min[1]+max[1])/2.0;
-       center[2]= (min[2]+max[2])/2.0;
-       
+       mid_v3_v3v3(center, min, max);
 }
 
 /* *********************** operators ******************** */
@@ -457,6 +447,7 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode)
 static int snap_sel_to_grid(bContext *C, wmOperator *op)
 {
        extern float originmat[3][3];   /* XXX object.c */
+       Main *bmain= CTX_data_main(C);
        Object *obedit= CTX_data_edit_object(C);
        Scene *scene= CTX_data_scene(C);
        RegionView3D *rv3d= CTX_wm_region_data(C);
@@ -563,7 +554,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op)
                CTX_DATA_END;
        }
 
-       DAG_ids_flush_update(0);
+       DAG_ids_flush_update(bmain, 0);
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
        
        return OPERATOR_FINISHED;
@@ -589,6 +580,7 @@ void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot)
 static int snap_sel_to_curs(bContext *C, wmOperator *op)
 {
        extern float originmat[3][3];   /* XXX object.c */
+       Main *bmain= CTX_data_main(C);
        Object *obedit= CTX_data_edit_object(C);
        Scene *scene= CTX_data_scene(C);
        View3D *v3d= CTX_wm_view3d(C);
@@ -687,7 +679,7 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op)
                CTX_DATA_END;
        }
 
-       DAG_ids_flush_update(0);
+       DAG_ids_flush_update(bmain, 0);
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
        
        return OPERATOR_FINISHED;
@@ -1075,7 +1067,7 @@ static int snap_selected_to_center(bContext *C, wmOperator *op)
                CTX_DATA_END;
        }
        
-       DAG_ids_flush_update(0);
+       DAG_ids_flush_update(CTX_data_main(C), 0);
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
        
        return OPERATOR_FINISHED;