2.5
[blender-staging.git] / source / blender / editors / object / object_edit.c
index ba344b5d67d808eb550bbdcfe34ae9abf84acc94..c6cbbf90b79a5abc904f9049c379df65c853a764 100644 (file)
@@ -98,7 +98,6 @@
 #include "BKE_material.h"
 #include "BKE_mball.h"
 #include "BKE_mesh.h"
-#include "BKE_multires.h"
 #include "BKE_nla.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
 #include "BKE_modifier.h"
 
 #include "ED_anim_api.h"
+#include "ED_armature.h"
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
@@ -180,8 +180,8 @@ void ED_base_object_activate(bContext *C, Base *base)
        Base *tbase;
        
        /* activating a non-mesh, should end a couple of modes... */
-       //      if(base && base->object->type!=OB_MESH)
-       // XXX          exit_paint_modes();
+       if(base && base->object->type!=OB_MESH)
+               ED_view3d_exit_paint_modes(C);
        
        /* sets scene->basact */
        BASACT= base;
@@ -235,29 +235,48 @@ int object_data_is_libdata(Object *ob)
 
 
 
-void exit_paint_modes(void)
+/* exported */
+void ED_object_base_init_from_view(Scene *scene, View3D *v3d, Base *base)
 {
-#if 0
-       if(G.f & G_VERTEXPAINT) set_vpaint();
-       if(G.f & G_TEXTUREPAINT) set_texturepaint();
-       if(G.f & G_WEIGHTPAINT) set_wpaint();
-       if(G.f & G_SCULPTMODE) set_sculptmode();
-       if(G.f & G_PARTICLEEDIT) PE_set_particle_edit();
-
-       G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT+G_SCULPTMODE+G_PARTICLEEDIT);
-#endif
+       Object *ob= base->object;
+       
+       if (scene==NULL)
+               return;
+       
+       if (v3d==NULL) {
+               base->lay = scene->lay;
+               VECCOPY(ob->loc, scene->cursor);
+       } 
+       else {
+               if (v3d->localview) {
+                       base->lay= ob->lay= v3d->layact | v3d->lay;
+                       VECCOPY(ob->loc, v3d->cursor);
+               } 
+               else {
+                       base->lay= ob->lay= v3d->layact;
+                       VECCOPY(ob->loc, scene->cursor);
+               }
+               
+               if (U.flag & USER_ADD_VIEWALIGNED) {
+                       v3d->viewquat[0]= -v3d->viewquat[0];
+                       
+                       QuatToEul(v3d->viewquat, ob->rot);
+                       v3d->viewquat[0]= -v3d->viewquat[0];
+               }
+       }
 }
 
+
 void add_object_draw(Scene *scene, View3D *v3d, int type)      /* for toolbox or menus, only non-editmode stuff */
 {
        Object *ob;
        
-       exit_paint_modes();
+//     ED_view3d_exit_paint_modes(C);
 
 // XXX if (obedit) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
        ob= add_object(scene, type);
 //     ED_base_object_activate(C, BASACT);
-       base_init_from_view3d(BASACT, v3d, scene);
+       ED_object_base_init_from_view(scene, v3d, BASACT);
        
        /* only undo pushes on objects without editmode... */
        if(type==OB_EMPTY) BIF_undo_push("Add Empty");
@@ -287,7 +306,7 @@ void add_objectLamp(Scene *scene, View3D *v3d, short type)
 
        if(scene->obedit==NULL) { // XXX get from context
                add_object_draw(scene, v3d, OB_LAMP);
-               base_init_from_view3d(BASACT, v3d, scene);
+               ED_object_base_init_from_view(scene, v3d, BASACT);
        }
        
        la = BASACT->object->data;
@@ -330,7 +349,7 @@ void delete_obj(Scene *scene, View3D *v3d, int ok)
                                }
                        }
                        
-                       exit_paint_modes();
+//                     ED_view3d_exit_paint_modes(C);
 
                        if(base->object->type==OB_LAMP) islamp= 1;
 
@@ -584,7 +603,7 @@ static int return_editcurve_indexar(int *tot, int **indexar, float *cent)
        return totvert;
 }
 
