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:
authorDalai Felinto <dfelinto@gmail.com>2018-03-28 20:54:17 +0300
committerDalai Felinto <dfelinto@gmail.com>2018-03-28 23:14:51 +0300
commitf167226b793e5dd39816f0b250771177d088dc54 (patch)
tree96b569a678b998f4f8b869192bd4bedf19219663 /source/blender/blenkernel/intern/collection.c
parent205fe8afd7011ca8db2dc14579dec6a088b9086f (diff)
Move to Collection - initial operator
How to use: Select a few objects, and press "M" in the viewport. If you hold ctrl the objects will be added to the selected collection. Otherwise they are removed from all their original collections and moved to the selected one instead. Development Notes ================= The ideal solution would be to implement an elegant generic multi-level menu system similar to toolbox_generic() in 2.49. Instead I used `uiItemMenuF` to acchieve the required nesting of the menus. The downside is that `uiItemMenuF` requires the data its callback uses to be always valid until the menu is discarded. But since there is no callback we can call when the menu is discarded for operators that exited with `OPERATOR_INTERFACE`. That means we are using static allocated data, that is only freed next time the operator is called. Which also means there will always be some memory leakage. Reviewers: campbellbarton Differential Revision: https://developer.blender.org/D3117
Diffstat (limited to 'source/blender/blenkernel/intern/collection.c')
-rw-r--r--source/blender/blenkernel/intern/collection.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index fb27249402b..880d28970c0 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -458,19 +458,11 @@ bool BKE_collection_object_remove(Main *bmain, ID *owner_id, SceneCollection *sc
}
/**
- * Move object from a collection into another
- */
-void BKE_collection_object_move(ID *owner_id, SceneCollection *sc_dst, SceneCollection *sc_src, Object *ob)
-{
- if (BKE_collection_object_add(owner_id, sc_dst, ob)) {
- BKE_collection_object_remove(NULL, owner_id, sc_src, ob, false);
- }
-}
-
-/**
* Remove object from all collections of scene
+ * \param scene_collection_skip: Don't remove base from this collection.
*/
-bool BKE_collections_object_remove(Main *bmain, ID *owner_id, Object *ob, const bool free_us)
+static bool collections_object_remove_ex(Main *bmain, ID *owner_id, Object *ob, const bool free_us,
+ SceneCollection *scene_collection_skip)
{
bool removed = false;
if (GS(owner_id->name) == ID_SCE) {
@@ -482,12 +474,44 @@ bool BKE_collections_object_remove(Main *bmain, ID *owner_id, Object *ob, const
FOREACH_SCENE_COLLECTION_BEGIN(owner_id, sc)
{
- removed |= BKE_collection_object_remove(bmain, owner_id, sc, ob, free_us);
+ if (sc != scene_collection_skip) {
+ removed |= BKE_collection_object_remove(bmain, owner_id, sc, ob, free_us);
+ }
}
FOREACH_SCENE_COLLECTION_END;
return removed;
}
+/**
+ * Remove object from all collections of scene
+ */
+bool BKE_collections_object_remove(Main *bmain, ID *owner_id, Object *ob, const bool free_us)
+{
+ return collections_object_remove_ex(bmain, owner_id, ob, free_us, NULL);
+}
+
+/**
+ * Move object from a collection into another
+ *
+ * If source collection is NULL move it from all the existing collections.
+ */
+void BKE_collection_object_move(ID *owner_id, SceneCollection *sc_dst, SceneCollection *sc_src, Object *ob)
+{
+ /* In both cases we first add the object, then remove it from the other collections.
+ * Otherwise we lose the original base and whether it was active and selected. */
+ if (sc_src != NULL) {
+ if (BKE_collection_object_add(owner_id, sc_dst, ob)) {
+ BKE_collection_object_remove(NULL, owner_id, sc_src, ob, false);
+ }
+ }
+ else {
+ /* Adding will fail if object is already in collection.
+ * However we still need to remove it from the other collections. */
+ BKE_collection_object_add(owner_id, sc_dst, ob);
+ collections_object_remove_ex(NULL, owner_id, ob, false, sc_dst);
+ }
+}
+
static void layer_collection_sync(LayerCollection *lc_dst, LayerCollection *lc_src)
{
lc_dst->flag = lc_src->flag;