[Bf-blender-cvs] [897ed456751] asset-browser-poselib: Cleanup: Move temporary ID consumer class for assets into own file
Julian Eisel
noreply at git.blender.org
Mon Jun 14 20:26:07 CEST 2021
Commit: 897ed45675106bb5c2742df8bdaf0574d0b70559
Author: Julian Eisel
Date: Mon Jun 14 20:22:36 2021 +0200
Branches: asset-browser-poselib
https://developer.blender.org/rB897ed45675106bb5c2742df8bdaf0574d0b70559
Cleanup: Move temporary ID consumer class for assets into own file
Doesn't really make sense to keep this in `asset_edit.cc`.
===================================================================
M source/blender/editors/asset/CMakeLists.txt
M source/blender/editors/asset/asset_edit.cc
A source/blender/editors/asset/asset_temp_id_consumer.cc
===================================================================
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
index d87879bea2a..a27975bc37b 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -33,6 +33,7 @@ set(SRC
asset_edit.cc
asset_list.cc
asset_ops.cc
+ asset_temp_id_consumer.cc
)
set(LIB
diff --git a/source/blender/editors/asset/asset_edit.cc b/source/blender/editors/asset/asset_edit.cc
index 57832aa1e20..0937af0dbf1 100644
--- a/source/blender/editors/asset/asset_edit.cc
+++ b/source/blender/editors/asset/asset_edit.cc
@@ -24,9 +24,6 @@
#include "BKE_asset.h"
#include "BKE_context.h"
#include "BKE_lib_id.h"
-#include "BKE_report.h"
-
-#include "BLI_utility_mixins.hh"
#include "BLO_readfile.h"
@@ -34,10 +31,6 @@
#include "DNA_asset_types.h"
#include "DNA_space_types.h"
-#include "ED_fileselect.h"
-
-#include "MEM_guardedalloc.h"
-
#include "UI_interface_icons.h"
#include "RNA_access.h"
@@ -160,79 +153,3 @@ void ED_asset_handle_get_full_library_path(const bContext *C,
BLO_library_path_explode(asset_path.c_str(), r_full_lib_path, nullptr, nullptr);
}
-
-class AssetTemporaryIDConsumer : NonCopyable, NonMovable {
- const AssetHandle &handle_;
- TempLibraryContext *temp_lib_context_ = nullptr;
-
- public:
- AssetTemporaryIDConsumer(const AssetHandle &handle) : handle_(handle)
- {
- }
- ~AssetTemporaryIDConsumer()
- {
- if (temp_lib_context_) {
- BLO_library_temp_free(temp_lib_context_);
- }
- }
-
- ID *get_local_id()
- {
- return ED_assetlist_asset_local_id_get(&handle_);
- }
-
- ID *import_id(const bContext *C,
- const AssetLibraryReference &asset_library,
- ID_Type id_type,
- Main &bmain,
- ReportList &reports)
- {
- const char *asset_name = ED_asset_handle_get_name(&handle_);
- char blend_file_path[FILE_MAX_LIBEXTRA];
- ED_asset_handle_get_full_library_path(C, &asset_library, &handle_, blend_file_path);
-
- temp_lib_context_ = BLO_library_temp_load_id(
- &bmain, blend_file_path, id_type, asset_name, &reports);
-
- if (temp_lib_context_ == nullptr || temp_lib_context_->temp_id == nullptr) {
- BKE_reportf(&reports, RPT_ERROR, "Unable to load %s from %s", asset_name, blend_file_path);
- return nullptr;
- }
-
- BLI_assert(GS(temp_lib_context_->temp_id->name) == id_type);
- return temp_lib_context_->temp_id;
- }
-};
-
-AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const AssetHandle *handle)
-{
- if (!handle) {
- return nullptr;
- }
- BLI_assert(handle->file_data->asset_data != nullptr);
- return reinterpret_cast<AssetTempIDConsumer *>(
- OBJECT_GUARDED_NEW(AssetTemporaryIDConsumer, *handle));
-}
-
-void ED_asset_temp_id_consumer_free(AssetTempIDConsumer **consumer)
-{
- OBJECT_GUARDED_SAFE_DELETE(*consumer, AssetTemporaryIDConsumer);
-}
-
-ID *ED_asset_temp_id_consumer_ensure_local_id(AssetTempIDConsumer *consumer_,
- const bContext *C,
- const AssetLibraryReference *asset_library,
- ID_Type id_type,
- Main *bmain,
- ReportList *reports)
-{
- if (!(consumer_ && asset_library && bmain && reports)) {
- return nullptr;
- }
- AssetTemporaryIDConsumer *consumer = reinterpret_cast<AssetTemporaryIDConsumer *>(consumer_);
-
- if (ID *local_id = consumer->get_local_id()) {
- return local_id;
- }
- return consumer->import_id(C, *asset_library, id_type, *bmain, *reports);
-}
diff --git a/source/blender/editors/asset/asset_temp_id_consumer.cc b/source/blender/editors/asset/asset_temp_id_consumer.cc
new file mode 100644
index 00000000000..24e1fc86fef
--- /dev/null
+++ b/source/blender/editors/asset/asset_temp_id_consumer.cc
@@ -0,0 +1,113 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ *
+ * API for temporary loading of asset IDs.
+ * Uses the `BLO_library_temp_xxx()` API internally.
+ */
+
+#include "DNA_asset_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_report.h"
+
+#include "BLI_utility_mixins.hh"
+
+#include "BLO_readfile.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "ED_asset.h"
+
+using namespace blender;
+
+class AssetTemporaryIDConsumer : NonCopyable, NonMovable {
+ const AssetHandle &handle_;
+ TempLibraryContext *temp_lib_context_ = nullptr;
+
+ public:
+ AssetTemporaryIDConsumer(const AssetHandle &handle) : handle_(handle)
+ {
+ }
+ ~AssetTemporaryIDConsumer()
+ {
+ if (temp_lib_context_) {
+ BLO_library_temp_free(temp_lib_context_);
+ }
+ }
+
+ ID *get_local_id()
+ {
+ return ED_assetlist_asset_local_id_get(&handle_);
+ }
+
+ ID *import_id(const bContext *C,
+ const AssetLibraryReference &asset_library,
+ ID_Type id_type,
+ Main &bmain,
+ ReportList &reports)
+ {
+ const char *asset_name = ED_asset_handle_get_name(&handle_);
+ char blend_file_path[FILE_MAX_LIBEXTRA];
+ ED_asset_handle_get_full_library_path(C, &asset_library, &handle_, blend_file_path);
+
+ temp_lib_context_ = BLO_library_temp_load_id(
+ &bmain, blend_file_path, id_type, asset_name, &reports);
+
+ if (temp_lib_context_ == nullptr || temp_lib_context_->temp_id == nullptr) {
+ BKE_reportf(&reports, RPT_ERROR, "Unable to load %s from %s", asset_name, blend_file_path);
+ return nullptr;
+ }
+
+ BLI_assert(GS(temp_lib_context_->temp_id->name) == id_type);
+ return temp_lib_context_->temp_id;
+ }
+};
+
+AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const AssetHandle *handle)
+{
+ if (!handle) {
+ return nullptr;
+ }
+ BLI_assert(handle->file_data->asset_data != nullptr);
+ return reinterpret_cast<AssetTempIDConsumer *>(
+ OBJECT_GUARDED_NEW(AssetTemporaryIDConsumer, *handle));
+}
+
+void ED_asset_temp_id_consumer_free(AssetTempIDConsumer **consumer)
+{
+ OBJECT_GUARDED_SAFE_DELETE(*consumer, AssetTemporaryIDConsumer);
+}
+
+ID *ED_asset_temp_id_consumer_ensure_local_id(AssetTempIDConsumer *consumer_,
+ const bContext *C,
+ const AssetLibraryReference *asset_library,
+ ID_Type id_type,
+ Main *bmain,
+ ReportList *reports)
+{
+ if (!(consumer_ && asset_library && bmain && reports)) {
+ return nullptr;
+ }
+ AssetTemporaryIDConsumer *consumer = reinterpret_cast<AssetTemporaryIDConsumer *>(consumer_);
+
+ if (ID *local_id = consumer->get_local_id()) {
+ return local_id;
+ }
+ return consumer->import_id(C, *asset_library, id_type, *bmain, *reports);
+}
More information about the Bf-blender-cvs
mailing list