2016-04-19 17:08:31 +02:00
|
|
|
/*
|
|
|
|
|
* 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
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2016-04-19 17:08:31 +02:00
|
|
|
*
|
|
|
|
|
* 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) 2007 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup wm
|
2016-04-19 17:08:31 +02:00
|
|
|
*
|
|
|
|
|
* Functions for dealing with append/link operators and helpers.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <ctype.h>
|
2016-04-19 17:08:31 +02:00
|
|
|
#include <errno.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <float.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2016-04-19 17:08:31 +02:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_ID.h"
|
2020-07-23 17:03:02 +02:00
|
|
|
#include "DNA_key_types.h"
|
2016-04-19 17:08:31 +02:00
|
|
|
#include "DNA_scene_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_screen_types.h"
|
2016-04-19 17:08:31 +02:00
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_bitmap.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_ghash.h"
|
2016-04-19 17:08:31 +02:00
|
|
|
#include "BLI_linklist.h"
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_memarena.h"
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLO_readfile.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_global.h"
|
2020-07-23 17:03:02 +02:00
|
|
|
#include "BKE_key.h"
|
2017-05-19 19:34:15 +02:00
|
|
|
#include "BKE_layer.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-07-23 17:03:02 +02:00
|
|
|
#include "BKE_lib_override.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_remap.h"
|
2016-04-19 17:08:31 +02:00
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_report.h"
|
|
|
|
|
|
2020-03-19 19:37:00 +01:00
|
|
|
#include "BKE_idtype.h"
|
2016-04-19 17:08:31 +02:00
|
|
|
|
2017-05-19 19:34:15 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2017-04-06 16:44:32 +02:00
|
|
|
#include "DEG_depsgraph_build.h"
|
2016-04-19 17:08:31 +02:00
|
|
|
|
|
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
|
|
2018-08-20 13:52:50 +02:00
|
|
|
#include "ED_datafiles.h"
|
2016-04-19 17:08:31 +02:00
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
|
|
#include "wm_files.h"
|
|
|
|
|
|
2020-03-25 16:36:01 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Link/Append Operator
|
|
|
|
|
* \{ */
|
2016-04-19 17:08:31 +02:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool wm_link_append_poll(bContext *C)
|
2016-04-19 17:08:31 +02:00
|
|
|
{
|
|
|
|
|
if (WM_operator_winactive(C)) {
|
|
|
|
|
/* linking changes active object which is pretty useful in general,
|
|
|
|
|
* but which totally confuses edit mode (i.e. it becoming not so obvious
|
|
|
|
|
* to leave from edit mode and invalid tools in toolbar might be displayed)
|
|
|
|
|
* so disable link/append when in edit mode (sergey) */
|
2019-04-13 09:15:15 +02:00
|
|
|
if (CTX_data_edit_object(C)) {
|
2016-04-19 17:08:31 +02:00
|
|
|
return 0;
|
2019-04-13 09:15:15 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int wm_link_append_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
|
{
|
2018-10-22 17:18:42 +02:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
|
2016-04-19 17:08:31 +02:00
|
|
|
if (G.lib[0] != '\0') {
|
|
|
|
|
RNA_string_set(op->ptr, "filepath", G.lib);
|
|
|
|
|
}
|
|
|
|
|
else if (G.relbase_valid) {
|
|
|
|
|
char path[FILE_MAX];
|
2018-06-05 15:10:33 +02:00
|
|
|
BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path));
|
2020-04-07 12:02:21 +10:00
|
|
|
BLI_path_parent_dir(path);
|
2016-04-19 17:08:31 +02:00
|
|
|
RNA_string_set(op->ptr, "filepath", path);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-22 17:18:42 +02:00
|
|
|
WM_event_add_fileselect(C, op);
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2016-04-19 17:08:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static short wm_link_append_flag(wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
short flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-13 09:15:15 +02:00
|
|
|
if (RNA_boolean_get(op->ptr, "autoselect")) {
|
2016-04-19 17:08:31 +02:00
|
|
|
flag |= FILE_AUTOSELECT;
|
2019-04-13 09:15:15 +02:00
|
|
|
}
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "active_collection")) {
|
2017-05-26 17:41:50 +02:00
|
|
|
flag |= FILE_ACTIVE_COLLECTION;
|
2019-04-13 09:15:15 +02:00
|
|
|
}
|
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "relative_path")) &&
|
|
|
|
|
RNA_property_boolean_get(op->ptr, prop)) {
|
2016-04-19 17:08:31 +02:00
|
|
|
flag |= FILE_RELPATH;
|
2019-04-13 09:15:15 +02:00
|
|
|
}
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "link")) {
|
2016-04-19 17:08:31 +02:00
|
|
|
flag |= FILE_LINK;
|
2019-04-13 09:15:15 +02:00
|
|
|
}
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "instance_collections")) {
|
2020-09-08 16:49:17 +10:00
|
|
|
flag |= FILE_COLLECTION_INSTANCE;
|
2019-04-13 09:15:15 +02:00
|
|
|
}
|
2020-09-08 16:02:16 +10:00
|
|
|
if (RNA_boolean_get(op->ptr, "instance_object_data")) {
|
|
|
|
|
flag |= FILE_OBDATA_INSTANCE;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct WMLinkAppendDataItem {
|
|
|
|
|
char *name;
|
|
|
|
|
BLI_bitmap
|
|
|
|
|
*libraries; /* All libs (from WMLinkAppendData.libraries) to try to load this ID from. */
|
|
|
|
|
short idcode;
|
|
|
|
|
|
|
|
|
|
ID *new_id;
|
|
|
|
|
void *customdata;
|
|
|
|
|
} WMLinkAppendDataItem;
|
|
|
|
|
|
|
|
|
|
typedef struct WMLinkAppendData {
|
|
|
|
|
LinkNodePair libraries;
|
|
|
|
|
LinkNodePair items;
|
|
|
|
|
int num_libraries;
|
|
|
|
|
int num_items;
|
2020-09-08 16:41:55 +10:00
|
|
|
/**
|
|
|
|
|
* Combines #eFileSel_Params_Flag from DNA_space_types.h & #eBLOLibLinkFlags from BLO_readfile.h
|
|
|
|
|
*/
|
2019-04-20 10:02:28 +02:00
|
|
|
int flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* Internal 'private' data */
|
|
|
|
|
MemArena *memarena;
|
|
|
|
|
} WMLinkAppendData;
|
|
|
|
|
|
|
|
|
|
static WMLinkAppendData *wm_link_append_data_new(const int flag)
|
|
|
|
|
{
|
|
|
|
|
MemArena *ma = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
|
|
|
|
|
WMLinkAppendData *lapp_data = BLI_memarena_calloc(ma, sizeof(*lapp_data));
|
|
|
|
|
|
|
|
|
|
lapp_data->flag = flag;
|
|
|
|
|
lapp_data->memarena = ma;
|
|
|
|
|
|
|
|
|
|
return lapp_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wm_link_append_data_free(WMLinkAppendData *lapp_data)
|
|
|
|
|
{
|
|
|
|
|
BLI_memarena_free(lapp_data->memarena);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* WARNING! *Never* call wm_link_append_data_library_add() after having added some items! */
|
|
|
|
|
|
|
|
|
|
static void wm_link_append_data_library_add(WMLinkAppendData *lapp_data, const char *libname)
|
|
|
|
|
{
|
|
|
|
|
size_t len = strlen(libname) + 1;
|
|
|
|
|
char *libpath = BLI_memarena_alloc(lapp_data->memarena, len);
|
|
|
|
|
|
|
|
|
|
BLI_strncpy(libpath, libname, len);
|
|
|
|
|
BLI_linklist_append_arena(&lapp_data->libraries, libpath, lapp_data->memarena);
|
|
|
|
|
lapp_data->num_libraries++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static WMLinkAppendDataItem *wm_link_append_data_item_add(WMLinkAppendData *lapp_data,
|
|
|
|
|
const char *idname,
|
|
|
|
|
const short idcode,
|
|
|
|
|
void *customdata)
|
|
|
|
|
{
|
|
|
|
|
WMLinkAppendDataItem *item = BLI_memarena_alloc(lapp_data->memarena, sizeof(*item));
|
|
|
|
|
size_t len = strlen(idname) + 1;
|
|
|
|
|
|
|
|
|
|
item->name = BLI_memarena_alloc(lapp_data->memarena, len);
|
|
|
|
|
BLI_strncpy(item->name, idname, len);
|
|
|
|
|
item->idcode = idcode;
|
|
|
|
|
item->libraries = BLI_BITMAP_NEW_MEMARENA(lapp_data->memarena, lapp_data->num_libraries);
|
|
|
|
|
|
|
|
|
|
item->new_id = NULL;
|
|
|
|
|
item->customdata = customdata;
|
|
|
|
|
|
|
|
|
|
BLI_linklist_append_arena(&lapp_data->items, item, lapp_data->memarena);
|
|
|
|
|
lapp_data->num_items++;
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-18 16:23:38 +11:00
|
|
|
static void wm_link_do(WMLinkAppendData *lapp_data,
|
|
|
|
|
ReportList *reports,
|
|
|
|
|
Main *bmain,
|
|
|
|
|
Scene *scene,
|
|
|
|
|
ViewLayer *view_layer,
|
|
|
|
|
const View3D *v3d)
|
2016-04-19 17:08:31 +02:00
|
|
|
{
|
|
|
|
|
Main *mainl;
|
|
|
|
|
BlendHandle *bh;
|
|
|
|
|
Library *lib;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
const int flag = lapp_data->flag;
|
2021-03-09 00:53:13 +11:00
|
|
|
const int id_tag_extra = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
LinkNode *liblink, *itemlink;
|
|
|
|
|
int lib_idx, item_idx;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
BLI_assert(lapp_data->num_items && lapp_data->num_libraries);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
for (lib_idx = 0, liblink = lapp_data->libraries.list; liblink;
|
|
|
|
|
lib_idx++, liblink = liblink->next) {
|
|
|
|
|
char *libname = liblink->link;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-20 13:52:50 +02:00
|
|
|
if (STREQ(libname, BLO_EMBEDDED_STARTUP_BLEND)) {
|
|
|
|
|
bh = BLO_blendhandle_from_memory(datatoc_startup_blend, datatoc_startup_blend_size);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bh = BLO_blendhandle_from_file(libname, reports);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
if (bh == NULL) {
|
|
|
|
|
/* Unlikely since we just browsed it, but possible
|
|
|
|
|
* Error reports will have been made by BLO_blendhandle_from_file() */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* here appending/linking starts */
|
2020-09-08 15:32:43 +10:00
|
|
|
struct LibraryLink_Params liblink_params;
|
|
|
|
|
BLO_library_link_params_init_with_context(
|
2021-03-09 00:53:13 +11:00
|
|
|
&liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
|
2020-09-08 15:32:43 +10:00
|
|
|
|
|
|
|
|
mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
2016-04-19 17:08:31 +02:00
|
|
|
lib = mainl->curlib;
|
|
|
|
|
BLI_assert(lib);
|
|
|
|
|
UNUSED_VARS_NDEBUG(lib);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
if (mainl->versionfile < 250) {
|
|
|
|
|
BKE_reportf(reports,
|
|
|
|
|
RPT_WARNING,
|
|
|
|
|
"Linking or appending from a very old .blend file format (%d.%d), no animation "
|
|
|
|
|
"conversion will "
|
|
|
|
|
"be done! You may want to re-save your lib file with current Blender",
|
|
|
|
|
mainl->versionfile,
|
|
|
|
|
mainl->subversionfile);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* For each lib file, we try to link all items belonging to that lib,
|
|
|
|
|
* and tag those successful to not try to load them again with the other libs. */
|
|
|
|
|
for (item_idx = 0, itemlink = lapp_data->items.list; itemlink;
|
|
|
|
|
item_idx++, itemlink = itemlink->next) {
|
|
|
|
|
WMLinkAppendDataItem *item = itemlink->link;
|
|
|
|
|
ID *new_id;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
if (!BLI_BITMAP_TEST(item->libraries, lib_idx)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-08 15:32:43 +10:00
|
|
|
new_id = BLO_library_link_named_part(mainl, &bh, item->idcode, item->name, &liblink_params);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
if (new_id) {
|
2016-06-29 20:37:54 +10:00
|
|
|
/* If the link is successful, clear item's libs 'todo' flags.
|
2016-04-19 17:08:31 +02:00
|
|
|
* This avoids trying to link same item with other libraries to come. */
|
2018-12-15 11:47:24 +03:00
|
|
|
BLI_bitmap_set_all(item->libraries, false, lapp_data->num_libraries);
|
2016-04-19 17:08:31 +02:00
|
|
|
item->new_id = new_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-08 15:32:43 +10:00
|
|
|
BLO_library_link_end(mainl, &bh, &liblink_params);
|
2016-04-19 17:08:31 +02:00
|
|
|
BLO_blendhandle_close(bh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
/**
|
|
|
|
|
* Check if an item defined by \a name and \a group can be appended/linked.
|
|
|
|
|
*
|
|
|
|
|
* \param reports: Optionally report an error when an item can't be appended/linked.
|
|
|
|
|
*/
|
|
|
|
|
static bool wm_link_append_item_poll(ReportList *reports,
|
|
|
|
|
const char *path,
|
|
|
|
|
const char *group,
|
|
|
|
|
const char *name,
|
|
|
|
|
const bool do_append)
|
|
|
|
|
{
|
|
|
|
|
short idcode;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (!group || !name) {
|
|
|
|
|
printf("skipping %s\n", path);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-19 19:37:00 +01:00
|
|
|
idcode = BKE_idtype_idcode_from_name(group);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
/* XXX For now, we do a nasty exception for workspace, forbid linking them.
|
|
|
|
|
* Not nice, ultimately should be solved! */
|
2020-03-19 19:37:00 +01:00
|
|
|
if (!BKE_idtype_idcode_is_linkable(idcode) && (do_append || idcode != ID_WS)) {
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (reports) {
|
|
|
|
|
if (do_append) {
|
|
|
|
|
BKE_reportf(reports,
|
|
|
|
|
RPT_ERROR_INVALID_INPUT,
|
|
|
|
|
"Can't append data-block '%s' of type '%s'",
|
|
|
|
|
name,
|
|
|
|
|
group);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_reportf(reports,
|
|
|
|
|
RPT_ERROR_INVALID_INPUT,
|
|
|
|
|
"Can't link data-block '%s' of type '%s'",
|
|
|
|
|
name,
|
|
|
|
|
group);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
static int wm_link_append_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2016-04-19 17:08:31 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
WMLinkAppendData *lapp_data;
|
2017-10-08 16:08:00 +02:00
|
|
|
char path[FILE_MAX_LIBEXTRA], root[FILE_MAXDIR], libname[FILE_MAX_LIBEXTRA], relname[FILE_MAX];
|
2016-04-19 17:08:31 +02:00
|
|
|
char *group, *name;
|
|
|
|
|
int totfiles = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
RNA_string_get(op->ptr, "filename", relname);
|
|
|
|
|
RNA_string_get(op->ptr, "directory", root);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
BLI_join_dirfile(path, sizeof(path), root, relname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* test if we have a valid data */
|
|
|
|
|
if (!BLO_library_path_explode(path, libname, &group, &name)) {
|
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "'%s': not a library", path);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (!group) {
|
2016-04-19 17:08:31 +02:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (BLI_path_cmp(BKE_main_blendfile_path(bmain), libname) == 0) {
|
2016-04-19 17:08:31 +02:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "'%s': cannot use current file as library", path);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* check if something is indicated for append/link */
|
|
|
|
|
prop = RNA_struct_find_property(op->ptr, "files");
|
|
|
|
|
if (prop) {
|
|
|
|
|
totfiles = RNA_property_collection_length(op->ptr, prop);
|
|
|
|
|
if (totfiles == 0) {
|
|
|
|
|
if (!name) {
|
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-04-19 17:08:31 +02:00
|
|
|
}
|
|
|
|
|
else if (!name) {
|
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-07 22:09:44 +01:00
|
|
|
short flag = wm_link_append_flag(op);
|
2018-02-07 22:19:11 +01:00
|
|
|
const bool do_append = (flag & FILE_LINK) == 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* sanity checks for flag */
|
|
|
|
|
if (scene && scene->id.lib) {
|
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
|
RPT_WARNING,
|
2020-09-08 16:49:17 +10:00
|
|
|
"Scene '%s' is linked, instantiation of objects is disabled",
|
2016-04-19 17:08:31 +02:00
|
|
|
scene->id.name + 2);
|
2020-09-08 16:49:17 +10:00
|
|
|
flag &= ~(FILE_COLLECTION_INSTANCE | FILE_OBDATA_INSTANCE);
|
2016-04-19 17:08:31 +02:00
|
|
|
scene = NULL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-08 16:41:55 +10:00
|
|
|
/* We need to add nothing from #eBLOLibLinkFlags to flag here. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* from here down, no error returns */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
if (view_layer && RNA_boolean_get(op->ptr, "autoselect")) {
|
|
|
|
|
BKE_view_layer_base_deselect_all(view_layer);
|
2016-04-19 17:08:31 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* tag everything, all untagged data can be made local
|
|
|
|
|
* its also generally useful to know what is new
|
|
|
|
|
*
|
|
|
|
|
* take extra care BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false) is called after! */
|
|
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* We define our working data...
|
|
|
|
|
* Note that here, each item 'uses' one library, and only one. */
|
|
|
|
|
lapp_data = wm_link_append_data_new(flag);
|
|
|
|
|
if (totfiles != 0) {
|
|
|
|
|
GHash *libraries = BLI_ghash_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, __func__);
|
|
|
|
|
int lib_idx = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
RNA_BEGIN (op->ptr, itemptr, "files") {
|
|
|
|
|
RNA_string_get(&itemptr, "name", relname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
BLI_join_dirfile(path, sizeof(path), root, relname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
if (BLO_library_path_explode(path, libname, &group, &name)) {
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (!wm_link_append_item_poll(NULL, path, group, name, do_append)) {
|
2016-04-19 17:08:31 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
if (!BLI_ghash_haskey(libraries, libname)) {
|
2018-09-19 12:05:58 +10:00
|
|
|
BLI_ghash_insert(libraries, BLI_strdup(libname), POINTER_FROM_INT(lib_idx));
|
2016-04-19 17:08:31 +02:00
|
|
|
lib_idx++;
|
|
|
|
|
wm_link_append_data_library_add(lapp_data, libname);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-04-19 17:08:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RNA_END;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
RNA_BEGIN (op->ptr, itemptr, "files") {
|
|
|
|
|
RNA_string_get(&itemptr, "name", relname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
BLI_join_dirfile(path, sizeof(path), root, relname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
if (BLO_library_path_explode(path, libname, &group, &name)) {
|
|
|
|
|
WMLinkAppendDataItem *item;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (!wm_link_append_item_poll(op->reports, path, group, name, do_append)) {
|
2016-04-19 17:08:31 +02:00
|
|
|
continue;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
lib_idx = POINTER_AS_INT(BLI_ghash_lookup(libraries, libname));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-19 19:37:00 +01:00
|
|
|
item = wm_link_append_data_item_add(
|
|
|
|
|
lapp_data, name, BKE_idtype_idcode_from_name(group), NULL);
|
2018-09-19 12:05:58 +10:00
|
|
|
BLI_BITMAP_ENABLE(item->libraries, lib_idx);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RNA_END;
|
|
|
|
|
|
2018-09-19 12:05:58 +10:00
|
|
|
BLI_ghash_free(libraries, MEM_freeN, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2018-09-19 12:05:58 +10:00
|
|
|
WMLinkAppendDataItem *item;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-19 12:05:58 +10:00
|
|
|
wm_link_append_data_library_add(lapp_data, libname);
|
2020-03-19 19:37:00 +01:00
|
|
|
item = wm_link_append_data_item_add(lapp_data, name, BKE_idtype_idcode_from_name(group), NULL);
|
2016-04-19 17:08:31 +02:00
|
|
|
BLI_BITMAP_ENABLE(item->libraries, 0);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
if (lapp_data->num_items == 0) {
|
|
|
|
|
/* Early out in case there is nothing to link. */
|
|
|
|
|
wm_link_append_data_free(lapp_data);
|
2019-07-03 20:40:33 +02:00
|
|
|
/* Clear pre existing tag. */
|
|
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
|
2016-04-19 17:08:31 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-07 22:09:44 +01:00
|
|
|
/* XXX We'd need re-entrant locking on Main for this to work... */
|
|
|
|
|
/* BKE_main_lock(bmain); */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
wm_link_do(lapp_data, op->reports, bmain, scene, view_layer, CTX_wm_view3d(C));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* BKE_main_unlock(bmain); */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-18 16:23:38 +11:00
|
|
|
/* mark all library linked objects to be updated */
|
2016-04-19 17:08:31 +02:00
|
|
|
BKE_main_lib_objects_recalc_all(bmain);
|
2018-12-18 16:23:38 +11:00
|
|
|
IMB_colormanagement_check_file_config(bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-18 16:23:38 +11:00
|
|
|
/* append, rather than linking */
|
|
|
|
|
if (do_append) {
|
2016-05-13 12:54:09 +02:00
|
|
|
const bool set_fake = RNA_boolean_get(op->ptr, "set_fake");
|
2018-12-18 16:23:38 +11:00
|
|
|
const bool use_recursive = RNA_boolean_get(op->ptr, "use_recursive");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-14 01:28:21 +10:00
|
|
|
if (use_recursive) {
|
2018-12-18 16:23:38 +11:00
|
|
|
BKE_library_make_local(bmain, NULL, NULL, true, set_fake);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2016-05-13 12:54:09 +02:00
|
|
|
LinkNode *itemlink;
|
2018-12-18 16:23:38 +11:00
|
|
|
GSet *done_libraries = BLI_gset_new_ex(
|
|
|
|
|
BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__, lapp_data->num_libraries);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
for (itemlink = lapp_data->items.list; itemlink; itemlink = itemlink->next) {
|
|
|
|
|
ID *new_id = ((WMLinkAppendDataItem *)(itemlink->link))->new_id;
|
|
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (new_id && !BLI_gset_haskey(done_libraries, new_id->lib)) {
|
2016-11-01 13:39:31 +01:00
|
|
|
BKE_library_make_local(bmain, new_id->lib, NULL, true, set_fake);
|
2016-05-13 12:54:09 +02:00
|
|
|
BLI_gset_insert(done_libraries, new_id->lib);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-13 12:54:09 +02:00
|
|
|
BLI_gset_free(done_libraries, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-05-13 12:54:09 +02:00
|
|
|
|
|
|
|
|
wm_link_append_data_free(lapp_data);
|
|
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* important we unset, otherwise these object wont
|
|
|
|
|
* link into other scenes from this blend file */
|
|
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
|
|
|
|
|
|
2017-05-19 19:34:15 +02:00
|
|
|
/* TODO(sergey): Use proper flag for tagging here. */
|
|
|
|
|
|
2020-09-19 14:32:41 +10:00
|
|
|
/* TODO(dalai): Temporary solution!
|
2019-04-20 10:02:28 +02:00
|
|
|
* Ideally we only need to tag the new objects themselves, not the scene.
|
|
|
|
|
* This way we'll avoid flush of collection properties
|
|
|
|
|
* to all objects and limit update to the particular object only.
|
|
|
|
|
* But afraid first we need to change collection evaluation in DEG
|
|
|
|
|
* according to depsgraph manifesto. */
|
2017-05-19 19:34:15 +02:00
|
|
|
DEG_id_tag_update(&scene->id, 0);
|
|
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* recreate dependency graph to include new objects */
|
2017-10-24 16:47:34 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2016-04-19 17:08:31 +02:00
|
|
|
|
|
|
|
|
/* XXX TODO: align G.lib with other directory storage (like last opened image etc...) */
|
|
|
|
|
BLI_strncpy(G.lib, root, FILE_MAX);
|
|
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wm_link_append_properties_common(wmOperatorType *ot, bool is_link)
|
|
|
|
|
{
|
|
|
|
|
PropertyRNA *prop;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
/* better not save _any_ settings for this operator */
|
|
|
|
|
/* properties */
|
|
|
|
|
prop = RNA_def_boolean(
|
2016-09-19 16:46:20 +02:00
|
|
|
ot->srna, "link", is_link, "Link", "Link the objects or data-blocks rather than appending");
|
2016-04-19 17:08:31 +02:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
|
|
|
|
|
prop = RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select new objects");
|
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2017-05-19 19:34:15 +02:00
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
|
"active_collection",
|
|
|
|
|
true,
|
|
|
|
|
"Active Collection",
|
|
|
|
|
"Put new objects on the active collection");
|
2016-04-19 17:08:31 +02:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
|
|
|
prop = RNA_def_boolean(
|
|
|
|
|
ot->srna,
|
|
|
|
|
"instance_collections",
|
|
|
|
|
is_link,
|
|
|
|
|
"Instance Collections",
|
|
|
|
|
"Create instances for collections, rather than adding them directly to the scene");
|
2016-04-19 17:08:31 +02:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2020-09-08 16:02:16 +10:00
|
|
|
|
|
|
|
|
prop = RNA_def_boolean(
|
|
|
|
|
ot->srna,
|
|
|
|
|
"instance_object_data",
|
|
|
|
|
true,
|
|
|
|
|
"Instance Object Data",
|
|
|
|
|
"Create instances for object data which are not referenced by any objects");
|
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2016-04-19 17:08:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WM_OT_link(wmOperatorType *ot)
|
|
|
|
|
{
|
UI: File Browser Design Overhaul
This is a general redesign of the File Browser GUI and interaction
methods. For screenshots, check patch D5601.
Main changes in short:
* File Browser as floating window
* New layout of regions
* Popovers for view and filter options
* Vertical list view with interactive column header
* New and updated icons
* Keymap consistency fixes
* Many tweaks and fixes to the drawing of views
----
General:
* The file browser now opens as temporary floating window. It closes on
Esc. The header is hidden then.
* When the file browser is opened as regular editor, the header remains
visible.
* All file browser regions are now defined in Python (the button
layout).
* Adjusted related operator UI names.
Keymap:
Keymap is now consistent with other list-based views in Blender, such as
the Outliner.
* Left click to select, double-click to open
* Right-click context menus
* Shift-click to fill selection
* Ctrl-click to extend selection
Operator options:
These previously overlapped with the source list, which caused numerous
issues with resizing and presenting many settings in a small panel area.
It was also generally inconsistent with Blender.
* Moved to new sidebar, which can easily be shown or hidden using a
prominent Options toggle.
* IO operators have new layouts to match this new sidebar, using
sub-panels. This will have to be committed separately (Add-on
repository).
* If operators want to show the options by default, they have the option
to do so (see `WM_FILESEL_SHOW_PROPS`, `hide_props_region`), otherwise
they are hidden by default.
General Layout:
The layout has been changed to be simpler, more standard, and fits
better in with Blender 2.8.
* More conventional layout (file path at top, file name at the bottom,
execute/cancel buttons in bottom right).
* Use of popovers to group controls, and allow for more descriptive
naming.
* Search box is always live now, just like Outliner.
Views:
* Date Modified column combines both date and time, also uses user
friendly strings for recent dates (i.e. "Yesterday", "Today").
* Details columns (file size, modification date/time) are now toggleable
for all display types, they are not hardcoded per display type.
* File sizes now show as B, KB, MB, ... rather than B, KiB, MiB, … They
are now also calculated using base 10 of course.
* Option to sort in inverse order.
Vertical List View:
* This view now used a much simpler single vertical list with columns
for information.
* Users can click on the headers of these columns to order by that
category, and click again to reverse the ordering.
Icons:
* Updated icons by Jendrzych, with better centering.
* Files and folders have new icons in Icon view.
* Both files and folders have reworked superimposed icons that show
users the file/folder type.
* 3D file documents correctly use the 3d file icon, which was unused
previously.
* Workspaces now show their icon on Link/Append - also when listed in
the Outliner.
Minor Python-API breakage:
* `bpy.types.FileSelectParams.display_type`: `LIST_SHORT` and
`LIST_LONG` are replaced by `LIST_VERTICAL` and `LIST_HORIZONTAL`.
Removes the feature where directories would automatically be created if
they are entered into the file path text button, but don't exist. We
were not sure if users use it enough to keep it. We can definitely bring
it back.
----
//Combined effort by @billreynish, @harley, @jendrzych, my university
colleague Brian Meisenheimer and myself.//
Differential Revision: https://developer.blender.org/D5601
Reviewers: Brecht, Bastien
2019-09-03 15:43:38 +02:00
|
|
|
ot->name = "Link";
|
2016-04-19 17:08:31 +02:00
|
|
|
ot->idname = "WM_OT_link";
|
|
|
|
|
ot->description = "Link from a Library .blend file";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
ot->invoke = wm_link_append_invoke;
|
|
|
|
|
ot->exec = wm_link_append_exec;
|
|
|
|
|
ot->poll = wm_link_append_poll;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
ot->flag |= OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_BLENDER | FILE_TYPE_BLENDERLIB,
|
|
|
|
|
FILE_LOADLIB,
|
|
|
|
|
FILE_OPENFILE,
|
|
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILENAME |
|
2019-09-16 18:35:27 +02:00
|
|
|
WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_SHOW_PROPS,
|
2016-04-19 17:08:31 +02:00
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
wm_link_append_properties_common(ot, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WM_OT_append(wmOperatorType *ot)
|
|
|
|
|
{
|
UI: File Browser Design Overhaul
This is a general redesign of the File Browser GUI and interaction
methods. For screenshots, check patch D5601.
Main changes in short:
* File Browser as floating window
* New layout of regions
* Popovers for view and filter options
* Vertical list view with interactive column header
* New and updated icons
* Keymap consistency fixes
* Many tweaks and fixes to the drawing of views
----
General:
* The file browser now opens as temporary floating window. It closes on
Esc. The header is hidden then.
* When the file browser is opened as regular editor, the header remains
visible.
* All file browser regions are now defined in Python (the button
layout).
* Adjusted related operator UI names.
Keymap:
Keymap is now consistent with other list-based views in Blender, such as
the Outliner.
* Left click to select, double-click to open
* Right-click context menus
* Shift-click to fill selection
* Ctrl-click to extend selection
Operator options:
These previously overlapped with the source list, which caused numerous
issues with resizing and presenting many settings in a small panel area.
It was also generally inconsistent with Blender.
* Moved to new sidebar, which can easily be shown or hidden using a
prominent Options toggle.
* IO operators have new layouts to match this new sidebar, using
sub-panels. This will have to be committed separately (Add-on
repository).
* If operators want to show the options by default, they have the option
to do so (see `WM_FILESEL_SHOW_PROPS`, `hide_props_region`), otherwise
they are hidden by default.
General Layout:
The layout has been changed to be simpler, more standard, and fits
better in with Blender 2.8.
* More conventional layout (file path at top, file name at the bottom,
execute/cancel buttons in bottom right).
* Use of popovers to group controls, and allow for more descriptive
naming.
* Search box is always live now, just like Outliner.
Views:
* Date Modified column combines both date and time, also uses user
friendly strings for recent dates (i.e. "Yesterday", "Today").
* Details columns (file size, modification date/time) are now toggleable
for all display types, they are not hardcoded per display type.
* File sizes now show as B, KB, MB, ... rather than B, KiB, MiB, … They
are now also calculated using base 10 of course.
* Option to sort in inverse order.
Vertical List View:
* This view now used a much simpler single vertical list with columns
for information.
* Users can click on the headers of these columns to order by that
category, and click again to reverse the ordering.
Icons:
* Updated icons by Jendrzych, with better centering.
* Files and folders have new icons in Icon view.
* Both files and folders have reworked superimposed icons that show
users the file/folder type.
* 3D file documents correctly use the 3d file icon, which was unused
previously.
* Workspaces now show their icon on Link/Append - also when listed in
the Outliner.
Minor Python-API breakage:
* `bpy.types.FileSelectParams.display_type`: `LIST_SHORT` and
`LIST_LONG` are replaced by `LIST_VERTICAL` and `LIST_HORIZONTAL`.
Removes the feature where directories would automatically be created if
they are entered into the file path text button, but don't exist. We
were not sure if users use it enough to keep it. We can definitely bring
it back.
----
//Combined effort by @billreynish, @harley, @jendrzych, my university
colleague Brian Meisenheimer and myself.//
Differential Revision: https://developer.blender.org/D5601
Reviewers: Brecht, Bastien
2019-09-03 15:43:38 +02:00
|
|
|
ot->name = "Append";
|
2016-04-19 17:08:31 +02:00
|
|
|
ot->idname = "WM_OT_append";
|
|
|
|
|
ot->description = "Append from a Library .blend file";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
ot->invoke = wm_link_append_invoke;
|
|
|
|
|
ot->exec = wm_link_append_exec;
|
|
|
|
|
ot->poll = wm_link_append_poll;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
ot->flag |= OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_BLENDER | FILE_TYPE_BLENDERLIB,
|
|
|
|
|
FILE_LOADLIB,
|
|
|
|
|
FILE_OPENFILE,
|
|
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILENAME |
|
2019-09-16 18:35:27 +02:00
|
|
|
WM_FILESEL_FILES | WM_FILESEL_SHOW_PROPS,
|
2016-04-19 17:08:31 +02:00
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-19 17:08:31 +02:00
|
|
|
wm_link_append_properties_common(ot, false);
|
2016-05-13 12:54:09 +02:00
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
|
"set_fake",
|
|
|
|
|
false,
|
|
|
|
|
"Fake User",
|
2021-02-24 13:25:44 -06:00
|
|
|
"Set \"Fake User\" for appended items (except objects and collections)");
|
2016-05-14 01:28:21 +10:00
|
|
|
RNA_def_boolean(
|
|
|
|
|
ot->srna,
|
|
|
|
|
"use_recursive",
|
|
|
|
|
true,
|
|
|
|
|
"Localize All",
|
2016-05-13 12:54:09 +02:00
|
|
|
"Localize all appended data, including those indirectly linked from other libraries");
|
2016-04-19 17:08:31 +02:00
|
|
|
}
|
2016-06-22 18:05:55 +02:00
|
|
|
|
2020-03-25 16:36:01 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Append Single Data-Block & Return it
|
2019-07-03 20:36:49 +02:00
|
|
|
*
|
|
|
|
|
* Used for appending workspace from startup files.
|
2016-06-22 18:05:55 +02:00
|
|
|
* \{ */
|
|
|
|
|
|
2020-03-06 16:22:28 +01:00
|
|
|
ID *WM_file_append_datablock(Main *bmain,
|
|
|
|
|
Scene *scene,
|
|
|
|
|
ViewLayer *view_layer,
|
|
|
|
|
View3D *v3d,
|
2019-07-03 20:36:49 +02:00
|
|
|
const char *filepath,
|
|
|
|
|
const short id_code,
|
|
|
|
|
const char *id_name)
|
|
|
|
|
{
|
|
|
|
|
/* Tag everything so we can make local only the new datablock. */
|
|
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
|
|
|
|
|
|
|
|
|
|
/* Define working data, with just the one item we want to append. */
|
|
|
|
|
WMLinkAppendData *lapp_data = wm_link_append_data_new(0);
|
|
|
|
|
|
|
|
|
|
wm_link_append_data_library_add(lapp_data, filepath);
|
|
|
|
|
WMLinkAppendDataItem *item = wm_link_append_data_item_add(lapp_data, id_name, id_code, NULL);
|
|
|
|
|
BLI_BITMAP_ENABLE(item->libraries, 0);
|
|
|
|
|
|
|
|
|
|
/* Link datablock. */
|
|
|
|
|
wm_link_do(lapp_data, NULL, bmain, scene, view_layer, v3d);
|
|
|
|
|
|
|
|
|
|
/* Get linked datablock and free working data. */
|
|
|
|
|
ID *id = item->new_id;
|
|
|
|
|
wm_link_append_data_free(lapp_data);
|
|
|
|
|
|
|
|
|
|
/* Make datablock local. */
|
|
|
|
|
BKE_library_make_local(bmain, NULL, NULL, true, false);
|
|
|
|
|
|
|
|
|
|
/* Clear pre existing tag. */
|
|
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2020-03-25 16:36:01 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Library Relocate Operator & Library Reload API
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
Library *lib;
|
|
|
|
|
char lib_name[MAX_NAME];
|
|
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "library", lib_name);
|
2018-05-31 16:04:04 +02:00
|
|
|
lib = (Library *)BKE_libblock_find_name(CTX_data_main(C), ID_LI, lib_name);
|
2016-06-22 18:05:55 +02:00
|
|
|
|
|
|
|
|
if (lib) {
|
|
|
|
|
if (lib->parent) {
|
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
|
RPT_ERROR_INVALID_INPUT,
|
|
|
|
|
"Cannot relocate indirectly linked library '%s'",
|
2020-06-23 09:54:07 +10:00
|
|
|
lib->filepath_abs);
|
2016-06-22 18:05:55 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2020-06-23 09:54:07 +10:00
|
|
|
RNA_string_set(op->ptr, "filepath", lib->filepath_abs);
|
2016-06-22 18:05:55 +02:00
|
|
|
|
|
|
|
|
WM_event_add_fileselect(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 17:03:02 +02:00
|
|
|
static void lib_relocate_do_remap(Main *bmain,
|
|
|
|
|
ID *old_id,
|
|
|
|
|
ID *new_id,
|
|
|
|
|
ReportList *reports,
|
|
|
|
|
const bool do_reload,
|
|
|
|
|
const short remap_flags)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(old_id);
|
|
|
|
|
if (do_reload) {
|
|
|
|
|
/* Since we asked for placeholders in case of missing IDs,
|
|
|
|
|
* we expect to always get a valid one. */
|
|
|
|
|
BLI_assert(new_id);
|
|
|
|
|
}
|
|
|
|
|
if (new_id) {
|
|
|
|
|
#ifdef PRINT_DEBUG
|
|
|
|
|
printf("before remap of %s, old_id users: %d, new_id users: %d\n",
|
|
|
|
|
old_id->name,
|
|
|
|
|
old_id->us,
|
|
|
|
|
new_id->us);
|
|
|
|
|
#endif
|
|
|
|
|
BKE_libblock_remap_locked(bmain, old_id, new_id, remap_flags);
|
|
|
|
|
|
|
|
|
|
if (old_id->flag & LIB_FAKEUSER) {
|
|
|
|
|
id_fake_user_clear(old_id);
|
|
|
|
|
id_fake_user_set(new_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef PRINT_DEBUG
|
|
|
|
|
printf("after remap of %s, old_id users: %d, new_id users: %d\n",
|
|
|
|
|
old_id->name,
|
|
|
|
|
old_id->us,
|
|
|
|
|
new_id->us);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* In some cases, new_id might become direct link, remove parent of library in this case. */
|
|
|
|
|
if (new_id->lib->parent && (new_id->tag & LIB_TAG_INDIRECT) == 0) {
|
|
|
|
|
if (do_reload) {
|
2021-03-24 12:38:08 +11:00
|
|
|
BLI_assert_unreachable(); /* Should not happen in 'pure' reload case... */
|
2020-07-23 17:03:02 +02:00
|
|
|
}
|
|
|
|
|
new_id->lib->parent = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (old_id->us > 0 && new_id && old_id->lib == new_id->lib) {
|
|
|
|
|
/* Note that this *should* not happen - but better be safe than sorry in this area,
|
|
|
|
|
* at least until we are 100% sure this cannot ever happen.
|
|
|
|
|
* Also, we can safely assume names were unique so far,
|
|
|
|
|
* so just replacing '.' by '~' should work,
|
|
|
|
|
* but this does not totally rules out the possibility of name collision. */
|
|
|
|
|
size_t len = strlen(old_id->name);
|
|
|
|
|
size_t dot_pos;
|
|
|
|
|
bool has_num = false;
|
|
|
|
|
|
|
|
|
|
for (dot_pos = len; dot_pos--;) {
|
|
|
|
|
char c = old_id->name[dot_pos];
|
|
|
|
|
if (c == '.') {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (c < '0' || c > '9') {
|
2020-07-23 17:03:02 +02:00
|
|
|
has_num = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
has_num = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (has_num) {
|
|
|
|
|
old_id->name[dot_pos] = '~';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
len = MIN2(len, MAX_ID_NAME - 7);
|
|
|
|
|
BLI_strncpy(&old_id->name[len], "~000", 7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id_sort_by_name(which_libbase(bmain, GS(old_id->name)), old_id, NULL);
|
|
|
|
|
|
|
|
|
|
BKE_reportf(
|
|
|
|
|
reports,
|
|
|
|
|
RPT_WARNING,
|
|
|
|
|
"Lib Reload: Replacing all references to old data-block '%s' by reloaded one failed, "
|
|
|
|
|
"old one (%d remaining users) had to be kept and was renamed to '%s'",
|
|
|
|
|
new_id->name,
|
|
|
|
|
old_id->us,
|
|
|
|
|
old_id->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 17:49:01 +02:00
|
|
|
static void lib_relocate_do(Main *bmain,
|
|
|
|
|
Library *library,
|
|
|
|
|
WMLinkAppendData *lapp_data,
|
|
|
|
|
ReportList *reports,
|
|
|
|
|
const bool do_reload)
|
2016-06-22 18:05:55 +02:00
|
|
|
{
|
2021-03-04 18:39:07 +01:00
|
|
|
ListBase *lbarray[INDEX_ID_MAX];
|
2016-06-22 18:05:55 +02:00
|
|
|
int lba_idx;
|
|
|
|
|
|
|
|
|
|
LinkNode *itemlink;
|
|
|
|
|
int item_idx;
|
|
|
|
|
|
2016-07-19 17:49:01 +02:00
|
|
|
/* Remove all IDs to be reloaded from Main. */
|
|
|
|
|
lba_idx = set_listbasepointers(bmain, lbarray);
|
|
|
|
|
while (lba_idx--) {
|
|
|
|
|
ID *id = lbarray[lba_idx]->first;
|
|
|
|
|
const short idcode = id ? GS(id->name) : 0;
|
|
|
|
|
|
2020-03-19 19:37:00 +01:00
|
|
|
if (!id || !BKE_idtype_idcode_is_linkable(idcode)) {
|
2019-04-20 10:02:28 +02:00
|
|
|
/* No need to reload non-linkable datatypes,
|
|
|
|
|
* those will get relinked with their 'users ID'. */
|
2016-07-19 17:49:01 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (; id; id = id->next) {
|
|
|
|
|
if (id->lib == library) {
|
|
|
|
|
WMLinkAppendDataItem *item;
|
|
|
|
|
|
|
|
|
|
/* We remove it from current Main, and add it to items to link... */
|
2016-07-31 17:41:05 +10:00
|
|
|
/* Note that non-linkable IDs (like e.g. shapekeys) are also explicitly linked here... */
|
2016-07-19 17:49:01 +02:00
|
|
|
BLI_remlink(lbarray[lba_idx], id);
|
2020-07-23 17:03:02 +02:00
|
|
|
/* Usual special code for ShapeKeys snowflakes... */
|
|
|
|
|
Key *old_key = BKE_key_from_id(id);
|
|
|
|
|
if (old_key != NULL) {
|
|
|
|
|
BLI_remlink(which_libbase(bmain, GS(old_key->id.name)), &old_key->id);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 17:49:01 +02:00
|
|
|
item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id);
|
2018-12-15 11:47:24 +03:00
|
|
|
BLI_bitmap_set_all(item->libraries, true, lapp_data->num_libraries);
|
2016-07-19 17:49:01 +02:00
|
|
|
|
|
|
|
|
#ifdef PRINT_DEBUG
|
|
|
|
|
printf("\tdatablock to seek for: %s\n", id->name);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-07 21:52:38 +01:00
|
|
|
if (lapp_data->num_items == 0) {
|
|
|
|
|
/* Early out in case there is nothing to do. */
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-24 17:27:41 +02:00
|
|
|
/* We do not want any instantiation here! */
|
2018-12-18 16:23:38 +11:00
|
|
|
wm_link_do(lapp_data, reports, bmain, NULL, NULL, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
BKE_main_lock(bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
/* We add back old id to bmain.
|
|
|
|
|
* We need to do this in a first, separated loop, otherwise some of those may not be handled by
|
|
|
|
|
* ID remapping, which means they would still reference old data to be deleted... */
|
|
|
|
|
for (item_idx = 0, itemlink = lapp_data->items.list; itemlink;
|
|
|
|
|
item_idx++, itemlink = itemlink->next) {
|
|
|
|
|
WMLinkAppendDataItem *item = itemlink->link;
|
|
|
|
|
ID *old_id = item->customdata;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
BLI_assert(old_id);
|
|
|
|
|
BLI_addtail(which_libbase(bmain, GS(old_id->name)), old_id);
|
2020-07-23 17:03:02 +02:00
|
|
|
|
|
|
|
|
/* Usual special code for ShapeKeys snowflakes... */
|
|
|
|
|
Key *old_key = BKE_key_from_id(old_id);
|
|
|
|
|
if (old_key != NULL) {
|
|
|
|
|
BLI_addtail(which_libbase(bmain, GS(old_key->id.name)), &old_key->id);
|
|
|
|
|
}
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-15 15:02:32 +02:00
|
|
|
/* Since our (old) reloaded IDs were removed from main, the user count done for them in linking
|
|
|
|
|
* code is wrong, we need to redo it here after adding them back to main. */
|
|
|
|
|
BKE_main_id_refcount_recompute(bmain, false);
|
|
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
/* Note that in reload case, we also want to replace indirect usages. */
|
2017-06-26 18:55:30 +02:00
|
|
|
const short remap_flags = ID_REMAP_SKIP_NEVER_NULL_USAGE |
|
|
|
|
|
ID_REMAP_NO_INDIRECT_PROXY_DATA_USAGE |
|
|
|
|
|
(do_reload ? 0 : ID_REMAP_SKIP_INDIRECT_USAGE);
|
2016-06-22 18:05:55 +02:00
|
|
|
for (item_idx = 0, itemlink = lapp_data->items.list; itemlink;
|
|
|
|
|
item_idx++, itemlink = itemlink->next) {
|
|
|
|
|
WMLinkAppendDataItem *item = itemlink->link;
|
|
|
|
|
ID *old_id = item->customdata;
|
|
|
|
|
ID *new_id = item->new_id;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-23 17:03:02 +02:00
|
|
|
lib_relocate_do_remap(bmain, old_id, new_id, reports, do_reload, remap_flags);
|
2020-10-16 15:22:20 +02:00
|
|
|
if (new_id == NULL) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-07-23 17:03:02 +02:00
|
|
|
/* Usual special code for ShapeKeys snowflakes... */
|
|
|
|
|
Key **old_key_p = BKE_key_from_id_p(old_id);
|
|
|
|
|
if (old_key_p == NULL) {
|
|
|
|
|
continue;
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
2020-07-23 17:03:02 +02:00
|
|
|
Key *old_key = *old_key_p;
|
|
|
|
|
Key *new_key = BKE_key_from_id(new_id);
|
|
|
|
|
if (old_key != NULL) {
|
|
|
|
|
*old_key_p = NULL;
|
|
|
|
|
id_us_min(&old_key->id);
|
|
|
|
|
lib_relocate_do_remap(bmain, &old_key->id, &new_key->id, reports, do_reload, remap_flags);
|
|
|
|
|
*old_key_p = old_key;
|
|
|
|
|
id_us_plus_no_lib(&old_key->id);
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
BKE_main_unlock(bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
for (item_idx = 0, itemlink = lapp_data->items.list; itemlink;
|
|
|
|
|
item_idx++, itemlink = itemlink->next) {
|
|
|
|
|
WMLinkAppendDataItem *item = itemlink->link;
|
|
|
|
|
ID *old_id = item->customdata;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
if (old_id->us == 0) {
|
2019-01-14 15:47:11 +01:00
|
|
|
BKE_id_free(bmain, old_id);
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-20 10:02:28 +02:00
|
|
|
/* Some datablocks can get reloaded/replaced 'silently' because they are not linkable
|
|
|
|
|
* (shape keys e.g.), so we need another loop here to clear old ones if possible. */
|
2016-06-22 18:05:55 +02:00
|
|
|
lba_idx = set_listbasepointers(bmain, lbarray);
|
|
|
|
|
while (lba_idx--) {
|
|
|
|
|
ID *id, *id_next;
|
|
|
|
|
for (id = lbarray[lba_idx]->first; id; id = id_next) {
|
|
|
|
|
id_next = id->next;
|
|
|
|
|
/* XXX That check may be a bit to generic/permissive? */
|
|
|
|
|
if (id->lib && (id->flag & LIB_TAG_PRE_EXISTING) && id->us == 0) {
|
2019-01-14 15:47:11 +01:00
|
|
|
BKE_id_free(bmain, id);
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
/* Get rid of no more used libraries... */
|
|
|
|
|
BKE_main_id_tag_idcode(bmain, ID_LI, LIB_TAG_DOIT, true);
|
|
|
|
|
lba_idx = set_listbasepointers(bmain, lbarray);
|
|
|
|
|
while (lba_idx--) {
|
|
|
|
|
ID *id;
|
|
|
|
|
for (id = lbarray[lba_idx]->first; id; id = id->next) {
|
|
|
|
|
if (id->lib) {
|
|
|
|
|
id->lib->id.tag &= ~LIB_TAG_DOIT;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-06-22 18:05:55 +02:00
|
|
|
Library *lib, *lib_next;
|
|
|
|
|
for (lib = which_libbase(bmain, ID_LI)->first; lib; lib = lib_next) {
|
|
|
|
|
lib_next = lib->id.next;
|
|
|
|
|
if (lib->id.tag & LIB_TAG_DOIT) {
|
|
|
|
|
id_us_clear_real(&lib->id);
|
|
|
|
|
if (lib->id.us == 0) {
|
2019-01-14 15:47:11 +01:00
|
|
|
BKE_id_free(bmain, (ID *)lib);
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-23 17:07:48 +02:00
|
|
|
/* Update overrides of reloaded linked data-blocks.
|
|
|
|
|
* Note that this will not necessarily fully update the override, it might need to be manually
|
|
|
|
|
* 're-generated' depending on changes in linked data. */
|
|
|
|
|
ID *id;
|
|
|
|
|
FOREACH_MAIN_ID_BEGIN (bmain, id) {
|
|
|
|
|
if (ID_IS_LINKED(id) || !ID_IS_OVERRIDE_LIBRARY_REAL(id) ||
|
|
|
|
|
(id->tag & LIB_TAG_PRE_EXISTING) == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (id->override_library->reference->lib == library) {
|
|
|
|
|
BKE_lib_override_library_update(bmain, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_ID_END;
|
|
|
|
|
|
2020-07-23 17:03:02 +02:00
|
|
|
BKE_main_collection_sync(bmain);
|
|
|
|
|
|
2016-07-19 17:49:01 +02:00
|
|
|
BKE_main_lib_objects_recalc_all(bmain);
|
|
|
|
|
IMB_colormanagement_check_file_config(bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-19 17:49:01 +02:00
|
|
|
/* important we unset, otherwise these object wont
|
|
|
|
|
* link into other scenes from this blend file */
|
|
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-19 17:49:01 +02:00
|
|
|
/* recreate dependency graph to include new objects */
|
2017-10-24 16:47:34 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2016-07-19 17:49:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WM_lib_reload(Library *lib, bContext *C, ReportList *reports)
|
|
|
|
|
{
|
2020-06-23 09:54:07 +10:00
|
|
|
if (!BLO_has_bfile_extension(lib->filepath_abs)) {
|
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "'%s' is not a valid library filepath", lib->filepath_abs);
|
2016-07-19 17:49:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 09:54:07 +10:00
|
|
|
if (!BLI_exists(lib->filepath_abs)) {
|
2016-07-19 17:49:01 +02:00
|
|
|
BKE_reportf(reports,
|
|
|
|
|
RPT_ERROR,
|
|
|
|
|
"Trying to reload library '%s' from invalid path '%s'",
|
|
|
|
|
lib->id.name,
|
2020-06-23 09:54:07 +10:00
|
|
|
lib->filepath_abs);
|
2016-07-19 17:49:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:09:13 +01:00
|
|
|
WMLinkAppendData *lapp_data = wm_link_append_data_new(BLO_LIBLINK_USE_PLACEHOLDERS |
|
|
|
|
|
BLO_LIBLINK_FORCE_INDIRECT);
|
2016-07-19 17:49:01 +02:00
|
|
|
|
2020-06-23 09:54:07 +10:00
|
|
|
wm_link_append_data_library_add(lapp_data, lib->filepath_abs);
|
2016-07-19 17:49:01 +02:00
|
|
|
|
2017-10-24 16:47:34 +02:00
|
|
|
lib_relocate_do(CTX_data_main(C), lib, lapp_data, reports, true);
|
2016-07-19 17:49:01 +02:00
|
|
|
|
|
|
|
|
wm_link_append_data_free(lapp_data);
|
|
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
|
|
|
|
|
{
|
|
|
|
|
Library *lib;
|
|
|
|
|
char lib_name[MAX_NAME];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
RNA_string_get(op->ptr, "library", lib_name);
|
2018-05-31 16:04:04 +02:00
|
|
|
lib = (Library *)BKE_libblock_find_name(CTX_data_main(C), ID_LI, lib_name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
if (lib) {
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
WMLinkAppendData *lapp_data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
char path[FILE_MAX], root[FILE_MAXDIR], libname[FILE_MAX], relname[FILE_MAX];
|
|
|
|
|
short flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
if (RNA_boolean_get(op->ptr, "relative_path")) {
|
|
|
|
|
flag |= FILE_RELPATH;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
if (lib->parent && !do_reload) {
|
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
|
RPT_ERROR_INVALID_INPUT,
|
|
|
|
|
"Cannot relocate indirectly linked library '%s'",
|
2020-06-23 09:54:07 +10:00
|
|
|
lib->filepath_abs);
|
2016-06-22 18:05:55 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
RNA_string_get(op->ptr, "directory", root);
|
|
|
|
|
RNA_string_get(op->ptr, "filename", libname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
if (!BLO_has_bfile_extension(libname)) {
|
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Not a library");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
BLI_join_dirfile(path, sizeof(path), root, libname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-22 18:05:55 +02:00
|
|
|
if (!BLI_exists(path)) {
|
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
|
RPT_ERROR_INVALID_INPUT,
|
|
|
|
|
"Trying to reload or relocate library '%s' to invalid path '%s'",
|
|
|
|
|
lib->id.name,
|
|
|
|
|
path);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-13 11:43:32 +02:00
|
|
|
if (BLI_path_cmp(BKE_main_blendfile_path(bmain), path) == 0) {
|
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
|
RPT_ERROR_INVALID_INPUT,
|
|
|
|
|
"Cannot relocate library '%s' to current blend file '%s'",
|
|
|
|
|
lib->id.name,
|
|
|
|
|
path);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 09:54:07 +10:00
|
|
|
if (BLI_path_cmp(lib->filepath_abs, path) == 0) {
|
2016-06-22 18:05:55 +02:00
|
|
|
#ifdef PRINT_DEBUG
|
|
|
|
|
printf("We are supposed to reload '%s' lib (%d)...\n", lib->filepath, lib->id.us);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
do_reload = true;
|
|
|
|
|
|
|
|
|
|
lapp_data = wm_link_append_data_new(flag);
|
|
|
|
|
wm_link_append_data_library_add(lapp_data, path);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int totfiles = 0;
|
|
|
|
|
|
|
|
|
|
#ifdef PRINT_DEBUG
|
|
|
|
|
printf("We are supposed to relocate '%s' lib to new '%s' one...\n", lib->filepath, libname);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Check if something is indicated for relocate. */
|
|
|
|
|
prop = RNA_struct_find_property(op->ptr, "files");
|
|
|
|
|
if (prop) {
|
|
|
|
|
totfiles = RNA_property_collection_length(op->ptr, prop);
|
|
|
|
|
if (totfiles == 0) {
|
|
|
|
|
if (!libname[0]) {
|
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lapp_data = wm_link_append_data_new(flag);
|
|
|
|
|
|
|
|
|
|
if (totfiles) {
|
|
|
|
|
RNA_BEGIN (op->ptr, itemptr, "files") {
|
|
|
|
|
RNA_string_get(&itemptr, "name", relname);
|
|
|
|
|
|
|
|
|
|
BLI_join_dirfile(path, sizeof(path), root, relname);
|
|
|
|
|
|
2020-06-23 09:54:07 +10:00
|
|
|
if (BLI_path_cmp(path, lib->filepath_abs) == 0 || !BLO_has_bfile_extension(relname)) {
|
2016-06-22 18:05:55 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef PRINT_DEBUG
|
|
|
|
|
printf("\t candidate new lib to reload datablocks from: %s\n", path);
|
|
|
|
|
#endif
|
|
|
|
|
wm_link_append_data_library_add(lapp_data, path);
|
|
|
|
|
}
|
|
|
|
|
RNA_END;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#ifdef PRINT_DEBUG
|
|
|
|
|
printf("\t candidate new lib to reload datablocks from: %s\n", path);
|
|
|
|
|
#endif
|
|
|
|
|
wm_link_append_data_library_add(lapp_data, path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:09:13 +01:00
|
|
|
if (do_reload) {
|
|
|
|
|
lapp_data->flag |= BLO_LIBLINK_USE_PLACEHOLDERS | BLO_LIBLINK_FORCE_INDIRECT;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 16:47:34 +02:00
|
|
|
lib_relocate_do(bmain, lib, lapp_data, op->reports, do_reload);
|
2016-06-22 18:05:55 +02:00
|
|
|
|
|
|
|
|
wm_link_append_data_free(lapp_data);
|
|
|
|
|
|
|
|
|
|
/* XXX TODO: align G.lib with other directory storage (like last opened image etc...) */
|
|
|
|
|
BLI_strncpy(G.lib, root, FILE_MAX);
|
|
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int wm_lib_relocate_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
return wm_lib_relocate_exec_do(C, op, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WM_OT_lib_relocate(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
|
|
ot->name = "Relocate Library";
|
|
|
|
|
ot->idname = "WM_OT_lib_relocate";
|
|
|
|
|
ot->description = "Relocate the given library to one or several others";
|
|
|
|
|
|
|
|
|
|
ot->invoke = wm_lib_relocate_invoke;
|
|
|
|
|
ot->exec = wm_lib_relocate_exec;
|
|
|
|
|
|
|
|
|
|
ot->flag |= OPTYPE_UNDO;
|
|
|
|
|
|
|
|
|
|
prop = RNA_def_string(ot->srna, "library", NULL, MAX_NAME, "Library", "Library to relocate");
|
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
|
|
|
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_BLENDER,
|
|
|
|
|
FILE_BLENDER,
|
|
|
|
|
FILE_OPENFILE,
|
|
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILENAME |
|
|
|
|
|
WM_FILESEL_FILES | WM_FILESEL_RELPATH,
|
|
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int wm_lib_reload_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
return wm_lib_relocate_exec_do(C, op, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WM_OT_lib_reload(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
|
|
ot->name = "Reload Library";
|
|
|
|
|
ot->idname = "WM_OT_lib_reload";
|
|
|
|
|
ot->description = "Reload the given library";
|
|
|
|
|
|
|
|
|
|
ot->exec = wm_lib_reload_exec;
|
|
|
|
|
|
|
|
|
|
ot->flag |= OPTYPE_UNDO;
|
|
|
|
|
|
|
|
|
|
prop = RNA_def_string(ot->srna, "library", NULL, MAX_NAME, "Library", "Library to reload");
|
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
|
|
|
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_BLENDER,
|
|
|
|
|
FILE_BLENDER,
|
|
|
|
|
FILE_OPENFILE,
|
|
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILENAME |
|
|
|
|
|
WM_FILESEL_RELPATH,
|
|
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2016-06-22 18:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|