-
-
Notifications
You must be signed in to change notification settings - Fork 428
File error reporting #3103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
File error reporting #3103
Changes from 6 commits
50f94ef
4d0079e
706ed0e
61ee9f3
acc5d29
b41202e
4f5a195
a4265d8
af67c7a
b3057b5
e19254b
7e77e39
348af74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -65,6 +65,12 @@ Force a specific reader to be used, disregarding the file extension and file con | |||||
|
|
||||||
| CLI: `--force-reader`. | ||||||
|
|
||||||
| ### `--skip-content-check` (_bool_, default: `false`) | ||||||
|
Prospect138 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| Make attempt to read file without checking it's header. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| CLI: `--skip-content-check`. | ||||||
|
|
||||||
| ### `scene.camera.orthographic` (_bool_, optional) | ||||||
|
|
||||||
| Set to true to force orthographic projection. Model-specified by default, which is false if not specified. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -33,6 +33,10 @@ List available _readers_ and exit. Ignore `--verbose`. | |||||
|
|
||||||
| Force a specific [reader](02-SUPPORTED_FORMATS.md) to be used, disregarding the file extension and file content. | ||||||
|
|
||||||
| ### `--skip-content-check` (_bool_, default: `false`) | ||||||
|
|
||||||
| Make attempt to read file without checking it's header. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ### `--list-bindings` | ||||||
|
|
||||||
| List available _bindings_ and exit. Ignore `--verbose`. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -6,9 +6,12 @@ | |||
| #include <vtkImporter.h> | ||||
| #include <vtkSmartPointer.h> | ||||
|
|
||||
| #include "../public/reader_types.h" | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| #include <algorithm> | ||||
| #include <cctype> | ||||
| #include <map> | ||||
| #include <optional> | ||||
| #include <string> | ||||
| #include <vector> | ||||
|
|
||||
|
|
@@ -66,26 +69,37 @@ class reader | |||
| /** | ||||
| * Check if this reader can read the given filename - according to its extension and file content | ||||
| */ | ||||
| virtual bool canRead(const std::string& fileName) const | ||||
| virtual bool canRead(const std::string& fileName, const std::optional<bool> skipContentCheck, | ||||
| reader_types::file_availability& availability) const | ||||
| { | ||||
| std::string ext = fileName.substr(fileName.find_last_of(".") + 1); | ||||
| std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); | ||||
|
|
||||
| const std::vector<std::string>& extensions = this->getExtensions(); | ||||
|
|
||||
| if (!std::any_of( | ||||
| if (std::any_of( | ||||
| extensions.begin(), extensions.end(), [&](const std::string& s) { return s == ext; })) | ||||
| { | ||||
| return false; | ||||
| } | ||||
|
|
||||
| vtkNew<vtkFileResourceStream> stream; | ||||
| if (!stream->Open(fileName.c_str())) | ||||
| { | ||||
| return false; | ||||
| vtkNew<vtkFileResourceStream> stream; | ||||
| if (skipContentCheck.has_value() && skipContentCheck.value() == true) | ||||
| { | ||||
| availability = reader_types::file_availability::AVAILABLE; | ||||
| return true; | ||||
| } | ||||
| else if (stream->Open(fileName.c_str())) | ||||
| { | ||||
| if (this->canRead(stream)) | ||||
| { | ||||
| availability = reader_types::file_availability::AVAILABLE; | ||||
| return true; | ||||
| } | ||||
| else | ||||
| { | ||||
| availability = reader_types::file_availability::UNSUPPORTED_CONTENT; | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
||||
| return this->canRead(stream); | ||||
| return false; | ||||
| } | ||||
|
|
||||
| /** | ||||
|
|
||||
|
Prospect138 marked this conversation as resolved.
Outdated
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #ifndef f3d_reader_types_h | ||
| #define f3d_reader_types_h | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace f3d | ||
| { | ||
| namespace reader_types | ||
| { | ||
|
|
||
| enum class file_availability : std::uint8_t | ||
| { | ||
| AVAILABLE = 1, | ||
|
Prospect138 marked this conversation as resolved.
Outdated
|
||
| UNSUPPORTED_EXSTENSION = 2, | ||
|
Prospect138 marked this conversation as resolved.
Outdated
|
||
| UNSUPPORTED_CONTENT = 3, | ||
| }; | ||
|
|
||
| } // namespace reader_types | ||
| } // namespace f3d | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -252,9 +252,12 @@ scene& scene_impl::add(const std::vector<fs::path>& filePaths) | |||||||||
| throw scene::load_failure_exception(filePath.string() + " does not exists"); | ||||||||||
| } | ||||||||||
| std::optional<std::string> forceReader = this->Internals->Options.scene.force_reader; | ||||||||||
| const std::optional<bool> skipContentCheck = this->Internals->Options.scene.skip_content_check; | ||||||||||
| // Recover the importer for the provided file path | ||||||||||
| const f3d::reader* reader = f3d::factory::instance()->getReader(filePath.string(), forceReader); | ||||||||||
| if (reader) | ||||||||||
| reader_types::file_availability availability; | ||||||||||
| const f3d::reader* reader = f3d::factory::instance()->getReader( | ||||||||||
| filePath.string(), forceReader, skipContentCheck, availability); | ||||||||||
| if (availability == reader_types::file_availability::AVAILABLE) | ||||||||||
| { | ||||||||||
| if (forceReader) | ||||||||||
| { | ||||||||||
|
|
@@ -271,9 +274,25 @@ scene& scene_impl::add(const std::vector<fs::path>& filePaths) | |||||||||
| { | ||||||||||
| throw scene::load_failure_exception(*forceReader + " is not a valid force reader"); | ||||||||||
| } | ||||||||||
| throw scene::load_failure_exception(filePath.string() + | ||||||||||
| " is not a file of a supported 3D scene file format, use force reader to force a specific " | ||||||||||
| "reader"); | ||||||||||
| std::string errorMessage; | ||||||||||
| switch (availability) | ||||||||||
| { | ||||||||||
| case reader_types::file_availability::UNSUPPORTED_EXSTENSION: | ||||||||||
| errorMessage = (filePath.string() + | ||||||||||
| " is not a file of a supported 3D scene file format, use force reader to force a " | ||||||||||
| "specific " | ||||||||||
| "reader"); | ||||||||||
|
Comment on lines
+282
to
+284
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| break; | ||||||||||
| case reader_types::file_availability::UNSUPPORTED_CONTENT: | ||||||||||
| errorMessage = (filePath.string() + | ||||||||||
| " contains unsupported content " //! todo add skip content check | ||||||||||
| "reader"); | ||||||||||
| break; | ||||||||||
| default: | ||||||||||
| errorMessage = "Something went wrong"; | ||||||||||
| break; | ||||||||||
| } | ||||||||||
| throw scene::load_failure_exception(errorMessage); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| vtkSmartPointer<vtkImporter> importer = reader->createSceneReader(filePath.string()); | ||||||||||
|
|
@@ -319,6 +338,7 @@ scene& scene_impl::add(const std::byte* buffer, std::size_t size) | |||||||||
|
|
||||||||||
| // Recover the appropriate reader | ||||||||||
| std::optional<std::string> forceReader = this->Internals->Options.scene.force_reader; | ||||||||||
| const std::optional<bool> skipContentCheck = this->Internals->Options.scene.skip_content_check; | ||||||||||
|
|
||||||||||
| #if VTK_VERSION_NUMBER < VTK_VERSION_CHECK(9, 6, 20260128) | ||||||||||
| if (!forceReader) | ||||||||||
|
|
@@ -328,7 +348,8 @@ scene& scene_impl::add(const std::byte* buffer, std::size_t size) | |||||||||
| } | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| const f3d::reader* reader = f3d::factory::instance()->getReader(buffer, size, forceReader); | ||||||||||
| const f3d::reader* reader = | ||||||||||
| f3d::factory::instance()->getReader(buffer, size, forceReader, skipContentCheck); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but how can this ever work ? How is the reader selected when there is no extension and no content check ? |
||||||||||
| if (reader) | ||||||||||
| { | ||||||||||
| if (forceReader) | ||||||||||
|
|
@@ -849,10 +870,14 @@ scene& scene_impl::removeAllLights() | |||||||||
| } | ||||||||||
|
|
||||||||||
| //---------------------------------------------------------------------------- | ||||||||||
| bool scene_impl::supports(const fs::path& filePath) | ||||||||||
| f3d::reader_types::file_availability scene_impl::supports(const fs::path& filePath) | ||||||||||
| { | ||||||||||
| return f3d::factory::instance()->getReader( | ||||||||||
| filePath.string(), this->Internals->Options.scene.force_reader) != nullptr; | ||||||||||
| f3d::reader_types::file_availability availability = | ||||||||||
| reader_types::file_availability::UNSUPPORTED_EXSTENSION; | ||||||||||
| f3d::factory::instance()->getReader(filePath.string(), | ||||||||||
| this->Internals->Options.scene.force_reader, this->Internals->Options.scene.skip_content_check, | ||||||||||
| availability) != nullptr; | ||||||||||
| return availability; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| //---------------------------------------------------------------------------- | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.