editmesh accessor functions. most editmesh access now goes through:
[blender.git] / source / blender / editors / mesh / editmesh_mods.c
index 74defeea9f160f7a7774260a4631002ba24f9602..0f8a15fd2003725c455728d05bca33fd057cff6a 100644 (file)
@@ -801,7 +801,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        Mesh *me= obedit->data;
-       EditMesh *em= me->edit_mesh
+       EditMesh *em= EM_GetEditMesh(me)
 
        int selcount = similar_face_select__internal(scene, em, RNA_int_get(op->ptr, "type"));
        
@@ -809,9 +809,11 @@ static int similar_face_select_exec(bContext *C, wmOperator *op)
                /* here was an edge-mode only select flush case, has to be generalized */
                EM_selectmode_flush(em);
                WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+               EM_EndEditMesh(me, em);
                return OPERATOR_FINISHED;
        }
        
+       EM_EndEditMesh(me, em);
        return OPERATOR_CANCELLED;
 }      
 
@@ -1060,7 +1062,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        Mesh *me= obedit->data;
-       EditMesh *em= me->edit_mesh
+       EditMesh *em= EM_GetEditMesh(me)
 
        int selcount = similar_edge_select__internal(scene, em, RNA_int_get(op->ptr, "type"));
        
@@ -1068,9 +1070,11 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op)
                /* here was an edge-mode only select flush case, has to be generalized */
                EM_selectmode_flush(em);
                WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+               EM_EndEditMesh(me, em);
                return OPERATOR_FINISHED;
        }
        
+       EM_EndEditMesh(me, em);
        return OPERATOR_CANCELLED;
 }
 
@@ -1113,7 +1117,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        Mesh *me= obedit->data;
-       EditMesh *em= me->edit_mesh
+       EditMesh *em= EM_GetEditMesh(me)
        EditVert *eve, *base_eve=NULL;
        unsigned int selcount=0; /* count how many new edges we select*/
        
@@ -1139,8 +1143,10 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
                
        }
        
-       if (!ok || !deselcount) /* no data selected OR no more data to select*/
+       if (!ok || !deselcount) { /* no data selected OR no more data to select*/
+               EM_EndEditMesh(me, em);
                return 0;
+       }
        
        if(RNA_enum_is_equal(op->ptr, "type", "FACE")) {
                /* store face users */
@@ -1168,8 +1174,10 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
                                                        eve->f |= SELECT;
                                                        selcount++;
                                                        deselcount--;
-                                                       if (!deselcount) /*have we selected all posible faces?, if so return*/
+                                                       if (!deselcount) {/*have we selected all posible faces?, if so return*/
+                                                               EM_EndEditMesh(me, em);
                                                                return selcount;
+                                                       }
                                                }
                                        }
                                }
@@ -1184,8 +1192,10 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
                                                eve->f |= SELECT;
                                                selcount++;
                                                deselcount--;
-                                               if (!deselcount) /*have we selected all posible faces?, if so return*/
+                                               if (!deselcount) {/*have we selected all posible faces?, if so return*/
+                                                       EM_EndEditMesh(me, em);
                                                        return selcount;
+                                               }
                                        }
                                }
                        } 
@@ -1196,8 +1206,10 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
                                base_dvert= CustomData_em_get(&em->vdata, base_eve->data,
                                        CD_MDEFORMVERT);
 
-                               if (!base_dvert || base_dvert->totweight == 0)
+                               if (!base_dvert || base_dvert->totweight == 0) {
+                                       EM_EndEditMesh(me, em);
                                        return selcount;
+                               }
                                
                                for(eve= em->verts.first; eve; eve= eve->next) {
                                        dvert= CustomData_em_get(&em->vdata, eve->data,
@@ -1212,8 +1224,10 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
                                                                        eve->f |= SELECT;
                                                                        selcount++;
                                                                        deselcount--;
-                                                                       if (!deselcount) /*have we selected all posible faces?, if so return*/
+                                                                       if (!deselcount) { /*have we selected all posible faces?, if so return*/
+                                                                               EM_EndEditMesh(me, em);
                                                                                return selcount;
+                                                                       }
                                                                        break;
                                                                }
                                                        }
