[Bf-blender-cvs] [e3c12bb] workspaces: Fix glitch when removing custom transform orientations

Julian Eisel noreply at git.blender.org
Thu Jan 5 16:48:00 CET 2017


Commit: e3c12bb139250b7573bd8a2fd13d564d9424c4c8
Author: Julian Eisel
Date:   Thu Jan 5 03:15:09 2017 +0100
Branches: workspaces
https://developer.blender.org/rBe3c12bb139250b7573bd8a2fd13d564d9424c4c8

Fix glitch when removing custom transform orientations

Scenes aren't stored within screens anymore, meaning we can't associate a 3D View in an inactive workspace/screen with a scene. This again means we can't identify the active transform orientation of a 3D View by its index (it might belong to a different scene) to unset it correctly  when removing it. We now additionally store a pointer in the 3D View to the active custom orientation data to identify it.

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

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/BKE_workspace.h
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/editors/transform/transform_ops.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 07f9edd..b33aa31 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -42,6 +42,7 @@ struct Panel;
 struct Scene;
 struct ScrArea;
 struct SpaceType;
+struct TransformOrientation;
 struct View3D;
 struct bContext;
 struct bContextDataResult;
@@ -307,7 +308,8 @@ unsigned int BKE_screen_view3d_layer_all(const struct bScreen *sc) ATTR_WARN_UNU
 
 void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene);
 void BKE_screen_view3d_scene_sync(struct bScreen *sc, struct Scene *scene);
