2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-01-13 15:18:41 +00:00
|
|
|
* ***** 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-01-13 15:18:41 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/object/object_lattice.c
|
|
|
|
* \ingroup edobj
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_listbase.h"
|
2011-11-07 01:38:32 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
#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"
|
|
|
|
|
2009-11-29 22:16:29 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_depsgraph.h"
|
|
|
|
#include "BKE_key.h"
|
|
|
|
#include "BKE_lattice.h"
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
#include "ED_lattice.h"
|
|
|
|
#include "ED_object.h"
|
2009-07-03 15:23:33 +00:00
|
|
|
#include "ED_screen.h"
|
2009-01-13 15:18:41 +00:00
|
|
|
#include "ED_view3d.h"
|
|
|
|
#include "ED_util.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "object_intern.h"
|
|
|
|
|
2009-07-03 15:23:33 +00:00
|
|
|
/********************** Load/Make/Free ********************/
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
void free_editLatt(Object *ob)
|
|
|
|
{
|
|
|
|
Lattice *lt= ob->data;
|
|
|
|
|
|
|
|
if(lt->editlatt) {
|
2010-08-10 06:36:42 +00:00
|
|
|
Lattice *editlt= lt->editlatt->latt;
|
|
|
|
|
|
|
|
if(editlt->def)
|
|
|
|
MEM_freeN(editlt->def);
|
|
|
|
if(editlt->dvert)
|
|
|
|
free_dverts(editlt->dvert, editlt->pntsu*editlt->pntsv*editlt->pntsw);
|
|
|
|
|
|
|
|
MEM_freeN(editlt);
|
2009-01-13 15:18:41 +00:00
|
|
|
MEM_freeN(lt->editlatt);
|
2010-08-10 06:36:42 +00:00
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
lt->editlatt= NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void make_editLatt(Object *obedit)
|
|
|
|
{
|
|
|
|
Lattice *lt= obedit->data;
|
|
|
|
KeyBlock *actkey;
|
2010-08-10 06:36:42 +00:00
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
free_editLatt(obedit);
|
2010-08-10 06:36:42 +00:00
|
|
|
|
2009-07-03 15:23:33 +00:00
|
|
|
actkey= ob_get_keyblock(obedit);
|
|
|
|
if(actkey)
|
2009-01-13 15:18:41 +00:00
|
|
|
key_to_latt(actkey, lt);
|
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
lt->editlatt= MEM_callocN(sizeof(EditLatt), "editlatt");
|
|
|
|
lt->editlatt->latt= MEM_dupallocN(lt);
|
|
|
|
lt->editlatt->latt->def= MEM_dupallocN(lt->def);
|
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
if(lt->dvert) {
|
|
|
|
int tot= lt->pntsu*lt->pntsv*lt->pntsw;
|
2010-08-10 06:36:42 +00:00
|
|
|
lt->editlatt->latt->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert");
|
|
|
|
copy_dverts(lt->editlatt->latt->dvert, lt->dvert, tot);
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2010-08-10 06:36:42 +00:00
|
|
|
|
|
|
|
if(lt->key) lt->editlatt->shapenr= obedit->shapenr;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void load_editLatt(Object *obedit)
|
|
|
|
{
|
2010-08-10 06:36:42 +00:00
|
|
|
Lattice *lt, *editlt;
|
2009-01-13 15:18:41 +00:00
|
|
|
KeyBlock *actkey;
|
|
|
|
BPoint *bp;
|
|
|
|
float *fp;
|
|
|
|
int tot;
|
2010-08-10 06:36:42 +00:00
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
lt= obedit->data;
|
2010-08-10 06:36:42 +00:00
|
|
|
editlt= lt->editlatt->latt;
|
|
|
|
|
|
|
|
if(lt->editlatt->shapenr) {
|
|
|
|
actkey= BLI_findlink(<->key->block, lt->editlatt->shapenr-1);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
/* active key: vertices */
|
2010-08-10 06:36:42 +00:00
|
|
|
tot= editlt->pntsu*editlt->pntsv*editlt->pntsw;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
if(actkey->data) MEM_freeN(actkey->data);
|
|
|
|
|
|
|
|
fp=actkey->data= MEM_callocN(lt->key->elemsize*tot, "actkey->data");
|
|
|
|
actkey->totelem= tot;
|
2010-08-10 06:36:42 +00:00
|
|
|
|
|
|
|
bp= editlt->def;
|
2009-01-13 15:18:41 +00:00
|
|
|
while(tot--) {
|
2011-11-07 01:38:32 +00:00
|
|
|
copy_v3_v3(fp, bp->vec);
|
2009-01-13 15:18:41 +00:00
|
|
|
fp+= 3;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
MEM_freeN(lt->def);
|
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
lt->def= MEM_dupallocN(editlt->def);
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
lt->flag= editlt->flag;
|
|
|
|
|
|
|
|
lt->pntsu= editlt->pntsu;
|
|
|
|
lt->pntsv= editlt->pntsv;
|
|
|
|
lt->pntsw= editlt->pntsw;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
lt->typeu= editlt->typeu;
|
|
|
|
lt->typev= editlt->typev;
|
|
|
|
lt->typew= editlt->typew;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2010-08-10 06:36:42 +00:00
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
if(lt->dvert) {
|
|
|
|
free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw);
|
|
|
|
lt->dvert= NULL;
|
|
|
|
}
|
2010-08-10 06:36:42 +00:00
|
|
|
|
|
|
|
if(editlt->dvert) {
|
2010-12-03 12:30:59 +00:00
|
|
|
tot= lt->pntsu*lt->pntsv*lt->pntsw;
|
2010-08-10 06:36:42 +00:00
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
lt->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert");
|
2010-08-10 06:36:42 +00:00
|
|
|
copy_dverts(lt->dvert, editlt->dvert, tot);
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 15:23:33 +00:00
|
|
|
/************************** Operators *************************/
|
|
|
|
|
2009-11-29 22:16:29 +00:00
|
|
|
void ED_setflagsLatt(Object *obedit, int flag)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
2009-07-03 15:23:33 +00:00
|
|
|
Lattice *lt= obedit->data;
|
|
|
|
BPoint *bp;
|
|
|
|
int a;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
bp= lt->editlatt->latt->def;
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
|
2009-07-03 15:23:33 +00:00
|
|
|
|
|
|
|
while(a--) {
|
|
|
|
if(bp->hide==0) {
|
|
|
|
bp->f1= flag;
|
|
|
|
}
|
|
|
|
bp++;
|
|
|
|
}
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 03:02:09 +00:00
|
|
|
static int lattice_select_all_exec(bContext *C, wmOperator *op)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
2009-07-03 15:23:33 +00:00
|
|
|
Object *obedit= CTX_data_edit_object(C);
|
2009-01-13 15:18:41 +00:00
|
|
|
Lattice *lt= obedit->data;
|
|
|
|
BPoint *bp;
|
2009-11-29 22:16:29 +00:00
|
|
|
int a;
|
|
|
|
int action = RNA_enum_get(op->ptr, "action");
|
|
|
|
|
|
|
|
if (action == SEL_TOGGLE) {
|
|
|
|
action = SEL_SELECT;
|
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
bp= lt->editlatt->latt->def;
|
|
|
|
a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
|
2009-11-29 22:16:29 +00:00
|
|
|
|
|
|
|
while(a--) {
|
|
|
|
if(bp->hide==0) {
|
|
|
|
if(bp->f1) {
|
|
|
|
action = SEL_DESELECT;
|
|
|
|
break;
|
|
|
|
}
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2009-11-29 22:16:29 +00:00
|
|
|
bp++;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2009-11-29 22:16:29 +00:00
|
|
|
switch (action) {
|
|
|
|
case SEL_SELECT:
|
|
|
|
ED_setflagsLatt(obedit, 1);
|
|
|
|
break;
|
|
|
|
case SEL_DESELECT:
|
|
|
|
ED_setflagsLatt(obedit, 0);
|
|
|
|
break;
|
|
|
|
case SEL_INVERT:
|
2010-08-10 06:36:42 +00:00
|
|
|
bp= lt->editlatt->latt->def;
|
|
|
|
a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
|
2009-11-29 22:16:29 +00:00
|
|
|
|
|
|
|
while(a--) {
|
|
|
|
if(bp->hide==0) {
|
|
|
|
bp->f1 ^= 1;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2009-11-29 22:16:29 +00:00
|
|
|
bp++;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2009-11-29 22:16:29 +00:00
|
|
|
break;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
2009-11-29 22:16:29 +00:00
|
|
|
void LATTICE_OT_select_all(wmOperatorType *ot)
|
2009-07-03 15:23:33 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-17 19:14:08 +00:00
|
|
|
ot->name= "(De)select All";
|
2010-03-22 09:30:00 +00:00
|
|
|
ot->description= "Change selection of all UVW control points";
|
2009-11-29 22:16:29 +00:00
|
|
|
ot->idname= "LATTICE_OT_select_all";
|
2009-07-03 15:23:33 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2011-10-28 03:02:09 +00:00
|
|
|
ot->exec= lattice_select_all_exec;
|
2009-07-03 15:23:33 +00:00
|
|
|
ot->poll= ED_operator_editlattice;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
2009-11-29 22:16:29 +00:00
|
|
|
|
|
|
|
WM_operator_properties_select_all(ot);
|
2009-07-03 15:23:33 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int make_regular_poll(bContext *C)
|
2009-07-03 15:23:33 +00:00
|
|
|
{
|
|
|
|
Object *ob;
|
|
|
|
|
|
|
|
if(ED_operator_editlattice(C)) return 1;
|
|
|
|
|
|
|
|
ob= CTX_data_active_object(C);
|
|
|
|
return (ob && ob->type==OB_LATTICE);
|
|
|
|
}
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int make_regular_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-07-03 15:23:33 +00:00
|
|
|
{
|
|
|
|
Object *ob= CTX_data_edit_object(C);
|
|
|
|
Lattice *lt;
|
|
|
|
|
|
|
|
if(ob) {
|
|
|
|
lt= ob->data;
|
2010-08-10 06:36:42 +00:00
|
|
|
resizelattice(lt->editlatt->latt, lt->pntsu, lt->pntsv, lt->pntsw, NULL);
|
2009-07-03 15:23:33 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ob= CTX_data_active_object(C);
|
|
|
|
lt= ob->data;
|
|
|
|
resizelattice(lt, lt->pntsu, lt->pntsv, lt->pntsw, NULL);
|
|
|
|
}
|
|
|
|
|
2010-12-05 18:59:23 +00:00
|
|
|
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
|
2009-09-16 17:43:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LATTICE_OT_make_regular(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Make Regular";
|
2010-03-22 09:30:00 +00:00
|
|
|
ot->description= "Set UVW control points a uniform distance apart";
|
2009-07-03 15:23:33 +00:00
|
|
|
ot->idname= "LATTICE_OT_make_regular";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= make_regular_exec;
|
|
|
|
ot->poll= make_regular_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************** Mouse Selection *************************/
|
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
static void findnearestLattvert__doClosest(void *userData, BPoint *bp, int x, int y)
|
|
|
|
{
|
2011-05-12 16:47:36 +00:00
|
|
|
struct { BPoint *bp; short dist, select; int mval[2]; } *data = userData;
|
2009-01-13 15:18:41 +00:00
|
|
|
float temp = abs(data->mval[0]-x) + abs(data->mval[1]-y);
|
|
|
|
|
2009-07-03 15:23:33 +00:00
|
|
|
if((bp->f1 & SELECT)==data->select)
|
|
|
|
temp += 5;
|
|
|
|
|
|
|
|
if(temp<data->dist) {
|
2009-01-13 15:18:41 +00:00
|
|
|
data->dist = temp;
|
|
|
|
|
|
|
|
data->bp = bp;
|
|
|
|
}
|
|
|
|
}
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2011-05-12 16:47:36 +00:00
|
|
|
static BPoint *findnearestLattvert(ViewContext *vc, const int mval[2], int sel)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
|
|
|
/* sel==1: selected gets a disadvantage */
|
|
|
|
/* in nurb and bezt or bp the nearest is written */
|
|
|
|
/* return 0 1 2: handlepunt */
|
2011-05-12 16:47:36 +00:00
|
|
|
struct { BPoint *bp; short dist, select; int mval[2]; } data = {NULL};
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
data.dist = 100;
|
|
|
|
data.select = sel;
|
|
|
|
data.mval[0]= mval[0];
|
|
|
|
data.mval[1]= mval[1];
|
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
|
2009-01-13 15:18:41 +00:00
|
|
|
lattice_foreachScreenVert(vc, findnearestLattvert__doClosest, &data);
|
|
|
|
|
|
|
|
return data.bp;
|
|
|
|
}
|
|
|
|
|
2011-05-12 16:47:36 +00:00
|
|
|
int mouse_lattice(bContext *C, const int mval[2], int extend)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
|
|
|
ViewContext vc;
|
2009-07-03 15:23:33 +00:00
|
|
|
BPoint *bp= NULL;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
view3d_set_viewcontext(C, &vc);
|
|
|
|
bp= findnearestLattvert(&vc, mval, 1);
|
|
|
|
|
|
|
|
if(bp) {
|
|
|
|
if(extend==0) {
|
2009-11-29 22:16:29 +00:00
|
|
|
ED_setflagsLatt(vc.obedit, 0);
|
2009-01-13 15:18:41 +00:00
|
|
|
bp->f1 |= SELECT;
|
|
|
|
}
|
2009-07-03 15:23:33 +00:00
|
|
|
else
|
2009-01-13 15:18:41 +00:00
|
|
|
bp->f1 ^= SELECT; /* swap */
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit->data);
|
2009-11-24 04:59:52 +00:00
|
|
|
|
|
|
|
return 1;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
2009-11-24 04:59:52 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 15:23:33 +00:00
|
|
|
/******************************** Undo *************************/
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
typedef struct UndoLattice {
|
|
|
|
BPoint *def;
|
|
|
|
int pntsu, pntsv, pntsw;
|
|
|
|
} UndoLattice;
|
|
|
|
|
2011-05-09 14:32:55 +00:00
|
|
|
static void undoLatt_to_editLatt(void *data, void *edata, void *UNUSED(obdata))
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
|
|
|
UndoLattice *ult= (UndoLattice*)data;
|
2010-08-10 06:36:42 +00:00
|
|
|
EditLatt *editlatt= (EditLatt *)edata;
|
|
|
|
int a= editlatt->latt->pntsu*editlatt->latt->pntsv*editlatt->latt->pntsw;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
memcpy(editlatt->latt->def, ult->def, a*sizeof(BPoint));
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
2011-05-09 14:32:55 +00:00
|
|
|
static void *editLatt_to_undoLatt(void *edata, void *UNUSED(obdata))
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
|
|
|
UndoLattice *ult= MEM_callocN(sizeof(UndoLattice), "UndoLattice");
|
2010-08-10 06:36:42 +00:00
|
|
|
EditLatt *editlatt= (EditLatt *)edata;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
ult->def= MEM_dupallocN(editlatt->latt->def);
|
|
|
|
ult->pntsu= editlatt->latt->pntsu;
|
|
|
|
ult->pntsv= editlatt->latt->pntsv;
|
|
|
|
ult->pntsw= editlatt->latt->pntsw;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
|
|
|
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;
|
2010-08-10 06:36:42 +00:00
|
|
|
EditLatt *editlatt= (EditLatt *)edata;
|
2009-01-13 15:18:41 +00:00
|
|
|
|
2010-08-10 06:36:42 +00:00
|
|
|
return (ult->pntsu == editlatt->latt->pntsu &&
|
|
|
|
ult->pntsv == editlatt->latt->pntsv &&
|
|
|
|
ult->pntsw == editlatt->latt->pntsw);
|
2009-01-13 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *get_editlatt(bContext *C)
|
|
|
|
{
|
|
|
|
Object *obedit= CTX_data_edit_object(C);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
if(obedit && obedit->type==OB_LATTICE) {
|
|
|
|
Lattice *lt= obedit->data;
|
|
|
|
return lt->editlatt;
|
|
|
|
}
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2009-01-13 15:18:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and this is all the undo system needs to know */
|
2010-11-17 09:45:45 +00:00
|
|
|
void undo_push_lattice(bContext *C, const char *name)
|
2009-01-13 15:18:41 +00:00
|
|
|
{
|
|
|
|
undo_editmode_push(C, name, get_editlatt, free_undoLatt, undoLatt_to_editLatt, editLatt_to_undoLatt, validate_undoLatt);
|
|
|
|
}
|
|
|
|
|