@@ -1226,8 +1240,11 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
 
        if(selcount) {
                WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+               EM_EndEditMesh(me, em);
                return OPERATOR_FINISHED;
        }
+
+       EM_EndEditMesh(me, em);
        return OPERATOR_CANCELLED;
 }
 
@@ -1915,7 +1932,7 @@ static void edgering_select(EditMesh *em, EditEdge *startedge, int select)
 static int loop_multiselect(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        EditEdge *eed;
        EditEdge **edarray;
        int edindex, edfirstcount;
@@ -1953,6 +1970,8 @@ static int loop_multiselect(bContext *C, wmOperator *op)
 //     if (EM_texFaceCheck())
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -2490,7 +2509,7 @@ void selectconnected_mesh_all(EditMesh *em)
 static int select_linked_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(obedit->data);
        
        if( RNA_boolean_get(op->ptr, "limit") ) {
                ViewContext vc;
@@ -2501,6 +2520,8 @@ static int select_linked_exec(bContext *C, wmOperator *op)
                selectconnected_mesh_all(em);
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -2629,11 +2650,13 @@ void EM_hide_mesh(EditMesh *em, int swap)
 static int hide_mesh_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        EM_hide_mesh(em, RNA_boolean_get(op->ptr, "unselected"));
                
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -2693,11 +2716,13 @@ void EM_reveal_mesh(EditMesh *em)
 static int reveal_mesh_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        EM_reveal_mesh(em);
 
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -2751,7 +2776,7 @@ static int select_sharp_edges_exec(bContext *C, wmOperator *op)
        * small enough, select the edge
        */
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        EditEdge *eed;
        EditFace *efa;
        EditFace **efa1;
@@ -2763,6 +2788,7 @@ static int select_sharp_edges_exec(bContext *C, wmOperator *op)
        
        if(em->selectmode==SCE_SELECT_FACE) {
                BKE_report(op->reports, RPT_ERROR, "Doesn't work in face selection mode");
+               EM_EndEditMesh(obedit->data, em);
                return OPERATOR_CANCELLED;
        }
 
@@ -2841,6 +2867,8 @@ static int select_sharp_edges_exec(bContext *C, wmOperator *op)
 //     if (EM_texFaceCheck())
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); //TODO is this needed ?
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -3001,11 +3029,13 @@ static void select_linked_flat_faces(EditMesh *em, wmOperator *op, float sharpne
 static int select_linked_flat_faces_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        select_linked_flat_faces(em, op, RNA_float_get(op->ptr, "sharpness"));
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -3099,11 +3129,13 @@ void select_non_manifold(EditMesh *em, wmOperator *op )
 static int select_non_manifold_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        select_non_manifold(em, op);
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -3160,11 +3192,13 @@ void EM_select_swap(EditMesh *em) /* exported for UV */
 static int select_invert_mesh_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        EM_select_swap(em);
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -3195,11 +3229,12 @@ void EM_toggle_select_all(EditMesh *em) /* exported for UV */
 static int toggle_select_all_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        EM_toggle_select_all(em);
        
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);     
+       EM_EndEditMesh(obedit->data, em);
 
        return OPERATOR_FINISHED;
 }
@@ -3262,13 +3297,15 @@ void EM_select_more(EditMesh *em)
 static int select_more(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data)) ;
 
        EM_select_more(em);
 
 //     if (EM_texFaceCheck(em))
 
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }
 
@@ -3350,12 +3387,14 @@ void EM_select_less(EditMesh *em)
 static int select_less(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
 
        EM_select_less(em);
 
 //     if (EM_texFaceCheck(em))
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }
 
