Move custom transform orientations to workspace

This commit moves the list of transform orientations from scenes to workspaces.
Main reasons for this are:
* Transform orientations are UI data and should not be stored in the scene.
* Introducion of workspaces caused some (expected) glitches with transform orientations. Mainly when removing one.
* Improves code.

More technically speaking, this commit does:
* Move list of custom transform orientations from Scene to WorkSpace struct.
* Store active transform orientation index separate from View3D.twmode (twmode can only be set to preprocessor defined values now).
* Display custom transform orientation name in header when transforming in it (used to show "global" which isn't really correct).
This commit is contained in:
Julian Eisel 2017-06-01 20:41:18 +02:00
parent 7f564d74f9
commit 46fc0bb87e
25 changed files with 304 additions and 193 deletions

View File

@ -42,6 +42,7 @@ struct Panel;
struct Scene;
struct ScrArea;
struct SpaceType;
struct TransformOrientation;
struct View3D;
struct bContext;
struct bContextDataResult;
@ -53,6 +54,7 @@ struct wmManipulatorMap;
struct wmNotifier;
struct wmWindow;
struct wmWindowManager;
struct WorkSpace;
struct GPUFXSettings;
#include "BLI_compiler_attrs.h"
@ -309,8 +311,9 @@ 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 View3D *v3d, const int i);
void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, struct Scene *scene, const int i);
void BKE_screen_transform_orientation_remove(
const struct bScreen *screen, const struct WorkSpace *workspace,
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();

View File

@ -28,6 +28,7 @@
#include "BLI_compiler_attrs.h"
struct bScreen;
struct TransformOrientation;
typedef struct WorkSpace WorkSpace;
typedef struct WorkSpaceInstanceHook WorkSpaceInstanceHook;
@ -66,11 +67,18 @@ void BKE_workspace_layout_remove(
/* -------------------------------------------------------------------- */
/* General Utils */
void BKE_workspace_transform_orientation_remove(
WorkSpace *workspace, struct TransformOrientation *orientation) ATTR_NONNULL();
struct TransformOrientation *BKE_workspace_transform_orientation_find(
const WorkSpace *workspace, const int index) ATTR_NONNULL();
int BKE_workspace_transform_orientation_get_index(
const WorkSpace *workspace, const struct TransformOrientation *orientation) ATTR_NONNULL();
WorkSpaceLayout *BKE_workspace_layout_find(
const WorkSpace *workspace, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
WorkSpaceLayout *BKE_workspace_layout_find_global(
const struct Main *bmain, const struct bScreen *screen,
WorkSpace **r_workspace) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT;
WorkSpace **r_workspace) ATTR_NONNULL(1, 2);
WorkSpaceLayout *BKE_workspace_layout_iter_circular(
const WorkSpace *workspace, WorkSpaceLayout *start,
@ -95,6 +103,7 @@ enum ObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace) GETTER
#ifdef USE_WORKSPACE_MODE
void BKE_workspace_object_mode_set(WorkSpace *workspace, const enum ObjectMode mode) SETTER_ATTRS;
#endif
struct ListBase *BKE_workspace_transform_orientations_get(WorkSpace *workspace) GETTER_ATTRS;
struct SceneLayer *BKE_workspace_render_layer_get(const WorkSpace *workspace) GETTER_ATTRS;
void BKE_workspace_render_layer_set(WorkSpace *workspace, struct SceneLayer *layer) SETTER_ATTRS;
struct ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) GETTER_ATTRS;

View File

@ -261,7 +261,6 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
scen->rigidbody_world = BKE_rigidbody_world_copy(sce->rigidbody_world);
BLI_duplicatelist(&(scen->markers), &(sce->markers));
BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces));
BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers));
BLI_duplicatelist(&(scen->r.views), &(sce->r.views));
BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets));
@ -534,10 +533,9 @@ void BKE_scene_free(Scene *sce)
}
BLI_freelistN(&sce->markers);
BLI_freelistN(&sce->transform_spaces);
BLI_freelistN(&sce->r.layers);
BLI_freelistN(&sce->r.views);
if (sce->toolsettings) {
if (sce->toolsettings->vpaint) {
BKE_paint_free(&sce->toolsettings->vpaint->paint);

View File

@ -53,6 +53,7 @@
#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_screen.h"
#include "BKE_workspace.h"
/* ************ Spacetype/regiontype handling ************** */
@ -611,33 +612,20 @@ void BKE_screen_view3d_scene_sync(bScreen *sc, Scene *scene)
}
}
/* XXX apply D2687 */
void BKE_screen_view3d_twmode_remove(View3D *v3d, const int i)
void BKE_screen_transform_orientation_remove(
const bScreen *screen, const WorkSpace *workspace, const TransformOrientation *orientation)
{
const int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
if (selected_index == i) {
v3d->twmode = V3D_MANIP_GLOBAL;
}
else if (selected_index > i) {
v3d->twmode--;
}
}
const int orientation_index = BKE_workspace_transform_orientation_get_index(workspace, orientation);
/* XXX apply D2687 */
void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, Scene *scene, const int i)
{
bScreen *sc;
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;
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);
}
if (v3d->custom_orientation_index == orientation_index) {
/* could also use orientation_index-- */
v3d->twmode = V3D_MANIP_GLOBAL;
v3d->custom_orientation_index = -1;
}
}
}

