2.5
authorTon Roosendaal <ton@blender.org>
Tue, 13 Jan 2009 15:18:41 +0000 (15:18 +0000)
committerTon Roosendaal <ton@blender.org>
Tue, 13 Jan 2009 15:18:41 +0000 (15:18 +0000)
- restored three more C files: editlattice, editkey
  and editgroup
- editmode lattice working, (mouse select works)
- accidentally removed yesterday 3d cursor drawing
- removed global editLatt entirely now.

16 files changed:
source/blender/blenkernel/BKE_lattice.h
source/blender/blenkernel/intern/lattice.c
source/blender/editors/armature/editarmature.c
source/blender/editors/include/ED_object.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/mesh/editdeform.c
source/blender/editors/mesh/editmesh.c
source/blender/editors/object/editgroup.c [new file with mode: 0644]
source/blender/editors/object/editkey.c [new file with mode: 0644]
source/blender/editors/object/editlattice.c [new file with mode: 0644]
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_intern.h
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_select.c

index c0a6dc4..2e4a533 100644 (file)
@@ -38,9 +38,6 @@ struct DerivedMesh;
 struct BPoint;
 struct MDeformVert;
 
-extern struct Lattice *editLatt;
-
-
 void resizelattice(struct Lattice *lt, int u, int v, int w, struct Object *ltOb);
 struct Lattice *add_lattice(char *name);
 struct Lattice *copy_lattice(struct Lattice *lt);
index 46e7022..134d9f7 100644 (file)
@@ -73,8 +73,6 @@
 
 //XXX #include "BIF_editdeform.h"
 
