Blender  V2.93
asset_edit.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BKE_asset.h"
22 #include "BKE_context.h"
23 #include "BKE_lib_id.h"
24 
25 #include "DNA_ID.h"
26 
27 #include "UI_interface_icons.h"
28 
29 #include "RNA_access.h"
30 
31 #include "ED_asset.h"
32 
33 bool ED_asset_mark_id(const bContext *C, ID *id)
34 {
35  if (id->asset_data) {
36  return false;
37  }
38  if (!BKE_id_can_be_asset(id)) {
39  return false;
40  }
41 
42  id_fake_user_set(id);
43 
44  id->asset_data = BKE_asset_metadata_create();
45 
46  UI_icon_render_id(C, nullptr, id, ICON_SIZE_PREVIEW, true);
47 
48  return true;
49 }
50 
52 {
53  if (!id->asset_data) {
54  return false;
55  }
57  /* Don't clear fake user here, there's no guarantee that it was actually set by
58  * #ED_asset_mark_id(), it might have been something/someone else. */
59 
60  return true;
61 }
62 
64 {
65  /* Context needs a "id" pointer to be set for #ASSET_OT_mark()/#ASSET_OT_clear() to use. */
66  return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != nullptr;
67 }
struct AssetMetaData * BKE_asset_metadata_create(void)
Definition: asset.cc:40
void BKE_asset_metadata_free(struct AssetMetaData **asset_data)
Definition: asset.cc:47
PointerRNA CTX_data_pointer_get_type_silent(const bContext *C, const char *member, StructRNA *type)
Definition: context.c:475
void id_fake_user_set(struct ID *id)
Definition: lib_id.c:328
bool BKE_id_can_be_asset(const struct ID *id)
ID and Library types, which are fundamental for sdna.
@ ICON_SIZE_PREVIEW
Definition: DNA_ID_enums.h:30
StructRNA RNA_ID
#define C
Definition: RandGen.cpp:39
void UI_icon_render_id(const struct bContext *C, struct Scene *scene, struct ID *id, const enum eIconSizes size, const bool use_job)
bool ED_asset_clear_id(ID *id)
Definition: asset_edit.cc:51
bool ED_asset_mark_id(const bContext *C, ID *id)
Definition: asset_edit.cc:33
bool ED_asset_can_make_single_from_context(const bContext *C)
Definition: asset_edit.cc:63
Definition: DNA_ID.h:273
struct AssetMetaData * asset_data
Definition: DNA_ID.h:280
void * data
Definition: RNA_types.h:52