Blender V5.3
outliner_tools.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "CLG_log.h"
12
13#include "DNA_anim_types.h"
14#include "DNA_armature_types.h"
17#include "DNA_curves_types.h"
19#include "DNA_light_types.h"
20#include "DNA_linestyle_types.h"
21#include "DNA_material_types.h"
22#include "DNA_mesh_types.h"
23#include "DNA_meta_types.h"
24#include "DNA_modifier_types.h"
25#include "DNA_object_types.h"
27#include "DNA_scene_types.h"
28#include "DNA_sequence_types.h"
29#include "DNA_volume_types.h"
30#include "DNA_world_types.h"
31
32#include "BLI_listbase.hh"
33#include "BLI_map.hh"
34#include "BLI_set.hh"
35#include "BLI_string.hh"
36#include "BLI_utildefines.hh"
37#include "BLI_vector.hh"
38
39#include "BLT_translation.hh"
40
41#include "BKE_anim_data.hh"
42#include "BKE_animsys.hh"
43#include "BKE_armature.hh"
44#include "BKE_collection.hh"
45#include "BKE_constraint.h"
46#include "BKE_context.hh"
47#include "BKE_fcurve.hh"
48#include "BKE_global.hh"
49#include "BKE_grease_pencil.hh"
50#include "BKE_idtype.hh"
51#include "BKE_image.hh"
52#include "BKE_layer.hh"
53#include "BKE_lib_id.hh"
54#include "BKE_lib_override.hh"
55#include "BKE_lib_query.hh"
56#include "BKE_lib_remap.hh"
57#include "BKE_library.hh"
58#include "BKE_main.hh"
60#include "BKE_object.hh"
61#include "BKE_report.hh"
62#include "BKE_scene.hh"
63#include "BKE_screen.hh"
64
65#include "DEG_depsgraph.hh"
67
68#include "ED_node.hh"
69#include "ED_object.hh"
70#include "ED_outliner.hh"
71#include "ED_scene.hh"
72#include "ED_screen.hh"
73#include "ED_sequencer.hh"
74#include "ED_undo.hh"
75#include "ED_util.hh"
76
77#include "WM_api.hh"
78#include "WM_message.hh"
79#include "WM_types.hh"
80
81#include "UI_interface.hh"
83#include "UI_resources.hh"
84#include "UI_view2d.hh"
85
87
88#include "RNA_access.hh"
89#include "RNA_define.hh"
90#include "RNA_enum_types.hh"
91
92#include "ANIM_action_legacy.hh"
93#include "ANIM_armature.hh"
94
95#include "SEQ_relations.hh"
96#include "SEQ_sequencer.hh"
97
98#include "outliner_intern.hh"
99#include "tree/tree_element.hh"
104#include "tree/tree_iterator.hh"
105
106namespace blender::ed::outliner {
107
108static CLG_LogRef LOG = {"outliner.tools"};
109
110/* -------------------------------------------------------------------- */
113
115 const TreeElement *te, int *scenelevel, int *objectlevel, int *idlevel, int *datalevel)
116{
117 *scenelevel = *objectlevel = *idlevel = *datalevel = 0;
118
119 const TreeStoreElem *tselem = TREESTORE(te);
120 if ((tselem->flag & TSE_SELECTED) == 0) {
121 return;
122 }
123
124 /* Layer collection points to collection ID. */
125 if (!ELEM(tselem->type, TSE_SOME_ID, TSE_LAYER_COLLECTION)) {
126 *datalevel = tselem->type;
127 }
128 else {
129 const ID_Type idcode = tselem->id->id_type();
130 bool is_standard_id = false;
131 switch (idcode) {
132 case ID_SCE:
133 *scenelevel = 1;
134 break;
135 case ID_OB:
136 *objectlevel = 1;
137 break;
138
139 case ID_ME:
140 case ID_CU_LEGACY:
141 case ID_MB:
142 case ID_LT:
143 case ID_LA:
144 case ID_AR:
145 case ID_CA:
146 case ID_SPK:
147 case ID_MA:
148 case ID_TE:
149 case ID_IM:
150 case ID_SO:
151 case ID_KE:
152 case ID_WO:
153 case ID_AC:
154 case ID_TXT:
155 case ID_GR:
156 case ID_LS:
157 case ID_LI:
158 case ID_VF:
159 case ID_NT:
160 case ID_BR:
161 case ID_PA:
162 case ID_GD_LEGACY:
163 case ID_MC:
164 case ID_MSK:
165 case ID_PAL:
166 case ID_PC:
167 case ID_CF:
168 case ID_WS:
169 case ID_LP:
170 case ID_CV:
171 case ID_PT:
172 case ID_VO:
173 case ID_GP:
174 is_standard_id = true;
175 break;
176 case ID_WM:
177 case ID_SCR:
178 /* Those are ignored here. */
179 /* NOTE: while Screens should be manageable here, deleting a screen used by a workspace
180 * will cause crashes when trying to use that workspace, so for now let's play minimal,
181 * safe change. */
182 break;
183 }
184 if (idcode == ID_NLA) {
185 /* Fake one, not an actual ID type... */
186 is_standard_id = true;
187 }
188
189 if (is_standard_id) {
190 *idlevel = idcode;
191 }
192 }
193
194 /* Return values are exclusive, only one may be non-null. */
195 BLI_assert(((*scenelevel != 0) && (*objectlevel == 0) && (*idlevel == 0) && (*datalevel == 0)) ||
196 ((*scenelevel == 0) && (*objectlevel != 0) && (*idlevel == 0) && (*datalevel == 0)) ||
197 ((*scenelevel == 0) && (*objectlevel == 0) && (*idlevel != 0) && (*datalevel == 0)) ||
198 ((*scenelevel == 0) && (*objectlevel == 0) && (*idlevel == 0) && (*datalevel != 0)) ||
199 /* All null. */
200 ((*scenelevel == 0) && (*objectlevel == 0) && (*idlevel == 0) && (*datalevel == 0)));
201}
202
203static TreeElement *get_target_element(const SpaceOutliner *space_outliner)
204{
206
207 return te;
208}
209
211{
213 return false;
214 }
215 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
216 TreeElement *te = get_target_element(space_outliner);
217 if (te == nullptr) {
218 return false;
219 }
220
221 return true;
222}
223
225 ReportList *reports,
226 Scene * /*scene*/,
227 TreeElement * /*te*/,
228 TreeStoreElem *tsep,
229 TreeStoreElem *tselem)
230{
231 if (!tsep || !TSE_IS_REAL_ID(tsep)) {
232 /* Valid case, no parent element of the action or it is not an ID (could be a #TSE_ID_BASE
233 * for example) so there's no data to unlink from. */
234 BKE_reportf(reports,
236 "Cannot unlink action '%s'. It's not clear which object or object-data it "
237 "should be unlinked from, there's no object or object-data as parent in the "
238 "Outliner tree",
239 tselem->id->name + 2);
240 return;
241 }
242
243 /* just set action to nullptr */
244 BKE_animdata_set_action(CTX_wm_reports(C), tsep->id, nullptr);
245}
246
247static void unlink_material_fn(bContext * /*C*/,
248 ReportList *reports,
249 Scene * /*scene*/,
250 TreeElement *te,
251 TreeStoreElem *tsep,
252 TreeStoreElem *tselem)
253{
254 const bool te_is_material = TSE_IS_REAL_ID(tselem) && (tselem->id->id_type() == ID_MA);
255
256 if (!te_is_material) {
257 /* Just fail silently. Another element may be selected that is a material, we don't want to
258 * confuse users with an error in that case. */
259 return;
260 }
261
262 if (!tsep || !TSE_IS_REAL_ID(tsep)) {
263 /* Valid case, no parent element of the material or it is not an ID (could be a #TSE_ID_BASE
264 * for example) so there's no data to unlink from. */
265 BKE_reportf(reports,
267 "Cannot unlink material '%s'. It's not clear which object or object-data it "
268 "should be unlinked from, there's no object or object-data as parent in the "
269 "Outliner tree",
270 tselem->id->name + 2);
271 return;
272 }
273
274 if (!ID_IS_EDITABLE(tsep->id) || ID_IS_OVERRIDE_LIBRARY(tsep->id)) {
275 BKE_reportf(reports,
277 "Cannot unlink the material '%s' from linked object data",
278 tselem->id->name + 2);
279 return;
280 }
281
282 Material **matar = nullptr;
283 int a, totcol = 0;
284
285 switch (tsep->id->id_type()) {
286 case ID_OB: {
287 Object *ob = id_cast<Object *>(tsep->id);
288 totcol = ob->totcol;
289 matar = ob->mat;
290 break;
291 }
292 case ID_ME: {
293 Mesh *mesh = id_cast<Mesh *>(tsep->id);
294 totcol = mesh->totcol;
295 matar = mesh->mat;
296 break;
297 }
298 case ID_CU_LEGACY: {
299 Curve *cu = id_cast<Curve *>(tsep->id);
300 totcol = cu->totcol;
301 matar = cu->mat;
302 break;
303 }
304 case ID_MB: {
305 MetaBall *mb = id_cast<MetaBall *>(tsep->id);
306 totcol = mb->totcol;
307 matar = mb->mat;
308 break;
309 }
310 case ID_CV: {
311 Curves *curves = id_cast<Curves *>(tsep->id);
312 totcol = curves->totcol;
313 matar = curves->mat;
314 break;
315 }
316 case ID_PT: {
317 PointCloud *pointcloud = id_cast<PointCloud *>(tsep->id);
318 totcol = pointcloud->totcol;
319 matar = pointcloud->mat;
320 break;
321 }
322 case ID_VO: {
323 Volume *volume = id_cast<Volume *>(tsep->id);
324 totcol = volume->totcol;
325 matar = volume->mat;
326 break;
327 }
328 default:
330 }
331
332 if (matar != nullptr) [[likely]] {
333 for (a = 0; a < totcol; a++) {
334 if (a == te->index && matar[a]) {
335 id_us_min(&matar[a]->id);
336 matar[a] = nullptr;
337 }
338 }
339 }
340}
341
342static void unlink_texture_fn(bContext * /*C*/,
343 ReportList *reports,
344 Scene * /*scene*/,
345 TreeElement *te,
346 TreeStoreElem *tsep,
347 TreeStoreElem *tselem)
348{
349 if (!tsep || !TSE_IS_REAL_ID(tsep)) {
350 /* Valid case, no parent element of the texture or it is not an ID (could be a #TSE_ID_BASE
351 * for example) so there's no data to unlink from. */
352 BKE_reportf(reports,
354 "Cannot unlink texture '%s'. It's not clear which Freestyle line style it should "
355 "be unlinked from, there's no Freestyle line style as parent in the Outliner tree",
356 tselem->id->name + 2);
357 return;
358 }
359
360 MTex **mtex = nullptr;
361 int a;
362
363 if (tsep->id->id_type() == ID_LS) {
364 FreestyleLineStyle *ls = id_cast<FreestyleLineStyle *>(tsep->id);
365 mtex = ls->mtex;
366 }
367 else {
368 return;
369 }
370
371 for (a = 0; a < MAX_MTEX; a++) {
372 if (a == te->index && mtex[a]) {
373 if (mtex[a]->tex) {
374 id_us_min(&mtex[a]->tex->id);
375 mtex[a]->tex = nullptr;
376 }
377 }
378 }
379}
380
382 ReportList *reports,
383 Scene * /*scene*/,
384 TreeElement * /*te*/,
385 TreeStoreElem *tsep,
386 TreeStoreElem *tselem)
387{
388 Main *bmain = CTX_data_main(C);
389 Collection *collection = id_cast<Collection *>(tselem->id);
390
391 if (!tsep || !TSE_IS_REAL_ID(tsep)) {
392 /* Valid case, no parent element of the collection or it is not an ID (could be a #TSE_ID_BASE
393 * for example) so there's no data to unlink from. */
394 BKE_reportf(reports,
396 "Cannot unlink collection '%s'. It's not clear which scene, collection or "
397 "instance empties it should be unlinked from, there's no scene, collection or "
398 "instance empties as parent in the Outliner tree",
399 tselem->id->name + 2);
400 return;
401 }
402
403 if (tsep && (!ID_IS_EDITABLE(tsep->id) || ID_IS_OVERRIDE_LIBRARY(tsep->id))) {
404 BKE_reportf(reports,
406 "Cannot unlink collection '%s' parented to another linked collection '%s'",
407 collection->id.name + 2,
408 tsep->id->name + 2);
409 return;
410 }
411
412 if (tsep) {
413 if (tsep->id->id_type() == ID_OB) {
414 Object *ob = id_cast<Object *>(tsep->id);
415 ob->instance_collection = nullptr;
418 }
419 else if (tsep->id->id_type() == ID_GR) {
420 Collection *parent = id_cast<Collection *>(tsep->id);
421 id_fake_user_set(&collection->id);
422 BKE_collection_child_remove(bmain, parent, collection);
425 }
426 else if (tsep->id->id_type() == ID_SCE) {
427 Scene *scene = id_cast<Scene *>(tsep->id);
428 Collection *parent = scene->master_collection;
429 id_fake_user_set(&collection->id);
430 BKE_collection_child_remove(bmain, parent, collection);
433 }
434 }
435}
436
438 ReportList *reports,
439 Scene * /*scene*/,
440 TreeElement *te,
441 TreeStoreElem *tsep,
442 TreeStoreElem *tselem)
443{
444 if (!tsep || !TSE_IS_REAL_ID(tsep)) {
445 BKE_reportf(reports,
447 "Cannot unlink object '%s'. It's not clear which collection or scene it should be "
448 "unlinked from, there's no collection or scene as parent in the Outliner tree",
449 tselem->id->name + 2);
450 return;
451 }
452
453 Main *bmain = CTX_data_main(C);
454 Object *ob = id_cast<Object *>(tselem->id);
455 const eSpaceOutliner_Mode outliner_mode = eSpaceOutliner_Mode(
456 CTX_wm_space_outliner(C)->outlinevis);
457
458 if (tsep->id->id_type() == ID_OB) {
459 /* Parented objects need to find which collection to unlink from. */
460 TreeElement *te_parent = te->parent;
461 while (tsep && tsep->id->id_type() == ID_OB) {
462 if (!ID_IS_EDITABLE(tsep->id)) {
463 BKE_reportf(reports,
465 "Cannot unlink object '%s' parented to another linked object '%s'",
466 ob->id.name + 2,
467 tsep->id->name + 2);
468 return;
469 }
470 te_parent = te_parent->parent;
471 tsep = te_parent ? TREESTORE(te_parent) : nullptr;
472 }
473 }
474
475 if (tsep && tsep->id) {
476 if (!ID_IS_EDITABLE(tsep->id) || ID_IS_OVERRIDE_LIBRARY(tsep->id)) {
477 BKE_reportf(reports,
479 "Cannot unlink object '%s' from linked collection or scene '%s'",
480 ob->id.name + 2,
481 tsep->id->name + 2);
482 return;
483 }
484 switch (tsep->id->id_type()) {
485 case ID_GR: {
486 Collection *parent = id_cast<Collection *>(tsep->id);
487 BKE_collection_object_remove(bmain, parent, ob, true);
489 break;
490 }
491 case ID_SCE: {
492 Scene *scene = reinterpret_cast<Scene *>(tsep->id);
493 /* In Scene view, remove the object from all collections in the scene. */
494 if (outliner_mode == SO_SCENES) {
495 FOREACH_SCENE_COLLECTION_BEGIN (scene, collection) {
496 if (BKE_collection_has_object(collection, ob)) {
497 BKE_collection_object_remove(bmain, collection, ob, true);
498 DEG_id_tag_update(&collection->id, ID_RECALC_HIERARCHY);
500 }
501 }
503 }
504 /* Otherwise, remove the object from the scene's main collection. */
505 else {
506 Collection *parent = scene->master_collection;
507 BKE_collection_object_remove(bmain, parent, ob, true);
509 }
510 break;
511 }
512 default: {
513 /* Un-handled case, should never be reached. */
515 return;
516 }
517 }
518 /* NOTE: Cannot risk tagging the object here, as it may have been deleted if its last usage
519 * was removed by above code. */
521 /* Clear selection flags. Tree store elements are reused by other matching tree elements, see:
522 * !159899 */
523 tselem->flag &= ~(TSE_ACTIVE | TSE_SELECTED);
525 }
526}
527
528static void unlink_world_fn(bContext * /*C*/,
529 ReportList *reports,
530 Scene * /*scene*/,
531 TreeElement * /*te*/,
532 TreeStoreElem *tsep,
533 TreeStoreElem *tselem)
534{
535 if (!tsep || !TSE_IS_REAL_ID(tsep)) {
536 /* Valid case, no parent element of the world or it is not an ID (could be a #TSE_ID_BASE
537 * for example) so there's no data to unlink from. */
538 BKE_reportf(reports,
540 "Cannot unlink world '%s'. It's not clear which scene it should be unlinked from, "
541 "there's no scene as parent in the Outliner tree",
542 tselem->id->name + 2);
543 return;
544 }
545
546 Scene *parscene = id_cast<Scene *>(tsep->id);
547 World *wo = id_cast<World *>(tselem->id);
548
549 /* need to use parent scene not just scene, otherwise may end up getting wrong one */
550 id_us_min(&wo->id);
551 parscene->world = nullptr;
552}
553
555 ReportList *reports,
556 Scene *scene,
557 SpaceOutliner *space_outliner,
558 outliner_operation_fn operation_fn)
559{
560 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
561 TreeStoreElem *tselem = TREESTORE(te);
562 if (tselem->flag & TSE_SELECTED) {
563 if (((tselem->type == TSE_SOME_ID) && (te->idcode != 0)) ||
564 tselem->type == TSE_LAYER_COLLECTION)
565 {
566 TreeStoreElem *tsep = te->parent ? TREESTORE(te->parent) : nullptr;
567 operation_fn(C, reports, scene, te, tsep, tselem);
568 }
569 }
570 });
571}
572
574 /* Only selected items. */
576 /* Only content 'inside' selected items (their sub-tree). */
578 /* Combining both options above. */
580};
581
584 "SELECTED",
585 0,
586 "Selected",
587 "Apply the operation over selected data-blocks only"},
589 "CONTENT",
590 0,
591 "Content",
592 "Apply the operation over content of the selected items only (the data-blocks in their "
593 "sub-tree)"},
595 "SELECTED_AND_CONTENT",
596 0,
597 "Selected & Content",
598 "Apply the operation over selected data-blocks and all their dependencies"},
599 {0, nullptr, 0, nullptr, nullptr},
600};
601
603 bContext *C,
604 ReportList *reports,
605 Scene *scene,
607 TreeStoreElem *tselem,
608 const bool has_parent_selected,
609 outliner_operation_fn operation_fn,
610 eOutlinerLibOpSelectionSet selection_set)
611{
612 const bool do_selected = ELEM(selection_set,
615 const bool do_content = ELEM(selection_set,
618
619 const bool is_selected = tselem->flag & TSE_SELECTED;
620 if ((is_selected && do_selected) || (has_parent_selected && do_content)) {
621 if (((tselem->type == TSE_SOME_ID) && (element->idcode != 0)) ||
622 tselem->type == TSE_LAYER_COLLECTION)
623 {
624 TreeStoreElem *tsep = element->parent ? TREESTORE(element->parent) : nullptr;
625 operation_fn(C, reports, scene, element, tsep, tselem);
626 }
627 }
628 return is_selected;
629}
630
632 ReportList *reports,
633 Scene *scene,
634 SpaceOutliner *space_outliner,
635 ListBaseT<TreeElement> &subtree,
636 const bool has_parent_selected,
637 outliner_operation_fn operation_fn,
638 eOutlinerLibOpSelectionSet selection_set)
639{
640 for (TreeElement &element : subtree.items_mutable()) {
641 /* Get needed data out in case element gets freed. */
642 TreeStoreElem *tselem = TREESTORE(&element);
643 ListBaseT<TreeElement> subtree = element.subtree;
644
646 C, reports, scene, &element, tselem, has_parent_selected, operation_fn, selection_set);
647
648 /* Don't access element from now on, it may be freed. Note that the open/collapsed state may
649 * also have been changed in the visitor callback. */
651 reports,
652 scene,
653 space_outliner,
654 subtree,
655 is_selected || has_parent_selected,
656 operation_fn,
657 selection_set);
658 }
659}
660
662 ReportList *reports,
663 Scene *scene,
664 SpaceOutliner *space_outliner,
665 outliner_operation_fn operation_fn,
666 eOutlinerLibOpSelectionSet selection_set,
667 const bool do_active_element_first)
668{
669 if (do_active_element_first) {
670 TreeElement *active_element = get_target_element(space_outliner);
671 if (active_element != nullptr) {
672 TreeStoreElem *tselem = TREESTORE(active_element);
673 ListBaseT<TreeElement> subtree = active_element->subtree;
674
676 C, reports, scene, active_element, tselem, false, operation_fn, selection_set);
677
678 /* Don't access element from now on, it may be freed. Note that the open/collapsed state may
679 * also have been changed in the visitor callback. */
681 C, reports, scene, space_outliner, subtree, is_selected, operation_fn, selection_set);
682 }
683 }
684
686 reports,
687 scene,
688 space_outliner,
689 space_outliner->runtime->tree,
690 false,
691 operation_fn,
692 selection_set);
693}
694
696
697/* -------------------------------------------------------------------- */
700
704
706 {OL_SCENE_OP_DELETE, "DELETE", ICON_X, "Delete", ""},
707 {0, nullptr, 0, nullptr, nullptr},
708};
709
711 bContext *C,
712 SpaceOutliner *space_outliner,
714 bool (*operation_fn)(bContext *, eOutliner_PropSceneOps, TreeElement *, TreeStoreElem *))
715{
716 bool success = false;
717
718 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
719 TreeStoreElem *tselem = TREESTORE(te);
720 if (tselem->flag & TSE_SELECTED) {
721 if ((tselem->type == TSE_SOME_ID) && (te->idcode == ID_SCE)) {
722 if (operation_fn(C, event, te, tselem)) {
723 success = true;
724 }
725 }
726 }
727 });
728
729 return success;
730}
731
732static bool scene_fn(bContext *C,
734 TreeElement * /*te*/,
735 TreeStoreElem *tselem)
736{
737 Scene *scene = id_cast<Scene *>(tselem->id);
738
739 if (event == OL_SCENE_OP_DELETE) {
740 if (ED_scene_delete(C, CTX_data_main(C), scene)) {
742 }
743 else {
744 return false;
745 }
746 }
747
748 return true;
749}
750
752{
753 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
755
756 if (outliner_do_scene_operation(C, space_outliner, event, scene_fn) == false) {
757 return OPERATOR_CANCELLED;
758 }
759
760 if (event == OL_SCENE_OP_DELETE) {
761 outliner_cleanup_tree(space_outliner);
762 ED_undo_push(C, "Delete Scene(s)");
763 }
764 else {
766 return OPERATOR_CANCELLED;
767 }
768
769 return OPERATOR_FINISHED;
770}
771
773{
774 /* identifiers */
775 ot->name = "Outliner Scene Operation";
776 ot->idname = "OUTLINER_OT_scene_operation";
777 ot->description = "Context menu for scene operations";
778
779 /* callbacks */
783
784 ot->flag = 0;
785
786 ot->prop = RNA_def_enum(ot->srna, "type", prop_scene_op_types, 0, "Scene Operation", "");
787}
788
790
791/* -------------------------------------------------------------------- */
794
804
805static void merged_element_search_fn_recursive(const ListBaseT<TreeElement> *tree,
806 short tselem_type,
807 short type,
808 const char *str,
809 ui::SearchItems *items)
810{
811 char name[64];
812 int iconid;
813
814 for (TreeElement &te : *tree) {
815 TreeStoreElem *tselem = TREESTORE(&te);
816
817 if (tree_element_id_type_to_index(&te) == type && tselem_type == tselem->type) {
818 if (BLI_strcasestr(te.name, str)) {
819 STRNCPY(name, te.name);
820
821 iconid = tree_element_get_icon(tselem, &te).icon;
823 const Collection &collection = *outliner_collection_from_tree_element(&te);
824 if (collection.color_tag != COLLECTION_COLOR_NONE) {
825 iconid = int(ICON_COLLECTION_COLOR_01) + int(collection.color_tag);
826 }
827 }
828
829 /* Don't allow duplicate named items */
830 if (search_items_find_index(items, name) == -1) {
831 if (!search_item_add(items, name, &te, iconid, 0, 0)) {
832 break;
833 }
834 }
835 }
836 }
837
838 merged_element_search_fn_recursive(&te.subtree, tselem_type, type, str, items);
839 }
840}
841
842/* Get a list of elements that match the search string */
844 void *data,
845 const char *str,
846 ui::SearchItems *items,
847 const bool /*is_first*/)
848{
849 MergedSearchData *search_data = static_cast<MergedSearchData *>(data);
850 TreeElement *parent = search_data->parent_element;
851 TreeElement *te = search_data->select_element;
852
853 int type = tree_element_id_type_to_index(te);
854
855 merged_element_search_fn_recursive(&parent->subtree, TREESTORE(te)->type, type, str, items);
856}
857
858/* Activate an element from the merged element search menu */
859static void merged_element_search_exec_fn(bContext *C, void * /*arg1*/, void *element)
860{
861 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
862 TreeElement *te = static_cast<TreeElement *>(element);
863
865
867}
868
874{
875 static char search[64] = "";
876 ui::Block *block;
877 ui::Button *but;
878
879 /* Clear search on each menu creation */
880 *search = '\0';
881
882 block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
884 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_POPUP);
885
886 short menu_width = 10 * UI_UNIT_X;
887 but = uiDefSearchBut(
888 block, search, ICON_VIEWZOOM, sizeof(search), 0, 0, menu_width, UI_UNIT_Y, "");
889 button_func_search_set(but,
890 nullptr,
892 data,
893 false,
894 nullptr,
896 nullptr);
897 button_flag_enable(but, ui::BUT_ACTIVATE_ON_INIT);
898
899 /* Fake button to hold space for search items */
900 const int height = ui::searchbox_size_y() - UI_SEARCHBOX_BOUNDS;
901 uiDefBut(block,
903 "",
904 0,
905 -height,
906 menu_width,
907 height,
908 nullptr,
909 0,
910 0,
911 std::nullopt);
912
913 /* Center the menu on the cursor */
914 const int offset[2] = {-(menu_width / 2), 0};
915 block_bounds_set_popup(block, UI_SEARCHBOX_BOUNDS, offset);
916
917 return block;
918}
919
921 TreeElement *parent_te,
922 TreeElement *activate_te)
923{
924 MergedSearchData *select_data = MEM_new_zeroed<MergedSearchData>("merge_search_data");
925 select_data->parent_element = parent_te;
926 select_data->select_element = activate_te;
927
928 popup_block_invoke(C, merged_element_search_menu, select_data, MEM_delete_void);
929}
930
932 ReportList * /*reports*/,
933 Scene * /*scene*/,
934 TreeElement * /*te*/,
935 TreeStoreElem * /*tsep*/,
936 TreeStoreElem *tselem)
937{
938 const Main *bmain = CTX_data_main(C);
939 const Scene *scene = CTX_data_scene(C);
940 ViewLayer *view_layer = CTX_data_view_layer(C);
941 Object *ob = id_cast<Object *>(tselem->id);
942 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
943 Base *base = BKE_view_layer_base_find(view_layer, ob);
944
945 if (base) {
947 }
948}
949
951
952/* -------------------------------------------------------------------- */
955
957 ReportList * /*reports*/,
958 Scene * /*scene*/,
959 TreeElement *te,
960 TreeStoreElem * /*tsep*/,
961 TreeStoreElem * /*tselem*/)
962{
963 /* Don't extend because this toggles, which is nice for Ctrl-Click but not for a menu item.
964 * it's especially confusing when multiple items are selected since some toggle on/off. */
965 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
967 C, space_outliner, te, OL_ITEM_SELECT | OL_ITEM_ACTIVATE | OL_ITEM_RECURSIVE);
968}
969
971 ReportList * /*reports*/,
972 Scene * /*scene*/,
973 TreeElement * /*te*/,
974 TreeStoreElem * /*tsep*/,
975 TreeStoreElem *tselem)
976{
977 const Main *bmain = CTX_data_main(C);
978 const Scene *scene = CTX_data_scene(C);
979 ViewLayer *view_layer = CTX_data_view_layer(C);
980 Object *ob = id_cast<Object *>(tselem->id);
981 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
982 Base *base = BKE_view_layer_base_find(view_layer, ob);
983
984 if (base) {
985 base->flag &= ~BASE_SELECTED;
986 }
987}
988
989static void outliner_object_delete_fn(bContext *C, ReportList *reports, Scene *scene, Object *ob)
990{
991 if (ob) {
992 Main *bmain = CTX_data_main(C);
993 if (ob->id.tag & ID_TAG_INDIRECT) {
995 reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", ob->id.name + 2);
996 return;
997 }
998 if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
1000 {
1001 BKE_reportf(reports,
1003 "Cannot delete object '%s' from scene '%s', indirectly used objects need at "
1004 "least one user",
1005 ob->id.name + 2,
1006 scene->id.name + 2);
1007 return;
1008 }
1009
1010 /* Check also library later. */
1011 if ((ob->mode & OB_MODE_EDIT) && BKE_object_is_in_editmode(ob)) {
1013 }
1014 BKE_id_delete(bmain, ob);
1015 }
1016}
1017
1019 ReportList * /*reports*/,
1020 Scene * /*scene*/,
1021 TreeElement * /*te*/,
1022 TreeStoreElem * /*tsep*/,
1023 TreeStoreElem *tselem)
1024{
1025 if (ID_IS_LINKED(tselem->id) && (tselem->id->tag & ID_TAG_EXTERN)) {
1026 Main *bmain = CTX_data_main(C);
1029
1030 /* Fix an edge case where a data pointer can be invalid during drawing after a grease
1031 * pencil data block is made local. See
1032 * https://projects.blender.org/blender/blender/pulls/153750. */
1033 if (tselem->id->id_type() == ID_GP) {
1035 }
1036 }
1037 }
1038 else if (ID_IS_OVERRIDE_LIBRARY_REAL(tselem->id)) {
1040 }
1041}
1042
1061
1064
1067
1073
1077
1084
1087
1088 void id_root_add(ID *id_hierarchy_root_reference,
1089 ID *id_root_reference,
1090 ID *id_instance_hint,
1091 const bool is_override_instancing_object)
1092 {
1093 OutlinerLiboverrideDataIDRoot id_root_data;
1094 id_root_data.id_root_reference = id_root_reference;
1095 id_root_data.id_hierarchy_root_override = nullptr;
1096 id_root_data.id_instance_hint = id_instance_hint;
1097 id_root_data.is_override_instancing_object = is_override_instancing_object;
1098
1100 id_hierarchy_root_reference);
1101 value.append(id_root_data);
1102 }
1103 void id_root_set(ID *id_hierarchy_root_reference)
1104 {
1105 OutlinerLiboverrideDataIDRoot id_root_data;
1106 id_root_data.id_root_reference = nullptr;
1107 id_root_data.id_hierarchy_root_override = nullptr;
1108 id_root_data.id_instance_hint = nullptr;
1109 id_root_data.is_override_instancing_object = false;
1110
1112 id_hierarchy_root_reference);
1113 if (value.is_empty()) {
1114 value.append(id_root_data);
1115 }
1116 }
1117};
1118
1119/* Store 'UUID' of IDs of selected elements in the Outliner tree, before generating the override
1120 * hierarchy. */
1123 ReportList *reports,
1124 TreeElement *te,
1125 TreeStoreElem *tsep,
1126 TreeStoreElem *tselem)
1127{
1128 BLI_assert(TSE_IS_REAL_ID(tselem));
1129
1130 const bool do_hierarchy = data->do_hierarchy;
1131 ID *id_root_reference = tselem->id;
1132
1133 if (!BKE_idtype_idcode_is_linkable(id_root_reference->id_type()) ||
1135 0)
1136 {
1137 return;
1138 }
1139
1140 /* Only process a given ID once. Otherwise, all kind of weird things can happen if e.g. a
1141 * selected sub-collection is part of more than one override hierarchies. */
1142 if (data->selected_id_uid.contains(id_root_reference->session_uid)) {
1143 return;
1144 }
1145 data->selected_id_uid.add(id_root_reference->session_uid);
1146
1147 if (ID_IS_OVERRIDE_LIBRARY_REAL(id_root_reference) && !ID_IS_LINKED(id_root_reference)) {
1149 return;
1150 }
1151
1152 if (!ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(id_root_reference)) {
1153 if (ID_IS_LINKED(id_root_reference)) {
1155 reports,
1157 "Could not create library override from data-block '%s', as it is not overridable",
1158 id_root_reference->name);
1159 }
1160 /* Else it's a local ID, do not bother reporting this, as it gets annoyingly noisy then when
1161 * operated e.g. on a hierarchy of liboverrides. */
1162 return;
1163 }
1164
1165 BLI_assert(do_hierarchy);
1166 UNUSED_VARS_NDEBUG(do_hierarchy);
1167
1168 if (id_root_reference->id_type() == ID_GR && (tselem->flag & TSE_CLOSED) != 0) {
1169 /* If selected element is a (closed) collection, check all of its objects recursively, and also
1170 * consider the armature ones as 'selected' (i.e. to not become system overrides). */
1171 Collection *root_collection = reinterpret_cast<Collection *>(id_root_reference);
1172 FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (root_collection, object_iter) {
1173 if (id_root_reference->lib == object_iter->id.lib && object_iter->type == OB_ARMATURE) {
1174 data->selected_id_uid.add(object_iter->id.session_uid);
1175 }
1176 }
1178 }
1179
1180 ID *id_instance_hint = nullptr;
1181 bool is_override_instancing_object = false;
1182 if (tsep != nullptr && tsep->type == TSE_SOME_ID && tsep->id != nullptr &&
1183 tsep->id->id_type() == ID_OB && !ID_IS_OVERRIDE_LIBRARY(tsep->id))
1184 {
1185 Object *ob = reinterpret_cast<Object *>(tsep->id);
1186 if (ob->type == OB_EMPTY && &ob->instance_collection->id == id_root_reference) {
1187 BLI_assert(GS(id_root_reference->name) == ID_GR);
1188 /* Empty instantiating the collection we override, we need to pass it to BKE overriding code
1189 * for proper handling. */
1190 id_instance_hint = tsep->id;
1191 is_override_instancing_object = true;
1192 }
1193 }
1194
1195 if (!ID_IS_OVERRIDABLE_LIBRARY(id_root_reference) &&
1196 !(ID_IS_LINKED(id_root_reference) && do_hierarchy))
1197 {
1198 return;
1199 }
1200
1201 Main *bmain = CTX_data_main(C);
1202
1203 if (do_hierarchy) {
1204 /* Tag all linked parents in tree hierarchy to be also overridden. */
1205 ID *id_hierarchy_root_reference = id_root_reference;
1206 while ((te = te->parent) != nullptr) {
1207 if (!TSE_IS_REAL_ID(te->store_elem)) {
1208 continue;
1209 }
1210
1211 /* Tentative hierarchy root. */
1212 ID *id_current_hierarchy_root = te->store_elem->id;
1213
1214 /* If the parent ID is from a different library than the reference root one, we are done
1215 * with upwards tree processing in any case. */
1216 if (id_current_hierarchy_root->lib != id_root_reference->lib) {
1217 if (ID_IS_OVERRIDE_LIBRARY_VIRTUAL(id_current_hierarchy_root)) {
1218 /* Virtual overrides (i.e. embedded IDs), we can simply keep processing their parent to
1219 * get an actual real override. */
1220 continue;
1221 }
1222
1223 /* If the parent ID is already an override, and is valid (i.e. local override), we can
1224 * access its hierarchy root directly. */
1225 if (!ID_IS_LINKED(id_current_hierarchy_root) &&
1226 ID_IS_OVERRIDE_LIBRARY_REAL(id_current_hierarchy_root) &&
1227 id_current_hierarchy_root->override_library->reference->lib == id_root_reference->lib)
1228 {
1229 id_hierarchy_root_reference =
1230 id_current_hierarchy_root->override_library->hierarchy_root;
1231 BLI_assert(ID_IS_OVERRIDE_LIBRARY_REAL(id_hierarchy_root_reference));
1232 break;
1233 }
1234
1235 if (ID_IS_LINKED(id_current_hierarchy_root)) {
1236 /* No local 'anchor' was found for the hierarchy to override, do not proceed, as this
1237 * would most likely generate invisible/confusing/hard to use and manage overrides. */
1238 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
1239 BKE_reportf(reports,
1241 "Invalid anchor ('%s') found, needed to create library override from "
1242 "data-block '%s'",
1243 id_current_hierarchy_root->name,
1244 id_root_reference->name);
1245 return;
1246 }
1247
1248 /* In all other cases, `id_current_hierarchy_root` cannot be a valid hierarchy root, so
1249 * current `id_hierarchy_root_reference` is our best candidate. */
1250
1251 break;
1252 }
1253
1254 /* If some element in the tree needs to be overridden, but its ID is not overridable,
1255 * abort. */
1256 if (!ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(id_current_hierarchy_root)) {
1257 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
1258 BKE_reportf(reports,
1260 "Could not create library override from data-block '%s', one of its parents "
1261 "is not overridable ('%s')",
1262 id_root_reference->name,
1263 id_current_hierarchy_root->name);
1264 return;
1265 }
1266 id_current_hierarchy_root->tag |= ID_TAG_DOIT;
1267 id_hierarchy_root_reference = id_current_hierarchy_root;
1268 }
1269
1270 /* That case can happen when linked data is a complex mix involving several libraries and/or
1271 * linked overrides. E.g. a mix of overrides from one library, and indirectly linked data
1272 * from another library. Do not try to support such cases for now. */
1273 if (!((id_hierarchy_root_reference->lib == id_root_reference->lib) ||
1274 (!ID_IS_LINKED(id_hierarchy_root_reference) &&
1275 ID_IS_OVERRIDE_LIBRARY_REAL(id_hierarchy_root_reference) &&
1276 id_hierarchy_root_reference->override_library->reference->lib ==
1277 id_root_reference->lib)))
1278 {
1279 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
1280 BKE_reportf(reports,
1282 "Invalid hierarchy root ('%s') found, needed to create library override from "
1283 "data-block '%s'",
1284 id_hierarchy_root_reference->name,
1285 id_root_reference->name);
1286 return;
1287 }
1288
1289 /* While ideally this should not be needed, in practice user almost _never_ wants to actually
1290 * create liboverrides for all data under a selected hierarchy node, and this has currently a
1291 * dreadful consequences over performances (since it would call
1292 * #BKE_lib_override_library_create over _all_ items in the hierarchy). So only the clearing of
1293 * the system override flag is supported for non-selected items for now.
1294 */
1295 const bool is_selected = tselem->flag & TSE_SELECTED;
1296 if (!is_selected && data->id_hierarchy_roots.contains(id_hierarchy_root_reference)) {
1297 return;
1298 }
1299
1300 data->id_root_add(id_hierarchy_root_reference,
1301 id_root_reference,
1302 id_instance_hint,
1303 is_override_instancing_object);
1304 }
1305 else if (ID_IS_OVERRIDABLE_LIBRARY(id_root_reference)) {
1306 data->id_root_add(
1307 id_root_reference, id_root_reference, id_instance_hint, is_override_instancing_object);
1308 }
1309}
1310
1312 Main &bmain,
1313 Scene *scene,
1314 ViewLayer *view_layer,
1316 ID *id_hierarchy_root_reference,
1318 bool &r_aggregated_success)
1319{
1320 BLI_assert(ID_IS_LINKED(id_hierarchy_root_reference) ||
1321 ID_IS_OVERRIDE_LIBRARY_REAL(id_hierarchy_root_reference));
1322
1323 const bool do_hierarchy = data.do_hierarchy;
1324
1325 /* NOTE: This process is not the most efficient, but allows to re-use existing code.
1326 * If this becomes a bottle-neck at some point, we need to implement a new
1327 * `BKE_lib_override_library_hierarchy_create()` function able to process several roots inside of
1328 * a same hierarchy in a single call. */
1329 for (OutlinerLiboverrideDataIDRoot &data_idroot : data_idroots) {
1330 /* For now, remap all local usages of linked ID to local override one here. */
1331 ID *id_iter;
1332 FOREACH_MAIN_ID_BEGIN (&bmain, id_iter) {
1333 if (ID_IS_LINKED(id_iter) || ID_IS_OVERRIDE_LIBRARY(id_iter)) {
1334 id_iter->tag &= ~ID_TAG_DOIT;
1335 }
1336 else {
1337 id_iter->tag |= ID_TAG_DOIT;
1338 }
1339 }
1341
1342 bool success = false;
1343 if (do_hierarchy) {
1344 ID *id_root_override = nullptr;
1345 success = BKE_lib_override_library_create(&bmain,
1346 scene,
1347 view_layer,
1348 nullptr,
1349 data_idroot.id_root_reference,
1350 id_hierarchy_root_reference,
1351 data_idroot.id_instance_hint,
1352 &id_root_override,
1353 data.do_fully_editable);
1354
1355 if (success) {
1356 BLI_assert(id_root_override != nullptr);
1357 BLI_assert(!ID_IS_LINKED(id_root_override));
1358 BLI_assert(ID_IS_OVERRIDE_LIBRARY_REAL(id_root_override));
1359
1360 ID *id_hierarchy_root_override = id_root_override->override_library->hierarchy_root;
1361 BLI_assert(ID_IS_OVERRIDE_LIBRARY_REAL(id_hierarchy_root_override));
1362 if (ID_IS_LINKED(id_hierarchy_root_reference)) {
1363 BLI_assert(id_hierarchy_root_override->override_library->reference ==
1364 id_hierarchy_root_reference);
1365 /* If the hierarchy root reference was a linked data, after the first iteration there is
1366 * now a matching override, which shall be used for all further partial overrides with
1367 * this same hierarchy. */
1368 id_hierarchy_root_reference = id_hierarchy_root_override;
1369 }
1370 else {
1371 BLI_assert(id_hierarchy_root_override == id_hierarchy_root_reference);
1372 }
1373 data_idroot.id_hierarchy_root_override = id_hierarchy_root_override;
1374 data.id_hierarchy_roots_uid.add(id_hierarchy_root_override->session_uid);
1375 }
1376 }
1377 else if (ID_IS_OVERRIDABLE_LIBRARY(data_idroot.id_root_reference)) {
1378 ID *id_root_override = BKE_lib_override_library_create_from_id(
1379 &bmain, data_idroot.id_root_reference, true);
1380
1381 success = id_root_override != nullptr;
1382 if (success) {
1383 BLI_assert(ID_IS_OVERRIDE_LIBRARY_REAL(id_root_override));
1385 }
1386 /* Cleanup. */
1388 BKE_main_id_tag_all(&bmain, ID_TAG_DOIT, false);
1389 }
1390 else {
1392 }
1393
1394 /* Remove the instance empty from this scene, the items now have an overridden collection
1395 * instead. */
1396 if (success && data_idroot.is_override_instancing_object) {
1397 BLI_assert(GS(data_idroot.id_instance_hint->name) == ID_OB);
1399 &bmain, scene, reinterpret_cast<Object *>(data_idroot.id_instance_hint));
1400 }
1401
1402 r_aggregated_success = r_aggregated_success && success;
1403 }
1404}
1405
1406/* Clear system override flag from newly created overrides which linked reference were previously
1407 * selected in the Outliner tree. */
1409 ReportList *reports,
1411{
1412 Main *bmain = CTX_data_main(C);
1413 Scene *scene = CTX_data_scene(C);
1414 ViewLayer *view_layer = CTX_data_view_layer(C);
1415 const bool do_hierarchy = data.do_hierarchy;
1416
1417 bool success = true;
1418 for (auto &&[id_hierarchy_root_reference, data_idroots] : data.id_hierarchy_roots.items()) {
1420 *bmain, scene, view_layer, data, id_hierarchy_root_reference, data_idroots, success);
1421 }
1422
1423 if (!success) {
1424 BKE_reportf(reports,
1426 "Could not create library override from one or more of the selected data-blocks");
1427 }
1428
1429 if (!do_hierarchy) {
1430 return;
1431 }
1432
1433 ID *id_iter;
1434 FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
1435 if (ID_IS_LINKED(id_iter) || !ID_IS_OVERRIDE_LIBRARY_REAL(id_iter)) {
1436 continue;
1437 }
1438 if (id_iter->override_library->hierarchy_root != nullptr &&
1439 !data.id_hierarchy_roots_uid.contains(
1441 {
1442 continue;
1443 }
1444 if (data.selected_id_uid.contains(id_iter->override_library->reference->session_uid) ||
1445 data.selected_id_uid.contains(id_iter->session_uid))
1446 {
1448 }
1449 }
1451}
1452
1455 TreeStoreElem *tselem)
1456{
1457 BLI_assert(TSE_IS_REAL_ID(tselem));
1458 ID *id_root = tselem->id;
1459 const bool do_hierarchy = data->do_hierarchy;
1460
1461 if (!ID_IS_OVERRIDE_LIBRARY_REAL(id_root) || ID_IS_LINKED(id_root)) {
1462 CLOG_WARN(&LOG, "Could not reset library override of data block '%s'", id_root->name);
1463 return;
1464 }
1465
1466 Main *bmain = CTX_data_main(C);
1467
1468 if (do_hierarchy) {
1469 BKE_lib_override_library_id_hierarchy_reset(bmain, id_root, false);
1470 }
1471 else {
1472 BKE_lib_override_library_id_reset(bmain, id_root, false);
1473 }
1474}
1475
1477 ReportList * /*reports*/,
1479{
1480 Main *bmain = CTX_data_main(C);
1481 ViewLayer *view_layer = CTX_data_view_layer(C);
1482 Scene *scene = CTX_data_scene(C);
1483
1484 /* TODO: At some point this likely needs to be re-written as a BKE function instead, with better
1485 * handling of hierarchies among other things. */
1486
1487 /* Try to process all potential leaves first (deleting some liboverride leaves will turn other
1488 * liboverrides into leaves as well). */
1489 bool do_process_leaves = true;
1490 while (!data.id_hierarchy_roots.is_empty()) {
1491 bool has_found_leaves = false;
1492
1493 for (auto &&id : data.id_hierarchy_roots.keys()) {
1494 if (do_process_leaves) {
1496 /* If given ID is not using any other override (it's a 'leaf' in the override hierarchy),
1497 * delete it and remap its usages to its linked reference. Otherwise, keep it as a reset
1498 * system override. */
1499 bool do_remap_active = false;
1500 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1501 if (BKE_view_layer_active_object_get(view_layer) == reinterpret_cast<Object *>(id)) {
1502 BLI_assert(GS(id->name) == ID_OB);
1503 do_remap_active = true;
1504 }
1506 bmain, id, id->override_library->reference, ID_REMAP_SKIP_INDIRECT_USAGE);
1507 if (do_remap_active) {
1508 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1509 Object *ref_object = reinterpret_cast<Object *>(id->override_library->reference);
1510 Base *basact = BKE_view_layer_base_find(view_layer, ref_object);
1511 if (basact != nullptr) {
1512 view_layer->basact = basact;
1513 }
1515 }
1516
1517 BKE_id_delete(bmain, id);
1518 data.id_hierarchy_roots.remove(id);
1519 has_found_leaves = true;
1520 }
1521 }
1522 else {
1524 BKE_lib_override_library_id_reset(bmain, id, true);
1525 data.id_hierarchy_roots.remove(id);
1526 }
1527 }
1528
1529 do_process_leaves = has_found_leaves;
1530 }
1532}
1533
1535 ReportList *reports,
1536 TreeStoreElem *tselem)
1537{
1538 BLI_assert(TSE_IS_REAL_ID(tselem));
1539 ID *id = tselem->id;
1540
1541 if (!ID_IS_OVERRIDE_LIBRARY(id)) {
1542 return;
1543 }
1544 if (!ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
1545 BKE_reportf(reports,
1547 "Cannot clear embedded library override '%s', only overrides of real data-blocks "
1548 "can be directly cleared",
1549 id->name);
1550 return;
1551 }
1552 if (ID_IS_LINKED(id)) {
1554 reports,
1556 "Cannot clear linked library override '%s', only local overrides can be directly cleared",
1557 id->name);
1558 return;
1559 }
1560
1561 data->id_root_set(id);
1562}
1563
1565{
1566 BLI_assert(TSE_IS_REAL_ID(tselem));
1567 ID *id_root = tselem->id;
1568
1569 if (!ID_IS_OVERRIDE_LIBRARY_REAL(id_root) || ID_IS_LINKED(id_root)) {
1570 CLOG_WARN(&LOG, "Could not resync library override of data block '%s'", id_root->name);
1571 return;
1572 }
1573
1574 if (id_root->override_library->hierarchy_root != nullptr) {
1575 id_root = id_root->override_library->hierarchy_root;
1576 }
1577
1578 data->id_root_set(id_root);
1579}
1580
1581/* Resync a hierarchy of library overrides. */
1583 ReportList *reports,
1585{
1586 Main *bmain = CTX_data_main(C);
1587 Scene *scene = CTX_data_scene(C);
1588 const bool do_hierarchy_enforce = data.do_resync_hierarchy_enforce;
1589
1590 BlendFileReadReport report{};
1591 report.reports = reports;
1592
1593 /* In some cases, resync issues can be caused by missing hierarchy data (e.g. some liboverrides
1594 * have lost their hierarchy root ID pointer). So always attempt to fix/rebuild invalid hierarchy
1595 * info when this 'troubleshooting' tool is used.
1596 *
1597 * NOTE: Reproduction of this issue was never achieved simply so far, nor is it understood what
1598 * can cause hierarchy info to get broken.
1599 * Only known case so far, from Singularity Blender Studio production:
1600 * `singularity/pro/shots/090_ignite/090_0040/090_0040-fx.blend`, rev. 1651 ,
1601 * `FX-creature_blob` liboverride collection, several objects lost their hierarchy data,
1602 * e.g. `RIG-creature_blob`, `GEO-creature_blob-curve`, and the three `WGT` rigging widgets. */
1604
1605 for (auto &&id_hierarchy_root : data.id_hierarchy_roots.keys()) {
1607 scene,
1609 id_hierarchy_root,
1610 nullptr,
1611 do_hierarchy_enforce,
1612 &report);
1613 }
1614
1616}
1617
1619 TreeStoreElem *tselem)
1620{
1621 BLI_assert(TSE_IS_REAL_ID(tselem));
1622 ID *id_root = tselem->id;
1623
1624 if (!ID_IS_OVERRIDE_LIBRARY_REAL(id_root) || ID_IS_LINKED(id_root)) {
1625 CLOG_WARN(&LOG, "Could not delete library override of data block '%s'", id_root->name);
1626 return;
1627 }
1628
1629 if (id_root->override_library->hierarchy_root != nullptr) {
1630 id_root = id_root->override_library->hierarchy_root;
1631 }
1632
1633 data->id_root_set(id_root);
1634}
1635
1636/* Clear (delete) a hierarchy of library overrides. */
1638 ReportList * /*reports*/,
1640{
1641 Main *bmain = CTX_data_main(C);
1642
1643 for (auto &&id_hierarchy_root : data.id_hierarchy_roots.keys()) {
1644 BKE_lib_override_library_delete(bmain, id_hierarchy_root);
1645 }
1646}
1647
1648static void id_fake_user_set_fn(bContext * /*C*/,
1649 ReportList *reports,
1650 Scene * /*scene*/,
1651 TreeElement * /*te*/,
1652 TreeStoreElem * /*tsep*/,
1653 TreeStoreElem *tselem)
1654{
1655 ID *id = tselem->id;
1656
1657 if (ID_IS_LINKED(id)) {
1658 BKE_report(reports,
1659 RPT_INFO,
1660 "Cannot set fake user on a linked datablock, consider referencing it through a "
1661 "Custom Property");
1662 return;
1663 }
1664
1665 id_fake_user_set(id);
1666}
1667
1669 ReportList *reports,
1670 Scene * /*scene*/,
1671 TreeElement * /*te*/,
1672 TreeStoreElem * /*tsep*/,
1673 TreeStoreElem *tselem)
1674{
1675 ID *id = tselem->id;
1676
1677 if (ID_IS_LINKED(id)) {
1678 BKE_report(reports, RPT_INFO, "Cannot clear fake user on a linked datablock");
1679 return;
1680 }
1681
1683}
1684
1686 ReportList * /*reports*/,
1687 Scene * /*scene*/,
1688 TreeElement * /*te*/,
1689 TreeStoreElem * /*tsep*/,
1690 TreeStoreElem *tselem)
1691{
1692 ID *id = tselem->id;
1693
1695}
1696
1698 ReportList * /*reports*/,
1699 Scene * /*scene*/,
1700 TreeElement *te,
1701 TreeStoreElem *tsep,
1702 TreeStoreElem *tselem)
1703{
1704 /* This callback runs for all selected elements, some of which may not be actions which results
1705 * in a crash. */
1706 if (te->idcode != ID_AC) {
1707 return;
1708 }
1709
1710 ID *id = tselem->id;
1711
1712 if (id) {
1713 IdAdtTemplate *iat = (IdAdtTemplate *)tsep->id;
1714 PropertyRNA *prop;
1715
1716 PointerRNA ptr = RNA_pointer_create_discrete(&iat->id, RNA_AnimData, iat->adt);
1717 prop = RNA_struct_find_property(&ptr, "action");
1718
1719 id_single_user(C, id, &ptr, prop);
1720 }
1721}
1722
1724 ReportList * /*reports*/,
1725 Scene * /*scene*/,
1726 TreeElement * /*te*/,
1727 TreeStoreElem *tsep,
1728 TreeStoreElem *tselem)
1729{
1730 ID *id = tselem->id;
1731
1732 /* need to use parent scene not just scene, otherwise may end up getting wrong one */
1733 if (id) {
1734 Scene *parscene = id_cast<Scene *>(tsep->id);
1735 PropertyRNA *prop;
1736
1737 PointerRNA ptr = RNA_id_pointer_create(&parscene->id);
1738 prop = RNA_struct_find_property(&ptr, "world");
1739
1740 id_single_user(C, id, &ptr, prop);
1741 }
1742}
1743
1745 ReportList *reports,
1746 Scene *scene_act,
1747 SpaceOutliner *space_outliner,
1748 ListBaseT<TreeElement> *lb,
1749 outliner_operation_fn operation_fn,
1750 bool recurse_selected)
1751{
1752 for (TreeElement &te : *lb) {
1753 TreeStoreElem *tselem = TREESTORE(&te);
1754 bool select_handled = false;
1755 if (tselem->flag & TSE_SELECTED) {
1756 if ((tselem->type == TSE_SOME_ID) && (te.idcode == ID_OB)) {
1757 /* When objects selected in other scenes, don't know if that should be allowed. */
1758 Scene *scene_owner = id_cast<Scene *>(outliner_search_back(&te, ID_SCE));
1759 if (scene_owner && scene_act != scene_owner) {
1761 }
1762 /* Important to use 'scene_owner' not scene_act else deleting objects can crash.
1763 * only use 'scene_act' when 'scene_owner' is nullptr, which can happen when the
1764 * outliner isn't showing scenes: Visible Layer draw mode for eg. */
1765 operation_fn(C, reports, scene_owner ? scene_owner : scene_act, &te, nullptr, tselem);
1766 select_handled = true;
1767 }
1768 }
1769 if (TSELEM_OPEN(tselem, space_outliner)) {
1770 if ((select_handled == false) || recurse_selected) {
1772 C, reports, scene_act, space_outliner, &te.subtree, operation_fn, recurse_selected);
1773 }
1774 }
1775 }
1776}
1777
1779 ReportList *reports,
1780 Scene *scene_act,
1781 SpaceOutliner *space_outliner,
1782 ListBaseT<TreeElement> *lb,
1783 outliner_operation_fn operation_fn)
1784{
1785 outliner_do_object_operation_ex(C, reports, scene_act, space_outliner, lb, operation_fn, true);
1786}
1787
1789
1790/* -------------------------------------------------------------------- */
1793
1794static void clear_animdata_fn(int /*event*/,
1795 TreeElement * /*te*/,
1796 TreeStoreElem *tselem,
1797 void * /*arg*/)
1798{
1799 BKE_animdata_free(tselem->id, true);
1801}
1802
1803static void unlinkact_animdata_fn(int /*event*/,
1804 TreeElement * /*te*/,
1805 TreeStoreElem *tselem,
1806 void * /*arg*/)
1807{
1808 /* just set action to nullptr */
1809 BKE_animdata_set_action(nullptr, tselem->id, nullptr);
1810}
1811
1812static void cleardrivers_animdata_fn(int /*event*/,
1813 TreeElement * /*te*/,
1814 TreeStoreElem *tselem,
1815 void * /*arg*/)
1816{
1817 IdAdtTemplate *iat = (IdAdtTemplate *)tselem->id;
1818
1819 /* just free drivers - stored as a list of F-Curves */
1822}
1823
1824static void refreshdrivers_animdata_fn(int /*event*/,
1825 TreeElement * /*te*/,
1826 TreeStoreElem *tselem,
1827 void * /*arg*/)
1828{
1829 IdAdtTemplate *iat = (IdAdtTemplate *)tselem->id;
1830
1831 /* Loop over drivers, performing refresh
1832 * (i.e. check `graph_buttons.cc` and `rna_fcurve.cc` for details). */
1833 for (FCurve &fcu : iat->adt->drivers) {
1834 fcu.flag &= ~FCURVE_DISABLED;
1835
1836 if (fcu.driver) {
1838 }
1839 }
1840}
1841
1843
1844/* -------------------------------------------------------------------- */
1847
1859
1862 "OVERRIDE_LIBRARY_CREATE_HIERARCHY",
1863 0,
1864 "Make",
1865 "Create a local override of the selected linked data-blocks, and their hierarchy of "
1866 "dependencies"},
1868 "OVERRIDE_LIBRARY_RESET",
1869 0,
1870 "Reset",
1871 "Reset the selected local overrides to their linked references values"},
1873 "OVERRIDE_LIBRARY_CLEAR_SINGLE",
1874 0,
1875 "Clear",
1876 "Delete the selected local overrides and relink their usages to the linked data-blocks if "
1877 "possible, else reset them and mark them as non editable"},
1878 {0, nullptr, 0, nullptr, nullptr},
1879};
1880
1883 "OVERRIDE_LIBRARY_RESYNC_HIERARCHY",
1884 0,
1885 "Resync",
1886 "Rebuild the selected local overrides from their linked references, as well as their "
1887 "hierarchies of dependencies"},
1889 "OVERRIDE_LIBRARY_RESYNC_HIERARCHY_ENFORCE",
1890 0,
1891 "Resync Enforce",
1892 "Rebuild the selected local overrides from their linked references, as well as their "
1893 "hierarchies of dependencies, enforcing these hierarchies to match the linked data (i.e. "
1894 "ignoring existing overrides on data-blocks pointer properties)"},
1897 "OVERRIDE_LIBRARY_DELETE_HIERARCHY",
1898 0,
1899 "Delete",
1900 "Delete the selected local overrides (including their hierarchies of override dependencies) "
1901 "and relink their usages to the linked data-blocks"},
1902 {0, nullptr, 0, nullptr, nullptr},
1903};
1904
1906{
1908 return false;
1909 }
1910 return true;
1911}
1912
1914{
1915 Scene *scene = CTX_data_scene(C);
1916 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1917
1918 /* check for invalid states */
1919 if (space_outliner == nullptr) {
1920 return OPERATOR_CANCELLED;
1921 }
1922
1923 const eOutlinerLibOpSelectionSet selection_set = static_cast<eOutlinerLibOpSelectionSet>(
1924 RNA_enum_get(op->ptr, "selection_set"));
1926 RNA_enum_get(op->ptr, "type"));
1927 switch (event) {
1929 OutlinerLibOverrideData override_data{};
1930 override_data.do_hierarchy = true;
1931 override_data.do_fully_editable = false;
1932
1934 C,
1935 op->reports,
1936 scene,
1937 space_outliner,
1938 [&](bContext *C,
1939 ReportList *reports,
1940 Scene * /*scene*/,
1941 TreeElement *te,
1942 TreeStoreElem *tsep,
1943 TreeStoreElem *tselem) {
1944 id_override_library_create_hierarchy_pre_process(
1945 C, &override_data, reports, te, tsep, tselem);
1946 },
1947 selection_set,
1948 true);
1949
1951
1952 ED_undo_push(C, "Overridden Data Hierarchy");
1953 break;
1954 }
1956 OutlinerLibOverrideData override_data{};
1958 C,
1959 op->reports,
1960 scene,
1961 space_outliner,
1962 [&](bContext *C,
1963 ReportList * /*reports*/,
1964 Scene * /*scene*/,
1965 TreeElement * /*te*/,
1966 TreeStoreElem * /*tsep*/,
1967 TreeStoreElem *tselem) { id_override_library_reset(C, &override_data, tselem); },
1968 selection_set,
1969 false);
1970 ED_undo_push(C, "Reset Overridden Data");
1971 break;
1972 }
1974 OutlinerLibOverrideData override_data{};
1975 override_data.do_hierarchy = false;
1976 override_data.do_fully_editable = false;
1977
1979 C,
1980 op->reports,
1981 scene,
1982 space_outliner,
1983 [&](bContext * /*C*/,
1984 ReportList *reports,
1985 Scene * /*scene*/,
1986 TreeElement * /*te*/,
1987 TreeStoreElem * /*tsep*/,
1988 TreeStoreElem *tselem) {
1989 id_override_library_clear_single(&override_data, reports, tselem);
1990 },
1991 selection_set,
1992 false);
1993
1995
1996 ED_undo_push(C, "Clear Overridden Data");
1997 break;
1998 }
1999
2001 OutlinerLibOverrideData override_data{};
2002 override_data.do_hierarchy = true;
2004 C,
2005 op->reports,
2006 scene,
2007 space_outliner,
2008 [&](bContext * /*C*/,
2009 ReportList * /*reports*/,
2010 Scene * /*scene*/,
2011 TreeElement * /*te*/,
2012 TreeStoreElem * /*tsep*/,
2013 TreeStoreElem *tselem) { id_override_library_resync(&override_data, tselem); },
2015 false);
2016
2018
2019 ED_undo_push(C, "Resync Overridden Data Hierarchy");
2020 break;
2021 }
2023 OutlinerLibOverrideData override_data{};
2024 override_data.do_hierarchy = true;
2025 override_data.do_resync_hierarchy_enforce = true;
2027 C,
2028 op->reports,
2029 scene,
2030 space_outliner,
2031 [&](bContext * /*C*/,
2032 ReportList * /*reports*/,
2033 Scene * /*scene*/,
2034 TreeElement * /*te*/,
2035 TreeStoreElem * /*tsep*/,
2036 TreeStoreElem *tselem) { id_override_library_resync(&override_data, tselem); },
2038 false);
2039
2041
2042 ED_undo_push(C, "Resync Overridden Data Hierarchy Enforce");
2043 break;
2044 }
2046 OutlinerLibOverrideData override_data{};
2047 override_data.do_hierarchy = true;
2049 C,
2050 op->reports,
2051 scene,
2052 space_outliner,
2053 [&](bContext * /*C*/,
2054 ReportList * /*reports*/,
2055 Scene * /*scene*/,
2056 TreeElement * /*te*/,
2057 TreeStoreElem * /*tsep*/,
2058 TreeStoreElem *tselem) {
2059 id_override_library_delete_hierarchy(&override_data, tselem);
2060 },
2062 false);
2063
2065
2066 ED_undo_push(C, "Delete Overridden Data Hierarchy");
2067 break;
2068 }
2069 default:
2070 /* Invalid - unhandled. */
2071 break;
2072 }
2073
2077
2078 return OPERATOR_FINISHED;
2079}
2080
2082{
2083 /* identifiers */
2084 ot->name = "Outliner Library Override Operation";
2085 ot->idname = "OUTLINER_OT_liboverride_operation";
2086 ot->description = "Create, reset or clear library override hierarchies";
2087
2088 /* callbacks */
2089 ot->invoke = WM_menu_invoke;
2092
2093 ot->flag = 0;
2094
2095 RNA_def_enum(ot->srna, "type", prop_liboverride_op_types, 0, "Library Override Operation", "");
2096 ot->prop = RNA_def_enum(ot->srna,
2097 "selection_set",
2099 0,
2100 "Selection Set",
2101 "Over which part of the tree items to apply the operation");
2102}
2103
2105{
2106 /* identifiers */
2107 ot->name = "Outliner Library Override Troubleshoot Operation";
2108 ot->idname = "OUTLINER_OT_liboverride_troubleshoot_operation";
2109 ot->description = "Advanced operations over library override to help fix broken hierarchies";
2110
2111 /* callbacks */
2112 ot->invoke = WM_menu_invoke;
2115
2116 ot->flag = 0;
2117
2118 ot->prop = RNA_def_enum(ot->srna,
2119 "type",
2121 0,
2122 "Library Override Troubleshoot Operation",
2123 "");
2124 RNA_def_enum(ot->srna,
2125 "selection_set",
2127 0,
2128 "Selection Set",
2129 "Over which part of the tree items to apply the operation");
2130}
2131
2133 ReportList *reports,
2134 Scene *scene,
2135 ListBaseT<TreeElement> &subtree,
2136 const bool has_parent_selected,
2137 outliner_operation_fn operation_fn)
2138{
2139 for (TreeElement &element : subtree.items_mutable()) {
2140 /* Get needed data out in case element gets freed. */
2141 TreeStoreElem *tselem = TREESTORE(&element);
2142 ListBaseT<TreeElement> subtree = element.subtree;
2143
2144 const bool is_selected = (tselem->flag & TSE_SELECTED) || has_parent_selected;
2145 if (is_selected) {
2147 TreeStoreElem *tsep = element.parent ? TREESTORE(element.parent) : nullptr;
2148 operation_fn(C, reports, scene, &element, tsep, tselem);
2149 }
2150 }
2151 /* Don't access element from now on, it may be freed. Note that the open/collapsed state may
2152 * also have been changed in the visitor callback. */
2153
2155 C, reports, scene, subtree, is_selected, operation_fn);
2156 }
2157}
2158
2160{
2162 return false;
2163 }
2164 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2165 TreeElement *te = get_target_element(space_outliner);
2166 TreeStoreElem *tselem = TREESTORE(te);
2167
2168 return (space_outliner->outlinevis == SO_OVERRIDES_LIBRARY &&
2169 ELEM(tselem->type,
2174}
2175
2176template<typename TreeElementOverridesT>
2178 Main &bmain,
2179 TreeStoreElem &tselem,
2180 TreeElementOverridesT &override_elem,
2181 ReportList *reports)
2182{
2183 ID *current_id = tselem.id;
2184 BLI_assert(current_id);
2186
2187 IDOverrideLibraryProperty *liboverride_property = override_elem.get_override_property_from_id(
2188 *current_id);
2189 if (!liboverride_property) {
2190 BKE_reportf(reports,
2191 RPT_ERROR,
2192 "Failed to find a matching Library Override property for ID '%s' (Library "
2193 "'%s'), path '%s'",
2194 current_id->override_library->reference->name,
2195 current_id->override_library->reference->lib ?
2197 "<NONE>",
2198 override_elem.rna_path.c_str());
2199 return false;
2200 }
2201
2202 IDOverrideLibraryPropertyOperation *liboverride_property_operation = nullptr;
2203 if constexpr (std::is_same_v<TreeElementOverridesT, const TreeElementOverridesPropertyOperation>)
2204 {
2205 const eID_OverrideLib_Op override_opcode = eID_OverrideLib_Op(
2206 override_elem.get_operation_type());
2208 BKE_reportf(reports,
2210 "Cannot remove 'Insert' type of library override operations for ID '%s' "
2211 "(library '%s'), RNA path '%s'. Please delete the added data directly",
2212 current_id->name,
2213 current_id->lib ? current_id->lib->runtime->filepath_abs : "<NONE>",
2214 override_elem.rna_path.c_str());
2215 return false;
2216 }
2217
2218 liboverride_property_operation = override_elem.get_override_operation_from_id(
2219 *current_id, *liboverride_property);
2220 if (!liboverride_property_operation) {
2221 BKE_reportf(reports,
2222 RPT_ERROR,
2223 "Failed to find a matching Library Override property operation for ID '%s' "
2224 "(Library '%s'), path '%s'",
2225 current_id->override_library->reference->name,
2226 current_id->override_library->reference->lib ?
2228 "<NONE>",
2229 override_elem.rna_path.c_str());
2230 return false;
2231 }
2232 }
2233
2234 /* The source (i.e. linked data) is required to restore values of deleted overrides. */
2235 PropertyRNA *reference_rna_prop;
2237 PointerRNA reference_rna_ptr;
2239 &id_refptr, liboverride_property->rna_path, &reference_rna_ptr, &reference_rna_prop))
2240 {
2241 BKE_reportf(reports,
2242 RPT_ERROR,
2243 "Failed to create matching reference (linked data) RNA pointer for ID '%s' "
2244 "(Library '%s'), path '%s'",
2245 current_id->override_library->reference->name,
2246 current_id->override_library->reference->lib ?
2248 "<NONE>",
2249 liboverride_property->rna_path);
2250 return false;
2251 }
2252
2253 RNA_property_copy(&bmain,
2254 const_cast<PointerRNA *>(&override_elem.override_rna_ptr),
2255 &reference_rna_ptr,
2256 &override_elem.override_rna_prop,
2257 liboverride_property_operation ?
2258 liboverride_property_operation->subitem_reference_index :
2259 -1,
2260 liboverride_property,
2261 liboverride_property_operation);
2262 if (liboverride_property_operation) {
2264 liboverride_property_operation);
2265 if (BLI_listbase_is_empty(&liboverride_property->operations)) {
2266 BKE_lib_override_library_property_delete(current_id->override_library, liboverride_property);
2267 }
2268 }
2269 else {
2270 BKE_lib_override_library_property_delete(current_id->override_library, liboverride_property);
2271 }
2272
2273 /* Perform updates required for this property. */
2275 const_cast<PointerRNA *>(&override_elem.override_rna_ptr),
2276 &override_elem.override_rna_prop);
2277
2278 return true;
2279}
2280
2282{
2283 Main *bmain = CTX_data_main(C);
2284 Scene *scene = CTX_data_scene(C);
2285 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2286
2287 /* check for invalid states */
2288 if (space_outliner == nullptr) {
2289 return OPERATOR_CANCELLED;
2290 }
2291
2292 bool has_changes = false;
2293 auto property_remove_cb = [bmain, &has_changes](bContext *C,
2294 ReportList *reports,
2295 Scene * /*scene*/,
2296 TreeElement *te,
2297 TreeStoreElem * /*tsep*/,
2298 TreeStoreElem *tselem) -> void {
2299 switch (tselem->type) {
2302 if (const TreeElementOverridesProperty *override_op_elem =
2304 {
2306 C, *bmain, *tselem, *override_op_elem, reports))
2307 {
2308 has_changes = true;
2309 }
2310 }
2311 break;
2313 if (const TreeElementOverridesPropertyOperation *override_op_elem =
2315 {
2317 C, *bmain, *tselem, *override_op_elem, reports))
2318 {
2319 has_changes = true;
2320 }
2321 }
2322 break;
2323 }
2324 default:
2326 }
2327 };
2328
2330 C, op->reports, scene, space_outliner->runtime->tree, false, property_remove_cb);
2331
2332 if (!has_changes) {
2333 return OPERATOR_CANCELLED;
2334 }
2335
2339
2340 return OPERATOR_FINISHED;
2341}
2342
2344{
2345 /* identifiers */
2346 ot->name = "Outliner Library Override Property Remove";
2347 ot->idname = "OUTLINER_OT_liboverride_property_remove";
2348 ot->description =
2349 "Remove the selected library override properties, and reset the relevant data to the linked "
2350 "reference values";
2351
2352 /* callbacks */
2355
2357}
2358
2360
2361/* -------------------------------------------------------------------- */
2364
2372
2378
2385
2386static void pchan_fn(int event, TreeElement *te, TreeStoreElem * /*tselem*/, void * /*arg*/)
2387{
2388 bPoseChannel *pchan = static_cast<bPoseChannel *>(te->directdata);
2389
2390 if (event == OL_DOP_SELECT) {
2391 animrig::bone_select(pchan);
2392 }
2393 else if (event == OL_DOP_DESELECT) {
2395 }
2396 else if (event == OL_DOP_HIDE) {
2397 pchan->drawflag |= PCHAN_DRAW_HIDDEN;
2399 }
2400 else if (event == OL_DOP_UNHIDE) {
2401 pchan->drawflag &= ~PCHAN_DRAW_HIDDEN;
2402 }
2403}
2404
2405static void bone_fn(int event, TreeElement *te, TreeStoreElem * /*tselem*/, void * /*arg*/)
2406{
2407 Bone *bone = static_cast<Bone *>(te->directdata);
2408
2409 if (event == OL_DOP_SELECT) {
2410 bone->flag |= BONE_SELECTED;
2411 }
2412 else if (event == OL_DOP_DESELECT) {
2413 bone->flag &= ~BONE_SELECTED;
2414 }
2415 else if (event == OL_DOP_HIDE) {
2416 bone->flag |= BONE_HIDDEN_P;
2417 bone->flag &= ~BONE_SELECTED;
2418 }
2419 else if (event == OL_DOP_UNHIDE) {
2420 bone->flag &= ~BONE_HIDDEN_P;
2421 }
2422}
2423
2424static void ebone_fn(int event, TreeElement *te, TreeStoreElem * /*tselem*/, void * /*arg*/)
2425{
2426 EditBone *ebone = static_cast<EditBone *>(te->directdata);
2427
2428 if (event == OL_DOP_SELECT) {
2429 ebone->flag |= BONE_SELECTED;
2430 }
2431 else if (event == OL_DOP_DESELECT) {
2432 ebone->flag &= ~BONE_SELECTED;
2433 }
2434 else if (event == OL_DOP_HIDE) {
2435 ebone->flag |= BONE_HIDDEN_A;
2436 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
2437 }
2438 else if (event == OL_DOP_UNHIDE) {
2439 ebone->flag &= ~BONE_HIDDEN_A;
2440 }
2441}
2442
2443static void sequence_fn(int event, TreeElement *te, TreeStoreElem * /*tselem*/, void *scene_ptr)
2444{
2446 Strip *strip = &te_strip->get_strip();
2447 Scene *scene = static_cast<Scene *>(scene_ptr);
2448 Editing *ed = seq::editing_get(scene);
2449 if (BLI_findindex(ed->current_strips(), strip) != -1) {
2450 if (event == OL_DOP_SELECT) {
2451 vse::select_strip_single(scene, strip, true);
2452 }
2453 else if (event == OL_DOP_DESELECT) {
2454 strip->flag &= ~SEQ_SELECT;
2455 }
2456 else if (event == OL_DOP_HIDE) {
2457 if (!(strip->flag & SEQ_MUTE)) {
2458 strip->flag |= SEQ_MUTE;
2459 seq::relations_invalidate_cache(scene, strip);
2460 }
2461 }
2462 else if (event == OL_DOP_UNHIDE) {
2463 if (strip->flag & SEQ_MUTE) {
2464 strip->flag &= ~SEQ_MUTE;
2465 seq::relations_invalidate_cache(scene, strip);
2466 }
2467 }
2468 }
2469}
2470
2471static void gpencil_layer_fn(int event,
2472 TreeElement *te,
2473 TreeStoreElem * /*tselem*/,
2474 void * /*arg*/)
2475{
2476 bGPDlayer *gpl = static_cast<bGPDlayer *>(te->directdata);
2477
2478 if (event == OL_DOP_SELECT) {
2479 gpl->flag |= GP_LAYER_SELECT;
2480 }
2481 else if (event == OL_DOP_DESELECT) {
2482 gpl->flag &= ~GP_LAYER_SELECT;
2483 }
2484 else if (event == OL_DOP_HIDE) {
2485 gpl->flag |= GP_LAYER_HIDE;
2486 }
2487 else if (event == OL_DOP_UNHIDE) {
2488 gpl->flag &= ~GP_LAYER_HIDE;
2489 }
2490}
2491
2492static void grease_pencil_node_fn(int event,
2493 TreeElement *te,
2494 TreeStoreElem * /*tselem*/,
2495 void * /*arg*/)
2496{
2498
2499 if (event == OL_DOP_SELECT) {
2500 node.set_selected(true);
2501 }
2502 else if (event == OL_DOP_DESELECT) {
2503 node.set_selected(false);
2504 }
2505 else if (event == OL_DOP_HIDE) {
2506 node.set_visible(false);
2507 }
2508 else if (event == OL_DOP_UNHIDE) {
2509 node.set_visible(true);
2510 }
2511}
2512
2513static void data_select_linked_fn(int event,
2514 TreeElement *te,
2515 TreeStoreElem * /*tselem*/,
2516 void *C_v)
2517{
2519 if (!te_rna_struct) {
2520 return;
2521 }
2522
2523 if (event == OL_DOP_SELECT_LINKED) {
2524 const PointerRNA &ptr = te_rna_struct->get_pointer_rna();
2525 if (RNA_struct_is_ID(ptr.type)) {
2526 bContext *C = static_cast<bContext *>(C_v);
2527 ID *id = static_cast<ID *>(ptr.data);
2528
2530 }
2531 }
2532}
2533
2534static void constraint_fn(int event, TreeElement *te, TreeStoreElem * /*tselem*/, void *C_v)
2535{
2536 bContext *C = static_cast<bContext *>(C_v);
2537 Main *bmain = CTX_data_main(C);
2538 bConstraint *constraint = static_cast<bConstraint *>(te->directdata);
2539 Object *ob = id_cast<Object *>(outliner_search_back(te, ID_OB));
2540
2541 if (event == OL_CONSTRAINTOP_ENABLE) {
2542 constraint->flag &= ~CONSTRAINT_OFF;
2543 object::constraint_update(bmain, ob);
2545 }
2546 else if (event == OL_CONSTRAINTOP_DISABLE) {
2547 constraint->flag |= CONSTRAINT_OFF;
2548 object::constraint_update(bmain, ob);
2550 }
2551 else if (event == OL_CONSTRAINTOP_DELETE) {
2552 ListBaseT<bConstraint> *lb = nullptr;
2553
2554 if (TREESTORE(te->parent->parent)->type == TSE_POSE_CHANNEL) {
2555 lb = &(static_cast<bPoseChannel *>(te->parent->parent->directdata))->constraints;
2556 }
2557 else {
2558 lb = &ob->constraints;
2559 }
2560
2561 if (BKE_constraint_remove_ex(lb, ob, constraint)) {
2562 /* there's no active constraint now, so make sure this is the case */
2564
2565 /* Needed to set the flags on pose-bones correctly. */
2566 object::constraint_update(bmain, ob);
2567
2570 }
2571 }
2572}
2573
2578
2579static void modifier_fn(int event, TreeElement *te, TreeStoreElem * /*tselem*/, void *arg)
2580{
2581 ModifierFnArgs *data = static_cast<ModifierFnArgs *>(arg);
2582 bContext *C = data->C;
2583 Main *bmain = CTX_data_main(C);
2584 Scene *scene = CTX_data_scene(C);
2585 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
2586 ModifierData *md = static_cast<ModifierData *>(te->directdata);
2587 Object *ob = id_cast<Object *>(outliner_search_back(te, ID_OB));
2588
2589 if (event == OL_MODIFIER_OP_TOGVIS) {
2593 }
2594 else if (event == OL_MODIFIER_OP_TOGREN) {
2598 }
2599 else if (event == OL_MODIFIER_OP_DELETE) {
2600 object::modifier_remove(data->reports, bmain, scene, ob, md);
2603 }
2604 else if (event == OL_MODIFIER_OP_APPLY) {
2606 bmain, data->reports, depsgraph, scene, ob, md, object::MODIFIER_APPLY_DATA, false, false);
2611 }
2612}
2613
2615 SpaceOutliner *space_outliner,
2616 int type,
2617 int event,
2618 void (*operation_fn)(int, TreeElement *, TreeStoreElem *, void *),
2619 void *arg)
2620{
2621 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
2622 TreeStoreElem *tselem = TREESTORE(te);
2623 if (tselem->flag & TSE_SELECTED) {
2624 if (tselem->type == type) {
2625 operation_fn(event, te, tselem, arg);
2626 }
2627 }
2628 });
2629}
2630
2632 Main *bmain,
2633 Scene *scene,
2634 Object *object)
2635{
2636 if (object->id.tag & ID_TAG_INDIRECT) {
2638 reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", object->id.name + 2);
2639 BLI_assert((object->id.tag & ID_TAG_DOIT) == 0);
2640 }
2641 /* FIXME: This code checking object user-count won't work as expected if a same object belongs to
2642 * more than one collection in the scene. */
2643 if (ID_REAL_USERS(object) <= 1 && ID_EXTRA_USERS(object) == 0 &&
2644 BKE_library_ID_is_indirectly_used(bmain, object))
2645 {
2646 BKE_reportf(reports,
2648 "Cannot delete object '%s' from scene '%s', indirectly used objects need at least "
2649 "one user",
2650 object->id.name + 2,
2651 scene->id.name + 2);
2652 BLI_assert((object->id.tag & ID_TAG_DOIT) == 0);
2653 }
2654
2655 object->id.tag |= ID_TAG_DOIT;
2656}
2657
2659 ReportList *reports, Main *bmain, ViewLayer *view_layer, Scene *scene, Base *base)
2660{
2661 Object *object = base->object;
2662 BLI_assert(object != nullptr);
2663
2664 outliner_batch_delete_object_tag(reports, bmain, scene, object);
2665
2666 /* Even though the object itself may not be deletable, some of its children may still be
2667 * deletable. */
2668 for (Base *base_iter = BKE_view_layer_object_bases_get(view_layer)->first();
2669 base_iter != nullptr;
2670 base_iter = base_iter->next)
2671 {
2672 Object *parent_ob_iter;
2673 for (parent_ob_iter = base_iter->object->parent;
2674 (parent_ob_iter != nullptr && parent_ob_iter != object &&
2675 (parent_ob_iter->id.tag & ID_TAG_DOIT) == 0);
2676 parent_ob_iter = parent_ob_iter->parent)
2677 {
2678 /* pass */
2679 }
2680 if (parent_ob_iter != nullptr) {
2681 /* There is one or more parents to current iterated object that also need to be deleted,
2682 * process the parenting chain again to tag them as such.
2683 *
2684 * NOTE: Since objects that cannot be deleted are not tagged, the relevant 'parenting'
2685 * branches may be looped over more than once. Would not expect this to be a real issue in
2686 * practice though. */
2687 for (parent_ob_iter = base_iter->object;
2688 (parent_ob_iter != nullptr && parent_ob_iter != object &&
2689 (parent_ob_iter->id.tag & ID_TAG_DOIT) == 0);
2690 parent_ob_iter = parent_ob_iter->parent)
2691 {
2692 outliner_batch_delete_object_tag(reports, bmain, scene, parent_ob_iter);
2693 }
2694 }
2695 }
2696}
2697
2699 ReportList *reports,
2700 Scene *scene,
2701 Object *ob)
2702{
2703 if (ob->id.tag & ID_TAG_DOIT) {
2704 /* Object has already been processed and tagged for removal as part of another parenting
2705 * hierarchy. */
2706#ifndef NDEBUG
2707 const Main *bmain = CTX_data_main(C);
2708 ViewLayer *view_layer = CTX_data_view_layer(C);
2709 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2710 BLI_assert(BKE_view_layer_base_find(view_layer, ob) == nullptr);
2711#endif
2712 return;
2713 }
2714
2715 ViewLayer *view_layer = CTX_data_view_layer(C);
2716 Object *obedit = CTX_data_edit_object(C);
2717
2718 Base *base = BKE_view_layer_base_find(view_layer, ob);
2719
2720 if (base == nullptr) {
2721 return;
2722 }
2723
2724 /* Exit Edit mode if the active object or one of its children are being edited. */
2725 for (; obedit && (obedit != base->object); obedit = obedit->parent) {
2726 /* pass */
2727 }
2728 if (obedit == base->object) {
2730 }
2731
2732 Main *bmain = CTX_data_main(C);
2733 outliner_batch_delete_object_hierarchy_tag(reports, bmain, view_layer, scene, base);
2734}
2735
2737{
2738 for (Object &ob_iter : bmain->objects) {
2739 if ((ob_iter.id.tag & ID_TAG_DOIT) == 0) {
2740 continue;
2741 }
2742
2743 BKE_scene_collections_object_remove(bmain, scene, &ob_iter, false);
2744
2745 /* Check on all objects tagged for deletion, these that are still in use (e.g. in collections
2746 * from another scene) should not be deleted. They also need to be tagged for depsgraph update.
2747 */
2748 if (ob_iter.id.us != 0) {
2749 ob_iter.id.tag &= ~ID_TAG_DOIT;
2751 }
2752 }
2753
2755}
2756
2758
2759/* -------------------------------------------------------------------- */
2762
2763enum {
2769};
2770
2772 {OL_OP_SELECT, "SELECT", ICON_RESTRICT_SELECT_OFF, "Select", ""},
2773 {OL_OP_DESELECT, "DESELECT", 0, "Deselect", ""},
2774 {OL_OP_SELECT_HIERARCHY, "SELECT_HIERARCHY", 0, "Select Hierarchy", ""},
2775 {OL_OP_REMAP,
2776 "REMAP",
2777 0,
2778 "Remap Users",
2779 "Make all users of selected data-blocks to use instead a new chosen one"},
2780 {OL_OP_RENAME, "RENAME", 0, "Rename", ""},
2781 {0, nullptr, 0, nullptr, nullptr},
2782};
2783
2785{
2786 Main *bmain = CTX_data_main(C);
2787 Scene *scene = CTX_data_scene(C);
2788 wmWindow *win = CTX_wm_window(C);
2789 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2790 int event;
2791 const char *str = nullptr;
2792 bool selection_changed = false;
2793
2794 /* check for invalid states */
2795 if (space_outliner == nullptr) {
2796 return OPERATOR_CANCELLED;
2797 }
2798
2799 event = RNA_enum_get(op->ptr, "type");
2800
2801 switch (event) {
2802 case OL_OP_SELECT: {
2803 Scene *sce = scene; /* To be able to delete, scenes are set... */
2805 C, op->reports, scene, space_outliner, &space_outliner->runtime->tree, object_select_fn);
2806 /* FIXME: This is most certainly broken, maybe check should rather be
2807 * `if (CTX_data_scene(C) != scene)` ? */
2808 if (scene != sce) {
2809 WM_window_set_active_scene(bmain, C, win, sce);
2810 }
2811
2812 str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select Objects");
2813 selection_changed = true;
2814 break;
2815 }
2817 Scene *sce = scene; /* To be able to delete, scenes are set... */
2819 op->reports,
2820 scene,
2821 space_outliner,
2822 &space_outliner->runtime->tree,
2824 false);
2825 /* FIXME: This is most certainly broken, maybe check should rather be
2826 * `if (CTX_data_scene(C) != scene)` ? */
2827 if (scene != sce) {
2828 WM_window_set_active_scene(bmain, C, win, sce);
2829 }
2830 str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select Object Hierarchy");
2831 selection_changed = true;
2832 break;
2833 }
2834 case OL_OP_DESELECT:
2836 op->reports,
2837 scene,
2838 space_outliner,
2839 &space_outliner->runtime->tree,
2841 str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Deselect Objects");
2842 selection_changed = true;
2843 break;
2844 case OL_OP_REMAP: {
2845 TreeElement *active_elem = get_target_element(space_outliner);
2846 if (active_elem) {
2847 id_remap_fn(C, TREESTORE(active_elem));
2848 }
2849 /* No undo push here, operator does it itself (since it's a modal one, the op_undo_depth
2850 * trick does not work here). */
2851 break;
2852 }
2853 case OL_OP_RENAME:
2855 C, op->reports, scene, space_outliner, &space_outliner->runtime->tree, item_rename_fn);
2856 str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Object");
2857 break;
2858 default:
2860 return OPERATOR_CANCELLED;
2861 }
2862
2863 if (selection_changed) {
2867 }
2868
2869 if (str != nullptr) {
2870 ED_undo_push(C, str);
2871 }
2872
2873 return OPERATOR_FINISHED;
2874}
2875
2877{
2878 /* identifiers */
2879 ot->name = "Outliner Object Operation";
2880 ot->idname = "OUTLINER_OT_object_operation";
2881
2882 /* callbacks */
2883 ot->invoke = WM_menu_invoke;
2886
2887 ot->flag = 0;
2888
2889 ot->prop = RNA_def_enum(ot->srna, "type", prop_object_op_types, 0, "Object Operation", "");
2890}
2891
2893
2894/* -------------------------------------------------------------------- */
2897
2898using OutlinerDeleteFn = void (*)(bContext *C, ReportList *reports, Scene *scene, Object *ob);
2899
2905
2907 ReportList *reports,
2908 Scene *scene,
2909 const Set<Object *> &objects_to_delete,
2910 OutlinerDeleteFn delete_fn)
2911{
2912 for (Object *ob : objects_to_delete) {
2913 delete_fn(C, reports, scene, ob);
2914 }
2915}
2916
2918{
2919 ObjectEditData *data = static_cast<ObjectEditData *>(customdata);
2920 TreeStoreElem *tselem = TREESTORE(te);
2921
2923 return TRAVERSE_CONTINUE;
2924 }
2925
2926 if ((tselem->type != TSE_SOME_ID) || (tselem->id == nullptr) || (tselem->id->id_type() != ID_OB))
2927 {
2928 return TRAVERSE_SKIP_CHILDS;
2929 }
2930
2931 /* Do not allow to delete children objects of an override collection. */
2932 TreeElement *te_parent = te->parent;
2933 if (te_parent != nullptr && outliner_is_collection_tree_element(te_parent)) {
2934 TreeStoreElem *tselem_parent = TREESTORE(te_parent);
2935 ID *id_parent = tselem_parent->id;
2936 /* It's not possible to remove an object from an overridden collection (and potentially scene,
2937 * through the master collection). */
2938 if (ELEM(id_parent->id_type(), ID_GR, ID_SCE)) {
2939 if (ID_IS_OVERRIDE_LIBRARY_REAL(id_parent)) {
2940 return TRAVERSE_SKIP_CHILDS;
2941 }
2942 }
2943 }
2944
2945 ID *id = tselem->id;
2946
2949 if (!(data->is_liboverride_hierarchy_root_allowed || data->is_liboverride_allowed)) {
2950 return TRAVERSE_SKIP_CHILDS;
2951 }
2952 }
2953 else {
2954 if (!data->is_liboverride_allowed) {
2955 return TRAVERSE_SKIP_CHILDS;
2956 }
2957 }
2958 }
2959
2960 data->objects_set.add(reinterpret_cast<Object *>(id));
2961
2962 return TRAVERSE_CONTINUE;
2963}
2964
2966{
2967 Main *bmain = CTX_data_main(C);
2968 Scene *scene = CTX_data_scene(C);
2969 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2970 wmMsgBus *mbus = CTX_wm_message_bus(C);
2971 ViewLayer *view_layer = CTX_data_view_layer(C);
2972 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2973 const Base *basact_prev = BKE_view_layer_active_base_get(view_layer);
2974
2975 const bool delete_hierarchy = RNA_boolean_get(op->ptr, "hierarchy");
2976
2977 /* Get selected objects skipping duplicates to prevent deleting objects linked to multiple
2978 * collections twice */
2979 ObjectEditData object_delete_data = {};
2980 object_delete_data.is_liboverride_allowed = false;
2981 object_delete_data.is_liboverride_hierarchy_root_allowed = delete_hierarchy;
2982 outliner_tree_traverse(space_outliner,
2983 &space_outliner->runtime->tree,
2984 0,
2987 &object_delete_data);
2988
2989 if (delete_hierarchy) {
2990 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
2991
2992 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2993
2994 /* #object_batch_delete_hierarchy_fn callback will only remove objects from collections and tag
2995 * them for deletion. */
2997 op->reports,
2998 scene,
2999 object_delete_data.objects_set,
3001
3003 }
3004 else {
3006 C, op->reports, scene, object_delete_data.objects_set, outliner_object_delete_fn);
3007 }
3008
3009 outliner_collection_delete(C, bmain, scene, op->reports, delete_hierarchy);
3010
3011 /* Tree management normally happens from draw_outliner(), but when
3012 * you're clicking too fast on Delete object from context menu in
3013 * outliner several mouse events can be handled in one cycle without
3014 * handling notifiers/redraw which leads to deleting the same object twice.
3015 * cleanup tree here to prevent such cases. */
3016 outliner_cleanup_tree(space_outliner);
3017
3020
3021 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
3022 if (basact_prev != BKE_view_layer_active_base_get(view_layer)) {
3024 WM_msg_publish_rna_prop(mbus, &scene->id, view_layer, LayerObjects, active);
3025 }
3026
3028
3033
3034 return OPERATOR_FINISHED;
3035}
3036
3038{
3039 /* identifiers */
3040 ot->name = "Delete";
3041 ot->idname = "OUTLINER_OT_delete";
3042 ot->description = "Delete selected objects and collections";
3043
3044 /* callbacks */
3047
3048 /* flags */
3050
3051 /* properties */
3053 ot->srna, "hierarchy", false, "Hierarchy", "Delete child objects and collections");
3055}
3056
3058
3060{
3061 Main *bmain = CTX_data_main(C);
3063 int count = 0;
3064
3065 for (PointerRNA &idptr : selected_idptrs) {
3066 ID *id = static_cast<ID *>(idptr.data);
3067 if (id->id_type() == ID_IM) {
3068 Image *image = reinterpret_cast<Image *>(id);
3069 BKE_image_packfile_ensure(bmain, image, op->reports, nullptr, 0);
3071 }
3072 }
3073
3074 if (count > 0) {
3075 BKE_reportf(op->reports, RPT_INFO, "Packed %d images into the .blend file", count);
3077 return OPERATOR_FINISHED;
3078 }
3079
3080 return OPERATOR_CANCELLED;
3081}
3082
3084{
3085 /* identifiers */
3086 ot->name = "Pack ID Data";
3087 ot->idname = "OUTLINER_OT_pack_data";
3088 ot->description = "Embed selected data-blocks into the .blend file";
3089
3090 /* callbacks */
3093
3094 /* flags */
3096}
3097
3098/* -------------------------------------------------------------------- */
3101
3121
3122/* TODO: implement support for changing the ID-block used. */
3124 {OUTLINER_IDOP_UNLINK, "UNLINK", 0, "Unlink", ""},
3125 {OUTLINER_IDOP_LOCAL, "LOCAL", 0, "Make Local", ""},
3126 {OUTLINER_IDOP_SINGLE, "SINGLE", 0, "Make Single User", ""},
3127 {OUTLINER_IDOP_DELETE, "DELETE", ICON_X, "Delete", ""},
3129 "REMAP",
3130 0,
3131 "Remap Users",
3132 "Make all users of selected data-blocks to use instead current (clicked) one"},
3134 {OUTLINER_IDOP_COPY, "COPY", ICON_COPYDOWN, "Copy", ""},
3135 {OUTLINER_IDOP_PASTE, "PASTE", ICON_PASTEDOWN, "Paste", ""},
3138 "ADD_FAKE",
3139 0,
3140 "Add Fake User",
3141 "Ensure data-block gets saved even if it isn't in use (e.g. for motion and material "
3142 "libraries)"},
3143 {OUTLINER_IDOP_FAKE_CLEAR, "CLEAR_FAKE", 0, "Clear Fake User", ""},
3144 {OUTLINER_IDOP_RENAME, "RENAME", 0, "Rename", ""},
3145 {OUTLINER_IDOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""},
3146 {OUTLINER_IDOP_PACK, "PACK", ICON_PACKAGE, "Pack", "Embed data-blocks into the .blend file"},
3147 {0, nullptr, 0, nullptr, nullptr},
3148};
3149
3151 PointerRNA * /*ptr*/,
3152 PropertyRNA * /*prop*/,
3153 const int enum_value)
3154{
3156 return false;
3157 }
3158
3159 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3160 TreeElement *te = get_target_element(space_outliner);
3161 TreeStoreElem *tselem = TREESTORE(te);
3162 if (!TSE_IS_REAL_ID(tselem)) {
3163 return false;
3164 }
3165
3166 switch (enum_value) {
3168 if (ELEM(space_outliner->outlinevis, SO_SCENES, SO_VIEW_LAYER)) {
3169 return true;
3170 }
3171 /* TODO(dalai): enable in the few cases where this can be supported
3172 * (i.e., when we have a valid parent for the tselem). */
3173 return false;
3174 }
3175
3176 return true;
3177}
3178
3180 PointerRNA *ptr,
3181 PropertyRNA *prop,
3182 bool *r_free)
3183{
3184 EnumPropertyItem *items = nullptr;
3185 int totitem = 0;
3186
3187 if ((C == nullptr) || (ED_operator_outliner_active(C) == false)) {
3188 return prop_id_op_types;
3189 }
3190 for (const EnumPropertyItem *it = prop_id_op_types; it->identifier != nullptr; it++) {
3191 if (!outliner_id_operation_item_poll(C, ptr, prop, it->value)) {
3192 continue;
3193 }
3194 if (it->value == OUTLINER_IDOP_PACK) {
3195 /* Include Pack operation in context menu just for tree elements that represent image IDs. */
3196 const SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3197 const TreeElement *te = get_target_element(space_outliner);
3198 const TreeStoreElem *tselem = TREESTORE(te);
3199 if (TSE_IS_REAL_ID(tselem) && tselem->id && (tselem->id->id_type() != ID_IM)) {
3200 continue;
3201 }
3202 }
3203 RNA_enum_item_add(&items, &totitem, it);
3204 }
3205 RNA_enum_item_end(&items, &totitem);
3206 *r_free = true;
3207
3208 return items;
3209}
3210
3212{
3213 Main *bmain = CTX_data_main(C);
3215 Scene *scene = CTX_data_scene(C);
3216 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3217 int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
3218
3219 /* check for invalid states */
3220 if (space_outliner == nullptr) {
3221 return OPERATOR_CANCELLED;
3222 }
3223
3224 TreeElement *te = get_target_element(space_outliner);
3225 get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel);
3226
3228 switch (event) {
3229 case OUTLINER_IDOP_UNLINK: {
3230 /* unlink datablock from its parent */
3231 if (objectlevel) {
3232 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, unlink_object_fn);
3233
3235 ED_undo_push(C, "Unlink Object");
3236 break;
3237 }
3238
3239 switch (idlevel) {
3240 case ID_AC:
3241 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, unlink_action_fn);
3242
3244 ED_undo_push(C, "Unlink action");
3245 break;
3246 case ID_MA:
3247 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, unlink_material_fn);
3248
3250 ED_undo_push(C, "Unlink material");
3251 break;
3252 case ID_TE:
3253 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, unlink_texture_fn);
3254
3256 ED_undo_push(C, "Unlink texture");
3257 break;
3258 case ID_WO:
3259 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, unlink_world_fn);
3260
3262 ED_undo_push(C, "Unlink world");
3263 break;
3264 case ID_GR:
3266 C, op->reports, scene, space_outliner, unlink_collection_fn);
3267
3269 ED_undo_push(C, "Unlink Collection");
3270 break;
3271 default:
3272 BKE_report(op->reports, RPT_WARNING, "Not yet implemented");
3273 break;
3274 }
3275 break;
3276 }
3277 case OUTLINER_IDOP_LOCAL: {
3278 /* make local */
3279 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, id_local_fn);
3280 ED_undo_push(C, "Localized Data");
3281 break;
3282 }
3283 case OUTLINER_IDOP_SINGLE: {
3284 /* make single user */
3285 switch (idlevel) {
3286 case ID_AC:
3288 C, op->reports, scene, space_outliner, singleuser_action_fn);
3289
3291 ED_undo_push(C, "Single-User Action");
3292 break;
3293
3294 case ID_WO:
3296 C, op->reports, scene, space_outliner, singleuser_world_fn);
3297
3299 ED_undo_push(C, "Single-User World");
3300 break;
3301
3302 default:
3303 BKE_report(op->reports, RPT_WARNING, "Not yet implemented");
3304 break;
3305 }
3306 break;
3307 }
3308 case OUTLINER_IDOP_DELETE: {
3309 if (idlevel > 0) {
3310 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
3311 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, id_delete_tag_fn);
3314 ED_undo_push(C, "Delete");
3315 }
3316 break;
3317 }
3318 case OUTLINER_IDOP_REMAP: {
3319 if (idlevel > 0 || objectlevel) {
3320 /* Only work on the active element. Working on selection would spawn multiple popup
3321 * windows. See #93814. */
3322 if (te) {
3323 id_remap_fn(C, TREESTORE(te));
3324 }
3325 /* No undo push here, operator does it itself (since it's a modal one, the op_undo_depth
3326 * trick does not work here). */
3327 }
3328 break;
3329 }
3330 case OUTLINER_IDOP_COPY: {
3331 wm->op_undo_depth++;
3333 C, "OUTLINER_OT_id_copy", wm::OpCallContext::InvokeDefault, nullptr, nullptr);
3334 wm->op_undo_depth--;
3335 /* No need for undo, this operation does not change anything... */
3336 break;
3337 }
3338 case OUTLINER_IDOP_PASTE: {
3339 wm->op_undo_depth++;
3341 C, "OUTLINER_OT_id_paste", wm::OpCallContext::InvokeDefault, nullptr, nullptr);
3342 wm->op_undo_depth--;
3344 ED_undo_push(C, "Paste");
3345 break;
3346 }
3348 /* set fake user */
3349 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, id_fake_user_set_fn);
3350
3352 ED_undo_push(C, "Add Fake User");
3353 break;
3354 }
3356 /* clear fake user */
3357 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, id_fake_user_clear_fn);
3359 ED_undo_push(C, "Clear Fake User");
3360 break;
3361 }
3362 case OUTLINER_IDOP_RENAME: {
3363 /* rename */
3364 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, item_rename_fn);
3365
3367 ED_undo_push(C, "Rename");
3368 break;
3369 }
3371 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, id_select_linked_fn);
3373 ED_undo_push(C, "Select");
3374 break;
3375 case OUTLINER_IDOP_PACK:
3376 if (idlevel == ID_IM) {
3378 C, "OUTLINER_OT_pack_data", wm::OpCallContext::InvokeDefault, nullptr, nullptr);
3379 }
3380 default:
3381 /* Invalid - unhandled. */
3382 break;
3383 }
3384
3386
3387 /* wrong notifier still... */
3389
3390 /* XXX: this is just so that outliner is always up to date. */
3392
3393 return OPERATOR_FINISHED;
3394}
3395
3397{
3398 /* identifiers */
3399 ot->name = "Outliner ID Data Operation";
3400 ot->idname = "OUTLINER_OT_id_operation";
3401 ot->description = "General data-block management operations";
3402
3403 /* callbacks */
3404 ot->invoke = WM_menu_invoke;
3407
3408 ot->flag = 0;
3409
3410 ot->prop = RNA_def_enum(ot->srna, "type", prop_id_op_types, 0, "ID Data Operation", "");
3412}
3413
3415
3416/* -------------------------------------------------------------------- */
3419
3427
3429 {OL_LIB_DELETE, "DELETE", ICON_X, "Delete", "Delete this library and all its items"},
3431 "RELOCATE",
3432 0,
3433 "Relocate",
3434 "Select a new path for this library, and reload all its data"},
3435 {OL_LIB_RELOAD, "RELOAD", ICON_FILE_REFRESH, "Reload", "Reload all data from this library"},
3436 {0, nullptr, 0, nullptr, nullptr},
3437};
3438
3440{
3441 Main *bmain = CTX_data_main(C);
3442 Scene *scene = CTX_data_scene(C);
3443 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3444
3445 /* check for invalid states */
3446 if (space_outliner == nullptr) {
3447 return OPERATOR_CANCELLED;
3448 }
3449
3451 switch (event) {
3452 case OL_LIB_DELETE: {
3453 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
3454 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, id_delete_tag_fn);
3456 ED_undo_push(C, "Delete Library");
3457 break;
3458 }
3459 case OL_LIB_RELOCATE: {
3460 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, lib_relocate_fn);
3461 /* No undo push here, operator does it itself (since it's a modal one, the op_undo_depth
3462 * trick does not work here). */
3463 break;
3464 }
3465 case OL_LIB_RELOAD: {
3466 outliner_do_libdata_operation(C, op->reports, scene, space_outliner, lib_reload_fn);
3467 /* No undo push here, operator does it itself (since it's a modal one, the op_undo_depth
3468 * trick does not work here). */
3469 break;
3470 }
3471 default:
3472 /* invalid - unhandled */
3473 break;
3474 }
3475
3477
3478 /* wrong notifier still... */
3480
3481 /* XXX: this is just so that outliner is always up to date */
3483
3484 return OPERATOR_FINISHED;
3485}
3486
3488{
3489 /* identifiers */
3490 ot->name = "Outliner Library Operation";
3491 ot->idname = "OUTLINER_OT_lib_operation";
3492
3493 /* callbacks */
3494 ot->invoke = WM_menu_invoke;
3497
3498 ot->prop = RNA_def_enum(
3499 ot->srna, "type", outliner_lib_op_type_items, 0, "Library Operation", "");
3500}
3501
3503
3504/* -------------------------------------------------------------------- */
3507
3509 SpaceOutliner *space_outliner,
3510 int type,
3511 ID *newid,
3512 void (*operation_fn)(TreeElement *, TreeStoreElem *, TreeStoreElem *, ID *))
3513{
3514 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
3515 TreeStoreElem *tselem = TREESTORE(te);
3516 if (tselem->flag & TSE_SELECTED) {
3517 if (tselem->type == type) {
3518 TreeStoreElem *tsep = te->parent ? TREESTORE(te->parent) : nullptr;
3519 operation_fn(te, tselem, tsep, newid);
3520 }
3521 }
3522 });
3523}
3524
3525static void actionset_id_fn(TreeElement * /*te*/,
3526 TreeStoreElem *tselem,
3527 TreeStoreElem *tsep,
3528 ID *actId)
3529{
3530 bAction *act = id_cast<bAction *>(actId);
3531
3532 if (tselem->type == TSE_ANIM_DATA) {
3533 /* "animation" entries - action is child of this */
3534 BKE_animdata_set_action(nullptr, tselem->id, act);
3535 }
3536 /* TODO: if any other "expander" channels which own actions need to support this menu,
3537 * add: tselem->type = ...
3538 */
3539 else if (tsep && (tsep->type == TSE_ANIM_DATA)) {
3540 /* "animation" entries case again */
3541 BKE_animdata_set_action(nullptr, tsep->id, act);
3542 }
3543 /* TODO: other cases not supported yet. */
3544}
3545
3547{
3548 Main *bmain = CTX_data_main(C);
3549 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3550 int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
3551 bAction *act;
3552
3553 TreeElement *te = get_target_element(space_outliner);
3554 get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel);
3555
3556 /* get action to use */
3557 act = static_cast<bAction *>(BLI_findlink(&bmain->actions, RNA_enum_get(op->ptr, "action")));
3558
3559 if (act == nullptr) {
3560 BKE_report(op->reports, RPT_ERROR, "No valid action to add");
3561 return OPERATOR_CANCELLED;
3562 }
3563
3564 /* perform action if valid channel */
3565 if (datalevel == TSE_ANIM_DATA) {
3566 outliner_do_id_set_operation(space_outliner, datalevel, id_cast<ID *>(act), actionset_id_fn);
3567 }
3568 else if (idlevel == ID_AC) {
3569 outliner_do_id_set_operation(space_outliner, idlevel, id_cast<ID *>(act), actionset_id_fn);
3570 }
3571 else {
3572 return OPERATOR_CANCELLED;
3573 }
3574
3575 /* set notifier that things have changed */
3578 ED_undo_push(C, "Set action");
3579
3580 /* done */
3581 return OPERATOR_FINISHED;
3582}
3583
3585{
3586 PropertyRNA *prop;
3587
3588 /* identifiers */
3589 ot->name = "Outliner Set Action";
3590 ot->idname = "OUTLINER_OT_action_set";
3591 ot->description = "Change the active action used";
3592
3593 /* API callbacks. */
3597
3598 /* flags */
3600
3601 /* props */
3602 /* TODO: this would be nicer as an ID-pointer... */
3603 prop = RNA_def_enum(ot->srna, "action", rna_enum_dummy_NULL_items, 0, "Action", "");
3606 ot->prop = prop;
3607}
3608
3610
3611/* -------------------------------------------------------------------- */
3614
3626
3629 "CLEAR_ANIMDATA",
3630 0,
3631 "Clear Animation Data",
3632 "Remove this animation data container"},
3633 {OUTLINER_ANIMOP_SET_ACT, "SET_ACT", 0, "Set Action", ""},
3634 {OUTLINER_ANIMOP_CLEAR_ACT, "CLEAR_ACT", 0, "Unlink Action", ""},
3635 {OUTLINER_ANIMOP_REFRESH_DRV, "REFRESH_DRIVERS", 0, "Refresh Drivers", ""},
3636 {OUTLINER_ANIMOP_CLEAR_DRV, "CLEAR_DRIVERS", 0, "Clear Drivers", ""},
3637 {0, nullptr, 0, nullptr, nullptr},
3638};
3639
3641{
3643 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3644 int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
3645 TreeElement *te = get_target_element(space_outliner);
3646 get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel);
3647
3648 if (datalevel != TSE_ANIM_DATA) {
3649 return OPERATOR_CANCELLED;
3650 }
3651
3652 /* perform the core operation */
3654 switch (event) {
3656 /* Remove Animation Data - this may remove the active action, in some cases... */
3657 outliner_do_data_operation(space_outliner, datalevel, event, clear_animdata_fn, nullptr);
3658
3660 ED_undo_push(C, "Clear Animation Data");
3661 break;
3662
3664 /* delegate once again... */
3665 wm->op_undo_depth++;
3667 C, "OUTLINER_OT_action_set", wm::OpCallContext::InvokeRegionWin, nullptr, nullptr);
3668 wm->op_undo_depth--;
3669 ED_undo_push(C, "Set active action");
3670 break;
3671
3673 /* clear active action - using standard rules */
3674 outliner_do_data_operation(space_outliner, datalevel, event, unlinkact_animdata_fn, nullptr);
3675
3677 ED_undo_push(C, "Unlink action");
3678 break;
3679
3682 space_outliner, datalevel, event, refreshdrivers_animdata_fn, nullptr);
3683
3685 // ED_undo_push(C, "Refresh Drivers"); /* No undo needed - shouldn't have any impact? */
3686 break;
3687
3690 space_outliner, datalevel, event, cleardrivers_animdata_fn, nullptr);
3691
3693 ED_undo_push(C, "Clear Drivers");
3694 break;
3695
3696 default: /* Invalid. */
3697 break;
3698 }
3699
3700 /* update dependencies */
3702
3703 return OPERATOR_FINISHED;
3704}
3705
3707{
3708 /* identifiers */
3709 ot->name = "Outliner Animation Data Operation";
3710 ot->idname = "OUTLINER_OT_animdata_operation";
3711
3712 /* callbacks */
3713 ot->invoke = WM_menu_invoke;
3716
3717 ot->flag = 0;
3718
3719 ot->prop = RNA_def_enum(ot->srna, "type", prop_animdata_op_types, 0, "Animation Operation", "");
3720}
3721
3723
3724/* -------------------------------------------------------------------- */
3727
3729 {OL_CONSTRAINTOP_ENABLE, "ENABLE", ICON_HIDE_OFF, "Enable", ""},
3730 {OL_CONSTRAINTOP_DISABLE, "DISABLE", ICON_HIDE_ON, "Disable", ""},
3731 {OL_CONSTRAINTOP_DELETE, "DELETE", ICON_X, "Delete", ""},
3732 {0, nullptr, 0, nullptr, nullptr},
3733};
3734
3736{
3737 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3739
3740 outliner_do_data_operation(space_outliner, TSE_CONSTRAINT, event, constraint_fn, C);
3741
3742 if (event == OL_CONSTRAINTOP_DELETE) {
3743 outliner_cleanup_tree(space_outliner);
3744 }
3745
3746 ED_undo_push(C, "Constraint operation");
3747
3748 return OPERATOR_FINISHED;
3749}
3750
3752{
3753 /* identifiers */
3754 ot->name = "Outliner Constraint Operation";
3755 ot->idname = "OUTLINER_OT_constraint_operation";
3756
3757 /* callbacks */
3758 ot->invoke = WM_menu_invoke;
3761
3762 ot->flag = 0;
3763
3764 ot->prop = RNA_def_enum(
3765 ot->srna, "type", prop_constraint_op_types, 0, "Constraint Operation", "");
3766}
3767
3769
3770/* -------------------------------------------------------------------- */
3773
3775 {OL_MODIFIER_OP_APPLY, "APPLY", ICON_CHECKMARK, "Apply", ""},
3776 {OL_MODIFIER_OP_DELETE, "DELETE", ICON_X, "Delete", ""},
3778 {OL_MODIFIER_OP_TOGVIS, "TOGVIS", ICON_RESTRICT_VIEW_OFF, "Toggle Viewport Use", ""},
3779 {OL_MODIFIER_OP_TOGREN, "TOGREN", ICON_RESTRICT_RENDER_OFF, "Toggle Render Use", ""},
3780 {0, nullptr, 0, nullptr, nullptr},
3781};
3782
3784{
3785 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3787
3788 ModifierFnArgs args{};
3789 args.C = C;
3790 args.reports = op->reports;
3791
3792 outliner_do_data_operation(space_outliner, TSE_MODIFIER, event, modifier_fn, &args);
3793
3795 outliner_cleanup_tree(space_outliner);
3796 }
3797
3798 ED_undo_push(C, "Modifier operation");
3799
3800 return OPERATOR_FINISHED;
3801}
3802
3804{
3805 /* identifiers */
3806 ot->name = "Outliner Modifier Operation";
3807 ot->idname = "OUTLINER_OT_modifier_operation";
3808
3809 /* callbacks */
3810 ot->invoke = WM_menu_invoke;
3813
3814 ot->flag = 0;
3815
3816 ot->prop = RNA_def_enum(ot->srna, "type", prop_modifier_op_types, 0, "Modifier Operation", "");
3817}
3818
3820
3821/* -------------------------------------------------------------------- */
3824
3826{
3828 return false;
3829 }
3830 const SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3831 const TreeElement *te = get_target_element(space_outliner);
3832
3833 if (te == nullptr) {
3834 return false;
3835 }
3836
3837 int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
3838 get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel);
3839 return ELEM(
3841}
3842
3844{
3845 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3846 int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
3847 TreeElement *te = get_target_element(space_outliner);
3848 get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel);
3849
3851 switch (datalevel) {
3852 case TSE_POSE_CHANNEL: {
3853 outliner_do_data_operation(space_outliner, datalevel, event, pchan_fn, nullptr);
3855 ED_undo_push(C, "PoseChannel operation");
3856
3857 break;
3858 }
3859 case TSE_BONE: {
3860 outliner_do_data_operation(space_outliner, datalevel, event, bone_fn, nullptr);
3862 ED_undo_push(C, "Bone operation");
3863
3864 break;
3865 }
3866 case TSE_EBONE: {
3867 outliner_do_data_operation(space_outliner, datalevel, event, ebone_fn, nullptr);
3869 ED_undo_push(C, "EditBone operation");
3870
3871 break;
3872 }
3873 case TSE_STRIP: {
3874 Scene *sequencer_scene = CTX_data_sequencer_scene(C);
3875 outliner_do_data_operation(space_outliner, datalevel, event, sequence_fn, sequencer_scene);
3877 ED_undo_push(C, "Sequencer operation");
3878
3879 break;
3880 }
3881 case TSE_GP_LAYER: {
3882 outliner_do_data_operation(space_outliner, datalevel, event, gpencil_layer_fn, nullptr);
3884 ED_undo_push(C, "Grease Pencil Layer operation");
3885
3886 break;
3887 }
3889 outliner_do_data_operation(space_outliner, datalevel, event, grease_pencil_node_fn, nullptr);
3891 ED_undo_push(C, "Grease Pencil Node operation");
3892 break;
3893 }
3894 case TSE_RNA_STRUCT:
3895 if (event == OL_DOP_SELECT_LINKED) {
3896 outliner_do_data_operation(space_outliner, datalevel, event, data_select_linked_fn, C);
3897 }
3898
3899 break;
3900
3901 default:
3902 BKE_report(op->reports, RPT_WARNING, "Not yet implemented");
3903 break;
3904 }
3905
3906 return OPERATOR_FINISHED;
3907}
3908
3909/* Dynamically populate an enum of Keying Sets */
3911 PointerRNA * /*ptr*/,
3912 PropertyRNA * /*prop*/,
3913 bool * /*r_free*/)
3914{
3915 /* Check for invalid states. */
3916 if (C == nullptr) {
3918 }
3919
3920 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3921 if (space_outliner == nullptr) {
3923 }
3924
3925 TreeElement *te = get_target_element(space_outliner);
3926 if (te == nullptr) {
3928 }
3929
3930 TreeStoreElem *tselem = TREESTORE(te);
3931
3932 static const EnumPropertyItem optype_sel_and_hide[] = {
3933 {OL_DOP_SELECT, "SELECT", 0, "Select", ""},
3934 {OL_DOP_DESELECT, "DESELECT", 0, "Deselect", ""},
3935 {OL_DOP_HIDE, "HIDE", 0, "Hide", ""},
3936 {OL_DOP_UNHIDE, "UNHIDE", 0, "Unhide", ""},
3937 {0, nullptr, 0, nullptr, nullptr}};
3938
3939 static const EnumPropertyItem optype_sel_linked[] = {
3940 {OL_DOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""},
3941 {0, nullptr, 0, nullptr, nullptr}};
3942
3943 if (tselem->type == TSE_RNA_STRUCT) {
3944 return optype_sel_linked;
3945 }
3946
3947 return optype_sel_and_hide;
3948}
3949
3951{
3952 /* identifiers */
3953 ot->name = "Outliner Data Operation";
3954 ot->idname = "OUTLINER_OT_data_operation";
3955
3956 /* callbacks */
3957 ot->invoke = WM_menu_invoke;
3960
3961 ot->flag = 0;
3962
3963 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_dummy_DEFAULT_items, 0, "Data Operation", "");
3965}
3966
3968
3969/* -------------------------------------------------------------------- */
3972
3974{
3975 wmOperatorType *ot = WM_operatortype_find(opname, false);
3977 C, WM_operatortype_name(ot, nullptr).c_str(), ICON_NONE);
3978 ui::Layout &layout = *popup_menu_layout(pup);
3979
3980 /* Set this so the default execution context is the same as sub-menus. */
3982
3983 if (WM_operator_poll(C, ot)) {
3984 layout.op_enum(ot->idname, RNA_property_identifier(ot->prop));
3985
3986 layout.separator();
3987 }
3988
3989 layout.menu_contents("OUTLINER_MT_context_menu");
3990
3991 popup_menu_end(C, pup);
3992
3993 return OPERATOR_INTERFACE;
3994}
3995
3997 ARegion *region,
3998 SpaceOutliner *space_outliner,
3999 TreeElement *te)
4000{
4001 int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
4002 TreeStoreElem *tselem = TREESTORE(te);
4003
4004 int select_flag = OL_ITEM_ACTIVATE | OL_ITEM_SELECT;
4005 if (tselem->flag & TSE_SELECTED) {
4006 select_flag |= OL_ITEM_EXTEND;
4007 }
4008
4009 outliner_item_select(C, space_outliner, te, select_flag);
4010
4011 /* Only redraw, don't rebuild here because TreeElement pointers will
4012 * become invalid and operations will crash. */
4015
4016 get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel);
4017
4018 if (scenelevel) {
4019 return outliner_operator_menu(C, "OUTLINER_OT_scene_operation");
4020 }
4021 if (objectlevel) {
4023 return OPERATOR_FINISHED;
4024 }
4025 if (idlevel) {
4026 switch (idlevel) {
4027 case ID_GR:
4028 WM_menu_name_call(C, "OUTLINER_MT_collection", wm::OpCallContext::InvokeRegionWin);
4029 return OPERATOR_FINISHED;
4030 break;
4031 case ID_LI:
4032 return outliner_operator_menu(C, "OUTLINER_OT_lib_operation");
4033 break;
4034 default:
4035 return outliner_operator_menu(C, "OUTLINER_OT_id_operation");
4036 break;
4037 }
4038 }
4039 else if (datalevel) {
4040 if (datalevel == TSE_ANIM_DATA) {
4041 return outliner_operator_menu(C, "OUTLINER_OT_animdata_operation");
4042 }
4043 if (datalevel == TSE_DRIVER_BASE) {
4044 /* do nothing... no special ops needed yet */
4045 return OPERATOR_CANCELLED;
4046 }
4047 if (datalevel == TSE_LAYER_COLLECTION) {
4048 WM_menu_name_call(C, "OUTLINER_MT_collection", wm::OpCallContext::InvokeRegionWin);
4049 return OPERATOR_FINISHED;
4050 }
4052 WM_menu_name_call(C, "OUTLINER_MT_collection_new", wm::OpCallContext::InvokeRegionWin);
4053 return OPERATOR_FINISHED;
4054 }
4055 if (datalevel == TSE_ID_BASE) {
4056 /* do nothing... there are no ops needed here yet */
4057 return OPERATOR_CANCELLED;
4058 }
4059 if (datalevel == TSE_CONSTRAINT) {
4060 return outliner_operator_menu(C, "OUTLINER_OT_constraint_operation");
4061 }
4062 if (datalevel == TSE_MODIFIER) {
4063 return outliner_operator_menu(C, "OUTLINER_OT_modifier_operation");
4064 }
4065 return outliner_operator_menu(C, "OUTLINER_OT_data_operation");
4066 }
4067
4068 return OPERATOR_CANCELLED;
4069}
4070
4072 wmOperator * /*op*/,
4073 const wmEvent *event)
4074{
4075 ARegion *region = CTX_wm_region(C);
4076 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
4078 float view_mval[2];
4079
4080 if (but) {
4081 button_tooltip_timer_remove(C, but);
4082 }
4083
4085 &region->v2d, event->mval[0], event->mval[1], &view_mval[0], &view_mval[1]);
4086
4088 space_outliner, &space_outliner->runtime->tree, view_mval[1]);
4089 if (!hovered_te) {
4090 /* Let this fall through to 'OUTLINER_MT_context_menu'. */
4091 return OPERATOR_PASS_THROUGH;
4092 }
4093
4094 return do_outliner_operation_event(C, region, space_outliner, hovered_te);
4095}
4096
4098{
4099 ot->name = "Context Menu";
4100 ot->idname = "OUTLINER_OT_operation";
4101 ot->description = "Context menu for item operations";
4102
4104
4106}
4107
4109
4110} // namespace blender::ed::outliner
Functions for backward compatibility with the legacy Action API.
Functions to deal with Armatures.
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_SCENE_COLLECTION_END
#define FOREACH_SCENE_COLLECTION_BEGIN(scene, _instance)
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
Low-level operations for grease pencil.
#define FOREACH_MAIN_ID_END
Definition BKE_main.hh:735
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition BKE_main.hh:729
General operations, lookup, etc. for blender objects.
external readfile function prototypes.
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define ID_IS_OVERRIDE_LIBRARY_VIRTUAL(_id)
Definition DNA_ID.h:733
#define ID_EXTRA_USERS(id)
Definition DNA_ID.h:665
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition DNA_ID.h:729
#define ID_IS_OVERRIDABLE_LIBRARY(_id)
Definition DNA_ID.h:721
#define ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(_id)
Definition DNA_ID.h:715
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_REAL_USERS(id)
Definition DNA_ID.h:679
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define ID_IS_OVERRIDE_LIBRARY_HIERARCHY_ROOT(_id)
Definition DNA_ID.h:739
#define ID_NLA
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
#define TSE_IS_REAL_ID(_tse)
Read Blender memory allocation and freeing.
#define RNA_ENUM_ITEM_SEPR
Definition RNA_types.hh:762
#define C
Definition RandGen.cpp:29
#define MAX_MTEX
Definition Stroke.h:31
#define UI_UNIT_Y
#define UI_SEARCHBOX_BOUNDS
#define UI_UNIT_X
#define ND_SEQUENCER
Definition WM_types.hh:456
#define ND_WORLD
Definition WM_types.hh:471
#define NC_WINDOW
Definition WM_types.hh:388
#define NC_ID
Definition WM_types.hh:408
#define ND_NLA_ACTCHANGE
Definition WM_types.hh:541
#define ND_OB_ACTIVE
Definition WM_types.hh:459
#define NC_WM
Definition WM_types.hh:387
#define ND_DATA
Definition WM_types.hh:552
#define NC_ANIMATION
Definition WM_types.hh:401
#define ND_LIB_OVERRIDE_CHANGED
Definition WM_types.hh:435
#define ND_OB_SELECT
Definition WM_types.hh:461
#define NC_SCENE
Definition WM_types.hh:391
#define ND_LAYER_CONTENT
Definition WM_types.hh:472
#define ND_MODIFIER
Definition WM_types.hh:503
#define NA_EDITED
Definition WM_types.hh:634
#define NC_IMAGE
Definition WM_types.hh:397
#define ND_CONSTRAINT
Definition WM_types.hh:505
#define NA_REMOVED
Definition WM_types.hh:637
#define NC_GPENCIL
Definition WM_types.hh:412
#define ND_LAYER
Definition WM_types.hh:469
#define ND_BONE_SELECT
Definition WM_types.hh:491
#define ND_OB_SHADING
Definition WM_types.hh:476
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_ANIMCHAN
Definition WM_types.hh:539
#define NC_SPACE
Definition WM_types.hh:405
#define NA_SELECTED
Definition WM_types.hh:639
#define ND_SPACE_OUTLINER
Definition WM_types.hh:570
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
btSequentialImpulseConstraintSolverMt int btPersistentManifold int btTypedConstraint ** constraints
Value & lookup_or_add_default(const Key &key)
Definition BLI_map.hh:639
void append(const T &value)
bool is_empty() const
#define str(s)
void bone_deselect(bPoseChannel *pchan)
void bone_select(bPoseChannel *pchan)
bool modifier_apply(Main *bmain, ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md, int mode, bool keep_modifier, bool do_all_keyframes)
void constraint_update(Main *bmain, Object *ob)
void base_select(Base *base, eObjectSelect_Mode mode)
bool editmode_exit(bContext *C, int flag)
void select_linked_by_id(bContext *C, ID *id)
void base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
bool editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag)
bool modifier_remove(ReportList *reports, Main *bmain, Scene *scene, Object *ob, ModifierData *md)
void all_open(const SpaceOutliner &space_outliner, const ConstVisitorFn visitor)
static bool outliner_liboverride_operation_poll(bContext *C)
void OUTLINER_OT_delete(wmOperatorType *ot)
static void unlink_texture_fn(bContext *, ReportList *reports, Scene *, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
static void ebone_fn(int event, TreeElement *te, TreeStoreElem *, void *)
static const EnumPropertyItem outliner_lib_op_type_items[]
static void object_deselect_fn(bContext *C, ReportList *, Scene *, TreeElement *, TreeStoreElem *, TreeStoreElem *tselem)
TreeElement * outliner_find_item_at_y(const SpaceOutliner *space_outliner, const ListBaseT< TreeElement > *tree, float view_co_y)
static bool outliner_do_libdata_operation_selection_set_element(bContext *C, ReportList *reports, Scene *scene, TreeElement *element, TreeStoreElem *tselem, const bool has_parent_selected, outliner_operation_fn operation_fn, eOutlinerLibOpSelectionSet selection_set)
static void id_override_library_create_hierarchy_process(bContext *C, ReportList *reports, OutlinerLibOverrideData &data)
static wmOperatorStatus outliner_scene_operation_exec(bContext *C, wmOperator *op)
void OUTLINER_OT_scene_operation(wmOperatorType *ot)
void OUTLINER_OT_pack_data(wmOperatorType *ot)
static const EnumPropertyItem * outliner_data_op_sets_enum_item_fn(bContext *C, PointerRNA *, PropertyRNA *, bool *)
static void object_select_hierarchy_fn(bContext *C, ReportList *, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *)
static void unlink_action_fn(bContext *C, ReportList *reports, Scene *, TreeElement *, TreeStoreElem *tsep, TreeStoreElem *tselem)
static void unlink_object_fn(bContext *C, ReportList *reports, Scene *, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
static TreeTraversalAction outliner_collect_objects_to_delete(TreeElement *te, void *customdata)
static bool scene_fn(bContext *C, eOutliner_PropSceneOps event, TreeElement *, TreeStoreElem *tselem)
static wmOperatorStatus outliner_animdata_operation_exec(bContext *C, wmOperator *op)
bool outliner_tree_traverse(const SpaceOutliner *space_outliner, ListBaseT< TreeElement > *tree, int filter_te_flag, int filter_tselem_flag, TreeTraversalFunc func, void *customdata)
bool outliner_is_collection_tree_element(const TreeElement *te)
static void get_element_operation_type(const TreeElement *te, int *scenelevel, int *objectlevel, int *idlevel, int *datalevel)
static void clear_animdata_fn(int, TreeElement *, TreeStoreElem *tselem, void *)
void OUTLINER_OT_data_operation(wmOperatorType *ot)
static bool outliner_liboverride_property_remove_do(bContext *C, Main &bmain, TreeStoreElem &tselem, TreeElementOverridesT &override_elem, ReportList *reports)
void OUTLINER_OT_lib_operation(wmOperatorType *ot)
static CLG_LogRef LOG
void OUTLINER_OT_constraint_operation(wmOperatorType *ot)
static const EnumPropertyItem prop_constraint_op_types[]
static const EnumPropertyItem prop_lib_op_selection_set[]
static void modifier_fn(int event, TreeElement *te, TreeStoreElem *, void *arg)
static void object_select_fn(bContext *C, ReportList *, Scene *, TreeElement *, TreeStoreElem *, TreeStoreElem *tselem)
static void id_override_library_clear_single_process(bContext *C, ReportList *, OutlinerLibOverrideData &data)
static void outliner_batch_delete_object_hierarchy(Main *bmain, Scene *scene)
static void refreshdrivers_animdata_fn(int, TreeElement *, TreeStoreElem *tselem, void *)
static wmOperatorStatus outliner_object_operation_exec(bContext *C, wmOperator *op)
void id_delete_tag_fn(bContext *C, ReportList *reports, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *tselem)
static void id_override_library_reset(bContext *C, OutlinerLibOverrideData *data, TreeStoreElem *tselem)
static wmOperatorStatus outliner_constraint_operation_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem prop_scene_op_types[]
static void pchan_fn(int event, TreeElement *te, TreeStoreElem *, void *)
static void merged_element_search_update_fn(const bContext *, void *data, const char *str, ui::SearchItems *items, const bool)
FunctionRef< void(bContext *C, ReportList *reports, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)> outliner_operation_fn
static wmOperatorStatus outliner_id_operation_exec(bContext *C, wmOperator *op)
static void outliner_batch_delete_object_hierarchy_tag(ReportList *reports, Main *bmain, ViewLayer *view_layer, Scene *scene, Base *base)
void OUTLINER_OT_modifier_operation(wmOperatorType *ot)
static void unlinkact_animdata_fn(int, TreeElement *, TreeStoreElem *tselem, void *)
void outliner_collection_delete(bContext *C, Main *bmain, Scene *scene, ReportList *reports, bool do_hierarchy)
TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te)
static void merged_element_search_fn_recursive(const ListBaseT< TreeElement > *tree, short tselem_type, short type, const char *str, ui::SearchItems *items)
static void object_batch_delete_hierarchy_tag_fn(bContext *C, ReportList *reports, Scene *scene, Object *ob)
static void outliner_object_delete_fn(bContext *C, ReportList *reports, Scene *scene, Object *ob)
static wmOperatorStatus outliner_pack_data_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem prop_animdata_op_types[]
static void data_select_linked_fn(int event, TreeElement *te, TreeStoreElem *, void *C_v)
static void merged_element_search_exec_fn(bContext *C, void *, void *element)
static bool outliner_data_operation_poll(bContext *C)
static void id_override_library_resync(OutlinerLibOverrideData *data, TreeStoreElem *tselem)
static void id_fake_user_clear_fn(bContext *, ReportList *reports, Scene *, TreeElement *, TreeStoreElem *, TreeStoreElem *tselem)
static void singleuser_action_fn(bContext *C, ReportList *, Scene *, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
void OUTLINER_OT_object_operation(wmOperatorType *ot)
void outliner_do_object_operation_ex(bContext *C, ReportList *reports, Scene *scene, SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, outliner_operation_fn operation_fn, bool recurse_selected)
static void id_select_linked_fn(bContext *C, ReportList *, Scene *, TreeElement *, TreeStoreElem *, TreeStoreElem *tselem)
static void id_local_fn(bContext *C, ReportList *, Scene *, TreeElement *, TreeStoreElem *, TreeStoreElem *tselem)
static void outliner_do_libdata_operation_selection_set(bContext *C, ReportList *reports, Scene *scene, SpaceOutliner *space_outliner, ListBaseT< TreeElement > &subtree, const bool has_parent_selected, outliner_operation_fn operation_fn, eOutlinerLibOpSelectionSet selection_set)
static void bone_fn(int event, TreeElement *te, TreeStoreElem *, void *)
Collection * outliner_collection_from_tree_element(const TreeElement *te)
static void outliner_do_liboverride_property_selection_set(bContext *C, ReportList *reports, Scene *scene, ListBaseT< TreeElement > &subtree, const bool has_parent_selected, outliner_operation_fn operation_fn)
void OUTLINER_OT_animdata_operation(wmOperatorType *ot)
static void unlink_world_fn(bContext *, ReportList *reports, Scene *, TreeElement *, TreeStoreElem *tsep, TreeStoreElem *tselem)
void lib_relocate_fn(bContext *C, ReportList *, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *tselem)
int tree_element_id_type_to_index(TreeElement *te)
static void id_override_library_clear_single(OutlinerLibOverrideData *data, ReportList *reports, TreeStoreElem *tselem)
static void id_override_library_create_hierarchy(Main &bmain, Scene *scene, ViewLayer *view_layer, OutlinerLibOverrideData &data, ID *id_hierarchy_root_reference, Vector< OutlinerLiboverrideDataIDRoot > &data_idroots, bool &r_aggregated_success)
static void unlink_collection_fn(bContext *C, ReportList *reports, Scene *, TreeElement *, TreeStoreElem *tsep, TreeStoreElem *tselem)
static wmOperatorStatus outliner_lib_operation_exec(bContext *C, wmOperator *op)
static void outliner_do_data_operation(SpaceOutliner *space_outliner, int type, int event, void(*operation_fn)(int, TreeElement *, TreeStoreElem *, void *), void *arg)
static const EnumPropertyItem prop_liboverride_op_types[]
static void id_override_library_delete_hierarchy(OutlinerLibOverrideData *data, TreeStoreElem *tselem)
void OUTLINER_OT_action_set(wmOperatorType *ot)
static bool outliner_id_operation_item_poll(bContext *C, PointerRNA *, PropertyRNA *, const int enum_value)
static const EnumPropertyItem prop_id_op_types[]
static void id_override_library_resync_hierarchy_process(bContext *C, ReportList *reports, OutlinerLibOverrideData &data)
static wmOperatorStatus outliner_data_operation_exec(bContext *C, wmOperator *op)
void id_remap_fn(bContext *C, TreeStoreElem *tselem)
TreeElementT * tree_element_cast(const TreeElement *te)
ID * outliner_search_back(TreeElement *te, short idcode)
static void cleardrivers_animdata_fn(int, TreeElement *, TreeStoreElem *tselem, void *)
static wmOperatorStatus outliner_operator_menu(bContext *C, const char *opname)
void merged_element_search_menu_invoke(bContext *C, TreeElement *parent_te, TreeElement *activate_te)
static wmOperatorStatus outliner_liboverride_property_remove_exec(bContext *C, wmOperator *op)
static TreeElement * get_target_element(const SpaceOutliner *space_outliner)
static void unlink_material_fn(bContext *, ReportList *reports, Scene *, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
static void constraint_fn(int event, TreeElement *te, TreeStoreElem *, void *C_v)
static void actionset_id_fn(TreeElement *, TreeStoreElem *tselem, TreeStoreElem *tsep, ID *actId)
@ OUTLINER_LIB_LIB_SELECTIONSET_SELECTED_AND_CONTENT
static void outliner_batch_delete_object_tag(ReportList *reports, Main *bmain, Scene *scene, Object *object)
static void id_fake_user_set_fn(bContext *, ReportList *reports, Scene *, TreeElement *, TreeStoreElem *, TreeStoreElem *tselem)
void lib_reload_fn(bContext *C, ReportList *, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *tselem)
void outliner_cleanup_tree(SpaceOutliner *space_outliner)
void OUTLINER_OT_liboverride_property_remove(wmOperatorType *ot)
static void singleuser_world_fn(bContext *C, ReportList *, Scene *, TreeElement *, TreeStoreElem *tsep, TreeStoreElem *tselem)
static ui::Block * merged_element_search_menu(bContext *C, ARegion *region, void *data)
static wmOperatorStatus outliner_operation_invoke(bContext *C, wmOperator *, const wmEvent *event)
static void outliner_do_libdata_operation(bContext *C, ReportList *reports, Scene *scene, SpaceOutliner *space_outliner, outliner_operation_fn operation_fn)
static wmOperatorStatus outliner_delete_exec(bContext *C, wmOperator *op)
void OUTLINER_OT_liboverride_troubleshoot_operation(wmOperatorType *ot)
static wmOperatorStatus outliner_liboverride_operation_exec(bContext *C, wmOperator *op)
static wmOperatorStatus outliner_modifier_operation_exec(bContext *C, wmOperator *op)
void OUTLINER_OT_operation(wmOperatorType *ot)
static bool outliner_liboverride_property_remove_poll(bContext *C)
static const EnumPropertyItem * outliner_id_operation_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
static const EnumPropertyItem prop_modifier_op_types[]
void item_rename_fn(bContext *C, ReportList *reports, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *tselem)
static bool outliner_do_scene_operation(bContext *C, SpaceOutliner *space_outliner, eOutliner_PropSceneOps event, bool(*operation_fn)(bContext *, eOutliner_PropSceneOps, TreeElement *, TreeStoreElem *))
static void sequence_fn(int event, TreeElement *te, TreeStoreElem *, void *scene_ptr)
static void outliner_do_id_set_operation(SpaceOutliner *space_outliner, int type, ID *newid, void(*operation_fn)(TreeElement *, TreeStoreElem *, TreeStoreElem *, ID *))
static void gpencil_layer_fn(int event, TreeElement *te, TreeStoreElem *, void *)
static wmOperatorStatus do_outliner_operation_event(bContext *C, ARegion *region, SpaceOutliner *space_outliner, TreeElement *te)
void(*)(bContext *C, ReportList *reports, Scene *scene, Object *ob) OutlinerDeleteFn
static const EnumPropertyItem prop_liboverride_troubleshoot_op_types[]
static wmOperatorStatus outliner_action_set_exec(bContext *C, wmOperator *op)
void outliner_do_object_operation(bContext *C, ReportList *reports, Scene *scene, SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, outliner_operation_fn operation_fn)
void OUTLINER_OT_id_operation(wmOperatorType *ot)
void OUTLINER_OT_liboverride_operation(wmOperatorType *ot)
static void id_override_library_delete_hierarchy_process(bContext *C, ReportList *, OutlinerLibOverrideData &data)
void outliner_item_select(bContext *C, SpaceOutliner *space_outliner, TreeElement *te, short select_flag)
static void id_override_library_create_hierarchy_pre_process(bContext *C, OutlinerLibOverrideData *data, ReportList *reports, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
static void outliner_do_object_delete(bContext *C, ReportList *reports, Scene *scene, const Set< Object * > &objects_to_delete, OutlinerDeleteFn delete_fn)
static const EnumPropertyItem prop_object_op_types[]
TreeElement * outliner_find_element_with_flag(const ListBaseT< TreeElement > *lb, short flag)
static void grease_pencil_node_fn(int event, TreeElement *te, TreeStoreElem *, void *)
static bool outliner_operation_tree_element_poll(bContext *C)
void select_strip_single(Scene *scene, Strip *strip, bool deselect_all)
void relations_invalidate_cache(Scene *scene, Strip *strip)
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
Button * context_active_but_get(const bContext *C)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
void WM_window_set_active_scene(Main *bmain, bContext *C, wmWindow *win, Scene *scene)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
@ DRIVER_FLAG_INVALID
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
@ RPT_WARNING
Definition BKE_report.hh:40
Scene * CTX_data_sequencer_scene(const bContext *C)
void BKE_id_delete(Main *bmain, void *idv, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool BKE_lib_override_library_create(Main *bmain, Scene *scene, ViewLayer *view_layer, Library *owner_library, ID *id_root_reference, ID *id_hierarchy_root_reference, ID *id_instance_hint, ID **r_id_root_override, const bool do_fully_editable)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
PointerRNA RNA_id_pointer_create(ID *id)
void BKE_fcurves_free(ListBaseT< FCurve > *list)
const char * RNA_property_identifier(const PropertyRNA *prop)
void ED_outliner_select_sync_from_outliner(bContext *C, SpaceOutliner *space_outliner)
bool BKE_idtype_idcode_is_linkable(short idcode)
Definition idtype.cc:307
void void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(1
Definition lib_remap.cc:701
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us)
void ED_outliner_select_sync_from_all_tag(bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
bool ED_operator_outliner_active(bContext *C)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
ID * BKE_lib_override_library_create_from_id(Main *bmain, ID *reference_id, bool do_tagged_remap)
@ ID_REMAP_SKIP_INDIRECT_USAGE
bool BKE_lib_override_library_resync(Main *bmain, Scene *scene, ViewLayer *view_layer, ID *id_root, Collection *override_resync_residual_storage, bool do_hierarchy_enforce, BlendFileReadReport *reports)
void id_fake_user_set(ID *id)
Definition lib_id.cc:471
eID_OverrideLib_Op
Definition DNA_ID.h:182
@ LIBOVERRIDE_OP_INSERT_AFTER
Definition DNA_ID.h:200
@ LIBOVERRIDE_OP_INSERT_BEFORE
Definition DNA_ID.h:202
int char * BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void MEM_delete_void(void *vmemh)
@ LIBOVERRIDE_FLAG_SYSTEM_DEFINED
Definition DNA_ID.h:308
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_SCENE_COLLECTION_BASE
@ TSE_LIBRARY_OVERRIDE_OPERATION
ViewLayer * CTX_data_view_layer(const bContext *C)
void ED_outliner_select_sync_from_object_tag(bContext *C)
Vector< PointerRNA > ED_operator_get_ids_from_context_as_vec(const bContext *C)
const EnumPropertyItem * RNA_action_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
bool BKE_collection_has_object(Collection *collection, const Object *ob)
bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
Definition anim_data.cc:135
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_lib_override_library_delete(Main *bmain, ID *id_root)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_lib_override_library_main_hierarchy_root_ensure(Main *bmain, LibOverride_HierarchyRoot_ValidateOptions options={}, ReportList *reports=nullptr)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void BKE_animdata_free(ID *id, bool do_id_user)
Definition anim_data.cc:174
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
Object * CTX_data_edit_object(const bContext *C)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
bool ED_scene_delete(bContext *C, Main *bmain, Scene *scene) ATTR_NONNULL()
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
void WM_menu_name_call(bContext *C, const char *menu_name, wm::OpCallContext context)
void BKE_lib_override_library_make_local(Main *bmain, ID *id)
size_t BKE_id_multi_tagged_delete(Main *bmain, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
void BKE_id_newptr_and_tag_clear(ID *id)
Definition lib_id.cc:487
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool BKE_constraint_remove_ex(ListBaseT< bConstraint > *list, struct Object *ob, struct bConstraint *con)
void BKE_lib_override_library_property_operation_delete(IDOverrideLibraryProperty *liboverride_property, IDOverrideLibraryPropertyOperation *liboverride_property_operation)
void BKE_lib_override_library_id_reset(Main *bmain, ID *id_root, bool do_reset_system_override)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
const EnumPropertyItem rna_enum_dummy_DEFAULT_items[]
Definition rna_rna.cc:34
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1314
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
Definition lib_id.cc:1142
bool RNA_struct_is_ID(const StructRNA *type)
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
void BKE_image_packfile_ensure(Main *bmain, Image *image, ReportList *reports, const char *data, int data_len)
void BKE_main_id_newptr_and_tag_clear(Main *bmain)
Definition lib_id.cc:2097
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us)
Main * CTX_data_main(const bContext *C)
bool BKE_lib_override_library_is_hierarchy_leaf(Main *bmain, ID *id)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1158
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:502
void BKE_constraints_active_set(ListBaseT< bConstraint > *list, struct bConstraint *con)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
@ ID_TAG_INDIRECT
Definition DNA_ID.h:851
@ ID_TAG_EXTERN
Definition DNA_ID.h:845
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
wmOperatorStatus WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *)
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:775
@ ID_FLAG_EMBEDDED_DATA_LIB_OVERRIDE
Definition DNA_ID.h:786
@ LIB_ID_MAKELOCAL_ASSET_DATA_CLEAR
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
bool BKE_library_ID_is_indirectly_used(Main *bmain, void *idv)
Definition lib_query.cc:652
bool BKE_image_has_packedfile(const Image *image)
ATTR_WARN_UNUSED_RESULT const void * element
bool BKE_lib_id_make_local(Main *bmain, ID *id, int flags)
Definition lib_id.cc:672
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
ReportList * CTX_wm_reports(const bContext *C)
bool ED_operator_region_outliner_active(bContext *C)
void BKE_lib_override_library_property_delete(IDOverrideLibrary *liboverride, IDOverrideLibraryProperty *liboverride_property)
bool WM_operator_poll(bContext *C, wmOperatorType *ot)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
void id_us_min(ID *id)
Definition lib_id.cc:441
void BKE_lib_override_library_id_hierarchy_reset(Main *bmain, ID *id_root, bool do_reset_system_override)
void id_fake_user_clear(ID *id)
Definition lib_id.cc:479
ARegion * CTX_wm_region(const bContext *C)
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:727
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
bool RNA_property_copy(Main *bmain, PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index, IDOverrideLibraryProperty *removed_oprop, IDOverrideLibraryPropertyOperation *removed_opop)
#define TREESTORE(a)
#define TSELEM_OPEN(telm, sv)
ListBaseT< FCurve > drivers
struct Object * object
CollectionColorTag color_tag
struct Material ** mat
eFCurve_Flags flag
ChannelDriver * driver
ListBaseT< IDOverrideLibraryPropertyOperation > operations
Definition DNA_ID.h:326
eID_OverrideLib_Flag flag
Definition DNA_ID.h:356
struct ID * hierarchy_root
Definition DNA_ID.h:352
char name[258]
Definition DNA_ID.h:433
unsigned int session_uid
Definition DNA_ID.h:463
struct Library * lib
Definition DNA_ID.h:421
short flag
Definition DNA_ID.h:439
IDOverrideLibrary * override_library
Definition DNA_ID.h:495
bke::library::LibraryRuntime * runtime
Definition DNA_ID.h:591
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< bAction > actions
Definition BKE_main.hh:408
struct Material ** mat
struct Object * parent
ListBaseT< bConstraint > constraints
struct Collection * instance_collection
struct Material ** mat
StructRNA * type
Definition RNA_types.hh:63
struct World * world
struct Collection * master_collection
eSpaceOutliner_Mode outlinevis
ed::outliner::SpaceOutliner_Runtime * runtime
eTreeStoreElem_Flag flag
struct Material ** mat
Map< ID *, Vector< OutlinerLiboverrideDataIDRoot > > id_hierarchy_roots
void id_root_add(ID *id_hierarchy_root_reference, ID *id_root_reference, ID *id_instance_hint, const bool is_override_instancing_object)
void id_root_set(ID *id_hierarchy_root_reference)
ListBaseT< ed::outliner::TreeElement > tree
void operator_context_set(wm::OpCallContext opcontext)
void menu_contents(StringRef menuname)
void op_enum(StringRefNull opname, StringRefNull propname, IDProperty *properties, wm::OpCallContext context, eUI_Item_Flag flag, const int active=-1)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)