Blender V5.3
rna_blender_project.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_userdef_types.h"
10
11#include "ED_userpref.hh"
12
13#include "RNA_access.hh"
14#include "RNA_define.hh"
15#include "RNA_enum_types.hh"
16
17#include "rna_internal.hh"
18
20#include "BKE_path_templates.hh"
21
22#include "BLI_string_ref.hh"
23#include "BLI_string_utils.hh"
24#include "BLI_uuid.hh"
25
26#include "BLT_translation.hh"
27
28#include "WM_api.hh"
29
30namespace blender {
31
33 {int(bke::ProjectVariableType::STRING), "STRING", 0, "String", "A string variable"},
34 {int(bke::ProjectVariableType::INT), "INTEGER", 0, "Integer", "An integer variable"},
35 {int(bke::ProjectVariableType::FLOAT), "FLOAT", 0, "Float", "A floating point variable"},
36 {0, nullptr, 0, nullptr, nullptr},
37};
38
40 {int(bke::ProjectVariableStringSubtype::NONE), "NONE", 0, "None", "A standard string"},
42 "FILEPATH",
43 0,
44 "Filepath",
45 "A string interpreted as a filepath. Will be used as-is (unescaped) when substituted into "
46 "part of a filepath"},
47 {0, nullptr, 0, nullptr, nullptr},
48};
49
56
59 "BLENDER",
60 0,
61 "Blender",
62 "The default Blender OpenColorIO configuration. Works with both ACES workflows "
63 "and Blender specific views and color spaces"},
65 "ACES_2_0_STUDIO",
66 0,
67 "ACES 2.0 Studio",
68 "Academy Color Encoding System 2.0, Studio Config v4.0.0. Less compatible with existing "
69 "assets and add-ons, but more consistent with other applications using the same "
70 "configuration"},
72 "ACES_1_3_STUDIO",
73 0,
74 "ACES 1.3 Studio",
75 "Academy Color Encoding System 1.3, Studio Config v2.2.0. Less compatible with existing "
76 "assets and add-ons, but more consistent with other applications using the same "
77 "configuration"},
79 "PATH",
80 0,
81 "Path",
82 "OpenColorIO configuration from a file path or ocio:// URI"},
83 {0, nullptr, 0, nullptr, nullptr},
84};
85
86} // namespace blender
87
88#ifdef RNA_RUNTIME
89
90namespace blender {
91
92using namespace bke;
93
94static void project_mark_dirty(bke::BlenderProject *project)
95{
96 BLI_assert(project != nullptr);
97 bke::with_blender_project_write_lock([&] { project->is_dirty = true; });
98}
99
100/* For properties that AREN'T saved to disk as part of the project data. */
101static void rna_BlenderProject_ui_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA * /*ptr*/)
102{
103 /* Force full redraw of all windows. */
105}
106
107/* For properties that ARE saved to disk as part of the project data. */
108static void rna_BlenderProject_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
109{
110 bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
111 project_mark_dirty(project);
112
113 /* Force full redraw of all windows. */
115}
116
117/* The project name is displayed in the window title. */
118static void rna_BlenderProject_name_update(Main *bmain, Scene *scene, PointerRNA *ptr)
119{
120 rna_BlenderProject_update(bmain, scene, ptr);
121
123}
124
125static void rna_ProjectVariable_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
126{
127 BlenderProject *project = ptr->parent().data_as<BlenderProject>();
128 BLI_assert(project != nullptr);
129
130 project_mark_dirty(project);
131
132 /* Force full redraw of all windows. */
134}
135
136/* --------------------------------------------------------- */
137
138static StructRNA *rna_ProjectVariable_refine(PointerRNA *ptr)
139{
140 ProjectVariable *var = ptr->data_as<ProjectVariable>();
141
142 switch (var->type_get()) {
143 case ProjectVariableType::STRING:
144 return RNA_ProjectVariableString;
145 case ProjectVariableType::INT:
146 return RNA_ProjectVariableInteger;
147 case ProjectVariableType::FLOAT:
148 return RNA_ProjectVariableFloat;
149 default:
150 return RNA_UnknownType;
151 }
152}
153
154static int rna_ProjectVariable_type_get(PointerRNA *ptr)
155{
156 int var_type;
158 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
159 var_type = int(var->type_get());
160 });
161 return var_type;
162}
163
164static void rna_ProjectVariable_name_get(PointerRNA *ptr, char *value)
165{
167 ProjectVariable *var = ptr->data_as<ProjectVariable>();
168 strcpy(value, var->name_get().c_str());
169 });
170}
171
172static int rna_ProjectVariable_name_length(PointerRNA *ptr)
173{
174 int name_length;
176 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
177 name_length = var->name_get().size();
178 });
179 return name_length;
180}
181
182static void rna_ProjectVariable_name_set(PointerRNA *ptr, const char *value)
183{
185 BlenderProject *project = ptr->parent().data_as<BlenderProject>();
186 BLI_assert(project != nullptr);
187
188 ProjectVariable *var = ptr->data_as<ProjectVariable>();
189
190 project->rename_variable(project->find_variable_index(var), value);
191 });
192}
193
194static void rna_ProjectVariable_description_get(PointerRNA *ptr, char *value)
195{
197 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
198 strcpy(value, var->description_get().c_str());
199 });
200}
201
202static int rna_ProjectVariable_description_length(PointerRNA *ptr)
203{
204 int description_length;
206 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
207 description_length = var->description_get().size();
208 });
209 return description_length;
210}
211
212static void rna_ProjectVariable_description_set(PointerRNA *ptr, const char *value)
213{
215 ProjectVariable *var = ptr->data_as<ProjectVariable>();
216 var->description_set(value);
217 });
218}
219
220static int rna_ProjectVariableInteger_value_get(PointerRNA *ptr)
221{
222 int value_int;
224 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
225 value_int = var->value_int_get();
226 });
227 return value_int;
228}
229
230static void rna_ProjectVariableInteger_value_set(PointerRNA *ptr, int value)
231{
233 ProjectVariable *var = ptr->data_as<ProjectVariable>();
234 var->value_set(value);
235 });
236}
237
238static float rna_ProjectVariableFloat_value_get(PointerRNA *ptr)
239{
240 float value_float;
242 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
243 value_float = var->value_float_get();
244 });
245 return value_float;
246}
247
248static void rna_ProjectVariableFloat_value_set(PointerRNA *ptr, float value)
249{
251 ProjectVariable *var = ptr->data_as<ProjectVariable>();
252 var->value_set(value);
253 });
254}
255
256static void rna_ProjectVariableString_value_get(PointerRNA *ptr, char *value)
257{
259 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
260 strcpy(value, var->value_string_get().c_str());
261 });
262}
263
264static int rna_ProjectVariableString_value_length(PointerRNA *ptr)
265{
266 int string_length;
268 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
269 string_length = var->value_string_get().size();
270 });
271 return string_length;
272}
273
274static void rna_ProjectVariableString_value_set(PointerRNA *ptr, const char *value)
275{
277 ProjectVariable *var = ptr->data_as<ProjectVariable>();
278 var->value_set(StringRefNull(value));
279 });
280}
281
282static int rna_ProjectVariableString_subtype_get(PointerRNA *ptr)
283{
284 int var_type;
286 const ProjectVariable *var = ptr->data_as<ProjectVariable>();
287 var_type = int(var->string_subtype_get());
288 });
289 return var_type;
290}
291
292static void rna_ProjectVariableString_subtype_set(PointerRNA *ptr, int value)
293{
295 ProjectVariable *var = ptr->data_as<ProjectVariable>();
297 });
298}
299
300/* --------------------------------------------------------- */
301
302static void rna_BlenderProject_name_get(PointerRNA *ptr, char *value)
303{
305 const bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
306 strcpy(value, project->get_name().c_str());
307 });
308}
309
310static int rna_BlenderProject_name_length(PointerRNA *ptr)
311{
312 int name_length;
314 const bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
315 name_length = project->get_name().size();
316 });
317 return name_length;
318}
319
320static void rna_BlenderProject_name_set(PointerRNA *ptr, const char *value)
321{
323 bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
324
325 StringRef name = StringRef(value);
326
327 if (name.is_empty()) {
328 /* Leave the name as-is when passed an empty (which is invalid) name. */
329 return;
330 }
331
332 project->set_name(name);
333 });
334}
335
336static void rna_BlenderProject_root_path_get(PointerRNA *ptr, char *value)
337{
339 const bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
340 strcpy(value, project->get_root_path().c_str());
341 });
342}
343
344static int rna_BlenderProject_root_path_length(PointerRNA *ptr)
345{
346 int root_path_length;
348 const bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
349 root_path_length = project->get_root_path().size();
350 });
351 return root_path_length;
352}
353
354static int rna_BlenderProject_active_variable_index_get(PointerRNA *ptr)
355{
356 int active_variable_index;
358 const bke::BlenderProject *project = ptr->data_as<BlenderProject>();
359 active_variable_index = project->active_variable_index;
360 });
361 return active_variable_index;
362}
363
364static void rna_BlenderProject_active_variable_index_set(PointerRNA *ptr, int value)
365{
367 bke::BlenderProject *project = ptr->data_as<BlenderProject>();
368 project->active_variable_index = value;
369 });
370}
371
372static void rna_BlenderProject_active_variable_index_range(
373 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
374{
376 const bke::BlenderProject *project = ptr->data_as<BlenderProject>();
377 *min = 0;
378 *max = project->variables.size() - 1;
379 });
380}
381
382static void rna_iterator_BlenderProject_variables_begin(CollectionPropertyIterator *iter,
383 PointerRNA *ptr)
384{
385 /* Note: we use a read lock here despite `rna_iterator_array_begin()` taking
386 * non-const pointers from the project, because in reality this is a read
387 * operation that doesn't modify any project data. */
389 bke::BlenderProject *project = ptr->data_as<BlenderProject>();
391 ptr,
392 (void *)project->variables.begin(),
393 sizeof(std::unique_ptr<IDProperty, idprop::IDPropertyDeleter>),
394 project->variables.size(),
395 0,
396 nullptr);
397 });
398}
399
400static int rna_iterator_BlenderProject_variables_length(PointerRNA *ptr)
401{
402 int variables_length;
404 const bke::BlenderProject *project = ptr->data_as<bke::BlenderProject>();
405 variables_length = project->variables.size();
406 });
407 return variables_length;
408}
409
410static PointerRNA rna_iterator_BlenderProject_variables_get(CollectionPropertyIterator *iter)
411{
412 PointerRNA variable;
414 BLI_assert(iter->valid);
415
416 ArrayIterator *internal = &iter->internal.array;
417
418 std::unique_ptr<IDProperty, idprop::IDPropertyDeleter> *var_ptr_ptr =
419 reinterpret_cast<std::unique_ptr<IDProperty, idprop::IDPropertyDeleter> *>(internal->ptr);
420
421 IDProperty *var_ptr = var_ptr_ptr->get();
422
423 variable = RNA_pointer_create_with_parent(iter->parent, RNA_ProjectVariable, var_ptr);
424 });
425 return variable;
426}
427
428static PointerRNA rna_ProjectVariables_new(BlenderProject *project,
429 ReportList *reports,
430 const char *name,
431 int type)
432{
434 BKE_reportf(reports,
435 RPT_ERROR,
436 "Invalid variable name '%s': name must not be empty, must not start with a digit, "
437 "and must contain only alphanumeric characters and underscores.",
438 name);
439 return {};
440 }
441
442 PointerRNA variable;
444 ProjectVariable *new_var = project->new_variable(name, ProjectVariableType(type));
445
446 project->active_variable_index = project->variables.size() - 1;
447
449 RNA_pointer_create_discrete(nullptr, RNA_BlenderProject, project),
450 RNA_ProjectVariable,
451 new_var);
452 });
453 project_mark_dirty(project);
455 return variable;
456}
457
458void rna_ProjectVariables_remove(BlenderProject *project,
459 ReportList *reports,
460 PointerRNA *variable_ptr)
461{
462 BLI_assert(ELEM(variable_ptr->type,
463 RNA_ProjectVariableString,
464 RNA_ProjectVariableInteger,
465 RNA_ProjectVariableFloat));
466
468 ProjectVariable *var = variable_ptr->data_as<ProjectVariable>();
469 if (project->remove_variable(var) == -1) {
470 BKE_reportf(reports, RPT_ERROR, "Variable not found in project variables.");
471 return;
472 }
473 });
474 project_mark_dirty(project);
476}
477
478void rna_ProjectVariables_move(BlenderProject *project,
479 ReportList *reports,
480 int from_index,
481 int to_index)
482{
484 if (from_index >= project->variables.size()) {
485 BKE_reportf(reports, RPT_ERROR, "From index is out of bounds of the variable list.");
486 return;
487 }
488
489 if (to_index >= project->variables.size()) {
490 BKE_reportf(reports, RPT_ERROR, "To index is out of bounds of the variable list.");
491 return;
492 }
493
494 project->move_variable(from_index, to_index);
495 });
496 project_mark_dirty(project);
498}
499
500/* --------------------------------------------------------- */
501
502/* Purely runtime presets and enum for easily setting common configs paths from the UI. */
503struct ProjectOCIOConfigPreset {
504 ProjectOCIOConfig value;
505 const char *uri;
506};
507
508static const ProjectOCIOConfigPreset project_ocio_config_presets[] = {
509 {ProjectOCIOConfig::ACES_1_3_Studio, "ocio://studio-config-v2.2.0_aces-v1.3_ocio-v2.4"},
510 {ProjectOCIOConfig::ACES_2_0_Studio, "ocio://studio-config-v4.0.0_aces-v2.0_ocio-v2.5"},
511};
512
513static int rna_BlenderProject_ocio_config_get(PointerRNA *ptr)
514{
517 const bke::BlenderProject *project = ptr->data_as<bke::BlenderProject>();
518 if (project->ocio_config_use_path) {
519 return;
520 }
521
522 /* Determine preset from the path. */
523 const StringRefNull path = project->get_ocio_config_path();
524 if (path.is_empty()) {
525 ocio_config = ProjectOCIOConfig::Blender;
526 return;
527 }
528 for (const auto &preset : project_ocio_config_presets) {
529 if (path == preset.uri) {
530 ocio_config = preset.value;
531 return;
532 }
533 }
534 });
535 return int(ocio_config);
536}
537
538static void rna_BlenderProject_ocio_config_set(PointerRNA *ptr, const int value)
539{
540 const ProjectOCIOConfig ocio_config = ProjectOCIOConfig(value);
543
544 /* Keep the existing path for the user to edit, even if it matches a preset. */
545 project->ocio_config_use_path = ocio_config == ProjectOCIOConfig::Path;
546 if (ocio_config == ProjectOCIOConfig::Path) {
547 return;
548 }
549
550 StringRefNull path = "";
551 for (const auto &preset : project_ocio_config_presets) {
552 if (ocio_config == preset.value) {
553 path = preset.uri;
554 break;
555 }
556 }
557 if (project->get_ocio_config_path() != path) {
558 project->set_ocio_config_path(path);
559 }
560 });
561}
562
563static void rna_BlenderProject_ocio_config_path_get(PointerRNA *ptr, char *value)
564{
566 const bke::BlenderProject *project = ptr->data_as<bke::BlenderProject>();
567 strcpy(value, project->get_ocio_config_path().c_str());
568 });
569}
570
571static int rna_BlenderProject_ocio_config_path_length(PointerRNA *ptr)
572{
573 int ocio_config_path_length;
575 const bke::BlenderProject *project = ptr->data_as<bke::BlenderProject>();
576 ocio_config_path_length = project->get_ocio_config_path().size();
577 });
578 return ocio_config_path_length;
579}
580
581static void rna_BlenderProject_ocio_config_path_set(PointerRNA *ptr, const char *value)
582{
585 project->set_ocio_config_path(value);
586 });
587}
588
589static std::optional<std::string> rna_BlenderProject_ocio_config_path_filter(
590 const bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/)
591{
592 return "*.ocio";
593}
594
595static void rna_BlenderProject_splash_image_path_get(PointerRNA *ptr, char *value)
596{
598 const bke::BlenderProject *project = ptr->data_as<bke::BlenderProject>();
599 strcpy(value, project->get_splash_image_path().c_str());
600 });
601}
602
603static int rna_BlenderProject_splash_image_path_length(PointerRNA *ptr)
604{
605 int splash_image_path_length;
607 const bke::BlenderProject *project = ptr->data_as<bke::BlenderProject>();
608 splash_image_path_length = project->get_splash_image_path().size();
609 });
610 return splash_image_path_length;
611}
612
613static void rna_BlenderProject_splash_image_path_set(PointerRNA *ptr, const char *value)
614{
617 project->set_splash_image_path(value);
618 });
619}
620
621static std::optional<std::string> rna_BlenderProject_splash_image_path_filter(
622 const bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/)
623{
624 return "*.png;*.jpg;*.jpeg;*.webp";
625}
626
627static bool rna_BlenderProject_is_dirty_get(PointerRNA *ptr)
628{
629 bool is_dirty;
631 bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
632 is_dirty = project->is_dirty;
633 });
634 return is_dirty;
635}
636
637static void rna_BlenderProject_is_dirty_set(PointerRNA *ptr, bool value)
638{
640 bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
641 project->is_dirty = value;
642 });
643}
644
645static bool skip_assetlist_item(CollectionPropertyIterator * /*iter*/, void *data)
646{
647 bUserAssetLibrary *asset_library = static_cast<bUserAssetLibrary *>(data);
648 return !(asset_library->flag & ASSET_LIBRARY_PROJECT_DEFINED);
649}
650
651static void rna_BlenderProject_asset_library_list_begin(CollectionPropertyIterator *iter,
652 PointerRNA *ptr)
653{
654 rna_iterator_listbase_begin(iter, ptr, &U.asset_libraries, skip_assetlist_item);
655}
656
657static int rna_BlenderProject_active_asset_library_get(PointerRNA *ptr)
658{
659 int active_index;
661 const bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
662 active_index = project->active_asset_library_index;
663 });
664 return active_index;
665}
666
667static void rna_BlenderProject_active_asset_library_set(PointerRNA *ptr, int value)
668{
670 bke::BlenderProject *project = static_cast<bke::BlenderProject *>(ptr->data);
671 project->active_asset_library_index = value;
672 });
673}
674
675static bUserAssetLibrary *rna_BlenderProject_asset_library_new(const bContext *C,
676 const char *name,
677 const char *directory,
678 const char *uuid_str,
679 const char *remote_url)
680{
681 /* Keep this function in sync with the logic in project_asset_library_add in
682 * blender_project_config.cc. */
683
684 bUserAssetLibrary *new_library;
685 Main *bmain = CTX_data_main(C);
686 const bool is_remote = remote_url && remote_url[0];
687
689 std::optional<UUID> uuid = {};
690 bool invalid_uuid = false;
691 if (uuid_str) {
692 try {
693 uuid = UUID(uuid_str);
694 }
695 catch (const std::runtime_error &e) {
696 invalid_uuid = true;
697 }
698 }
699
700 const bool path_is_template = true;
701 const std::string directory_str = BKE_blender_project_path_make_relative(
702 directory ? directory : "", path_is_template, *project);
703
704 new_library = ED_userpref_asset_library_new(C,
705 name ? name : "",
706 is_remote ? remote_url : directory_str.c_str(),
709 true,
710 uuid,
711 {});
712 if (invalid_uuid) {
713 /* User passed an invalid UUID, disable the library and set the invalid_uuid string so we can
714 * notify the user about this in the UI.
715 */
716 new_library->flag |= ASSET_LIBRARY_DISABLED;
717 new_library->invalid_uuid = BLI_strdup(uuid_str);
718 }
719
720 int project_asset_index = -1;
721 for (bUserAssetLibrary &library : U.asset_libraries) {
723 project_asset_index++;
724 }
725 if (&library == new_library) {
726 break;
727 }
728 }
729
730 project->active_asset_library_index = project_asset_index;
731 project->is_dirty = true;
732 });
733 /* Force full redraw of all windows. (No notifier to redraw just the project asset windows yet)
734 */
736 return new_library;
737}
738
739static void rna_BlenderProject_asset_library_remove(bContext *C,
740 ReportList *reports,
741 PointerRNA *ptr)
742{
743 bUserAssetLibrary *library = static_cast<bUserAssetLibrary *>(ptr->data);
744 Main *bmain = CTX_data_main(C);
745
747 if (BLI_findindex(&U.asset_libraries, library) == -1) {
748 BKE_report(reports, RPT_ERROR, "Asset Library not found");
749 return;
750 }
751
753
754 int count_remaining = 0;
755 for (bUserAssetLibrary &library : U.asset_libraries) {
757 count_remaining++;
758 }
759 }
760 CLAMP(project->active_asset_library_index, 0, count_remaining - 1);
761
762 ptr->invalidate();
763 project->is_dirty = true;
764 });
765 /* Force full redraw of all windows.(No notifier to redraw just the project asset windows yet) */
767}
768
769} // namespace blender
770
771#else
772
773namespace blender {
774
776{
777 StructRNA *srna;
778 PropertyRNA *prop;
779
780 srna = RNA_def_struct(brna, "ProjectVariableString", "ProjectVariable");
781 RNA_def_struct_ui_text(srna, "String Project Variable", "A project variable of type string");
782
783 prop = RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
784 RNA_def_property_ui_text(prop, "Value", "The variable's string/path value");
786 "rna_ProjectVariableString_value_get",
787 "rna_ProjectVariableString_value_length",
788 "rna_ProjectVariableString_value_set");
789 RNA_def_property_update(prop, 0, "rna_ProjectVariable_update");
790
791 prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
792 RNA_def_property_ui_text(prop, "Subtype", "The string variable's subtype");
795 "rna_ProjectVariableString_subtype_get",
796 "rna_ProjectVariableString_subtype_set",
797 nullptr);
798 RNA_def_property_update(prop, 0, "rna_ProjectVariable_update");
799}
800
802{
803 StructRNA *srna;
804 PropertyRNA *prop;
805
806 srna = RNA_def_struct(brna, "ProjectVariableInteger", "ProjectVariable");
807 RNA_def_struct_ui_text(srna, "Integer Project Variable", "A project variable of type integer");
808
809 prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
810 RNA_def_property_ui_text(prop, "Value", "The variable's integer value");
812 "rna_ProjectVariableInteger_value_get",
813 "rna_ProjectVariableInteger_value_set",
814 nullptr);
815 RNA_def_property_update(prop, 0, "rna_ProjectVariable_update");
816}
817
819{
820 StructRNA *srna;
821 PropertyRNA *prop;
822
823 srna = RNA_def_struct(brna, "ProjectVariableFloat", "ProjectVariable");
824 RNA_def_struct_ui_text(srna, "Float Project Variable", "A project variable of type float");
825
826 prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
827 RNA_def_property_ui_text(prop, "Value", "The variable's float value");
829 prop, "rna_ProjectVariableFloat_value_get", "rna_ProjectVariableFloat_value_set", nullptr);
830 RNA_def_property_update(prop, 0, "rna_ProjectVariable_update");
831}
832
834{
835 StructRNA *srna;
836 PropertyRNA *prop;
837
838 srna = RNA_def_struct(brna, "ProjectVariable", nullptr);
839 RNA_def_struct_ui_text(srna, "Blender Project Variable", "");
840 RNA_def_struct_refine_func(srna, "rna_ProjectVariable_refine");
841
842 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
843 RNA_def_property_ui_text(prop, "Type", "The variable's data type");
845 RNA_def_property_enum_funcs(prop, "rna_ProjectVariable_type_get", nullptr, nullptr);
847
848 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
851 "Name",
852 "The variable's name. Must not start with a digit, and must contain "
853 "only alphanumeric characters and underscores");
855 "rna_ProjectVariable_name_get",
856 "rna_ProjectVariable_name_length",
857 "rna_ProjectVariable_name_set");
858 RNA_def_property_update(prop, 0, "rna_ProjectVariable_update");
859
860 prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
862 prop, "Description", "Description of the variable (e.g. purpose, semantics, etc.)");
864 "rna_ProjectVariable_description_get",
865 "rna_ProjectVariable_description_length",
866 "rna_ProjectVariable_description_set");
867 RNA_def_property_update(prop, 0, "rna_ProjectVariable_update");
868
869 /* Define ProjectVariable subtypes. */
873}
874
876{
877 StructRNA *srna;
878
879 FunctionRNA *func;
880 PropertyRNA *parm;
881
882 RNA_def_property_srna(cprop, "ProjectVariables");
883 srna = RNA_def_struct(brna, "ProjectVariables", nullptr);
884 RNA_def_struct_sdna(srna, "BlenderProject");
885 RNA_def_struct_ui_text(srna, "Project Variables", "Collection of project variables");
886
887 /* BlenderProject.variables.new(...) */
888 func = RNA_def_function(srna, "new", "rna_ProjectVariables_new");
889 RNA_def_function_ui_description(func, "Add a new variable to the project");
891 parm = RNA_def_string(func, "name", "Variable", 0, "Name", "Name of the new variable");
893 parm = RNA_def_enum(func,
894 "type",
897 "Variable Type",
898 "The data type of the variable");
899 parm = RNA_def_pointer(
900 func, "variable", "ProjectVariable", "", "Newly created project variable");
902 RNA_def_function_return(func, parm);
903
904 /* BlenderProject.variables.remove(variable) */
905 func = RNA_def_function(srna, "remove", "rna_ProjectVariables_remove");
907 RNA_def_function_ui_description(func, "Remove a variable from the project");
908 parm = RNA_def_pointer(
909 func, "variable", "ProjectVariable", "Variable", "The variable to remove");
911
912 /* BlenderProject.variables.move(from_index, to_index) */
913 func = RNA_def_function(srna, "move", "rna_ProjectVariables_move");
916 func, "Move a variable from one position to another in the list of variables");
917 parm = RNA_def_int(func,
918 "from_index",
919 0,
920 0,
921 INT_MAX,
922 "From Index",
923 "The index of the variable to move",
924 0,
925 INT_MAX);
927 parm = RNA_def_int(func,
928 "to_index",
929 0,
930 0,
931 INT_MAX,
932 "To Index",
933 "The index to move the variable to",
934 0,
935 INT_MAX);
937}
938
940{
941 StructRNA *srna;
942 FunctionRNA *func;
943 PropertyRNA *parm;
944
945 RNA_def_property_srna(cprop, "ProjectAssetLibraryCollection");
946 srna = RNA_def_struct(brna, "ProjectAssetLibraryCollection", nullptr);
947 RNA_def_struct_ui_text(srna, "Project Asset Libraries", "Collection of project asset libraries");
948
949 func = RNA_def_function(srna, "new", "rna_BlenderProject_asset_library_new");
951 RNA_def_function_ui_description(func, "Add a new Project Asset Library");
952 RNA_def_string(func, "name", nullptr, sizeof(bUserAssetLibrary::name), "Name", "");
953 RNA_def_string(func, "directory", nullptr, sizeof(bUserAssetLibrary::dirpath), "Directory", "");
954 RNA_def_string(func, "uuid", nullptr, sizeof(bUserAssetLibrary::uuid), "UUID", "");
955 RNA_def_string(func,
956 "remote_url",
957 nullptr,
959 "Remote URL",
960 "When set, add a remote asset library instead of a local directory");
961 /* return type */
962 parm = RNA_def_pointer(func, "library", "ProjectAssetLibrary", "", "Newly added asset library");
963 RNA_def_function_return(func, parm);
964
965 func = RNA_def_function(srna, "remove", "rna_BlenderProject_asset_library_remove");
967 RNA_def_function_ui_description(func, "Remove a Project Asset Library");
968 parm = RNA_def_pointer(func, "library", "ProjectAssetLibrary", "", "");
971}
972
974{
975 StructRNA *srna = RNA_def_struct(brna, "BlenderProject", nullptr);
976 RNA_def_struct_ui_text(srna, "Blender Project", "");
977
978 PropertyRNA *prop;
979 prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
981 prop, "rna_BlenderProject_is_dirty_get", "rna_BlenderProject_is_dirty_set");
982 RNA_def_property_ui_text(prop, "Dirty", "Whether the project has unsaved changes");
983 RNA_def_property_update(prop, 0, "rna_BlenderProject_ui_update");
984
985 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
987 "rna_BlenderProject_name_get",
988 "rna_BlenderProject_name_length",
989 "rna_BlenderProject_name_set");
990 RNA_def_property_ui_text(prop, "Name", "The project's name");
992 RNA_def_property_update(prop, 0, "rna_BlenderProject_name_update");
993
994 prop = RNA_def_property(srna, "root_path", PROP_STRING, PROP_DIRPATH);
998 prop, "rna_BlenderProject_root_path_get", "rna_BlenderProject_root_path_length", nullptr);
999 RNA_def_property_ui_text(prop, "Root Folder", "The path to the root folder of the project");
1000
1001 prop = RNA_def_property(srna, "ocio_config", PROP_ENUM, PROP_NONE);
1004 prop, "rna_BlenderProject_ocio_config_get", "rna_BlenderProject_ocio_config_set", nullptr);
1006 prop, "OpenColorIO Configuration", "OpenColorIO configuration to use for this project");
1007 RNA_def_property_update(prop, 0, "rna_BlenderProject_ui_update");
1008
1009 prop = RNA_def_property(srna, "ocio_config_path", PROP_STRING, PROP_FILEPATH);
1014 "rna_BlenderProject_ocio_config_path_get",
1015 "rna_BlenderProject_ocio_config_path_length",
1016 "rna_BlenderProject_ocio_config_path_set");
1017 RNA_def_property_string_filepath_filter_func(prop, "rna_BlenderProject_ocio_config_path_filter");
1019 prop,
1020 "OpenColorIO Configuration Path",
1021 "Path to the OpenColorIO configuration to use for this project. May be an absolute file "
1022 "path, project relative path with {project_root}, or an ocio:// built-in OpenColorIO "
1023 "config");
1024 RNA_def_property_update(prop, 0, "rna_BlenderProject_update");
1025
1026 prop = RNA_def_property(srna, "splash_image_path", PROP_STRING, PROP_FILEPATH);
1031 "rna_BlenderProject_splash_image_path_get",
1032 "rna_BlenderProject_splash_image_path_length",
1033 "rna_BlenderProject_splash_image_path_set");
1035 "rna_BlenderProject_splash_image_path_filter");
1037 prop,
1038 "Splash Artwork",
1039 "Image to show in the splash screen for this project. Expected size is 1000x500 pixels");
1040 RNA_def_property_update(prop, 0, "rna_BlenderProject_update");
1041
1042 prop = RNA_def_property(srna, "active_variable_index", PROP_INT, PROP_NONE);
1044 "rna_BlenderProject_active_variable_index_get",
1045 "rna_BlenderProject_active_variable_index_set",
1046 "rna_BlenderProject_active_variable_index_range");
1048 prop, "Active Project Variable", "Index of the currently active variable in the UI");
1049
1050 /* Collection properties. */
1051 prop = RNA_def_property(srna, "variables", PROP_COLLECTION, PROP_NONE);
1052 RNA_def_property_struct_type(prop, "ProjectVariable");
1054 "rna_iterator_BlenderProject_variables_begin",
1055 "rna_iterator_array_next",
1056 "rna_iterator_array_end",
1057 "rna_iterator_BlenderProject_variables_get",
1058 "rna_iterator_BlenderProject_variables_length",
1059 nullptr,
1060 nullptr,
1061 nullptr);
1062 RNA_def_property_ui_text(prop, "Project Variables", "The variables in this project");
1063 rna_def_ProjectVariables(brna, prop);
1064
1065 prop = RNA_def_property(srna, "asset_libraries", PROP_COLLECTION, PROP_NONE);
1067 "rna_BlenderProject_asset_library_list_begin",
1068 "rna_iterator_listbase_next",
1069 "rna_iterator_listbase_end",
1070 "rna_iterator_listbase_get",
1071 nullptr,
1072 nullptr,
1073 nullptr,
1074 nullptr);
1075 RNA_def_property_struct_type(prop, "ProjectAssetLibrary");
1076 RNA_def_property_ui_text(prop, "Project Asset Libraries", "");
1077
1079
1080 prop = RNA_def_property(srna, "active_asset_library", PROP_INT, PROP_NONE);
1082 "rna_BlenderProject_active_asset_library_get",
1083 "rna_BlenderProject_active_asset_library_set",
1084 nullptr);
1086 "Active Asset Library",
1087 "Index of the asset library being edited in the Project Settings UI");
1088}
1089
1095
1096} // namespace blender
1097
1098#endif
Functions and classes for evaluating template expressions in filepaths.
#define FILE_MAX
#define C
Definition RandGen.cpp:29
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_PROJECT_CHANGED
Definition WM_types.hh:436
#define NC_WM
Definition WM_types.hh:387
#define CLAMP(a, b, c)
#define ELEM(...)
btScalar max
constexpr StringRefNull()
constexpr StringRef()
UUID()=default
void string_subtype_set(ProjectVariableStringSubtype type)
void description_set(StringRef description)
StringRefNull description_get() const
void value_set(StringRefNull value)
StringRefNull value_string_get() const
StringRefNull name_get() const
constexpr int64_t size() const
#define INT_MAX
void with_blender_project_write_lock(FunctionRef< void()> lambda)
void with_blender_project_read_lock(FunctionRef< void()> lambda)
bool is_valid_project_variable_name(StringRef name)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
UserDef U
Definition blender.cc:58
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
static void rna_def_ProjectVariables(BlenderRNA *brna, PropertyRNA *cprop)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
static void rna_def_project_variable_integer(BlenderRNA *brna)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
@ ASSET_LIBRARY_PROJECT_DEFINED
@ ASSET_LIBRARY_DISABLED
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
static void rna_def_project_asset_library_collection(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
@ FUNC_USE_REPORTS
@ FUNC_NO_SELF
Definition RNA_types.hh:998
@ FUNC_USE_CONTEXT
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_path_template_type(PropertyRNA *prop, PropertyPathTemplateType path_template_type)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
const EnumPropertyItem rna_enum_project_variable_type_items[]
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
@ PROP_VARIABLES_PROJECT
Definition RNA_types.hh:577
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void ED_userpref_asset_library_remove(bContext *C, struct bUserAssetLibrary *asset_library)
static void rna_def_project_variable(BlenderRNA *brna)
struct bUserAssetLibrary * ED_userpref_asset_library_new(const struct bContext *C, const char *name, const char *dirpath, bUserAssetLibraryAddType library_type, bool is_project_defined, std::optional< UUID > uuid, std::optional< char * > auth_token)
void RNA_def_property_string_filepath_filter_func(PropertyRNA *prop, const char *filter)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
static const EnumPropertyItem rna_enum_project_ocio_config_items[]
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void RNA_def_blender_project(BlenderRNA *brna)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
const EnumPropertyItem rna_enum_project_variable_string_subtype_items[]
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
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)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
static void rna_def_project_variable_float(BlenderRNA *brna)
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
static void rna_def_project_variable_string(BlenderRNA *brna)
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_PATH_SUPPORTS_TEMPLATES
Definition RNA_types.hh:540
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
@ PROP_FILEPATH
Definition RNA_types.hh:284
@ PROP_DIRPATH
Definition RNA_types.hh:285
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, ListBase *lb, IteratorSkipFunc skip)
static void rna_def_blender_project(BlenderRNA *brna)
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop, const bool allow_replace)
void rna_iterator_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, void *data, size_t itemsize, int64_t length, bool free_ptr, IteratorSkipFunc skip)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
auto BKE_blender_project_write_callback(const Main *bmain, Fn lambda)
std::string BKE_blender_project_path_make_relative(StringRef path, bool path_is_template, const bke::BlenderProject &project)
#define min(a, b)
Definition sort.cc:38