@@ -3418,12 +3457,13 @@ static void selectrandom_mesh(EditMesh *em, float perc) /* randomly selects a us
 static int mesh_select_random_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        selectrandom_mesh(em, RNA_float_get(op->ptr,"percent"));
                
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -3507,12 +3547,13 @@ static int mesh_selection_type_exec(bContext *C, wmOperator *op)
 {              
        
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
 
        mesh_selection_type(CTX_data_scene(C), em, RNA_enum_get(op->ptr,"type"));
 
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
+       
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }
 
@@ -3540,7 +3581,7 @@ void MESH_OT_selection_type(wmOperatorType *ot)
 static int editmesh_mark_seam(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        Mesh *me= ((Mesh *)obedit->data);
        EditEdge *eed;
        int clear = RNA_boolean_get(op->ptr, "clear");
@@ -3571,6 +3612,7 @@ static int editmesh_mark_seam(bContext *C, wmOperator *op)
 
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
 
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }
 
@@ -3593,7 +3635,7 @@ void MESH_OT_mark_seam(wmOperatorType *ot)
 static int editmesh_mark_sharp(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        Mesh *me= ((Mesh *)obedit->data);
        int set = RNA_boolean_get(op->ptr, "set");
        EditEdge *eed;
@@ -3619,6 +3661,7 @@ static int editmesh_mark_sharp(bContext *C, wmOperator *op)
 
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
 
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }
 
@@ -4013,7 +4056,7 @@ void righthandfaces(EditMesh *em, int select)     /* makes faces righthand turning *
 static int righthandfaces_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        /* 'standard' behaviour - check if selected, then apply relevant selection */
        
@@ -4021,6 +4064,8 @@ static int righthandfaces_exec(bContext *C, wmOperator *op)
        righthandfaces(em, RNA_boolean_get(op->ptr, "inside"));
        
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); //TODO is this needed ?
+
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -4221,7 +4266,7 @@ static int smooth_vertex(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        Mesh *me= obedit->data;
-       EditMesh *em= me->edit_mesh
+       EditMesh *em= me; 
 
        EditVert *eve, *eve_mir = NULL;
        EditEdge *eed;
@@ -4230,7 +4275,10 @@ static int smooth_vertex(bContext *C, wmOperator *op)
        int teller=0;
        ModifierData *md= obedit->modifiers.first;
 
-       if(em==NULL) return OPERATOR_CANCELLED;
+       if(em==NULL) {
+               EM_EndEditMesh(obedit->data, em);
+               return OPERATOR_CANCELLED;
+       }
 
        /* count */
        eve= em->verts.first;
@@ -4238,7 +4286,10 @@ static int smooth_vertex(bContext *C, wmOperator *op)
                if(eve->f & SELECT) teller++;
                eve= eve->next;
        }
-       if(teller==0) return OPERATOR_CANCELLED;
+       if(teller==0) {
+               EM_EndEditMesh(obedit->data, em);
+               return OPERATOR_CANCELLED;
+       }
        
        adr=adror= (float *)MEM_callocN(3*sizeof(float *)*teller, "vertsmooth");
        eve= em->verts.first;
@@ -4351,6 +4402,7 @@ static int smooth_vertex(bContext *C, wmOperator *op)
 
 //     DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
 
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }
 
@@ -4475,12 +4527,13 @@ static int vertices_to_sphere_exec(bContext *C, wmOperator *op)
        Object *obedit= CTX_data_edit_object(C);
        View3D *v3d = CTX_wm_view3d(C);
        Scene *scene = CTX_data_scene(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        
        vertices_to_sphere(scene, v3d, obedit, em, RNA_float_get(op->ptr,"percent"));
                
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
        
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;       
 }
 
@@ -4524,7 +4577,7 @@ void flipface(EditMesh *em, EditFace *efa)
 static int flip_editnormals(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       EditMesh *em= EM_GetEditMesh(((Mesh *)obedit->data));
        EditFace *efa;
        
        efa= em->faces.first;
@@ -4538,6 +4591,7 @@ static int flip_editnormals(bContext *C, wmOperator *op)
        /* update vertex normals too */
        recalc_editnormals(em);
 
+       EM_EndEditMesh(obedit->data, em);
        return OPERATOR_FINISHED;
 }