-void BKE_screen_view3d_twmode_remove(struct bScreen *screen, const int twmode);
+void BKE_screen_transform_orientation_remove(const struct bScreen *screen,
+                                             const struct TransformOrientation *orientation) ATTR_NONNULL();
 void BKE_screen_gpu_fx_validate(struct GPUFXSettings *fx_settings);
 bool BKE_screen_is_fullscreen_area(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 bool BKE_screen_is_used(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
index 8c33edd..e95146b 100644
--- a/source/blender/blenkernel/BKE_workspace.h
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -28,6 +28,7 @@
 #include "BLI_compiler_attrs.h"
 
 struct bScreen;
+struct TransformOrientation;
 struct WorkSpace;
 
 typedef struct WorkSpace WorkSpace;
@@ -53,6 +54,9 @@ void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout,
 		_workspace##_next = BKE_workspace_next_get(_workspace); /* support removing workspace from list */
 #define BKE_workspace_iter_end } (void)0
 
+void BKE_workspaces_transform_orientation_remove(const ListBase *workspaces,
+                                                 const struct TransformOrientation *orientation) ATTR_NONNULL();
+
 WorkSpaceLayout *BKE_workspace_layout_find(const WorkSpace *ws, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 WorkSpaceLayout *BKE_workspace_layout_find_exec(const WorkSpace *ws, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 91f0d81..2082975 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -611,24 +611,17 @@ void BKE_screen_view3d_scene_sync(bScreen *sc, Scene *scene)
 	}
 }
 
-/**
- * TODO hrmpf... stupid issue: Removing a custom transform orientation only updates View3D orientations
- * in visible workspaces/screens. If an invisible one uses it, it keeps using the removed orientation.
- * Need to solve that somehow... Maybe store TranformOrientation * in View3D?
- */
-void BKE_screen_view3d_twmode_remove(bScreen *screen, const int twmode)
+void BKE_screen_transform_orientation_remove(const bScreen *screen, const TransformOrientation *orientation)
 {
 	for (ScrArea *area = screen->areabase.first; area; area = area->next) {
 		for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
 			if (sl->spacetype == SPACE_VIEW3D) {
 				View3D *v3d = (View3D *)sl;
-				const int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
 
-				if (selected_index == twmode) {
-					v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global	*/
-				}
-				else if (selected_index > twmode) {
-					v3d->twmode--;
+				if (v3d->custom_orientation == orientation) {
+					/* could also use v3d->custom_orientation->prev. */
+					v3d->twmode = V3D_MANIP_GLOBAL;
+					v3d->custom_orientation = NULL;
 				}
 			}
 		}
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 1e77bd5..1703326 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -30,6 +30,7 @@
 #include "BKE_library.h"
 #include "BLI_listbase.h"
 #include "BKE_main.h"
+#include "BKE_screen.h"
 #include "BKE_workspace.h"
 
 #include "DNA_object_types.h"
@@ -101,6 +102,19 @@ void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout,
 /* -------------------------------------------------------------------- */
 /* General Utils */
 
+void BKE_workspaces_transform_orientation_remove(const ListBase *workspaces, const TransformOrientation *orientation)
+{
+	BKE_workspace_iter_begin(workspace, workspaces->first)
+	{
+		BKE_workspace_layout_iter_begin(layout, workspace->layouts.first)
+		{
+			BKE_screen_transform_orientation_remove(BKE_workspace_layout_screen_get(layout), orientation);
+		}
+		BKE_workspace_layout_iter_end;
+	}
+	BKE_workspace_iter_end;
+}
+
 /**
  * Checks if \a screen is already used within any workspace. A screen should never be assigned to multiple
  * WorkSpaceLayouts, but that should be ensured outside of the BKE_workspace module and without such checks.
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fd5990b..67f59fe 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5918,7 +5918,33 @@ static void direct_link_view_settings(FileData *fd, ColorManagedViewSettings *vi
 		direct_link_curvemapping(fd, view_settings->curve_mapping);
 }
 
-static void direct_link_scene(FileData *fd, Scene *sce)
+/**
+ * bScreen data may use pointers to Scene data. bScreens are however read before Scenes, meaning
+ * FileData.datamap doesn't contain the Scene data when reading bScreens. This function should
+ * be called during Scene direct linking to update needed pointers within bScreen data.
+ *
+ * Maybe we could change read order so that screens are read after scene. But guess that
+ * would be asking for trouble. Depending on the write/read order sounds ugly anyway...
+ * -- Julian
+ */
+static void direct_link_scene_update_screens(FileData *fd, const ListBase *screens)
+{
+	for (bScreen *screen = screens->first; screen; screen = screen->id.next) {
+		for (ScrArea *area = screen->areabase.first; area; area = area->next) {
+			for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
+				if (sl->spacetype == SPACE_VIEW3D) {
+					View3D *v3d = (View3D *)sl;
+
+					if (v3d->custom_orientation) {
+						v3d->custom_orientation = newdataadr(fd, v3d->custom_orientation);
+					}
+				}
+			}
+		}
+	}
+}
+
+static void direct_link_scene(FileData *fd, Scene *sce, Main *bmain)
 {
 	Editing *ed;
 	Sequence *seq;
@@ -6167,6 +6193,8 @@ static void direct_link_scene(FileData *fd, Scene *sce)
 	sce->preview = direct_link_preview_image(fd, sce->preview);
 
 	direct_link_curvemapping(fd, &sce->r.mblur_shutter_curve);
+
+	direct_link_scene_update_screens(fd, &bmain->screen);
 }
 
 /* ************ READ WM ***************** */
@@ -7098,7 +7126,9 @@ static bool direct_link_screen(FileData *fd, bScreen *sc)
 			if (sl->spacetype == SPACE_VIEW3D) {
 				View3D *v3d= (View3D*) sl;
 				BGpic *bgpic;
-				
+
+				/* v3d->custom_orientation will be updated later, see direct_link_scene_update_screens */
+
 				v3d->flag |= V3D_INVALID_BACKBUF;
 				
 				link_list(fd, &v3d->bgpicbase);
@@ -8201,7 +8231,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
 			wrong_id = direct_link_screen(fd, (bScreen *)id);
 			break;
 		case ID_SCE:
-			direct_link_scene(fd, (Scene *)id);
+			direct_link_scene(fd, (Scene *)id, main);
 			break;
 		case ID_OB:
 			direct_link_object(fd, (Object *)id);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 4f0f15f..227ff37 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3056,6 +3056,10 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
 					View3D *v3d = (View3D *)sl;
 					BGpic *bgpic;
 					writestruct(wd, DATA, View3D, 1, v3d);
+
+					/* Don't write data of custom_orientation pointer here, scene already writes it. We only
+					 * have to update the pointer when reading (see direct_link_scene_update_screens) */
+
 					for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
 						writestruct(wd, DATA, BGpic, 1, bgpic);
 					}
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index ebd2a3d..be62830 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -123,7 +123,6 @@ struct ReportList;
 
 void BIF_clearTransformOrientation(struct bContext *C);
 void BIF_removeTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
-void BIF_removeTransformOrientationIndex(struct bContext *C, int index);
 void BIF_createTransformOrientation(struct bContext *C, struct ReportList *reports,
                                     const char *name, const bool use_view,
                                     const bool activate, const bool overwrite);
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index a59f9dc..73fb34d 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -784,7 +784,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);
-bool applyTransformOrientation(const struct bContext *C, float mat[3][3], char r_name[64], int index);
+bool applyTransformOrientation(const struct TransformOrientation *ts, float r_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 e1abf34..08906ed 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -663,7 +663,7 @@ static int calc_manipulator_stats(const bContext *C)
 			default: /* V3D_MA

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list