Blender V5.3
object_collection.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
11#include "BLI_listbase.hh"
12#include "BLI_path_utils.hh"
13#include "BLI_string_utf8.hh"
14#include "BLI_utildefines.hh"
15
16#include "BLO_readfile.hh"
17
19#include "DNA_object_types.h"
20#include "DNA_scene_types.h"
21
23#include "BKE_collection.hh"
24#include "BKE_context.hh"
25#include "BKE_file_handler.hh"
26#include "BKE_idprop.hh"
27#include "BKE_layer.hh"
28#include "BKE_lib_id.hh"
29#include "BKE_library.hh"
30#include "BKE_main.hh"
31#include "BKE_object.hh"
32#include "BKE_report.hh"
33#include "BKE_screen.hh"
34
35#include "BLT_translation.hh"
36
37#include "DEG_depsgraph.hh"
39
40#include "ED_object.hh"
41#include "ED_screen.hh"
42#include "ED_undo.hh"
43
44#include "WM_api.hh"
45#include "WM_types.hh"
46
47#include "RNA_access.hh"
48#include "RNA_define.hh"
49#include "RNA_enum_types.hh"
50#include "RNA_prototypes.hh"
51
52#include "UI_interface.hh"
53#include "UI_interface_icons.hh"
55
56#include "object_intern.hh"
57
58namespace blender::ed::object {
59
60/********************* 3d view operators ***********************/
61
62/* can be called with C == nullptr */
64 PointerRNA * /*ptr*/,
65 PropertyRNA * /*prop*/,
66 bool *r_free)
67{
68 if (C == nullptr) {
70 }
71
72 Main *bmain = CTX_data_main(C);
73 Scene *scene = CTX_data_scene(C);
74 Object *ob;
75 EnumPropertyItem *item = nullptr, item_tmp = {0};
76 int totitem = 0;
77
78 ob = context_object(C);
79
80 /* check that the object exists */
81 if (ob) {
82 Collection *collection;
83 int i = 0, count = 0;
84
85 /* if 2 or more collections, add option to add to all collections */
86 collection = nullptr;
87 while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
88 count++;
89 }
90
91 if (count >= 2) {
92 item_tmp.identifier = item_tmp.name = "All Collections";
93 item_tmp.value = INT_MAX; /* this will give nullptr on lookup */
94 RNA_enum_item_add(&item, &totitem, &item_tmp);
95 RNA_enum_item_add_separator(&item, &totitem);
96 }
97
98 /* add collections */
99 collection = nullptr;
100 while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
101 item_tmp.identifier = item_tmp.name = collection->id.name + 2;
102 item_tmp.icon = ui::icon_color_from_collection(collection);
103 item_tmp.value = i;
104 RNA_enum_item_add(&item, &totitem, &item_tmp);
105 i++;
106 }
107 }
108
109 RNA_enum_item_end(&item, &totitem);
110 *r_free = true;
111
112 return item;
113}
114
115/* get the collection back from the enum index, quite awkward and UI specific */
117 Scene *scene,
118 Object *ob,
119 const int collection_object_index)
120{
121 Collection *collection = nullptr;
122 int i = 0;
123 while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
124 if (i == collection_object_index) {
125 break;
126 }
127 i++;
128 }
129
130 return collection;
131}
132
134{
135 Object *ob = context_object(C);
136 Main *bmain = CTX_data_main(C);
137 Scene *scene = CTX_data_scene(C);
138 int single_collection_index = RNA_enum_get(op->ptr, "collection");
140 bmain, scene, ob, single_collection_index);
141 bool is_cycle = false;
142 bool changed_multi = false;
143
144 if (ob == nullptr) {
145 return OPERATOR_CANCELLED;
146 }
147
148 /* now add all selected objects to the collection(s) */
149 FOREACH_COLLECTION_BEGIN (bmain, scene, Collection *, collection) {
150 if (single_collection && collection != single_collection) {
151 continue;
152 }
153 if (!BKE_collection_has_object(collection, ob)) {
154 continue;
155 }
156
157 bool changed = false;
158 CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
159 if (BKE_collection_has_object(collection, base->object)) {
160 continue;
161 }
162
163 if (!BKE_collection_object_cyclic_check(bmain, base->object, collection)) {
164 BKE_collection_object_add(bmain, collection, base->object);
165 changed = true;
166 }
167 else {
168 is_cycle = true;
169 }
170 }
172
173 if (changed) {
175 changed_multi = true;
176 }
177 }
179
180 if (is_cycle) {
181 BKE_report(op->reports, RPT_WARNING, "Skipped some collections because of cycle detected");
182 }
183
184 if (!changed_multi) {
185 return OPERATOR_CANCELLED;
186 }
187
190
191 return OPERATOR_FINISHED;
192}
193
195{
196 PropertyRNA *prop;
197
198 /* identifiers */
199 ot->name = "Add Selected to Active Object's Collection";
200 ot->description =
201 "Add selected objects to one of the collections the active-object is part of. "
202 "Optionally add to \"All Collections\" to ensure selected objects are included in "
203 "the same collections as the active object";
204 ot->idname = "COLLECTION_OT_objects_add_active";
205
206 /* API callbacks. */
210
211 /* flags */
213
214 /* properties */
215 prop = RNA_def_enum(ot->srna,
216 "collection",
218 0,
219 "Collection",
220 "The collection to add other selected objects to");
223 ot->prop = prop;
224}
225
227{
228 Main *bmain = CTX_data_main(C);
229 Scene *scene = CTX_data_scene(C);
230 ViewLayer *view_layer = CTX_data_view_layer(C);
231 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
233 int single_collection_index = RNA_enum_get(op->ptr, "collection");
235 bmain, scene, ob, single_collection_index);
236 bool changed_multi = false;
237
238 if (ob == nullptr) {
239 return OPERATOR_CANCELLED;
240 }
241
242 /* Linking to same collection requires its own loop so we can avoid
243 * looking up the active objects collections each time. */
244 FOREACH_COLLECTION_BEGIN (bmain, scene, Collection *, collection) {
245 if (single_collection && collection != single_collection) {
246 continue;
247 }
248
249 if (BKE_collection_has_object(collection, ob)) {
250 /* Remove collections from selected objects */
251 bool changed = false;
252 CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
253 BKE_collection_object_remove(bmain, collection, base->object, false);
254 changed = true;
255 }
257
258 if (changed) {
260 changed_multi = true;
261 }
262 }
263 }
265
266 if (!changed_multi) {
267 BKE_report(op->reports, RPT_ERROR, "Active object contains no collections");
268 }
269
272
273 return OPERATOR_FINISHED;
274}
275
277{
278 PropertyRNA *prop;
279
280 /* identifiers */
281 ot->name = "Remove Selected from Active Collection";
282 ot->description = "Remove the object from an object collection that contains the active object";
283 ot->idname = "COLLECTION_OT_objects_remove_active";
284
285 /* API callbacks. */
289
290 /* flags */
292
293 /* properties */
294 prop = RNA_def_enum(ot->srna,
295 "collection",
297 0,
298 "Collection",
299 "The collection to remove other selected objects from");
302 ot->prop = prop;
303}
304
306{
307 Main *bmain = CTX_data_main(C);
308 Scene *scene = CTX_data_scene(C);
309
310 CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
311 BKE_object_groups_clear(bmain, scene, base->object);
312 }
314
317
318 return OPERATOR_FINISHED;
319}
320
322{
323 /* identifiers */
324 ot->name = "Remove from All Collections";
325 ot->description = "Remove selected objects from all collections";
326 ot->idname = "COLLECTION_OT_objects_remove_all";
327
328 /* API callbacks. */
331
332 /* flags */
334}
335
337{
338 Object *ob = context_object(C);
339 Main *bmain = CTX_data_main(C);
340 Scene *scene = CTX_data_scene(C);
341 int single_collection_index = RNA_enum_get(op->ptr, "collection");
343 bmain, scene, ob, single_collection_index);
344 bool changed_multi = false;
345
346 if (ob == nullptr) {
347 return OPERATOR_CANCELLED;
348 }
349
350 FOREACH_COLLECTION_BEGIN (bmain, scene, Collection *, collection) {
351 if (single_collection && collection != single_collection) {
352 continue;
353 }
354 if (!BKE_collection_has_object(collection, ob)) {
355 continue;
356 }
357
358 /* now remove all selected objects from the collection */
359 bool changed = false;
360 CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
361 BKE_collection_object_remove(bmain, collection, base->object, false);
362 changed = true;
363 }
365
366 if (changed) {
368 changed_multi = true;
369 }
370 }
372
373 if (!changed_multi) {
374 return OPERATOR_CANCELLED;
375 }
376
379
380 return OPERATOR_FINISHED;
381}
382
384{
385 PropertyRNA *prop;
386
387 /* identifiers */
388 ot->name = "Remove from Collection";
389 ot->description = "Remove selected objects from a collection";
390 ot->idname = "COLLECTION_OT_objects_remove";
391
392 /* API callbacks. */
396
397 /* flags */
399
400 /* properties */
401 prop = RNA_def_enum(ot->srna,
402 "collection",
404 0,
405 "Collection",
406 "The collection to remove this object from");
409 ot->prop = prop;
410}
411
413{
414 Main *bmain = CTX_data_main(C);
415 char name[MAX_ID_NAME - 2]; /* id name */
416 bool changed = false;
417
418 RNA_string_get(op->ptr, "name", name);
419
420 Collection *collection = BKE_collection_add(bmain, nullptr, name);
421 id_fake_user_set(&collection->id);
422
423 CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
424 BKE_collection_object_add(bmain, collection, base->object);
425 changed = true;
426 }
428
429 if (changed) {
431 }
432
435
436 return OPERATOR_FINISHED;
437}
438
440{
441 /* identifiers */
442 ot->name = "Create New Collection";
443 ot->description = "Create an object collection from selected objects";
444 ot->idname = "COLLECTION_OT_create";
445
446 /* API callbacks. */
449
450 /* flags */
452
453 RNA_def_string(ot->srna, "name", nullptr, MAX_ID_NAME - 2, "Name", "Name of the new collection");
454}
455
457 std::string &reason)
458{
459 if (!collection) {
460 reason = N_("Could not find an active collection");
461 return false;
462 }
463 if (!BKE_collection_is_content_editable(collection, &reason)) {
464 return false;
465 }
466 if (!BKE_collection_is_empty(collection)) {
467 reason = N_("Collection needs to be empty");
468 return false;
469 }
470 return true;
471}
472
474{
475 const Collection *collection = CTX_data_collection(C);
476 std::string reason;
477 if (!collection_importer_add_collection_validate(collection, reason)) {
479 return false;
480 }
481 return true;
482}
483
485{
486 const Collection *collection = CTX_data_collection(C);
487 if (!collection || !collection->importer || ID_IS_LINKED(&collection->id) ||
488 ID_IS_OVERRIDE_LIBRARY(&collection->id))
489 {
490 return false;
491 }
492
493 return true;
494}
495
497{
498 const Collection *collection = CTX_data_collection(C);
499 if (!collection || !collection->importer || ID_IS_LINKED(&collection->id) ||
500 ID_IS_OVERRIDE_LIBRARY(&collection->id))
501 {
502 return false;
503 }
504
505 const IDProperty *import_properties = collection->importer->import_properties;
506 const std::optional<StringRefNull> filepath = import_properties ?
507 IDP_group_lookup_string(*import_properties,
508 "filepath") :
509 std::nullopt;
510 if (!filepath.has_value() || filepath->is_empty()) {
511 CTX_wm_operator_poll_msg_set(C, "Filepath needs to be set first");
512 return false;
513 }
514
515 return true;
516}
517
526
528 wmOperator *op,
529 const bool do_undo_push,
531{
532 const std::string name = RNA_string_get(op->ptr, "name");
534 if (r_fh) {
535 *r_fh = fh;
536 }
537 if (!fh) {
538 BKE_reportf(op->reports, RPT_ERROR, "File handler '%s' not found", name.c_str());
539 return nullptr;
540 }
541
542 Collection *collection = CTX_data_collection(C);
543 std::string reason;
544 if (collection && collection->importer) {
545 /* Note: In theory, this is weak, as another collection with an importer of the same type might
546 * have been made active between the invocation of the file-browser, and the call to this
547 * function from the 'exec' callback. Very unlikely in practice, so think that we can live with
548 * this for now. */
549 if (StringRef(collection->importer->fh_idname) == fh->idname) {
550 return collection;
551 }
552 BKE_report(op->reports, RPT_ERROR, "The active collection already has another importer");
553 return nullptr;
554 }
555 /* 'collection_importer_add_exec' called after invoking the file-browser might get different
556 * context data, and the poll function is not called again in this case (which is a good thing
557 * anyway, since the collection will already have its importer data created at that point). So
558 * the collection needs to be re-validated here - after the check for an existing compatible
559 * importer data has been performed. */
560 if (!collection_importer_add_collection_validate(collection, reason)) {
561 BKE_report(op->reports, RPT_ERROR, reason.c_str());
562 return nullptr;
563 }
564
565 if (!WM_operatortype_find(fh->import_operator, true)) {
567 op->reports, RPT_ERROR, "File handler operator '%s' not found", fh->import_operator);
568 return nullptr;
569 }
570
571 if (!BKE_collection_importer_add(collection, fh->idname)) {
573 RPT_ERROR,
574 "Could not add an importer to the active collection '%s'",
575 BKE_id_name(collection->id));
576 return nullptr;
577 }
578
580 /* Since the importer is added even if the operator is 'cancelled' (through file-browser
581 * cancellation), undo must be handled manually here.
582 *
583 * This does imply that selecting a file and validating the file-browser operation will create
584 * another undo push - not sure how to avoid that currently. */
585 if (do_undo_push) {
586 ED_undo_push(C, op->type->name);
587 }
588
589 return collection;
590}
591
593{
594 Collection *collection = collection_importer_add_ensure(C, op, false, nullptr);
595 if (!collection) {
596 return OPERATOR_CANCELLED;
597 }
598 CollectionImport *collection_importer = collection->importer;
599 BLI_assert(collection_importer);
600
601 const std::string filepath = RNA_string_get(op->ptr, "filepath");
602 if (!filepath.empty()) {
603 if (!collection_importer->import_properties) {
604 collection_importer->import_properties =
605 bke::idprop::create_group("Collection Import System Properties").release();
606 }
607 IDProperty *import_properties = collection_importer->import_properties;
608 IDProperty *filepath_property = bke::idprop::create("filepath", filepath).release();
609 IDP_ReplaceInGroup(import_properties, filepath_property);
610 }
611
613
614 return OPERATOR_FINISHED;
615}
616
618 wmOperator *op,
619 const wmEvent *event)
620{
621 if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
622 RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0);
623 }
624
625 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
626 return WM_operator_call_notest(C, op); /* Call exec direct. */
627 }
628
629 bke::FileHandlerType *fh = nullptr;
630 Collection *collection = collection_importer_add_ensure(C, op, true, &fh);
631 if (!collection) {
632 return OPERATOR_CANCELLED;
633 }
634
635 BLI_assert(collection->importer);
636 BLI_assert(fh);
637
638 const std::optional<std::string> filter_glob = fh->filter_glob_from_extensions();
639 if (filter_glob) {
640 RNA_string_set(op->ptr, "filter_glob", filter_glob->c_str());
641 }
642
643 /* This will call again `collection_importer_add_exec` when user validate their choice, which
644 * will copy the value of the 'filepath' property of this operator, into the collection_importer
645 * 'filepath' property. */
646 return WM_operator_filesel(C, op, event);
647}
648
650{
651 PropertyRNA *prop;
652
653 /* identifiers */
654 ot->name = "Add Importer";
655 ot->description = "Add Importer";
656 ot->idname = "COLLECTION_OT_importer_add";
657
658 /* api callbacks */
662
663 /* flags */
665
666 prop = RNA_def_string(ot->srna, "name", nullptr, MAX_ID_NAME - 2, "Name", "FileHandler idname");
668
669 prop = RNA_def_string(
670 ot->srna, "filepath", nullptr, FILE_MAX, "Filepath", "Filepath for the collection import");
673 prop = RNA_def_string(ot->srna,
674 "filter_glob",
675 nullptr,
677 "File Extension",
678 "'Glob' file type extension(s), as defined by the selected file handler");
681 "relative_path",
682 true,
683 "Relative Path",
684 "Select the file relative to the blend file");
685}
686
687/* Removes all imported IDs from a collection including the external archive library and its parent
688 * library (when empty). */
689static void collection_importer_clear_ids(Main *bmain, Library *external_archive_lib)
690{
691 Library *external_library = external_archive_lib->archive_parent_library;
692
693 Set<ID *> ids_to_delete;
694 for (ID &id_iter : MainAllIDsIterator(*bmain)) {
695 if (id_iter.lib == external_archive_lib) {
696 ids_to_delete.add(&id_iter);
697 }
698 }
699
700 ids_to_delete.add(&external_archive_lib->id);
701 BKE_id_multi_delete(bmain, ids_to_delete);
702
703 /* Remove the parent archive library if that is now empty. */
704 if (external_library->runtime->archived_libraries.is_empty()) {
705 BKE_id_delete(bmain, &external_library->id);
706 }
707}
708
710{
711 Collection *collection = CTX_data_collection(C);
712 CollectionImport *data = collection->importer;
713
714 if (!data) {
715 return OPERATOR_CANCELLED;
716 }
717
718 /* Clear all imported data, including the chain of libraries, if an import has occurred. */
719 Library *external_archive_lib = data->runtime->archive_library;
720 if (external_archive_lib) {
721 Main *bmain = CTX_data_main(C);
722 collection_importer_clear_ids(bmain, external_archive_lib);
723 }
724
726 MEM_delete(data);
727
728 collection->importer = nullptr;
729
732
735
736 return OPERATOR_FINISHED;
737}
738
740{
741 /* identifiers */
742 ot->name = "Remove Importer";
743 ot->description = "Remove Collection Importer and delete its imported data";
744 ot->idname = "COLLECTION_OT_importer_remove";
745
746 /* api callbacks */
749
750 /* flags */
752}
753
755{
756 Collection *collection = CTX_data_collection(C);
757 CollectionImport *data = collection->importer;
758
759 if (!data) {
760 return OPERATOR_CANCELLED;
761 }
762
764 if (!fh) {
765 BKE_reportf(op->reports, RPT_ERROR, "File handler '%s' not found", data->fh_idname);
766 return OPERATOR_CANCELLED;
767 }
768
770 if (!ot) {
772 op->reports, RPT_ERROR, "File handler operator '%s' not found", fh->import_operator);
773 return OPERATOR_CANCELLED;
774 }
775
776 /* Execute operator with our stored properties. */
777 IDProperty *op_props = IDP_CopyProperty(data->import_properties);
778 PointerRNA properties = RNA_pointer_create_discrete(nullptr, ot->srna, op_props);
779 Main *bmain = CTX_data_main(C);
780
781 /* Ensure we have a valid filepath set. Create one if the user has not specified anything yet. */
782 char filepath_abs[FILE_MAX];
783 RNA_string_get(&properties, "filepath", filepath_abs);
784 BLI_path_abs(filepath_abs, BKE_main_blendfile_path(bmain));
785
786 if (!filepath_abs[0]) {
787 BKE_report(op->reports, RPT_ERROR, "No filepath set");
788
789 IDP_FreeProperty(op_props);
790 return OPERATOR_CANCELLED;
791 }
792 else {
793 const char *filename = BLI_path_basename(filepath_abs);
794 if (!filename[0] || !BLI_path_extension(filename)) {
795 BKE_reportf(op->reports, RPT_ERROR, "File path '%s' is not a valid file", filepath_abs);
796
797 IDP_FreeProperty(op_props);
798 return OPERATOR_CANCELLED;
799 }
800 }
801
802 RNA_string_set(&properties, "filepath", filepath_abs);
803
804 /* If there is already a library for this collection importer, then an import has already
805 * occurred. */
806 if (data->runtime->archive_library) {
809 "Collection '%s' has already been imported from '%s'",
810 collection->id.name + 2,
811 filepath_abs);
812 IDP_FreeProperty(op_props);
813 return OPERATOR_CANCELLED;
814 }
815
817
818 Main *temp_main = BKE_main_new();
819 bContext *temp_C = CTX_create();
820
821 CTX_data_main_set(temp_C, temp_main);
822 CTX_wm_manager_set(temp_C, wm);
824 CTX_data_scene_set(temp_C, nullptr);
826
827 /* Ensure that any properties from when this operator was "last used" are cleared. Save them for
828 * restoration later. Otherwise properties from a regular File->Import may contaminate this
829 * collection import. */
830 IDProperty *last_properties = ot->last_properties;
831 ot->last_properties = nullptr;
832
833 /* Manually increment the operator undo depth to ensure that the import operator itself does not
834 * push an undo step. */
835 wm->op_undo_depth++;
836
837 /* Use own report-list, which is then moved back into this operator's reports once import
838 * operation into the temp Main is done. */
839 ReportList reports;
842 temp_C, ot, wm::OpCallContext::ExecDefault, &properties, &reports, nullptr);
843 /* In case of modal operator, WM would take ownership of the given report-list. This should never
844 * happen here, and is not supported at all for now. In case this would be needed, we'd need some
845 * heap-allocated report-list instead, similar to what `bpy_op_fn_call_impl` is doing. */
848 BKE_reports_free(&reports);
849
850 wm->op_undo_depth--;
851
852 /* Only complete the collection import if there's at least one real object that was imported. */
853 if (temp_main->objects.is_empty()) {
854 BKE_reportf(op->reports, RPT_WARNING, "No objects were imported from '%s'", filepath_abs);
855 op_result = OPERATOR_CANCELLED;
856 }
857
858 if (op_result == OPERATOR_FINISHED) {
859 /* Create an external parent library to encapsulate the external archive library if one is
860 * not already present. */
861 Library *external_lib = nullptr;
862 for (Library &lib : bmain->libraries) {
863 if ((lib.flag & LIBRARY_FLAG_IS_EXTERNAL) && STREQ(lib.runtime->filepath_abs, filepath_abs))
864 {
865 external_lib = &lib;
866 break;
867 }
868 }
869
870 if (!external_lib) {
871 external_lib = BKE_id_new<Library>(bmain, BLI_path_basename(filepath_abs));
872 external_lib->flag |= LIBRARY_FLAG_IS_EXTERNAL;
873 id_us_ensure_real(&external_lib->id);
874 BKE_library_filepath_set(bmain, external_lib, filepath_abs);
875
876 /* Immediately make the filepath relative for UI display and other queries. */
877 if (U.flag & USER_RELPATHS) {
878 BLI_path_rel(external_lib->filepath, BKE_main_blendfile_path(bmain));
879 }
880 }
881
882 /* Create the external archive library to serve as the namespace for all IDs imported from the
883 * external file. The library is marked as both an archive (it will never be written out as a
884 * separate .blend) and external (it originates outside Blender). */
885 Library *external_archive_lib = bke::library::create_external_archive_library(*bmain,
886 *external_lib);
887
888 /* Tag everything so we can make local only the new datablocks. */
890
892 BKE_main_merge_as_archive_library(*bmain, temp_main, *external_archive_lib, r);
893
894 /* Temporarily remove the importer to allow collection edits. */
895 collection->importer = nullptr;
896
897 ViewLayer *view_layer = CTX_data_view_layer(C);
898 Scene *scene = CTX_data_scene(C);
899
901 bmain, scene, view_layer, collection, op->reports);
902
904
905 data->runtime->archive_library = external_archive_lib;
906 collection->importer = data;
907
911
912 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
913
914 BKE_reportf(op->reports, RPT_INFO, "Imported '%s'", filepath_abs);
915 }
916 else {
917 BKE_main_free(temp_main);
918 }
919
920 CTX_free(temp_C);
921
922 /* Free the "last used" properties that were set from the collection import and restore the
923 * original "last used" properties. */
924 if (ot->last_properties) {
926 }
927 ot->last_properties = last_properties;
928
929 IDP_FreeProperty(op_props);
930
931 return op_result;
932}
933
935{
936 /* identifiers */
937 ot->name = "Import";
938 ot->description = "Invoke the import operation";
939 ot->idname = "COLLECTION_OT_importer_import";
940
941 /* api callbacks */
944
945 /* flags */
947}
948
950{
951 const Collection *collection = CTX_data_collection(C);
952 CollectionImport *data = collection->importer;
953 if (!data) {
954 return OPERATOR_CANCELLED;
955 }
956
957 Library *external_archive_lib = data->runtime->archive_library;
958 if (!external_archive_lib) {
959 /* It is ok to clear a collection which hasn't been imported yet (e.g. if executing the Reload
960 * operator on an empty collection). */
961 return OPERATOR_FINISHED;
962 }
963
964 /* Clear all imported data, including the chain of libraries. */
965 Main *bmain = CTX_data_main(C);
966 collection_importer_clear_ids(bmain, external_archive_lib);
967
968 data->runtime->archive_library = nullptr;
969
971
972 return OPERATOR_FINISHED;
973}
974
976{
977 /* identifiers */
978 ot->name = "Clear Importer";
979 ot->description = "Clear the importer data";
980 ot->idname = "COLLECTION_OT_importer_clear";
981
982 /* api callbacks */
985
986 /* flags */
988}
989
991{
992 Main *bmain = CTX_data_main(C);
993 Collection *collection = CTX_data_collection(C);
994 CollectionImport *data = collection->importer;
995 if (!data) {
996 return OPERATOR_CANCELLED;
997 }
998
999 Library *external_archive_lib = data->runtime->archive_library;
1000 if (external_archive_lib) {
1001 /* Make local every ID associated with the external archive library */
1002 BKE_library_make_local(bmain, external_archive_lib, nullptr, false, false, false);
1003
1004 /* Remove external archive library and the main external library too if it's now empty. */
1005 Library *external_library = external_archive_lib->archive_parent_library;
1006 BKE_id_delete(bmain, &external_archive_lib->id);
1007 if (external_library->runtime->archived_libraries.is_empty()) {
1008 BKE_id_delete(bmain, &external_library->id);
1009 }
1010 }
1011
1013 MEM_delete(data);
1014
1015 collection->importer = nullptr;
1016
1021
1022 return OPERATOR_FINISHED;
1023}
1024
1026{
1027 /* identifiers */
1028 ot->name = "Make Importer Local";
1029 ot->description = "Make the importer data local";
1030 ot->idname = "COLLECTION_OT_importer_make_local";
1031 /* api callbacks */
1034 /* flags */
1036}
1037
1038static bool collection_exporter_common_check(const Collection *collection)
1039{
1040 return collection != nullptr &&
1041 !(ID_IS_LINKED(&collection->id) || ID_IS_OVERRIDE_LIBRARY(&collection->id));
1042}
1043
1045{
1046 const Collection *collection = CTX_data_collection(C);
1047 return collection_exporter_common_check(collection);
1048}
1049
1051{
1052 const Collection *collection = CTX_data_collection(C);
1053 return collection_exporter_common_check(collection) && !collection->exporters.is_empty();
1054}
1055
1057{
1058 return CTX_data_view_layer(C) != nullptr;
1059}
1060
1062{
1063 Collection *collection = CTX_data_collection(C);
1064
1065 char name[MAX_ID_NAME - 2]; /* id name */
1066 RNA_string_get(op->ptr, "name", name);
1067
1069 if (!fh) {
1070 BKE_reportf(op->reports, RPT_ERROR, "File handler '%s' not found", name);
1071 return OPERATOR_CANCELLED;
1072 }
1073
1074 if (!WM_operatortype_find(fh->export_operator, true)) {
1076 op->reports, RPT_ERROR, "File handler operator '%s' not found", fh->export_operator);
1077 return OPERATOR_CANCELLED;
1078 }
1079
1080 BKE_collection_exporter_add(collection, fh->idname, fh->label);
1081
1084
1087
1088 return OPERATOR_FINISHED;
1089}
1090
1092{
1093 /* identifiers */
1094 ot->name = "Add Exporter";
1095 ot->description = "Add exporter to the exporter list";
1096 ot->idname = "COLLECTION_OT_exporter_add";
1097
1098 /* API callbacks. */
1101
1102 /* flags */
1104
1105 RNA_def_string(ot->srna, "name", nullptr, MAX_ID_NAME - 2, "Name", "FileHandler idname");
1106}
1107
1109{
1110 Collection *collection = CTX_data_collection(C);
1111 ListBaseT<CollectionExport> *exporters = &collection->exporters;
1112
1113 int index = RNA_int_get(op->ptr, "index");
1114 CollectionExport *data = static_cast<CollectionExport *>(BLI_findlink(exporters, index));
1115 if (!data) {
1116 return OPERATOR_CANCELLED;
1117 }
1118
1120
1123
1126
1127 return OPERATOR_FINISHED;
1128}
1129
1131{
1132 /* identifiers */
1133 ot->name = "Remove Exporter";
1134 ot->description = "Remove exporter from the exporter list";
1135 ot->idname = "COLLECTION_OT_exporter_remove";
1136
1137 /* API callbacks. */
1140
1141 /* flags */
1143
1144 RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Exporter index", 0, INT_MAX);
1145}
1146
1148{
1149 Collection *collection = CTX_data_collection(C);
1150 const int dir = RNA_enum_get(op->ptr, "direction");
1151 const int from = collection->active_exporter_index;
1152
1153 /* Move Up/down to index. */
1154 const int to = from + dir;
1155
1156 if (!BKE_collection_exporter_move(collection, from, to)) {
1157 return OPERATOR_CANCELLED;
1158 }
1159
1160 collection->active_exporter_index = to;
1161 return OPERATOR_FINISHED;
1162}
1163
1165{
1166 static const EnumPropertyItem exporter_move[] = {
1167 {-1, "UP", 0, "Up", ""},
1168 {1, "DOWN", 0, "Down", ""},
1169 {0, nullptr, 0, nullptr, nullptr},
1170 };
1171
1172 /* identifiers */
1173 ot->name = "Move Exporter";
1174 ot->description = "Move exporter up or down in the exporter list";
1175 ot->idname = "COLLECTION_OT_exporter_move";
1176
1177 /* API callbacks. */
1180
1181 /* flags */
1183
1184 RNA_def_enum(ot->srna,
1185 "direction",
1186 exporter_move,
1187 0,
1188 "Direction",
1189 "Direction to move the active exporter");
1190}
1191
1193 wmOperator *op,
1195 Collection *collection,
1196 const bool report_success)
1197{
1199 if (!fh) {
1200 BKE_reportf(op->reports, RPT_ERROR, "File handler '%s' not found", data->fh_idname);
1201 return OPERATOR_CANCELLED;
1202 }
1203
1205 if (!ot) {
1207 op->reports, RPT_ERROR, "File handler operator '%s' not found", fh->export_operator);
1208 return OPERATOR_CANCELLED;
1209 }
1210
1211 /* Execute operator with our stored properties. */
1212 /* TODO: Cascade settings down from parent collections(?) */
1213 IDProperty *op_props = IDP_CopyProperty(data->export_properties);
1214 PointerRNA properties = RNA_pointer_create_discrete(nullptr, ot->srna, op_props);
1215 const char *collection_name = collection->id.name + 2;
1216
1217 /* Ensure we have a valid filepath set. Create one if the user has not specified anything yet. */
1218 char filepath[FILE_MAX];
1219 RNA_string_get(&properties, "filepath", filepath);
1220 if (!filepath[0]) {
1222 filepath, sizeof(filepath), "//", fh->get_default_filename(collection_name).c_str());
1223 }
1224 else {
1225 const char *filename = BLI_path_basename(filepath);
1226 if (!filename[0] || !BLI_path_extension(filename)) {
1227 BKE_reportf(op->reports, RPT_ERROR, "File path '%s' is not a valid file", filepath);
1228
1229 IDP_FreeProperty(op_props);
1230 return OPERATOR_CANCELLED;
1231 }
1232 }
1233
1234 const Main *bmain = CTX_data_main(C);
1235 BLI_path_abs(filepath, BKE_main_blendfile_path(bmain));
1236
1237 /* Ensure that any properties from when this operator was "last used" are cleared. Save them for
1238 * restoration later. Otherwise properties from a regular File->Export may contaminate this
1239 * collection export. */
1240 IDProperty *last_properties = ot->last_properties;
1241 ot->last_properties = nullptr;
1242
1243 RNA_string_set(&properties, "filepath", filepath);
1244 RNA_string_set(&properties, "collection", collection_name);
1246 C, ot, wm::OpCallContext::ExecDefault, &properties, nullptr);
1247
1248 /* Free the "last used" properties that were just set from the collection export and restore the
1249 * original "last used" properties. */
1250 if (ot->last_properties) {
1252 }
1253 ot->last_properties = last_properties;
1254
1255 IDP_FreeProperty(op_props);
1256
1257 if (report_success && op_result == OPERATOR_FINISHED) {
1258 BKE_reportf(op->reports, RPT_INFO, "Exported '%s'", filepath);
1259 }
1260
1261 return op_result;
1262}
1263
1265{
1266 Collection *collection = CTX_data_collection(C);
1267 ListBaseT<CollectionExport> *exporters = &collection->exporters;
1268
1269 int index = RNA_int_get(op->ptr, "index");
1270 CollectionExport *data = static_cast<CollectionExport *>(BLI_findlink(exporters, index));
1271 if (!data) {
1272 return OPERATOR_CANCELLED;
1273 }
1274
1275 return collection_exporter_export(C, op, data, collection, true);
1276}
1277
1279{
1280 /* identifiers */
1281 ot->name = "Export";
1282 ot->description = "Invoke the export operation";
1283 ot->idname = "COLLECTION_OT_exporter_export";
1284
1285 /* API callbacks. */
1288
1289 /* flags */
1290 ot->flag = 0;
1291
1292 RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Exporter index", 0, INT_MAX);
1293}
1294
1299
1301 wmOperator *op,
1302 Collection *collection,
1303 CollectionExportStats &stats)
1304{
1305 ListBaseT<CollectionExport> *exporters = &collection->exporters;
1306 int files_num = 0;
1307
1308 for (CollectionExport &data : *exporters) {
1309 if (collection_exporter_export(C, op, &data, collection, false) != OPERATOR_FINISHED) {
1310 /* Do not continue calling exporters if we encounter one that fails. */
1311 return OPERATOR_CANCELLED;
1312 }
1313 files_num++;
1314 }
1315
1316 if (files_num) {
1317 stats.successful_exports_num += files_num;
1318 stats.collections_num++;
1319 }
1320 return OPERATOR_FINISHED;
1321}
1322
1324{
1325 Collection *collection = CTX_data_collection(C);
1327 wmOperatorStatus result = collection_export(C, op, collection, stats);
1328
1329 /* Only report if nothing was cancelled along the way. We don't want this UI report to happen
1330 * over-top any reports from the actual failures. */
1331 if (result == OPERATOR_FINISHED && stats.successful_exports_num > 0) {
1332 BKE_reportf(op->reports,
1333 RPT_INFO,
1334 "Exported %d files from collection '%s'",
1336 collection->id.name + 2);
1337 }
1338
1339 return result;
1340}
1341
1343{
1344 /* identifiers */
1345 ot->name = "Export All";
1346 ot->description = "Invoke all configured exporters on this collection";
1347 ot->idname = "COLLECTION_OT_export_all";
1348
1349 /* API callbacks. */
1352
1353 /* flags */
1354 ot->flag = 0;
1355}
1356
1358 wmOperator *op,
1359 LayerCollection *layer_collection,
1360 CollectionExportStats &stats)
1361{
1362 /* Skip collections which have been Excluded in the View Layer. */
1363 if (layer_collection->flag & LAYER_COLLECTION_EXCLUDE) {
1364 return OPERATOR_FINISHED;
1365 }
1366
1367 if (!collection_exporter_common_check(layer_collection->collection)) {
1368 return OPERATOR_FINISHED;
1369 }
1370
1371 if (collection_export(C, op, layer_collection->collection, stats) != OPERATOR_FINISHED) {
1372 return OPERATOR_CANCELLED;
1373 }
1374
1375 for (LayerCollection &child : layer_collection->layer_collections) {
1376 if (collection_export_recursive(C, op, &child, stats) != OPERATOR_FINISHED) {
1377 return OPERATOR_CANCELLED;
1378 }
1379 }
1380
1381 return OPERATOR_FINISHED;
1382}
1383
1385{
1386 ViewLayer *view_layer = CTX_data_view_layer(C);
1387
1389 for (LayerCollection &layer_collection : view_layer->layer_collections) {
1390 if (collection_export_recursive(C, op, &layer_collection, stats) != OPERATOR_FINISHED) {
1391 return OPERATOR_CANCELLED;
1392 }
1393 }
1394
1395 /* Only report if nothing was cancelled along the way. We don't want this UI report to happen
1396 * over-top any reports from the actual failures. */
1397 if (stats.successful_exports_num > 0) {
1398 BKE_reportf(op->reports,
1399 RPT_INFO,
1400 "Exported %d files from %d collections",
1402 stats.collections_num);
1403 }
1404
1405 return OPERATOR_FINISHED;
1406}
1407
1409{
1410 /* identifiers */
1411 ot->name = "Export All Collections";
1412 ot->description = "Invoke all configured exporters for all collections";
1413 ot->idname = "WM_OT_collection_export_all";
1414
1415 /* API callbacks. */
1418
1419 /* flags */
1420 ot->flag = 0;
1421}
1422
1423static void collection_importer_menu_draw(const bContext * /*C*/, Menu *menu)
1424{
1425 using namespace blender;
1426 ui::Layout &layout = *menu->layout;
1427
1428 /* Add all file handlers capable of being imported to the menu. */
1429 bool at_least_one = false;
1430 for (const auto &fh : bke::file_handlers()) {
1431 if (STREQ(fh->idname, "IO_FH_usd") && WM_operatortype_find(fh->import_operator, true)) {
1432 PointerRNA op_ptr = layout.op(
1433 "COLLECTION_OT_importer_add", fh->label_with_extensions(), ICON_NONE);
1434 RNA_string_set(&op_ptr, "name", fh->idname);
1435 at_least_one = true;
1436 }
1437 }
1438
1439 if (!at_least_one) {
1440 layout.label(IFACE_("No file handlers available"), ICON_NONE);
1441 }
1442}
1443
1444static void collection_importer_control_menu_draw(const bContext * /*C*/, Menu *menu)
1445{
1446 ui::Layout &layout = *menu->layout;
1447 layout.op("COLLECTION_OT_importer_make_local", IFACE_("Apply and Make Local"), ICON_CHECKMARK);
1448 layout.op("COLLECTION_OT_importer_clear", IFACE_("Delete Collection Content"), ICON_NONE);
1449 layout.separator();
1450 layout.op("COLLECTION_OT_importer_remove", IFACE_("Remove Importer"), ICON_TRASH);
1451}
1452
1453static void collection_exporter_menu_draw(const bContext * /*C*/, Menu *menu)
1454{
1455 ui::Layout &layout = *menu->layout;
1456
1457 /* Add all file handlers capable of being exported to the menu. */
1458 bool at_least_one = false;
1459 for (const auto &fh : bke::file_handlers()) {
1460 if (WM_operatortype_find(fh->export_operator, true)) {
1461 PointerRNA op_ptr = layout.op(
1462 "COLLECTION_OT_exporter_add", fh->label_with_extensions(), ICON_NONE);
1463 RNA_string_set(&op_ptr, "name", fh->idname);
1464 at_least_one = true;
1465 }
1466 }
1467
1468 if (!at_least_one) {
1469 layout.label(IFACE_("No file handlers available"), ICON_NONE);
1470 }
1471}
1472
1493
1495{
1496 wmOperatorType *ot = WM_operatortype_append_macro("COLLECTION_OT_importer_reload",
1497 "Reload Importer",
1498 "Clear and reload the importer data",
1500 WM_operatortype_macro_define(ot, "COLLECTION_OT_importer_clear");
1501 WM_operatortype_macro_define(ot, "COLLECTION_OT_importer_import");
1502}
1503
1519
1520/****************** properties window operators *********************/
1521
1523{
1524 Object *ob = context_object(C);
1525 Main *bmain = CTX_data_main(C);
1526
1527 if (ob == nullptr) {
1528 return OPERATOR_CANCELLED;
1529 }
1530
1531 Collection *collection = BKE_collection_add(bmain, nullptr, "Collection");
1532 id_fake_user_set(&collection->id);
1533 BKE_collection_object_add(bmain, collection, ob);
1534
1537
1539
1540 return OPERATOR_FINISHED;
1541}
1542
1544{
1545 /* identifiers */
1546 ot->name = "Add to Collection";
1547 ot->idname = "OBJECT_OT_collection_add";
1548 ot->description = "Add an object to a new collection";
1549
1550 /* API callbacks. */
1553
1554 /* flags */
1556}
1557
1559{
1560 Main *bmain = CTX_data_main(C);
1561 Object *ob = context_object(C);
1562 Collection *collection = static_cast<Collection *>(
1563 BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection")));
1564
1565 if (ELEM(nullptr, ob, collection)) {
1566 return OPERATOR_CANCELLED;
1567 }
1568
1569 /* Early return check, if the object is already in collection
1570 * we could skip all the dependency check and just consider
1571 * operator is finished.
1572 */
1573 if (BKE_collection_has_object(collection, ob)) {
1574 return OPERATOR_FINISHED;
1575 }
1576
1577 std::string reason;
1578 if (!BKE_collection_is_content_editable(collection, &reason)) {
1580 op->reports, RPT_ERROR, "Cannot add objects to the collection. %s", reason.c_str());
1581 return OPERATOR_CANCELLED;
1582 }
1583
1584 /* Adding object to collection which is used as dupli-collection for self is bad idea.
1585 *
1586 * It is also bad idea to add object to collection which is in collection which
1587 * contains our current object.
1588 */
1589 if (BKE_collection_object_cyclic_check(bmain, ob, collection)) {
1590 BKE_report(op->reports,
1591 RPT_ERROR,
1592 "Could not add the collection because of dependency cycle detected");
1593 return OPERATOR_CANCELLED;
1594 }
1595
1596 BKE_collection_object_add(bmain, collection, ob);
1597
1600
1602
1603 return OPERATOR_FINISHED;
1604}
1605
1607{
1608 PropertyRNA *prop;
1609
1610 /* identifiers */
1611 ot->name = "Link to Collection";
1612 ot->idname = "OBJECT_OT_collection_link";
1613 ot->description = "Add an object to an existing collection";
1614
1615 /* API callbacks. */
1619
1620 /* flags */
1622
1623 /* properties */
1624 prop = RNA_def_enum(ot->srna, "collection", rna_enum_dummy_NULL_items, 0, "Collection", "");
1627 ot->prop = prop;
1628}
1629
1631{
1632 Main *bmain = CTX_data_main(C);
1633 Object *ob = context_object(C);
1634 Collection *collection = static_cast<Collection *>(
1635 CTX_data_pointer_get_type(C, "collection", RNA_Collection).data);
1636
1637 if (!ob || !collection) {
1638 return OPERATOR_CANCELLED;
1639 }
1640
1641 std::string reason;
1642 if (!BKE_collection_is_content_editable(collection, &reason)) {
1644 op->reports, RPT_ERROR, "Cannot remove an object from the collection. %s", reason.c_str());
1645 return OPERATOR_CANCELLED;
1646 }
1647
1648 BKE_collection_object_remove(bmain, collection, ob, false);
1649
1652
1654
1655 return OPERATOR_FINISHED;
1656}
1657
1659{
1660 /* identifiers */
1661 ot->name = "Remove Collection";
1662 ot->idname = "OBJECT_OT_collection_remove";
1663 ot->description = "Remove the active object from this collection";
1664
1665 /* API callbacks. */
1668
1669 /* flags */
1671}
1672
1674{
1675 Main *bmain = CTX_data_main(C);
1676 Collection *collection = CTX_data_collection(C);
1677
1678 if (!collection) {
1679 return OPERATOR_CANCELLED;
1680 }
1681 if (collection->flag & COLLECTION_IS_MASTER) {
1682 return OPERATOR_CANCELLED;
1683 }
1684 BLI_assert((collection->id.flag & ID_FLAG_EMBEDDED_DATA) == 0);
1685 if (ID_IS_OVERRIDE_LIBRARY(collection) &&
1686 collection->id.override_library->hierarchy_root != &collection->id)
1687 {
1688 BKE_report(op->reports,
1689 RPT_ERROR,
1690 "Cannot unlink a library override collection which is not the root of its override "
1691 "hierarchy");
1692 return OPERATOR_CANCELLED;
1693 }
1694
1695 BKE_id_delete(bmain, collection);
1696
1698
1700
1701 return OPERATOR_FINISHED;
1702}
1703
1705{
1706 Collection *collection = CTX_data_collection(C);
1707
1708 if (!collection) {
1709 return false;
1710 }
1711 if (collection->flag & COLLECTION_IS_MASTER) {
1712 return false;
1713 }
1714 BLI_assert((collection->id.flag & ID_FLAG_EMBEDDED_DATA) == 0);
1715 if (ID_IS_OVERRIDE_LIBRARY(collection) &&
1716 collection->id.override_library->hierarchy_root != &collection->id)
1717 {
1718 return false;
1719 }
1720
1721 return ED_operator_objectmode(C);
1722}
1723
1725{
1726 /* identifiers */
1727 ot->name = "Unlink Collection";
1728 ot->idname = "OBJECT_OT_collection_unlink";
1729 ot->description = "Unlink the collection from all objects";
1730
1731 /* API callbacks. */
1734
1735 /* flags */
1737}
1738
1739/* Select objects in the same collection as the active */
1741{
1742 Scene *scene = CTX_data_scene(C);
1743 Collection *collection = static_cast<Collection *>(
1744 CTX_data_pointer_get_type(C, "collection", RNA_Collection).data);
1745
1746 if (!collection) {
1747 return OPERATOR_CANCELLED;
1748 }
1749
1750 CTX_DATA_BEGIN (C, Base *, base, visible_bases) {
1751 if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLE) != 0)) {
1752 if (BKE_collection_has_object_recursive(collection, base->object)) {
1753 base_select(base, BA_SELECT);
1754 }
1755 }
1756 }
1758
1761
1762 return OPERATOR_FINISHED;
1763}
1764
1766{
1767 /* identifiers */
1768 ot->name = "Select Objects in Collection";
1769 ot->idname = "OBJECT_OT_collection_objects_select";
1770 ot->description = "Select all objects in collection";
1771
1772 /* API callbacks. */
1775
1776 /* flags */
1778}
1779
1780} // namespace blender::ed::object
#define FOREACH_COLLECTION_BEGIN(_bmain, _scene, Type, _instance)
#define FOREACH_COLLECTION_END
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
#define FH_MAX_FILE_EXTENSIONS_STR
General operations, lookup, etc. for blender objects.
#define FILE_MAX
#define BLI_path_join(...)
#define STRNCPY_UTF8(dst, src)
external readfile function prototypes.
#define IFACE_(msgid)
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define ND_DRAW
Definition WM_types.hh:502
#define ND_OB_SELECT
Definition WM_types.hh:461
#define ND_SPACE_PROPERTIES
Definition WM_types.hh:572
#define NC_SCENE
Definition WM_types.hh:391
#define NC_GROUP
Definition WM_types.hh:396
#define NA_EDITED
Definition WM_types.hh:634
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define NC_OBJECT
Definition WM_types.hh:392
#define NC_SPACE
Definition WM_types.hh:405
#define ND_SPACE_OUTLINER
Definition WM_types.hh:570
#define ELEM(...)
#define STREQ(a, b)
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr StringRef()
#define INT_MAX
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
Library * create_external_archive_library(Main &bmain, Library &external_library)
Definition library.cc:823
FileHandlerType * file_handler_find(StringRef idname)
Span< std::unique_ptr< FileHandlerType > > file_handlers()
static wmOperatorStatus collection_objects_remove_exec(bContext *C, wmOperator *op)
static wmOperatorStatus collection_importer_import_exec(bContext *C, wmOperator *op)
static void COLLECTION_OT_exporter_add(wmOperatorType *ot)
static bool collection_unlink_poll(bContext *C)
static wmOperatorStatus collection_remove_exec(bContext *C, wmOperator *op)
static wmOperatorStatus objects_add_active_exec(bContext *C, wmOperator *op)
static void COLLECTION_OT_exporter_move(wmOperatorType *ot)
static void collection_importer_menu_draw(const bContext *, Menu *menu)
static wmOperatorStatus collection_export(bContext *C, wmOperator *op, Collection *collection, CollectionExportStats &stats)
static bool collection_export_all_poll(bContext *C)
static void collection_importer_add_tag_update(bContext *C, Collection &collection)
static void COLLECTION_OT_exporter_remove(wmOperatorType *ot)
static wmOperatorStatus collection_exporter_remove_exec(bContext *C, wmOperator *op)
static wmOperatorStatus collection_unlink_exec(bContext *C, wmOperator *op)
static wmOperatorStatus collection_importer_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void COLLECTION_OT_export_all(wmOperatorType *ot)
static void COLLECTION_OT_importer_clear(wmOperatorType *ot)
static wmOperatorStatus collection_objects_remove_all_exec(bContext *C, wmOperator *)
static bool collection_exporter_common_check(const Collection *collection)
static wmOperatorStatus collection_add_exec(bContext *C, wmOperator *)
static wmOperatorStatus select_grouped_exec(bContext *C, wmOperator *)
static wmOperatorStatus collection_exporter_export_exec(bContext *C, wmOperator *op)
void OBJECT_OT_collection_objects_select(wmOperatorType *ot)
void base_select(Base *base, eObjectSelect_Mode mode)
void OBJECT_OT_collection_link(wmOperatorType *ot)
static void COLLECTION_OT_importer_import(wmOperatorType *ot)
static bool collection_importer_add_collection_validate(const Collection *collection, std::string &reason)
Object * context_object(const bContext *C)
static wmOperatorStatus collection_importer_clear_exec(bContext *C, wmOperator *)
static wmOperatorStatus collection_importer_make_local_exec(bContext *C, wmOperator *)
static bool collection_exporter_poll(bContext *C)
static void collection_importer_control_menu_draw(const bContext *, Menu *menu)
static bool collection_importer_add_poll(bContext *C)
static void COLLECTION_OT_importer_remove(wmOperatorType *ot)
static Collection * collection_object_active_find_index(Main *bmain, Scene *scene, Object *ob, const int collection_object_index)
static bool collection_importer_remove_poll(bContext *C)
static wmOperatorStatus collection_importer_add_exec(bContext *C, wmOperator *op)
static void WM_OT_collection_export_all(wmOperatorType *ot)
static void COLLECTION_OT_importer_make_local(wmOperatorType *ot)
static bool collection_importer_import_poll(bContext *C)
void OBJECT_OT_collection_add(wmOperatorType *ot)
static const EnumPropertyItem * collection_object_active_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
static wmOperatorStatus objects_remove_active_exec(bContext *C, wmOperator *op)
static wmOperatorStatus collection_exporter_export(bContext *C, wmOperator *op, CollectionExport *data, Collection *collection, const bool report_success)
static void collection_exporter_menu_draw(const bContext *, Menu *menu)
static wmOperatorStatus collection_io_export_all_exec(bContext *C, wmOperator *op)
static wmOperatorStatus collection_importer_remove_exec(bContext *C, wmOperator *)
static bool collection_exporter_remove_poll(bContext *C)
void COLLECTION_OT_create(wmOperatorType *ot)
static wmOperatorStatus collection_link_exec(bContext *C, wmOperator *op)
static Collection * collection_importer_add_ensure(bContext *C, wmOperator *op, const bool do_undo_push, bke::FileHandlerType **r_fh)
static wmOperatorStatus collection_exporter_add_exec(bContext *C, wmOperator *op)
void OBJECT_OT_collection_unlink(wmOperatorType *ot)
static void collection_importer_clear_ids(Main *bmain, Library *external_archive_lib)
static wmOperatorStatus collection_exporter_move_exec(bContext *C, wmOperator *op)
void OBJECT_OT_collection_remove(wmOperatorType *ot)
static wmOperatorStatus collection_export_recursive(bContext *C, wmOperator *op, LayerCollection *layer_collection, CollectionExportStats &stats)
static wmOperatorStatus collection_create_exec(bContext *C, wmOperator *op)
void COLLECTION_OT_objects_add_active(wmOperatorType *ot)
void COLLECTION_OT_objects_remove_all(wmOperatorType *ot)
static wmOperatorStatus wm_collection_export_all_exec(bContext *C, wmOperator *op)
void COLLECTION_OT_objects_remove_active(wmOperatorType *ot)
static void COLLECTION_OT_exporter_export(wmOperatorType *ot)
void COLLECTION_OT_objects_remove(wmOperatorType *ot)
static void COLLECTION_OT_importer_add(wmOperatorType *ot)
std::string filename(const std::string_view &str, size_t pos)
int icon_color_from_collection(const Collection *collection)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:737
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
@ RPT_WARNING
Definition BKE_report.hh:40
void BKE_id_delete(Main *bmain, void *idv, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
wmOperatorStatus WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *)
void BKE_reports_free(ReportList *reports)
Definition report.cc:106
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:91
void CTX_wm_window_set(bContext *C, wmWindow *win)
Main * BKE_main_new()
Definition main.cc:93
const char * BLI_path_extension(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
const EnumPropertyItem * RNA_collection_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
int RNA_int_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_call_notest(bContext *C, wmOperator *op)
wmWindow * CTX_wm_window(const bContext *C)
void BKE_reports_move_to_reports(ReportList *reports_dst, ReportList *reports_src)
Definition report.cc:150
void BKE_collection_importer_free_data(CollectionImport *data)
const char * BKE_id_name(const ID &id)
std::optional< StringRefNull > IDP_group_lookup_string(const IDProperty &group, StringRef name)
Definition idprop.cc:862
void id_fake_user_set(ID *id)
Definition lib_id.cc:471
CollectionImport * BKE_collection_importer_add(Collection *collection, const char *idname)
void BKE_view_layer_need_resync_tag(ViewLayer *view_layer)
ViewLayer * CTX_data_view_layer(const bContext *C)
bool BKE_collection_exporter_move(Collection *collection, const int from, const int to)
bContext * CTX_create()
bool BKE_collection_has_object(Collection *collection, const Object *ob)
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
Collection * BKE_collection_object_find(Main *bmain, Scene *scene, Collection *collection, Object *ob)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *object)
Definition object.cc:5362
void BKE_blendfile_link_append_instantiate_loose_from_bmain(Main *bmain, Scene *scene, ViewLayer *view_layer, Collection *target_collection, ReportList *reports)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
@ LAYER_COLLECTION_EXCLUDE
wmWindowManager * CTX_wm_manager(const bContext *C)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
bool BKE_collection_is_empty(const Collection *collection)
bool BKE_collection_object_cyclic_check(Main *bmain, Object *object, Collection *collection)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
CollectionExport * BKE_collection_exporter_add(Collection *collection, char *idname, char *label)
void CTX_free(bContext *C)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void BKE_main_merge_as_archive_library(Main &bmain_dst, Main *&r_bmain_src, Library &dst_external_library, MainMergeReport &reports)
Definition main.cc:575
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
@ LIBRARY_FLAG_IS_EXTERNAL
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)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void BKE_main_free(Main *bmain)
Definition main.cc:202
void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
Definition library.cc:249
void id_us_ensure_real(ID *id)
Definition lib_id.cc:388
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)
bool ED_operator_objectmode(bContext *C)
bool BKE_collection_is_content_editable(const Collection *collection, std::string *reason=nullptr)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
wmOperatorStatus WM_operator_type_call_ptr_with_reports(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, ReportList *reports, const wmEvent *event)
bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us)
Main * CTX_data_main(const bContext *C)
void RNA_enum_item_add_separator(EnumPropertyItem **items, int *totitem)
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
void BKE_collection_exporter_remove(Collection *collection, CollectionExport *data)
bool WM_menutype_add(MenuType *mt)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:502
@ PROP_HIDDEN
Definition RNA_types.hh:408
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:929
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
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
void CTX_data_main_set(bContext *C, Main *bmain)
bool BKE_collection_has_object_recursive(Collection *collection, Object *ob)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
std::string RNA_string_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void CTX_data_ui_context_access_deny(bContext *C, bool deny)
@ RPT_OP_HOLD
Definition BKE_report.hh:60
@ RPT_PRINT_HANDLED_BY_OWNER
Definition BKE_report.hh:62
@ PROP_FILEPATH
Definition RNA_types.hh:284
size_t BKE_id_multi_delete(Main *bmain, Set< ID * > &ids_to_delete, const BKEIDDeleteOptions &options={})
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
void CTX_data_scene_set(bContext *C, Scene *scene)
void BKE_library_make_local(Main *bmain, const Library *lib, GHash *old_to_new_ids, bool untagged_only, bool set_fake, bool clear_asset_data)
Definition lib_id.cc:2395
Collection * CTX_data_collection(const bContext *C)
Collection * BKE_collection_add(Main *bmain, Collection *collection_parent, const char *name_custom)
ListBaseT< CollectionExport > exporters
CollectionImport * importer
struct ID * hierarchy_root
Definition DNA_ID.h:352
char name[258]
Definition DNA_ID.h:433
short flag
Definition DNA_ID.h:439
IDOverrideLibrary * override_library
Definition DNA_ID.h:495
eLayerCollection_Flag flag
struct Collection * collection
ListBaseT< LayerCollection > layer_collections
struct Library * archive_parent_library
Definition DNA_ID.h:575
char filepath[1024]
Definition DNA_ID.h:562
bke::library::LibraryRuntime * runtime
Definition DNA_ID.h:591
uint16_t flag
Definition DNA_ID.h:565
ListBaseT< Collection > collections
Definition BKE_main.hh:406
ListBaseT< Library > libraries
Definition BKE_main.hh:387
ListBaseT< Object > objects
Definition BKE_main.hh:388
char idname[BKE_ST_MAXNAME]
char label[BKE_ST_MAXNAME]
void(*) draw(const bContext *C, Menu *menu)
ui::Layout * layout
ListBaseT< LayerCollection > layer_collections
std::string get_default_filename(StringRefNull name)
char export_operator[OP_MAX_TYPENAME]
char import_operator[OP_MAX_TYPENAME]
std::optional< std::string > filter_glob_from_extensions() const
void label(StringRef name, int icon)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
IDProperty * last_properties
Definition WM_types.hh:1206
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
struct wmOperatorType * type
#define N_(msgid)