| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2013-07-19 10:44:39 +00:00
										 |  |  | #include "BLI_rand.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-19 10:49:23 +00:00
										 |  |  | #include "BLI_bitmap.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | #include "RNA_define.h"
 | 
					
						
							| 
									
										
										
										
											2013-12-09 15:40:41 +11:00
										 |  |  | #include "RNA_enum_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-29 22:16:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_depsgraph.h"
 | 
					
						
							|  |  |  | #include "BKE_key.h"
 | 
					
						
							|  |  |  | #include "BKE_lattice.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-28 09:06:48 +00:00
										 |  |  | #include "BKE_deform.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-19 10:49:23 +00:00
										 |  |  | #include "BKE_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	Lattice *lt = ob->data; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (lt->editlatt) { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		Lattice *editlt = lt->editlatt->latt; | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		if (editlt->def) | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 			MEM_freeN(editlt->def); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		if (editlt->dvert) | 
					
						
							| 
									
										
										
										
											2012-12-28 09:06:48 +00:00
										 |  |  | 			BKE_defvert_array_free(editlt->dvert, editlt->pntsu * editlt->pntsv * editlt->pntsw); | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		MEM_freeN(editlt); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 		MEM_freeN(lt->editlatt); | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		lt->editlatt = NULL; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void make_editLatt(Object *obedit) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	Lattice *lt = obedit->data; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 10:12:07 +00:00
										 |  |  | 	actkey = BKE_keyblock_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (actkey) | 
					
						
							| 
									
										
										
										
											2012-09-19 10:12:07 +00:00
										 |  |  | 		BKE_key_convert_to_lattice(actkey, lt); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	lt->editlatt = MEM_callocN(sizeof(EditLatt), "editlatt"); | 
					
						
							|  |  |  | 	lt->editlatt->latt = MEM_dupallocN(lt); | 
					
						
							|  |  |  | 	lt->editlatt->latt->def = MEM_dupallocN(lt->def); | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (lt->dvert) { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		int tot = lt->pntsu * lt->pntsv * lt->pntsw; | 
					
						
							| 
									
										
										
										
											2012-06-17 09:58:26 +00:00
										 |  |  | 		lt->editlatt->latt->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert"); | 
					
						
							| 
									
										
										
										
											2012-12-28 09:06:48 +00:00
										 |  |  | 		BKE_defvert_array_copy(lt->editlatt->latt->dvert, lt->dvert, tot); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	lt = obedit->data; | 
					
						
							|  |  |  | 	editlt = lt->editlatt->latt; | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (lt->editlatt->shapenr) { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		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 */ | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		tot = editlt->pntsu * editlt->pntsv * editlt->pntsw; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		if (actkey->data) MEM_freeN(actkey->data); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		fp = actkey->data = MEM_callocN(lt->key->elemsize * tot, "actkey->data"); | 
					
						
							|  |  |  | 		actkey->totelem = tot; | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		bp = editlt->def; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		while (tot--) { | 
					
						
							| 
									
										
										
										
											2011-11-07 01:38:32 +00:00
										 |  |  | 			copy_v3_v3(fp, bp->vec); | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 			fp += 3; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 			bp++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		MEM_freeN(lt->def); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		lt->def = MEM_dupallocN(editlt->def); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		lt->flag = editlt->flag; | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		lt->pntsu = editlt->pntsu; | 
					
						
							|  |  |  | 		lt->pntsv = editlt->pntsv; | 
					
						
							|  |  |  | 		lt->pntsw = editlt->pntsw; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		lt->typeu = editlt->typeu; | 
					
						
							|  |  |  | 		lt->typev = editlt->typev; | 
					
						
							|  |  |  | 		lt->typew = editlt->typew; | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 		lt->actbp = editlt->actbp; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (lt->dvert) { | 
					
						
							| 
									
										
										
										
											2012-12-28 09:06:48 +00:00
										 |  |  | 		BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		lt->dvert = NULL; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (editlt->dvert) { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		tot = lt->pntsu * lt->pntsv * lt->pntsw; | 
					
						
							| 
									
										
										
										
											2010-08-10 06:36:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 09:58:26 +00:00
										 |  |  | 		lt->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert"); | 
					
						
							| 
									
										
										
										
											2012-12-28 09:06:48 +00:00
										 |  |  | 		BKE_defvert_array_copy(lt->dvert, editlt->dvert, tot); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 22:13:15 +11:00
										 |  |  | /*************************** Transform Operator ************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ED_lattice_transform(Lattice *lt, float mat[4][4]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPoint *bp = lt->def; | 
					
						
							|  |  |  | 	int a = lt->pntsu * lt->pntsv * lt->pntsw; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (a--) { | 
					
						
							|  |  |  | 		mul_m4_v3(mat, bp->vec); | 
					
						
							|  |  |  | 		bp++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DAG_id_tag_update(<->id, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-13 20:36:38 +11:00
										 |  |  | static void bpoint_select_set(BPoint *bp, bool select) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (select) { | 
					
						
							|  |  |  | 		if (!bp->hide) { | 
					
						
							|  |  |  | 			bp->f1 |= SELECT; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		bp->f1 &= ~SELECT; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-19 10:44:39 +00:00
										 |  |  | /************************** Select Random Operator **********************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int lattice_select_random_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-07-21 08:16:37 +00:00
										 |  |  | 	Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt; | 
					
						
							| 
									
										
										
										
											2013-07-19 10:44:39 +00:00
										 |  |  | 	const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f; | 
					
						
							| 
									
										
										
										
											2014-01-13 20:36:38 +11:00
										 |  |  | 	const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-19 10:44:39 +00:00
										 |  |  | 	int tot; | 
					
						
							|  |  |  | 	BPoint *bp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tot = lt->pntsu * lt->pntsv * lt->pntsw; | 
					
						
							|  |  |  | 	bp = lt->def; | 
					
						
							|  |  |  | 	while (tot--) { | 
					
						
							|  |  |  | 		if (!bp->hide) { | 
					
						
							|  |  |  | 			if (BLI_frand() < randfac) { | 
					
						
							| 
									
										
										
										
											2014-01-13 20:36:38 +11:00
										 |  |  | 				bpoint_select_set(bp, select); | 
					
						
							| 
									
										
										
										
											2013-07-19 10:44:39 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		bp++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-13 20:36:38 +11:00
										 |  |  | 	if (select == false) { | 
					
						
							|  |  |  | 		lt->actbp = LT_ACTBP_NONE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-19 10:44:39 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LATTICE_OT_select_random(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Random"; | 
					
						
							|  |  |  | 	ot->description = "Randomly select UVW control points"; | 
					
						
							|  |  |  | 	ot->idname = "LATTICE_OT_select_random"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = lattice_select_random_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editlattice; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, | 
					
						
							|  |  |  | 	                         "Percent", "Percentage of elements to select randomly", 0.f, 100.0f); | 
					
						
							| 
									
										
										
										
											2014-01-13 20:36:38 +11:00
										 |  |  | 	WM_operator_properties_select_action_simple(ot, SEL_SELECT); | 
					
						
							| 
									
										
										
										
											2013-07-19 10:44:39 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-09 15:40:41 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Select Mirror Operator */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int lattice_select_mirror_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt; | 
					
						
							|  |  |  | 	const bool extend = RNA_boolean_get(op->ptr, "extend"); | 
					
						
							|  |  |  | 	const int axis = RNA_enum_get(op->ptr, "axis"); | 
					
						
							|  |  |  | 	bool flip_uvw[3] = {false}; | 
					
						
							|  |  |  | 	int tot, i; | 
					
						
							|  |  |  | 	BPoint *bp; | 
					
						
							|  |  |  | 	BLI_bitmap *selpoints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tot = lt->pntsu * lt->pntsv * lt->pntsw; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	flip_uvw[axis] = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!extend) { | 
					
						
							|  |  |  | 		lt->actbp = LT_ACTBP_NONE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* store "original" selection */ | 
					
						
							|  |  |  | 	selpoints = BLI_BITMAP_NEW(tot, __func__); | 
					
						
							|  |  |  | 	BKE_lattice_bitmap_from_flag(lt, selpoints, SELECT, false, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* actual (de)selection */ | 
					
						
							|  |  |  | 	for (i = 0; i < tot; i++) { | 
					
						
							|  |  |  | 		const int i_flip = BKE_lattice_index_flip(lt, i, flip_uvw[0], flip_uvw[1], flip_uvw[2]); | 
					
						
							|  |  |  | 		bp = <->def[i]; | 
					
						
							|  |  |  | 		if (!bp->hide) { | 
					
						
							| 
									
										
										
										
											2014-06-06 16:05:15 +10:00
										 |  |  | 			if (BLI_BITMAP_TEST(selpoints, i_flip)) { | 
					
						
							| 
									
										
										
										
											2013-12-09 15:40:41 +11:00
										 |  |  | 				bp->f1 |= SELECT; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				if (!extend) { | 
					
						
							|  |  |  | 					bp->f1 &= ~SELECT; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MEM_freeN(selpoints); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LATTICE_OT_select_mirror(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Mirror"; | 
					
						
							|  |  |  | 	ot->description = "Select mirrored lattice points"; | 
					
						
							|  |  |  | 	ot->idname = "LATTICE_OT_select_mirror"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = lattice_select_mirror_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editlattice; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "axis", object_axis_unsigned_items, 0, "Axis", ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-19 10:49:23 +00:00
										 |  |  | /************************** Select More/Less Operator *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-22 23:20:48 +00:00
										 |  |  | static bool lattice_test_bitmap_uvw(Lattice *lt, BLI_bitmap *selpoints, int u, int v, int w, const bool selected) | 
					
						
							| 
									
										
										
										
											2013-07-19 10:49:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if ((u < 0 || u >= lt->pntsu) || | 
					
						
							|  |  |  | 	    (v < 0 || v >= lt->pntsv) || | 
					
						
							|  |  |  | 	    (w < 0 || w >= lt->pntsw)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		int i = BKE_lattice_index_from_uvw(lt, u, v, w); | 
					
						
							|  |  |  | 		if (lt->def[i].hide == 0) { | 
					
						
							| 
									
										
										
										
											2014-06-06 16:05:15 +10:00
										 |  |  | 			return (BLI_BITMAP_TEST(selpoints, i) != 0) == selected; | 
					
						
							| 
									
										
										
										
											2013-07-19 10:49:23 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int lattice_select_more_less(bContext *C, const bool select) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt; | 
					
						
							|  |  |  | 	BPoint *bp; | 
					
						
							|  |  |  | 	const int tot = lt->pntsu * lt->pntsv * lt->pntsw; | 
					
						
							| 
									
										
										
										
											2013-12-09 15:32:05 +11:00
										 |  |  | 	int u, v, w; | 
					
						
							| 
									
										
										
										
											2013-07-22 23:20:48 +00:00
										 |  |  | 	BLI_bitmap *selpoints; | 
					
						
							| 
									
										
										
										
											2013-07-19 10:49:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	lt->actbp = LT_ACTBP_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	selpoints = BLI_BITMAP_NEW(tot, __func__); | 
					
						
							| 
									
										
										
										
											2013-12-09 15:32:05 +11:00
										 |  |  | 	BKE_lattice_bitmap_from_flag(lt, selpoints, SELECT, false, false); | 
					
						
							| 
									
										
										
										
											2013-07-19 10:49:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bp = lt->def; | 
					
						
							|  |  |  | 	for (w = 0; w < lt->pntsw; w++) { | 
					
						
							|  |  |  | 		for (v = 0; v < lt->pntsv; v++) { | 
					
						
							|  |  |  | 			for (u = 0; u < lt->pntsu; u++) { | 
					
						
							|  |  |  | 				if ((bp->hide == 0) && (((bp->f1 & SELECT) == 0) == select)) { | 
					
						
							|  |  |  | 					if (lattice_test_bitmap_uvw(lt, selpoints, u + 1, v, w, select) || | 
					
						
							|  |  |  | 					    lattice_test_bitmap_uvw(lt, selpoints, u - 1, v, w, select) || | 
					
						
							|  |  |  | 					    lattice_test_bitmap_uvw(lt, selpoints, u, v + 1, w, select) || | 
					
						
							|  |  |  | 					    lattice_test_bitmap_uvw(lt, selpoints, u, v - 1, w, select) || | 
					
						
							|  |  |  | 					    lattice_test_bitmap_uvw(lt, selpoints, u, v, w + 1, select) || | 
					
						
							|  |  |  | 					    lattice_test_bitmap_uvw(lt, selpoints, u, v, w - 1, select)) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						BKE_BIT_TEST_SET(bp->f1, select, SELECT); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				bp++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MEM_freeN(selpoints); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int lattice_select_more_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return lattice_select_more_less(C, true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int lattice_select_less_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return lattice_select_more_less(C, false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LATTICE_OT_select_more(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select More"; | 
					
						
							|  |  |  | 	ot->description = "Select vertex directly linked to already selected ones"; | 
					
						
							|  |  |  | 	ot->idname = "LATTICE_OT_select_more"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = lattice_select_more_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editlattice; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LATTICE_OT_select_less(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Less"; | 
					
						
							|  |  |  | 	ot->description = "Deselect vertices at the boundary of each selection region"; | 
					
						
							|  |  |  | 	ot->idname = "LATTICE_OT_select_less"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = lattice_select_less_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editlattice; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | /************************** Select All Operator *************************/ | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-29 22:16:29 +00:00
										 |  |  | void ED_setflagsLatt(Object *obedit, int flag) | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	Lattice *lt = obedit->data; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	BPoint *bp; | 
					
						
							|  |  |  | 	int a; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	bp = lt->editlatt->latt->def; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 	lt->editlatt->latt->actbp = LT_ACTBP_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	while (a--) { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		if (bp->hide == 0) { | 
					
						
							|  |  |  | 			bp->f1 = flag; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Lattice *lt = obedit->data; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		while (a--) { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 			if (bp->hide == 0) { | 
					
						
							| 
									
										
										
										
											2012-07-19 11:40:25 +00:00
										 |  |  | 				if (bp->f1 & SELECT) { | 
					
						
							| 
									
										
										
										
											2009-11-29 22:16:29 +00:00
										 |  |  | 					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) { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		case SEL_SELECT: | 
					
						
							|  |  |  | 			ED_setflagsLatt(obedit, 1); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SEL_DESELECT: | 
					
						
							|  |  |  | 			ED_setflagsLatt(obedit, 0); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SEL_INVERT: | 
					
						
							|  |  |  | 			bp = lt->editlatt->latt->def; | 
					
						
							|  |  |  | 			a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 			lt->editlatt->latt->actbp = LT_ACTBP_NONE; | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			while (a--) { | 
					
						
							|  |  |  | 				if (bp->hide == 0) { | 
					
						
							| 
									
										
										
										
											2012-07-19 11:40:25 +00:00
										 |  |  | 					bp->f1 ^= SELECT; | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				bp++; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +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-22 07:26:09 +00:00
										 |  |  | 	ot->name = "(De)select All"; | 
					
						
							|  |  |  | 	ot->description = "Change selection of all UVW control points"; | 
					
						
							|  |  |  | 	ot->idname = "LATTICE_OT_select_all"; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = lattice_select_all_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editlattice; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | /************************** Select Ungrouped Verts Operator *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int lattice_select_ungrouped_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt; | 
					
						
							|  |  |  | 	MDeformVert *dv; | 
					
						
							|  |  |  | 	BPoint *bp; | 
					
						
							|  |  |  | 	int a, tot; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 06:07:10 +11:00
										 |  |  | 	if (BLI_listbase_is_empty(&obedit->defbase) || lt->dvert == NULL) { | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_ERROR, "No weights/vertex groups on object"); | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!RNA_boolean_get(op->ptr, "extend")) { | 
					
						
							|  |  |  | 		ED_setflagsLatt(obedit, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dv = lt->dvert; | 
					
						
							|  |  |  | 	tot = lt->pntsu * lt->pntsv * lt->pntsw; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (a = 0, bp = lt->def; a < tot; a++, bp++, dv++) { | 
					
						
							|  |  |  | 		if (bp->hide == 0) { | 
					
						
							|  |  |  | 			if (dv->dw == NULL) { | 
					
						
							|  |  |  | 				bp->f1 |= SELECT; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LATTICE_OT_select_ungrouped(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Ungrouped"; | 
					
						
							|  |  |  | 	ot->idname = "LATTICE_OT_select_ungrouped"; | 
					
						
							|  |  |  | 	ot->description = "Select vertices without a group"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = lattice_select_ungrouped_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editlattice; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | /************************** Make Regular Operator *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (ED_operator_editlattice(C)) return 1; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	ob = CTX_data_active_object(C); | 
					
						
							|  |  |  | 	return (ob && ob->type == OB_LATTICE); | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	Lattice *lt; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (ob) { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		lt = ob->data; | 
					
						
							| 
									
										
										
										
											2012-05-05 16:03:57 +00:00
										 |  |  | 		BKE_lattice_resize(lt->editlatt->latt, lt->pntsu, lt->pntsv, lt->pntsw, NULL); | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		ob = CTX_data_active_object(C); | 
					
						
							|  |  |  | 		lt = ob->data; | 
					
						
							| 
									
										
										
										
											2012-05-05 16:03:57 +00:00
										 |  |  | 		BKE_lattice_resize(lt, lt->pntsu, lt->pntsv, lt->pntsw, NULL); | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-12-05 18:59:23 +00:00
										 |  |  | 	DAG_id_tag_update(&ob->id, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +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 */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Make Regular"; | 
					
						
							|  |  |  | 	ot->description = "Set UVW control points a uniform distance apart"; | 
					
						
							|  |  |  | 	ot->idname = "LATTICE_OT_make_regular"; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = make_regular_exec; | 
					
						
							|  |  |  | 	ot->poll = make_regular_poll; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | /************************** Flip Verts Operator *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* flipping options */ | 
					
						
							|  |  |  | typedef enum eLattice_FlipAxes { | 
					
						
							|  |  |  | 	LATTICE_FLIP_U = 0, | 
					
						
							|  |  |  | 	LATTICE_FLIP_V = 1, | 
					
						
							|  |  |  | 	LATTICE_FLIP_W = 2 | 
					
						
							|  |  |  | } eLattice_FlipAxes; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-31 14:10:01 +00:00
										 |  |  | /* Flip midpoint value so that relative distances between midpoint and neighbor-pair is maintained
 | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  |  * ! Assumes that uvw <=> xyz (i.e. axis-aligned index-axes with coordinate-axes) | 
					
						
							|  |  |  |  * - Helper for lattice_flip_exec() | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void lattice_flip_point_value(Lattice *lt, int u, int v, int w, float mid, eLattice_FlipAxes axis) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPoint *bp; | 
					
						
							|  |  |  | 	float diff; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* just the point in the middle (unpaired) */ | 
					
						
							| 
									
										
										
										
											2013-06-28 21:24:38 +00:00
										 |  |  | 	bp = <->def[BKE_lattice_index_from_uvw(lt, u, v, w)]; | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flip over axis */ | 
					
						
							|  |  |  | 	diff = mid - bp->vec[axis]; | 
					
						
							|  |  |  | 	bp->vec[axis] = mid + diff; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Swap pairs of lattice points along a specified axis
 | 
					
						
							|  |  |  |  * - Helper for lattice_flip_exec() | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void lattice_swap_point_pairs(Lattice *lt, int u, int v, int w, float mid, eLattice_FlipAxes axis) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPoint *bpA, *bpB; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	int numU = lt->pntsu; | 
					
						
							|  |  |  | 	int numV = lt->pntsv; | 
					
						
							|  |  |  | 	int numW = lt->pntsw; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	int u0 = u, u1 = u; | 
					
						
							|  |  |  | 	int v0 = v, v1 = v; | 
					
						
							|  |  |  | 	int w0 = w, w1 = w; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get pair index by just overriding the relevant pair-value
 | 
					
						
							|  |  |  | 	 * - "-1" else buffer overflow | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	switch (axis) { | 
					
						
							|  |  |  | 		case LATTICE_FLIP_U: | 
					
						
							|  |  |  | 			u1 = numU - u - 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case LATTICE_FLIP_V: | 
					
						
							|  |  |  | 			v1 = numV - v - 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case LATTICE_FLIP_W: | 
					
						
							|  |  |  | 			w1 = numW - w - 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get points to operate on */ | 
					
						
							| 
									
										
										
										
											2013-06-28 21:24:38 +00:00
										 |  |  | 	bpA = <->def[BKE_lattice_index_from_uvw(lt, u0, v0, w0)]; | 
					
						
							|  |  |  | 	bpB = <->def[BKE_lattice_index_from_uvw(lt, u1, v1, w1)]; | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* Swap all coordinates, so that flipped coordinates belong to
 | 
					
						
							|  |  |  | 	 * the indices on the correct side of the lattice. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 *   Coords:  (-2 4) |0| (3 4)   --> (3 4) |0| (-2 4)  | 
					
						
							|  |  |  | 	 *   Indices:  (0,L)     (1,R)   --> (0,L)     (1,R) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	swap_v3_v3(bpA->vec, bpB->vec); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* However, we need to mirror the coordinate values on the axis we're dealing with,
 | 
					
						
							|  |  |  | 	 * otherwise we'd have effectively only rotated the points around. If we don't do this, | 
					
						
							|  |  |  | 	 * we'd just be reimplementing the naive mirroring algorithm, which causes unwanted deforms | 
					
						
							|  |  |  | 	 * such as flipped normals, etc. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 *   Coords:  (3 4) |0| (-2 4)  --\    | 
					
						
							|  |  |  | 	 *                                 \-> (-3 4) |0| (2 4) | 
					
						
							|  |  |  | 	 *   Indices: (0,L)     (1,R)   -->     (0,L)     (1,R) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	lattice_flip_point_value(lt, u0, v0, w0, mid, axis); | 
					
						
							|  |  |  | 	lattice_flip_point_value(lt, u1, v1, w1, mid, axis); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | static int lattice_flip_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Lattice *lt; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	eLattice_FlipAxes axis = RNA_enum_get(op->ptr, "axis"); | 
					
						
							|  |  |  | 	int numU, numV, numW; | 
					
						
							|  |  |  | 	int totP; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	float mid = 0.0f; | 
					
						
							|  |  |  | 	short isOdd = 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get lattice - we need the "edit lattice" from the lattice... confusing... */ | 
					
						
							|  |  |  | 	lt = (Lattice *)obedit->data; | 
					
						
							|  |  |  | 	lt = lt->editlatt->latt; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	numU = lt->pntsu; | 
					
						
							|  |  |  | 	numV = lt->pntsv; | 
					
						
							|  |  |  | 	numW = lt->pntsw; | 
					
						
							|  |  |  | 	totP = numU * numV * numW; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* First Pass: determine midpoint - used for flipping center verts if there are odd number of points on axis */ | 
					
						
							|  |  |  | 	switch (axis) { | 
					
						
							|  |  |  | 		case LATTICE_FLIP_U: | 
					
						
							|  |  |  | 			isOdd = numU & 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case LATTICE_FLIP_V: | 
					
						
							|  |  |  | 			isOdd = numV & 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case LATTICE_FLIP_W: | 
					
						
							|  |  |  | 			isOdd = numW & 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			printf("lattice_flip(): Unknown flipping axis (%d)\n", axis); | 
					
						
							|  |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (isOdd) { | 
					
						
							|  |  |  | 		BPoint *bp; | 
					
						
							|  |  |  | 		float avgInv = 1.0f / (float)totP; | 
					
						
							|  |  |  | 		int i; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* midpoint calculation - assuming that u/v/w are axis-aligned */ | 
					
						
							|  |  |  | 		for (i = 0, bp = lt->def; i < totP; i++, bp++) { | 
					
						
							|  |  |  | 			mid += bp->vec[axis] * avgInv; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Second Pass: swap pairs of vertices per axis, assuming they are all sorted */ | 
					
						
							|  |  |  | 	switch (axis) { | 
					
						
							|  |  |  | 		case LATTICE_FLIP_U: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			int u, v, w; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			/* v/w strips - front to back, top to bottom */ | 
					
						
							|  |  |  | 			for (w = 0; w < numW; w++) { | 
					
						
							|  |  |  | 				for (v = 0; v < numV; v++) { | 
					
						
							|  |  |  | 					/* swap coordinates of pairs of vertices on u */ | 
					
						
							|  |  |  | 					for (u = 0; u < (numU / 2); u++) { | 
					
						
							|  |  |  | 						lattice_swap_point_pairs(lt, u, v, w, mid, axis); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					/* flip u-coordinate of midpoint (i.e. unpaired point on u) */ | 
					
						
							|  |  |  | 					if (isOdd) { | 
					
						
							|  |  |  | 						u = (numU / 2); | 
					
						
							|  |  |  | 						lattice_flip_point_value(lt, u, v, w, mid, axis); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-07-19 15:23:42 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		case LATTICE_FLIP_V: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			int u, v, w; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			/* u/w strips - front to back, left to right */ | 
					
						
							|  |  |  | 			for (w = 0; w < numW; w++) { | 
					
						
							|  |  |  | 				for (u = 0; u < numU; u++) { | 
					
						
							|  |  |  | 					/* swap coordinates of pairs of vertices on v */ | 
					
						
							|  |  |  | 					for (v = 0; v < (numV / 2); v++) { | 
					
						
							|  |  |  | 						lattice_swap_point_pairs(lt, u, v, w, mid, axis); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					/* flip v-coordinate of midpoint (i.e. unpaired point on v) */ | 
					
						
							|  |  |  | 					if (isOdd) { | 
					
						
							|  |  |  | 						v = (numV / 2); | 
					
						
							|  |  |  | 						lattice_flip_point_value(lt, u, v, w, mid, axis); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-07-19 15:23:42 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		case LATTICE_FLIP_W: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			int u, v, w; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			for (v = 0; v < numV; v++) { | 
					
						
							|  |  |  | 				for (u = 0; u < numU; u++) { | 
					
						
							|  |  |  | 					/* swap coordinates of pairs of vertices on w */ | 
					
						
							|  |  |  | 					for (w = 0; w < (numW / 2); w++) { | 
					
						
							|  |  |  | 						lattice_swap_point_pairs(lt, u, v, w, mid, axis); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					/* flip w-coordinate of midpoint (i.e. unpaired point on w) */ | 
					
						
							|  |  |  | 					if (isOdd) { | 
					
						
							|  |  |  | 						w = (numW / 2); | 
					
						
							|  |  |  | 						lattice_flip_point_value(lt, u, v, w, mid, axis); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-07-19 15:23:42 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2012-10-13 10:42:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		default: /* shouldn't happen, but just in case */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* updates */ | 
					
						
							|  |  |  | 	DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LATTICE_OT_flip(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static EnumPropertyItem flip_items[] = { | 
					
						
							|  |  |  | 		{LATTICE_FLIP_U, "U", 0, "U (X) Axis", ""}, | 
					
						
							|  |  |  | 		{LATTICE_FLIP_V, "V", 0, "V (Y) Axis", ""}, | 
					
						
							|  |  |  | 		{LATTICE_FLIP_W, "W", 0, "W (Z) Axis", ""}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL}}; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Flip (Distortion Free)"; | 
					
						
							|  |  |  | 	ot->description = "Mirror all control points without inverting the lattice deform"; | 
					
						
							|  |  |  | 	ot->idname = "LATTICE_OT_flip"; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editlattice; | 
					
						
							|  |  |  | 	ot->invoke = WM_menu_invoke; | 
					
						
							|  |  |  | 	ot->exec = lattice_flip_exec; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	ot->prop = RNA_def_enum(ot->srna, "axis", flip_items, LATTICE_FLIP_U, "Flip Axis", "Coordinates along this axis get flipped"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | /****************************** Mouse Selection *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | static void findnearestLattvert__doClosest(void *userData, BPoint *bp, const float screen_co[2]) | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	struct { BPoint *bp; float dist; int select; float mval_fl[2]; } *data = userData; | 
					
						
							|  |  |  | 	float dist_test = len_manhattan_v2v2(data->mval_fl, screen_co); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	if ((bp->f1 & SELECT) && data->select) | 
					
						
							|  |  |  | 		dist_test += 5.0f; | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	if (dist_test < data->dist) { | 
					
						
							|  |  |  | 		data->dist = dist_test; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-23 03:38:26 +00:00
										 |  |  | 	/* (sel == 1): selected gets a disadvantage */ | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	/* in nurb and bezt or bp the nearest is written */ | 
					
						
							|  |  |  | 	/* return 0 1 2: handlepunt */ | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	struct { BPoint *bp; float dist; int select; float mval_fl[2]; } data = {NULL}; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-11 15:34:19 +11:00
										 |  |  | 	data.dist = ED_view3d_select_dist_px(); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	data.select = sel; | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	data.mval_fl[0] = mval[0]; | 
					
						
							|  |  |  | 	data.mval_fl[1] = mval[1]; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); | 
					
						
							| 
									
										
										
										
											2012-10-10 04:03:22 +00:00
										 |  |  | 	lattice_foreachScreenVert(vc, findnearestLattvert__doClosest, &data, V3D_PROJ_TEST_CLIP_DEFAULT); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return data.bp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 23:17:44 +00:00
										 |  |  | bool mouse_lattice(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ViewContext vc; | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	BPoint *bp = NULL; | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 	Lattice *lt; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	view3d_set_viewcontext(C, &vc); | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 	lt = ((Lattice *)vc.obedit->data)->editlatt->latt; | 
					
						
							| 
									
										
										
										
											2014-04-01 11:34:00 +11:00
										 |  |  | 	bp = findnearestLattvert(&vc, mval, true); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (bp) { | 
					
						
							| 
									
										
										
										
											2012-06-05 21:54:21 +00:00
										 |  |  | 		if (extend) { | 
					
						
							|  |  |  | 			bp->f1 |= SELECT; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if (deselect) { | 
					
						
							|  |  |  | 			bp->f1 &= ~SELECT; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 		else if (toggle) { | 
					
						
							|  |  |  | 			bp->f1 ^= SELECT;  /* swap */ | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-06-05 21:54:21 +00:00
										 |  |  | 		else { | 
					
						
							|  |  |  | 			ED_setflagsLatt(vc.obedit, 0); | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			bp->f1 |= SELECT; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 		if (bp->f1 & SELECT) { | 
					
						
							|  |  |  | 			lt->actbp = bp - lt->def; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			lt->actbp = LT_ACTBP_NONE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); | 
					
						
							| 
									
										
										
										
											2009-11-24 04:59:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 23:17:44 +00:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-11-24 04:59:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 23:17:44 +00:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 	int pntsu, pntsv, pntsw, actbp; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | } 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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	UndoLattice *ult = (UndoLattice *)data; | 
					
						
							|  |  |  | 	EditLatt *editlatt = (EditLatt *)edata; | 
					
						
							|  |  |  | 	int a = editlatt->latt->pntsu * editlatt->latt->pntsv * editlatt->latt->pntsw; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	memcpy(editlatt->latt->def, ult->def, a * sizeof(BPoint)); | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 	editlatt->latt->actbp = ult->actbp; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	UndoLattice *ult = MEM_callocN(sizeof(UndoLattice), "UndoLattice"); | 
					
						
							|  |  |  | 	EditLatt *editlatt = (EditLatt *)edata; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	ult->def = MEM_dupallocN(editlatt->latt->def); | 
					
						
							|  |  |  | 	ult->pntsu = editlatt->latt->pntsu; | 
					
						
							|  |  |  | 	ult->pntsv = editlatt->latt->pntsv; | 
					
						
							|  |  |  | 	ult->pntsw = editlatt->latt->pntsw; | 
					
						
							| 
									
										
										
										
											2013-06-09 20:28:08 +00:00
										 |  |  | 	ult->actbp = editlatt->latt->actbp; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return ult; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void free_undoLatt(void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	UndoLattice *ult = (UndoLattice *)data; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (ult->def) MEM_freeN(ult->def); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 	MEM_freeN(ult); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int validate_undoLatt(void *data, void *edata) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	UndoLattice *ult = (UndoLattice *)data; | 
					
						
							|  |  |  | 	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 && | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	        ult->pntsv == editlatt->latt->pntsv && | 
					
						
							|  |  |  | 	        ult->pntsw == editlatt->latt->pntsw); | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void *get_editlatt(bContext *C) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2009-07-03 15:23:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 15:42:27 +00:00
										 |  |  | 	if (obedit && obedit->type == OB_LATTICE) { | 
					
						
							|  |  |  | 		Lattice *lt = obedit->data; | 
					
						
							| 
									
										
										
										
											2009-01-13 15:18:41 +00:00
										 |  |  | 		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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |