[Bf-blender-cvs] [d305df2] master: Transform: old todo, removing an orientation now checks all screens.

Campbell Barton noreply at git.blender.org
Mon Nov 25 00:39:22 CET 2013


Commit: d305df2226ccdf371d127d1c4f39690042f483bd
Author: Campbell Barton
Date:   Mon Nov 25 08:37:57 2013 +1100
http://developer.blender.org/rBd305df2226ccdf371d127d1c4f39690042f483bd

Transform: old todo, removing an orientation now checks all screens.

also fix for using uninitialized matrix when an out-of-range index is
set for custom orientations.

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

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/editors/transform/transform_orientations.c

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

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 3c0928d..9702b2e 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -282,6 +282,8 @@ struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype
 void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene);
 void BKE_screen_view3d_scene_sync(struct bScreen *sc);
 void BKE_screen_view3d_main_sync(ListBase *screen_lb, struct Scene *scene);
+void BKE_screen_view3d_twmode_remove(struct View3D *v3d, const int i);
+void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, struct Scene *scene, const int i);
 
 /* zoom factor conversion */
 float BKE_screen_view3d_zoom_to_fac(float camzoom);
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index c41c66e..5b1bb78 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -417,7 +417,7 @@ ScrArea *BKE_screen_find_big_area(bScreen *sc, const int spacetype, const short
 	return big;
 }
 
-void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene)
+void BKE_screen_view3d_sync(View3D *v3d, struct Scene *scene)
 {
 	int bit;
 
@@ -481,6 +481,37 @@ void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene)
 	}
 }
 
+void BKE_screen_view3d_twmode_remove(View3D *v3d, const int i)
+{
+	const int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
+	if (selected_index == i) {
+		v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global	*/
+	}
+	else if (selected_index > i) {
+		v3d->twmode--;
+	}
+}
+
+void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, Scene *scene, const int i)
+{
+	bScreen *sc;
+
+	for (sc = screen_lb->first; sc; sc = sc->id.next) {
+		if (sc->scene == scene) {
+			ScrArea *sa;
+			for (sa = sc->areabase.first; sa; sa = sa->next) {
+				SpaceLink *sl;
+				for (sl = sa->spacedata.first; sl; sl = sl->next) {
+					if (sl->spacetype == SPACE_VIEW3D) {
+						View3D *v3d = (View3D *)sl;
+						BKE_screen_view3d_twmode_remove(v3d, i);
+					}
+				}
+			}
+		}
+	}
+}
+
 /* magic zoom calculation, no idea what
  * it signifies, if you find out, tell me! -zr
  */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index ad3b0df..c7e82c1 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5944,14 +5944,6 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
 					
 					/* not very nice, but could help */
 					if ((v3d->layact & v3d->lay) == 0) v3d->layact = v3d->lay;
-					
-					/* its possible the current transform orientation has been removed */
-					if (v3d->twmode >= V3D_MANIP_CUSTOM) {
-						const int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
-						if (!BLI_findlink(&sc->scene->transform_spaces, selected_index)) {
-							v3d->twmode = V3D_MANIP_GLOBAL;
-						}
-					}
 
 					/* free render engines for now */
 					for (ar = sa->regionbase.first; ar; ar = ar->next) {
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 164ad74..1e70529 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -650,7 +650,7 @@ bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const floa
 
 struct TransformOrientation *addMatrixSpace(struct bContext *C, float mat[3][3],
                                             const char *name, const bool overwrite);
-void applyTransformOrientation(const struct bContext *C, float mat[3][3], char r_name[64]);
+bool applyTransformOrientation(const struct bContext *C, float mat[3][3], char r_name[64]);
 
 #define ORIENTATION_NONE	0
 #define ORIENTATION_NORMAL	1
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 132a464..5ac97ed 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -642,8 +642,9 @@ int calc_manipulator_stats(const bContext *C)
 			default: /* V3D_MANIP_CUSTOM */
 			{
 				float mat[3][3];
-				applyTransformOrientation(C, mat, NULL);
-				copy_m4_m3(rv3d->twmat, mat);
+				if (applyTransformOrientation(C, mat, NULL)) {
+					copy_m4_m3(rv3d->twmat, mat);
+				}
 				break;
 			}
 		}
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index 9a50c0c..c8b6144 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -26,6 +26,7 @@
 
 
 #include <string.h>
+#include <stddef.h>
 #include <ctype.h>
 
 #include "MEM_guardedalloc.h"
@@ -40,7 +41,9 @@
 #include "DNA_view3d_types.h"
 
 #include "BLI_math.h"
-#include "BLI_blenlib.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_path_util.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_action.h"
@@ -49,6 +52,8 @@
 #include "BKE_context.h"
 #include "BKE_editmesh.h"
 #include "BKE_report.h"
+#include "BKE_main.h"
+#include "BKE_screen.h"
 
 #include "BLF_translation.h"
 
@@ -349,29 +354,15 @@ TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3],
 
 void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target)
 {
-	ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
+	Scene *scene = CTX_data_scene(C);
+	ListBase *transform_spaces = &scene->transform_spaces;
 	TransformOrientation *ts;
-	int i;
-	
-	for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) {
-		if (ts == target) {
-			View3D *v3d = CTX_wm_view3d(C);
-			if (v3d) {
-				int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
-				
-				// Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D
-				if (selected_index == i) {
-					v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global	*/
-				}
-				else if (selected_index > i) {
-					v3d->twmode--;
-				}
-				
-			}
+	const int i = BLI_findindex(transform_spaces, target);
 
-			BLI_freelinkN(transform_spaces, ts);
-			break;
-		}
+	if (i != -1) {
+		Main *bmain = CTX_data_main(C);
+		BKE_screen_view3d_main_twmode_remove(&bmain->screen, scene, i);
+		BLI_freelinkN(transform_spaces, ts);
 	}
 }
 
@@ -381,36 +372,18 @@ void BIF_removeTransformOrientationIndex(bContext *C, int index)
 	TransformOrientation *ts = BLI_findlink(transform_spaces, index);
 
 	if (ts) {
-		View3D *v3d = CTX_wm_view3d(C);
-		if (v3d) {
-			int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
-			
-			// Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D
-			if (selected_index == index) {
-				v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global	*/
-			}
-			else if (selected_index > index) {
-				v3d->twmode--;
-			}
-			
-		}
-
-		BLI_freelinkN(transform_spaces, ts);
+		BIF_removeTransformOrientation(C, ts);
 	}
 }
 
 void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target)
 {
 	ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
-	View3D *v3d = CTX_wm_view3d(C);
-	TransformOrientation *ts;
-	int i;
-	
-	for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) {
-		if (ts == target) {
-			v3d->twmode = V3D_MANIP_CUSTOM + i;
-			break;
-		}
+	const int i = BLI_findindex(transform_spaces, target);
+
+	if (i != -1) {
+		View3D *v3d = CTX_wm_view3d(C);
+		v3d->twmode = V3D_MANIP_CUSTOM + i;
 	}
 }
 
@@ -427,25 +400,27 @@ int BIF_countTransformOrientation(const bContext *C)
 	return BLI_countlist(transform_spaces);
 }
 
-void applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name)
+bool applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name)
 {
-	TransformOrientation *ts;
 	View3D *v3d = CTX_wm_view3d(C);
 	int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
-	int i;
-	
-	if (selected_index >= 0) {
-		for (i = 0, ts = CTX_data_scene(C)->transform_spaces.first; ts; ts = ts->next, i++) {
-			if (selected_index == i) {
-				
-				if (r_name) {
-					BLI_strncpy(r_name, ts->name, MAX_NAME);
-				}
-				
-				copy_m3_m3(mat, ts->mat);
-				break;
-			}
+
+	ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
+	TransformOrientation *ts = BLI_findlink(transform_spaces, selected_index);
+
+	BLI_assert(selected_index >= 0);
+
+	if (ts) {
+		if (r_name) {
+			BLI_strncpy(r_name, ts->name, MAX_NAME);
 		}
+
+		copy_m3_m3(mat, ts->mat);
+		return true;
+	}
+	else {
+		/* invalid index, can happen sometimes */
+		return false;
 	}
 }
 
@@ -529,7 +504,12 @@ void initTransformOrientation(bContext *C, TransInfo *t)
 			}
 			break;
 		default: /* V3D_MANIP_CUSTOM */
-			applyTransformOrientation(C, t->spacemtx, t->spacename);
+			if (applyTransformOrientation(C, t->spacemtx, t->spacename)) {
+				/* pass */
+			}
+			else {
+				unit_m3(t->spacemtx);
+			}
 			break;
 	}
 }




More information about the Bf-blender-cvs mailing list