Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/util/ed_util.c')
-rw-r--r--source/blender/editors/util/ed_util.c122
1 files changed, 73 insertions, 49 deletions
diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c
index 73f328f85d7..0320a2a9a1a 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -33,7 +33,9 @@
#include "BLT_translation.h"
+#include "BKE_collection.h"
#include "BKE_global.h"
+#include "BKE_lib_remap.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_multires.h"
@@ -121,48 +123,66 @@ void ED_editors_init(bContext *C)
continue;
}
+ /* Reset object to Object mode, so that code below can properly re-switch it to its
+ * previous mode if possible, re-creating its mode data, etc. */
ID *ob_data = ob->data;
ob->mode = OB_MODE_OBJECT;
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
- if (obact && (ob->type == obact->type) && !ID_IS_LINKED(ob) &&
- !(ob_data && ID_IS_LINKED(ob_data))) {
- if (mode == OB_MODE_EDIT) {
- ED_object_editmode_enter_ex(bmain, scene, ob, 0);
- }
- else if (mode == OB_MODE_POSE) {
- ED_object_posemode_enter_ex(bmain, ob);
- }
- else if (mode & OB_MODE_ALL_SCULPT) {
- if (obact == ob) {
- if (mode == OB_MODE_SCULPT) {
- ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, true, reports);
- }
- else if (mode == OB_MODE_VERTEX_PAINT) {
- ED_object_vpaintmode_enter_ex(bmain, depsgraph, scene, ob);
- }
- else if (mode == OB_MODE_WEIGHT_PAINT) {
- ED_object_wpaintmode_enter_ex(bmain, depsgraph, scene, ob);
- }
- else {
- BLI_assert_unreachable();
- }
+
+ /* Object mode is enforced if there is no active object, or if the active object's type is
+ * different. */
+ if (obact == NULL || ob->type != obact->type) {
+ continue;
+ }
+ /* Object mode is enforced for linked data (or their obdata). */
+ if (ID_IS_LINKED(ob) || (ob_data != NULL && ID_IS_LINKED(ob_data))) {
+ continue;
+ }
+
+ /* Pose mode is very similar to Object one, we can apply it even on objects not in current
+ * scene. */
+ if (mode == OB_MODE_POSE) {
+ ED_object_posemode_enter_ex(bmain, ob);
+ }
+
+ /* Other edit/paint/etc. modes are only settable for objects in active scene currently. */
+ if (!BKE_collection_has_object_recursive(scene->master_collection, ob)) {
+ continue;
+ }
+
+ if (mode == OB_MODE_EDIT) {
+ ED_object_editmode_enter_ex(bmain, scene, ob, 0);
+ }
+ else if (mode & OB_MODE_ALL_SCULPT) {
+ if (obact == ob) {
+ if (mode == OB_MODE_SCULPT) {
+ ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, true, reports);
+ }
+ else if (mode == OB_MODE_VERTEX_PAINT) {
+ ED_object_vpaintmode_enter_ex(bmain, depsgraph, scene, ob);
+ }
+ else if (mode == OB_MODE_WEIGHT_PAINT) {
+ ED_object_wpaintmode_enter_ex(bmain, depsgraph, scene, ob);
}
else {
- /* Create data for non-active objects which need it for
- * mode-switching but don't yet support multi-editing. */
- if (mode & OB_MODE_ALL_SCULPT) {
- ob->mode = mode;
- BKE_object_sculpt_data_create(ob);
- }
+ BLI_assert_unreachable();
}
}
else {
- /* TODO(campbell): avoid operator calls. */
- if (obact == ob) {
- ED_object_mode_set(C, mode);
+ /* Create data for non-active objects which need it for
+ * mode-switching but don't yet support multi-editing. */
+ if (mode & OB_MODE_ALL_SCULPT) {
+ ob->mode = mode;
+ BKE_object_sculpt_data_create(ob);
}
}
}
+ else {
+ /* TODO(campbell): avoid operator calls. */
+ if (obact == ob) {
+ ED_object_mode_set(C, mode);
+ }
+ }
}
/* image editor paint mode */
@@ -176,7 +196,6 @@ void ED_editors_init(bContext *C)
wm->op_undo_depth--;
}
-/* frees all editmode stuff */
void ED_editors_exit(Main *bmain, bool do_undo_system)
{
if (!bmain) {
@@ -272,8 +291,6 @@ bool ED_editors_flush_edits_for_object(Main *bmain, Object *ob)
return ED_editors_flush_edits_for_object_ex(bmain, ob, false, false);
}
-/* flush any temp data from object editing to DNA before writing files,
- * rendering, copying, etc. */
bool ED_editors_flush_edits_ex(Main *bmain, bool for_render, bool check_needs_flush)
{
bool has_edited = false;
@@ -298,11 +315,6 @@ bool ED_editors_flush_edits(Main *bmain)
/* ***** XXX: functions are using old blender names, cleanup later ***** */
-/**
- * Now only used in 2D spaces, like time, f-curve, NLA, image, etc.
- *
- * \note Shift/Control are not configurable key-bindings.
- */
void apply_keyb_grid(
int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert)
{
@@ -341,6 +353,7 @@ void unpack_menu(bContext *C,
uiLayout *layout;
char line[FILE_MAX + 100];
wmOperatorType *ot = WM_operatortype_find(opname, 1);
+ const char *blendfile_path = BKE_main_blendfile_path(bmain);
pup = UI_popup_menu_begin(C, IFACE_("Unpack File"), ICON_NONE);
layout = UI_popup_menu_layout(pup);
@@ -350,13 +363,13 @@ void unpack_menu(bContext *C,
RNA_enum_set(&props_ptr, "method", PF_REMOVE);
RNA_string_set(&props_ptr, "id", id_name);
- if (G.relbase_valid) {
+ if (blendfile_path[0] != '\0') {
char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
BLI_split_file_part(abs_name, fi, sizeof(fi));
BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi);
if (!STREQ(abs_name, local_name)) {
- switch (BKE_packedfile_compare_to_file(BKE_main_blendfile_path(bmain), local_name, pf)) {
+ switch (BKE_packedfile_compare_to_file(blendfile_path, local_name, pf)) {
case PF_CMP_NOFILE:
BLI_snprintf(line, sizeof(line), TIP_("Create %s"), local_name);
uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr);
@@ -389,7 +402,7 @@ void unpack_menu(bContext *C,
}
}
- switch (BKE_packedfile_compare_to_file(BKE_main_blendfile_path(bmain), abs_name, pf)) {
+ switch (BKE_packedfile_compare_to_file(blendfile_path, abs_name, pf)) {
case PF_CMP_NOFILE:
BLI_snprintf(line, sizeof(line), TIP_("Create %s"), abs_name);
// uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL);
@@ -422,16 +435,27 @@ void unpack_menu(bContext *C,
UI_popup_menu_end(C, pup);
}
-/**
- * Use to free ID references within runtime data (stored outside of DNA)
- *
- * \param new_id: may be NULL to unlink \a old_id.
- */
-void ED_spacedata_id_remap(struct ScrArea *area, struct SpaceLink *sl, ID *old_id, ID *new_id)
+void ED_spacedata_id_remap(struct ScrArea *area,
+ struct SpaceLink *sl,
+ const struct IDRemapper *mappings)
+{
+ SpaceType *st = BKE_spacetype_from_id(sl->spacetype);
+ if (st && st->id_remap) {
+ st->id_remap(area, sl, mappings);
+ }
+}
+
+void ED_spacedata_id_remap_single(struct ScrArea *area,
+ struct SpaceLink *sl,
+ ID *old_id,
+ ID *new_id)
{
SpaceType *st = BKE_spacetype_from_id(sl->spacetype);
if (st && st->id_remap) {
- st->id_remap(area, sl, old_id, new_id);
+ struct IDRemapper *mappings = BKE_id_remapper_create();
+ BKE_id_remapper_add(mappings, old_id, new_id);
+ st->id_remap(area, sl, mappings);
+ BKE_id_remapper_free(mappings);
}
}