Blender
V4.3
source
blender
editors
asset
intern
asset_library_reference_enum.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
14
#include "
BLI_listbase.h
"
15
16
#include "
BKE_preferences.h
"
17
18
#include "
DNA_userdef_types.h
"
19
20
#include "
UI_resources.hh
"
21
22
#include "
RNA_define.hh
"
23
#include "
RNA_enum_types.hh
"
24
25
#include "
ED_asset_library.hh
"
26
27
namespace
blender::ed::asset
{
28
29
int
library_reference_to_enum_value
(
const
AssetLibraryReference
*library)
30
{
31
/* Simple case: Predefined repository, just set the value. */
32
if
(library->
type
<
ASSET_LIBRARY_CUSTOM
) {
33
return
library->
type
;
34
}
35
36
/* Note that the path isn't checked for validity here. If an invalid library path is used, the
37
* Asset Browser can give a nice hint on what's wrong. */
38
const
bUserAssetLibrary
*user_library =
BKE_preferences_asset_library_find_index
(
39
&
U
, library->
custom_library_index
);
40
if
(user_library) {
41
return
ASSET_LIBRARY_CUSTOM
+ library->
custom_library_index
;
42
}
43
44
return
ASSET_LIBRARY_LOCAL
;
45
}
46
47
AssetLibraryReference
library_reference_from_enum_value
(
int
value)
48
{
49
AssetLibraryReference
library;
50
51
/* Simple case: Predefined repository, just set the value. */
52
if
(value <
ASSET_LIBRARY_CUSTOM
) {
53
library.
type
= value;
54
library.
custom_library_index
= -1;
55
BLI_assert
(
ELEM
(value,
ASSET_LIBRARY_ALL
,
ASSET_LIBRARY_LOCAL
,
ASSET_LIBRARY_ESSENTIALS
));
56
return
library;
57
}
58
59
const
bUserAssetLibrary
*user_library =
BKE_preferences_asset_library_find_index
(
60
&
U
, value -
ASSET_LIBRARY_CUSTOM
);
61
62
/* Note that there is no check if the path exists here. If an invalid library path is used, the
63
* Asset Browser can give a nice hint on what's wrong. */
64
if
(!user_library) {
65
library.
type
=
ASSET_LIBRARY_ALL
;
66
library.
custom_library_index
= -1;
67
}
68
else
{
69
const
bool
is_valid
= (user_library->
name
[0] && user_library->
dirpath
[0]);
70
if
(
is_valid
) {
71
library.
custom_library_index
= value -
ASSET_LIBRARY_CUSTOM
;
72
library.
type
=
ASSET_LIBRARY_CUSTOM
;
73
}
74
}
75
return
library;
76
}
77
78
const
EnumPropertyItem
*
library_reference_to_rna_enum_itemf
(
const
bool
include_generated)
79
{
80
EnumPropertyItem
*item =
nullptr
;
81
int
totitem = 0;
82
83
if
(include_generated) {
84
/* Add predefined libraries that are generated and not simple directories that can be written
85
* to. */
86
BLI_assert
(
rna_enum_asset_library_type_items
[0].value ==
ASSET_LIBRARY_ALL
);
87
RNA_enum_item_add
(&item, &totitem, &
rna_enum_asset_library_type_items
[0]);
88
RNA_enum_item_add_separator
(&item, &totitem);
89
90
BLI_assert
(
rna_enum_asset_library_type_items
[1].value ==
ASSET_LIBRARY_LOCAL
);
91
RNA_enum_item_add
(&item, &totitem, &
rna_enum_asset_library_type_items
[1]);
92
BLI_assert
(
rna_enum_asset_library_type_items
[2].value ==
ASSET_LIBRARY_ESSENTIALS
);
93
RNA_enum_item_add
(&item, &totitem, &
rna_enum_asset_library_type_items
[2]);
94
}
95
96
/* Add separator if needed. */
97
if
(!
BLI_listbase_is_empty
(&
U
.asset_libraries)) {
98
RNA_enum_item_add_separator
(&item, &totitem);
99
}
100
101
int
i;
102
LISTBASE_FOREACH_INDEX
(
bUserAssetLibrary
*, user_library, &
U
.asset_libraries, i) {
103
/* Note that the path itself isn't checked for validity here. If an invalid library path is
104
* used, the Asset Browser can give a nice hint on what's wrong. */
105
const
bool
is_valid
= (user_library->name[0] && user_library->dirpath[0]);
106
if
(!
is_valid
) {
107
continue
;
108
}
109
110
AssetLibraryReference
library_reference;
111
library_reference.
type
=
ASSET_LIBRARY_CUSTOM
;
112
library_reference.
custom_library_index
= i;
113
114
const
int
enum_value =
library_reference_to_enum_value
(&library_reference);
115
/* Use library path as description, it's a nice hint for users. */
116
EnumPropertyItem
tmp = {
117
enum_value, user_library->
name
, ICON_NONE, user_library->name, user_library->dirpath};
118
RNA_enum_item_add
(&item, &totitem, &tmp);
119
}
120
121
RNA_enum_item_end
(&item, &totitem);
122
return
item;
123
}
124
125
}
// namespace blender::ed::asset
BKE_preferences.h
BKE_preferences_asset_library_find_index
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
BLI_assert
#define BLI_assert(a)
Definition
BLI_assert.h:50
BLI_listbase.h
BLI_listbase_is_empty
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition
BLI_listbase.h:298
LISTBASE_FOREACH_INDEX
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
Definition
BLI_listbase.h:380
ELEM
#define ELEM(...)
Definition
BLI_utildefines.h:144
ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_CUSTOM
Definition
DNA_asset_types.h:109
ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_ESSENTIALS
Definition
DNA_asset_types.h:102
ASSET_LIBRARY_LOCAL
@ ASSET_LIBRARY_LOCAL
Definition
DNA_asset_types.h:99
ASSET_LIBRARY_ALL
@ ASSET_LIBRARY_ALL
Definition
DNA_asset_types.h:100
DNA_userdef_types.h
ED_asset_library.hh
RNA_define.hh
RNA_enum_types.hh
UI_resources.hh
U
unsigned int U
Definition
btGjkEpa3.h:78
is_valid
bool is_valid
Definition
deg_eval_copy_on_write.cc:265
blender::ed::asset
Definition
ED_asset_catalog.hh:28
blender::ed::asset::library_reference_to_enum_value
int library_reference_to_enum_value(const AssetLibraryReference *library)
Definition
asset_library_reference_enum.cc:29
blender::ed::asset::library_reference_from_enum_value
AssetLibraryReference library_reference_from_enum_value(int value)
Definition
asset_library_reference_enum.cc:47
blender::ed::asset::library_reference_to_rna_enum_itemf
const EnumPropertyItem * library_reference_to_rna_enum_itemf(bool include_generated)
Definition
asset_library_reference_enum.cc:78
rna_enum_asset_library_type_items
const EnumPropertyItem rna_enum_asset_library_type_items[]
Definition
rna_asset.cc:22
RNA_enum_item_end
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
Definition
rna_define.cc:4665
RNA_enum_item_add
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
Definition
rna_define.cc:4613
RNA_enum_item_add_separator
void RNA_enum_item_add_separator(EnumPropertyItem **items, int *totitem)
Definition
rna_define.cc:4637
AssetLibraryReference
Definition
DNA_asset_types.h:134
AssetLibraryReference::type
short type
Definition
DNA_asset_types.h:135
AssetLibraryReference::custom_library_index
int custom_library_index
Definition
DNA_asset_types.h:142
EnumPropertyItem
Definition
RNA_types.hh:497
EnumPropertyItem::name
const char * name
Definition
RNA_types.hh:510
bUserAssetLibrary
Definition
DNA_userdef_types.h:618
bUserAssetLibrary::name
char name[64]
Definition
DNA_userdef_types.h:621
bUserAssetLibrary::dirpath
char dirpath[1024]
Definition
DNA_userdef_types.h:622
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0