diff --git a/application/F3DOptionsTools.cxx b/application/F3DOptionsTools.cxx index d9ee14ae54..b8b1460d96 100644 --- a/application/F3DOptionsTools.cxx +++ b/application/F3DOptionsTools.cxx @@ -53,6 +53,7 @@ struct CLIGroup /** * Declaration of all F3D CLI options except `--input` using above structs * Order of groups matters in the context of `--help` + * TODO update help text for optional values */ // clang-format off #if F3D_MODULE_RAYTRACING @@ -82,7 +83,7 @@ static inline const std::array CLIOptions = {{ { "up", "", "Up direction", "{-X, +X, -Y, +Y, -Z, +Z}", "" }, { "axis", "x", "Show axes", "", "1" }, { "grid", "g", "Show grid", "", "1" }, { "grid-absolute", "", "Position grid at the absolute origin instead of below the model", "", "1" }, - { "grid-unit", "", "Size of grid unit square, set to a non-positive value for automatic computation", "", "" }, + { "grid-unit", "", "Size of grid unit square, automatically computed by default", "", "" }, { "grid-subdivisions", "", "Number of grid subdivisions", "", "" }, { "grid-color", "", "Color of main grid lines", "", "" }, { "edges", "e", "Show cell edges", "", "1" }, @@ -451,7 +452,14 @@ F3DOptionsTools::OptionsDict F3DOptionsTools::ParseCLIOptions( if (libIter != F3DOptionsTools::LibOptionsNames.end()) { f3d::options opt; - defaultValue = opt.getAsString(std::string(libIter->second)); + try + { + defaultValue = opt.getAsString(std::string(libIter->second)); + } + catch (const f3d::options::unset_exception&) + { + // let defaultValue empty for unset options + } } } diff --git a/application/F3DOptionsTools.h b/application/F3DOptionsTools.h index 2c53a227c5..9d5a5094aa 100644 --- a/application/F3DOptionsTools.h +++ b/application/F3DOptionsTools.h @@ -79,7 +79,7 @@ static inline const std::map LibOptionsNames { "animation-frame-rate", "scene.animation.frame_rate" }, { "font-file", "ui.font_file" }, { "point-sprites", "model.point_sprites.enable" }, - { "point-sprites-type", "model.point_sprites.type" }, + { "point-sprites-type", "model.point_sprites.shape" }, { "point-sprites-size", "model.point_sprites.size" }, { "point-size", "render.point_size" }, { "line-width", "render.line_width" }, diff --git a/application/main.cxx b/application/main.cxx index d1f6e1f866..cb6ada89a1 100644 --- a/application/main.cxx +++ b/application/main.cxx @@ -22,13 +22,13 @@ int main(int argc, char** argv) // exit with error when needed exit(EXIT_FAILURE); } - catch (const std::exception& ex) +/* catch (const std::exception& ex) { f3d::log::error("F3D encountered an unexpected exception:"); f3d::log::error(ex.what()); f3d::log::waitForUser(); exit(EXIT_FAILURE); - } + }*/ return res; } diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index 588551126b..f64c1903f7 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -137,9 +137,9 @@ f3d_test(NAME TestGridColor DATA suzanne.ply ARGS -g --grid-color=1,1,1) f3d_test(NAME TestAxis DATA suzanne.ply ARGS -x) f3d_test(NAME TestBackfaceVisible DATA backface.vtp ARGS --backface-type=visible) f3d_test(NAME TestBackfaceHidden DATA backface.vtp ARGS --backface-type=hidden) -f3d_test(NAME TestPointCloud DATA pointsCloud.vtp ARGS -o --point-size=20) -f3d_test(NAME TestPointCloudBar DATA pointsCloud.vtp ARGS -sob --point-size=20) -f3d_test(NAME TestPointCloudUG DATA pointsCloud.vtu ARGS -o --point-size=20) +f3d_test(NAME TestPointCloud DATA pointsCloud.vtp ARGS -o --point-sprites-size=20) +f3d_test(NAME TestPointCloudBar DATA pointsCloud.vtp ARGS -sob --point-sprites-size=20) +f3d_test(NAME TestPointCloudUG DATA pointsCloud.vtu ARGS -o --point-sprites-size=20) f3d_test(NAME TestPointCloudVolume DATA bluntfin.vts ARGS -sob) f3d_test(NAME TestPointCloudDefaultScene DATA pointsCloud.vtp ARGS --point-size=20) f3d_test(NAME Test3DSImporter DATA iflamigm.3ds ARGS --up=+Z) @@ -721,7 +721,7 @@ f3d_test(NAME TestInteractionCycleCell DATA waveletArrays.vti INTERACTION) #VCCC f3d_test(NAME TestInteractionCycleComp DATA dragon.vtu INTERACTION) #SYYYY f3d_test(NAME TestInteractionCycleScalars DATA dragon.vtu INTERACTION) #BSSSS f3d_test(NAME TestInteractionVolumeInverse DATA HeadMRVolume.mhd ARGS --camera-position=127.5,-400,127.5 --camera-view-up=0,0,1 INTERACTION) #VI -f3d_test(NAME TestInteractionPointCloud DATA pointsCloud.vtp ARGS --point-size=20 INTERACTION) #O +f3d_test(NAME TestInteractionPointCloud DATA pointsCloud.vtp ARGS --point-sprites-size=20 INTERACTION) #O f3d_test(NAME TestInteractionDirectory DATA mb INTERACTION ARGS --scalar-coloring) #Right;Right;Right;Left;Up; f3d_test(NAME TestInteractionDirectoryLoop DATA mb INTERACTION ARGS --scalar-coloring) #Left;Left;Left; f3d_test(NAME TestInteractionDirectoryEmpty DATA mb INTERACTION NO_DATA_FORCE_RENDER) #Right;Right;Right; diff --git a/library/private/options_tools.h.in b/library/private/options_tools.h.in index c4e04150f9..cf872b43d8 100644 --- a/library/private/options_tools.h.in +++ b/library/private/options_tools.h.in @@ -243,10 +243,17 @@ void set(options& opt, const std::string& name, const option_variant_t& value) */ option_variant_t get(const options& opt, const std::string& name) { - // clang-format off - ${_options_getter}; - // clang-format on - else throw options::inexistent_exception("Option " + name + " does not exist"); + try + { + // clang-format off + ${_options_getter}; + // clang-format on + else throw options::inexistent_exception("Option " + name + " does not exist"); + } + catch (const std::bad_optional_access&) + { + throw options::unset_exception("Trying to get " + name + " before it was set"); + } } //---------------------------------------------------------------------------- @@ -277,10 +284,17 @@ void setAsString(options& opt, const std::string& name, const std::string& str) */ std::string getAsString(const options& opt, const std::string& name) { - // clang-format off - ${_options_string_getter}; - // clang-format on - else throw options::inexistent_exception("Option " + name + " does not exist"); + try + { + // clang-format off + ${_options_string_getter}; + // clang-format on + else throw options::inexistent_exception("Option " + name + " does not exist"); + } + catch (const std::bad_optional_access&) + { + throw options::unset_exception("Trying to get " + name + " before it was set"); + } } } // option_tools } // f3d diff --git a/library/public/options.h.in b/library/public/options.h.in index 30a91e2c74..fe2899e591 100644 --- a/library/public/options.h.in +++ b/library/public/options.h.in @@ -57,6 +57,7 @@ public: /** * Get an option as a variant based on its name * Throw an options::inexistent_exception if option does not exist. + * Throw an options::unset_exception if option has not been set. */ option_variant_t get(const std::string& name) const; #endif @@ -73,6 +74,7 @@ public: /** * Get an option as a string based on its name * Throw an options::inexistent_exception if option does not exist. + * Throw an options::unset_exception if option has not been set. */ std::string getAsString(const std::string& name) const; @@ -80,6 +82,7 @@ public: * A boolean option specific method to toggle it. * Throw an options::inexistent_exception if option does not exist. * Throw an options::incompatible_exception if option is not boolean. + * Throw an options::unset_exception if option has not been set. */ options& toggle(const std::string& name); @@ -145,6 +148,15 @@ public: explicit inexistent_exception(const std::string& what = ""); }; + /** + * An exception that can be thrown by the options + * when a provided option is accessed before being set. + */ + struct unset_exception : public exception + { + explicit unset_exception(const std::string& what = ""); + }; + #ifndef F3D_DISABLE_CXX17_API /** * The complete generated options struct diff --git a/library/src/animationManager.cxx b/library/src/animationManager.cxx index 40ff19bff6..50551da70a 100644 --- a/library/src/animationManager.cxx +++ b/library/src/animationManager.cxx @@ -65,7 +65,7 @@ bool animationManager::Initialize( { log::warn("An animation index has been specified but there are no animation available."); } - if (options->scene.animation.time != 0) + if (options->scene.animation.time.has_value()) { log::warn("No animation available, cannot load a specific animation time"); } diff --git a/library/src/options.cxx b/library/src/options.cxx index cb07fe7c81..58090f4aac 100644 --- a/library/src/options.cxx +++ b/library/src/options.cxx @@ -66,7 +66,30 @@ options& options::toggle(const std::string& name) //---------------------------------------------------------------------------- bool options::isSame(const options& other, const std::string& name) const { - return options_tools::get(*this, name) == options_tools::get(other, name); + option_variant_t ownVal; + option_variant_t otherVal; + bool ownUnset = false; + bool otherUnset = false; + + try + { + ownVal = options_tools::get(*this, name); + } + catch (const f3d::options::unset_exception&) + { + ownUnset = true; + } + + try + { + otherVal = options_tools::get(other, name); + } + catch (const f3d::options::unset_exception&) + { + otherUnset = true; + } + + return ownUnset == otherUnset && ownVal == otherVal; } //---------------------------------------------------------------------------- @@ -141,4 +164,10 @@ options::inexistent_exception::inexistent_exception(const std::string& what) : exception(what) { } + +//---------------------------------------------------------------------------- +options::unset_exception::unset_exception(const std::string& what) + : exception(what) +{ +} } diff --git a/vtkext/private/module/vtkF3DRendererWithColoring.cxx b/vtkext/private/module/vtkF3DRendererWithColoring.cxx index 8710bc30c4..6d9847dfe7 100644 --- a/vtkext/private/module/vtkF3DRendererWithColoring.cxx +++ b/vtkext/private/module/vtkF3DRendererWithColoring.cxx @@ -253,7 +253,7 @@ void vtkF3DRendererWithColoring::ConfigureColoringActorsProperties() //---------------------------------------------------------------------------- void vtkF3DRendererWithColoring::SetPointSpritesProperties(SplatType type, double pointSpritesSize) { -// this->SetPointSize(pointSize); TODO +// this->SetPointSize(pointSpritesSize); TODO if (!this->Importer) {