Commit: 5743a6e36458874be1fe992a361ce493edbee5a4
Author: Campbell Barton
Date:   Wed Nov 20 02:40:29 2013 +1100
http://developer.blender.org/rB5743a6e36458874be1fe992a361ce493edbee5a4

Code Cleanup: move trans-verts out of snap code into their own file.

Developer Note:
* minmax & centroid was being calculated when creating trans-verts but never 
used.
* static vars removed, replace with TransVertStore stack var.

===================================================================

A       source/blender/editors/include/ED_transverts.h
M       source/blender/editors/space_view3d/view3d_snap.c
M       source/blender/editors/util/CMakeLists.txt
A       source/blender/editors/util/ed_transverts.c

===================================================================

diff --git a/source/blender/editors/include/ED_transverts.h 
b/source/blender/editors/include/ED_transverts.h
new file mode 100644
index 0000000..a82e54e
--- /dev/null
+++ b/source/blender/editors/include/ED_transverts.h
@@ -0,0 +1,70 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file ED_transverts.h
+ *  \ingroup editors
+ */
+
+#ifndef __ED_TRANSVERTS_H__
+#define __ED_TRANSVERTS_H__
+
+struct Object;
+
+typedef struct TransVert {
+       float *loc;
+       float oldloc[3], maploc[3];
+       float *val, oldval;
+       int flag;
+} TransVert;
+
+typedef struct TransVertStore {
+       struct TransVert *transverts;
+       int transverts_tot;
+} TransVertStore;
+
+void ED_transverts_create_from_obedit(TransVertStore *tvs, struct Object 
*obedit, int mode);
+void ED_transverts_update_obedit(TransVertStore *tvs, struct Object *obedit);
+void ED_transverts_free(TransVertStore *tvs);
+bool ED_transverts_check_obedit(Object *obedit);
+
+/* currently only used for bmesh index values */
+enum {
+       TM_INDEX_ON      =  1,  /* tag to make trans verts */
+       TM_INDEX_OFF     =  0,  /* don't make verts */
+       TM_INDEX_SKIP    = -1   /* dont make verts (when the index values point 
to trans-verts) */
+};
+
+/* mode flags: */
+enum {
+       TM_ALL_JOINTS      = 1, /* all joints (for bones only) */
+       TM_SKIP_HANDLES    = 2  /* skip handles when control point is selected 
(for curves only) */
+};
+
+
+              /* SELECT == (1 << 0) */
+#define TX_VERT_USE_MAPLOC (1 << 1)
+
+#endif  /* __ED_TRANSVERTS_H__ */
diff --git a/source/blender/editors/space_view3d/view3d_snap.c 
b/source/blender/editors/space_view3d/view3d_snap.c
index 34896eb..2545861 100644
--- a/source/blender/editors/space_view3d/view3d_snap.c
+++ b/source/blender/editors/space_view3d/view3d_snap.c
@@ -30,35 +30,21 @@
  */
 
 
-#include <math.h>
-#include <string.h>
-
-#include "MEM_guardedalloc.h"
-
 #include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
-#include "DNA_lattice_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meta_types.h"
-#include "DNA_scene_types.h"
 #include "DNA_object_types.h"
 
 #include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_linklist.h"
 #include "BLI_utildefines.h"
+#include "BLI_math.h"
 
 #include "BKE_armature.h"
 #include "BKE_context.h"
-#include "BKE_curve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_lattice.h"
-#include "BKE_main.h"
 #include "BKE_mball.h"
 #include "BKE_object.h"
 #include "BKE_editmesh.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_scene.h"
 #include "BKE_tracking.h"
 
 #include "WM_api.h"
@@ -67,468 +53,14 @@
 #include "RNA_access.h"
 #include "RNA_define.h"
 
-#include "ED_armature.h"
-#include "ED_mesh.h"
+#include "ED_transverts.h"
 #include "ED_keyframing.h"
 #include "ED_screen.h"
-#include "ED_curve.h" /* for curve_editnurbs */
 
 #include "view3d_intern.h"
 
-/* ************************************************** */
-/* ********************* old transform stuff ******** */
-/* *********** will get replaced with new transform * */
-/* ************************************************** */
-
 static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]);
 
