2.5: Object module
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 9 Sep 2009 11:52:56 +0000 (11:52 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 9 Sep 2009 11:52:56 +0000 (11:52 +0000)
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...

38 files changed:
projectfiles_vc9/blender/editors/ED_editors.vcproj
release/ui/space_info.py
source/blender/blenkernel/BKE_animsys.h
source/blender/blenkernel/intern/anim_sys.c
source/blender/blenkernel/intern/library.c
source/blender/blenlib/intern/util.c
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/editarmature_retarget.c
source/blender/editors/armature/meshlaplacian.c
source/blender/editors/armature/poseobject.c
source/blender/editors/include/ED_armature.h
source/blender/editors/include/ED_mball.h
source/blender/editors/include/ED_mesh.h
source/blender/editors/include/ED_object.h
source/blender/editors/metaball/mball_edit.c [moved from source/blender/editors/metaball/editmball.c with 100% similarity]
source/blender/editors/object/object_add.c [new file with mode: 0644]
source/blender/editors/object/object_constraint.c [moved from source/blender/editors/object/editconstraint.c with 99% similarity]
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_group.c [moved from source/blender/editors/object/editgroup.c with 60% similarity]
source/blender/editors/object/object_hook.c [new file with mode: 0644]
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_lattice.c [moved from source/blender/editors/object/editlattice.c with 98% similarity]
source/blender/editors/object/object_modifier.c
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_relations.c [new file with mode: 0644]
source/blender/editors/object/object_select.c [new file with mode: 0644]
source/blender/editors/object/object_shapekey.c [moved from source/blender/editors/object/editkey.c with 100% similarity]
source/blender/editors/object/object_transform.c [new file with mode: 0644]
source/blender/editors/object/object_vgroup.c
source/blender/editors/screen/screen_context.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/space_buttons/buttons_ops.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/util/undo.c
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_object.c
source/blender/windowmanager/intern/wm_event_system.c

index 9f2fc769e49ab280b500c9e648d96db68456270c..db0b851fd74a7dfb5bf4f41ed297354d4d82cd82 100644 (file)
                        Name="object"\r
                        >\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\object\editconstraint.c"\r
+                               RelativePath="..\..\..\source\blender\editors\object\object_constraint.c"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\object\editgroup.c"\r
+                               RelativePath="..\..\..\source\blender\editors\object\object_group.c"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\object\editkey.c"\r
+                               RelativePath="..\..\..\source\blender\editors\object\object_shapekey.c"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\object\editlattice.c"\r
+                               RelativePath="..\..\..\source\blender\editors\object\object_lattice.c"\r
                                >\r
                        </File>\r
                        <File\r
                                RelativePath="..\..\..\source\blender\editors\object\object_vgroup.c"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\..\source\blender\editors\object\object_hook.c"\r
+                               >\r
+                       </File>\r
                </Filter>\r
                <Filter\r
                        Name="transform"\r
                        Name="metaball"\r
                        >\r
                        <File\r
-                               RelativePath="..\..\..\source\blender\editors\metaball\editmball.c"\r
+                               RelativePath="..\..\..\source\blender\editors\metaball\mball_edit.c"\r
                                >\r
                        </File>\r
                        <File\r
index 79937816791f412515faea9524acedf31b5ca1e6..97243f857a63000daec5c0c6b142fab1f3785294 100644 (file)
@@ -117,22 +117,22 @@ class INFO_MT_add(bpy.types.Menu):
 
                layout.operator_context = "EXEC_SCREEN"
 
-               layout.item_menu_enumO( "object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH')
-               layout.item_menu_enumO( "object.curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE')
-               layout.item_menu_enumO( "object.surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE')
-               layout.item_menu_enumO( "object.metaball_add", "type", 'META', icon='ICON_OUTLINER_OB_META')
+               layout.item_menu_enumO("object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH')
+               layout.item_menu_enumO("object.curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE')
+               layout.item_menu_enumO("object.surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE')
+               layout.item_menu_enumO("object.metaball_add", "type", 'META', icon='ICON_OUTLINER_OB_META')
                layout.itemO("object.text_add", text="Text", icon='ICON_OUTLINER_OB_FONT')
 
                layout.itemS()
 
                layout.itemO("object.armature_add", text="Armature", icon='ICON_OUTLINER_OB_ARMATURE')
-               layout.item_enumO("object.object_add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE')
-               layout.item_enumO("object.object_add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY')
+               layout.item_enumO("object.add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE')
+               layout.item_enumO("object.add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY')
 
                layout.itemS()
 
-               layout.item_enumO("object.object_add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA')
-               layout.item_enumO("object.object_add", "type", 'LAMP', icon='ICON_OUTLINER_OB_LAMP')
+               layout.item_enumO("object.add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA')
+               layout.item_enumO("object.add", "type", 'LAMP', icon='ICON_OUTLINER_OB_LAMP')
 
 class INFO_MT_game(bpy.types.Menu):
        __space_type__ = 'INFO'
index cabbaa7aa0f5684cbdbb9e102400fca32a115fec..cc5b4dfdcaf7ccfec48d2335430fb067e9216f4d 100644 (file)
@@ -55,6 +55,9 @@ void BKE_free_animdata(struct ID *id);
 /* Copy AnimData */
 struct AnimData *BKE_copy_animdata(struct AnimData *adt);
 
+/* Make Local */
+void BKE_animdata_make_local(struct AnimData *adt);
+
 /* ************************************* */
 /* KeyingSets API */
 
index b7cc98063ed3d71d96bcdc91f2de2a3d993b70da..0e8450025da0d79778ed4cb74e6aeb4fe2e9ce9b 100644 (file)
@@ -204,6 +204,32 @@ AnimData *BKE_copy_animdata (AnimData *adt)
        return dadt;
 }
 
+/* Make Local -------------------------------------------- */
+
+static void make_local_strips(ListBase *strips)
+{
+       NlaStrip *strip;
+
+       for(strip=strips->first; strip; strip=strip->next) {
+               if(strip->act) make_local_action(strip->act);
+               if(strip->remap && strip->remap->target) make_local_action(strip->remap->target);
+
+               make_local_strips(&strip->strips);
+       }
+}
+
+void BKE_animdata_make_local(AnimData *adt)
+{
+       NlaTrack *nlt;
+
+       if(adt->action) make_local_action(adt->action);
+       if(adt->tmpact) make_local_action(adt->tmpact);
+       if(adt->remap && adt->remap->target) make_local_action(adt->remap->target);
+
+       for(nlt=adt->nla_tracks.first; nlt; nlt=nlt->next) 
+               make_local_strips(&nlt->strips);
+}
+
 /* *********************************** */ 
 /* KeyingSet API */
 
index f15552ab40c369ac7721ad44cb399c4f77c12897..02d92a62b59b11dda9a75be6400439bbc69de3be 100644 (file)
@@ -194,7 +194,10 @@ int id_make_local(ID *id, int test)
                case ID_WV:
                        return 0; /* deprecated */
                case ID_LT:
-                       if(!test) make_local_lattice((Lattice*)id);
+                       if(!test) {
+                               make_local_lattice((Lattice*)id);
+                               make_local_key(((Lattice*)id)->key);
+                       }
                        return 1;
                case ID_LA:
                        if(!test) make_local_lamp((Lamp*)id);
index acf236d382b96cf9fd03c2a04c63360a1422693e..c7bb7a54457b7a0dd0fe5f95675b4312bbed1a99 100644 (file)
 
 #include "BLI_winstuff.h"
 
-/* for duplicate_defgroup */
-#if !(defined vsnprintf)
-#define vsnprintf _vsnprintf
-#endif
-
 #endif
 
 
index 65051c384b325cc0d9ad8859917aac3edf7d7d6a..4f5d8872384ecacb68bf59a4556ccea701bf30df 100644 (file)
@@ -239,7 +239,7 @@ static void fix_bonelist_roll (ListBase *bonelist, ListBase *editbonelist)
 }
 
 /* put EditMode back in Object */
-void ED_armature_from_edit(Scene *scene, Object *obedit)
+void ED_armature_from_edit(Object *obedit)
 {
        bArmature *arm= obedit->data;
        EditBone *eBone, *neBone;
@@ -343,21 +343,19 @@ void ED_armature_from_edit(Scene *scene, Object *obedit)
        DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
 }
 
-
-
-void apply_rot_armature (Scene *scene, Object *ob, float mat[3][3])
+void ED_armature_apply_transform(Object *ob, float mat[4][4])
 {
        EditBone *ebone;
        bArmature *arm= ob->data;
-       float scale = Mat3ToScalef(mat);        /* store the scale of the matrix here to use on envelopes */
+       float scale = Mat4ToScalef(mat);        /* store the scale of the matrix here to use on envelopes */
        
        /* Put the armature into editmode */
        ED_armature_to_edit(ob);
 
        /* Do the rotations */
        for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
-               Mat3MulVecfl(mat, ebone->head);
-               Mat3MulVecfl(mat, ebone->tail);
+               Mat4MulVecfl(mat, ebone->head);
+               Mat4MulVecfl(mat, ebone->tail);
                
                ebone->rad_head *= scale;
                ebone->rad_tail *= scale;
@@ -365,7 +363,7 @@ void apply_rot_armature (Scene *scene, Object *ob, float mat[3][3])
        }
        
        /* Turn the list into an armature */
-       ED_armature_from_edit(scene, ob);
+       ED_armature_from_edit(ob);
        ED_armature_edit_free(ob);
 }
 
@@ -411,7 +409,7 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode)
        }
        
        /* Turn the list into an armature */
-       ED_armature_from_edit(scene, ob);
+       ED_armature_from_edit(ob);
        
        /* Adjust object location for new centerpoint */
        if(centermode && obedit==NULL) {
@@ -557,7 +555,7 @@ static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op)
        }
        
        /* convert editbones back to bones */
-       ED_armature_from_edit(scene, ob);
+       ED_armature_from_edit(ob);
        
        /* flush positions of posebones */
        where_is_pose(scene, ob);
@@ -791,7 +789,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
        
        DAG_scene_sort(scene);  // because we removed object(s)
 
-       ED_armature_from_edit(scene, ob);
+       ED_armature_from_edit(ob);
        ED_armature_edit_free(ob);
 
        WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
@@ -994,7 +992,7 @@ static void separate_armature_bones (Scene *scene, Object *ob, short sel)
        }
        
        /* exit editmode (recalculates pchans too) */
-       ED_armature_from_edit(scene, ob);
+       ED_armature_from_edit(ob);
        ED_armature_edit_free(ob);
 }
 
@@ -1037,7 +1035,7 @@ static int separate_armature_exec (bContext *C, wmOperator *op)
        oldob->mode &= ~OB_MODE_POSE;
        //oldbase->flag &= ~OB_POSEMODE;
        
-       ED_armature_from_edit(scene, obedit);
+       ED_armature_from_edit(obedit);
        ED_armature_edit_free(obedit);
        
        /* 2) duplicate base */
@@ -4334,7 +4332,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor
                /* in weightpaint we select the associated vertex group too */
                if (ob->mode & OB_MODE_WEIGHT_PAINT) {
                        if (nearBone->flag & BONE_ACTIVE) {
-                               vertexgroup_select_by_name(OBACT, nearBone->name);
+                               ED_vgroup_select_by_name(OBACT, nearBone->name);
                                DAG_id_flush_update(&OBACT->id, OB_RECALC_DATA);
                        }
                }
@@ -4445,7 +4443,7 @@ static int bone_skinnable(Object *ob, Bone *bone, void *datap)
     return 0;
 }
 
-static int add_defgroup_unique_bone(Object *ob, Bone *bone, void *data) 
+static int ED_vgroup_add_unique_bone(Object *ob, Bone *bone, void *data) 
 {
     /* This group creates a vertex group to ob that has the
       * same name as bone (provided the bone is skinnable). 
@@ -4453,7 +4451,7 @@ static int add_defgroup_unique_bone(Object *ob, Bone *bone, void *data)
       */
        if (!(bone->flag & BONE_NO_DEFORM)) {
                if (!get_named_vertexgroup(ob,bone->name)) {
-                       add_defgroup_name(ob, bone->name);
+                       ED_vgroup_add_name(ob, bone->name);
                        return 1;
                }
     }
@@ -4497,7 +4495,7 @@ static int dgroup_skinnable(Object *ob, Bone *bone, void *datap)
                                segments = 1;
                        
                        if (!(defgroup = get_named_vertexgroup(ob, bone->name)))
-                               defgroup = add_defgroup_name(ob, bone->name);
+                               defgroup = ED_vgroup_add_name(ob, bone->name);
                        
                        if (data->list != NULL) {
                                hgroup = (bDeformGroup ***) &data->list;
@@ -4548,17 +4546,17 @@ static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], i
                        
                        /* add the vert to the deform group if weight!=0.0 */
                        if (distance!=0.0)
-                               add_vert_to_defgroup (ob, dgroup, i, distance, WEIGHT_REPLACE);
+                               ED_vgroup_vert_add (ob, dgroup, i, distance, WEIGHT_REPLACE);
                        else
-                               remove_vert_defgroup (ob, dgroup, i);
+                               ED_vgroup_vert_remove (ob, dgroup, i);
                        
                        /* do same for mirror */
                        if (dgroupflip && dgroupflip[j] && iflip >= 0) {
                                if (distance!=0.0)
-                                       add_vert_to_defgroup (ob, dgroupflip[j], iflip, distance,
+                                       ED_vgroup_vert_add (ob, dgroupflip[j], iflip, distance,
                                                WEIGHT_REPLACE);
                                else
-                                       remove_vert_defgroup (ob, dgroupflip[j], iflip);
+                                       ED_vgroup_vert_remove (ob, dgroupflip[j], iflip);
                        }
                }
        }
@@ -4748,10 +4746,10 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mod
                /* Traverse the bone list, trying to create empty vertex 
                 * groups cooresponding to the bone.
                 */
-               bone_looper(ob, arm->bonebase.first, NULL, add_defgroup_unique_bone);
+               bone_looper(ob, arm->bonebase.first, NULL, ED_vgroup_add_unique_bone);
 
                if (ob->type == OB_MESH)
-                       create_dverts(ob->data);
+                       ED_vgroup_data_create(ob->data);
        }
        else if(mode == ARM_GROUPS_ENVELOPE || mode == ARM_GROUPS_AUTO) {
                /* Traverse the bone list, trying to create vertex groups 
@@ -5659,7 +5657,7 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg)
        
        if (obedit != NULL)
        {
-               ED_armature_from_edit(scene, obedit);
+               ED_armature_from_edit(obedit);
                ED_armature_edit_free(obedit);
        }
        
index 1d87ca8a6df650924a5bbc09f126f44cea140de8..16e78f7c8d133c4995e85d580dc45ceee6aa3b8b 100644 (file)
@@ -2732,7 +2732,7 @@ static void adjustGraphs(bContext *C, RigGraph *rigg)
 
        /* Turn the list into an armature */
        arm->edbo = rigg->editbones;
-       ED_armature_from_edit(scene, rigg->ob);
+       ED_armature_from_edit(rigg->ob);
        
        ED_undo_push(C, "Retarget Skeleton");
 }
@@ -2762,7 +2762,7 @@ static void retargetGraphs(bContext *C, RigGraph *rigg)
 
        /* Turn the list into an armature */
        arm->edbo = rigg->editbones;
-       ED_armature_from_edit(scene, rigg->ob);
+       ED_armature_from_edit(rigg->ob);
 }
 
 char *RIG_nameBone(RigGraph *rg, int arc_index, int bone_index)
index 1b167518a5ac31f0f037929b5cd420244a4f1b0a..a6c94bee5b1a216373a8bdbbb42b172deded9d87 100644 (file)
@@ -672,9 +672,9 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones,
                /* clear weights */
                if(bbone && firstsegment) {
                        for(a=0; a<me->totvert; a++) {
-                               remove_vert_defgroup(ob, dgrouplist[j], a);
+                               ED_vgroup_vert_remove(ob, dgrouplist[j], a);
                                if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0)
-                                       remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]);
+                                       ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]);
                        }
                }
 
@@ -694,32 +694,32 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones,
                                
                                if(bbone) {
                                        if(solution > 0.0f)
-                                               add_vert_to_defgroup(ob, dgrouplist[j], a, solution,
+                                               ED_vgroup_vert_add(ob, dgrouplist[j], a, solution,
                                                        WEIGHT_ADD);
                                }
                                else {
                                        weight= heat_limit_weight(solution);
                                        if(weight > 0.0f)
-                                               add_vert_to_defgroup(ob, dgrouplist[j], a, weight,
+                                               ED_vgroup_vert_add(ob, dgrouplist[j], a, weight,
                                                        WEIGHT_REPLACE);
                                        else
-                                               remove_vert_defgroup(ob, dgrouplist[j], a);
+                                               ED_vgroup_vert_remove(ob, dgrouplist[j], a);
                                }
 
                                /* do same for mirror */
                                if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) {
                                        if(bbone) {
                                                if(solution > 0.0f)
-                                                       add_vert_to_defgroup(ob, dgroupflip[j], vertsflipped[a],
+                                                       ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a],
                                                                solution, WEIGHT_ADD);
                                        }
                                        else {
                                                weight= heat_limit_weight(solution);
                                                if(weight > 0.0f)
-                                                       add_vert_to_defgroup(ob, dgroupflip[j], vertsflipped[a],
+                                                       ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a],
                                                                weight, WEIGHT_REPLACE);
                                                else
-                                                       remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]);
+                                                       ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]);
                                        }
                                }
                        }
@@ -734,16 +734,16 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones,
                /* remove too small vertex weights */
                if(bbone && lastsegment) {
                        for(a=0; a<me->totvert; a++) {
-                               weight= get_vert_defgroup(ob, dgrouplist[j], a);
+                               weight= ED_vgroup_vert_weight(ob, dgrouplist[j], a);
                                weight= heat_limit_weight(weight);
                                if(weight <= 0.0f)
-                                       remove_vert_defgroup(ob, dgrouplist[j], a);
+                                       ED_vgroup_vert_remove(ob, dgrouplist[j], a);
 
                                if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) {
-                                       weight= get_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]);
+                                       weight= ED_vgroup_vert_weight(ob, dgroupflip[j], vertsflipped[a]);
                                        weight= heat_limit_weight(weight);
                                        if(weight <= 0.0f)
-                                               remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]);
+                                               ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]);
                                }
                        }
                }
index a4a518bc0032d1631e61d078bb0ee02bbccd4fc0..0ae92de4407dcb88e58400f2ad791bebad5424d7 100644 (file)
@@ -1673,7 +1673,7 @@ void pose_activate_flipped_bone(Scene *scene)
                        
                                /* in weightpaint we select the associated vertex group too */
                                if(ob->mode & OB_MODE_WEIGHT_PAINT) {
-                                       vertexgroup_select_by_name(OBACT, name);
+                                       ED_vgroup_select_by_name(OBACT, name);
                                        DAG_id_flush_update(&OBACT->id, OB_RECALC_DATA);
                                }
                                
index 738cbf094cb163bcc3e21dd7f1821cfbdc33f54d..8bdfe41ef80ad0ce5c11adcc4dedfef28173ee89 100644 (file)
@@ -95,7 +95,7 @@ void ED_operatortypes_armature(void);
 void ED_keymap_armature(struct wmWindowManager *wm);
 
 /* editarmature.c */
-void ED_armature_from_edit(struct Scene *scene, struct Object *obedit);
+void ED_armature_from_edit(struct Object *obedit);
 void ED_armature_to_edit(struct Object *ob);
 void ED_armature_edit_free(struct Object *ob);
 void ED_armature_edit_remake(struct Object *obedit);
@@ -116,6 +116,8 @@ void transform_armature_mirror_update(struct Object *obedit);
 void clear_armature(struct Scene *scene, struct Object *ob, char mode);
 void docenter_armature (struct Scene *scene, struct View3D *v3d, struct Object *ob, int centermode);
 
+void ED_armature_apply_transform(struct Object *ob, float mat[4][4]);
+
 #define ARM_GROUPS_NAME                1
 #define ARM_GROUPS_ENVELOPE    2
 #define ARM_GROUPS_AUTO                3
index adb50867bf938025b2725df310b22e6719df7788..49c1d856a27850aae6b9ba3db6956373a6481f13 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
+struct bContext;
+struct Object;
+struct wmWindowManager;
+
 void ED_operatortypes_metaball(void);
 void ED_keymap_metaball(struct wmWindowManager *wm);
 
@@ -37,3 +41,5 @@ void free_editMball(struct Object *obedit);
 void make_editMball(struct Object *obedit);
 void load_editMball(struct Object *obedit);
 
+void undo_push_mball(struct bContext *C, char *name);
+
index 0face00f82b272e441cdda77e54cffc9aad98054..a2dba89ec2040c90c278bab2177b981605dea80b 100644 (file)
@@ -157,25 +157,23 @@ void              EM_deselect_by_material(struct EditMesh *em, int index);
 /* editface.c */
 struct MTFace  *EM_get_active_mtface(struct EditMesh *em, struct EditFace **act_efa, struct MCol **mcol, int sloppy);
 
-/* editdeform.c XXX rename functions? */
+/* object_vgroup.c */
 
 #define WEIGHT_REPLACE 1
 #define WEIGHT_ADD 2
 #define WEIGHT_SUBTRACT 3
 
-void           add_defgroup (Object *ob);
-void           create_dverts(struct ID *id);
-float          get_vert_defgroup (Object *ob, struct bDeformGroup *dg, int vertnum);
-void           remove_vert_defgroup (Object *ob, struct bDeformGroup *dg, int vertnum);
-void           remove_verts_defgroup (Object *obedit, int allverts);
-void           vertexgroup_select_by_name(Object *ob, char *name);
-void           add_vert_to_defgroup (Object *ob, struct bDeformGroup *dg, int vertnum, 
-                           float weight, int assignmode);
+struct bDeformGroup            *ED_vgroup_add(struct Object *ob);
+struct bDeformGroup            *ED_vgroup_add_name(struct Object *ob, char *name);
+void                                   ED_vgroup_select_by_name(struct Object *ob, char *name);
+void                                   ED_vgroup_data_create(struct ID *id);
 
-struct bDeformGroup            *add_defgroup_name (Object *ob, char *name);
-struct MDeformWeight   *verify_defweight (struct MDeformVert *dv, int defgroup);
-struct MDeformWeight   *get_defweight (struct MDeformVert *dv, int defgroup);
+void           ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup *dg, int vertnum,  float weight, int assignmode);
+void           ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum);
+float          ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum);
 
+struct MDeformWeight   *ED_vgroup_weight_verify(struct MDeformVert *dv, int defgroup);
+struct MDeformWeight   *ED_vgroup_weight_get(struct MDeformVert *dv, int defgroup);
 
 #endif /* ED_MESH_H */
 
index d31f85d08ea4724003329b18f65e9c865fdd4b66..67dc6dada5f204a99e74e49dca1c458f6bced6d5 100644 (file)
@@ -89,14 +89,11 @@ void object_test_constraints(struct Object *ob);
 void ED_object_constraint_rename(struct Object *ob, struct bConstraint *con, char *oldname);
 void ED_object_constraint_set_active(struct Object *ob, struct bConstraint *con);
 
-/* editlattice.c */
+/* object_lattice.c */
 void mouse_lattice(struct bContext *C, short mval[2], int extend);
 void undo_push_lattice(struct bContext *C, char *name);
 