-Lattice *editLatt=0;
-
 void calc_lat_fudu(int flag, int res, float *fu, float *du)
 {
        if(res==1) {
@@ -233,6 +231,11 @@ void free_lattice(Lattice *lt)
 {
        if(lt->def) MEM_freeN(lt->def);
        if(lt->dvert) free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
+       if(lt->editlatt) {
+               if(lt->def) MEM_freeN(lt->def);
+               if(lt->dvert) free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
+               MEM_freeN(lt->editlatt);
+       }
 }
 
 
index bc4f39d..54da390 100644 (file)
@@ -1134,17 +1134,14 @@ static void *get_bone_from_selectbuffer(Scene *scene, Base *base, unsigned int *
 
 /* used by posemode as well editmode */
 /* only checks scene->basact! */
-static void *get_nearest_bone (Scene *scene, short findunsel)
+static void *get_nearest_bone (bContext *C, short findunsel)
 {
        ViewContext vc;
        rcti rect;
        unsigned int buffer[MAXPICKBUF];
        short hits;
        
-       memset(&vc, 0, sizeof(ViewContext));
-       vc.scene= scene;
-       vc.obedit= scene->obedit;
-       // XXX fill in further!
+       view3d_set_viewcontext(C, &vc);
        
        // rect.xmin= ... mouseco!
        
@@ -1152,7 +1149,7 @@ static void *get_nearest_bone (Scene *scene, short findunsel)
        hits= view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
 
        if (hits>0)
-               return get_bone_from_selectbuffer(scene, scene->basact, buffer, hits, findunsel);
+               return get_bone_from_selectbuffer(vc.scene, vc.scene->basact, buffer, hits, findunsel);
        
        return NULL;
 }
@@ -1346,18 +1343,16 @@ static void selectconnected_posebonechildren (Object *ob, Bone *bone)
 }
 
 /* within active object context */
-void selectconnected_posearmature(Scene *scene)
+void selectconnected_posearmature(bContext *C)
 {
+       Object *ob= CTX_data_edit_object(C);
        Bone *bone, *curBone, *next;
-       Object *ob= OBACT;
        int shift= 0; // XXX
        
-       if(!ob || !ob->pose) return;
-       
        if (shift)
-               bone= get_nearest_bone(scene, 0);
+               bone= get_nearest_bone(C, 0);
        else
-               bone = get_nearest_bone(scene, 1);
+               bone = get_nearest_bone(C, 1);
        
        if (!bone)
                return;
@@ -1391,16 +1386,17 @@ void selectconnected_posearmature(Scene *scene)
 /* **************** EditMode stuff ********************** */
 
 /* called in space.c */
-void selectconnected_armature(Scene *scene, View3D *v3d, Object *obedit)
+void selectconnected_armature(bContext *C)
 {
+       Object *obedit= CTX_data_edit_object(C);
        bArmature *arm= obedit->data;
        EditBone *bone, *curBone, *next;
        int shift= 0; // XXX
 
        if (shift)
-               bone= get_nearest_bone(scene, 0);
+               bone= get_nearest_bone(C, 0);
        else
-               bone= get_nearest_bone(scene, 1);
+               bone= get_nearest_bone(C, 1);
 
        if (!bone)
                return;
@@ -1721,12 +1717,7 @@ void mouse_armature(bContext *C, short mval[2], int extend)
        EditBone *nearBone = NULL, *ebone;
        int     selmask;
 
-       memset(&vc, 0, sizeof(ViewContext));
-       vc.ar= CTX_wm_region(C);
-       vc.scene= CTX_data_scene(C);
-       vc.v3d= (View3D *)CTX_wm_space_data(C);
-       vc.obact= CTX_data_active_object(C);
-       vc.obedit= obedit; 
+       view3d_set_viewcontext(C, &vc);
        
        nearBone= get_nearest_editbonepoint(&vc, mval, arm->edbo, 1, &selmask);
        if (nearBone) {
index 59beb95..5fdc957 100644 (file)
@@ -66,6 +66,12 @@ int object_is_libdata(struct Object *ob);
 struct bConstraint *add_new_constraint (short type);
 void add_constraint_to_object (struct bConstraint *con, struct Object *ob);
 
+/* editlattice.c */
+void mouse_lattice(struct bContext *C, short mval[2], int extend);
+
+/* keys */
+void insert_shapekey(struct Scene *scene, struct Object *ob);
+void delete_key(struct Scene *scene, struct Object *ob);
 
 #endif /* ED_OBJECT_H */
 
index 9de1095..f9ea805 100644 (file)
@@ -93,6 +93,7 @@ unsigned int view3d_sample_backbuf(struct ViewContext *vc, int x, int y);
 /* select */
 #define MAXPICKBUF      10000
 short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, rcti *input);
+void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc);
 
 /* modes */
 void ED_view3d_exit_paint_modes(struct bContext *C);
index 0533c37..8452906 100644 (file)
 static void BIF_undo_push() {}
 static void error() {}
 
+static Lattice *def_get_lattice(Object *ob)
+{
+       if(ob->type==OB_LATTICE) {
+               Lattice *lt= ob->data;
+               if(lt->editlatt)
+                       return lt->editlatt;
+               return lt;
+       }
+       return NULL;
+}
+
 /* only in editmode */
 void sel_verts_defgroup (Object *obedit, int select)
 {
@@ -103,14 +114,17 @@ void sel_verts_defgroup (Object *obedit, int select)
        }
                break;
        case OB_LATTICE:
-               if(editLatt->dvert) {
+       {
+               Lattice *lt= def_get_lattice(ob);
+               
+               if(lt->dvert) {
                        BPoint *bp;
                        int a, tot;
                        
-                       dvert= editLatt->dvert;
+                       dvert= lt->dvert;
 
-                       tot= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
-                       for(a=0, bp= editLatt->def; a<tot; a++, bp++, dvert++) {
+                       tot= lt->pntsu*lt->pntsv*lt->pntsw;
+                       for(a=0, bp= lt->def; a<tot; a++, bp++, dvert++) {
                                for (i=0; i<dvert->totweight; i++){
                                        if (dvert->dw[i].def_nr == (ob->actdef-1)) {
                                                if(select) bp->f1 |= SELECT;
@@ -120,7 +134,8 @@ void sel_verts_defgroup (Object *obedit, int select)
                                        }
                                }
                        }
-               }       
+               }
+       }
                break;
                
        default:
@@ -392,14 +407,15 @@ void del_defgroup (Object *ob)
                                                dvert->dw[i].def_nr--;
                }
        }
-       else {
+       else if(ob->type==OB_LATTICE) {
+               Lattice *lt= def_get_lattice(ob);
                BPoint *bp;
-               MDeformVert *dvert= editLatt->dvert;
+               MDeformVert *dvert= lt->dvert;
                int a, tot;
                
                if (dvert) {
-                       tot= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
-                       for(a=0, bp= editLatt->def; a<tot; a++, bp++, dvert++) {
+                       tot= lt->pntsu*lt->pntsv*lt->pntsw;
+                       for(a=0, bp= lt->def; a<tot; a++, bp++, dvert++) {
                                for (i=0; i<dvert->totweight; i++){
                                        if (dvert->dw[i].def_nr > (ob->actdef-1))
                                                dvert->dw[i].def_nr--;
@@ -424,10 +440,11 @@ void del_defgroup (Object *ob)
                        CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
                        me->dvert= NULL;
                }
-               else {
-                       if (editLatt->dvert) {
-                               MEM_freeN(editLatt->dvert);
-                               editLatt->dvert= NULL;
+               else if(ob->type==OB_LATTICE) {
+                       Lattice *lt= def_get_lattice(ob);
+                       if (lt->dvert) {
+                               MEM_freeN(lt->dvert);
+                               lt->dvert= NULL;
                        }
                }
        }
@@ -445,10 +462,11 @@ void del_all_defgroups (Object *ob)
                CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
                me->dvert= NULL;
        }
-       else {
-               if (editLatt->dvert) {
-                       MEM_freeN(editLatt->dvert);
-                       editLatt->dvert= NULL;
+       else if(ob->type==OB_LATTICE) {
+               Lattice *lt= def_get_lattice(ob);
+               if (lt->dvert) {
+                       MEM_freeN(lt->dvert);
+                       lt->dvert= NULL;
                }
        }
        
@@ -500,9 +518,8 @@ void remove_vert_def_nr (Object *ob, int def_nr, int vertnum)
                        dvert = ((Mesh*)ob->data)->dvert + vertnum;
        }
        else if(ob->type==OB_LATTICE) {
-               Lattice *lt= ob->data;
+               Lattice *lt= def_get_lattice(ob);
                
-               if(lt->editlatt) lt= lt->editlatt;
                if(lt->dvert)
                        dvert = lt->dvert + vertnum;
        }
@@ -568,10 +585,8 @@ void add_vert_defnr (Object *ob, int def_nr, int vertnum,
                        dv = ((Mesh*)ob->data)->dvert + vertnum;
        }
        else if(ob->type==OB_LATTICE) {
-               Lattice *lt= ob->data;
+               Lattice *lt= def_get_lattice(ob);
                
-               if(lt->editlatt) lt= lt->editlatt;
-                       
                if(lt->dvert)
                        dv = lt->dvert + vertnum;
        }
@@ -747,18 +762,19 @@ void assign_verts_defgroup (Object *obedit, float weight)
                break;
        case OB_LATTICE:
                {
+                       Lattice *lt= def_get_lattice(ob);
                        BPoint *bp;
                        int a, tot;
                        
-                       if(editLatt->dvert==NULL)
-                               create_dverts(&editLatt->id);
+                       if(lt->dvert==NULL)
+                               create_dverts(&lt->id);
                        
-                       tot= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
-                       for(a=0, bp= editLatt->def; a<tot; a++, bp++) {
+                       tot= lt->pntsu*lt->pntsv*lt->pntsw;
+                       for(a=0, bp= lt->def; a<tot; a++, bp++) {
                                if(bp->f1 & SELECT)
                                        add_vert_defnr (ob, ob->actdef-1, a, weight, WEIGHT_REPLACE);
                        }
-               }       
+               }
                break;
        default:
                printf ("Assigning deformation groups to unknown object type\n");
@@ -807,9 +823,7 @@ static float get_vert_def_nr (Object *ob, int def_nr, int vertnum)
                        dvert = ((Mesh*)ob->data)->dvert + vertnum;
        }
        else if(ob->type==OB_LATTICE) {
-               Lattice *lt= ob->data;
-               
-               if(lt->editlatt) lt= lt->editlatt;
+               Lattice *lt= def_get_lattice(ob);
                
                if(lt->dvert)
                        dvert = lt->dvert + vertnum;
@@ -899,16 +913,19 @@ void remove_verts_defgroup (Object *obedit, int allverts)
        }
                break;
        case OB_LATTICE:
+       {
+               Lattice *lt= def_get_lattice(ob);
                
-               if(editLatt->dvert) {
+               if(lt->dvert) {
                        BPoint *bp;
-                       int a, tot= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
+                       int a, tot= lt->pntsu*lt->pntsv*lt->pntsw;
                                
-                       for(a=0, bp= editLatt->def; a<tot; a++, bp++) {
+                       for(a=0, bp= lt->def; a<tot; a++, bp++) {
                                if(allverts || (bp->f1 & SELECT))
                                        remove_vert_defgroup (ob, dg, a);
                        }
                }
+       }
                break;
                
        default:
index b91fc0e..412929b 100644 (file)
@@ -2167,12 +2167,8 @@ int EM_vertColorCheck(EditMesh *em)
 
 void em_setup_viewcontext(bContext *C, ViewContext *vc)
 {
-       memset(vc, 0, sizeof(ViewContext));
-       vc->ar= CTX_wm_region(C);
-       vc->scene= CTX_data_scene(C);
-       vc->v3d= (View3D *)CTX_wm_space_data(C);
-       vc->obact= CTX_data_active_object(C);
-       vc->obedit= CTX_data_edit_object(C);
+       view3d_set_viewcontext(C, vc);
+       
        if(vc->obedit) {
                Mesh *me= vc->obedit->data;
                vc->em= me->edit_mesh;
diff --git a/source/blender/editors/object/editgroup.c b/source/blender/editors/object/editgroup.c
new file mode 100644 (file)
index 0000000..01e791c
--- /dev/null
@@ -0,0 +1,244 @@
+/**
+ * $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) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+
+#include "DNA_group_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_depsgraph.h"
+#include "BKE_group.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+
+#include "object_intern.h"
+
+/* XXX */
+static void BIF_undo_push() {}
+static void error() {}
+static int pupmenu() {return 0;}
+static int pupmenu_col() {return 0;}
+
+void add_selected_to_group(Scene *scene, View3D *v3d, Group *group)
+{
+       Base *base;
+       
+       for(base=FIRSTBASE; base; base= base->next) {
+               if (TESTBASE(v3d, base)) {
+                       add_to_group(group, base->object);
+                       base->object->flag |= OB_FROMGROUP;
+                       base->flag |= OB_FROMGROUP;
+               }
+       }
+       
+       DAG_scene_sort(scene);
+       BIF_undo_push("Add to Group");
+}
+
+void add_selected_to_act_ob_groups(Scene *scene, View3D *v3d)
+{
+       Object *ob= OBACT, *obt;
+       Base *base;
+       Group *group;
+       
+       if (!ob) return;
+       
+       /* linking to same group requires its own loop so we can avoid
+          looking up the active objects groups each time */
+
+       group= G.main->group.first;
+       while(group) {
+               if(object_in_group(ob, group)) {
+                       /* Assign groups to selected objects */
+                       base= FIRSTBASE;
+                       while(base) {
+                               if(TESTBASE(v3d, base)) {
+                                       obt= base->object;
+                                       add_to_group(group, obt);
+                                       obt->flag |= OB_FROMGROUP;
+                                       base->flag |= OB_FROMGROUP;
+                               }
+                               base= base->next;
+                       }
+               }
+               group= group->id.next;
+       }
+       DAG_scene_sort(scene);
+       BIF_undo_push("Add to Active Objects Group");
+}
+
+
+void rem_selected_from_all_groups(Scene *scene, View3D *v3d)
+{
+       Base *base;
+       Group *group;
+       
+       for(base=FIRSTBASE; base; base= base->next) {
+               if (TESTBASE(v3d, base)) {
+                       group = NULL;
+                       while( (group = find_group(base->object, group)) ) {
+                               rem_from_group(group, base->object);
+                       }
+                       base->object->flag &= ~OB_FROMGROUP;
+                       base->flag &= ~OB_FROMGROUP;
+               }
+       }
+       
+       DAG_scene_sort(scene);
+       BIF_undo_push("Remove from Group");
+}
+
+
+void rem_selected_from_group(Scene *scene, View3D *v3d)
+{
+       char menutext[30+(22*22)], *menupt;
+       int i=0;
+       short ret;
+       Group *group= NULL;
+       Object *ob;
+       Base *base;
+       Group *group_array[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+       
+       /* UnSet Tags for Objects and Groups */
+       for(group= G.main->group.first; group; group= group->id.next) {
+               if(group->id.lib==NULL) {
+                       group->id.flag &= ~LIB_DOIT;
+               }
+       }
+       for(ob=G.main->object.first; ob; ob= ob->id.next) {
+               ob->id.flag &= ~LIB_DOIT;
+       }
+       
+       /* Not tag selected objects */
+       for(base=FIRSTBASE; base; base= base->next) {
+               if (TESTBASELIB(v3d, base)) {
+                       base->object->id.flag |= LIB_DOIT;
+               }
+       }
+       
+       menupt = menutext;
+       /* Build a list of groups that contain selected objects */
+       for(group= G.main->group.first; group && i<24; group= group->id.next) {
+               if(group->id.lib==NULL) {
+                       GroupObject *go;
+                       for(go= group->gobject.first; go; go= go->next) {
+                               if(go->ob->id.flag & LIB_DOIT) {
+                                       group_array[i] = group;
+                                       menupt += sprintf(menupt, "|%s", group->id.name+2);
+                                       i++;
+                                       break; /* Only want to know if this group should go in the list*/
+                               }
+                       }
+               }
+       }
+       
+       /* do we have any groups? */
+       if (group_array[0] == NULL) {
+               error("Object selection contains no groups");
+       } else {
+               ret = pupmenu(menutext);
+               if (ret==-1) {
+                       return;
+               } else { 
+                       group = group_array[ret-1];
+                       for(base=FIRSTBASE; base; base= base->next) {
+                               if (TESTBASELIB(v3d, base)) {
+                                       /* if we are removed and are not in any group, set our flag */
+                                       if(rem_from_group(group, base->object) && find_group(base->object, NULL)==NULL) {
+                                               base->object->flag &= ~OB_FROMGROUP;
+                                               base->flag &= ~OB_FROMGROUP;
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       DAG_scene_sort(scene);
+       BIF_undo_push("Remove from Group");
+}
+
+void group_operation(Scene *scene, View3D *v3d, int mode)
+{
+       Group *group= NULL;
+       
+       /* are there existing groups? */
+       for(group= G.main->group.first; group; group= group->id.next)
+               if(group->id.lib==NULL)
+                       break;
+       
+       if(mode>0) {
+               if(group==NULL || mode==1) group= add_group( "Group" );
+               if(mode==3) {
+                       int tot= BLI_countlist(&G.main->group);
+                       char *strp= MEM_callocN(tot*32 + 32, "group menu"), *strp1;
+                       
+                       strp1= strp;
+                       for(tot=1, group= G.main->group.first; group; group= group->id.next, tot++) {
+                               if(group->id.lib==NULL) {
+                                       strp1 += sprintf(strp1, "%s %%x%d|", group->id.name+2, tot);
+                               }
+                       }
+                       tot= pupmenu_col(strp, 20);
+                       MEM_freeN(strp);
+                       if(tot>0) group= BLI_findlink(&G.main->group, tot-1);
+                       else return;
+               }
+               
+               if(mode==4) add_selected_to_act_ob_groups(scene, v3d);
+               else if(mode==1 || mode==3) add_selected_to_group(scene, v3d, group);
+               else if(mode==2) rem_selected_from_all_groups(scene, v3d);
+               else if(mode==5) rem_selected_from_group(scene, v3d);
+       }
+}
+
+void group_operation_with_menu(Scene *scene, View3D *v3d)
+{
+       Group *group= NULL;
+       int mode;
+       
+       /* are there existing groups? */
+       for(group= G.main->group.first; group; group= group->id.next)
+               if(group->id.lib==NULL)
+                       break;
+       
+       if(group)
+               mode= pupmenu("Groups %t|Add to Existing Group %x3|Add to Active Objects Groups %x4|Add to New Group %x1|Remove from Group %x5|Remove from All Groups %x2");
+       else
+               mode= pupmenu("Groups %t|Add to New Group %x1|Remove from All Groups %x2");
+       
+       group_operation(scene, v3d, mode);
+}
+
diff --git a/source/blender/editors/object/editkey.c b/source/blender/editors/object/editkey.c
new file mode 100644 (file)
index 0000000..9b3150c
--- /dev/null
@@ -0,0 +1,560 @@
+/**
+ * $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, shapekey support
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <math.h>
+#include <string.h>
+
+#ifndef WIN32
+#include <unistd.h>
+#else
+#include <io.h>
+#endif   
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+
+#include "DNA_action_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_ipo_types.h"
+#include "DNA_key_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view2d_types.h"
+
+#include "BKE_action.h"
+#include "BKE_anim.h"
+#include "BKE_curve.h"
+#include "BKE_depsgraph.h"
+#include "BKE_global.h"
+#include "BKE_ipo.h"
+#include "BKE_key.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_utildefines.h"
+
+#include "BLO_sys_types.h" // for intptr_t support
+
+#include "ED_object.h"
+
+#include "object_intern.h"
+
+/* XXX */
+static void BIF_undo_push() {}
+static void error() {}
+/* XXX */
+
+extern ListBase editNurb; /* in editcurve.c */
+
+
+static void default_key_ipo(Scene *scene, Key *key)
+{
+       IpoCurve *icu;
+       BezTriple *bezt;
+       
+       key->ipo= add_ipo(scene, "KeyIpo", ID_KE);
+       
+       icu= MEM_callocN(sizeof(IpoCurve), "ipocurve");
+                       
+       icu->blocktype= ID_KE;
+       icu->adrcode= KEY_SPEED;
+       icu->flag= IPO_VISIBLE|IPO_SELECT|IPO_AUTO_HORIZ;
+       set_icu_vars(icu);
+       
+       BLI_addtail( &(key->ipo->curve), icu);
+       
+       icu->bezt= bezt= MEM_callocN(2*sizeof(BezTriple), "defaultipo");
+       icu->totvert= 2;
+       
+       bezt->hide= IPO_BEZ;
+       bezt->f1=bezt->f2= bezt->f3= SELECT;
+       bezt->h1= bezt->h2= HD_AUTO;
+       bezt++;
+       bezt->vec[1][0]= 100.0;
+       bezt->vec[1][1]= 1.0;
+       bezt->hide= IPO_BEZ;
+       bezt->f1=bezt->f2= bezt->f3= SELECT;
+       bezt->h1= bezt->h2= HD_AUTO;
+       
+       calchandles_ipocurve(icu);
+}
+
+       
+
+/* **************************************** */
+
+void mesh_to_key(Mesh *me, KeyBlock *kb)
+{
+       MVert *mvert;
+       float *fp;
+       int a;
+       
+       if(me->totvert==0) return;
+       
+       if(kb->data) MEM_freeN(kb->data);
+       
+       kb->data= MEM_callocN(me->key->elemsize*me->totvert, "kb->data");
+       kb->totelem= me->totvert;
+       
+       mvert= me->mvert;
+       fp= kb->data;
+       for(a=0; a<kb->totelem; a++, fp+=3, mvert++) {
+               VECCOPY(fp, mvert->co);
+               
+       }
+}
+
+void key_to_mesh(KeyBlock *kb, Mesh *me)
+{
+       MVert *mvert;
+       float *fp;
+       int a, tot;
+       
+       mvert= me->mvert;
+       fp= kb->data;
+       
+       tot= MIN2(kb->totelem, me->totvert);
+       
+       for(a=0; a<tot; a++, fp+=3, mvert++) {
+               VECCOPY(mvert->co, fp);
+       }
+}
+
+static KeyBlock *add_keyblock(Scene *scene, Key *key)
+{
+       KeyBlock *kb;
+       float curpos= -0.1;
+       int tot;
+       
+       kb= key->block.last;
+       if(kb) curpos= kb->pos;
+       
+       kb= MEM_callocN(sizeof(KeyBlock), "Keyblock");
+       BLI_addtail(&key->block, kb);
+       kb->type= KEY_CARDINAL;
+       tot= BLI_countlist(&key->block);
+       if(tot==1) strcpy(kb->name, "Basis");
+       else sprintf(kb->name, "Key %d", tot-1);
+       kb->adrcode= tot-1;
+       
+       key->totkey++;
+       if(key->totkey==1) key->refkey= kb;
+       
+       
+       if(key->type == KEY_RELATIVE) 
+               kb->pos= curpos+0.1;
+       else {
+               curpos= bsystem_time(scene, 0, (float)CFRA, 0.0);
+               if(calc_ipo_spec(key->ipo, KEY_SPEED, &curpos)==0) {
+                       curpos /= 100.0;
+               }
+               kb->pos= curpos;
+               
+               sort_keys(key);
+       }
+       return kb;
+}
+
+void insert_meshkey(Scene *scene, Mesh *me, short rel)
+{
+       Key *key;
+       KeyBlock *kb;
+
+       if(me->key==NULL) {
+               me->key= add_key( (ID *)me);
+
+               if(rel)
+                       me->key->type = KEY_RELATIVE;
+               else
+                       default_key_ipo(scene, me->key);
+       }
+       key= me->key;
+       
+       kb= add_keyblock(scene, key);
+       
+       mesh_to_key(me, kb);
+}
+
+/* ******************** */
+
+void latt_to_key(Lattice *lt, KeyBlock *kb)
+{
+       BPoint *bp;
+       float *fp;
+       int a, tot;
+       
+       tot= lt->pntsu*lt->pntsv*lt->pntsw;
+       if(tot==0) return;
+       
+       if(kb->data) MEM_freeN(kb->data);
+       
+       kb->data= MEM_callocN(lt->key->elemsize*tot, "kb->data");
+       kb->totelem= tot;
+       
+       bp= lt->def;
+       fp= kb->data;
+       for(a=0; a<kb->totelem; a++, fp+=3, bp++) {
+               VECCOPY(fp, bp->vec);
+       }
+}
+
+void key_to_latt(KeyBlock *kb, Lattice *lt)
+{
+       BPoint *bp;
+       float *fp;
+       int a, tot;
+       
+       bp= lt->def;
+       fp= kb->data;
+       
+       tot= lt->pntsu*lt->pntsv*lt->pntsw;
+       tot= MIN2(kb->totelem, tot);
+       
+       for(a=0; a<tot; a++, fp+=3, bp++) {
+               VECCOPY(bp->vec, fp);
+       }
+       
+}
+
+/* exported to python... hrms, should not, use object levels! (ton) */
+void insert_lattkey(Scene *scene, Lattice *lt, short rel)
+{
+       Key *key;
+       KeyBlock *kb;
+       
+       if(lt->key==NULL) {
+               lt->key= add_key( (ID *)lt);
+               default_key_ipo(scene, lt->key);
+       }
+       key= lt->key;
+       
+       kb= add_keyblock(scene, key);
+       
+       latt_to_key(lt, kb);
+}
+
+/* ******************************** */
+
+void curve_to_key(Curve *cu, KeyBlock *kb, ListBase *nurb)
+{
+       Nurb *nu;
+       BezTriple *bezt;
+       BPoint *bp;
+       float *fp;
+       int a, tot;
+       
+       /* count */
+       tot= count_curveverts(nurb);
+       if(tot==0) return;
+       
+       if(kb->data) MEM_freeN(kb->data);
+       
+       kb->data= MEM_callocN(cu->key->elemsize*tot, "kb->data");
+       kb->totelem= tot;
+       
+       nu= nurb->first;
+       fp= kb->data;
+       while(nu) {
+               
+               if(nu->bezt) {
+                       bezt= nu->bezt;
+                       a= nu->pntsu;
+                       while(a--) {
+                               VECCOPY(fp, bezt->vec[0]);
+                               fp+= 3;
+                               VECCOPY(fp, bezt->vec[1]);
+                               fp+= 3;
+                               VECCOPY(fp, bezt->vec[2]);
+                               fp+= 3;
+                               fp[0]= bezt->alfa;
+                               fp+= 3; /* alphas */
+                               bezt++;
+                       }
+               }
+               else {
+                       bp= nu->bp;
+                       a= nu->pntsu*nu->pntsv;
+                       while(a--) {
+                               VECCOPY(fp, bp->vec);
+                               fp[3]= bp->alfa;
+                               
+                               fp+= 4;
+                               bp++;
+                       }
+               }
+               nu= nu->next;
+       }
+}
+
+void key_to_curve(KeyBlock *kb, Curve  *cu, ListBase *nurb)
+{
+       Nurb *nu;
+       BezTriple *bezt;
+       BPoint *bp;
+       float *fp;
+       int a, tot;
+       
+       nu= nurb->first;
+       fp= kb->data;
+       
+       tot= count_curveverts(nurb);
+
+       tot= MIN2(kb->totelem, tot);
+       
+       while(nu && tot>0) {
+               
+               if(nu->bezt) {
+                       bezt= nu->bezt;
+                       a= nu->pntsu;
+                       while(a-- && tot>0) {
+                               VECCOPY(bezt->vec[0], fp);
+                               fp+= 3;
+                               VECCOPY(bezt->vec[1], fp);
+                               fp+= 3;
+                               VECCOPY(bezt->vec[2], fp);
+                               fp+= 3;
+                               bezt->alfa= fp[0];
+                               fp+= 3; /* alphas */
+                       
+                               tot-= 3;
+                               bezt++;
+                       }
+               }
+               else {
+                       bp= nu->bp;
+                       a= nu->pntsu*nu->pntsv;
+                       while(a-- && tot>0) {
+                               VECCOPY(bp->vec, fp);
+                               bp->alfa= fp[3];
+                               
+                               fp+= 4;
+                               tot--;
+                               bp++;
+                       }
+               }
+               nu= nu->next;
+       }
+}
+
+
+void insert_curvekey(Scene *scene, Curve *cu, short rel) 
+{
+       Key *key;
+       KeyBlock *kb;
+       
+       if(cu->key==NULL) {
+               cu->key= add_key( (ID *)cu);
+
+               if (rel)
+                       cu->key->type = KEY_RELATIVE;
+               else
+                       default_key_ipo(scene, cu->key);
+       }
+       key= cu->key;
+       
+       kb= add_keyblock(scene, key);
+       
+       if(editNurb.first) curve_to_key(cu, kb, &editNurb);
+       else curve_to_key(cu, kb, &cu->nurb);
+}
+
+
+/* ******************** */
+
+void insert_shapekey(Scene *scene, Object *ob)
+{
+       if(get_mesh(ob) && get_mesh(ob)->mr) {
+               error("Cannot create shape keys on a multires mesh.");
+       }
+       else {
+               Key *key;
+       
+               if(ob->type==OB_MESH) insert_meshkey(scene, ob->data, 1);
+               else if ELEM(ob->type, OB_CURVE, OB_SURF) insert_curvekey(scene, ob->data, 1);
+               else if(ob->type==OB_LATTICE) insert_lattkey(scene, ob->data, 1);
+       
+               key= ob_get_key(ob);
+               ob->shapenr= BLI_countlist(&key->block);
+       
+               BIF_undo_push("Add Shapekey");
+       }
+}
+
+void delete_key(Scene *scene, Object *ob)
+{
+       KeyBlock *kb, *rkb;
+       Key *key;
+       IpoCurve *icu;
+       
+       key= ob_get_key(ob);
+       if(key==NULL) return;
+       
+       kb= BLI_findlink(&key->block, ob->shapenr-1);
+
+       if(kb) {
+               for(rkb= key->block.first; rkb; rkb= rkb->next)
+                       if(rkb->relative == ob->shapenr-1)
+                               rkb->relative= 0;
+
+               BLI_remlink(&key->block, kb);
+               key->totkey--;
+               if(key->refkey== kb) key->refkey= key->block.first;
+                       
+               if(kb->data) MEM_freeN(kb->data);
+               MEM_freeN(kb);
+               
+               for(kb= key->block.first; kb; kb= kb->next) {
+                       if(kb->adrcode>=ob->shapenr)
+                               kb->adrcode--;
+               }
+               
+               if(key->ipo) {
+                       
+                       for(icu= key->ipo->curve.first; icu; icu= icu->next) {
+                               if(icu->adrcode==ob->shapenr-1) {
+                                       BLI_remlink(&key->ipo->curve, icu);
+                                       free_ipo_curve(icu);
+                                       break;
+                               }
+                       }
+                       for(icu= key->ipo->curve.first; icu; icu= icu->next) 
+                               if(icu->adrcode>=ob->shapenr)
+                                       icu->adrcode--;
+               }               
+               
+               if(ob->shapenr>1) ob->shapenr--;
+       }
+       
+       if(key->totkey==0) {
+               if(GS(key->from->name)==ID_ME) ((Mesh *)key->from)->key= NULL;
+               else if(GS(key->from->name)==ID_CU) ((Curve *)key->from)->key= NULL;
+               else if(GS(key->from->name)==ID_LT) ((Lattice *)key->from)->key= NULL;
+
+               free_libblock_us(&(G.main->key), key);
+       }
+       
+       DAG_object_flush_update(scene, OBACT, OB_RECALC_DATA);
+       
+       BIF_undo_push("Delete Shapekey");
+}
+
+void move_keys(Object *ob)
+{
+#if 0
+       /* XXX probably goes away entirely */
+       Key *key;
+       KeyBlock *kb;
+       float div, dy, oldpos, vec[3], dvec[3];
+       int afbreek=0, firsttime= 1;
+       unsigned short event = 0;
+       short mval[2], val, xo, yo;
+       char str[32];
+       
+       if(G.sipo->blocktype!=ID_KE) return;
+       
+       if(G.sipo->ipo && G.sipo->ipo->id.lib) return;
+       if(G.sipo->editipo==NULL) return;
+
+       key= ob_get_key(ob);
+       if(key==NULL) return;
+       
+       /* which kb is involved */
+       kb= BLI_findlink(&key->block, ob->shapenr-1);
+       if(kb==NULL) return;    
+       
+       oldpos= kb->pos;
+       
+       getmouseco_areawin(mval);
+       xo= mval[0];
+       yo= mval[1];
+       dvec[0]=dvec[1]=dvec[2]= 0.0; 
+
+       while(afbreek==0) {
+               getmouseco_areawin(mval);
+               if(mval[0]!=xo || mval[1]!=yo || firsttime) {
+                       firsttime= 0;
+                       
+                       dy= (float)(mval[1]- yo);
+
+                       div= (float)(G.v2d->mask.ymax-G.v2d->mask.ymin);
+                       dvec[1]+= (G.v2d->cur.ymax-G.v2d->cur.ymin)*(dy)/div;
+                       
+                       VECCOPY(vec, dvec);
+
+                       apply_keyb_grid(vec, 0.0, 1.0, 0.1, U.flag & USER_AUTOGRABGRID);
+                       apply_keyb_grid(vec+1, 0.0, 1.0, 0.1, U.flag & USER_AUTOGRABGRID);
+
+                       kb->pos= oldpos+vec[1];
+                       
+                       sprintf(str, "Y: %.3f  ", vec[1]);
+                       headerprint(str);
+                       
+                       xo= mval[0];
+                       yo= mval[1];
+                               
+                       force_draw(0);
+               }
+               else BIF_wait_for_statechange();
+               
+               while(qtest()) {
+                       event= extern_qread(&val);
+                       if(val) {
+                               switch(event) {
+                               case ESCKEY:
+                               case LEFTMOUSE:
+                               case SPACEKEY:
+                                       afbreek= 1;
+                                       break;
+                               default:
+                                       arrows_move_cursor(event);
+                               }
+                       }
+               }
+       }
+       
+       if(event==ESCKEY) {
+               kb->pos= oldpos;
+       }
+       
+       sort_keys(key);
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+       
+       /* for boundbox */
+       editipo_changed(G.sipo, 0);
+
+       BIF_undo_push("Move Shapekey(s)");
+#endif
+}
diff --git a/source/blender/editors/object/editlattice.c b/source/blender/editors/object/editlattice.c
new file mode 100644 (file)
index 0000000..523f38d
--- /dev/null
@@ -0,0 +1,343 @@
+/**
+ * $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
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_key_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_armature.h"
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_global.h"
+#include "BKE_key.h"
+#include "BKE_lattice.h"
+#include "BKE_mesh.h"
+#include "BKE_utildefines.h"
+
+#include "ED_object.h"
+#include "ED_view3d.h"
+#include "ED_util.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "object_intern.h"
+
+/* ***************************** */
+
+static int okee() {return 0;}
+
+void free_editLatt(Object *ob)
+{
+       Lattice *lt= ob->data;
+       
+       if(lt->editlatt) {
+               if(lt->editlatt->def) MEM_freeN(lt->editlatt->def);
+               if(lt->editlatt->dvert) 
+                       free_dverts(lt->editlatt->dvert, lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw);
+               
+               MEM_freeN(lt->editlatt);
+               lt->editlatt= NULL;
+       }
+}
+
+
+static void setflagsLatt(Object *obedit, int flag)
+{
+       Lattice *lt= obedit->data;
+       BPoint *bp;
+       int a;
+       
+       bp= lt->editlatt->def;
+       
+       a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
+       
+       while(a--) {
+               if(bp->hide==0) {
+                       bp->f1= flag;
+               }
+               bp++;
+       }
+}
+
+
+
+void make_editLatt(Object *obedit)
+{
+       Lattice *lt= obedit->data;
+       KeyBlock *actkey;
+       
+       free_editLatt(obedit);
+       
+       lt= obedit->data;
+
+       actkey = ob_get_keyblock(obedit);
+       if(actkey) {
+               key_to_latt(actkey, lt);
+       }
+
+       lt->editlatt= MEM_dupallocN(lt);
+       lt->editlatt->def= MEM_dupallocN(lt->def);
+       
+       if(lt->dvert) {
+               int tot= lt->pntsu*lt->pntsv*lt->pntsw;
+               lt->editlatt->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert");
+               copy_dverts(lt->editlatt->dvert, lt->dvert, tot);
+       }
+       
+       //BIF_undo_push("Original");
+}
+
+
+void load_editLatt(Object *obedit)
+{
+       Lattice *lt;
+       KeyBlock *actkey;
+       BPoint *bp;
+       float *fp;
+       int tot;
+       
+       lt= obedit->data;
+       
+       actkey = ob_get_keyblock(obedit);
+       if(actkey) {
+               /* active key: vertices */
+               tot= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
+               
+               if(actkey->data) MEM_freeN(actkey->data);
+               
+               fp=actkey->data= MEM_callocN(lt->key->elemsize*tot, "actkey->data");
+               actkey->totelem= tot;
+       
+               bp= lt->editlatt->def;
+               while(tot--) {
+                       VECCOPY(fp, bp->vec);
+                       fp+= 3;
+                       bp++;
+               }
+       }
+       else {
+
+               MEM_freeN(lt->def);
+       
+               lt->def= MEM_dupallocN(lt->editlatt->def);
+
+               lt->flag= lt->editlatt->flag;
+
+               lt->pntsu= lt->editlatt->pntsu;
+               lt->pntsv= lt->editlatt->pntsv;
+               lt->pntsw= lt->editlatt->pntsw;
+               
+               lt->typeu= lt->editlatt->typeu;
+               lt->typev= lt->editlatt->typev;
+               lt->typew= lt->editlatt->typew;
+       }
+       
+       if(lt->dvert) {
+               free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
+               lt->dvert= NULL;
+       }
+       
+       if(lt->editlatt->dvert) {
+               int tot= lt->pntsu*lt->pntsv*lt->pntsw;
+               
+               lt->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert");
+               copy_dverts(lt->dvert, lt->editlatt->dvert, tot);
+       }
+       
+}
+
+void remake_editLatt(Object *obedit)
+{
+       if(okee("Reload original data")==0) return;
+       
+       make_editLatt(obedit);
+
+       //BIF_undo_push("Reload original");
+}
+
+
+void deselectall_Latt(Object *obedit)
+{
+       Lattice *lt= obedit->data;
+       BPoint *bp;
+       int a;
+       
+       bp= lt->editlatt->def;
+       
+       a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
+       
+       while(a--) {
+               if(bp->hide==0) {
+                       if(bp->f1) {
+                               setflagsLatt(obedit, 0);
+                               //BIF_undo_push("(De)select all");
+                               return;
+                       }
+               }
+               bp++;
+       }
+       setflagsLatt(obedit, 1);
+       //BIF_undo_push("(De)select all");
+}
+
+static void findnearestLattvert__doClosest(void *userData, BPoint *bp, int x, int y)
+{
+       struct { BPoint *bp; short dist, select, mval[2]; } *data = userData;
+       float temp = abs(data->mval[0]-x) + abs(data->mval[1]-y);
+       
+       if ((bp->f1 & SELECT)==data->select) temp += 5;
+       if (temp<data->dist) {
+               data->dist = temp;
+
+               data->bp = bp;
+       }
+}
+static BPoint *findnearestLattvert(ViewContext *vc, short mval[2], int sel)
+{
+               /* sel==1: selected gets a disadvantage */
+               /* in nurb and bezt or bp the nearest is written */
+               /* return 0 1 2: handlepunt */
+       struct { BPoint *bp; short dist, select, mval[2]; } data = {0};
+
+       data.dist = 100;
+       data.select = sel;
+       data.mval[0]= mval[0];
+       data.mval[1]= mval[1];
+
+       lattice_foreachScreenVert(vc, findnearestLattvert__doClosest, &data);
+
+       return data.bp;
+}
+
+
+void mouse_lattice(bContext *C, short mval[2], int extend)
+{
+       ViewContext vc;
+       BPoint *bp=0;
+
+       view3d_set_viewcontext(C, &vc);
+       
+       bp= findnearestLattvert(&vc, mval, 1);
+
+       if(bp) {
+               if(extend==0) {
+               
+                       setflagsLatt(vc.obedit, 0);
+                       bp->f1 |= SELECT;
+
+               }
+               else {
+                       bp->f1 ^= SELECT; /* swap */
+               }
+
+               WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, vc.obedit);
+               //BIF_undo_push("Select");
+       }
+}
+
+
+/* **************** undo for lattice object ************** */
+
+typedef struct UndoLattice {
+       BPoint *def;
+       int pntsu, pntsv, pntsw;
+} UndoLattice;
+
+static void undoLatt_to_editLatt(void *data, void *edata)
+{
+       UndoLattice *ult= (UndoLattice*)data;
+       Lattice *editlatt= (Lattice *)edata;
+       int a= editlatt->pntsu*editlatt->pntsv*editlatt->pntsw;
+
+       memcpy(editlatt->def, ult->def, a*sizeof(BPoint));
+}
+
+static void *editLatt_to_undoLatt(void *edata)
+{
+       UndoLattice *ult= MEM_callocN(sizeof(UndoLattice), "UndoLattice");
+       Lattice *editlatt= (Lattice *)edata;
+       
+       ult->def= MEM_dupallocN(editlatt->def);
+       ult->pntsu= editlatt->pntsu;
+       ult->pntsv= editlatt->pntsv;
+       ult->pntsw= editlatt->pntsw;
+       
+       return ult;
+}
+
+static void free_undoLatt(void *data)
+{
+       UndoLattice *ult= (UndoLattice*)data;
+
+       if(ult->def) MEM_freeN(ult->def);
+       MEM_freeN(ult);
+}
+
+static int validate_undoLatt(void *data, void *edata)
+{
+       UndoLattice *ult= (UndoLattice*)data;
+       Lattice *editlatt= (Lattice *)edata;
+
+       return (ult->pntsu == editlatt->pntsu &&
+               ult->pntsv == editlatt->pntsv &&
+               ult->pntsw == editlatt->pntsw);
+}
+
+static void *get_editlatt(bContext *C)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       if(obedit && obedit->type==OB_LATTICE) {
+               Lattice *lt= obedit->data;
+               return lt->editlatt;
+       }
+       return NULL;
+}
+
+
+/* and this is all the undo system needs to know */
+void undo_push_lattice(bContext *C, char *name)
+{
+       undo_editmode_push(C, name, get_editlatt, free_undoLatt, undoLatt_to_editLatt, editLatt_to_undoLatt, validate_undoLatt);
+}
+
+
+
+/***/
index 3e09315..27b4e35 100644 (file)
@@ -467,14 +467,14 @@ static void select_editmesh_hook(Object *ob, HookModifierData *hmd)
        EM_select_flush(em);
 }
 
-static int return_editlattice_indexar(int *tot, int **indexar, float *cent)
+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;
+       a= editlatt->pntsu*editlatt->pntsv*editlatt->pntsw;
+       bp= editlatt->def;
        while(a--) {
                if(bp->f1 & SELECT) {
                        if(bp->hide==0) totvert++;
@@ -489,8 +489,8 @@ static int return_editlattice_indexar(int *tot, int **indexar, float *cent)
        nr= 0;
        cent[0]= cent[1]= cent[2]= 0.0;
        
-       a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
-       bp= editLatt->def;
+       a= editlatt->pntsu*editlatt->pntsv*editlatt->pntsw;
+       bp= editlatt->def;
        while(a--) {
                if(bp->f1 & SELECT) {
                        if(bp->hide==0) {
@@ -507,14 +507,15 @@ static int return_editlattice_indexar(int *tot, int **indexar, float *cent)
        return totvert;
 }
 
-static void select_editlattice_hook(HookModifierData *hmd)
+static void select_editlattice_hook(Object *obedit, HookModifierData *hmd)
 {
+       Lattice *lt= obedit->data;
        BPoint *bp;
        int index=0, nr=0, a;
        
        /* count */
-       a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
-       bp= editLatt->def;
+       a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
+       bp= lt->editlatt->def;
        while(a--) {
                if(hmd->indexar[index]==nr) {
                        bp->f1 |= SELECT;
@@ -644,7 +645,10 @@ int hook_getIndexArray(Object *obedit, int *tot, int **indexar, char *name, floa
                case OB_SURF:
                        return return_editcurve_indexar(tot, indexar, cent_r);
                case OB_LATTICE:
-                       return return_editlattice_indexar(tot, indexar, cent_r);
+               {
+                       Lattice *lt= obedit->data;
+                       return return_editlattice_indexar(lt->editlatt, tot, indexar, cent_r);
+               }
                default:
                        return 0;
        }
@@ -701,7 +705,7 @@ void obedit_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(hmd);
+       else if(ob->type==OB_LATTICE) select_editlattice_hook(ob, hmd);
        else if(ob->type==OB_CURVE) select_editcurve_hook(hmd);
        else if(ob->type==OB_SURF) select_editcurve_hook(hmd);
 }
@@ -1813,9 +1817,10 @@ void make_vertex_parent(Scene *scene, Object *obedit, View3D *v3d)
                }
        }
        else if(obedit->type==OB_LATTICE) {
+               Lattice *lt= obedit->data;
                
-               a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
-               bp= editLatt->def;
+               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;
@@ -2691,8 +2696,8 @@ void ED_object_exit_editmode(bContext *C, int flag)
 //             load_editText();
        }
        else if(obedit->type==OB_LATTICE) {
-//             load_editLatt();
-//             if(freedata) free_editLatt();
+               load_editLatt(obedit);
+               if(freedata) free_editLatt(obedit);
        }
        else if(obedit->type==OB_MBALL) {
 //             extern ListBase editelems;
@@ -2783,21 +2788,28 @@ void ED_object_enter_editmode(bContext *C, int flag)
                scene->obedit= ob; // XXX for context
 //             ok= 1;
 // XXX         make_editText();
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_TEXT, ob);
        }
        else if(ob->type==OB_MBALL) {
                scene->obedit= ob; // XXX for context
 //             ok= 1;
 // XXX         make_editMball();
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MBALL, ob);
+               
        }
        else if(ob->type==OB_LATTICE) {
                scene->obedit= ob; // XXX for context
-//             ok= 1;
-// XXX         make_editLatt();
+               ok= 1;
+               make_editLatt(ob);
+               
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_LATTICE, ob);
        }
        else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
 //             ok= 1;
                scene->obedit= ob; // XXX for context
 // XXX         make_editNurb();
+               
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_CURVE, ob);
        }
        
        if(ok) {
@@ -3404,11 +3416,12 @@ void special_editmenu(Scene *scene, View3D *v3d)
 // XXX                 switch_direction_armature();
        }
        else if(obedit->type==OB_LATTICE) {
+               Lattice *lt= obedit->data;
                static float weight= 1.0f;
                { // XXX
 // XXX         if(fbutton(&weight, 0.0f, 1.0f, 10, 10, "Set Weight")) {
-                       int a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
-                       BPoint *bp= editLatt->def;
+                       int a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
+                       BPoint *bp= lt->editlatt->def;
                        
                        while(a--) {
                                if(bp->f1 & SELECT)
index a666149..f34ee44 100644 (file)
 #define ED_OBJECT_INTERN_H
 
 struct wmOperatorType;
+struct KeyBlock;
+struct Lattice;
+struct Curve;
+struct Object;
+struct Mesh;
 
 /* internal exports only */
 #define CLEAR_OBJ_ROTATION 0
@@ -58,5 +63,21 @@ void OBJECT_OT_set_slowparent(struct wmOperatorType *ot);
 void OBJECT_OT_clear_slowparent(struct wmOperatorType *ot);
 void OBJECT_OT_set_center(struct wmOperatorType *ot);
 
+/* editkey.c */
+void key_to_mesh(struct KeyBlock *kb, struct Mesh *me);
+void mesh_to_key(struct Mesh *me, struct KeyBlock *kb);
+void key_to_latt(struct KeyBlock *kb, struct Lattice *lt);
+void latt_to_key(struct Lattice *lt, struct KeyBlock *kb);
+void key_to_curve(struct KeyBlock *kb, struct Curve  *cu, struct ListBase *nurb);
+void curve_to_key(struct Curve *cu, struct KeyBlock *kb, struct ListBase *nurb);
+
+
+/* editlattice.c */
+void free_editLatt(Object *ob);
+void make_editLatt(Object *obedit);
+void load_editLatt(Object *obedit);
+void remake_editLatt(Object *obedit);
+
+
 #endif /* ED_OBJECT_INTERN_H */
 
index dfb4e0d..0044002 100644 (file)
 
 
 /* pretty stupid */
-/*  extern Lattice *editLatt; already in BKE_lattice.h  */
 /* editcurve.c */
 extern ListBase editNurb;
 /* editmball.c */
@@ -1083,11 +1082,13 @@ static void lattice_draw_verts(Lattice *lt, DispList *dl, short sel)
 
 void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPoint *bp, int x, int y), void *userData)
 {
-       BPoint *bp = editLatt->def;
-       DispList *dl = find_displist(&vc->obedit->disp, DL_VERTS);
+       Object *obedit= vc->obedit;
+       Lattice *lt= obedit->data;
+       BPoint *bp = lt->editlatt->def;
+       DispList *dl = find_displist(&obedit->disp, DL_VERTS);
        float *co = dl?dl->verts:NULL;
        float pmat[4][4], vmat[4][4];
-       int i, N = editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
+       int i, N = lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
        short s[2];
 
        view3d_get_object_project_mat(vc->v3d, vc->obedit, pmat, vmat);
index d828c0c..1be23b6 100644 (file)
@@ -2048,6 +2048,8 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
 //     if (v3d->flag2 & V3D_DISPGP)
 //             draw_gpencil_3dview(ar, 0);
 
+       drawcursor(scene, ar, v3d);
+       
        if(U.uiflag & USER_SHOW_ROTVIEWICON)
                draw_view_axis(v3d);
        else    
index f304418..e7e6f6f 100644 (file)
@@ -116,8 +116,6 @@ void VIEW3D_OT_circle_select(struct wmOperatorType *ot);
 void VIEW3D_OT_borderselect(struct wmOperatorType *ot);
 void VIEW3D_OT_lasso_select(struct wmOperatorType *ot);
 
-void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc);
-
 /* vpaint.c */
 void VIEW3D_OT_vpaint_toggle(struct wmOperatorType *ot);
 void VIEW3D_OT_vpaint(struct wmOperatorType *ot);
index 2a6d7f3..11f9ad9 100644 (file)
@@ -1541,6 +1541,8 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        mouse_mesh(C, mval, extend);
                else if(obedit->type==OB_ARMATURE)
                        mouse_armature(C, mval, extend);
+               else if(obedit->type==OB_LATTICE)
+                       mouse_lattice(C, mval, extend);
                        
        }
        else