-static void apply_obmat(Object *ob)
+void ED_object_apply_obmat(Object *ob)
 {
        float mat[3][3], imat[3][3], tmat[3][3];
        
@@ -853,7 +872,7 @@ static void ignore_parent_tx(Scene *scene, Object *ob )
        /* a change was made, adjust the children to compensate */
        for (ob_child=G.main->object.first; ob_child; ob_child=ob_child->id.next) {
                if (ob_child->parent == ob) {
-                       apply_obmat(ob_child);
+                       ED_object_apply_obmat(ob_child);
                        what_does_parent(scene, ob_child, &workob);
                        Mat4Invert(ob_child->parentinv, workob.obmat);
                }
@@ -991,7 +1010,7 @@ static int clear_parent_exec(bContext *C, wmOperator *op)
                if(RNA_enum_is_equal(op->ptr, "type", "CLEAR_KEEP_TRANSFORM")) {
                        ob->parent= NULL;
                        ob->track= NULL;
-                       apply_obmat(ob);
+                       ED_object_apply_obmat(ob);
                }
                if(RNA_enum_is_equal(op->ptr, "type", "CLEAR_INVERSE")) {
                        Mat4One(ob->parentinv);
@@ -1047,7 +1066,7 @@ static int object_clear_track_exec(bContext *C, wmOperator *op)
                        ob->recalc |= OB_RECALC;
                        
                        if(RNA_enum_is_equal(op->ptr, "type", "CLEAR_KEEP_TRANSFORM")) {
-                               apply_obmat(ob);
+                               ED_object_apply_obmat(ob);
                        }                       
                /*}*/
        }
@@ -1607,36 +1626,77 @@ void OBJECT_OT_set_restrictview(wmOperatorType *ot)
        RNA_def_property_enum_items(prop, prop_set_restrictview_types);
        
 }
-/* ******************** **************** */
+/* ************* Slow Parent ******************* */
+static int object_set_slowparent_exec(bContext *C, wmOperator *op)
+{
+
+       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+                               
+               if(base->object->parent) base->object->partype |= PARSLOW;
+               base->object->recalc |= OB_RECALC_OB;
+               
+       }
+       CTX_DATA_END;
+
+       ED_anim_dag_flush_update(C);    
+       ED_undo_push(C,"Set Slow Parent");
+       
+       WM_event_add_notifier(C, NC_SCENE, CTX_data_scene(C));
+       
+       return OPERATOR_FINISHED;
+}
 
-void reset_slowparents(Scene *scene, View3D *v3d)
+void OBJECT_OT_set_slowparent(wmOperatorType *ot)
 {
-       /* back to original locations */
-       Base *base;
+       
+       /* identifiers */
+       ot->name= "Set Slow Parent";
+       ot->idname= "OBJECT_OT_set_slow_parent";
+       
+       /* api callbacks */
+       ot->invoke= WM_operator_confirm;
+       ot->exec= object_set_slowparent_exec;
+       ot->poll= ED_operator_view3d_active;
+}
 
-       for(base= FIRSTBASE; base; base= base->next) {
+static int object_clear_slowparent_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+
+       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
                if(base->object->parent) {
                        if(base->object->partype & PARSLOW) {
                                base->object->partype -= PARSLOW;
                                where_is_object(scene, base->object);
                                base->object->partype |= PARSLOW;
+                               base->object->recalc |= OB_RECALC_OB;
                        }
                }
+               
        }
-}
-void set_slowparent(Scene *scene, View3D *v3d)
-{
-       Base *base;
+       CTX_DATA_END;
 
-       if( okee("Set slow parent")==0 ) return;
+       ED_anim_dag_flush_update(C);    
+       ED_undo_push(C,"Clear Slow Parent");
+       
+       WM_event_add_notifier(C, NC_SCENE, CTX_data_scene(C));
+       
+       return OPERATOR_FINISHED;
+}
 
-       for(base= FIRSTBASE; base; base= base->next) {
-               if(TESTBASELIB(v3d, base)) {
-                       if(base->object->parent) base->object->partype |= PARSLOW;
-               }
-       }
-       BIF_undo_push("Slow parent");
+void OBJECT_OT_clear_slowparent(wmOperatorType *ot)
+{
+       
+       /* identifiers */
+       ot->name= "Clear Slow Parent";
+       ot->idname= "OBJECT_OT_clear_slow_parent";
+       
+       /* api callbacks */
+       ot->invoke= WM_operator_confirm;
+       ot->exec= object_clear_slowparent_exec;
+       ot->poll= ED_operator_view3d_active;
 }
+/* ******************** **************** */
 
 // XXX
 #define BEZSELECTED_HIDDENHANDLES(bezt)   ((G.f & G_HIDDENHANDLES) ? (bezt)->f2 & SELECT : BEZSELECTED(bezt))
@@ -1996,7 +2056,7 @@ static int make_parent_exec(bContext *C, wmOperator *op)
                                Object workob;
                                
                                /* apply transformation of previous parenting */
-                               apply_obmat(ob);
+                               ED_object_apply_obmat(ob);
                                
                                ob->parent= par;
                                
@@ -2223,9 +2283,10 @@ void ED_object_exit_editmode(bContext *C, int flag)
                if(G.f & G_WEIGHTPAINT)
                        mesh_octree_table(obedit, NULL, NULL, 'e');
        }