-/* editmball.c */
-void undo_push_mball(struct bContext *C, char *name);
-
-/* editkey.c */
+/* object_shapekey.c */
 void insert_shapekey(struct Scene *scene, struct Object *ob);
 void delete_key(struct Scene *scene, struct Object *ob);
 void key_to_mesh(struct KeyBlock *kb, struct Mesh *me);
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
new file mode 100644 (file)
index 0000000..eaf7d41
--- /dev/null
@@ -0,0 +1,1451 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, 2002-2008 full recode
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_action_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_group_types.h"
+#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meta_types.h"
+#include "DNA_object_fluidsim.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_vfont_types.h"
+
+#include "BLI_arithb.h"
+#include "BLI_listbase.h"
+
+#include "BKE_anim.h"
+#include "BKE_armature.h"
+#include "BKE_constraint.h"
+#include "BKE_context.h"
+#include "BKE_curve.h"
+#include "BKE_customdata.h"
+#include "BKE_depsgraph.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_displist.h"
+#include "BKE_global.h"
+#include "BKE_group.h"
+#include "BKE_lattice.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_material.h"
+#include "BKE_mball.h"
+#include "BKE_mesh.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_particle.h"
+#include "BKE_report.h"
+#include "BKE_sca.h"
+#include "BKE_scene.h"
+#include "BKE_texture.h"
+#include "BKE_utildefines.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_anim_api.h"
+#include "ED_armature.h"
+#include "ED_curve.h"
+#include "ED_mball.h"
+#include "ED_mesh.h"
+#include "ED_object.h"
+#include "ED_screen.h"
+#include "ED_transform.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "object_intern.h"
+
+/************************** Exported *****************************/
+
+void ED_object_base_init_from_view(bContext *C, Base *base)
+{
+       View3D *v3d= CTX_wm_view3d(C);
+       Scene *scene= CTX_data_scene(C);
+       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) {
+                       ARegion *ar= CTX_wm_region(C);
+                       if(ar) {
+                               RegionView3D *rv3d= ar->regiondata;
+                               
+                               rv3d->viewquat[0]= -rv3d->viewquat[0];
+                               QuatToEul(rv3d->viewquat, ob->rot);
+                               rv3d->viewquat[0]= -rv3d->viewquat[0];
+                       }
+               }
+       }
+       where_is_object(scene, ob);
+}
+
+/********************* Add Object Operator ********************/
+
+void add_object_draw(Scene *scene, View3D *v3d, int type)      /* for toolbox or menus, only non-editmode stuff */
+{
+       /* keep here to get things compile, remove later */
+}
+
+/* for object add primitive operators */
+static Object *object_add_type(bContext *C, int type)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob;
+       
+       /* for as long scene has editmode... */
+       if (CTX_data_edit_object(C)) 
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
+       
+       /* deselects all, sets scene->basact */
+       ob= add_object(scene, type);
+       /* editor level activate, notifiers */
+       ED_base_object_activate(C, BASACT);
+
+       /* more editor stuff */
+       ED_object_base_init_from_view(C, BASACT);
+
+       DAG_scene_sort(scene);
+
+       return ob;
+}
+
+/* for object add operator */
+static int object_add_exec(bContext *C, wmOperator *op)
+{
+       object_add_type(C, RNA_int_get(op->ptr, "type"));
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Object";
+       ot->description = "Add an object to the scene.";
+       ot->idname= "OBJECT_OT_add";
+       
+       /* api callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= object_add_exec;
+       
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", object_type_items, 0, "Type", "");
+}
+
+/* ***************** add primitives *************** */
+/* ******  work both in and outside editmode ****** */
+
+static EnumPropertyItem prop_mesh_types[] = {
+       {0, "PLANE", ICON_MESH_PLANE, "Plane", ""},
+       {1, "CUBE", ICON_MESH_CUBE, "Cube", ""},
+       {2, "CIRCLE", ICON_MESH_CIRCLE, "Circle", ""},
+       {3, "UVSPHERE", ICON_MESH_UVSPHERE, "UVsphere", ""},
+       {4, "ICOSPHERE", ICON_MESH_ICOSPHERE, "Icosphere", ""},
+       {5, "CYLINDER", ICON_MESH_TUBE, "Cylinder", ""},
+       {6, "CONE", ICON_MESH_CONE, "Cone", ""},
+       {0, "", 0, NULL, NULL},
+       {7, "GRID", ICON_MESH_GRID, "Grid", ""},
+       {8, "MONKEY", ICON_MESH_MONKEY, "Monkey", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int object_add_mesh_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       int newob= 0;
+       
+       if(obedit==NULL || obedit->type!=OB_MESH) {
+               object_add_type(C, OB_MESH);
+               ED_object_enter_editmode(C, EM_DO_UNDO);
+               newob = 1;
+       }
+       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+
+       switch(RNA_enum_get(op->ptr, "type")) {
+               case 0:
+                       WM_operator_name_call(C, "MESH_OT_primitive_plane_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+               case 1:
+                       WM_operator_name_call(C, "MESH_OT_primitive_cube_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+               case 2:
+                       WM_operator_name_call(C, "MESH_OT_primitive_circle_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+               case 3:
+                       WM_operator_name_call(C, "MESH_OT_primitive_uv_sphere_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+               case 4:
+                       WM_operator_name_call(C, "MESH_OT_primitive_ico_sphere_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+               case 5:
+                       WM_operator_name_call(C, "MESH_OT_primitive_cylinder_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+               case 6:
+                       WM_operator_name_call(C, "MESH_OT_primitive_cone_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+               case 7:
+                       WM_operator_name_call(C, "MESH_OT_primitive_grid_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+               case 8:
+                       WM_operator_name_call(C, "MESH_OT_primitive_monkey_add", WM_OP_INVOKE_REGION_WIN, NULL);
+                       break;
+       }
+       /* userdef */
+       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+               ED_object_exit_editmode(C, EM_FREEDATA);
+       }
+       
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+       
+       return OPERATOR_FINISHED;
+}
+
+
+void OBJECT_OT_mesh_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Mesh";
+       ot->description = "Add a mesh object to the scene.";
+       ot->idname= "OBJECT_OT_mesh_add";
+       
+       /* api callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= object_add_mesh_exec;
+       
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags: no register or undo, this operator calls operators */
+       ot->flag= 0; //OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", prop_mesh_types, 0, "Primitive", "");
+}
+
+static EnumPropertyItem prop_curve_types[] = {
+       {CU_BEZIER|CU_PRIM_CURVE, "BEZIER_CURVE", ICON_CURVE_BEZCURVE, "Bezier Curve", ""},
+       {CU_BEZIER|CU_PRIM_CIRCLE, "BEZIER_CIRCLE", ICON_CURVE_BEZCIRCLE, "Bezier Circle", ""},
+       {CU_NURBS|CU_PRIM_CURVE, "NURBS_CURVE", ICON_CURVE_NCURVE, "NURBS Curve", ""},
+       {CU_NURBS|CU_PRIM_CIRCLE, "NURBS_CIRCLE", ICON_CURVE_NCIRCLE, "NURBS Circle", ""},
+       {CU_NURBS|CU_PRIM_PATH, "PATH", ICON_CURVE_PATH, "Path", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int object_add_curve_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       ListBase *editnurb;
+       Nurb *nu;
+       int newob= 0;
+       
+       if(obedit==NULL || obedit->type!=OB_CURVE) {
+               object_add_type(C, OB_CURVE);
+               ED_object_enter_editmode(C, 0);
+               newob = 1;
+       }
+       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+       
+       obedit= CTX_data_edit_object(C);
+       nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
+       editnurb= curve_get_editcurve(obedit);
+       BLI_addtail(editnurb, nu);
+       
+       /* userdef */
+       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+               ED_object_enter_editmode(C, 0);
+               ED_object_exit_editmode(C, EM_FREEDATA);
+       }
+       
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+       
+       return OPERATOR_FINISHED;
+}
+
+static int object_add_curve_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       uiPopupMenu *pup;
+       uiLayout *layout;
+
+       pup= uiPupMenuBegin(C, op->type->name, 0);
+       layout= uiPupMenuLayout(pup);
+       if(!obedit || obedit->type == OB_CURVE)
+               uiItemsEnumO(layout, op->type->idname, "type");
+       else
+               uiItemsEnumO(layout, "OBJECT_OT_surface_add", "type");
+       uiPupMenuEnd(C, pup);
+
+       return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_curve_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Curve";
+       ot->description = "Add a curve object to the scene.";
+       ot->idname= "OBJECT_OT_curve_add";
+       
+       /* api callbacks */
+       ot->invoke= object_add_curve_invoke;
+       ot->exec= object_add_curve_exec;
+       
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", prop_curve_types, 0, "Primitive", "");
+}
+
+static EnumPropertyItem prop_surface_types[]= {
+       {CU_PRIM_CURVE|CU_NURBS, "NURBS_CURVE", ICON_SURFACE_NCURVE, "NURBS Curve", ""},
+       {CU_PRIM_CIRCLE|CU_NURBS, "NURBS_CIRCLE", ICON_SURFACE_NCIRCLE, "NURBS Circle", ""},
+       {CU_PRIM_PATCH|CU_NURBS, "NURBS_SURFACE", ICON_SURFACE_NSURFACE, "NURBS Surface", ""},
+       {CU_PRIM_TUBE|CU_NURBS, "NURBS_TUBE", ICON_SURFACE_NTUBE, "NURBS Tube", ""},
+       {CU_PRIM_SPHERE|CU_NURBS, "NURBS_SPHERE", ICON_SURFACE_NSPHERE, "NURBS Sphere", ""},
+       {CU_PRIM_DONUT|CU_NURBS, "NURBS_DONUT", ICON_SURFACE_NDONUT, "NURBS Donut", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int object_add_surface_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       ListBase *editnurb;
+       Nurb *nu;
+       int newob= 0;
+       
+       if(obedit==NULL || obedit->type!=OB_SURF) {
+               object_add_type(C, OB_SURF);
+               ED_object_enter_editmode(C, 0);
+               newob = 1;
+       }
+       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+       
+       obedit= CTX_data_edit_object(C);
+       nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
+       editnurb= curve_get_editcurve(obedit);
+       BLI_addtail(editnurb, nu);
+       
+       /* userdef */
+       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+               ED_object_exit_editmode(C, EM_FREEDATA);
+       }
+       
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_surface_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Surface";
+       ot->description = "Add a surface object to the scene.";
+       ot->idname= "OBJECT_OT_surface_add";
+       
+       /* api callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= object_add_surface_exec;
+       
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", prop_surface_types, 0, "Primitive", "");
+}
+
+static EnumPropertyItem prop_metaball_types[]= {
+       {MB_BALL, "MBALL_BALL", ICON_META_BALL, "Meta Ball", ""},
+       {MB_TUBE, "MBALL_TUBE", ICON_META_TUBE, "Meta Tube", ""},
+       {MB_PLANE, "MBALL_PLANE", ICON_META_PLANE, "Meta Plane", ""},
+       {MB_CUBE, "MBALL_CUBE", ICON_META_CUBE, "Meta Cube", ""},
+       {MB_ELIPSOID, "MBALL_ELLIPSOID", ICON_META_ELLIPSOID, "Meta Ellipsoid", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int object_metaball_add_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       MetaBall *mball;
+       MetaElem *elem;
+       int newob= 0;
+       
+       if(obedit==NULL || obedit->type!=OB_MBALL) {
+               object_add_type(C, OB_MBALL);
+               ED_object_enter_editmode(C, 0);
+               newob = 1;
+       }
+       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+       
+       obedit= CTX_data_edit_object(C);
+       elem= (MetaElem*)add_metaball_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
+       mball= (MetaBall*)obedit->data;
+       BLI_addtail(mball->editelems, elem);
+       
+       /* userdef */
+       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+               ED_object_exit_editmode(C, EM_FREEDATA);
+       }
+       
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+       
+       return OPERATOR_FINISHED;
+}
+
+static int object_metaball_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       uiPopupMenu *pup;
+       uiLayout *layout;
+
+       pup= uiPupMenuBegin(C, op->type->name, 0);
+       layout= uiPupMenuLayout(pup);
+       if(!obedit || obedit->type == OB_MBALL)
+               uiItemsEnumO(layout, op->type->idname, "type");
+       else
+               uiItemsEnumO(layout, "OBJECT_OT_metaball_add", "type");
+       uiPupMenuEnd(C, pup);
+
+       return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_metaball_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Metaball";
+       ot->description= "Add an metaball object to the scene.";
+       ot->idname= "OBJECT_OT_metaball_add";
+
+       /* api callbacks */
+       ot->invoke= object_metaball_add_invoke;
+       ot->exec= object_metaball_add_exec;
+       ot->poll= ED_operator_scene_editable;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", prop_metaball_types, 0, "Primitive", "");
+}
+static int object_add_text_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       
+       if(obedit && obedit->type==OB_FONT)
+               return OPERATOR_CANCELLED;
+
+       object_add_type(C, OB_FONT);
+       obedit= CTX_data_active_object(C);
+
+       if(U.flag & USER_ADD_EDITMODE)
+               ED_object_enter_editmode(C, 0);
+       
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_text_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Text";
+       ot->description = "Add a text object to the scene";
+       ot->idname= "OBJECT_OT_text_add";
+       
+       /* api callbacks */
+       ot->exec= object_add_text_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int object_armature_add_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       View3D *v3d= CTX_wm_view3d(C);
+       RegionView3D *rv3d= NULL;
+       int newob= 0;
+       
+       if ((obedit==NULL) || (obedit->type != OB_ARMATURE)) {
+               object_add_type(C, OB_ARMATURE);
+               ED_object_enter_editmode(C, 0);
+               newob = 1;
+       }
+       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+       
+       if(v3d) 
+               rv3d= CTX_wm_region(C)->regiondata;
+       
+       /* v3d and rv3d are allowed to be NULL */
+       add_primitive_bone(CTX_data_scene(C), v3d, rv3d);
+
+       /* userdef */
+       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+               ED_object_exit_editmode(C, EM_FREEDATA);
+       }
+       
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_armature_add(wmOperatorType *ot)
+{      
+       /* identifiers */
+       ot->name= "Add Armature";
+       ot->description = "Add an armature object to the scene.";
+       ot->idname= "OBJECT_OT_armature_add";
+       
+       /* api callbacks */
+       ot->exec= object_armature_add_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int object_primitive_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       uiPopupMenu *pup= uiPupMenuBegin(C, "Add Object", 0);
+       uiLayout *layout= uiPupMenuLayout(pup);
+       
+       uiItemMenuEnumO(layout, "Mesh", ICON_OUTLINER_OB_MESH, "OBJECT_OT_mesh_add", "type");
+       uiItemMenuEnumO(layout, "Curve", ICON_OUTLINER_OB_CURVE, "OBJECT_OT_curve_add", "type");
+       uiItemMenuEnumO(layout, "Surface", ICON_OUTLINER_OB_SURFACE, "OBJECT_OT_surface_add", "type");
+       uiItemMenuEnumO(layout, NULL, ICON_OUTLINER_OB_META, "OBJECT_OT_metaball_add", "type");
+       uiItemO(layout, "Text", ICON_OUTLINER_OB_FONT, "OBJECT_OT_text_add");
+       uiItemS(layout);
+       uiItemO(layout, "Armature", ICON_OUTLINER_OB_ARMATURE, "OBJECT_OT_armature_add");
+       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_LATTICE, "OBJECT_OT_add", "type", OB_LATTICE);
+       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_EMPTY, "OBJECT_OT_add", "type", OB_EMPTY);
+       uiItemS(layout);
+       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_CAMERA, "OBJECT_OT_add", "type", OB_CAMERA);
+       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_LAMP, "OBJECT_OT_add", "type", OB_LAMP);
+       
+       uiPupMenuEnd(C, pup);
+       
+       /* this operator is only for a menu, not used further */
+       return OPERATOR_CANCELLED;
+}
+
+/* only used as menu */
+void OBJECT_OT_primitive_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Primitive";
+       ot->description = "Add a primitive object.";
+       ot->idname= "OBJECT_OT_primitive_add";
+       
+       /* api callbacks */
+       ot->invoke= object_primitive_add_invoke;
+       
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= 0;
+}
+
+/**************************** Delete Object *************************/
+
+/* remove base from a specific scene */
+/* note: now unlinks constraints as well */
+void ED_base_object_free_and_unlink(Scene *scene, Base *base)
+{
+       BLI_remlink(&scene->base, base);
+       free_libblock_us(&G.main->object, base->object);
+       if(scene->basact==base) scene->basact= NULL;
+       MEM_freeN(base);
+}
+
+static int object_delete_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       int islamp= 0;
+       
+       if(CTX_data_edit_object(C)) 
+               return OPERATOR_CANCELLED;
+       
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+
+               if(base->object->type==OB_LAMP) islamp= 1;
+               
+               /* remove from current scene only */
+               ED_base_object_free_and_unlink(scene, base);
+       }
+       CTX_DATA_END;
+
+       if(islamp) reshadeall_displist(scene);  /* only frees displist */
+       
+       DAG_scene_sort(scene);
+       ED_anim_dag_flush_update(C);
+       
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, CTX_data_scene(C));
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_delete(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Delete";
+       ot->description = "Delete selected objects.";
+       ot->idname= "OBJECT_OT_delete";
+       
+       /* api callbacks */
+       ot->invoke= WM_operator_confirm;
+       ot->exec= object_delete_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/**************************** Copy Utilities ******************************/
+
+static void copy_object__forwardModifierLinks(void *userData, Object *ob,
+                                              ID **idpoin)
+{
+       /* this is copied from ID_NEW; it might be better to have a macro */
+       if(*idpoin && (*idpoin)->newid) *idpoin = (*idpoin)->newid;
+}
+
+/* after copying objects, copied data should get new pointers */
+static void copy_object_set_idnew(bContext *C, int dupflag)
+{
+       Object *ob;
+       Material *ma, *mao;
+       ID *id;
+#if 0 // XXX old animation system
+       Ipo *ipo;
+       bActionStrip *strip;
+#endif // XXX old animation system
+       int a;
+       
+       /* XXX check object pointers */
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+               ob= base->object;
+               relink_constraints(&ob->constraints);
+               if (ob->pose){
+                       bPoseChannel *chan;
+                       for (chan = ob->pose->chanbase.first; chan; chan=chan->next){
+                               relink_constraints(&chan->constraints);
+                       }
+               }
+               modifiers_foreachIDLink(ob, copy_object__forwardModifierLinks, NULL);
+               ID_NEW(ob->parent);
+               ID_NEW(ob->track);
+               ID_NEW(ob->proxy);
+               ID_NEW(ob->proxy_group);
+               
+#if 0 // XXX old animation system
+               for(strip= ob->nlastrips.first; strip; strip= strip->next) {
+                       bActionModifier *amod;
+                       for(amod= strip->modifiers.first; amod; amod= amod->next)
+                               ID_NEW(amod->ob);
+               }
+#endif // XXX old animation system
+       }
+       CTX_DATA_END;
+       
+       /* materials */
+       if( dupflag & USER_DUP_MAT) {
+               mao= G.main->mat.first;
+               while(mao) {
+                       if(mao->id.newid) {
+                               
+                               ma= (Material *)mao->id.newid;
+                               
+                               if(dupflag & USER_DUP_TEX) {
+                                       for(a=0; a<MAX_MTEX; a++) {
+                                               if(ma->mtex[a]) {
+                                                       id= (ID *)ma->mtex[a]->tex;
+                                                       if(id) {
+                                                               ID_NEW_US(ma->mtex[a]->tex)
+                                                               else ma->mtex[a]->tex= copy_texture(ma->mtex[a]->tex);
+                                                               id->us--;
+                                                       }
+                                               }
+                                       }
+                               }
+#if 0 // XXX old animation system
+                               id= (ID *)ma->ipo;
+                               if(id) {
+                                       ID_NEW_US(ma->ipo)
+                                       else ma->ipo= copy_ipo(ma->ipo);
+                                       id->us--;
+                               }
+#endif // XXX old animation system
+                       }
+                       mao= mao->id.next;
+               }
+       }
+       
+#if 0 // XXX old animation system
+       /* lamps */
+       if( dupflag & USER_DUP_IPO) {
+               Lamp *la= G.main->lamp.first;
+               while(la) {
+                       if(la->id.newid) {
+                               Lamp *lan= (Lamp *)la->id.newid;
+                               id= (ID *)lan->ipo;
+                               if(id) {
+                                       ID_NEW_US(lan->ipo)
+                                       else lan->ipo= copy_ipo(lan->ipo);
+                                       id->us--;
+                               }
+                       }
+                       la= la->id.next;
+               }
+       }
+       
+       /* ipos */
+       ipo= G.main->ipo.first;
+       while(ipo) {
+               if(ipo->id.lib==NULL && ipo->id.newid) {
+                       Ipo *ipon= (Ipo *)ipo->id.newid;
+                       IpoCurve *icu;
+                       for(icu= ipon->curve.first; icu; icu= icu->next) {
+                               if(icu->driver) {
+                                       ID_NEW(icu->driver->ob);
+                               }
+                       }
+               }
+               ipo= ipo->id.next;
+       }
+#endif // XXX old animation system
+       
+       set_sca_new_poins();
+       
+       clear_id_newpoins();
+}
+
+/********************* Make Duplicates Real ************************/
+
+static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base)
+{
+       Base *basen;
+       Object *ob;
+       ListBase *lb;
+       DupliObject *dob;
+       
+       if(!base && !(base = BASACT))
+               return;
+       
+       if(!(base->object->transflag & OB_DUPLI))
+               return;
+       
+       lb= object_duplilist(scene, base->object);
+       
+       for(dob= lb->first; dob; dob= dob->next) {
+               ob= copy_object(dob->ob);
+               /* font duplis can have a totcol without material, we get them from parent
+               * should be implemented better...
+               */
+               if(ob->mat==NULL) ob->totcol= 0;
+               
+               basen= MEM_dupallocN(base);
+               basen->flag &= ~OB_FROMDUPLI;
+               BLI_addhead(&scene->base, basen);       /* addhead: othwise eternal loop */
+               basen->object= ob;
+               ob->ipo= NULL;          /* make sure apply works */
+               ob->parent= ob->track= NULL;
+               ob->disp.first= ob->disp.last= NULL;
+               ob->transflag &= ~OB_DUPLI;     
+               
+               Mat4CpyMat4(ob->obmat, dob->mat);
+               ED_object_apply_obmat(ob);
+       }
+       
+       copy_object_set_idnew(C, 0);
+       
+       free_object_duplilist(lb);
+       
+       base->object->transflag &= ~OB_DUPLI;   
+}
+
+static int object_duplicates_make_real_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       
+       clear_id_newpoins();
+               
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+               make_object_duplilist_real(C, scene, base);
+       }
+       CTX_DATA_END;
+
+       DAG_scene_sort(scene);
+       ED_anim_dag_flush_update(C);    
+       WM_event_add_notifier(C, NC_SCENE, scene);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
+{
+       
+       /* identifiers */
+       ot->name= "Make Duplicates Real";
+       ot->description = "Make dupli objects attached to this object real.";
+       ot->idname= "OBJECT_OT_duplicates_make_real";
+       
+       /* api callbacks */
+       ot->invoke= WM_operator_confirm;
+       ot->exec= object_duplicates_make_real_exec;
+       
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/**************************** Convert **************************/
+
+static EnumPropertyItem convert_target_items[]= {
+       {OB_CURVE, "CURVE", 0, "Curve", ""},
+       {OB_MESH, "MESH", 0, "Mesh", ""},
+       {0, NULL, 0, NULL, NULL}};
+
+static void curvetomesh(Scene *scene, Object *ob) 
+{
+       Curve *cu= ob->data;
+       
+       if(cu->disp.first==0)
+               makeDispListCurveTypes(scene, ob, 0); /* force creation */
+
+       nurbs_to_mesh(ob); /* also does users */
+
+       if(ob->type == OB_MESH)
+               object_free_modifiers(ob);
+}
+
+static int convert_poll(bContext *C)
+{
+       Object *obact= CTX_data_active_object(C);
+       Scene *scene= CTX_data_scene(C);
+
+       return (!scene->id.lib && obact && scene->obedit != obact && (obact->flag & SELECT));
+}
+
+static int convert_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Base *basen=NULL, *basact, *basedel=NULL;
+       Object *ob, *ob1, *obact= CTX_data_active_object(C);
+       DerivedMesh *dm;
+       Curve *cu;
+       Nurb *nu;
+       MetaBall *mb;
+       Mesh *me;
+       int target= RNA_enum_get(op->ptr, "target");
+       int keep_original= RNA_boolean_get(op->ptr, "keep_original");
+       int a;
+       
+       /* don't forget multiple users! */
+
+       /* reset flags */
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+               ob= base->object;
+               ob->flag &= ~OB_DONE;
+       }
+       CTX_DATA_END;
+
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+               ob= base->object;
+               
+               if(ob->flag & OB_DONE)
+                       continue;
+               else if(ob->type==OB_MESH && ob->modifiers.first) { /* converting a mesh with no modifiers causes a segfault */
+                       ob->flag |= OB_DONE;
+                       basedel = base;
+
+                       ob1= copy_object(ob);
+                       ob1->recalc |= OB_RECALC;
+
+                       basen= MEM_mallocN(sizeof(Base), "duplibase");
+                       *basen= *base;
+                       BLI_addhead(&scene->base, basen);       /* addhead: otherwise eternal loop */
+                       basen->object= ob1;
+                       basen->flag |= SELECT;
+                       base->flag &= ~SELECT;
+                       ob->flag &= ~SELECT;
+
+                       /* decrement original mesh's usage count  */
+                       me= ob1->data;
+                       me->id.us--;
+
+                       /* make a new copy of the mesh */
+                       ob1->data= copy_mesh(me);
+
+                       /* make new mesh data from the original copy */
+                       dm= mesh_get_derived_final(scene, ob1, CD_MASK_MESH);
+                       /* dm= mesh_create_derived_no_deform(ob1, NULL);        this was called original (instead of get_derived). man o man why! (ton) */
+                       
+                       DM_to_mesh(dm, ob1->data);
+
+                       dm->release(dm);
+                       object_free_modifiers(ob1);     /* after derivedmesh calls! */
+               }
+               else if(ob->type==OB_FONT) {
+                       ob->flag |= OB_DONE;
+
+                       ob->type= OB_CURVE;
+                       cu= ob->data;
+
+                       if(cu->vfont) {
+                               cu->vfont->id.us--;
+                               cu->vfont= 0;
+                       }
+                       if(cu->vfontb) {
+                               cu->vfontb->id.us--;
+                               cu->vfontb= 0;
+                       }
+                       if(cu->vfonti) {
+                               cu->vfonti->id.us--;
+                               cu->vfonti= 0;
+                       }
+                       if(cu->vfontbi) {
+                               cu->vfontbi->id.us--;
+                               cu->vfontbi= 0;
+                       }                                       
+                       /* other users */
+                       if(cu->id.us>1) {
+                               for(ob1= G.main->object.first; ob1; ob1=ob1->id.next) {
+                                       if(ob1->data==cu) {
+                                               ob1->type= OB_CURVE;
+                                               ob1->recalc |= OB_RECALC;
+                                       }
+                               }
+                       }
+
+                       for(nu=cu->nurb.first; nu; nu=nu->next)
+                               nu->charidx= 0;
+
+                       if(target == OB_MESH)
+                               curvetomesh(scene, ob);
+               }
+               else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
+                       ob->flag |= OB_DONE;
+
+                       if(target == OB_MESH)
+                               curvetomesh(scene, ob);
+               }
+               else if(ob->type==OB_MBALL) {
+                       ob= find_basis_mball(scene, ob);
+                       
+                       if(ob->disp.first && !(ob->flag & OB_DONE)) {
+                               ob->flag |= OB_DONE;
+                               basedel = base;
+
+                               ob1= copy_object(ob);
+                               ob1->recalc |= OB_RECALC;
+
+                               basen= MEM_mallocN(sizeof(Base), "duplibase");
+                               *basen= *base;
+                               BLI_addhead(&scene->base, basen);       /* addhead: otherwise eternal loop */
+                               basen->object= ob1;
+                               basen->flag |= SELECT;
+                               basedel->flag &= ~SELECT;
+                               ob->flag &= ~SELECT;
+                               
+                               mb= ob1->data;
+                               mb->id.us--;
+                               
+                               ob1->data= add_mesh("Mesh");
+                               ob1->type= OB_MESH;
+                               
+                               me= ob1->data;
+                               me->totcol= mb->totcol;
+                               if(ob1->totcol) {
+                                       me->mat= MEM_dupallocN(mb->mat);
+                                       for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
+                               }
+                               
+                               mball_to_mesh(&ob->disp, ob1->data);
+                               
+                               /* So we can see the wireframe */
+                               BASACT= basen; // XXX hm
+                       }
+                       else
+                               continue;
+               }
+               else
+                       continue;
+
+               /* If the original object is active then make this object active */
+               if(basen) {
+                       if(ob == obact) {
+                               ED_base_object_activate(C, basen);
+                               basact = basen;
+                       }
+
+                       basen= NULL;
+               }
+
+               /* delete original if needed */
+               if(basedel) {
+                       if(!keep_original)
+                               ED_base_object_free_and_unlink(scene, basedel); 
+
+                       basedel = NULL;
+               }
+       }
+       CTX_DATA_END;
+       
+       /* delete object should renew depsgraph */
+       if(!keep_original)
+               DAG_scene_sort(scene);
+
+       /* texspace and normals */
+       if(!basen) BASACT= NULL; // XXX base;
+
+// XXX ED_object_enter_editmode(C, 0);
+// XXX exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR); /* freedata, but no undo */
+       BASACT= basact;
+
+       DAG_scene_sort(scene);
+       WM_event_add_notifier(C, NC_SCENE, scene);
+
+       return OPERATOR_FINISHED;
+}
+
+static int convert_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       Object *obact= CTX_data_active_object(C);
+       uiPopupMenu *pup;
+       uiLayout *layout;
+       char *title;
+
+       if(obact->type==OB_FONT) {
+               pup= uiPupMenuBegin(C, "Convert Font to", 0);
+               layout= uiPupMenuLayout(pup);
+
+               uiItemEnumO(layout, "Curve", 0, op->type->idname, "target", OB_CURVE);
+       }
+       else {
+               if(obact->type == OB_MBALL)
+                       title= "Convert Metaball to";
+               else if(obact->type == OB_CURVE)
+                       title= "Convert Curve to";
+               else if(obact->type == OB_SURF)
+                       title= "Convert Nurbs Surface to";
+               else if(obact->type == OB_MESH)
+                       title= "Convert Modifiers to";
+               else
+                       return OPERATOR_CANCELLED;
+
+               pup= uiPupMenuBegin(C, title, 0);
+               layout= uiPupMenuLayout(pup);
+       }
+
+       uiItemBooleanO(layout, "Mesh (keep original)", 0, op->type->idname, "keep_original", 1);
+       uiItemBooleanO(layout, "Mesh (delete original)", 0, op->type->idname, "keep_original", 0);
+
+       uiPupMenuEnd(C, pup);
+
+       return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_convert(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Convert";
+       ot->description = "Convert selected objects to another type.";
+       ot->idname= "OBJECT_OT_convert";
+       
+       /* api callbacks */
+       ot->invoke= convert_invoke;
+       ot->exec= convert_exec;
+       ot->poll= convert_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* properties */
+       RNA_def_enum(ot->srna, "target", convert_target_items, OB_MESH, "Target", "Type of object to convert to.");
+       RNA_def_boolean(ot->srna, "keep_original", 0, "Keep Original", "Keep original objects instead of replacing them.");
+}
+
+/************************** Add Duplicate **********************/
+
+/* 
+       dupflag: a flag made from constants declared in DNA_userdef_types.h
+       The flag tells adduplicate() weather to copy data linked to the object, or to reference the existing data.
+       U.dupflag for default operations or you can construct a flag as python does
+       if the dupflag is 0 then no data will be copied (linked duplicate) */
+
+/* used below, assumes id.new is correct */
+/* leaves selection of base/object unaltered */
+static Base *object_add_duplicate_internal(Scene *scene, Base *base, int dupflag)
+{
+       Base *basen= NULL;
+       Material ***matarar;
+       Object *ob, *obn;
+       ID *id;
+       int a, didit;
+
+       ob= base->object;
+       if(ob->mode & OB_MODE_POSE) {
+               ; /* nothing? */
+       }
+       else {
+               obn= copy_object(ob);
+               obn->recalc |= OB_RECALC;
+               
+               basen= MEM_mallocN(sizeof(Base), "duplibase");
+               *basen= *base;
+               BLI_addhead(&scene->base, basen);       /* addhead: prevent eternal loop */
+               basen->object= obn;
+               
+               if(basen->flag & OB_FROMGROUP) {
+                       Group *group;
+                       for(group= G.main->group.first; group; group= group->id.next) {
+                               if(object_in_group(ob, group))
+                                       add_to_group(group, obn);
+                       }
+                       obn->flag |= OB_FROMGROUP; /* this flag is unset with copy_object() */
+               }
+               
+               /* duplicates using userflags */
+#if 0 // XXX old animation system                              
+               if(dupflag & USER_DUP_IPO) {
+                       bConstraintChannel *chan;
+                       id= (ID *)obn->ipo;
+                       
+                       if(id) {
+                               ID_NEW_US( obn->ipo)
+                               else obn->ipo= copy_ipo(obn->ipo);
+                               id->us--;
+                       }
+                       /* Handle constraint ipos */
+                       for (chan=obn->constraintChannels.first; chan; chan=chan->next){
+                               id= (ID *)chan->ipo;
+                               if(id) {
+                                       ID_NEW_US( chan->ipo)
+                                       else chan->ipo= copy_ipo(chan->ipo);
+                                       id->us--;
+                               }
+                       }
+               }
+               if(dupflag & USER_DUP_ACT){ /* Not buttons in the UI to modify this, add later? */
+                       id= (ID *)obn->action;
+                       if (id){
+                               ID_NEW_US(obn->action)
+                               else{
+                                       obn->action= copy_action(obn->action);
+                               }
+                               id->us--;
+                       }
+               }
+#endif // XXX old animation system
+               if(dupflag & USER_DUP_MAT) {
+                       for(a=0; a<obn->totcol; a++) {
+                               id= (ID *)obn->mat[a];
+                               if(id) {
+                                       ID_NEW_US(obn->mat[a])
+                                       else obn->mat[a]= copy_material(obn->mat[a]);
+                                       id->us--;
+                               }
+                       }
+               }
+               if(dupflag & USER_DUP_PSYS) {
+                       ParticleSystem *psys;
+                       for(psys=obn->particlesystem.first; psys; psys=psys->next) {
+                               id= (ID*) psys->part;
+                               if(id) {
+                                       ID_NEW_US(psys->part)
+                                       else psys->part= psys_copy_settings(psys->part);
+                                       id->us--;
+                               }
+                       }
+               }
+               
+               id= obn->data;
+               didit= 0;
+               
+               switch(obn->type) {
+                       case OB_MESH:
+                               if(dupflag & USER_DUP_MESH) {
+                                       ID_NEW_US2( obn->data )
+                                       else {
+                                               obn->data= copy_mesh(obn->data);
+                                               
+                                               if(obn->fluidsimSettings) {
+                                                       obn->fluidsimSettings->orgMesh = (Mesh *)obn->data;
+                                               }
+                                               
+                                               didit= 1;
+                                       }
+                                       id->us--;
+                               }
+                               break;
+                       case OB_CURVE:
+                               if(dupflag & USER_DUP_CURVE) {
+                                       ID_NEW_US2(obn->data )
+                                       else {
+                                               obn->data= copy_curve(obn->data);
+                                               didit= 1;
+                                       }
+                                       id->us--;
+                               }
+                               break;
+                       case OB_SURF:
+                               if(dupflag & USER_DUP_SURF) {
+                                       ID_NEW_US2( obn->data )
+                                       else {
+                                               obn->data= copy_curve(obn->data);
+                                               didit= 1;
+                                       }
+                                       id->us--;
+                               }
+                               break;
+                       case OB_FONT:
+                               if(dupflag & USER_DUP_FONT) {
+                                       ID_NEW_US2( obn->data )
+                                       else {
+                                               obn->data= copy_curve(obn->data);
+                                               didit= 1;
+                                       }
+                                       id->us--;
+                               }
+                               break;
+                       case OB_MBALL:
+                               if(dupflag & USER_DUP_MBALL) {
+                                       ID_NEW_US2(obn->data )
+                                       else {
+                                               obn->data= copy_mball(obn->data);
+                                               didit= 1;
+                                       }
+                                       id->us--;
+                               }
+                               break;
+                       case OB_LAMP:
+                               if(dupflag & USER_DUP_LAMP) {
+                                       ID_NEW_US2(obn->data )
+                                       else obn->data= copy_lamp(obn->data);
+                                       id->us--;
+                               }
+                               break;
+                               
+                       case OB_ARMATURE:
+                               obn->recalc |= OB_RECALC_DATA;
+                               if(obn->pose) obn->pose->flag |= POSE_RECALC;
+                                       
+                                       if(dupflag & USER_DUP_ARM) {
+                                               ID_NEW_US2(obn->data )
+                                               else {
+                                                       obn->data= copy_armature(obn->data);
+                                                       armature_rebuild_pose(obn, obn->data);
+                                                       didit= 1;
+                                               }
+                                               id->us--;
+                                       }
+                                               
+                                               break;
+                               
+                       case OB_LATTICE:
+                               if(dupflag!=0) {
+                                       ID_NEW_US2(obn->data )
+                                       else obn->data= copy_lattice(obn->data);
+                                       id->us--;
+                               }
+                               break;
+                       case OB_CAMERA:
+                               if(dupflag!=0) {
+                                       ID_NEW_US2(obn->data )
+                                       else obn->data= copy_camera(obn->data);
+                                       id->us--;
+                               }
+                               break;
+               }
+               
+               if(dupflag & USER_DUP_MAT) {
+                       matarar= give_matarar(obn);
+                       if(didit && matarar) {
+                               for(a=0; a<obn->totcol; a++) {
+                                       id= (ID *)(*matarar)[a];
+                                       if(id) {
+                                               ID_NEW_US( (*matarar)[a] )
+                                               else (*matarar)[a]= copy_material((*matarar)[a]);
+                                               
+                                               id->us--;
+                                       }
+                               }
+                       }
+               }
+       }
+       return basen;
+}
+
+/* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */
+/* leaves selection of base/object unaltered */
+Base *ED_object_add_duplicate(Scene *scene, Base *base, int dupflag)
+{
+       Base *basen;
+
+       clear_id_newpoins();
+       clear_sca_new_poins();  /* sensor/contr/act */
+       
+       basen= object_add_duplicate_internal(scene, base, dupflag);
+       
+       DAG_scene_sort(scene);
+       
+       return basen;
+}
+
+/* contextual operator dupli */
+static int duplicate_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       int linked= RNA_boolean_get(op->ptr, "linked");
+       int dupflag= (linked)? 0: U.dupflag;
+       
+       clear_id_newpoins();
+       clear_sca_new_poins();  /* sensor/contr/act */
+       
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+               Base *basen= object_add_duplicate_internal(scene, base, dupflag);
+               
+               /* note that this is safe to do with this context iterator,
+                  the list is made in advance */
+               ED_base_object_select(base, BA_DESELECT);
+
+               /* new object becomes active */
+               if(BASACT==base)
+                       ED_base_object_activate(C, basen);
+               
+       }
+       CTX_DATA_END;
+
+       copy_object_set_idnew(C, dupflag);
+
+       DAG_scene_sort(scene);
+       ED_anim_dag_flush_update(C);    
+
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
+
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_duplicate(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Duplicate";
+       ot->description = "Duplicate selected objects.";
+       ot->idname= "OBJECT_OT_duplicate";
+       
+       /* api callbacks */
+       ot->exec= duplicate_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* to give to transform */
+       RNA_def_boolean(ot->srna, "linked", 0, "Linked", "Duplicate object but not object data, linking to the original data.");
+       RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
+}
+
+/**************************** Join *************************/
+
+static int join_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+
+       if(scene->obedit) {
+               BKE_report(op->reports, RPT_ERROR, "This data does not support joining in editmode.");
+               return OPERATOR_CANCELLED;
+       }
+       else if(!ob) {
+               BKE_report(op->reports, RPT_ERROR, "Can't join unless there is an active object.");
+               return OPERATOR_CANCELLED;
+       }
+       else if(object_data_is_libdata(ob)) {
+               BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata.");
+               return OPERATOR_CANCELLED;
+       }
+
+       if(ob->type == OB_MESH)
+               return join_mesh_exec(C, op);
+       else if(ELEM(ob->type, OB_CURVE, OB_SURF))
+               return join_curve_exec(C, op);
+       else if(ob->type == OB_ARMATURE)
+               return join_armature_exec(C, op);
+
+       BKE_report(op->reports, RPT_ERROR, "This object type doesn't support joining.");
+
+       return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_join(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Join";
+       ot->description = "Join selected objects into active object.";
+       ot->idname= "OBJECT_OT_join";
+       
+       /* api callbacks */
+       ot->exec= join_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
similarity index 99%
rename from source/blender/editors/object/editconstraint.c
rename to source/blender/editors/object/object_constraint.c
index c1b1062bfc4ae76d5426d402e284177a8b4d8b8b..9b073ed58780b89a56c9261f2a0bd86a299a172a 100644 (file)
@@ -76,9 +76,6 @@
 
 #include "object_intern.h"
 
-/* XXX */
-static int pupmenu() {return 0;}
-
 /* -------------- Get Active Constraint Data ---------------------- */
 
 /* if object in posemode, active bone constraints, else object constraints */
@@ -1107,7 +1104,7 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase
 #ifndef DISABLE_PYTHON
                        /* popup a list of usable scripts */
                        menustr = buildmenu_pyconstraints(NULL, &scriptint);
-                       scriptint = pupmenu(menustr);
+                       // XXX scriptint = pupmenu(menustr);
                        MEM_freeN(menustr);
                        
                        /* only add constraint if a script was chosen */
@@ -1416,3 +1413,4 @@ void POSE_OT_ik_clear(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
+
index 31a604a79df3e83b038983fe0ca547d01561f9c1..daa63da03db9104f8f0a392d37c77d226c519ab0 100644 (file)
 static void error() {}
 static void waitcursor(int val) {}
 static int pupmenu(const char *msg) {return 0;}
-static int pupmenu_col(const char *msg, int val) {return 0;}
-static int okee(const char *msg) {return 0;}
 
 /* port over here */
 static bContext *C;
@@ -156,6636 +154,1433 @@ static void error_libdata() {}
 
 /* --------------------------------- */
 
-/* simple API for object selection, rather than just using the flag
- * this takes into account the 'restrict selection in 3d view' flag.
- * deselect works always, the restriction just prevents selection */
-
-/* Note: send a NC_SCENE|ND_OB_SELECT notifier yourself! */
-
-void ED_base_object_select(Base *base, short mode)
-{
-       if (base) {
-               if (mode==BA_SELECT) {
-                       if (!(base->object->restrictflag & OB_RESTRICT_SELECT))
-                               if (mode==BA_SELECT) base->flag |= SELECT;
-               }
-               else if (mode==BA_DESELECT) {
-                       base->flag &= ~SELECT;
-               }
-               base->object->flag= base->flag;
-       }
-}
-
-/* also to set active NULL */
-void ED_base_object_activate(bContext *C, Base *base)
+void ED_object_apply_obmat(Object *ob)
 {
-       Scene *scene= CTX_data_scene(C);
-       Base *tbase;
+       float mat[3][3], imat[3][3], tmat[3][3];
        
-       /* sets scene->basact */
-       BASACT= base;
+       /* from obmat to loc rot size */
        
-       if(base) {
-               
-               /* XXX old signals, remember to handle notifiers now! */
-               //              select_actionchannel_by_name(base->object->action, "Object", 1);
-               
-               /* disable temporal locks */
-               for(tbase=FIRSTBASE; tbase; tbase= tbase->next) {
-                       if(base!=tbase && (tbase->object->shapeflag & OB_SHAPE_TEMPLOCK)) {
-                               tbase->object->shapeflag &= ~OB_SHAPE_TEMPLOCK;
-                               DAG_id_flush_update(&tbase->object->id, OB_RECALC_DATA);
-                       }
-               }
-               WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
-       }
-       else
-               WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, NULL);
-}
+       if(ob==NULL) return;
+       Mat3CpyMat4(mat, ob->obmat);
+       
+       VECCOPY(ob->loc, ob->obmat[3]);
 
+       Mat3ToEul(mat, ob->rot);
+       EulToMat3(ob->rot, tmat);
 
-/* exported */
-void ED_object_base_init_from_view(bContext *C, Base *base)
-{
-       View3D *v3d= CTX_wm_view3d(C);
-       Scene *scene= CTX_data_scene(C);
-       Object *ob= base->object;
+       Mat3Inv(imat, tmat);
        
-       if (scene==NULL)
-               return;
+       Mat3MulMat3(tmat, imat, mat);
+       
+       ob->size[0]= tmat[0][0];
+       ob->size[1]= tmat[1][1];
+       ob->size[2]= tmat[2][2];
        
-       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) {
-                       ARegion *ar= CTX_wm_region(C);
-                       if(ar) {
-                               RegionView3D *rv3d= ar->regiondata;
-                               
-                               rv3d->viewquat[0]= -rv3d->viewquat[0];
-                               QuatToEul(rv3d->viewquat, ob->rot);
-                               rv3d->viewquat[0]= -rv3d->viewquat[0];
-                       }
-               }
-       }
-       where_is_object(scene, ob);
-}
-
-/* ******************* add object operator ****************** */
-
-static EnumPropertyItem prop_object_types[] = {
-       {OB_MESH, "MESH", 0, "Mesh", ""},
-       {OB_CURVE, "CURVE", 0, "Curve", ""},
-       {OB_SURF, "SURFACE", 0, "Surface", ""},
-       {OB_MBALL, "META", 0, "Meta", ""},
-       {OB_FONT, "TEXT", 0, "Text", ""},
-       {0, "", 0, NULL, NULL},
-       {OB_ARMATURE, "ARMATURE", 0, "Armature", ""},
-       {OB_LATTICE, "LATTICE", 0, "Lattice", ""},
-       {OB_EMPTY, "EMPTY", 0, "Empty", ""},
-       {0, "", 0, NULL, NULL},
-       {OB_CAMERA, "CAMERA", 0, "Camera", ""},
-       {OB_LAMP, "LAMP", 0, "Lamp", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-
-
-void add_object_draw(Scene *scene, View3D *v3d, int type)      /* for toolbox or menus, only non-editmode stuff */
-{
-       /* keep here to get things compile, remove later */
 }
 
-/* for object add primitive operators */
-static Object *object_add_type(bContext *C, int type)
+/* ********* clear/set restrict view *********/
+static int object_restrictview_clear_exec(bContext *C, wmOperator *op)
 {
+       ScrArea *sa= CTX_wm_area(C);
+       View3D *v3d= sa->spacedata.first;
        Scene *scene= CTX_data_scene(C);
-       Object *ob;
-       
-       /* for as long scene has editmode... */
-       if (CTX_data_edit_object(C)) 
-               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
+       Base *base;
+       int changed = 0;
        
-       /* deselects all, sets scene->basact */
-       ob= add_object(scene, type);
-       /* editor level activate, notifiers */
-       ED_base_object_activate(C, BASACT);
-
-       /* more editor stuff */
-       ED_object_base_init_from_view(C, BASACT);
-
-       DAG_scene_sort(scene);
-
-       return ob;
-}
+       /* XXX need a context loop to handle such cases */
+       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) {
+               DAG_scene_sort(scene);
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
+       }
 
-/* for object add operator */
-static int object_add_exec(bContext *C, wmOperator *op)
-{
-       object_add_type(C, RNA_int_get(op->ptr, "type"));
-       
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_object_add(wmOperatorType *ot)
+void OBJECT_OT_restrictview_clear(wmOperatorType *ot)
 {
+       
        /* identifiers */
-       ot->name= "Add Object";
-       ot->description = "Add an object to the scene.";
-       ot->idname= "OBJECT_OT_object_add";
+       ot->name= "Clear Restrict View";
+       ot->description = "Reveal the object by setting the restrictview flag.";
+       ot->idname= "OBJECT_OT_restrictview_clear";
        
        /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_add_exec;
-       
-       ot->poll= ED_operator_scene_editable;
+       ot->exec= object_restrictview_clear_exec;
+       ot->poll= ED_operator_view3d_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_object_types, 0, "Type", "");
 }
 
-/* ***************** add primitives *************** */
-/* ******  work both in and outside editmode ****** */
-
-static EnumPropertyItem prop_mesh_types[] = {
-       {0, "PLANE", ICON_MESH_PLANE, "Plane", ""},
-       {1, "CUBE", ICON_MESH_CUBE, "Cube", ""},
-       {2, "CIRCLE", ICON_MESH_CIRCLE, "Circle", ""},
-       {3, "UVSPHERE", ICON_MESH_UVSPHERE, "UVsphere", ""},
-       {4, "ICOSPHERE", ICON_MESH_ICOSPHERE, "Icosphere", ""},
-       {5, "CYLINDER", ICON_MESH_TUBE, "Cylinder", ""},
-       {6, "CONE", ICON_MESH_CONE, "Cone", ""},
-       {0, "", 0, NULL, NULL},
-       {7, "GRID", ICON_MESH_GRID, "Grid", ""},
-       {8, "MONKEY", ICON_MESH_MONKEY, "Monkey", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-static int object_add_mesh_exec(bContext *C, wmOperator *op)
+static int object_restrictview_set_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       int newob= 0;
+       Scene *scene= CTX_data_scene(C);
+       short changed = 0;
+       int unselected= RNA_boolean_get(op->ptr, "unselected");
        
-       if(obedit==NULL || obedit->type!=OB_MESH) {
-               object_add_type(C, OB_MESH);
-               ED_object_enter_editmode(C, EM_DO_UNDO);
-               newob = 1;
-       }
-       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
-
-       switch(RNA_enum_get(op->ptr, "type")) {
-               case 0:
-                       WM_operator_name_call(C, "MESH_OT_primitive_plane_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 1:
-                       WM_operator_name_call(C, "MESH_OT_primitive_cube_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 2:
-                       WM_operator_name_call(C, "MESH_OT_primitive_circle_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 3:
-                       WM_operator_name_call(C, "MESH_OT_primitive_uv_sphere_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 4:
-                       WM_operator_name_call(C, "MESH_OT_primitive_ico_sphere_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 5:
-                       WM_operator_name_call(C, "MESH_OT_primitive_cylinder_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 6:
-                       WM_operator_name_call(C, "MESH_OT_primitive_cone_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 7:
-                       WM_operator_name_call(C, "MESH_OT_primitive_grid_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 8:
-                       WM_operator_name_call(C, "MESH_OT_primitive_monkey_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
+       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+               if(!unselected) {
+                       if (base->flag & SELECT){
+                               base->flag &= ~SELECT;
+                               base->object->flag = base->flag;
+                               base->object->restrictflag |= OB_RESTRICT_VIEW;
+                               changed = 1;
+                               if (base==BASACT) {
+                                       ED_base_object_activate(C, NULL);
+                               }
+                       }
+               }
+               else {
+                       if (!(base->flag & SELECT)){
+                               base->object->restrictflag |= OB_RESTRICT_VIEW;
+                               changed = 1;
+                       }
+               }       
        }
-       /* userdef */
-       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+       CTX_DATA_END;
+
+       if (changed) {
+               DAG_scene_sort(scene);
+               
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
+               
        }
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
-       
+
        return OPERATOR_FINISHED;
 }
 
-
-void OBJECT_OT_mesh_add(wmOperatorType *ot)
+void OBJECT_OT_restrictview_set(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Add Mesh";
-       ot->description = "Add a mesh object to the scene.";
-       ot->idname= "OBJECT_OT_mesh_add";
+       ot->name= "Set Restrict View";
+       ot->description = "Hide the object by setting the restrictview flag.";
+       ot->idname= "OBJECT_OT_restrictview_set";
        
        /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_add_mesh_exec;
+       ot->exec= object_restrictview_set_exec;
+       ot->poll= ED_operator_view3d_active;
        
-       ot->poll= ED_operator_scene_editable;
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       /* flags: no register or undo, this operator calls operators */
-       ot->flag= 0; //OPTYPE_REGISTER|OPTYPE_UNDO;
+       RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects.");
        
-       RNA_def_enum(ot->srna, "type", prop_mesh_types, 0, "Primitive", "");
 }
 
-static EnumPropertyItem prop_curve_types[] = {
-       {CU_BEZIER|CU_PRIM_CURVE, "BEZIER_CURVE", ICON_CURVE_BEZCURVE, "Bezier Curve", ""},
-       {CU_BEZIER|CU_PRIM_CIRCLE, "BEZIER_CIRCLE", ICON_CURVE_BEZCIRCLE, "Bezier Circle", ""},
-       {CU_NURBS|CU_PRIM_CURVE, "NURBS_CURVE", ICON_CURVE_NCURVE, "NURBS Curve", ""},
-       {CU_NURBS|CU_PRIM_CIRCLE, "NURBS_CIRCLE", ICON_CURVE_NCIRCLE, "NURBS Circle", ""},
-       {CU_NURBS|CU_PRIM_PATH, "PATH", ICON_CURVE_PATH, "Path", ""},
-       {0, NULL, 0, NULL, NULL}
-};
 
-static int object_add_curve_exec(bContext *C, wmOperator *op)
+/* ******************* toggle editmode operator  ***************** */
+
+void ED_object_exit_editmode(bContext *C, int flag)
 {
+       Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb;
-       Nurb *nu;
-       int newob= 0;
-       
-       if(obedit==NULL || obedit->type!=OB_CURVE) {
-               object_add_type(C, OB_CURVE);
-               ED_object_enter_editmode(C, 0);
-               newob = 1;
-       }
-       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+       int freedata = flag & EM_FREEDATA;
        
-       obedit= CTX_data_edit_object(C);
-       nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
-       editnurb= curve_get_editcurve(obedit);
-       BLI_addtail(editnurb, nu);
+       if(obedit==NULL) return;
        
-       /* userdef */
-       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+       if(flag & EM_WAITCURSOR) waitcursor(1);
+       if(obedit->type==OB_MESH) {
+               Mesh *me= obedit->data;
+               
+//             if(EM_texFaceCheck())
+               
+//             if(retopo_mesh_paint_check())
+//                     retopo_end_okee();
+               
+               if(me->edit_mesh->totvert>MESH_MAX_VERTS) {
+                       error("Too many vertices");
+                       return;
+               }
+               load_editMesh(scene, obedit);
+               
+               if(freedata) {
+                       free_editMesh(me->edit_mesh);
+                       MEM_freeN(me->edit_mesh);
+                       me->edit_mesh= NULL;
+               }
+               
+               if(obedit->restore_mode & OB_MODE_WEIGHT_PAINT)
+                       mesh_octree_table(obedit, NULL, NULL, 'e');
+       }
+       else if (obedit->type==OB_ARMATURE) {   
+               ED_armature_from_edit(obedit);
+               if(freedata)
+                       ED_armature_edit_free(obedit);
+       }
+       else if(ELEM(obedit->type, OB_CURVE, OB_SURF)) {
+               load_editNurb(obedit);
+               if(freedata) free_editNurb(obedit);
+       }
+       else if(obedit->type==OB_FONT && freedata) {
+               load_editText(obedit);
+               if(freedata) free_editText(obedit);
+       }
+       else if(obedit->type==OB_LATTICE) {
+               load_editLatt(obedit);
+               if(freedata) free_editLatt(obedit);
+       }
+       else if(obedit->type==OB_MBALL) {
+               load_editMball(obedit);
+               if(freedata) free_editMball(obedit);
        }
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
-       
-       return OPERATOR_FINISHED;
-}
-
-static int object_add_curve_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       uiPopupMenu *pup;
-       uiLayout *layout;
-
-       pup= uiPupMenuBegin(C, op->type->name, 0);
-       layout= uiPupMenuLayout(pup);
-       if(!obedit || obedit->type == OB_CURVE)
-               uiItemsEnumO(layout, op->type->idname, "type");
-       else
-               uiItemsEnumO(layout, "OBJECT_OT_surface_add", "type");
-       uiPupMenuEnd(C, pup);
-
-       return OPERATOR_CANCELLED;
-}
 
-void OBJECT_OT_curve_add(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Add Curve";
-       ot->description = "Add a curve object to the scene.";
-       ot->idname= "OBJECT_OT_curve_add";
-       
-       /* api callbacks */
-       ot->invoke= object_add_curve_invoke;
-       ot->exec= object_add_curve_exec;
-       
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_curve_types, 0, "Primitive", "");
-}
+       /* freedata only 0 now on file saves */
+       if(freedata) {
+               /* for example; displist make is different in editmode */
+               scene->obedit= NULL; // XXX for context
+               
+               BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_DEPSGRAPH);
 
-static EnumPropertyItem prop_surface_types[]= {
-       {CU_PRIM_CURVE|CU_NURBS, "NURBS_CURVE", ICON_SURFACE_NCURVE, "NURBS Curve", ""},
-       {CU_PRIM_CIRCLE|CU_NURBS, "NURBS_CIRCLE", ICON_SURFACE_NCIRCLE, "NURBS Circle", ""},
-       {CU_PRIM_PATCH|CU_NURBS, "NURBS_SURFACE", ICON_SURFACE_NSURFACE, "NURBS Surface", ""},
-       {CU_PRIM_TUBE|CU_NURBS, "NURBS_TUBE", ICON_SURFACE_NTUBE, "NURBS Tube", ""},
-       {CU_PRIM_SPHERE|CU_NURBS, "NURBS_SPHERE", ICON_SURFACE_NSPHERE, "NURBS Sphere", ""},
-       {CU_PRIM_DONUT|CU_NURBS, "NURBS_DONUT", ICON_SURFACE_NDONUT, "NURBS Donut", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-static int object_add_surface_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       ListBase *editnurb;
-       Nurb *nu;
-       int newob= 0;
+               /* also flush ob recalc, doesn't take much overhead, but used for particles */
+               DAG_id_flush_update(&obedit->id, OB_RECALC_OB|OB_RECALC_DATA);
        
-       if(obedit==NULL || obedit->type!=OB_SURF) {
-               object_add_type(C, OB_SURF);
-               ED_object_enter_editmode(C, 0);
-               newob = 1;
-       }
-       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+               ED_undo_push(C, "Editmode");
        
-       obedit= CTX_data_edit_object(C);
-       nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
-       editnurb= curve_get_editcurve(obedit);
-       BLI_addtail(editnurb, nu);
+               if(flag & EM_WAITCURSOR) waitcursor(0);
        
-       /* userdef */
-       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
        }
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
-       
-       return OPERATOR_FINISHED;
+
+       obedit->mode &= ~OB_MODE_EDIT;
+       ED_object_toggle_modes(C, obedit->restore_mode);
 }
 
-void OBJECT_OT_surface_add(wmOperatorType *ot)
+
+void ED_object_enter_editmode(bContext *C, int flag)
 {
-       /* identifiers */
-       ot->name= "Add Surface";
-       ot->description = "Add a surface object to the scene.";
-       ot->idname= "OBJECT_OT_surface_add";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_add_surface_exec;
+       Scene *scene= CTX_data_scene(C);
+       Base *base= CTX_data_active_base(C);
+       Object *ob;
+       ScrArea *sa= CTX_wm_area(C);
+       View3D *v3d= NULL;
+       int ok= 0;
        
-       ot->poll= ED_operator_scene_editable;
+       if(scene->id.lib) return;
+       if(base==NULL) return;
        
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       if(sa && sa->spacetype==SPACE_VIEW3D)
+               v3d= sa->spacedata.first;
        
-       RNA_def_enum(ot->srna, "type", prop_surface_types, 0, "Primitive", "");
-}
+       if(v3d && (base->lay & v3d->lay)==0) return;
+       else if(!v3d && (base->lay & scene->lay)==0) return;
 
-static EnumPropertyItem prop_metaball_types[]= {
-       {MB_BALL, "MBALL_BALL", ICON_META_BALL, "Meta Ball", ""},
-       {MB_TUBE, "MBALL_TUBE", ICON_META_TUBE, "Meta Tube", ""},
-       {MB_PLANE, "MBALL_PLANE", ICON_META_PLANE, "Meta Plane", ""},
-       {MB_CUBE, "MBALL_CUBE", ICON_META_CUBE, "Meta Cube", ""},
-       {MB_ELIPSOID, "MBALL_ELLIPSOID", ICON_META_ELLIPSOID, "Meta Ellipsoid", ""},
-       {0, NULL, 0, NULL, NULL}
-};
+       ob = base->object;
 
-static int object_metaball_add_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       MetaBall *mball;
-       MetaElem *elem;
-       int newob= 0;
-       
-       if(obedit==NULL || obedit->type!=OB_MBALL) {
-               object_add_type(C, OB_MBALL);
-               ED_object_enter_editmode(C, 0);
-               newob = 1;
-       }
-       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
-       
-       obedit= CTX_data_edit_object(C);
-       elem= (MetaElem*)add_metaball_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
-       mball= (MetaBall*)obedit->data;
-       BLI_addtail(mball->editelems, elem);
+       if(ob==NULL) return;
+       if(ob->data==NULL) return;
        
-       /* userdef */
-       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+       if (object_data_is_libdata(ob)) {
+               error_libdata();
+               return;
        }
        
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
-       
-       return OPERATOR_FINISHED;
-}
-
-static int object_metaball_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       uiPopupMenu *pup;
-       uiLayout *layout;
-
-       pup= uiPupMenuBegin(C, op->type->name, 0);
-       layout= uiPupMenuLayout(pup);
-       if(!obedit || obedit->type == OB_MBALL)
-               uiItemsEnumO(layout, op->type->idname, "type");
-       else
-               uiItemsEnumO(layout, "OBJECT_OT_metaball_add", "type");
-       uiPupMenuEnd(C, pup);
-
-       return OPERATOR_CANCELLED;
-}
-
-void OBJECT_OT_metaball_add(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Metaball";
-       ot->description= "Add an metaball object to the scene.";
-       ot->idname= "OBJECT_OT_metaball_add";
+       if(flag & EM_WAITCURSOR) waitcursor(1);
 
-       /* api callbacks */
-       ot->invoke= object_metaball_add_invoke;
-       ot->exec= object_metaball_add_exec;
-       ot->poll= ED_operator_scene_editable;
+       ob->restore_mode = ob->mode;
+       ED_object_toggle_modes(C, ob->mode);
 
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_metaball_types, 0, "Primitive", "");
-}
-static int object_add_text_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
+       ob->mode |= OB_MODE_EDIT;
        
-       if(obedit && obedit->type==OB_FONT)
-               return OPERATOR_CANCELLED;
-
-       object_add_type(C, OB_FONT);
-       obedit= CTX_data_active_object(C);
+       if(ob->type==OB_MESH) {
+               Mesh *me= ob->data;
+               
+               if(me->pv) mesh_pmv_off(ob, me);
+               ok= 1;
+               scene->obedit= ob;      // context sees this
+               
+               make_editMesh(scene, ob);
 
-       if(U.flag & USER_ADD_EDITMODE)
-               ED_object_enter_editmode(C, 0);
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
-       
-       return OPERATOR_FINISHED;
-}
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MESH, scene);
+       }
+       else if (ob->type==OB_ARMATURE){
+               bArmature *arm= base->object->data;
+               if (!arm) return;
+               /*
+                * The function object_data_is_libdata make a problem here, the
+                * check for ob->proxy return 0 and let blender enter to edit mode
+                * this causa a crash when you try leave the edit mode.
+                * The problem is that i can't remove the ob->proxy check from
+                * object_data_is_libdata that prevent the bugfix #6614, so
+                * i add this little hack here.
+                */
+               if(arm->id.lib) {
+                       error_libdata();
+                       return;
+               }
+               ok=1;
+               scene->obedit= ob;
+               ED_armature_to_edit(ob);
+               /* to ensure all goes in restposition and without striding */
+               DAG_id_flush_update(&ob->id, OB_RECALC);
 
-void OBJECT_OT_text_add(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Add Text";
-       ot->description = "Add a text object to the scene";
-       ot->idname= "OBJECT_OT_text_add";
-       
-       /* api callbacks */
-       ot->exec= object_add_text_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_ARMATURE, scene);
+       }
+       else if(ob->type==OB_FONT) {
+               scene->obedit= ob; // XXX for context
+               ok= 1;
+               make_editText(ob);
 
-static int object_armature_add_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       View3D *v3d= CTX_wm_view3d(C);
-       RegionView3D *rv3d= NULL;
-       int newob= 0;
-       
-       if ((obedit==NULL) || (obedit->type != OB_ARMATURE)) {
-               object_add_type(C, OB_ARMATURE);
-               ED_object_enter_editmode(C, 0);
-               newob = 1;
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_TEXT, scene);
        }
-       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
-       
-       if(v3d) 
-               rv3d= CTX_wm_region(C)->regiondata;
-       
-       /* v3d and rv3d are allowed to be NULL */
-       add_primitive_bone(CTX_data_scene(C), v3d, rv3d);
+       else if(ob->type==OB_MBALL) {
+               scene->obedit= ob; // XXX for context
+               ok= 1;
+               make_editMball(ob);
 
-       /* userdef */
-       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MBALL, scene);
+       }
+       else if(ob->type==OB_LATTICE) {
+               scene->obedit= ob; // XXX for context
+               ok= 1;
+               make_editLatt(ob);
+               
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_LATTICE, scene);
+       }
+       else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
+               ok= 1;
+               scene->obedit= ob; // XXX for context
+               make_editNurb(ob);
+               
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_CURVE, scene);
        }
        
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+       if(ok) {
+               DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+       }
+       else {
+               scene->obedit= NULL; // XXX for context
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
+       }
        
-       return OPERATOR_FINISHED;
+       if(flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
+       if(flag & EM_WAITCURSOR) waitcursor(0);
 }
 
-void OBJECT_OT_armature_add(wmOperatorType *ot)
-{      
-       /* identifiers */
-       ot->name= "Add Armature";
-       ot->description = "Add an armature object to the scene.";
-       ot->idname= "OBJECT_OT_armature_add";
+static int editmode_toggle_exec(bContext *C, wmOperator *op)
+{
        
-       /* api callbacks */
-       ot->exec= object_armature_add_exec;
-       ot->poll= ED_operator_scene_editable;
+       if(!CTX_data_edit_object(C))
+               ED_object_enter_editmode(C, EM_WAITCURSOR);
+       else
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
        
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       return OPERATOR_FINISHED;
 }
 
-static int object_primitive_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int editmode_toggle_poll(bContext *C)
 {
-       uiPopupMenu *pup= uiPupMenuBegin(C, "Add Object", 0);
-       uiLayout *layout= uiPupMenuLayout(pup);
-       
-       uiItemMenuEnumO(layout, "Mesh", ICON_OUTLINER_OB_MESH, "OBJECT_OT_mesh_add", "type");
-       uiItemMenuEnumO(layout, "Curve", ICON_OUTLINER_OB_CURVE, "OBJECT_OT_curve_add", "type");
-       uiItemMenuEnumO(layout, "Surface", ICON_OUTLINER_OB_SURFACE, "OBJECT_OT_surface_add", "type");
-       uiItemMenuEnumO(layout, NULL, ICON_OUTLINER_OB_META, "OBJECT_OT_metaball_add", "type");
-       uiItemO(layout, "Text", ICON_OUTLINER_OB_FONT, "OBJECT_OT_text_add");
-       uiItemS(layout);
-       uiItemO(layout, "Armature", ICON_OUTLINER_OB_ARMATURE, "OBJECT_OT_armature_add");
-       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_LATTICE, "OBJECT_OT_object_add", "type", OB_LATTICE);
-       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_EMPTY, "OBJECT_OT_object_add", "type", OB_EMPTY);
-       uiItemS(layout);
-       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_CAMERA, "OBJECT_OT_object_add", "type", OB_CAMERA);
-       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_LAMP, "OBJECT_OT_object_add", "type", OB_LAMP);
-       
-       uiPupMenuEnd(C, pup);
-       
-       /* this operator is only for a menu, not used further */
-       return OPERATOR_CANCELLED;
+       Object *ob = CTX_data_active_object(C);
+
+       return ob && (ob->type == OB_MESH || ob->type == OB_ARMATURE ||
+                     ob->type == OB_FONT || ob->type == OB_MBALL ||
+                     ob->type == OB_LATTICE || ob->type == OB_SURF ||
+                     ob->type == OB_CURVE);
 }
 