-typedef struct TransVert {
-       float *loc;
-       float oldloc[3], maploc[3];
-       float *val, oldval;
-       int flag;
-} TransVert;
-
-              /* SELECT == (1 << 0) */
-#define TX_VERT_USE_MAPLOC (1 << 1)
-
-static TransVert *transvmain = NULL;
-static int tottrans = 0;
-
-/* copied from editobject.c, now uses (almost) proper depgraph */
-static void special_transvert_update(Object *obedit)
-{
-       if (obedit) {
-               DAG_id_tag_update(obedit->data, 0);
-               
-               if (obedit->type == OB_MESH) {
-                       BMEditMesh *em = BKE_editmesh_from_object(obedit);
-                       BM_mesh_normals_update(em->bm);
-               }
-               else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
-                       Curve *cu = obedit->data;
-                       ListBase *nurbs = BKE_curve_editNurbs_get(cu);
-                       Nurb *nu = nurbs->first;
-
-                       while (nu) {
-                               /* keep handles' vectors unchanged */
-                               if (nu->bezt) {
-                                       int a = nu->pntsu;
-                                       TransVert *tv = transvmain;
-                                       BezTriple *bezt = nu->bezt;
-
-                                       while (a--) {
-                                               if (bezt->f1 & SELECT) tv++;
-
-                                               if (bezt->f2 & SELECT) {
-                                                       float v[3];
-
-                                                       if (bezt->f1 & SELECT) {
-                                                               sub_v3_v3v3(v, 
(tv - 1)->oldloc, tv->oldloc);
-                                                               
add_v3_v3v3(bezt->vec[0], bezt->vec[1], v);
-                                                       }
-
-                                                       if (bezt->f3 & SELECT) {
-                                                               sub_v3_v3v3(v, 
(tv + 1)->oldloc, tv->oldloc);
-                                                               
add_v3_v3v3(bezt->vec[2], bezt->vec[1], v);
-                                                       }
-
-                                                       tv++;
-                                               }
-
-                                               if (bezt->f3 & SELECT) tv++;
-
-                                               bezt++;
-                                       }
-                               }
-
-                               BKE_nurb_test2D(nu);
-                               BKE_nurb_handles_test(nu, true); /* test for 
bezier too */
-                               nu = nu->next;
-                       }
-               }
-               else if (obedit->type == OB_ARMATURE) {
-                       bArmature *arm = obedit->data;
-                       EditBone *ebo;
-                       TransVert *tv = transvmain;
-                       int a = 0;
-                       
-                       /* Ensure all bone tails are correctly adjusted */
-                       for (ebo = arm->edbo->first; ebo; ebo = ebo->next) {
-                               /* adjust tip if both ends selected */
-                               if ((ebo->flag & BONE_ROOTSEL) && (ebo->flag & 
BONE_TIPSEL)) {
-                                       if (tv) {
-                                               float diffvec[3];
-                                               
-                                               sub_v3_v3v3(diffvec, tv->loc, 
tv->oldloc);
-                                               add_v3_v3(ebo->tail, diffvec);
-                                               
-                                               a++;
-                                               if (a < tottrans) tv++;
-                                       }
-                               }
-                       }
-                       
-                       /* Ensure all bones are correctly adjusted */
-                       for (ebo = arm->edbo->first; ebo; ebo = ebo->next) {
-                               if ((ebo->flag & BONE_CONNECTED) && 
ebo->parent) {
-                                       /* If this bone has a parent tip that 
has been moved */
-                                       if (ebo->parent->flag & BONE_TIPSEL) {
-                                               copy_v3_v3(ebo->head, 
ebo->parent->tail);
-                                       }
-                                       /* If this bone has a parent tip that 
has NOT been moved */
-                                       else {
-                                               copy_v3_v3(ebo->parent->tail, 
ebo->head);
-                                       }
-                               }
-                       }
-                       if (arm->flag & ARM_MIRROR_EDIT)
-                               transform_armature_mirror_update(obedit);
-               }
-               else if (obedit->type == OB_LATTICE) {
-                       Lattice *lt = obedit->data;
-                       
-                       if (lt->editlatt->latt->flag & LT_OUTSIDE)
-                               outside_lattice(lt->editlatt->latt);
-               }
-       }
-}
-
-/* currently only used for bmesh index values */
-enum {
-       TM_INDEX_ON      =  1,  /* tag to make trans verts */
-       TM_INDEX_OFF     =  0,  /* don't make verts */
-       TM_INDEX_SKIP    = -1   /* dont make verts (when the index values point 
to trans-verts) */
-};
-
-/* copied from editobject.c, needs to be replaced with new transform code 
still */
-/* mode flags: */
-enum {
-       TM_ALL_JOINTS      = 1, /* all joints (for bones only) */
-       TM_SKIP_HANDLES    = 2  /* skip handles when control point is selected 
(for curves only) */
-};
-
-static void set_mapped_co(void *vuserdata, int index, const float co[3],
-                          const float UNUSED(no[3]), const short 
UNUSED(no_s[3]))
-{
-       void **userdata = vuserdata;
-       BMEditMesh *em = userdata[0];
-       TransVert *tv = userdata[1];
-       BMVert *eve = BM_vert_at_index(em->bm, index);
-       
-       if (BM_elem_index_get(eve) != TM_INDEX_SKIP) {
-               tv = &tv[BM_elem_index_get(eve)];
-
-               /* be clever, get the closest vertex to the original,
-                * behaves most logically when the mirror modifier is used for 
eg [#33051]*/
-               if ((tv->flag & TX_VERT_USE_MAPLOC) == 0) {
-                       /* first time */
-                       copy_v3_v3(tv->maploc, co);
-                       tv->flag |= TX_VERT_USE_MAPLOC;
-               }
-               else {
-                       /* find best location to use */
-                       if (len_squared_v3v3(eve->co, co) < 
len_squared_v3v3(eve->co, tv->maploc)) {
-                               copy_v3_v3(tv->maploc, co);
-                       }
-               }
-       }
-}
-
-static void make_trans_verts(Object *obedit, float min[3], float max[3], int 
mode)
-{
-       Nurb *nu;
-       BezTriple *bezt;
-       BPoint *bp;
-       TransVert *tv = NULL;
-       MetaElem *ml;
-       BMVert *eve;
-       EditBone    *ebo;
-       float total, center[3], centroid[3];
-       int a;
-
-       tottrans = 0; /* global! */
-
-       INIT_MINMAX(min, max);
-       zero_v3(centroid);
-       
-       if (obedit->type == OB_MESH) {
-               BMEditMesh *em = BKE_editmesh_from_object(obedit);
-               BMesh *bm = em->bm;
-               BMIter iter;
-               void *userdata[2] = {em, NULL};
-               /*int proptrans = 0; */ /*UNUSED*/
-               
-               /* abuses vertex index all over, set, just set dirty here,
-                * perhaps this could use its own array instead? - campbell */
-
-               /* transform now requires awareness for select mode, so we tag 
the f1 flags in verts */
-               tottrans = 0;
-               if (em->selectmode & SCE_SELECT_VERTEX) {
-                       BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
-                               if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && 
BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
-                                       BM_elem_index_set(eve, TM_INDEX_ON); /* 
set_dirty! */
-                                       tottrans++;
-                               }
-                               else {
-                                       BM_elem_index_set(eve, TM_INDEX_OFF);  
/* set_dirty! */
-                               }
-                       }
-               }
-               else if (em->selectmode & SCE_SELECT_EDGE) {
-                       BMEdge *eed;
-
-                       BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
-                               BM_elem_index_set(eve, TM_INDEX_OFF);  /* 
set_dirty! */
-                       }
-
-                       BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
-                               if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && 
BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
-                                       BM_elem_index_set(eed->v1, 
TM_INDEX_ON);  /* set_dirty! */
-                                       BM_elem_index_set(eed->v2, 
TM_INDEX_ON);  /* set_dirty! */
-                               }
-                       }
-
-                       BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
-                               if (BM_elem_index_get(eve) == TM_INDEX_ON) 
tottrans++;
-                       }
-               }
-               else {
-                       BMFace *efa;
-
-                       BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
-                               BM_elem_index_set(eve, TM_INDEX_OFF);  /* 
set_dirty! */
-                       }
-
-                       BM_ITER_MESH (efa, &ite

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to