From ae42c7e93ceb60605b3e9208bc8d714a995a3854 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Wed, 4 Dec 2024 15:20:55 +0100 Subject: [PATCH 1/6] [workflow][Nix] initial packaging & flake (#5059) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Nix] initial packaging & flake * [Nix] setup CI * [CMake] FindQGLViewer: fix include dir computation we use `#include `, so `QGLViewer_INCLUDE_DIR` must not include `QGLViewer` component. Also, on darwin, headers are installed in Headers dir, not include, ref: https://github.com/GillesDebunne/libQGLViewer/blob/ba9a875784afbb7ee73088fe0e8701c31bc7277d/QGLViewer/QGLViewer.pro#L138 * [Nix] fix build on macos This require fixes in upstream nixpkgs: https://github.com/NixOS/nixpkgs/pull/348549 So we can use the source of that PR for now * [CMake] FindQGLViewer: fix for Qt6 ref. https://github.com/GillesDebunne/libQGLViewer/blob/ba9a875784afbb7ee73088fe0e8701c31bc7277d/QGLViewer/QGLViewer.pro#L176 * [Nix] Qt5 -> Qt6 * [CMake] fix typo for Qt6 * [CMake] fix SOFA_GUI_QT_HAVE_QT6 definition without this, `lib/cmake/Sofa.GUI.Qt/Sofa.GUI.QtConfig.cmake` has: > `set(SOFA_GUI_QT_HAVE_QT6 0)` and therefore, in SofaPython3, `find_package(QGLViewer QUIET REQUIRED)` is not called, and build ends up with: > [ 98%] Linking CXX shared library ../../lib/python3/site-packages/Sofa/Gui.cpython-312-x86_64-linux-gnu.so > […]/ld: cannot find -lQGLViewer: No such file or directory * [Nix] fixup lib path on Darwin TODO: This should be fixed in CMake instead, but I have no clue. error was: > dyld[61665]: Library not loaded: /nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/lib/libSceneChecking.24.12.99.dylib > Referenced from: <8B75C775-7FE5-3755-A190-B11A3F4F6666> /nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/bin/.runSofa-24.12.99-wrapped > Reason: tried: '/nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/lib/libSceneChecking.24.12.99.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/lib/libSceneChecking.24.12.99.dylib' (no such file), '/nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/lib/libSceneChecking.24.12.99.dylib' (no such file), '/usr/local/lib/libSceneChecking.24.12.99.dylib' (no such file), '/usr/lib/libSceneChecking.24.12.99.dylib' (no such file, not in dyld cache) > zsh: abort ./result/bin/runSofa * [Nix] CI on macos too * nix: add nixGL * [Nix] fix package description Co-authored-by: Hugo * Apply suggestions from code review --------- Co-authored-by: Hugo --- .github/workflows/nix.yml | 21 ++++++ Sofa/GUI/Qt/CMakeLists.txt | 7 +- cmake/Modules/FindQGLViewer.cmake | 6 +- flake.lock | 108 ++++++++++++++++++++++++++++++ flake.nix | 37 ++++++++++ package.nix | 82 +++++++++++++++++++++++ 6 files changed, 256 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/nix.yml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 00000000000..a1bff8fcec3 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,21 @@ +name: "CI - Nix" + +on: + push: + +jobs: + nix: + runs-on: "${{ matrix.os }}-latest" + if: ${{ github.repository_owner == 'sofa-framework' }} + strategy: + matrix: + os: [ubuntu, macos] + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + # TODO: the "sofa" account on cachix does not exist yet + #- uses: cachix/cachix-action@v15 + #with: + #name: sofa + #authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix build -L diff --git a/Sofa/GUI/Qt/CMakeLists.txt b/Sofa/GUI/Qt/CMakeLists.txt index 2989ce4279f..85ebe4e49ee 100644 --- a/Sofa/GUI/Qt/CMakeLists.txt +++ b/Sofa/GUI/Qt/CMakeLists.txt @@ -24,8 +24,11 @@ endif() if (Qt6Core_FOUND) message("${PROJECT_NAME}: will use Qt6") - sofa_find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets REQUIRED) - set(SOFA_GUI_QT_TARETS ${SOFA_GUI_QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets ) + find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets REQUIRED) + # GuiTools & WidgetsTools does not define a Qt6::component CMake target + # So we can't look for those target to know how we should define SOFA_GUI_QT_HAVE_QT6 + sofa_find_package(Qt6 COMPONENTS Gui Widgets OpenGLWidgets REQUIRED) + set(SOFA_GUI_QT_TARGETS ${SOFA_GUI_QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets ) elseif (Qt5Core_FOUND) message("${PROJECT_NAME}: will use Qt5 (deprecated)") sofa_find_package(Qt5 COMPONENTS Core Gui OpenGL REQUIRED) diff --git a/cmake/Modules/FindQGLViewer.cmake b/cmake/Modules/FindQGLViewer.cmake index ae6fe0d2091..65eb618dfff 100644 --- a/cmake/Modules/FindQGLViewer.cmake +++ b/cmake/Modules/FindQGLViewer.cmake @@ -14,14 +14,14 @@ if(NOT TARGET QGLViewer) if(NOT QGLViewer_INCLUDE_DIR) find_path(QGLViewer_INCLUDE_DIR - NAMES qglviewer.h - PATH_SUFFIXES include/QGLViewer + NAMES QGLViewer/qglviewer.h + PATH_SUFFIXES include Headers ) endif() if(NOT QGLViewer_LIBRARY) find_library(QGLViewer_LIBRARY - NAMES QGLViewer QGLViewer2 QGLViewer-qt5 + NAMES QGLViewer QGLViewer2 QGLViewer-qt5 QGLViewer-qt6 PATH_SUFFIXES lib ) endif() diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..26492ec359a --- /dev/null +++ b/flake.lock @@ -0,0 +1,108 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixgl": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1713543440, + "narHash": "sha256-lnzZQYG0+EXl/6NkGpyIz+FEOc/DSEG57AP1VsdeNrM=", + "owner": "nix-community", + "repo": "nixGL", + "rev": "310f8e49a149e4c9ea52f1adf70cdc768ec53f8a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixGL", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1660551188, + "narHash": "sha256-a1LARMMYQ8DPx1BgoI/UN4bXe12hhZkCNqdxNi6uS0g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "441dc5d512153039f19ef198e662e4f3dbb9fd65", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1728930054, + "narHash": "sha256-mCaSyViQyiLgZKVLpDcVacbPSNjvsBzfWnGaxvhTzs8=", + "owner": "nim65s", + "repo": "nixpkgs", + "rev": "8e906b3e2aa2274c9d0c555393b4801d3c0badee", + "type": "github" + }, + "original": { + "owner": "nim65s", + "ref": "qt6-libqglviewer", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixgl": "nixgl", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..054afca0134 --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +{ + description = "SOFA is an open-source framework for interactive physics simulation, with emphasis on biomechanical and robotic simulations"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + #nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + # ref. https://github.com/NixOS/nixpkgs/pull/348549 + nixpkgs.url = "github:nim65s/nixpkgs/qt6-libqglviewer"; + nixgl.url = "github:nix-community/nixGL"; + }; + + outputs = + inputs@{ flake-parts, nixgl, nixpkgs, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + perSystem = + { pkgs, self', system, ... }: + { + _module.args.pkgs = import nixpkgs { + inherit system; + overlays = [ nixgl.overlay ]; + }; + apps.nixgl = { + type = "app"; + program = pkgs.writeShellApplication { + name = "nixgl-sofa"; + text = "${pkgs.lib.getExe pkgs.nixgl.auto.nixGLDefault} ${pkgs.lib.getExe self'.packages.sofa}"; + }; + }; + devShells.default = pkgs.mkShell { inputsFrom = [ self'.packages.default ]; }; + packages = { + default = self'.packages.sofa; + sofa = pkgs.callPackage ./package.nix { }; + }; + }; + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 00000000000..1b879c51d14 --- /dev/null +++ b/package.nix @@ -0,0 +1,82 @@ +{ + boost, + cmake, + cxxopts, + eigen, + #fetchFromGitHub, + glew, + gtest, + lib, + qt6Packages, + libGL, + metis, + stdenv, + tinyxml-2, + zlib, +}: + +stdenv.mkDerivation { + pname = "sofa"; + version = "24.06.00"; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./applications + ./Authors.txt + ./cmake + ./CHANGELOG.md + ./CMakeLists.txt + ./CMakePresets.json + ./examples + ./extlibs + ./LICENSE-LGPL.md + ./package.cmake + ./README.md + ./scripts + ./share + ./Sofa + ./tools + ]; + }; + + propagatedNativeBuildInputs = [ + cmake + qt6Packages.wrapQtAppsHook + ]; + propagatedBuildInputs = [ + boost + cxxopts + eigen + glew + gtest + qt6Packages.libqglviewer + qt6Packages.qtbase + libGL + metis + tinyxml-2 + zlib + ]; + + cmakeFlags = [ + (lib.cmakeBool "SOFA_ALLOW_FETCH_DEPENDENCIES" false) + ]; + + doCheck = true; + + postFixup = lib.optionalString stdenv.hostPlatform.isDarwin '' + install_name_tool -change \ + $out/lib/libSceneChecking.24.12.99.dylib \ + $out/plugins/SceneChecking/lib/libSceneChecking.24.12.99.dylib \ + $out/bin/.runSofa-24.12.99-wrapped + ''; + + meta = { + description = "SOFA is an open-source framework for interactive physics simulation, with emphasis on biomechanical and robotic simulations"; + homepage = "https://github.com/sofa-framework/sofa"; + license = lib.licenses.lgpl21Only; + maintainers = with lib.maintainers; [ nim65s ]; + mainProgram = "runSofa"; + platforms = lib.platforms.unix ++ lib.platforms.windows; + }; +} From 71076be65aad8d360efe8ead45d3f457ea1e448e Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Wed, 4 Dec 2024 15:26:54 +0100 Subject: [PATCH 2/6] [Helper] A static alternative to OptionsGroup: SelectableItem (#5062) * [Helper] A static alternative to OptionsGroup: SelectableItem * include map * missing include * add unit tests for a common type string * A type info for SelectableItem * fix compilation * second fix * fix setSelectedId * Support SelectableItem in Qt * add Style and Alignment description * cleaning --- .../model/SlidingLagrangianConstraint.h | 2 +- .../solver/GenericConstraintSolver.cpp | 30 +- .../solver/GenericConstraintSolver.h | 10 +- .../component/rendering3d/OglSceneFrame.cpp | 35 +- .../gl/component/rendering3d/OglSceneFrame.h | 21 +- Sofa/GUI/Qt/src/sofa/gui/qt/DataWidget.h | 41 ++- .../Qt/src/sofa/gui/qt/SimpleDataWidget.cpp | 116 +++++++ .../GUI/Qt/src/sofa/gui/qt/SimpleDataWidget.h | 25 +- .../core/objectmodel/BaseClassNameHelper.h | 6 +- Sofa/framework/DefaultType/CMakeLists.txt | 1 + .../src/sofa/defaulttype/DataTypeInfo.h | 1 + .../sofa/defaulttype/typeinfo/DataTypeInfo.h | 4 +- .../typeinfo/TypeInfo_SelectableItem.h | 50 +++ Sofa/framework/Helper/CMakeLists.txt | 1 + .../Helper/src/sofa/helper/SelectableItem.h | 328 ++++++++++++++++++ Sofa/framework/Helper/test/CMakeLists.txt | 1 + .../Helper/test/OptionsGroup_test.cpp | 7 + .../Helper/test/SelectableItem_test.cpp | 214 ++++++++++++ 18 files changed, 842 insertions(+), 51 deletions(-) create mode 100644 Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/TypeInfo_SelectableItem.h create mode 100644 Sofa/framework/Helper/src/sofa/helper/SelectableItem.h create mode 100644 Sofa/framework/Helper/test/SelectableItem_test.cpp diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.h b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.h index 2aec761548d..4c9e9aa5c9c 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.h +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/SlidingLagrangianConstraint.h @@ -66,7 +66,7 @@ class SlidingLagrangianConstraint : public core::behavior::PairInteractionConstr SlidingLagrangianConstraint(MechanicalState* object); SlidingLagrangianConstraint(MechanicalState* object1, MechanicalState* object2); - virtual ~SlidingLagrangianConstraint(){} + ~SlidingLagrangianConstraint() override {} diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp index cf3d4e1a770..e33cbaa1b0b 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp @@ -60,8 +60,10 @@ void clearMultiVecId(sofa::core::objectmodel::BaseContext* ctx, const sofa::core } +static constexpr GenericConstraintSolver::ResolutionMethod defaultResolutionMethod("ProjectedGaussSeidel"); + GenericConstraintSolver::GenericConstraintSolver() - : d_resolutionMethod( initData(&d_resolutionMethod, "resolutionMethod", "Method used to solve the constraint problem, among: \"ProjectedGaussSeidel\", \"UnbuiltGaussSeidel\" or \"for NonsmoothNonlinearConjugateGradient\"")) + : d_resolutionMethod( initData(&d_resolutionMethod, defaultResolutionMethod, "resolutionMethod", ("Method used to solve the constraint problem\n" + ResolutionMethod::dataDescription()).c_str())) , d_maxIt(initData(&d_maxIt, 1000, "maxIterations", "maximal number of iterations of the Gauss-Seidel algorithm")) , d_tolerance(initData(&d_tolerance, 0.001_sreal, "tolerance", "residual error threshold for termination of the Gauss-Seidel algorithm")) , d_sor(initData(&d_sor, 1.0_sreal, "sor", "Successive Over Relaxation parameter (0-2)")) @@ -86,10 +88,6 @@ GenericConstraintSolver::GenericConstraintSolver() , current_cp(&m_cpBuffer[0]) , last_cp(nullptr) { - sofa::helper::OptionsGroup m_newoptiongroup{"ProjectedGaussSeidel","UnbuiltGaussSeidel", "NonsmoothNonlinearConjugateGradient"}; - m_newoptiongroup.setSelectedItem("ProjectedGaussSeidel"); - d_resolutionMethod.setValue(m_newoptiongroup); - addAlias(&d_maxIt, "maxIt"); d_graphErrors.setWidget("graph"); @@ -159,7 +157,8 @@ void GenericConstraintSolver::init() if(d_newtonIterations.isSet()) { - if (d_resolutionMethod.getValue().getSelectedId() != 2) + static constexpr ResolutionMethod NonsmoothNonlinearConjugateGradient("NonsmoothNonlinearConjugateGradient"); + if (d_resolutionMethod.getValue() != NonsmoothNonlinearConjugateGradient) { msg_warning() << "data \"newtonIterations\" is not only taken into account when using the NonsmoothNonlinearConjugateGradient solver"; } @@ -225,15 +224,15 @@ bool GenericConstraintSolver::buildSystem(const core::ConstraintParams *cParams, } // Resolution depending on the method selected - switch ( d_resolutionMethod.getValue().getSelectedId() ) + switch ( d_resolutionMethod.getValue() ) { - case 0: // ProjectedGaussSeidel - case 2: // NonsmoothNonlinearConjugateGradient + case ResolutionMethod("ProjectedGaussSeidel"): + case ResolutionMethod("NonsmoothNonlinearConjugateGradient"): { buildSystem_matrixAssembly(cParams); break; } - case 1: // UnbuiltGaussSeidel + case ResolutionMethod("UnbuiltGaussSeidel"): { buildSystem_matrixFree(numConstraints); break; @@ -429,10 +428,9 @@ bool GenericConstraintSolver::solveSystem(const core::ConstraintParams * /*cPara // Resolution depending on the method selected - switch ( d_resolutionMethod.getValue().getSelectedId() ) + switch ( d_resolutionMethod.getValue()) { - // ProjectedGaussSeidel - case 0: { + case ResolutionMethod("ProjectedGaussSeidel"): { if (notMuted()) { std::stringstream tmp; @@ -445,14 +443,12 @@ bool GenericConstraintSolver::solveSystem(const core::ConstraintParams * /*cPara current_cp->gaussSeidel(0, this); break; } - // UnbuiltGaussSeidel - case 1: { + case ResolutionMethod("UnbuiltGaussSeidel"): { SCOPED_TIMER_VARNAME(unbuiltGaussSeidelTimer, "ConstraintsUnbuiltGaussSeidel"); current_cp->unbuiltGaussSeidel(0, this); break; } - // NonsmoothNonlinearConjugateGradient - case 2: { + case ResolutionMethod("NonsmoothNonlinearConjugateGradient"): { current_cp->NNCG(this, d_newtonIterations.getValue()); break; } diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h index 7d752048930..cd3c770fd97 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h @@ -33,6 +33,8 @@ #include #include +#include + namespace sofa::component::constraint::lagrangian::solver { @@ -60,7 +62,13 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API GenericConstraintSolver : ConstraintProblem* getConstraintProblem() override; void lockConstraintProblem(sofa::core::objectmodel::BaseObject* from, ConstraintProblem* p1, ConstraintProblem* p2 = nullptr) override; - Data< sofa::helper::OptionsGroup > d_resolutionMethod; ///< Method used to solve the constraint problem, among: "ProjectedGaussSeidel", "UnbuiltGaussSeidel" or "for NonsmoothNonlinearConjugateGradient" + MAKE_SELECTABLE_ITEMS(ResolutionMethod, + sofa::helper::Item{"ProjectedGaussSeidel", "Projected Gauss-Seidel"}, + sofa::helper::Item{"UnbuiltGaussSeidel", "Gauss-Seidel where the matrix is not assembled"}, + sofa::helper::Item{"NonsmoothNonlinearConjugateGradient", "Non-smooth non-linear conjugate gradient"} + ); + + Data< ResolutionMethod > d_resolutionMethod; ///< Method used to solve the constraint problem, among: "ProjectedGaussSeidel", "UnbuiltGaussSeidel" or "for NonsmoothNonlinearConjugateGradient" SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_CONSTRAINT_LAGRANGIAN_SOLVER() sofa::core::objectmodel::RenamedData maxIt; diff --git a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.cpp b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.cpp index 41d46622f1a..f2bba6ceb04 100644 --- a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.cpp +++ b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.cpp @@ -32,20 +32,15 @@ int OglSceneFrameClass = core::RegisterObject("Display a frame at the corner of using namespace sofa::defaulttype; +static constexpr OglSceneFrame::Alignment defaultAlignment("BottomRight"); +static constexpr OglSceneFrame::Style defaultStyle("Cylinders"); + OglSceneFrame::OglSceneFrame() : d_drawFrame(initData(&d_drawFrame, true, "draw", "Display the frame or not")) - , d_style(initData(&d_style, "style", "Style of the frame")) - , d_alignment(initData(&d_alignment, "alignment", "Alignment of the frame in the view")) + , d_style(initData(&d_style, defaultStyle, "style", ("Style of the frame\n" + Style::dataDescription()).c_str())) + , d_alignment(initData(&d_alignment, defaultAlignment, "alignment", ("Alignment of the frame in the view\n" + Alignment::dataDescription()).c_str())) , d_viewportSize(initData(&d_viewportSize, 150, "viewportSize", "Size of the viewport where the frame is rendered")) -{ - sofa::helper::OptionsGroup styleOptions{"Arrows", "Cylinders", "CubeCones"}; - styleOptions.setSelectedItem(1); - d_style.setValue(styleOptions); - - sofa::helper::OptionsGroup alignmentOptions{"BottomLeft", "BottomRight", "TopRight", "TopLeft"}; - alignmentOptions.setSelectedItem(1); - d_alignment.setValue(alignmentOptions); -} +{} void OglSceneFrame::drawArrows(const core::visual::VisualParams* vparams) { @@ -112,22 +107,22 @@ void OglSceneFrame::doDrawVisual(const core::visual::VisualParams* vparams) const auto viewportSize = d_viewportSize.getValue(); - switch(d_alignment.getValue().getSelectedId()) + switch(d_alignment.getValue()) { - case 0: //BottomLeft + case Alignment("BottomLeft"): default: glViewport(0,0,viewportSize,viewportSize); glScissor(0,0,viewportSize,viewportSize); break; - case 1: //BottomRight + case Alignment("BottomRight"): glViewport(viewport[2]-viewportSize,0,viewportSize,viewportSize); glScissor(viewport[2]-viewportSize,0,viewportSize,viewportSize); break; - case 2: //TopRight + case Alignment("TopRight"): glViewport(viewport[2]-viewportSize,viewport[3]-viewportSize,viewportSize,viewportSize); glScissor(viewport[2]-viewportSize,viewport[3]-viewportSize,viewportSize,viewportSize); break; - case 3: //TopLeft + case Alignment("TopLeft"): glViewport(0,viewport[3]-viewportSize,viewportSize,viewportSize); glScissor(0,viewport[3]-viewportSize,viewportSize,viewportSize); break; @@ -157,18 +152,18 @@ void OglSceneFrame::doDrawVisual(const core::visual::VisualParams* vparams) vparams->drawTool()->disableLighting(); - switch (d_style.getValue().getSelectedId()) + switch (d_style.getValue()) { - case 0: + case Style("Arrows"): default: drawArrows(vparams); break; - case 1: + case Style("Cylinders"): drawCylinders(vparams); break; - case 2: + case Style("CubeCones"): drawCubeCones(vparams); break; } diff --git a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.h b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.h index c6cdd2288bb..d834c9584d1 100644 --- a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.h +++ b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglSceneFrame.h @@ -25,6 +25,8 @@ #include #include #include +#include + namespace sofa::gl::component::rendering3d { @@ -38,8 +40,23 @@ class SOFA_GL_COMPONENT_RENDERING3D_API OglSceneFrame : public core::visual::Vis typedef core::visual::VisualParams::Viewport Viewport; Data d_drawFrame; ///< Display the frame or not - Data d_style; ///< Style of the frame - Data d_alignment; ///< Alignment of the frame in the view + + MAKE_SELECTABLE_ITEMS(Style, + sofa::helper::Item{"Arrows", "The frame is composed of arrows"}, + sofa::helper::Item{"Cylinders", "The frame is composed of cylinders"}, + sofa::helper::Item{"CubeCones", "The frame is composed of cubes and cones"}, + ); + + Data