-       else if (obedit->type==OB_ARMATURE){    
-//             load_editArmature();
-//             if (freedata) free_editArmature();
+       else if (obedit->type==OB_ARMATURE) {   
+               ED_armature_from_edit(scene, obedit);
+               if(freedata)
+                       ED_armature_edit_free(obedit);
        }
        else if(ELEM(obedit->type, OB_CURVE, OB_SURF)) {
 //             extern ListBase editNurb;
@@ -2251,9 +2312,6 @@ void ED_object_exit_editmode(bContext *C, int flag)
        if(freedata) obedit= NULL;
        scene->obedit= obedit; // XXX for context
        
-       if(ob->type==OB_MESH && get_mesh(ob)->mr)
-               multires_edge_level_update(ob, get_mesh(ob));
-       
        /* also flush ob recalc, doesn't take much overhead, but used for particles */
        DAG_object_flush_update(scene, ob, OB_RECALC_OB|OB_RECALC_DATA);
        
@@ -2272,11 +2330,16 @@ void ED_object_enter_editmode(bContext *C, int flag)
        Scene *scene= CTX_data_scene(C);
        Base *base= CTX_data_active_base(C);
        Object *ob= base->object;
-       View3D *v3d= (View3D *)CTX_wm_space_data(C);
+       ScrArea *sa= CTX_wm_area(C);
+       View3D *v3d= NULL;
        int ok= 0;
        
        if(scene->id.lib) return;
        if(base==NULL) return;
+       
+       if(sa->spacetype==SPACE_VIEW3D)
+               v3d= sa->spacedata.first;
+       
        if((v3d==NULL || (base->lay & v3d->lay))==0) return;
        
        if(ob->data==NULL) return;
@@ -2299,7 +2362,7 @@ void ED_object_enter_editmode(bContext *C, int flag)
 
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MESH, ob);
        }
-       if (ob->type==OB_ARMATURE){
+       else if (ob->type==OB_ARMATURE){
                bArmature *arm= base->object->data;
                if (!arm) return;
                /*
@@ -2314,9 +2377,9 @@ void ED_object_enter_editmode(bContext *C, int flag)
                        error_libdata();
                        return;
                }
-//             ok=1;
+               ok=1;
                scene->obedit= ob;
-// XXX         make_editArmature();
+               ED_armature_to_edit(ob);
                /* to ensure all goes in restposition and without striding */
                DAG_object_flush_update(scene, ob, OB_RECALC);
 
@@ -4831,7 +4894,7 @@ void make_object_duplilist_real(Scene *scene, View3D *v3d, Base *base)
                ob->transflag &= ~OB_DUPLI;     
                
                Mat4CpyMat4(ob->obmat, dob->mat);
-               apply_obmat(ob);
+               ED_object_apply_obmat(ob);
        }
        
        copy_object_set_idnew(scene, v3d, 0);
@@ -6273,55 +6336,3 @@ void hookmenu(Scene *scene, View3D *v3d)
                allqueue(REDRAWBUTSEDIT, 0);
        }       
 }
-
-void hide_objects(Scene *scene, View3D *v3d, int select)
-{
-       Base *base;
-       short changed = 0, changed_act = 0;
-       for(base = FIRSTBASE; base; base=base->next){
-               if ((base->lay & v3d->lay) && TESTBASELIB(v3d, base)==select) {
-                       base->flag &= ~SELECT;
-                       base->object->flag = base->flag;
-                       base->object->restrictflag |= OB_RESTRICT_VIEW;
-                       changed = 1;
-                       if (base==BASACT) {
-                               BASACT= NULL;
-                               changed_act = 1;
-                       }
-               }
-       }
-       if (changed) {
-               if(select) BIF_undo_push("Hide Selected Objects");
-               else if(select) BIF_undo_push("Hide Unselected Objects");
-               DAG_scene_sort(scene);
-               allqueue(REDRAWVIEW3D,0);
-               allqueue(REDRAWOOPS,0);
-               allqueue(REDRAWDATASELECT,0);
-               if (changed_act) { /* these spaces depend on the active object */
-                       allqueue(REDRAWBUTSALL,0);
-                       allqueue(REDRAWIPO,0);
-                       allqueue(REDRAWACTION,0);
-               }
-       }
-}
-
-void show_objects(Scene *scene, View3D *v3d)
-{
-       Base *base;
-       int changed = 0;
-       
-       for(base = FIRSTBASE; base; base=base->next){
-               if((base->lay & v3d->lay) && base->object->restrictflag & OB_RESTRICT_VIEW) {
-                       base->flag |= SELECT;
-                       base->object->flag = base->flag;
-                       base->object->restrictflag &= ~OB_RESTRICT_VIEW; 
-                       changed = 1;
-               }
-       }
-       if (changed) {
-               BIF_undo_push("Unhide Objects");
-               DAG_scene_sort(scene);
-               allqueue(REDRAWVIEW3D,0);
-               allqueue(REDRAWOOPS,0);
-       }
-}