-/* only used as menu */
-void OBJECT_OT_primitive_add(wmOperatorType *ot)
+void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
 {
+       
        /* identifiers */
-       ot->name= "Add Primitive";
-       ot->description = "Add a primitive object.";
-       ot->idname= "OBJECT_OT_primitive_add";
+       ot->name= "Toggle Editmode";
+       ot->description = "Toggle object's editmode.";
+       ot->idname= "OBJECT_OT_editmode_toggle";
        
        /* api callbacks */
-       ot->invoke= object_primitive_add_invoke;
+       ot->exec= editmode_toggle_exec;
        
-       ot->poll= ED_operator_scene_editable;
+       ot->poll= editmode_toggle_poll;
        
        /* flags */
-       ot->flag= 0;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* *************************** */
 
-/* ******************************* */
-
-/* remove base from a specific scene */
-/* note: now unlinks constraints as well */
-void ED_base_object_free_and_unlink(Scene *scene, Base *base)
-{
-       BLI_remlink(&scene->base, base);
-       free_libblock_us(&G.main->object, base->object);
-       if(scene->basact==base) scene->basact= NULL;
-       MEM_freeN(base);
-}
-
-static int object_delete_exec(bContext *C, wmOperator *op)
+static int posemode_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene= CTX_data_scene(C);
-       int islamp= 0;
-       
-       if(CTX_data_edit_object(C)) 
-               return OPERATOR_CANCELLED;
+       Base *base= CTX_data_active_base(C);
        
-       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-
-               if(base->object->type==OB_LAMP) islamp= 1;
+       if(base->object->type==OB_ARMATURE) {
+               if(base->object==CTX_data_edit_object(C)) {
+                       ED_object_exit_editmode(C, EM_FREEDATA);
+                       ED_armature_enter_posemode(C, base);
+               }
+               else if(base->object->mode & OB_MODE_POSE)
+                       ED_armature_exit_posemode(C, base);
+               else
+                       ED_armature_enter_posemode(C, base);
                
-               /* remove from current scene only */
-               ED_base_object_free_and_unlink(scene, base);
+               return OPERATOR_FINISHED;
        }
-       CTX_DATA_END;
-
-       if(islamp) reshadeall_displist(scene);  /* only frees displist */
-       
-       DAG_scene_sort(scene);
-       ED_anim_dag_flush_update(C);
        
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
+       return OPERATOR_PASS_THROUGH;
 }
 
-void OBJECT_OT_delete(wmOperatorType *ot)
+void OBJECT_OT_posemode_toggle(wmOperatorType *ot) 
 {
-       
        /* identifiers */
-       ot->name= "Delete";
-       ot->description = "Delete selected objects.";
-       ot->idname= "OBJECT_OT_delete";
+       ot->name= "Toggle Pose Mode";
+       ot->idname= "OBJECT_OT_posemode_toggle";
+       ot->description= "Enables or disables posing/selecting bones";
        
        /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_delete_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->exec= posemode_exec;
+       ot->poll= ED_operator_object_active;
        
+       /* flag */
+       ot->flag= OPTYPE_REGISTER;
 }
 
+/* *********************** */
 
-static void single_object_users__forwardModifierLinks(void *userData, Object *ob, Object **obpoin)
+void check_editmode(int type)
 {
-       ID_NEW(*obpoin);
-}
+       Object *obedit= NULL; // XXX
+       
+       if (obedit==NULL || obedit->type==type) return;
 
-static void copy_object__forwardModifierLinks(void *userData, Object *ob,
-                                              ID **idpoin)
-{
-       /* this is copied from ID_NEW; it might be better to have a macro */
-       if(*idpoin && (*idpoin)->newid) *idpoin = (*idpoin)->newid;
+// XXX ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
 }
 
+#if 0
+// XXX should be in view3d?
 