View File

@ -35,6 +35,7 @@
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_screen.h"
#include "BKE_workspace.h"
#include "DNA_object_types.h"
@ -150,6 +151,7 @@ void BKE_workspace_free(WorkSpace *workspace)
workspace_relation_remove(&workspace->hook_layout_relations, relation);
}
BLI_freelistN(&workspace->layouts);
BLI_freelistN(&workspace->transform_orientations);
}
void BKE_workspace_remove(Main *bmain, WorkSpace *workspace)
@ -223,6 +225,31 @@ void BKE_workspace_layout_remove(
/* -------------------------------------------------------------------- */
/* General Utils */
void BKE_workspace_transform_orientation_remove(
WorkSpace *workspace, TransformOrientation *orientation)
{
for (WorkSpaceLayout *layout = workspace->layouts.first; layout; layout = layout->next) {
BKE_screen_transform_orientation_remove(BKE_workspace_layout_screen_get(layout), workspace, orientation);
}
BLI_freelinkN(&workspace->transform_orientations, orientation);
}
TransformOrientation *BKE_workspace_transform_orientation_find(
const WorkSpace *workspace, const int index)
{
return BLI_findlink(&workspace->transform_orientations, index);
}
/**
* \return the index that \a orientation has within \a workspace's transform-orientation list or -1 if not found.
*/
int BKE_workspace_transform_orientation_get_index(
const WorkSpace *workspace, const TransformOrientation *orientation)
{
return BLI_findindex(&workspace->transform_orientations, orientation);
}
WorkSpaceLayout *BKE_workspace_layout_find(
const WorkSpace *workspace, const bScreen *screen)
{
@ -240,6 +267,7 @@ WorkSpaceLayout *BKE_workspace_layout_find(
/**
* Find the layout for \a screen without knowing which workspace to look in.
* Can also be used to find the workspace that contains \a screen.
*
* \param r_workspace: Optionally return the workspace that contains the looked up layout (if found).
*/
@ -353,6 +381,11 @@ void BKE_workspace_object_mode_set(WorkSpace *workspace, const ObjectMode mode)
}
#endif
ListBase *BKE_workspace_transform_orientations_get(WorkSpace *workspace)
{
return &workspace->transform_orientations;
}
SceneLayer *BKE_workspace_render_layer_get(const WorkSpace *workspace)
{
return workspace->render_layer;

View File

@ -2820,6 +2820,7 @@ static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main
{
link_list(fd, BKE_workspace_layouts_get(workspace));
link_list(fd, &workspace->hook_layout_relations);
link_list(fd, BKE_workspace_transform_orientations_get(workspace));
for (WorkSpaceDataRelation *relation = workspace->hook_layout_relations.first;
relation;
@ -2835,7 +2836,7 @@ static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main
BKE_workspace_render_layer_set(workspace, NULL);
}
/* Same issue/fix as in direct_link_scene_update_screen_data: Can't read workspace data
/* Same issue/fix as in direct_link_workspace_link_scene_data: Can't read workspace data
* when reading windows, so have to update windows after/when reading workspaces. */
for (wmWindowManager *wm = main->wm.first; wm; wm = wm->id.next) {
for (wmWindow *win = wm->windows.first; win; win = win->next) {
@ -6057,7 +6058,10 @@ static void direct_link_layer_collections(FileData *fd, ListBase *lb)
}
}
static void direct_link_scene_update_screen_data(
/**
* Workspaces store a render layer pointer which can only be read after scene is read.
*/
static void direct_link_workspace_link_scene_data(
FileData *fd, const Scene *scene, const ListBase *workspaces)
{
for (WorkSpace *workspace = workspaces->first; workspace; workspace = workspace->id.next) {
@ -6285,7 +6289,7 @@ static void direct_link_scene(FileData *fd, Scene *sce, Main *bmain)
}
link_list(fd, &(sce->markers));
link_list(fd, &(sce->transform_spaces));
link_list(fd, &(sce->transform_spaces)); /* only for old files */
link_list(fd, &(sce->r.layers));
link_list(fd, &(sce->r.views));
@ -6371,7 +6375,7 @@ static void direct_link_scene(FileData *fd, Scene *sce, Main *bmain)
BKE_layer_collection_engine_settings_validate_scene(sce);
BKE_scene_layer_engine_settings_validate_scene(sce);
direct_link_scene_update_screen_data(fd, sce, &bmain->workspaces);
direct_link_workspace_link_scene_data(fd, sce, &bmain->workspaces);
}
/* ************ READ WM ***************** */

View File

@ -36,6 +36,7 @@
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_view3d_types.h"
#include "DNA_genfile.h"
#include "BKE_collection.h"
@ -77,6 +78,7 @@ static void do_version_workspaces_create_from_screens(Main *bmain)
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
const bScreen *screen_parent = screen_parent_find(screen);
WorkSpace *workspace;
ListBase *transform_orientations;
if (screen_parent) {
/* fullscreen with "Back to Previous" option, don't create
@ -89,6 +91,9 @@ static void do_version_workspaces_create_from_screens(Main *bmain)
}
BKE_workspace_layout_add(workspace, screen, screen->id.name + 2);
BKE_workspace_render_layer_set(workspace, screen->scene->render_layers.first);
transform_orientations = BKE_workspace_transform_orientations_get(workspace);
BLI_duplicatelist(transform_orientations, &screen->scene->transform_spaces);
}
}
@ -129,6 +134,7 @@ static void do_version_workspaces_after_lib_link(Main *bmain)
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
/* Deprecated from now on! */
BLI_freelistN(&screen->scene->transform_spaces);
screen->scene = NULL;
}
}
@ -373,5 +379,21 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
if (!DNA_struct_elem_find(fd->filesdna, "View3D", "short", "custom_orientation_index")) {
for (bScreen *screen = main->screen.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->twmode >= V3D_MANIP_CUSTOM) {
v3d->custom_orientation_index = v3d->twmode - V3D_MANIP_CUSTOM;
v3d->twmode = V3D_MANIP_CUSTOM;
}
}
}
}
}
}
}
}

