[Bf-blender-cvs] [eb4905a590f] new-object-types: Volumes: show error message in panel when volume failed to load
Brecht Van Lommel
noreply at git.blender.org
Tue Jan 28 09:17:55 CET 2020
Commit: eb4905a590fe4466736170098bf438f024139d8f
Author: Brecht Van Lommel
Date: Mon Jan 27 21:47:22 2020 +0100
Branches: new-object-types
https://developer.blender.org/rBeb4905a590fe4466736170098bf438f024139d8f
Volumes: show error message in panel when volume failed to load
===================================================================
M release/scripts/startup/bl_ui/properties_data_volume.py
M source/blender/blenkernel/BKE_volume.h
M source/blender/blenkernel/intern/volume.cc
M source/blender/makesrna/intern/rna_volume.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_volume.py b/release/scripts/startup/bl_ui/properties_data_volume.py
index 8a6fe2a566f..a5de87ea3d1 100644
--- a/release/scripts/startup/bl_ui/properties_data_volume.py
+++ b/release/scripts/startup/bl_ui/properties_data_volume.py
@@ -64,6 +64,12 @@ class DATA_PT_volume(DataButtonsPanel, Panel):
layout.prop(volume, "filepath", text="")
+ error_msg = volume.grids.error_message
+ if len(error_msg):
+ col = layout.column(align=True)
+ col.label(text="Failed to load volume:")
+ col.label(text=error_msg)
+
class VOLUME_UL_grids(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
@@ -81,6 +87,7 @@ class DATA_PT_volume_grids(DataButtonsPanel, Panel):
layout.template_list("VOLUME_UL_grids", "grids", volume, "grids", volume.grids, "active_index", rows=2)
+
class DATA_PT_custom_props_volume(DataButtonsPanel, PropertyPanel, Panel):
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
_context_path = "object.data"
diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h
index 5e66085ff21..5d2610f8a7a 100644
--- a/source/blender/blenkernel/BKE_volume.h
+++ b/source/blender/blenkernel/BKE_volume.h
@@ -85,6 +85,7 @@ extern void (*BKE_volume_batch_cache_free_cb)(struct Volume *volume);
typedef struct VolumeGrid VolumeGrid;
int BKE_volume_num_grids(struct Volume *volume);
+const char *BKE_volume_grids_error_msg(const struct Volume *volume);
/* Grid Metadata */
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index 3f2a2918d93..501641b9f42 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -64,8 +64,10 @@ struct VolumeGrid {
};
struct VolumeGridVector : public std::vector<VolumeGrid> {
- /* Absolute file path to read voxels from on-demand. */
+ /* Absolute file path that grids have been loaded from. */
char filepath[FILE_MAX];
+ /* File loading error message. */
+ std::string error_msg;
};
#endif
@@ -144,17 +146,20 @@ void BKE_volume_free(Volume *volume)
void BKE_volume_reload(Main *bmain, Volume *volume)
{
#ifdef WITH_OPENVDB
- volume->grids->clear();
+ VolumeGridVector &grids = *volume->grids;
+ grids.clear();
+ grids.error_msg.clear();
/* Get absolute file path. */
- STRNCPY(volume->grids->filepath, volume->filepath);
- BLI_path_abs(volume->grids->filepath, ID_BLEND_PATH(bmain, &volume->id));
+ STRNCPY(grids.filepath, volume->filepath);
+ BLI_path_abs(grids.filepath, ID_BLEND_PATH(bmain, &volume->id));
- /* TODO: move this to a better place. */
+ /* Initialize the first time we use it. This is thread safe and can be safely
+ * called multiple times. */
openvdb::initialize();
/* Open OpenVDB file. */
- openvdb::io::File file(volume->grids->filepath);
+ openvdb::io::File file(grids.filepath);
openvdb::GridPtrVec vdb_grids;
try {
@@ -163,8 +168,7 @@ void BKE_volume_reload(Main *bmain, Volume *volume)
vdb_grids = *(file.readAllGridMetadata());
}
catch (const openvdb::IoError &e) {
- /* TODO: report error to user. */
- std::cerr << e.what() << '\n';
+ grids.error_msg = e.what();
}
/* Add grids read from file to own vector, filtering out any NULL pointers. */
@@ -298,6 +302,11 @@ int BKE_volume_num_grids(Volume *volume)
#endif
}
+const char *BKE_volume_grids_error_msg(const Volume *volume)
+{
+ return volume->grids->error_msg.c_str();
+}
+
const VolumeGrid *BKE_volume_grid_for_metadata(Volume *volume, int grid_index)
{
#ifdef WITH_OPENVDB
@@ -311,29 +320,28 @@ const VolumeGrid *BKE_volume_grid_for_metadata(Volume *volume, int grid_index)
const VolumeGrid *BKE_volume_grid_for_tree(Volume *volume, int grid_index)
{
#ifdef WITH_OPENVDB
- VolumeGrid &grid = volume->grids->at(grid_index);
+ VolumeGridVector &grids = *volume->grids;
+ VolumeGrid &grid = grids.at(grid_index);
- if (!grid.has_tree) {
+ if (!grid.has_tree && grids.error_msg.empty()) {
std::lock_guard<std::mutex> lock(grid.mutex);
if (!grid.has_tree) {
/* Read OpenVDB grid on-demand. */
/* TODO: avoid repeating this for multiple grids when we know we will
* need them? How best to do it without keeping the file open forever? */
- openvdb::io::File file(volume->grids->filepath);
+ openvdb::io::File file(grids.filepath);
openvdb::GridPtrVec vdb_grids;
try {
file.setCopyMaxBytes(0);
file.open();
grid.vdb = file.readGrid(grid.vdb->getName());
+ grid.has_tree = true;
}
catch (const openvdb::IoError &e) {
- /* TODO: log error with clog. */
- std::cerr << e.what() << '\n';
+ grids.error_msg = e.what();
}
-
- grid.has_tree = true;
}
}
diff --git a/source/blender/makesrna/intern/rna_volume.c b/source/blender/makesrna/intern/rna_volume.c
index 6d348bd44a2..9e51722b81e 100644
--- a/source/blender/makesrna/intern/rna_volume.c
+++ b/source/blender/makesrna/intern/rna_volume.c
@@ -128,6 +128,20 @@ static void rna_VolumeGrids_active_grid_index_set(PointerRNA *ptr, int value)
volume->active_grid = value;
}
+/* Error Message */
+
+static void rna_VolumeGrids_error_message_get(PointerRNA *ptr, char *value)
+{
+ Volume *volume = (Volume *)ptr->data;
+ strcpy(value, BKE_volume_grids_error_msg(volume));
+}
+
+static int rna_VolumeGrids_error_message_length(PointerRNA *ptr)
+{
+ Volume *volume = (Volume *)ptr->data;
+ return strlen(BKE_volume_grids_error_msg(volume));
+}
+
#else
static void rna_def_volume_grid(BlenderRNA *brna)
@@ -162,6 +176,13 @@ static void rna_def_volume_grids(BlenderRNA *brna, PropertyRNA *cprop)
"rna_VolumeGrids_active_grid_index_set",
"rna_VolumeGrids_active_grid_index_range");
RNA_def_property_ui_text(prop, "Active Grid Index", "Index of active volume grid");
+
+ prop = RNA_def_property(srna, "error_message", PROP_STRING, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_string_funcs(
+ prop, "rna_VolumeGrids_error_message_get", "rna_VolumeGrids_error_message_length", NULL);
+ RNA_def_property_ui_text(
+ prop, "Error Message", "If loading grids failed, error message with details");
}
static void rna_def_volume(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list