-/* after copying objects, copied data should get new pointers */
-static void copy_object_set_idnew(Scene *scene, View3D *v3d, int dupflag)
+/* context: ob = lamp */
+/* code should be replaced with proper (custom) transform handles for lamp properties */
+static void spot_interactive(Object *ob, int mode)
 {
-       Base *base;
-       Object *ob;
-       Material *ma, *mao;
-       ID *id;
-#if 0 // XXX old animation system
-       Ipo *ipo;
-       bActionStrip *strip;
-#endif // XXX old animation system
-       int a;
-       
-       /* XXX check object pointers */
-       for(base= FIRSTBASE; base; base= base->next) {
-               if(TESTBASELIB_BGMODE(v3d, base)) {
-                       ob= base->object;
-                       relink_constraints(&ob->constraints);
-                       if (ob->pose){
-                               bPoseChannel *chan;
-                               for (chan = ob->pose->chanbase.first; chan; chan=chan->next){
-                                       relink_constraints(&chan->constraints);
-                               }
-                       }
-                       modifiers_foreachIDLink(ob, copy_object__forwardModifierLinks, NULL);
-                       ID_NEW(ob->parent);
-                       ID_NEW(ob->track);
-                       ID_NEW(ob->proxy);
-                       ID_NEW(ob->proxy_group);
-                       
-#if 0 // XXX old animation system
-                       for(strip= ob->nlastrips.first; strip; strip= strip->next) {
-                               bActionModifier *amod;
-                               for(amod= strip->modifiers.first; amod; amod= amod->next)
-                                       ID_NEW(amod->ob);
-                       }
-#endif // XXX old animation system
-               }
-       }
-       
-       /* materials */
-       if( dupflag & USER_DUP_MAT) {
-               mao= G.main->mat.first;
-               while(mao) {
-                       if(mao->id.newid) {
-                               
-                               ma= (Material *)mao->id.newid;
-                               
-                               if(dupflag & USER_DUP_TEX) {
-                                       for(a=0; a<MAX_MTEX; a++) {
-                                               if(ma->mtex[a]) {
-                                                       id= (ID *)ma->mtex[a]->tex;
-                                                       if(id) {
-                                                               ID_NEW_US(ma->mtex[a]->tex)
-                                                               else ma->mtex[a]->tex= copy_texture(ma->mtex[a]->tex);
-                                                               id->us--;
-                                                       }
-                                               }
-                                       }
-                               }
-#if 0 // XXX old animation system
-                               id= (ID *)ma->ipo;
-                               if(id) {
-                                       ID_NEW_US(ma->ipo)
-                                       else ma->ipo= copy_ipo(ma->ipo);
-                                       id->us--;
-                               }
-#endif // XXX old animation system
-                       }
-                       mao= mao->id.next;
-               }
-       }
+       Lamp *la= ob->data;
+       float transfac, dx, dy, ratio, origval;
+       int keep_running= 1, center2d[2];
+       short mval[2], mvalo[2];
        
-#if 0 // XXX old animation system
-       /* lamps */
-       if( dupflag & USER_DUP_IPO) {
-               Lamp *la= G.main->lamp.first;
-               while(la) {
-                       if(la->id.newid) {
-                               Lamp *lan= (Lamp *)la->id.newid;
-                               id= (ID *)lan->ipo;
-                               if(id) {
-                                       ID_NEW_US(lan->ipo)
-                                       else lan->ipo= copy_ipo(lan->ipo);
-                                       id->us--;
-                               }
-                       }
-                       la= la->id.next;
-               }
-       }
+//     getmouseco_areawin(mval);
+//     getmouseco_areawin(mvalo);
        
-       /* ipos */
-       ipo= G.main->ipo.first;
-       while(ipo) {
-               if(ipo->id.lib==NULL && ipo->id.newid) {
-                       Ipo *ipon= (Ipo *)ipo->id.newid;
-                       IpoCurve *icu;
-                       for(icu= ipon->curve.first; icu; icu= icu->next) {
-                               if(icu->driver) {
-                                       ID_NEW(icu->driver->ob);
-                               }
-                       }
-               }
-               ipo= ipo->id.next;
+       project_int(ob->obmat[3], center2d);
+       if( center2d[0] > 100000 ) {            /* behind camera */
+//             center2d[0]= curarea->winx/2;
+//             center2d[1]= curarea->winy/2;
        }
-#endif // XXX old animation system
-       
-       set_sca_new_poins();
-       
-       clear_id_newpoins();
-       
-}
 
-static int return_editmesh_indexar(EditMesh *em, int *tot, int **indexar, float *cent)
-{
-       EditVert *eve;
-       int *index, nr, totvert=0;
-       
-       for(eve= em->verts.first; eve; eve= eve->next) {
-               if(eve->f & SELECT) totvert++;
-       }
-       if(totvert==0) return 0;
-       
-       *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
-       *tot= totvert;
-       nr= 0;
-       cent[0]= cent[1]= cent[2]= 0.0;
+//     helpline(mval, center2d);
        
-       for(eve= em->verts.first; eve; eve= eve->next) {
-               if(eve->f & SELECT) {
-                       *index= nr; index++;
-                       VecAddf(cent, cent, eve->co);
-               }
-               nr++;
-       }
+       /* ratio is like scaling */
+       dx = (float)(center2d[0] - mval[0]);
+       dy = (float)(center2d[1] - mval[1]);
+       transfac = (float)sqrt( dx*dx + dy*dy);
+       if(transfac==0.0f) transfac= 1.0f;
        
-       VecMulf(cent, 1.0f/(float)totvert);
-       
-       return totvert;
-}
-
-static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, float *cent)
-{
-       MDeformVert *dvert;
-       EditVert *eve;
-       int i, totvert=0;
-       
-       cent[0]= cent[1]= cent[2]= 0.0;
+       if(mode==1)     
+               origval= la->spotsize;
+       else if(mode==2)        
+               origval= la->dist;
+       else if(mode==3)        
+               origval= la->clipsta;
+       else    
+               origval= la->clipend;
        
-       if(obedit->actdef) {
+       while (keep_running>0) {
                
-               /* find the vertices */
-               for(eve= em->verts.first; eve; eve= eve->next) {
-                       dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
-
-                       if(dvert) {
-                               for(i=0; i<dvert->totweight; i++){
-                                       if(dvert->dw[i].def_nr == (obedit->actdef-1)) {
-                                               totvert++;
-                                               VecAddf(cent, cent, eve->co);
-                                       }
-                               }
-                       }
-               }
-               if(totvert) {
-                       bDeformGroup *defGroup = BLI_findlink(&obedit->defbase, obedit->actdef-1);
-                       strcpy(name, defGroup->name);
-                       VecMulf(cent, 1.0f/(float)totvert);
-                       return 1;
+//             getmouseco_areawin(mval);
+               
+               /* essential for idling subloop */
+               if(mval[0]==mvalo[0] && mval[1]==mvalo[1]) {
+                       PIL_sleep_ms(2);
                }
-       }
-       
-       return 0;
-}      
+               else {
+                       char str[32];
+                       
+                       dx = (float)(center2d[0] - mval[0]);
+                       dy = (float)(center2d[1] - mval[1]);
+                       ratio = (float)(sqrt( dx*dx + dy*dy))/transfac;
+                       
+                       /* do the trick */
+                       
+                       if(mode==1) {   /* spot */
+                               la->spotsize = ratio*origval;
+                               CLAMP(la->spotsize, 1.0f, 180.0f);
+                               sprintf(str, "Spot size %.2f\n", la->spotsize);
+                       }
+                       else if(mode==2) {      /* dist */
+                               la->dist = ratio*origval;
+                               CLAMP(la->dist, 0.01f, 5000.0f);
+                               sprintf(str, "Distance %.2f\n", la->dist);
+                       }
+                       else if(mode==3) {      /* sta */
+                               la->clipsta = ratio*origval;
+                               CLAMP(la->clipsta, 0.001f, 5000.0f);
+                               sprintf(str, "Distance %.2f\n", la->clipsta);
+                       }
+                       else if(mode==4) {      /* end */
+                               la->clipend = ratio*origval;
+                               CLAMP(la->clipend, 0.1f, 5000.0f);
+                               sprintf(str, "Clip End %.2f\n", la->clipend);
+                       }
 
-static void select_editmesh_hook(Object *ob, HookModifierData *hmd)
-{
-       Mesh *me= ob->data;
-       EditMesh *em= BKE_mesh_get_editmesh(me);
-       EditVert *eve;
-       int index=0, nr=0;
-       
-       if (hmd->indexar == NULL)
-               return;
-       
-       for(eve= em->verts.first; eve; eve= eve->next, nr++) {
-               if(nr==hmd->indexar[index]) {
-                       eve->f |= SELECT;
-                       if(index < hmd->totindex-1) index++;
-               }
-       }
-       EM_select_flush(em);
+                       /* cleanup */
+                       mvalo[0]= mval[0];
+                       mvalo[1]= mval[1];
+                       
+                       /* handle shaded mode */
+// XXX                 shade_buttons_change_3d();
 
-       BKE_mesh_end_editmesh(me, em);
-}
+                       /* DRAW */      
+                       headerprint(str);
+                       force_draw_plus(SPACE_BUTS, 0);
 
-static int return_editlattice_indexar(Lattice *editlatt, int *tot, int **indexar, float *cent)
-{
-       BPoint *bp;
-       int *index, nr, totvert=0, a;
-       
-       /* count */
-       a= editlatt->pntsu*editlatt->pntsv*editlatt->pntsw;
-       bp= editlatt->def;
-       while(a--) {
-               if(bp->f1 & SELECT) {
-                       if(bp->hide==0) totvert++;
+//                     helpline(mval, center2d);
                }
-               bp++;
-       }
-
-       if(totvert==0) return 0;
-       
-       *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
-       *tot= totvert;
-       nr= 0;
-       cent[0]= cent[1]= cent[2]= 0.0;
-       
-       a= editlatt->pntsu*editlatt->pntsv*editlatt->pntsw;
-       bp= editlatt->def;
-       while(a--) {
-               if(bp->f1 & SELECT) {
-                       if(bp->hide==0) {
-                               *index= nr; index++;
-                               VecAddf(cent, cent, bp->vec);
+               
+               while( qtest() ) {
+                       short val;
+                       unsigned short event= extern_qread(&val);
+                       
+                       switch (event){
+                               case ESCKEY:
+                               case RIGHTMOUSE:
+                                       keep_running= 0;
+                                       break;
+                               case LEFTMOUSE:
+                               case SPACEKEY:
+                               case PADENTER:
+                               case RETKEY:
+                                       if(val)
+                                               keep_running= -1;
+                                       break;
                        }
                }
-               bp++;
-               nr++;
        }
-       
-       VecMulf(cent, 1.0f/(float)totvert);
-       
-       return totvert;
-}
 
-static void select_editlattice_hook(Object *obedit, HookModifierData *hmd)
-{
-       Lattice *lt= obedit->data;
-       BPoint *bp;
-       int index=0, nr=0, a;
-       
-       /* count */
-       a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
-       bp= lt->editlatt->def;
-       while(a--) {
-               if(hmd->indexar[index]==nr) {
-                       bp->f1 |= SELECT;
-                       if(index < hmd->totindex-1) index++;
-               }
-               nr++;
-               bp++;
+       if(keep_running==0) {
+               if(mode==1)     
+                       la->spotsize= origval;
+               else if(mode==2)        
+                       la->dist= origval;
+               else if(mode==3)        
+                       la->clipsta= origval;
+               else    
+                       la->clipend= origval;
        }
+
 }
+#endif
 
-static int return_editcurve_indexar(Object *obedit, int *tot, int **indexar, float *cent)
+void special_editmenu(Scene *scene, View3D *v3d)
 {
-       ListBase *editnurb= curve_get_editcurve(obedit);
-       Nurb *nu;
-       BPoint *bp;
-       BezTriple *bezt;
-       int *index, a, nr, totvert=0;
-       
-       for(nu= editnurb->first; nu; nu= nu->next) {
-               if(nu->type == CU_BEZIER) {
-                       bezt= nu->bezt;
-                       a= nu->pntsu;
-                       while(a--) {
-                               if(bezt->f1 & SELECT) totvert++;
-                               if(bezt->f2 & SELECT) totvert++;
-                               if(bezt->f3 & SELECT) totvert++;
-                               bezt++;
-                       }
-               }
-               else {
-                       bp= nu->bp;
-                       a= nu->pntsu*nu->pntsv;
-                       while(a--) {
-                               if(bp->f1 & SELECT) totvert++;
-                               bp++;
-                       }
-               }
-       }
-       if(totvert==0) return 0;
+// XXX static short numcuts= 2;
+       Object *ob= OBACT;
+       Object *obedit= NULL; // XXX
+       int nr,ret=0;
        
-       *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
-       *tot= totvert;
-       nr= 0;
-       cent[0]= cent[1]= cent[2]= 0.0;
+       if(ob==NULL) return;
        
-       for(nu= editnurb->first; nu; nu= nu->next) {
-               if(nu->type == CU_BEZIER) {
-                       bezt= nu->bezt;
-                       a= nu->pntsu;
-                       while(a--) {
-                               if(bezt->f1 & SELECT) {
-                                       *index= nr; index++;
-                                       VecAddf(cent, cent, bezt->vec[0]);
-                               }
-                               nr++;
-                               if(bezt->f2 & SELECT) {
-                                       *index= nr; index++;
-                                       VecAddf(cent, cent, bezt->vec[1]);
-                               }
-                               nr++;
-                               if(bezt->f3 & SELECT) {
-                                       *index= nr; index++;
-                                       VecAddf(cent, cent, bezt->vec[2]);
+       if(obedit==NULL) {
+               
+               if(ob->mode & OB_MODE_POSE) {
+// XXX                 pose_special_editmenu();
+               }
+               else if(paint_facesel_test(ob)) {
+                       Mesh *me= get_mesh(ob);
+                       MTFace *tface;
+                       MFace *mface;
+                       int a;
+                       
+                       if(me==0 || me->mtface==0) return;
+                       
+                       nr= pupmenu("Specials%t|Set     Tex%x1|         Shared%x2|         Light%x3|         Invisible%x4|         Collision%x5|         TwoSide%x6|Clr     Tex%x7|         Shared%x8|         Light%x9|         Invisible%x10|         Collision%x11|         TwoSide%x12");
+                       
+                       tface= me->mtface;
+                       mface= me->mface;
+                       for(a=me->totface; a>0; a--, tface++, mface++) {
+                               if(mface->flag & ME_FACE_SEL) {
+                                       switch(nr) {
+                                       case 1:
+                                               tface->mode |= TF_TEX; break;
+                                       case 2:
+                                               tface->mode |= TF_SHAREDCOL; break;
+                                       case 3:
+                                               tface->mode |= TF_LIGHT; break; 
+                                       case 4:
+                                               tface->mode |= TF_INVISIBLE; break;
+                                       case 5:
+                                               tface->mode |= TF_DYNAMIC; break;
+                                       case 6:
+                                               tface->mode |= TF_TWOSIDE; break;
+                                       case 7:
+                                               tface->mode &= ~TF_TEX;
+                                               tface->tpage= 0;
+                                               break;
+                                       case 8:
+                                               tface->mode &= ~TF_SHAREDCOL; break;
+                                       case 9:
+                                               tface->mode &= ~TF_LIGHT; break;
+                                       case 10:
+                                               tface->mode &= ~TF_INVISIBLE; break;
+                                       case 11:
+                                               tface->mode &= ~TF_DYNAMIC; break;
+                                       case 12:
+                                               tface->mode &= ~TF_TWOSIDE; break;
+                                       }
                                }
-                               nr++;
-                               bezt++;
                        }
+                       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
                }
-               else {
-                       bp= nu->bp;
-                       a= nu->pntsu*nu->pntsv;
-                       while(a--) {
-                               if(bp->f1 & SELECT) {
-                                       *index= nr; index++;
-                                       VecAddf(cent, cent, bp->vec);
-                               }
-                               nr++;
-                               bp++;
+               else if(ob->mode & OB_MODE_VERTEX_PAINT) {
+                       Mesh *me= get_mesh(ob);
+                       
+                       if(me==0 || (me->mcol==NULL && me->mtface==NULL) ) return;
+                       
+                       nr= pupmenu("Specials%t|Shared VertexCol%x1");
+                       if(nr==1) {
+                               
+// XXX                         do_shared_vertexcol(me);
+                               
+                               DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
                        }
                }
-       }
-       
-       VecMulf(cent, 1.0f/(float)totvert);
-       
-       return totvert;
-}
-
-void ED_object_apply_obmat(Object *ob)
-{
-       float mat[3][3], imat[3][3], tmat[3][3];
-       
-       /* from obmat to loc rot size */
-       
-       if(ob==NULL) return;
-       Mat3CpyMat4(mat, ob->obmat);
-       
-       VECCOPY(ob->loc, ob->obmat[3]);
-
-       Mat3ToEul(mat, ob->rot);
-       EulToMat3(ob->rot, tmat);
-
-       Mat3Inv(imat, tmat);
-       
-       Mat3MulMat3(tmat, imat, mat);
-       
-       ob->size[0]= tmat[0][0];
-       ob->size[1]= tmat[1][1];
-       ob->size[2]= tmat[2][2];
-       
-}
+               else if(ob->mode & OB_MODE_WEIGHT_PAINT) {
+                       Object *par= modifiers_isDeformedByArmature(ob);
 
-int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
-{
-       *indexar= NULL;
-       *tot= 0;
-       name[0]= 0;
-       
-       switch(obedit->type) {
-               case OB_MESH:
-               {
-                       Mesh *me= obedit->data;
-                       EditMesh *em = BKE_mesh_get_editmesh(me);
+                       if(par && (par->mode & OB_MODE_POSE)) {
+                               nr= pupmenu("Specials%t|Apply Bone Envelopes to Vertex Groups %x1|Apply Bone Heat Weights to Vertex Groups %x2");
 
-                       /* check selected vertices first */
-                       if( return_editmesh_indexar(em, tot, indexar, cent_r)) {
-                               BKE_mesh_end_editmesh(me, em);
-                               return 1;
-                       } else {
-                               int ret = return_editmesh_vgroup(obedit, em, name, cent_r);
-                               BKE_mesh_end_editmesh(me, em);
-                               return ret;
+// XXX                         if(nr==1 || nr==2)
+// XXX                                 pose_adds_vgroups(ob, (nr == 2));
                        }
                }
-               case OB_CURVE:
-               case OB_SURF:
-                       return return_editcurve_indexar(obedit, tot, indexar, cent_r);
-               case OB_LATTICE:
-               {
-                       Lattice *lt= obedit->data;
-                       return return_editlattice_indexar(lt->editlatt, tot, indexar, cent_r);
-               }
-               default:
-                       return 0;
-       }
-}
+               else if(ob->mode & OB_MODE_PARTICLE_EDIT) {
+#if 0
+                       // XXX
+                       ParticleSystem *psys = PE_get_current(ob);
+                       ParticleEditSettings *pset = PE_settings();
 
-static void select_editcurve_hook(Object *obedit, HookModifierData *hmd)
-{
-       ListBase *editnurb= curve_get_editcurve(obedit);
-       Nurb *nu;
-       BPoint *bp;
-       BezTriple *bezt;
-       int index=0, a, nr=0;
-       
-       for(nu= editnurb->first; nu; nu= nu->next) {
-               if(nu->type == CU_BEZIER) {
-                       bezt= nu->bezt;
-                       a= nu->pntsu;
-                       while(a--) {
-                               if(nr == hmd->indexar[index]) {
-                                       bezt->f1 |= SELECT;
-                                       if(index<hmd->totindex-1) index++;
-                               }
-                               nr++;
-                               if(nr == hmd->indexar[index]) {
-                                       bezt->f2 |= SELECT;
-                                       if(index<hmd->totindex-1) index++;
-                               }
-                               nr++;
-                               if(nr == hmd->indexar[index]) {
-                                       bezt->f3 |= SELECT;
-                                       if(index<hmd->totindex-1) index++;
-                               }
-                               nr++;
-                               
-                               bezt++;
-                       }
-               }
-               else {
-                       bp= nu->bp;
-                       a= nu->pntsu*nu->pntsv;
-                       while(a--) {
-                               if(nr == hmd->indexar[index]) {
-                                       bp->f1 |= SELECT;
-                                       if(index<hmd->totindex-1) index++;
-                               }
-                               nr++;
-                               bp++;
-                       }
-               }
-       }
-}
-
-void object_hook_select(Object *ob, HookModifierData *hmd) 
-{
-       if(ob->type==OB_MESH) select_editmesh_hook(ob, hmd);
-       else if(ob->type==OB_LATTICE) select_editlattice_hook(ob, hmd);
-       else if(ob->type==OB_CURVE) select_editcurve_hook(ob, hmd);
-       else if(ob->type==OB_SURF) select_editcurve_hook(ob, hmd);
-}
-
-
-void add_hook(Scene *scene, View3D *v3d, int mode)
-{
-       ModifierData *md = NULL;
-       HookModifierData *hmd = NULL;
-       Object *ob=NULL;
-       Object *obedit= scene->obedit;  // XXX get from context
-       
-       if(obedit==NULL) return;
-       
-       /* preconditions */
-       if(mode==2) { /* selected object */
-               Base *base;
-               for(base= FIRSTBASE; base; base= base->next) {
-                       if(TESTBASELIB(v3d, base)) {
-                               if(base!=BASACT) {
-                                       ob= base->object;
-                                       break;
-                               }
-                       }
-               }
-               if(ob==NULL) {
-                       error("Requires selected Object");
-                       return;
-               }
-       }
-       else if(mode!=1) {
-               int maxlen=0, a, nr;
-               char *cp;
-               
-               /* make pupmenu with hooks */
-               for(md=obedit->modifiers.first; md; md= md->next) {
-                       if (md->type==eModifierType_Hook) 
-                               maxlen+=32;
-               }
-               
-               if(maxlen==0) {
-                       error("Object has no hooks yet");
-                       return;
-               }
-               
-               cp= MEM_callocN(maxlen+32, "temp string");
-               if(mode==3) strcpy(cp, "Remove %t|");
-               else if(mode==4) strcpy(cp, "Reassign %t|");
-               else if(mode==5) strcpy(cp, "Select %t|");
-               else if(mode==6) strcpy(cp, "Clear Offset %t|");
-               
-               for(md=obedit->modifiers.first; md; md= md->next) {
-                       if (md->type==eModifierType_Hook) {
-                               strcat(cp, md->name);
-                               strcat(cp, " |");
-                       }
-               }
-               
-               nr= pupmenu(cp);
-               MEM_freeN(cp);
-               
-               if(nr<1) return;
-               
-               a= 1;
-               for(md=obedit->modifiers.first; md; md=md->next) {
-                       if (md->type==eModifierType_Hook) {
-                               if(a==nr) break;
-                               a++;
-                       }
-               }
-               
-               hmd = (HookModifierData*) md;
-               ob= hmd->object;
-       }
-
-       /* do it, new hooks or reassign */
-       if(mode==1 || mode==2 || mode==4) {
-               float cent[3];
-               int tot, ok, *indexar;
-               char name[32];
-               
-               ok = object_hook_index_array(obedit, &tot, &indexar, name, cent);
-               
-               if(ok==0) {
-                       error("Requires selected vertices or active Vertex Group");
-               }
-               else {
-                       
-                       if(mode==1) {
-                               Base *base= BASACT, *newbase;
-                               
-                               ob= add_object(scene, OB_EMPTY);
-                               /* set layers OK */
-                               newbase= BASACT;
-                               newbase->lay= base->lay;
-                               ob->lay= newbase->lay;
-                               
-                               /* transform cent to global coords for loc */
-                               VecMat4MulVecfl(ob->loc, obedit->obmat, cent);
-                               
-                               /* restore, add_object sets active */
-                               BASACT= base;
-                       }
-                       /* if mode is 2 or 4, ob has been set */
-                       
-                       /* new hook */
-                       if(mode==1 || mode==2) {
-                               ModifierData *md = obedit->modifiers.first;
-                               
-                               while (md && modifierType_getInfo(md->type)->type==eModifierTypeType_OnlyDeform) {
-                                       md = md->next;
-                               }
-                               
-                               hmd = (HookModifierData*) modifier_new(eModifierType_Hook);
-                               BLI_insertlinkbefore(&obedit->modifiers, md, hmd);
-                               sprintf(hmd->modifier.name, "Hook-%s", ob->id.name+2);
-                       }
-                       else if (hmd->indexar) MEM_freeN(hmd->indexar); /* reassign, hook was set */
-               
-                       hmd->object= ob;
-                       hmd->indexar= indexar;
-                       VECCOPY(hmd->cent, cent);
-                       hmd->totindex= tot;
-                       BLI_strncpy(hmd->name, name, 32);
-                       
-                       // TODO: need to take into account bone targets here too now...
-                       if(mode==1 || mode==2) {
-                               /* matrix calculus */
-                               /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */
-                               /*        (parentinv         )                          */
-                               
-                               where_is_object(scene, ob);
-                               
-                               Mat4Invert(ob->imat, ob->obmat);
-                               /* apparently this call goes from right to left... */
-                               Mat4MulSerie(hmd->parentinv, ob->imat, obedit->obmat, NULL, 
-                                                        NULL, NULL, NULL, NULL, NULL);
-                       }
-               }
-       }
-       else if(mode==3) { /* remove */
-               BLI_remlink(&obedit->modifiers, md);
-               modifier_free(md);
-       }
-       else if(mode==5) { /* select */
-               // FIXME: this is now OBJECT_OT_hook_select
-               object_hook_select(obedit, hmd);
-       }
-       else if(mode==6) { /* clear offset */
-               // FIXME: this is now OBJECT_OT_hook_reset operator
-               where_is_object(scene, ob);     /* ob is hook->parent */
-
-               Mat4Invert(ob->imat, ob->obmat);
-               /* this call goes from right to left... */
-               Mat4MulSerie(hmd->parentinv, ob->imat, obedit->obmat, NULL, 
-                                        NULL, NULL, NULL, NULL, NULL);
-       }
-
-       DAG_scene_sort(scene);
-}
-
-void add_hook_menu(Scene *scene, View3D *v3d)
-{
-       Object *obedit= scene->obedit;  // XXX get from context
-       int mode;
-       
-       if(obedit==NULL) return;
-       
-       if(modifiers_findByType(obedit, eModifierType_Hook))
-               mode= pupmenu("Hooks %t|Add, To New Empty %x1|Add, To Selected Object %x2|Remove... %x3|Reassign... %x4|Select... %x5|Clear Offset...%x6");
-       else
-               mode= pupmenu("Hooks %t|Add, New Empty %x1|Add, To Selected Object %x2");
-
-       if(mode<1) return;
-               
-       /* do operations */
-       add_hook(scene, v3d, mode);
-}
-
-
-
-/* use this when the loc/size/rot of the parent has changed but the children should stay in the same place
- * apply-size-rot or object center for eg */
-static void ignore_parent_tx(Scene *scene, Object *ob ) 
-{
-       Object workob;
-       Object *ob_child;
-       
-       /* 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) {
-                       ED_object_apply_obmat(ob_child);
-                       what_does_parent(scene, ob_child, &workob);
-                       Mat4Invert(ob_child->parentinv, workob.obmat);
-               }
-       }
-}
-
-/* ******************** clear parent operator ******************* */
-
-static EnumPropertyItem prop_clear_parent_types[] = {
-       {0, "CLEAR", 0, "Clear Parent", ""},
-       {1, "CLEAR_KEEP_TRANSFORM", 0, "Clear and Keep Transformation (Clear Track)", ""},
-       {2, "CLEAR_INVERSE", 0, "Clear Parent Inverse", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-/* note, poll should check for editable scene */
-static int parent_clear_exec(bContext *C, wmOperator *op)
-{
-       int type= RNA_enum_get(op->ptr, "type");
-       
-       CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-
-               if(type == 0) {
-                       ob->parent= NULL;
-               }                       
-               else if(type == 1) {
-                       ob->parent= NULL;
-                       ob->track= NULL;
-                       ED_object_apply_obmat(ob);
-               }
-               else if(type == 2)
-                       Mat4One(ob->parentinv);
-
-               ob->recalc |= OB_RECALC;
-       }
-       CTX_DATA_END;
-       
-       DAG_scene_sort(CTX_data_scene(C));
-       ED_anim_dag_flush_update(C);
-       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_parent_clear(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Clear Parent";
-       ot->description = "Clear the object's parenting.";
-       ot->idname= "OBJECT_OT_parent_clear";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= parent_clear_exec;
-       
-       ot->poll= ED_operator_object_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_clear_parent_types, 0, "Type", "");
-}
-
-/* ******************** clear track operator ******************* */
-
-
-static EnumPropertyItem prop_clear_track_types[] = {
-       {0, "CLEAR", 0, "Clear Track", ""},
-       {1, "CLEAR_KEEP_TRANSFORM", 0, "Clear and Keep Transformation (Clear Track)", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-/* note, poll should check for editable scene */
-static int object_track_clear_exec(bContext *C, wmOperator *op)
-{
-       int type= RNA_enum_get(op->ptr, "type");
-
-       if(CTX_data_edit_object(C)) {
-               BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in EditMode");
-               return OPERATOR_CANCELLED;
-       }
-       CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               ob->track= NULL;
-               ob->recalc |= OB_RECALC;
-               
-               if(type == 1)
-                       ED_object_apply_obmat(ob);
-       }
-       CTX_DATA_END;
-
-       DAG_scene_sort(CTX_data_scene(C));
-       ED_anim_dag_flush_update(C);
-
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_track_clear(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Clear track";
-       ot->description = "Clear tracking constraint or flag from object.";
-       ot->idname= "OBJECT_OT_track_clear";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_track_clear_exec;
-       
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_clear_track_types, 0, "Type", "");
-}
-
-/* *****************Selection Operators******************* */
-static EnumPropertyItem prop_select_types[] = {
-       {0, "EXCLUSIVE", 0, "Exclusive", ""},
-       {1, "EXTEND", 0, "Extend", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-/* ****** Select by Type ****** */
-
-static int object_select_by_type_exec(bContext *C, wmOperator *op)
-{
-       short obtype, seltype;
-       
-       obtype = RNA_enum_get(op->ptr, "type");
-       seltype = RNA_enum_get(op->ptr, "seltype");
-               
-       if (seltype == 0) {
-               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-                       ED_base_object_select(base, BA_DESELECT);
-               }
-               CTX_DATA_END;
-       }
-       
-       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if(base->object->type==obtype) {
-                       ED_base_object_select(base, BA_SELECT);
-               }
-       }
-       CTX_DATA_END;
-       
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_select_by_type(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Select By Type";
-       ot->description = "Select all visible objects that are of a type.";
-       ot->idname= "OBJECT_OT_select_by_type";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_select_by_type_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "seltype", prop_select_types, 0, "Selection", "Extend selection or clear selection then select");
-       RNA_def_enum(ot->srna, "type", prop_object_types, 1, "Type", "");
-
-}
-/* ****** selection by links *******/
-
-static EnumPropertyItem prop_select_linked_types[] = {
-       {1, "IPO", 0, "Object IPO", ""}, // XXX depreceated animation system stuff...
-       {2, "OBDATA", 0, "Ob Data", ""},
-       {3, "MATERIAL", 0, "Material", ""},
-       {4, "TEXTURE", 0, "Texture", ""},
-       {5, "DUPGROUP", 0, "Dupligroup", ""},
-       {6, "PARTICLE", 0, "Particle System", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-static int object_select_linked_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *ob;
-       void *obdata = NULL;
-       Material *mat = NULL, *mat1;
-       Tex *tex=0;
-       int a, b;
-       int nr = RNA_enum_get(op->ptr, "type");
-       short changed = 0, seltype;
-       /* events (nr):
-        * Object Ipo: 1
-        * ObData: 2
-        * Current Material: 3
-        * Current Texture: 4
-        * DupliGroup: 5
-        * PSys: 6
-        */
-
-       seltype = RNA_enum_get(op->ptr, "seltype");
-       
-       if (seltype == 0) {
-               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-                       ED_base_object_select(base, BA_DESELECT);
-               }
-               CTX_DATA_END;
-       }
-       
-       ob= OBACT;
-       if(ob==0){ 
-               BKE_report(op->reports, RPT_ERROR, "No Active Object");
-               return OPERATOR_CANCELLED;
-       }
-       
-       if(nr==1) {     
-                       // XXX old animation system
-               //ipo= ob->ipo;
-               //if(ipo==0) return OPERATOR_CANCELLED;
-               return OPERATOR_CANCELLED;
-       }
-       else if(nr==2) {
-               if(ob->data==0) return OPERATOR_CANCELLED;
-               obdata= ob->data;
-       }
-       else if(nr==3 || nr==4) {
-               mat= give_current_material(ob, ob->actcol);
-               if(mat==0) return OPERATOR_CANCELLED;
-               if(nr==4) {
-                       if(mat->mtex[ (int)mat->texact ]) tex= mat->mtex[ (int)mat->texact ]->tex;
-                       if(tex==0) return OPERATOR_CANCELLED;
-               }
-       }
-       else if(nr==5) {
-               if(ob->dup_group==NULL) return OPERATOR_CANCELLED;
-       }
-       else if(nr==6) {
-               if(ob->particlesystem.first==NULL) return OPERATOR_CANCELLED;
-       }
-       else return OPERATOR_CANCELLED;
-       
-       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if(nr==1) {
-                               // XXX old animation system
-                       //if(base->object->ipo==ipo) base->flag |= SELECT;
-                       //changed = 1;
-               }
-               else if(nr==2) {
-                       if(base->object->data==obdata) base->flag |= SELECT;
-                       changed = 1;
-               }
-               else if(nr==3 || nr==4) {
-                       ob= base->object;
-                       
-                       for(a=1; a<=ob->totcol; a++) {
-                               mat1= give_current_material(ob, a);
-                               if(nr==3) {
-                                       if(mat1==mat) base->flag |= SELECT;
-                                       changed = 1;
-                               }
-                               else if(mat1 && nr==4) {
-                                       for(b=0; b<MAX_MTEX; b++) {
-                                               if(mat1->mtex[b]) {
-                                                       if(tex==mat1->mtex[b]->tex) {
-                                                               base->flag |= SELECT;
-                                                               changed = 1;
-                                                               break;
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-               else if(nr==5) {
-                       if(base->object->dup_group==ob->dup_group) {
-                                base->flag |= SELECT;
-                                changed = 1;
-                       }
-               }
-               else if(nr==6) {
-                       /* loop through other, then actives particles*/
-                       ParticleSystem *psys;
-                       ParticleSystem *psys_act;
-                       
-                       for(psys=base->object->particlesystem.first; psys; psys=psys->next) {
-                               for(psys_act=ob->particlesystem.first; psys_act; psys_act=psys_act->next) {
-                                       if (psys->part == psys_act->part) {
-                                               base->flag |= SELECT;
-                                               changed = 1;
-                                               break;
-                                       }
-                               }
-                               
-                               if (base->flag & SELECT) {
-                                       break;
-                               }
-                       }
-               }
-               base->object->flag= base->flag;
-       }
-       CTX_DATA_END;
-       
-       if (changed) {
-               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-               return OPERATOR_FINISHED;
-       }
-       
-       return OPERATOR_CANCELLED;
-}
-
-void OBJECT_OT_select_linked(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Select Linked";
-       ot->description = "Select all visible objects that are linked.";
-       ot->idname= "OBJECT_OT_select_linked";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_select_linked_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_select_linked_types, 0, "Type", "");
-       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
-
-}
-
-/* ****** selection grouped *******/
-
-static EnumPropertyItem prop_select_grouped_types[] = {
-       {1, "CHILDREN_RECURSIVE", 0, "Children", ""}, // XXX depreceated animation system stuff...
-       {2, "CHILDREN", 0, "Immediate Children", ""},
-       {3, "PARENT", 0, "Parent", ""},
-       {4, "SIBLINGS", 0, "Siblings", "Shared Parent"},
-       {5, "TYPE", 0, "Type", "Shared object type"},
-       {6, "LAYER", 0, "Layer", "Shared layers"},
-       {7, "GROUP", 0, "Group", "Shared group"},
-       {8, "HOOK", 0, "Hook", ""},
-       {9, "PASS", 0, "Pass", "Render pass Index"},
-       {10, "COLOR", 0, "Color", "Object Color"},
-       {11, "PROPERTIES", 0, "Properties", "Game Properties"},
-       {0, NULL, 0, NULL, NULL}
-};
-
-
-static short select_grouped_children(bContext *C, Object *ob, int recursive)
-{
-       short changed = 0;
-
-       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-               if (ob == base->object->parent) {
-                       if (!(base->flag & SELECT)) {
-                               ED_base_object_select(base, BA_SELECT);
-                               changed = 1;
-                       }
-
-                       if (recursive)
-                               changed |= select_grouped_children(C, base->object, 1);
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static short select_grouped_parent(bContext *C)        /* Makes parent active and de-selected OBACT */
-{
-       Scene *scene= CTX_data_scene(C);
-       View3D *v3d= CTX_wm_view3d(C);
-
-       short changed = 0;
-       Base *baspar, *basact= CTX_data_active_base(C);
-
-       if (!basact || !(basact->object->parent)) return 0; /* we know OBACT is valid */
-
-       baspar= object_in_scene(basact->object->parent, scene);
-
-       /* can be NULL if parent in other scene */
-       if(baspar && BASE_SELECTABLE(v3d, baspar)) {
-               ED_base_object_select(basact, BA_DESELECT);
-               ED_base_object_select(baspar, BA_SELECT);
-               ED_base_object_activate(C, baspar);
-               changed = 1;
-       }
-       return changed;
-}
-
-
-#define GROUP_MENU_MAX 24
-static short select_grouped_group(bContext *C, Object *ob)     /* Select objects in the same group as the active */
-{
-       short changed = 0;
-       Group *group, *ob_groups[GROUP_MENU_MAX];
-       //char str[10 + (24*GROUP_MENU_MAX)];
-       //char *p = str;
-       int group_count=0; //, menu, i;
-
-       for (   group=G.main->group.first;
-                       group && group_count < GROUP_MENU_MAX;
-                       group=group->id.next
-               ) {
-               if (object_in_group (ob, group)) {
-                       ob_groups[group_count] = group;
-                       group_count++;
-               }
-       }
-
-       if (!group_count)
-               return 0;
-
-       else if (group_count == 1) {
-               group = ob_groups[0];
-               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-                       if (!(base->flag & SELECT) && object_in_group(base->object, group)) {
-                               ED_base_object_select(base, BA_SELECT);
-                               changed = 1;
-                       }
-               }
-               CTX_DATA_END;
-               return changed;
-       }
-#if 0 // XXX hows this work in 2.5?
-       /* build the menu. */
-       p += sprintf(str, "Groups%%t");
-       for (i=0; i<group_count; i++) {
-               group = ob_groups[i];
-               p += sprintf (p, "|%s%%x%i", group->id.name+2, i);
-       }
-
-       menu = pupmenu (str);
-       if (menu == -1)
-               return 0;
-
-       group = ob_groups[menu];
-       for (base= FIRSTBASE; base; base= base->next) {
-               if (!(base->flag & SELECT) && object_in_group(base->object, group)) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
-               }
-       }
-#endif
-       return changed;
-}
-
-static short select_grouped_object_hooks(bContext *C, Object *ob)
-{
-       Scene *scene= CTX_data_scene(C);
-       View3D *v3d= CTX_wm_view3d(C);
-
-       short changed = 0;
-       Base *base;
-       ModifierData *md;
-       HookModifierData *hmd;
-
-       for (md = ob->modifiers.first; md; md=md->next) {
-               if (md->type==eModifierType_Hook) {
-                       hmd= (HookModifierData*) md;
-                       if (hmd->object && !(hmd->object->flag & SELECT)) {
-                               base= object_in_scene(hmd->object, scene);
-                               if (base && (BASE_SELECTABLE(v3d, base))) {
-                                       ED_base_object_select(base, BA_SELECT);
-                                       changed = 1;
-                               }
-                       }
-               }
-       }
-       return changed;
-}
-
-/* Select objects woth the same parent as the active (siblings),
- * parent can be NULL also */
-static short select_grouped_siblings(bContext *C, Object *ob)
-{
-       short changed = 0;
-
-       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-               if ((base->object->parent==ob->parent)  && !(base->flag & SELECT)) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static short select_grouped_type(bContext *C, Object *ob)
-{
-       short changed = 0;
-
-       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-               if ((base->object->type == ob->type) && !(base->flag & SELECT)) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static short select_grouped_layer(bContext *C, Object *ob)
-{
-       char changed = 0;
-
-       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-               if ((base->lay & ob->lay) && !(base->flag & SELECT)) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static short select_grouped_index_object(bContext *C, Object *ob)
-{
-       char changed = 0;
-
-       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-               if ((base->object->index == ob->index) && !(base->flag & SELECT)) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static short select_grouped_color(bContext *C, Object *ob)
-{
-       char changed = 0;
-
-       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-               if (!(base->flag & SELECT) && (FloatCompare(base->object->col, ob->col, 0.005f))) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static short objects_share_gameprop(Object *a, Object *b)
-{
-       bProperty *prop;
-       /*make a copy of all its properties*/
-
-       for( prop= a->prop.first; prop; prop = prop->next ) {
-               if ( get_ob_property(b, prop->name) )
-                       return 1;
-       }
-       return 0;
-}
-
-static short select_grouped_gameprops(bContext *C, Object *ob)
-{
-       char changed = 0;
-
-       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-               if (!(base->flag & SELECT) && (objects_share_gameprop(base->object, ob))) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static int object_select_grouped_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *ob;
-       int nr = RNA_enum_get(op->ptr, "type");
-       short changed = 0, seltype;
-
-       seltype = RNA_enum_get(op->ptr, "seltype");
-       
-       if (seltype == 0) {
-               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-                       ED_base_object_select(base, BA_DESELECT);
-               }
-               CTX_DATA_END;
-       }
-       
-       ob= OBACT;
-       if(ob==0){ 
-               BKE_report(op->reports, RPT_ERROR, "No Active Object");
-               return OPERATOR_CANCELLED;
-       }
-       
-       if(nr==1)               changed = select_grouped_children(C, ob, 1);
-       else if(nr==2)  changed = select_grouped_children(C, ob, 0);
-       else if(nr==3)  changed = select_grouped_parent(C);
-       else if(nr==4)  changed = select_grouped_siblings(C, ob);
-       else if(nr==5)  changed = select_grouped_type(C, ob);
-       else if(nr==6)  changed = select_grouped_layer(C, ob);
-       else if(nr==7)  changed = select_grouped_group(C, ob);
-       else if(nr==8)  changed = select_grouped_object_hooks(C, ob);
-       else if(nr==9)  changed = select_grouped_index_object(C, ob);
-       else if(nr==10) changed = select_grouped_color(C, ob);
-       else if(nr==11) changed = select_grouped_gameprops(C, ob);
-       
-       if (changed) {
-               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-               return OPERATOR_FINISHED;
-       }
-       
-       return OPERATOR_CANCELLED;
-}
-
-void OBJECT_OT_select_grouped(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Select Grouped";
-       ot->description = "Select all visible objects grouped by various properties.";
-       ot->idname= "OBJECT_OT_select_grouped";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_select_grouped_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", "");
-       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
-
-}
-
-/* ****** selection by layer *******/
-
-static int object_select_by_layer_exec(bContext *C, wmOperator *op)
-{
-       unsigned int layernum;
-       short seltype;
-       
-       seltype = RNA_enum_get(op->ptr, "seltype");
-       layernum = RNA_int_get(op->ptr, "layer");
-       
-       if (seltype == 0) {
-               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-                       ED_base_object_select(base, BA_DESELECT);
-               }
-               CTX_DATA_END;
-       }
-               
-       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if(base->lay == (1<< (layernum -1)))
-                       ED_base_object_select(base, BA_SELECT);
-       }
-       CTX_DATA_END;
-       
-       /* undo? */
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_select_by_layer(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "select by layer";
-       ot->description = "Select all visible objects on a layer.";
-       ot->idname= "OBJECT_OT_select_by_layer";
-       
-       /* api callbacks */
-       /*ot->invoke = XXX - need a int grid popup*/
-       ot->exec= object_select_by_layer_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_int(ot->srna, "layer", 1, 1, 20, "Layer", "", 1, 20);
-       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
-}
-
-/* ****** invert selection *******/
-static int object_select_inverse_exec(bContext *C, wmOperator *op)
-{
-       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if (base->flag & SELECT)
-                       ED_base_object_select(base, BA_DESELECT);
-               else
-                       ED_base_object_select(base, BA_SELECT);
-       }
-       CTX_DATA_END;
-       
-       /* undo? */
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_select_inverse(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Select Inverse";
-       ot->description = "Invert selection of all visible objects.";
-       ot->idname= "OBJECT_OT_select_inverse";
-       
-       /* api callbacks */
-       ot->exec= object_select_inverse_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-}
-/* ****** (de)select All *******/
-
-static int object_select_de_select_all_exec(bContext *C, wmOperator *op)
-{
-       
-       int a=0, ok=0; 
-       
-       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if (base->flag & SELECT) {
-                       ok= a= 1;
-                       break;
-               }
-               else ok=1;
-       }
-       CTX_DATA_END;
-       
-       if (!ok) return OPERATOR_PASS_THROUGH;
-       
-       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if (a) ED_base_object_select(base, BA_DESELECT);
-               else ED_base_object_select(base, BA_SELECT);
-       }
-       CTX_DATA_END;
-       
-       /* undo? */
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_select_all_toggle(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "deselect all";
-       ot->description = "(de)select all visible objects in scene.";
-       ot->idname= "OBJECT_OT_select_all_toggle";
-       
-       /* api callbacks */
-       ot->exec= object_select_de_select_all_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-}
-/* ****** select mirror *******/
-/* finds the best possible flipped name. For renaming; check for unique names afterwards */
-/* if strip_number: removes number extensions */
-void object_flip_name (char *name)
-{
-       int     len;
-       char    prefix[128]={""};   /* The part before the facing */
-       char    suffix[128]={""};   /* The part after the facing */
-       char    replace[128]={""};  /* The replacement string */
-       char    number[128]={""};   /* The number extension string */
-       char    *index=NULL;
-
-       len= strlen(name);
-       if(len<3) return; // we don't do names like .R or .L
-
-       /* We first check the case with a .### extension, let's find the last period */
-       if(isdigit(name[len-1])) {
-               index= strrchr(name, '.'); // last occurrance
-               if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever!
-                       strcpy(number, index);
-                       *index= 0;
-                       len= strlen(name);
-               }
-       }
-
-       strcpy (prefix, name);
-
-#define IS_SEPARATOR(a) ((a)=='.' || (a)==' ' || (a)=='-' || (a)=='_')
-
-       /* first case; separator . - _ with extensions r R l L  */
-       if( IS_SEPARATOR(name[len-2]) ) {
-               switch(name[len-1]) {
-                       case 'l':
-                               prefix[len-1]= 0;
-                               strcpy(replace, "r");
-                               break;
-                       case 'r':
-                               prefix[len-1]= 0;
-                               strcpy(replace, "l");
-                               break;
-                       case 'L':
-                               prefix[len-1]= 0;
-                               strcpy(replace, "R");
-                               break;
-                       case 'R':
-                               prefix[len-1]= 0;
-                               strcpy(replace, "L");
-                               break;
-               }
-       }
-       /* case; beginning with r R l L , with separator after it */
-       else if( IS_SEPARATOR(name[1]) ) {
-               switch(name[0]) {
-                       case 'l':
-                               strcpy(replace, "r");
-                               strcpy(suffix, name+1);
-                               prefix[0]= 0;
-                               break;
-                       case 'r':
-                               strcpy(replace, "l");
-                               strcpy(suffix, name+1);
-                               prefix[0]= 0;
-                               break;
-                       case 'L':
-                               strcpy(replace, "R");
-                               strcpy(suffix, name+1);
-                               prefix[0]= 0;
-                               break;
-                       case 'R':
-                               strcpy(replace, "L");
-                               strcpy(suffix, name+1);
-                               prefix[0]= 0;
-                               break;
-               }
-       }
-       else if(len > 5) {
-               /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
-               index = BLI_strcasestr(prefix, "right");
-               if (index==prefix || index==prefix+len-5) {
-                       if(index[0]=='r') 
-                               strcpy (replace, "left");
-                       else {
-                               if(index[1]=='I') 
-                                       strcpy (replace, "LEFT");
-                               else
-                                       strcpy (replace, "Left");
-                       }
-                       *index= 0;
-                       strcpy (suffix, index+5);
-               }
-               else {
-                       index = BLI_strcasestr(prefix, "left");
-                       if (index==prefix || index==prefix+len-4) {
-                               if(index[0]=='l') 
-                                       strcpy (replace, "right");
-                               else {
-                                       if(index[1]=='E') 
-                                               strcpy (replace, "RIGHT");
-                                       else
-                                               strcpy (replace, "Right");
-                               }
-                               *index= 0;
-                               strcpy (suffix, index+4);
-                       }
-               }
-       }
-
-#undef IS_SEPARATOR
-
-       sprintf (name, "%s%s%s%s", prefix, replace, suffix, number);
-}
-
-static int object_select_mirror_exec(bContext *C, wmOperator *op)
-{
-       char tmpname[32];
-       short seltype;
-       
-       seltype = RNA_enum_get(op->ptr, "seltype");
-       
-       CTX_DATA_BEGIN(C, Base*, primbase, selected_bases) {
-
-               strcpy(tmpname, primbase->object->id.name+2);
-               object_flip_name(tmpname);
-               
-               CTX_DATA_BEGIN(C, Base*, secbase, visible_bases) {
-                       if(!strcmp(secbase->object->id.name+2, tmpname)) {
-                               ED_base_object_select(secbase, BA_SELECT);
-                       }
-               }
-               CTX_DATA_END;
-               
-               if (seltype == 0) ED_base_object_select(primbase, BA_DESELECT);
-               
-       }
-       CTX_DATA_END;
-       
-       /* undo? */
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_select_mirror(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Select Mirror";
-       ot->description = "Select the Mirror objects of the selected object eg. L.sword -> R.sword";
-       ot->idname= "OBJECT_OT_select_mirror";
-       
-       /* api callbacks */
-       ot->exec= object_select_mirror_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
-}
-/* ****** random selection *******/
-
-static int object_select_random_exec(bContext *C, wmOperator *op)
-{      
-       float percent;
-       short seltype;
-       
-       seltype = RNA_enum_get(op->ptr, "seltype");
-       
-       if (seltype == 0) {
-               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-                       ED_base_object_select(base, BA_DESELECT);
-               }
-               CTX_DATA_END;
-       }
-       percent = RNA_float_get(op->ptr, "percent");
-               
-       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if (BLI_frand() < percent) {
-                               ED_base_object_select(base, BA_SELECT);
-               }
-       }
-       CTX_DATA_END;
-       
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_select_random(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Random select";
-       ot->description = "Set select on random visible objects.";
-       ot->idname= "OBJECT_OT_select_random";
-       
-       /* api callbacks */
-       /*ot->invoke= object_select_random_invoke XXX - need a number popup ;*/
-       ot->exec = object_select_random_exec;
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_float_percentage(ot->srna, "percent", 0.5f, 0.0f, 1.0f, "Percent", "percentage of objects to randomly select", 0.0001f, 1.0f);
-       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
-}
-
-/* ******** Clear object Translation *********** */
-
-static int object_location_clear_exec(bContext *C, wmOperator *op)
-{
-       int armature_clear= 0;
-
-       CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
-                       if ((ob->protectflag & OB_LOCK_LOCX)==0)
-                               ob->loc[0]= ob->dloc[0]= 0.0f;
-                       if ((ob->protectflag & OB_LOCK_LOCY)==0)
-                               ob->loc[1]= ob->dloc[1]= 0.0f;
-                       if ((ob->protectflag & OB_LOCK_LOCZ)==0)
-                               ob->loc[2]= ob->dloc[2]= 0.0f;
-               }
-               ob->recalc |= OB_RECALC_OB;
-       }
-       CTX_DATA_END;
-
-       if(armature_clear==0) /* in this case flush was done */
-               ED_anim_dag_flush_update(C);    
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-
-
-void OBJECT_OT_location_clear(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Clear Location";
-       ot->description = "Clear the object's location.";
-       ot->idname= "OBJECT_OT_location_clear";
-       
-       /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_location_clear_exec;
-       ot->poll= ED_operator_object_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-static int object_rotation_clear_exec(bContext *C, wmOperator *op)
-{
-       int armature_clear= 0;
-
-       CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
-                       /* eulers can only get cleared if they are not protected */
-                       if ((ob->protectflag & OB_LOCK_ROTX)==0)
-                               ob->rot[0]= ob->drot[0]= 0.0f;
-                       if ((ob->protectflag & OB_LOCK_ROTY)==0)
-                               ob->rot[1]= ob->drot[1]= 0.0f;
-                       if ((ob->protectflag & OB_LOCK_ROTZ)==0)
-                               ob->rot[2]= ob->drot[2]= 0.0f;
-               }
-               ob->recalc |= OB_RECALC_OB;
-       }
-       CTX_DATA_END;
-
-       if(armature_clear==0) /* in this case flush was done */
-               ED_anim_dag_flush_update(C);    
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-
-
-void OBJECT_OT_rotation_clear(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Clear Rotation";
-       ot->description = "Clear the object's rotation.";
-       ot->idname= "OBJECT_OT_rotation_clear";
-       
-       /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_rotation_clear_exec;
-       ot->poll= ED_operator_object_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-static int object_scale_clear_exec(bContext *C, wmOperator *op)
-{
-       int armature_clear= 0;
-
-       CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
-                       if ((ob->protectflag & OB_LOCK_SCALEX)==0) {
-                               ob->dsize[0]= 0.0f;
-                               ob->size[0]= 1.0f;
-                       }
-                       if ((ob->protectflag & OB_LOCK_SCALEY)==0) {
-                               ob->dsize[1]= 0.0f;
-                               ob->size[1]= 1.0f;
-                       }
-                       if ((ob->protectflag & OB_LOCK_SCALEZ)==0) {
-                               ob->dsize[2]= 0.0f;
-                               ob->size[2]= 1.0f;
-                       }
-               }
-               ob->recalc |= OB_RECALC_OB;
-       }
-       CTX_DATA_END;
-       
-       if(armature_clear==0) /* in this case flush was done */
-               ED_anim_dag_flush_update(C);    
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_scale_clear(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Clear Scale";
-       ot->description = "Clear the object's scale.";
-       ot->idname= "OBJECT_OT_scale_clear";
-       
-       /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_scale_clear_exec;
-       ot->poll= ED_operator_object_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-static int object_origin_clear_exec(bContext *C, wmOperator *op)
-{
-       float *v1, *v3, mat[3][3];
-       int armature_clear= 0;
-
-       CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if(ob->parent) {
-                       v1= ob->loc;
-                       v3= ob->parentinv[3];
-                       
-                       Mat3CpyMat4(mat, ob->parentinv);
-                       VECCOPY(v3, v1);
-                       v3[0]= -v3[0];
-                       v3[1]= -v3[1];
-                       v3[2]= -v3[2];
-                       Mat3MulVecfl(mat, v3);
-               }
-               ob->recalc |= OB_RECALC_OB;
-       }
-       CTX_DATA_END;
-
-       if(armature_clear==0) /* in this case flush was done */
-               ED_anim_dag_flush_update(C);    
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_origin_clear(wmOperatorType *ot)
-{
-
-       /* identifiers */
-       ot->name= "Clear Origin";
-       ot->description = "Clear the object's origin.";
-       ot->idname= "OBJECT_OT_origin_clear";
-       
-       /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_origin_clear_exec;
-       ot->poll= ED_operator_object_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-/* ********* clear/set restrict view *********/
-static int object_restrictview_clear_exec(bContext *C, wmOperator *op)
-{
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
-       Scene *scene= CTX_data_scene(C);
-       Base *base;
-       int changed = 0;
-       
-       /* XXX need a context loop to handle such cases */
-       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) {
-               DAG_scene_sort(scene);
-               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
-       }
-
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_restrictview_clear(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Clear Restrict View";
-       ot->description = "Reveal the object by setting the restrictview flag.";
-       ot->idname= "OBJECT_OT_restrictview_clear";
-       
-       /* api callbacks */
-       ot->exec= object_restrictview_clear_exec;
-       ot->poll= ED_operator_view3d_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-static int object_restrictview_set_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       short changed = 0;
-       int unselected= RNA_boolean_get(op->ptr, "unselected");
-       
-       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if(!unselected) {
-                       if (base->flag & SELECT){
-                               base->flag &= ~SELECT;
-                               base->object->flag = base->flag;
-                               base->object->restrictflag |= OB_RESTRICT_VIEW;
-                               changed = 1;
-                               if (base==BASACT) {
-                                       ED_base_object_activate(C, NULL);
-                               }
-                       }
-               }
-               else {
-                       if (!(base->flag & SELECT)){
-                               base->object->restrictflag |= OB_RESTRICT_VIEW;
-                               changed = 1;
-                       }
-               }       
-       }
-       CTX_DATA_END;
-
-       if (changed) {
-               DAG_scene_sort(scene);
-               
-               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-               
-       }
-
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_restrictview_set(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Set Restrict View";
-       ot->description = "Hide the object by setting the restrictview flag.";
-       ot->idname= "OBJECT_OT_restrictview_set";
-       
-       /* api callbacks */
-       ot->exec= object_restrictview_set_exec;
-       ot->poll= ED_operator_view3d_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects.");
-       
-}
-/* ************* Slow Parent ******************* */
-static int object_slowparent_set_exec(bContext *C, wmOperator *op)
-{
-
-       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-               
-               if(base->object->parent) base->object->partype |= PARSLOW;
-               base->object->recalc |= OB_RECALC_OB;
-               
-       }
-       CTX_DATA_END;
-
-       ED_anim_dag_flush_update(C);    
-       
-       WM_event_add_notifier(C, NC_SCENE, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_slowparent_set(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Set Slow Parent";
-       ot->description = "Set the object's slow parent.";
-       ot->idname= "OBJECT_OT_slow_parent_set";
-       
-       /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_slowparent_set_exec;
-       ot->poll= ED_operator_view3d_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-static int object_slowparent_clear_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-
-       CTX_DATA_BEGIN(C, Base*, base, selected_editable_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;
-                       }
-               }
-               
-       }
-       CTX_DATA_END;
-
-       ED_anim_dag_flush_update(C);    
-       
-       WM_event_add_notifier(C, NC_SCENE, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_slowparent_clear(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Clear Slow Parent";
-       ot->description = "Clear the object's slow parent.";
-       ot->idname= "OBJECT_OT_slow_parent_clear";
-       
-       /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_slowparent_clear_exec;
-       ot->poll= ED_operator_view3d_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-/* ******************** **************** */
-
-/* only in edit mode */
-void make_vertex_parent(Scene *scene, Object *obedit, View3D *v3d)
-{
-       EditVert *eve;
-       Base *base;
-       Curve *cu= obedit->data;
-       Nurb *nu;
-       BezTriple *bezt;
-       BPoint *bp;
-       Object *par, *ob;
-       int a, v1=0, v2=0, v3=0, v4=0, nr=1;
-       
-       /* we need 1 to 3 selected vertices */
-       
-       if(obedit->type==OB_MESH) {
-               Mesh *me= obedit->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-
-               eve= em->verts.first;
-               while(eve) {
-                       if(eve->f & 1) {
-                               if(v1==0) v1= nr;
-                               else if(v2==0) v2= nr;
-                               else if(v3==0) v3= nr;
-                               else if(v4==0) v4= nr;
-                               else break;
-                       }
-                       nr++;
-                       eve= eve->next;
-               }
-
-               BKE_mesh_end_editmesh(me, em);
-       }
-       else if(ELEM(obedit->type, OB_SURF, OB_CURVE)) {
-               ListBase *editnurb= curve_get_editcurve(obedit);
-
-               nu= editnurb->first;
-               while(nu) {
-                       if(nu->type == CU_BEZIER) {
-                               bezt= nu->bezt;
-                               a= nu->pntsu;
-                               while(a--) {
-                                       if(BEZSELECTED_HIDDENHANDLES(cu, bezt)) {
-                                               if(v1==0) v1= nr;
-                                               else if(v2==0) v2= nr;
-                                               else if(v3==0) v3= nr;
-                                               else if(v4==0) v4= nr;
-                                               else break;
-                                       }
-                                       nr++;
-                                       bezt++;
-                               }
-                       }
-                       else {
-                               bp= nu->bp;
-                               a= nu->pntsu*nu->pntsv;
-                               while(a--) {
-                                       if(bp->f1 & SELECT) {
-                                               if(v1==0) v1= nr;
-                                               else if(v2==0) v2= nr;
-                                               else if(v3==0) v3= nr;
-                                               else if(v4==0) v4= nr;
-                                               else break;
-                                       }
-                                       nr++;
-                                       bp++;
-                               }
-                       }
-                       nu= nu->next;
-               }
-       }
-       else if(obedit->type==OB_LATTICE) {
-               Lattice *lt= obedit->data;
-               
-               a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
-               bp= lt->editlatt->def;
-               while(a--) {
-                       if(bp->f1 & SELECT) {
-                               if(v1==0) v1= nr;
-                               else if(v2==0) v2= nr;
-                               else if(v3==0) v3= nr;
-                               else if(v4==0) v4= nr;
-                               else break;
-                       }
-                       nr++;
-                       bp++;
-               }
-       }
-       
-       if(v4 || !((v1 && v2==0 && v3==0) || (v1 && v2 && v3)) ) {
-               error("Select either 1 or 3 vertices to parent to");
-               return;
-       }
-       
-       if(okee("Make vertex parent")==0) return;
-       
-       for(base= FIRSTBASE; base; base= base->next) {
-               if(TESTBASELIB(v3d, base)) {
-                       if(base!=BASACT) {
-                               
-                               ob= base->object;
-                               ob->recalc |= OB_RECALC;
-                               par= BASACT->object->parent;
-                               
-                               while(par) {
-                                       if(par==ob) break;
-                                       par= par->parent;
-                               }
-                               if(par) {
-                                       error("Loop in parents");
-                               }
-                               else {
-                                       Object workob;
-                                       
-                                       ob->parent= BASACT->object;
-                                       if(v3) {
-                                               ob->partype= PARVERT3;
-                                               ob->par1= v1-1;
-                                               ob->par2= v2-1;
-                                               ob->par3= v3-1;
-
-                                               /* inverse parent matrix */
-                                               what_does_parent(scene, ob, &workob);
-                                               Mat4Invert(ob->parentinv, workob.obmat);
-                                       }
-                                       else {
-                                               ob->partype= PARVERT1;
-                                               ob->par1= v1-1;
-
-                                               /* inverse parent matrix */
-                                               what_does_parent(scene, ob, &workob);
-                                               Mat4Invert(ob->parentinv, workob.obmat);
-                                       }
-                               }
-                       }
-               }
-       }
-       
-       DAG_scene_sort(scene);
-}
-
-
-/* ******************** make proxy operator *********************** */
-
-/* present menu listing the possible objects within the group to proxify */
-static void proxy_group_objects_menu (bContext *C, wmOperator *op, Object *ob, Group *group)
-{
-       uiPopupMenu *pup;
-       uiLayout *layout;
-       GroupObject *go;
-       int len=0;
-       
-       /* check if there are any objects within the group to assign for */
-       for (go= group->gobject.first; go; go= go->next) {
-               if (go->ob) len++;
-       }
-       if (len==0) return;
-       
-       /* now create the menu to draw */
-       pup= uiPupMenuBegin(C, "Make Proxy For:", 0);
-       layout= uiPupMenuLayout(pup);
-       
-       for (go= group->gobject.first; go; go= go->next) {
-               if (go->ob) {
-                       PointerRNA props_ptr;
-                       
-                       /* create operator menu item with relevant properties filled in */
-                       props_ptr= uiItemFullO(layout, go->ob->id.name+2, 0, op->idname, NULL, WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS);
-                       RNA_string_set(&props_ptr, "object", go->ob->id.name+2);
-                       RNA_string_set(&props_ptr, "group_object", go->ob->id.name+2);
-               }
-       }
-       
-       /* display the menu, and be done */
-       uiPupMenuEnd(C, pup);
-}
-
-/* set the object to proxify */
-static int make_proxy_invoke (bContext *C, wmOperator *op, wmEvent *evt)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C);
-       
-       /* sanity checks */
-       if (!scene || scene->id.lib || !ob)
-               return OPERATOR_CANCELLED;
-               
-       /* Get object to work on - use a menu if we need to... */
-       if (ob->dup_group && ob->dup_group->id.lib) {
-               /* gives menu with list of objects in group */
-               proxy_group_objects_menu(C, op, ob, ob->dup_group);
-       }
-       else if (ob->id.lib) {
-               uiPopupMenu *pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
-               uiLayout *layout= uiPupMenuLayout(pup);
-               PointerRNA props_ptr;
-               
-               /* create operator menu item with relevant properties filled in */
-               props_ptr= uiItemFullO(layout, op->type->name, 0, op->idname, NULL, WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS);
-               RNA_string_set(&props_ptr, "object", ob->id.name+2);
-               
-               /* present the menu and be done... */
-               uiPupMenuEnd(C, pup);
-       }
-       else {
-               /* error.. cannot continue */
-               BKE_report(op->reports, RPT_ERROR, "Can only make proxy for a referenced object or group");
-       }
-       
-       /* this invoke just calls another instance of this operator... */
-       return OPERATOR_CANCELLED;
-}
-
-static int make_proxy_exec (bContext *C, wmOperator *op)
-{
-       Object *ob=NULL, *gob=NULL;
-       Scene *scene= CTX_data_scene(C);
-       char ob_name[21], gob_name[21];
-       
-       /* get object and group object
-        *      - firstly names
-        *      - then pointers from context 
-        */
-       RNA_string_get(op->ptr, "object", ob_name);
-       RNA_string_get(op->ptr, "group_object", gob_name);
-       
-       if (gob_name[0]) {
-               Group *group;
-               GroupObject *go;
-               
-               /* active object is group object... */
-               // FIXME: we should get the nominated name instead
-               gob= CTX_data_active_object(C);
-               group= gob->dup_group;
-               
-               /* find the object to affect */
-               for (go= group->gobject.first; go; go= go->next) {
-                       if ((go->ob) && strcmp(go->ob->id.name+2, gob_name)==0) {
-                               ob= go->ob;
-                               break;
-                       }
-               }
-       }
-       else {
-               /* just use the active object for now */
-               // FIXME: we should get the nominated name instead
-               ob= CTX_data_active_object(C);
-       }
-       
-       if (ob) {
-               Object *newob;
-               Base *newbase, *oldbase= BASACT;
-               char name[32];
-               
-               /* Add new object for the proxy */
-               newob= add_object(scene, OB_EMPTY);
-               if (gob)
-                       strcpy(name, gob->id.name+2);
-               else
-                       strcpy(name, ob->id.name+2);
-               strcat(name, "_proxy");
-               rename_id(&newob->id, name);
-               
-               /* set layers OK */
-               newbase= BASACT;        /* add_object sets active... */
-               newbase->lay= oldbase->lay;
-               newob->lay= newbase->lay;
-               
-               /* remove base, leave user count of object, it gets linked in object_make_proxy */
-               if (gob==NULL) {
-                       BLI_remlink(&scene->base, oldbase);
-                       MEM_freeN(oldbase);
-               }
-               
-               object_make_proxy(newob, ob, gob);
-               
-               /* depsgraph flushes are needed for the new data */
-               DAG_scene_sort(scene);
-               DAG_id_flush_update(&newob->id, OB_RECALC);
-               
-               WM_event_add_notifier(C, NC_OBJECT, NULL);
-       }
-       else {
-               BKE_report(op->reports, RPT_ERROR, "No object to make proxy for");
-               return OPERATOR_CANCELLED;
-       }
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_proxy_make (wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Make Proxy";
-       ot->idname= "OBJECT_OT_proxy_make";
-       ot->description= "Add empty object to become local replacement data of a library-linked object";
-       
-       /* callbacks */
-       ot->invoke= make_proxy_invoke;
-       ot->exec= make_proxy_exec;
-       ot->poll= ED_operator_object_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* properties */
-       RNA_def_string(ot->srna, "object", "", 19, "Proxy Object", "Name of lib-linked/grouped object to make a proxy for.");
-       RNA_def_string(ot->srna, "group_object", "", 19, "Group Object", "Name of group instancer (if applicable).");
-}
-
-/* ******************** make parent operator *********************** */
-
-#define PAR_OBJECT                             0
-#define PAR_ARMATURE                   1
-#define PAR_ARMATURE_NAME              2
-#define PAR_ARMATURE_ENVELOPE  3
-#define PAR_ARMATURE_AUTO              4
-#define PAR_BONE                               5
-#define PAR_CURVE                              6
-#define PAR_FOLLOW                             7
-#define PAR_PATH_CONST                 8
-#define PAR_LATTICE                            9
-#define PAR_VERTEX                             10
-#define PAR_TRIA                               11
-
-static EnumPropertyItem prop_make_parent_types[] = {
-       {PAR_OBJECT, "OBJECT", 0, "Object", ""},
-       {PAR_ARMATURE, "ARMATURE", 0, "Armature Deform", ""},
-       {PAR_ARMATURE_NAME, "ARMATURE_NAME", 0, "   With Empty Groups", ""},
-       {PAR_ARMATURE_AUTO, "ARMATURE_AUTO", 0, "   With Automatic Weights", ""},
-       {PAR_ARMATURE_ENVELOPE, "ARMATURE_ENVELOPE", 0, "   With Envelope Weights", ""},
-       {PAR_BONE, "BONE", 0, "Bone", ""},
-       {PAR_CURVE, "CURVE", 0, "Curve Deform", ""},
-       {PAR_FOLLOW, "FOLLOW", 0, "Follow Path", ""},
-       {PAR_PATH_CONST, "PATH_CONST", 0, "Path Constraint", ""},
-       {PAR_LATTICE, "LATTICE", 0, "Lattice Deform", ""},
-       {PAR_VERTEX, "VERTEX", 0, "Vertex", ""},
-       {PAR_TRIA, "TRIA", 0, "Triangle", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-static int test_parent_loop(Object *par, Object *ob)
-{
-       /* test if 'ob' is a parent somewhere in par's parents */
-       
-       if(par == NULL) return 0;
-       if(ob == par) return 1;
-       
-       return test_parent_loop(par->parent, ob);
-}
-
-void ED_object_parent(Object *ob, Object *par, int type, const char *substr)
-{
-       if(!par || test_parent_loop(par, ob)) {
-               ob->parent= NULL;
-               ob->partype= PAROBJECT;
-               ob->parsubstr[0]= 0;
-               return;
-       }
-
-       /* this could use some more checks */
-
-       ob->parent= par;
-       ob->partype &= ~PARTYPE;
-       ob->partype |= type;
-       BLI_strncpy(ob->parsubstr, substr, sizeof(ob->parsubstr));
-}
-
-static int parent_set_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *par= CTX_data_active_object(C);
-       bPoseChannel *pchan= NULL;
-       int partype= RNA_enum_get(op->ptr, "type");
-       int pararm= ELEM4(partype, PAR_ARMATURE, PAR_ARMATURE_NAME, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO);
-       
-       par->recalc |= OB_RECALC_OB;
-       
-       /* preconditions */
-       if(partype==PAR_FOLLOW || partype==PAR_PATH_CONST) {
-               if(par->type!=OB_CURVE)
-                       return OPERATOR_CANCELLED;
-               else {
-                       Curve *cu= par->data;
-                       
-                       if((cu->flag & CU_PATH)==0) {
-                               cu->flag |= CU_PATH|CU_FOLLOW;
-                               makeDispListCurveTypes(scene, par, 0);  /* force creation of path data */
-                       }
-                       else cu->flag |= CU_FOLLOW;
-                       
-                       /* fall back on regular parenting now */
-                       partype= PAR_OBJECT;
-               }               
-       }
-       else if(partype==PAR_BONE) {
-               pchan= get_active_posechannel(par);
-               
-               if(pchan==NULL) {
-                       error("No active Bone");
-                       return OPERATOR_CANCELLED;
-               }
-       }
-       
-       /* context itterator */
-       CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               
-               if(ob!=par) {
-                       
-                       if( test_parent_loop(par, ob) ) {
-                               error("Loop in parents");
-                       }
-                       else {
-                               Object workob;
-                               
-                               /* apply transformation of previous parenting */
-                               ED_object_apply_obmat(ob);
-                               
-                               ob->parent= par;
-                               
-                               /* handle types */
-                               if (pchan)
-                                       strcpy (ob->parsubstr, pchan->name);
-                               else
-                                       ob->parsubstr[0]= 0;
-                               
-                               /* constraint */
-                               if(partype==PAR_PATH_CONST) {
-                                       bConstraint *con;
-                                       bFollowPathConstraint *data;
-                                       float cmat[4][4], vec[3];
-                                       
-                                       con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
-                                       strcpy (con->name, "AutoPath");
-                                       
-                                       data = con->data;
-                                       data->tar = par;
-                                       
-                                       add_constraint_to_object(con, ob);
-                                       
-                                       get_constraint_target_matrix(con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra - give_timeoffset(ob));
-                                       VecSubf(vec, ob->obmat[3], cmat[3]);
-                                       
-                                       ob->loc[0] = vec[0];
-                                       ob->loc[1] = vec[1];
-                               }
-                               else if(pararm && ob->type==OB_MESH && par->type == OB_ARMATURE) {
-                                       if(partype == PAR_ARMATURE_NAME)
-                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_NAME);
-                                       else if(partype == PAR_ARMATURE_ENVELOPE)
-                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_ENVELOPE);
-                                       else if(partype == PAR_ARMATURE_AUTO)
-                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_AUTO);
-                                       
-                                       /* get corrected inverse */
-                                       ob->partype= PAROBJECT;
-                                       what_does_parent(scene, ob, &workob);
-                                       
-                                       ob->partype= PARSKEL;
-
-                                       Mat4Invert(ob->parentinv, workob.obmat);
-                               }
-                               else {
-                                       /* calculate inverse parent matrix */
-                                       what_does_parent(scene, ob, &workob);
-                                       Mat4Invert(ob->parentinv, workob.obmat);
-                               }
-                               
-                               ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
-                               
-                               if( ELEM(partype, PAR_CURVE, PAR_LATTICE) || pararm )
-                                       ob->partype= PARSKEL; /* note, dna define, not operator property */
-                               else
-                                       ob->partype= PAROBJECT; /* note, dna define, not operator property */
-                       }
-               }
-       }
-       CTX_DATA_END;
-       
-       DAG_scene_sort(CTX_data_scene(C));
-       ED_anim_dag_flush_update(C);
-       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-
-static int parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       Object *ob= CTX_data_active_object(C);
-       uiPopupMenu *pup= uiPupMenuBegin(C, "Set Parent To", 0);
-       uiLayout *layout= uiPupMenuLayout(pup);
-       
-       uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
-       uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_OBJECT);
-       
-       /* ob becomes parent, make the associated menus */
-       if(ob->type==OB_ARMATURE) {
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE);
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE_NAME);
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE_ENVELOPE);
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE_AUTO);
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_BONE);
-       }
-       else if(ob->type==OB_CURVE) {
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_CURVE);
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_FOLLOW);
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_PATH_CONST);
-       }
-       else if(ob->type == OB_LATTICE) {
-               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_LATTICE);
-       }
-       
-       uiPupMenuEnd(C, pup);
-       
-       return OPERATOR_CANCELLED;
-}
-
-
-void OBJECT_OT_parent_set(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Make Parent";
-       ot->description = "Set the object's parenting.";
-       ot->idname= "OBJECT_OT_parent_set";
-       
-       /* api callbacks */
-       ot->invoke= parent_set_invoke;
-       ot->exec= parent_set_exec;
-       
-       ot->poll= ED_operator_object_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_make_parent_types, 0, "Type", "");
-}
-
-/* *** make track ***** */
-static EnumPropertyItem prop_make_track_types[] = {
-       {1, "TRACKTO", 0, "TrackTo Constraint", ""},
-       {2, "LOCKTRACK", 0, "LockTrack Constraint", ""},
-       {3, "OLDTRACK", 0, "Old Track", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-static int track_set_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       int type= RNA_enum_get(op->ptr, "type");
-               
-       if(type == 1) {
-               bConstraint *con;
-               bTrackToConstraint *data;
-
-               CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-                       if(base!=BASACT) {
-                               con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
-                               strcpy (con->name, "AutoTrack");
-
-                               data = con->data;
-                               data->tar = BASACT->object;
-                               base->object->recalc |= OB_RECALC;
-                               
-                               /* Lamp and Camera track differently by default */
-                               if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
-                                       data->reserved1 = TRACK_nZ;
-                                       data->reserved2 = UP_Y;
-                               }
-
-                               add_constraint_to_object(con, base->object);
-                       }
-               }
-               CTX_DATA_END;
-       }
-       else if(type == 2) {
-               bConstraint *con;
-               bLockTrackConstraint *data;
-
-               CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-                       if(base!=BASACT) {
-                               con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
-                               strcpy (con->name, "AutoTrack");
-
-                               data = con->data;
-                               data->tar = BASACT->object;
-                               base->object->recalc |= OB_RECALC;
-                               
-                               /* Lamp and Camera track differently by default */
-                               if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
-                                       data->trackflag = TRACK_nZ;
-                                       data->lockflag = LOCK_Y;
-                               }
-
-                               add_constraint_to_object(con, base->object);
-                       }
-               }
-               CTX_DATA_END;
-       }
-       else {
-               CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-                       if(base!=BASACT) {
-                               base->object->track= BASACT->object;
-                               base->object->recalc |= OB_RECALC;
-                       }
-               }
-               CTX_DATA_END;
-       }
-       DAG_scene_sort(CTX_data_scene(C));
-       ED_anim_dag_flush_update(C);    
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_track_set(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Make Track";
-       ot->description = "Make the object track another object, either by constraint or old way or locked track.";
-       ot->idname= "OBJECT_OT_track_set";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= track_set_exec;
-       
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_make_track_types, 0, "Type", "");
-}
-
-/* ************* Make Dupli Real ********* */
-static void make_object_duplilist_real(Scene *scene, View3D *v3d, Base *base)
-{
-       Base *basen;
-       Object *ob;
-       ListBase *lb;
-       DupliObject *dob;
-       
-       if(!base && !(base = BASACT))
-               return;
-       
-       if(!(base->object->transflag & OB_DUPLI))
-               return;
-       
-       lb= object_duplilist(scene, base->object);
-       
-       for(dob= lb->first; dob; dob= dob->next) {
-               ob= copy_object(dob->ob);
-               /* font duplis can have a totcol without material, we get them from parent
-               * should be implemented better...
-               */
-               if(ob->mat==NULL) ob->totcol= 0;
-               
-               basen= MEM_dupallocN(base);
-               basen->flag &= ~OB_FROMDUPLI;
-               BLI_addhead(&scene->base, basen);       /* addhead: othwise eternal loop */
-               basen->object= ob;
-               ob->ipo= NULL;          /* make sure apply works */
-               ob->parent= ob->track= NULL;
-               ob->disp.first= ob->disp.last= NULL;
-               ob->transflag &= ~OB_DUPLI;     
-               
-               Mat4CpyMat4(ob->obmat, dob->mat);
-               ED_object_apply_obmat(ob);
-       }
-       
-       copy_object_set_idnew(scene, v3d, 0);
-       
-       free_object_duplilist(lb);
-       
-       base->object->transflag &= ~OB_DUPLI;   
-}
-
-
-static int object_duplicates_make_real_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
-       
-       clear_id_newpoins();
-               
-       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-               make_object_duplilist_real(scene, v3d, base);
-       }
-       CTX_DATA_END;
-
-       DAG_scene_sort(CTX_data_scene(C));
-       ED_anim_dag_flush_update(C);    
-       WM_event_add_notifier(C, NC_SCENE, CTX_data_scene(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Make Duplicates Real";
-       ot->description = "Make dupli objects attached to this object real.";
-       ot->idname= "OBJECT_OT_duplicates_make_real";
-       
-       /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_duplicates_make_real_exec;
-       
-       ot->poll= ED_operator_scene_editable;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-/* ******************* Set Object Center ********************** */
-
-static EnumPropertyItem prop_set_center_types[] = {
-       {0, "CENTER", 0, "ObData to Center", "Move object data around Object center"},
-       {1, "CENTERNEW", 0, "Center New", "Move Object center to center of object data"},
-       {2, "CENTERCURSOR", 0, "Center Cursor", "Move Object Center to position of the 3d cursor"},
-       {0, NULL, 0, NULL, NULL}
-};
-
-/* 0 == do center, 1 == center new, 2 == center cursor */
-static int object_center_set_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
-       Object *obedit= CTX_data_edit_object(C);
-       Object *ob;
-       Mesh *me, *tme;
-       Curve *cu;
-/*     BezTriple *bezt;
-       BPoint *bp; */
-       Nurb *nu, *nu1;
-       EditVert *eve;
-       float cent[3], centn[3], min[3], max[3], omat[3][3];
-       int a, total= 0;
-       int centermode = RNA_enum_get(op->ptr, "type");
-       
-       /* keep track of what is changed */
-       int tot_change=0, tot_lib_error=0, tot_multiuser_arm_error=0;
-       MVert *mvert;
-
-       if(scene->id.lib || v3d==NULL){
-               BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed on Lib data");
-                return OPERATOR_CANCELLED;
-       }
-       if (obedit && centermode > 0) {
-               BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in EditMode");
-               return OPERATOR_CANCELLED;
-       }       
-       cent[0]= cent[1]= cent[2]= 0.0; 
-       
-       if(obedit) {
-
-               INIT_MINMAX(min, max);
-       
-               if(obedit->type==OB_MESH) {
-                       Mesh *me= obedit->data;
-                       EditMesh *em = BKE_mesh_get_editmesh(me);
-
-                       for(eve= em->verts.first; eve; eve= eve->next) {
-                               if(v3d->around==V3D_CENTROID) {
-                                       total++;
-                                       VECADD(cent, cent, eve->co);
-                               }
-                               else {
-                                       DO_MINMAX(eve->co, min, max);
-                               }
-                       }
-                       
-                       if(v3d->around==V3D_CENTROID) {
-                               VecMulf(cent, 1.0f/(float)total);
-                       }
-                       else {
-                               cent[0]= (min[0]+max[0])/2.0f;
-                               cent[1]= (min[1]+max[1])/2.0f;
-                               cent[2]= (min[2]+max[2])/2.0f;
-                       }
-                       
-                       for(eve= em->verts.first; eve; eve= eve->next) {
-                               VecSubf(eve->co, eve->co, cent);                        
-                       }
-                       
-                       recalc_editnormals(em);
-                       tot_change++;
-                       DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
-                       BKE_mesh_end_editmesh(me, em);
-               }
-       }
-       
-       /* reset flags */
-       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-                       base->object->flag &= ~OB_DONE;
-       }
-       CTX_DATA_END;
-       
-       for (me= G.main->mesh.first; me; me= me->id.next) {
-               me->flag &= ~ME_ISDONE;
-       }
-       
-       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-               if((base->object->flag & OB_DONE)==0) {
-                       base->object->flag |= OB_DONE;
-                               
-                       if(obedit==NULL && (me=get_mesh(base->object)) ) {
-                               if (me->id.lib) {
-                                       tot_lib_error++;
-                               } else {
-                                       if(centermode==2) {
-                                               VECCOPY(cent, give_cursor(scene, v3d));
-                                               Mat4Invert(base->object->imat, base->object->obmat);
-                                               Mat4MulVecfl(base->object->imat, cent);
-                                       } else {
-                                               INIT_MINMAX(min, max);
-                                               mvert= me->mvert;
-                                               for(a=0; a<me->totvert; a++, mvert++) {
-                                                       DO_MINMAX(mvert->co, min, max);
-                                               }
-                                       
-                                               cent[0]= (min[0]+max[0])/2.0f;
-                                               cent[1]= (min[1]+max[1])/2.0f;
-                                               cent[2]= (min[2]+max[2])/2.0f;
-                                       }
-
-                                       mvert= me->mvert;
-                                       for(a=0; a<me->totvert; a++, mvert++) {
-                                               VecSubf(mvert->co, mvert->co, cent);
-                                       }
-                                       
-                                       if (me->key) {
-                                               KeyBlock *kb;
-                                               for (kb=me->key->block.first; kb; kb=kb->next) {
-                                                       float *fp= kb->data;
-                                                       
-                                                       for (a=0; a<kb->totelem; a++, fp+=3) {
-                                                               VecSubf(fp, fp, cent);
-                                                       }
-                                               }
-                                       }
-                                               
-                                       me->flag |= ME_ISDONE;
-                                               
-                                       if(centermode) {
-                                               Mat3CpyMat4(omat, base->object->obmat);
-                                               
-                                               VECCOPY(centn, cent);
-                                               Mat3MulVecfl(omat, centn);
-                                               base->object->loc[0]+= centn[0];
-                                               base->object->loc[1]+= centn[1];
-                                               base->object->loc[2]+= centn[2];
-                                               
-                                               where_is_object(scene, base->object);
-                                               ignore_parent_tx(scene, base->object);
-                                               
-                                               /* other users? */
-                                               CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-                                                       ob = base->object;
-                                                       if((ob->flag & OB_DONE)==0) {
-                                                               tme= get_mesh(ob);
-                                                               
-                                                               if(tme==me) {
-                                                                       
-                                                                       ob->flag |= OB_DONE;
-                                                                       ob->recalc= OB_RECALC_OB|OB_RECALC_DATA;
-
-                                                                       Mat3CpyMat4(omat, ob->obmat);
-                                                                       VECCOPY(centn, cent);
-                                                                       Mat3MulVecfl(omat, centn);
-                                                                       ob->loc[0]+= centn[0];
-                                                                       ob->loc[1]+= centn[1];
-                                                                       ob->loc[2]+= centn[2];
-                                                                       
-                                                                       where_is_object(scene, ob);
-                                                                       ignore_parent_tx(scene, ob);
-                                                                       
-                                                                       if(tme && (tme->flag & ME_ISDONE)==0) {
-                                                                               mvert= tme->mvert;
-                                                                               for(a=0; a<tme->totvert; a++, mvert++) {
-                                                                                       VecSubf(mvert->co, mvert->co, cent);
-                                                                               }
-                                                                               
-                                                                               if (tme->key) {
-                                                                                       KeyBlock *kb;
-                                                                                       for (kb=tme->key->block.first; kb; kb=kb->next) {
-                                                                                               float *fp= kb->data;
-                                                                                               
-                                                                                               for (a=0; a<kb->totelem; a++, fp+=3) {
-                                                                                                       VecSubf(fp, fp, cent);
-                                                                                               }
-                                                                                       }
-                                                                               }
-                                                                               
-                                                                               tme->flag |= ME_ISDONE;
-                                                                       }
-                                                               }
-                                                       }
-                                                       
-                                                       ob= ob->id.next;
-                                               }
-                                               CTX_DATA_END;
-                                       }
-                                       tot_change++;
-                               }
-                       }
-                       else if (ELEM(base->object->type, OB_CURVE, OB_SURF)) {
-                               
-                               /* weak code here... (ton) */
-                               if(obedit==base->object) {
-                                       ListBase *editnurb= curve_get_editcurve(obedit);
-
-                                       nu1= editnurb->first;
-                                       cu= obedit->data;
-                               }
-                               else {
-                                       cu= base->object->data;
-                                       nu1= cu->nurb.first;
-                               }
-                               
-                               if (cu->id.lib) {
-                                       tot_lib_error++;
-                               } else {
-                                       if(centermode==2) {
-                                               VECCOPY(cent, give_cursor(scene, v3d));
-                                               Mat4Invert(base->object->imat, base->object->obmat);
-                                               Mat4MulVecfl(base->object->imat, cent);
-
-                                               /* don't allow Z change if curve is 2D */
-                                               if( !( cu->flag & CU_3D ) )
-                                                       cent[2] = 0.0;
-                                       } 
-                                       else {
-                                               INIT_MINMAX(min, max);
-                                               
-                                               nu= nu1;
-                                               while(nu) {
-                                                       minmaxNurb(nu, min, max);
-                                                       nu= nu->next;
-                                               }
-                                               
-                                               cent[0]= (min[0]+max[0])/2.0f;
-                                               cent[1]= (min[1]+max[1])/2.0f;
-                                               cent[2]= (min[2]+max[2])/2.0f;
-                                       }
-                                       
-                                       nu= nu1;
-                                       while(nu) {
-                                               if(nu->type == CU_BEZIER) {
-                                                       a= nu->pntsu;
-                                                       while (a--) {
-                                                               VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent);
-                                                               VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent);
-                                                               VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent);
-                                                       }
-                                               }
-                                               else {
-                                                       a= nu->pntsu*nu->pntsv;
-                                                       while (a--)
-                                                               VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent);
-                                               }
-                                               nu= nu->next;
-                                       }
-                       
-                                       if(centermode && obedit==0) {
-                                               Mat3CpyMat4(omat, base->object->obmat);
-                                               
-                                               Mat3MulVecfl(omat, cent);
-                                               base->object->loc[0]+= cent[0];
-                                               base->object->loc[1]+= cent[1];
-                                               base->object->loc[2]+= cent[2];
-                                               
-                                               where_is_object(scene, base->object);
-                                               ignore_parent_tx(scene, base->object);
-                                       }
-                                       
-                                       tot_change++;
-                                       if(obedit) {
-                                               if (centermode==0) {
-                                                       DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
-                                               }
-                                               break;
-                                       }
-                               }
-                       }
-                       else if(base->object->type==OB_FONT) {
-                               /* get from bb */
-                               
-                               cu= base->object->data;
-                               
-                               if(cu->bb==0) {
-                                       /* do nothing*/
-                               } else if (cu->id.lib) {
-                                       tot_lib_error++;
-                               } else {
-                                       cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]);
-                                       cu->yof= -0.5f -0.5f*( cu->bb->vec[0][1] - cu->bb->vec[2][1]);  /* extra 0.5 is the height o above line */
-                                       
-                                       /* not really ok, do this better once! */
-                                       cu->xof /= cu->fsize;
-                                       cu->yof /= cu->fsize;
-
-                                       tot_change++;
-                               }
-                       }
-                       else if(base->object->type==OB_ARMATURE) {
-                               bArmature *arm = base->object->data;
-                               
-                               if (arm->id.lib) {
-                                       tot_lib_error++;
-                               } else if(arm->id.us>1) {
-                                       /*error("Can't apply to a multi user armature");
-                                       return;*/
-                                       tot_multiuser_arm_error++;
-                               } else {
-                                       /* Function to recenter armatures in editarmature.c 
-                                        * Bone + object locations are handled there.
-                                        */
-                                       docenter_armature(scene, v3d, base->object, centermode);
-                                       tot_change++;
-                                       
-                                       where_is_object(scene, base->object);
-                                       ignore_parent_tx(scene, base->object);
-                                       
-                                       if(obedit) 
-                                               break;
-                               }
-                       }
-                       base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA;
-               }
-       }
-       CTX_DATA_END;
-       
-       if (tot_change) {
-               ED_anim_dag_flush_update(C);
-       }
-       
-       /* Warn if any errors occured */
-       if (tot_lib_error+tot_multiuser_arm_error) {
-               BKE_reportf(op->reports, RPT_WARNING, "%i Object(s) Not Centered, %i Changed:",tot_lib_error+tot_multiuser_arm_error, tot_change);              
-               if (tot_lib_error)
-                       BKE_reportf(op->reports, RPT_WARNING, "|%i linked library objects",tot_lib_error);
-               if (tot_multiuser_arm_error)
-                       BKE_reportf(op->reports, RPT_WARNING, "|%i multiuser armature object(s)",tot_multiuser_arm_error);
-       }
-       
-       return OPERATOR_FINISHED;
-}
-void OBJECT_OT_center_set(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Set Center";
-       ot->description = "Set the object's center, by either moving the data, or set to center of data, or use 3d cursor";
-       ot->idname= "OBJECT_OT_center_set";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_center_set_exec;
-       
-       ot->poll= ED_operator_view3d_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       RNA_def_enum(ot->srna, "type", prop_set_center_types, 0, "Type", "");
-}
-/* ******************* toggle editmode operator  ***************** */
-
-void ED_object_exit_editmode(bContext *C, int flag)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
-       int freedata = flag & EM_FREEDATA;
-       
-       if(obedit==NULL) return;
-       
-       if(flag & EM_WAITCURSOR) waitcursor(1);
-       if(obedit->type==OB_MESH) {
-               Mesh *me= obedit->data;
-               
-//             if(EM_texFaceCheck())
-               
-//             if(retopo_mesh_paint_check())
-//                     retopo_end_okee();
-               
-               if(me->edit_mesh->totvert>MESH_MAX_VERTS) {
-                       error("Too many vertices");
-                       return;
-               }
-               load_editMesh(scene, obedit);
-               
-               if(freedata) {
-                       free_editMesh(me->edit_mesh);
-                       MEM_freeN(me->edit_mesh);
-                       me->edit_mesh= NULL;
-               }
-               
-               if(obedit->restore_mode & OB_MODE_WEIGHT_PAINT)
-                       mesh_octree_table(obedit, NULL, NULL, 'e');
-       }
-       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)) {
-               load_editNurb(obedit);
-               if(freedata) free_editNurb(obedit);
-       }
-       else if(obedit->type==OB_FONT && freedata) {
-               load_editText(obedit);
-               if(freedata) free_editText(obedit);
-       }
-       else if(obedit->type==OB_LATTICE) {
-               load_editLatt(obedit);
-               if(freedata) free_editLatt(obedit);
-       }
-       else if(obedit->type==OB_MBALL) {
-               load_editMball(obedit);
-               if(freedata) free_editMball(obedit);
-       }
-
-       /* freedata only 0 now on file saves */
-       if(freedata) {
-               /* for example; displist make is different in editmode */
-               scene->obedit= NULL; // XXX for context
-               
-               BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_DEPSGRAPH);
-
-               /* also flush ob recalc, doesn't take much overhead, but used for particles */
-               DAG_id_flush_update(&obedit->id, OB_RECALC_OB|OB_RECALC_DATA);
-       
-               ED_undo_push(C, "Editmode");
-       
-               if(flag & EM_WAITCURSOR) waitcursor(0);
-       
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
-       }
-
-       obedit->mode &= ~OB_MODE_EDIT;
-       ED_object_toggle_modes(C, obedit->restore_mode);
-}
-
-
-void ED_object_enter_editmode(bContext *C, int flag)
-{
-       Scene *scene= CTX_data_scene(C);
-       Base *base= CTX_data_active_base(C);
-       Object *ob;
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= NULL;
-       int ok= 0;
-       
-       if(scene->id.lib) return;
-       if(base==NULL) return;
-       
-       if(sa && sa->spacetype==SPACE_VIEW3D)
-               v3d= sa->spacedata.first;
-       
-       if(v3d && (base->lay & v3d->lay)==0) return;
-       else if(!v3d && (base->lay & scene->lay)==0) return;
-
-       ob = base->object;
-
-       if(ob==NULL) return;
-       if(ob->data==NULL) return;
-       
-       if (object_data_is_libdata(ob)) {
-               error_libdata();
-               return;
-       }
-       
-       if(flag & EM_WAITCURSOR) waitcursor(1);
-
-       ob->restore_mode = ob->mode;
-       ED_object_toggle_modes(C, ob->mode);
-
-       ob->mode |= OB_MODE_EDIT;
-       
-       if(ob->type==OB_MESH) {
-               Mesh *me= ob->data;
-               
-               if(me->pv) mesh_pmv_off(ob, me);
-               ok= 1;
-               scene->obedit= ob;      // context sees this
-               
-               make_editMesh(scene, ob);
-
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MESH, scene);
-       }
-       else if (ob->type==OB_ARMATURE){
-               bArmature *arm= base->object->data;
-               if (!arm) return;
-               /*
-                * The function object_data_is_libdata make a problem here, the
-                * check for ob->proxy return 0 and let blender enter to edit mode
-                * this causa a crash when you try leave the edit mode.
-                * The problem is that i can't remove the ob->proxy check from
-                * object_data_is_libdata that prevent the bugfix #6614, so
-                * i add this little hack here.
-                */
-               if(arm->id.lib) {
-                       error_libdata();
-                       return;
-               }
-               ok=1;
-               scene->obedit= ob;
-               ED_armature_to_edit(ob);
-               /* to ensure all goes in restposition and without striding */
-               DAG_id_flush_update(&ob->id, OB_RECALC);
-
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_ARMATURE, scene);
-       }
-       else if(ob->type==OB_FONT) {
-               scene->obedit= ob; // XXX for context
-               ok= 1;
-               make_editText(ob);
-
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_TEXT, scene);
-       }
-       else if(ob->type==OB_MBALL) {
-               scene->obedit= ob; // XXX for context
-               ok= 1;
-               make_editMball(ob);
-
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MBALL, scene);
-       }
-       else if(ob->type==OB_LATTICE) {
-               scene->obedit= ob; // XXX for context
-               ok= 1;
-               make_editLatt(ob);
-               
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_LATTICE, scene);
-       }
-       else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
-               ok= 1;
-               scene->obedit= ob; // XXX for context
-               make_editNurb(ob);
-               
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_CURVE, scene);
-       }
-       
-       if(ok) {
-               DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
-       }
-       else {
-               scene->obedit= NULL; // XXX for context
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
-       }
-       
-       if(flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
-       if(flag & EM_WAITCURSOR) waitcursor(0);
-}
-
-static int editmode_toggle_exec(bContext *C, wmOperator *op)
-{
-       
-       if(!CTX_data_edit_object(C))
-               ED_object_enter_editmode(C, EM_WAITCURSOR);
-       else
-               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
-       
-       return OPERATOR_FINISHED;
-}
-
-static int editmode_toggle_poll(bContext *C)
-{
-       Object *ob = CTX_data_active_object(C);
-
-       return ob && (ob->type == OB_MESH || ob->type == OB_ARMATURE ||
-                     ob->type == OB_FONT || ob->type == OB_MBALL ||
-                     ob->type == OB_LATTICE || ob->type == OB_SURF ||
-                     ob->type == OB_CURVE);
-}
-
-void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
-{
-       
-       /* identifiers */
-       ot->name= "Toggle Editmode";
-       ot->description = "Toggle object's editmode.";
-       ot->idname= "OBJECT_OT_editmode_toggle";
-       
-       /* api callbacks */
-       ot->exec= editmode_toggle_exec;
-       
-       ot->poll= editmode_toggle_poll;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-/* *************************** */
-
-static int posemode_exec(bContext *C, wmOperator *op)
-{
-       Base *base= CTX_data_active_base(C);
-       
-       if(base->object->type==OB_ARMATURE) {
-               if(base->object==CTX_data_edit_object(C)) {
-                       ED_object_exit_editmode(C, EM_FREEDATA);
-                       ED_armature_enter_posemode(C, base);
-               }
-               else if(base->object->mode & OB_MODE_POSE)
-                       ED_armature_exit_posemode(C, base);
-               else
-                       ED_armature_enter_posemode(C, base);
-               
-               return OPERATOR_FINISHED;
-       }
-       
-       return OPERATOR_PASS_THROUGH;
-}
-
-void OBJECT_OT_posemode_toggle(wmOperatorType *ot) 
-{
-       /* identifiers */
-       ot->name= "Toggle Pose Mode";
-       ot->idname= "OBJECT_OT_posemode_toggle";
-       ot->description= "Enables or disables posing/selecting bones";
-       
-       /* api callbacks */
-       ot->exec= posemode_exec;
-       ot->poll= ED_operator_object_active;
-       
-       /* flag */
-       ot->flag= OPTYPE_REGISTER;
-}
-
-/* *********************** */
-
-void check_editmode(int type)
-{
-       Object *obedit= NULL; // XXX
-       
-       if (obedit==NULL || obedit->type==type) return;
-
-// XXX ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
-}
-void movetolayer(Scene *scene, View3D *v3d)
-{
-       Base *base;
-       unsigned int lay= 0, local;
-       int islamp= 0;
-       
-       if(scene->id.lib) return;
-
-       for(base= FIRSTBASE; base; base= base->next) {
-               if (TESTBASE(v3d, base)) lay |= base->lay;
-       }
-       if(lay==0) return;
-       lay &= 0xFFFFFF;
-       
-       if(lay==0) return;
-       
-       if(v3d->localview) {
-               /* now we can move out of localview. */
-               if (!okee("Move from localview")) return;
-               for(base= FIRSTBASE; base; base= base->next) {
-                       if (TESTBASE(v3d, base)) {
-                               lay= base->lay & ~v3d->lay;
-                               base->lay= lay;
-                               base->object->lay= lay;
-                               base->object->flag &= ~SELECT;
-                               base->flag &= ~SELECT;
-                               if(base->object->type==OB_LAMP) islamp= 1;
-                       }
-               }
-       } else {
-// XXX         if( movetolayer_buts(&lay, NULL)==0 ) return;
-               
-               /* normal non localview operation */
-               for(base= FIRSTBASE; base; base= base->next) {
-                       if (TESTBASE(v3d, base)) {
-                               /* upper byte is used for local view */
-                               local= base->lay & 0xFF000000;  
-                               base->lay= lay + local;
-                               base->object->lay= lay;
-                               if(base->object->type==OB_LAMP) islamp= 1;
-                       }
-               }
-       }
-       if(islamp) reshadeall_displist(scene);  /* only frees */
-       
-       /* warning, active object may be hidden now */
-       
-       DAG_scene_sort(scene);
-       
-}
-
-
-#if 0
-// XXX should be in view3d?
-
-/* context: ob = lamp */
-/* code should be replaced with proper (custom) transform handles for lamp properties */
-static void spot_interactive(Object *ob, int mode)
-{
-       Lamp *la= ob->data;
-       float transfac, dx, dy, ratio, origval;
-       int keep_running= 1, center2d[2];
-       short mval[2], mvalo[2];
-       
-//     getmouseco_areawin(mval);
-//     getmouseco_areawin(mvalo);
-       
-       project_int(ob->obmat[3], center2d);
-       if( center2d[0] > 100000 ) {            /* behind camera */
-//             center2d[0]= curarea->winx/2;
-//             center2d[1]= curarea->winy/2;
-       }
-
-//     helpline(mval, center2d);
-       
-       /* ratio is like scaling */
-       dx = (float)(center2d[0] - mval[0]);
-       dy = (float)(center2d[1] - mval[1]);
-       transfac = (float)sqrt( dx*dx + dy*dy);
-       if(transfac==0.0f) transfac= 1.0f;
-       
-       if(mode==1)     
-               origval= la->spotsize;
-       else if(mode==2)        
-               origval= la->dist;
-       else if(mode==3)        
-               origval= la->clipsta;
-       else    
-               origval= la->clipend;
-       
-       while (keep_running>0) {
-               
-//             getmouseco_areawin(mval);
-               
-               /* essential for idling subloop */
-               if(mval[0]==mvalo[0] && mval[1]==mvalo[1]) {
-                       PIL_sleep_ms(2);
-               }
-               else {
-                       char str[32];
-                       
-                       dx = (float)(center2d[0] - mval[0]);
-                       dy = (float)(center2d[1] - mval[1]);
-                       ratio = (float)(sqrt( dx*dx + dy*dy))/transfac;
-                       
-                       /* do the trick */
-                       
-                       if(mode==1) {   /* spot */
-                               la->spotsize = ratio*origval;
-                               CLAMP(la->spotsize, 1.0f, 180.0f);
-                               sprintf(str, "Spot size %.2f\n", la->spotsize);
-                       }
-                       else if(mode==2) {      /* dist */
-                               la->dist = ratio*origval;
-                               CLAMP(la->dist, 0.01f, 5000.0f);
-                               sprintf(str, "Distance %.2f\n", la->dist);
-                       }
-                       else if(mode==3) {      /* sta */
-                               la->clipsta = ratio*origval;
-                               CLAMP(la->clipsta, 0.001f, 5000.0f);
-                               sprintf(str, "Distance %.2f\n", la->clipsta);
-                       }
-                       else if(mode==4) {      /* end */
-                               la->clipend = ratio*origval;
-                               CLAMP(la->clipend, 0.1f, 5000.0f);
-                               sprintf(str, "Clip End %.2f\n", la->clipend);
-                       }
-
-                       /* cleanup */
-                       mvalo[0]= mval[0];
-                       mvalo[1]= mval[1];
-                       
-                       /* handle shaded mode */
-// XXX                 shade_buttons_change_3d();
-
-                       /* DRAW */      
-                       headerprint(str);
-                       force_draw_plus(SPACE_BUTS, 0);
-
-//                     helpline(mval, center2d);
-               }
-               
-               while( qtest() ) {
-                       short val;
-                       unsigned short event= extern_qread(&val);
-                       
-                       switch (event){
-                               case ESCKEY:
-                               case RIGHTMOUSE:
-                                       keep_running= 0;
-                                       break;
-                               case LEFTMOUSE:
-                               case SPACEKEY:
-                               case PADENTER:
-                               case RETKEY:
-                                       if(val)
-                                               keep_running= -1;
-                                       break;
-                       }
-               }
-       }
-
-       if(keep_running==0) {
-               if(mode==1)     
-                       la->spotsize= origval;
-               else if(mode==2)        
-                       la->dist= origval;
-               else if(mode==3)        
-                       la->clipsta= origval;
-               else    
-                       la->clipend= origval;
-       }
-
-}
-#endif
-
-void special_editmenu(Scene *scene, View3D *v3d)
-{
-// XXX static short numcuts= 2;
-       Object *ob= OBACT;
-       Object *obedit= NULL; // XXX
-       int nr,ret=0;
-       
-       if(ob==NULL) return;
-       
-       if(obedit==NULL) {
-               
-               if(ob->mode & OB_MODE_POSE) {
-// XXX                 pose_special_editmenu();
-               }
-               else if(paint_facesel_test(ob)) {
-                       Mesh *me= get_mesh(ob);
-                       MTFace *tface;
-                       MFace *mface;
-                       int a;
-                       
-                       if(me==0 || me->mtface==0) return;
-