View File

@ -2754,11 +2754,6 @@ static void write_scene(WriteData *wd, Scene *sce)
writestruct(wd, DATA, TimeMarker, 1, marker);
}
/* writing dynamic list of TransformOrientations to the blend file */
for (TransformOrientation *ts = sce->transform_spaces.first; ts; ts = ts->next) {
writestruct(wd, DATA, TransformOrientation, 1, ts);
}
for (SceneRenderLayer *srl = sce->r.layers.first; srl; srl = srl->next) {
writestruct(wd, DATA, SceneRenderLayer, 1, srl);
if (srl->prop) {
@ -3754,10 +3749,12 @@ static void write_cachefile(WriteData *wd, CacheFile *cache_file)
static void write_workspace(WriteData *wd, WorkSpace *workspace)
{
ListBase *layouts = BKE_workspace_layouts_get(workspace);
ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace);
writestruct(wd, ID_WS, WorkSpace, 1, workspace);
writelist(wd, DATA, WorkSpaceLayout, layouts);
writelist(wd, DATA, WorkSpaceDataRelation, &workspace->hook_layout_relations);
writelist(wd, DATA, TransformOrientation, transform_orientations);
}
/* Keep it last of write_foodata functions. */

View File

@ -43,6 +43,7 @@ struct wmEvent;
struct wmKeyConfig;
struct wmKeyMap;
struct wmOperatorType;
struct WorkSpace;
struct Main;
struct SnapObjectContext;
struct SnapObjectParams;
@ -130,7 +131,7 @@ void BIF_createTransformOrientation(struct bContext *C, struct ReportList *repor
const char *name, const bool use_view,
const bool activate, const bool overwrite);
void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
void BIF_selectTransformOrientationValue(struct bContext *C, int orientation);
void BIF_selectTransformOrientationValue(struct View3D *v3d, int orientation);
void ED_getTransformOrientationMatrix(const struct bContext *C, float orientation_mat[3][3], const short around);

View File

@ -216,10 +216,13 @@ WorkSpace *ED_workspace_duplicate(
WorkSpace *workspace_new = ED_workspace_add(
bmain, workspace_old->id.name + 2,
BKE_workspace_render_layer_get(workspace_old));
ListBase *transform_orientations_old = BKE_workspace_transform_orientations_get(workspace_old);
ListBase *transform_orientations_new = BKE_workspace_transform_orientations_get(workspace_new);
#ifdef USE_WORKSPACE_MODE
BKE_workspace_object_mode_set(workspace_new, BKE_workspace_object_mode_get(workspace_old));
#endif
BLI_duplicatelist(transform_orientations_new, transform_orientations_old);
for (WorkSpaceLayout *layout_old = layouts_old->first; layout_old; layout_old = layout_old->next) {
WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(workspace_new, layout_old, win);

View File

@ -63,6 +63,7 @@
#include "BKE_unit.h"
#include "BKE_mask.h"
#include "BKE_report.h"
#include "BKE_workspace.h"
#include "BIF_glutil.h"
@ -2013,6 +2014,8 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
View3D *v3d = t->view;
v3d->twmode = t->current_orientation;
BLI_assert(BKE_workspace_transform_orientation_get_index(CTX_wm_workspace(C), t->custom_orientation)
== v3d->custom_orientation_index);
}
}
}
@ -2032,15 +2035,20 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
}
if ((prop = RNA_struct_find_property(op->ptr, "constraint_axis"))) {
/* constraint orientation can be global, event if user selects something else
* so use the orientation in the constraint if set
* */
if (t->con.mode & CON_APPLY) {
RNA_enum_set(op->ptr, "constraint_orientation", t->con.orientation);
}
else {
RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
/* constraint orientation can be global, even if user selects something else
* so use the orientation in the constraint if set */
short orientation = (t->con.mode & CON_APPLY) ? t->con.orientation : t->current_orientation;
if (orientation == V3D_MANIP_CUSTOM) {
WorkSpace *workspace = CTX_wm_workspace(C);
const int custom_orientation_index = BKE_workspace_transform_orientation_get_index(
workspace, t->custom_orientation);
/* Maybe we need a t->con.custom_orientation? Seems like it would always match t->custom_orientation. */
orientation = V3D_MANIP_CUSTOM + custom_orientation_index;
BLI_assert(orientation >= V3D_MANIP_CUSTOM);
}
RNA_enum_set(op->ptr, "constraint_orientation", orientation);
if (t->con.mode & CON_APPLY) {
if (t->con.mode & CON_AXIS0) {

View File

@ -447,6 +447,7 @@ typedef struct TransInfo {
short launch_event; /* event type used to launch transform */
short current_orientation;
TransformOrientation *custom_orientation; /* this gets used when current_orientation is V3D_MANIP_CUSTOM */
short twtype; /* backup from view3d, to restore on end */
short prop_mode;
@ -788,7 +789,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

View File

@ -653,7 +653,7 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[])
*/
void setUserConstraint(TransInfo *t, short orientation, int mode, const char ftext[])
{
char text[40];
char text[256];
switch (orientation) {
case V3D_MANIP_GLOBAL:
@ -685,10 +685,15 @@ void setUserConstraint(TransInfo *t, short orientation, int mode, const char fte
BLI_snprintf(text, sizeof(text), ftext, IFACE_("gimbal"));
setConstraint(t, t->spacemtx, mode, text);
break;
default: /* V3D_MANIP_CUSTOM */
BLI_snprintf(text, sizeof(text), ftext, t->spacename);
case V3D_MANIP_CUSTOM:
{
char orientation_str[128];
BLI_snprintf(orientation_str, sizeof(orientation_str), "%s \"%s\"",
IFACE_("custom orientation"), t->custom_orientation->name);
BLI_snprintf(text, sizeof(text), ftext, orientation_str);
setConstraint(t, t->spacemtx, mode, text);
break;
}
}
t->con.orientation = orientation;

View File

@ -83,6 +83,7 @@
#include "BKE_tracking.h"
#include "BKE_mask.h"
#include "BKE_utildefines.h"
#include "BKE_workspace.h"
#include "ED_anim_api.h"
#include "ED_armature.h"
@ -1242,6 +1243,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
t->current_orientation = v3d->twmode;
t->custom_orientation = BKE_workspace_transform_orientation_find(
CTX_wm_workspace(C), v3d->custom_orientation_index);
/* exceptional case */
if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
@ -1332,13 +1335,24 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
if (op && ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
RNA_property_is_set(op->ptr, prop)))
{
t->current_orientation = RNA_property_enum_get(op->ptr, prop);
short orientation = RNA_property_enum_get(op->ptr, prop);
TransformOrientation *custom_orientation = NULL;
if (t->current_orientation >= V3D_MANIP_CUSTOM + BIF_countTransformOrientation(C)) {
t->current_orientation = V3D_MANIP_GLOBAL;
if (orientation >= V3D_MANIP_CUSTOM) {
if (orientation >= V3D_MANIP_CUSTOM + BIF_countTransformOrientation(C)) {
orientation = V3D_MANIP_GLOBAL;
}
else {
custom_orientation = BKE_workspace_transform_orientation_find(
CTX_wm_workspace(C), orientation - V3D_MANIP_CUSTOM);
orientation = V3D_MANIP_CUSTOM;
}
}
t->current_orientation = orientation;
t->custom_orientation = custom_orientation;
}
if (op && ((prop = RNA_struct_find_property(op->ptr, "release_confirm")) &&
RNA_property_is_set(op->ptr, prop)))
{

View File

@ -60,6 +60,7 @@
#include "BKE_editmesh.h"
#include "BKE_lattice.h"
#include "BKE_gpencil.h"
#include "BKE_workspace.h"
#include "BIF_gl.h"
@ -986,10 +987,13 @@ static int calc_manipulator_stats(const bContext *C)
copy_m4_m3(rv3d->twmat, mat);
break;
}
default: /* V3D_MANIP_CUSTOM */
case V3D_MANIP_CUSTOM:
{
TransformOrientation *custom_orientation = BKE_workspace_transform_orientation_find(
CTX_wm_workspace(C), v3d->custom_orientation_index);
float mat[3][3];
if (applyTransformOrientation(C, mat, NULL, v3d->twmode - V3D_MANIP_CUSTOM)) {
if (applyTransformOrientation(custom_orientation, mat, NULL)) {
copy_m4_m3(rv3d->twmat, mat);
}
break;

View File

@ -160,11 +160,12 @@ EnumPropertyItem rna_enum_transform_mode_types[] =
static int select_orientation_exec(bContext *C, wmOperator *op)
{
View3D *v3d = CTX_wm_view3d(C);
int orientation = RNA_enum_get(op->ptr, "orientation");
BIF_selectTransformOrientationValue(C, orientation);
BIF_selectTransformOrientationValue(v3d, orientation);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
return OPERATOR_FINISHED;
}
@ -206,10 +207,9 @@ static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
{
View3D *v3d = CTX_wm_view3d(C);
int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
BIF_removeTransformOrientationIndex(C, selected_index);
BIF_removeTransformOrientationIndex(C, v3d->custom_orientation_index);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
@ -223,18 +223,12 @@ static int delete_orientation_invoke(bContext *C, wmOperator *op, const wmEvent
static int delete_orientation_poll(bContext *C)
{
int selected_index = -1;
View3D *v3d = CTX_wm_view3d(C);
if (ED_operator_areaactive(C) == 0)
return 0;
if (v3d) {
selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
}
return selected_index >= 0;
return (v3d->twmode >= V3D_MANIP_CUSTOM) && (v3d->custom_orientation_index != -1);
}
static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)

View File

@ -52,6 +52,7 @@
#include "BKE_report.h"
#include "BKE_main.h"
#include "BKE_screen.h"
#include "BKE_workspace.h"
#include "BLT_translation.h"
@ -63,14 +64,16 @@
void BIF_clearTransformOrientation(bContext *C)
{
WorkSpace *workspace = CTX_wm_workspace(C);
ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace);
View3D *v3d = CTX_wm_view3d(C);
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
BLI_freelistN(transform_spaces);
BLI_freelistN(transform_orientations);
// Need to loop over all view3d
if (v3d && v3d->twmode >= V3D_MANIP_CUSTOM) {
v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
if (v3d && v3d->twmode == V3D_MANIP_CUSTOM) {
v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
v3d->custom_orientation_index = -1;
}
}
@ -318,23 +321,24 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports,
TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3],
const char *name, const bool overwrite)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
TransformOrientation *ts = NULL;
WorkSpace *workspace = CTX_wm_workspace(C);
ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace);
char name_unique[sizeof(ts->name)];
if (overwrite) {
ts = findOrientationName(transform_spaces, name);
ts = findOrientationName(transform_orientations, name);
}
else {
BLI_strncpy(name_unique, name, sizeof(name_unique));
uniqueOrientationName(transform_spaces, name_unique);
uniqueOrientationName(transform_orientations, name_unique);
name = name_unique;
}
/* if not, create a new one */
if (ts == NULL) {
ts = MEM_callocN(sizeof(TransformOrientation), "UserTransSpace from matrix");
BLI_addtail(transform_spaces, ts);
BLI_addtail(transform_orientations, ts);
BLI_strncpy(ts->name, name, sizeof(ts->name));
}
@ -346,72 +350,55 @@ TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3],
void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target)
{
Scene *scene = CTX_data_scene(C);
ListBase *transform_spaces = &scene->transform_spaces;
const int i = BLI_findindex(transform_spaces, target);
if (i != -1) {
Main *bmain = CTX_data_main(C);
BKE_screen_view3d_main_twmode_remove(&bmain->screen, scene, i);
BLI_freelinkN(transform_spaces, target);
}
BKE_workspace_transform_orientation_remove(CTX_wm_workspace(C), target);
}
void BIF_removeTransformOrientationIndex(bContext *C, int index)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
TransformOrientation *ts = BLI_findlink(transform_spaces, index);
if (ts) {
BIF_removeTransformOrientation(C, ts);
}
TransformOrientation *target = BKE_workspace_transform_orientation_find(CTX_wm_workspace(C), index);
BIF_removeTransformOrientation(C, target);
}
void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
const int i = BLI_findindex(transform_spaces, target);
if (i != -1) {
View3D *v3d = CTX_wm_view3d(C);
v3d->twmode = V3D_MANIP_CUSTOM + i;
}
}
void BIF_selectTransformOrientationValue(bContext *C, int orientation)
{
int index = BKE_workspace_transform_orientation_get_index(CTX_wm_workspace(C), target);
View3D *v3d = CTX_wm_view3d(C);
if (v3d) { /* currently using generic poll */
v3d->twmode = orientation;
}
BLI_assert(index != -1);
v3d->twmode = V3D_MANIP_CUSTOM;
v3d->custom_orientation_index = index;
}
/**
* Activate a transform orientation in a 3D view based on an enum value.
*
* \param orientation: If this is #V3D_MANIP_CUSTOM or greater, the custom transform orientation
* with index \a orientation - #V3D_MANIP_CUSTOM gets activated.
*/
void BIF_selectTransformOrientationValue(View3D *v3d, int orientation)
{
const bool is_custom = orientation >= V3D_MANIP_CUSTOM;
v3d->twmode = is_custom ? V3D_MANIP_CUSTOM : orientation;
v3d->custom_orientation_index = is_custom ? (orientation - V3D_MANIP_CUSTOM) : -1;
}
int BIF_countTransformOrientation(const bContext *C)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
return BLI_listbase_count(transform_spaces);
WorkSpace *workspace = CTX_wm_workspace(C);
ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace);
return BLI_listbase_count(transform_orientations);
}
bool applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name, int index)
bool applyTransformOrientation(const TransformOrientation *ts, float r_mat[3][3], char *r_name)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
TransformOrientation *ts = BLI_findlink(transform_spaces, index);
BLI_assert(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;
if (r_name) {
BLI_strncpy(r_name, ts->name, MAX_NAME);
}
copy_m3_m3(r_mat, ts->mat);
return true;
}
static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it)
@ -494,8 +481,10 @@ void initTransformOrientation(bContext *C, TransInfo *t)
unit_m3(t->spacemtx);
}
break;
default: /* V3D_MANIP_CUSTOM */
if (applyTransformOrientation(C, t->spacemtx, t->spacename, t->current_orientation - V3D_MANIP_CUSTOM)) {
case V3D_MANIP_CUSTOM:
BLI_strncpy(t->spacename, t->custom_orientation->name, sizeof(t->spacename));
if (applyTransformOrientation(t->custom_orientation, t->spacemtx, t->spacename)) {
/* pass */
}
else {

View File

@ -1297,17 +1297,6 @@ typedef enum eGP_Interpolate_Type {
GP_IPO_SINE = 12,
} eGP_Interpolate_Type;
/* *************************************************************** */
/* Transform Orientations */
typedef struct TransformOrientation {
struct TransformOrientation *next, *prev;
char name[64]; /* MAX_NAME */
float mat[3][3];
int pad;
} TransformOrientation;
/* *************************************************************** */
/* Unified Paint Settings
*/
@ -1696,10 +1685,10 @@ typedef struct Scene {
/* no, is on the right place (ton) */
struct RenderData r;
struct AudioData audio;
ListBase markers;
ListBase transform_spaces;
ListBase transform_spaces DNA_DEPRECATED;
void *sound_scene;
void *playback_handle;
void *sound_scrub_handle;

View File

@ -193,6 +193,13 @@ typedef struct uiList { /* some list UI data need to be saved in file
uiListDyn *dyn_data;
} uiList;
typedef struct TransformOrientation {
struct TransformOrientation *next, *prev;
char name[64]; /* MAX_NAME */
float mat[3][3];
int pad;
} TransformOrientation;
typedef struct uiPreview { /* some preview UI data need to be saved in file */
struct uiPreview *next, *prev;

View File

@ -225,7 +225,9 @@ typedef struct View3D {
char multiview_eye; /* multiview current eye - for internal use */
char pad3[4];
/* The active custom transform orientation of this 3D view. */
short custom_orientation_index;
char pad3[2];
/* note, 'fx_settings.dof' is currently _not_ allocated,
* instead set (temporarily) from camera */
@ -376,7 +378,7 @@ enum {
#define V3D_MANIP_NORMAL 2
#define V3D_MANIP_VIEW 3
#define V3D_MANIP_GIMBAL 4
#define V3D_MANIP_CUSTOM 5 /* anything of value 5 or higher is custom */
#define V3D_MANIP_CUSTOM 5
/* View3d->twflag */
/* USE = user setting, DRAW = based on selection */

View File

@ -73,6 +73,9 @@ typedef struct WorkSpace {
* been activated the last time this workspace was visible. */
ListBase hook_layout_relations DNA_PRIVATE_WORKSPACE_READ_WRITE; /* WorkSpaceDataRelation */
/* Custom transform orientations */
ListBase transform_orientations DNA_PRIVATE_WORKSPACE;
int object_mode DNA_PRIVATE_WORKSPACE; /* enum ObjectMode */
int pad;

View File

@ -3377,24 +3377,6 @@ static void rna_def_gpencil_brushes(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_ui_text(prop, "Active Brush Index", "Index of active brush");
}
static void rna_def_transform_orientation(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "TransformOrientation", NULL);
prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
RNA_def_property_float_sdna(prop, NULL, "mat");
RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_3x3);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_struct_name_property(srna, prop);
RNA_def_property_ui_text(prop, "Name", "Name of the custom transform orientation");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
}
static void rna_def_tool_settings(BlenderRNA *brna)
{
StructRNA *srna;
@ -9240,12 +9222,6 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil data-block");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
/* Transform Orientations */
prop = RNA_def_property(srna, "orientations", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "transform_spaces", NULL);
RNA_def_property_struct_type(prop, "TransformOrientation");
RNA_def_property_ui_text(prop, "Transform Orientations", "");
/* active MovieClip */
prop = RNA_def_property(srna, "active_clip", PROP_POINTER, PROP_NONE);
@ -9301,7 +9277,6 @@ void RNA_def_scene(BlenderRNA *brna)
rna_def_unit_settings(brna);
rna_def_scene_image_format_data(brna);
rna_def_scene_game_data(brna);
rna_def_transform_orientation(brna);
rna_def_selected_uv_element(brna);
rna_def_display_safe_areas(brna);
rna_def_scene_collection(brna);

View File

@ -262,11 +262,13 @@ EnumPropertyItem rna_enum_file_sort_items[] = {
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_icons.h"
#include "BKE_workspace.h"
#include "ED_buttons.h"
#include "ED_fileselect.h"
#include "ED_image.h"
#include "ED_node.h"
#include "ED_transform.h"
#include "ED_screen.h"
#include "ED_view3d.h"
#include "ED_sequencer.h"
@ -406,43 +408,63 @@ static void rna_Space_view2d_sync_update(Main *UNUSED(bmain), Scene *UNUSED(scen
}
}
static PointerRNA rna_CurrentOrientation_get(PointerRNA *ptr)
static int rna_View3D_transform_orientation_get(PointerRNA *ptr)
{
Scene *scene = WM_windows_scene_get_from_screen(G.main->wm.first, ptr->id.data);
View3D *v3d = (View3D *)ptr->data;
const View3D *v3d = (View3D *)ptr->data;
/* convert to enum value */
return (v3d->twmode == V3D_MANIP_CUSTOM) ? (v3d->twmode + v3d->custom_orientation_index) : v3d->twmode;
}
if (v3d->twmode < V3D_MANIP_CUSTOM)
return rna_pointer_inherit_refine(ptr, &RNA_TransformOrientation, NULL);
else
return rna_pointer_inherit_refine(ptr, &RNA_TransformOrientation,
BLI_findlink(&scene->transform_spaces, v3d->twmode - V3D_MANIP_CUSTOM));
void rna_View3D_transform_orientation_set(PointerRNA *ptr, int value)
{
View3D *v3d = (View3D *)ptr->data;
BIF_selectTransformOrientationValue(v3d, value);
}
static PointerRNA rna_View3D_current_orientation_get(PointerRNA *ptr)
{
View3D *v3d = (View3D *)ptr->data;
TransformOrientation *orientation;
if (v3d->twmode < V3D_MANIP_CUSTOM) {
orientation = NULL;
}
else {
WorkSpace *workspace;
bScreen *screen = ptr->id.data;
BKE_workspace_layout_find_global(G.main, screen, &workspace);
orientation = BKE_workspace_transform_orientation_find(workspace, v3d->custom_orientation_index);
}
return rna_pointer_inherit_refine(ptr, &RNA_TransformOrientation, orientation);
}
EnumPropertyItem *rna_TransformOrientation_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
{
Scene *scene = NULL;
ListBase *transform_spaces;
TransformOrientation *ts = NULL;
WorkSpace *workspace;
ListBase *transform_orientations;
EnumPropertyItem tmp = {0, "", 0, "", ""};
EnumPropertyItem *item = NULL;
int i = V3D_MANIP_CUSTOM, totitem = 0;
RNA_enum_items_add(&item, &totitem, transform_orientation_items);
if (ptr->type == &RNA_SpaceView3D)
scene = WM_windows_scene_get_from_screen(G.main->wm.first, ptr->id.data);
else
scene = CTX_data_scene(C); /* can't use scene from ptr->id.data because that enum is also used by operators */
if (scene) {
transform_spaces = &scene->transform_spaces;
ts = transform_spaces->first;
if (ptr->type == &RNA_SpaceView3D) {
bScreen *screen = ptr->id.data;
BKE_workspace_layout_find_global(G.main, screen, &workspace);
}
else {
/* can't use scene from ptr->id.data because that enum is also used by operators */
workspace = CTX_wm_workspace(C);
}
if (ts) {
transform_orientations = BKE_workspace_transform_orientations_get(workspace);
if (BLI_listbase_is_empty(transform_orientations) == false) {
RNA_enum_item_add_separator(&item, &totitem);
for (; ts; ts = ts->next) {
for (TransformOrientation *ts = transform_orientations->first; ts; ts = ts->next) {
tmp.identifier = ts->name;
tmp.name = ts->name;
tmp.value = i++;
@ -2668,13 +2690,14 @@ static void rna_def_space_view3d(BlenderRNA *brna)
prop = RNA_def_property(srna, "transform_orientation", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "twmode");
RNA_def_property_enum_items(prop, transform_orientation_items);
RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_TransformOrientation_itemf");
RNA_def_property_enum_funcs(prop, "rna_View3D_transform_orientation_get", "rna_View3D_transform_orientation_set",
"rna_TransformOrientation_itemf");
RNA_def_property_ui_text(prop, "Transform Orientation", "Transformation orientation");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "current_orientation", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "TransformOrientation");
RNA_def_property_pointer_funcs(prop, "rna_CurrentOrientation_get", NULL, NULL, NULL);
RNA_def_property_pointer_funcs(prop, "rna_View3D_current_orientation_get", NULL, NULL, NULL);
RNA_def_property_ui_text(prop, "Current Transform Orientation", "Current transformation orientation");
prop = RNA_def_property(srna, "lock_camera_and_layers", PROP_BOOLEAN, PROP_NONE);

View File

@ -76,6 +76,18 @@ static void rna_workspace_object_mode_set(PointerRNA *ptr, int value)
#endif /* USE_WORKSPACE_MODE */
void rna_workspace_transform_orientations_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
WorkSpace *workspace = ptr->id.data;
rna_iterator_listbase_begin(iter, BKE_workspace_transform_orientations_get(workspace), NULL);
}
static PointerRNA rna_workspace_transform_orientations_item_get(CollectionPropertyIterator *iter)
{
TransformOrientation *transform_orientation = rna_iterator_listbase_get(iter);
return rna_pointer_inherit_refine(&iter->parent, &RNA_TransformOrientation, transform_orientation);
}
static PointerRNA rna_workspace_render_layer_get(PointerRNA *ptr)
{
WorkSpace *workspace = ptr->data;
@ -127,6 +139,13 @@ static void rna_def_workspace(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Mode", "Object interaction mode");
#endif
prop = RNA_def_property(srna, "orientations", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "transform_orientations", NULL);
RNA_def_property_struct_type(prop, "TransformOrientation");
RNA_def_property_collection_funcs(prop, "rna_workspace_transform_orientations_begin", NULL, NULL,
"rna_workspace_transform_orientations_item_get", NULL, NULL, NULL, NULL);
RNA_def_property_ui_text(prop, "Transform Orientations", "");
prop = RNA_def_property(srna, "render_layer", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "SceneLayer");
RNA_def_property_pointer_funcs(prop, "rna_workspace_render_layer_get", "rna_workspace_render_layer_set",
@ -136,9 +155,28 @@ static void rna_def_workspace(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SCREEN | ND_LAYER, NULL);
}
static void rna_def_transform_orientation(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "TransformOrientation", NULL);
prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
RNA_def_property_float_sdna(prop, NULL, "mat");
RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_3x3);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_struct_name_property(srna, prop);
RNA_def_property_ui_text(prop, "Name", "Name of the custom transform orientation");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
}
void RNA_def_workspace(BlenderRNA *brna)
{
rna_def_workspace(brna);
rna_def_transform_orientation(brna);
}
#endif /* RNA_RUNTIME */

View File

@ -573,6 +573,7 @@ bool ED_transform_snap_object_project_ray_ex(
/* return args */
float r_loc[3], float r_no[3], int *r_index,
struct Object **r_ob, float r_obmat[4][4]) RET_ZERO
void BIF_selectTransformOrientationValue(struct View3D *v3d, int orientation) RET_NONE
void ED_lattice_editlatt_make(struct Object *obedit) RET_NONE
void ED_lattice_editlatt_load(struct Object *obedit) RET_NONE