Skip to content

Commit

Permalink
[SofaMatrix] Put Qt dependent code into an extension (#5234)
Browse files Browse the repository at this point in the history
* Put Qt related object fro mSofaMatrix into extensions folder

* Fix scene test

* Update applications/plugins/SofaMatrix/examples/FillReducingOrdering.scn

Co-authored-by: Frederick Roy <[email protected]>

---------

Co-authored-by: Frederick Roy <[email protected]>
  • Loading branch information
bakpaul and fredroy authored Jan 23, 2025
1 parent bb821d3 commit 66b9fd0
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 62 deletions.
35 changes: 3 additions & 32 deletions applications/plugins/SofaMatrix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ sofa_find_package(Sofa.Core REQUIRED)
sofa_find_package(Sofa.Component.Constraint.Lagrangian.Solver REQUIRED)
sofa_find_package(Sofa.Component.LinearSolver.Direct REQUIRED)
sofa_find_package(Eigen3 REQUIRED)
sofa_find_package(Sofa.GUI.Qt QUIET)

find_package(metis 5.1.0 EXACT QUIET)
if(NOT metis_FOUND AND SOFA_ALLOW_FETCH_DEPENDENCIES)
Expand Down Expand Up @@ -54,37 +53,6 @@ set(MOC_FILES
set(MOC_HEADER_FILES
)

if (NOT Sofa.GUI.Qt_FOUND)
message(NOTICE "[SofaMatrix] Module Sofa.GUI.Qt not found: some components (GlobalSystemMatrixImage) will not be compiled")
else()
list(APPEND HEADER_FILES
${SOFAMATRIX_SRC_DIR}/ComplianceMatrixImage.h
${SOFAMATRIX_SRC_DIR}/GlobalSystemMatrixImage.h
${SOFAMATRIX_SRC_DIR}/BaseMatrixImageProxy.h
)
list(APPEND SOURCE_FILES
${SOFAMATRIX_SRC_DIR}/ComplianceMatrixImage.cpp
${SOFAMATRIX_SRC_DIR}/GlobalSystemMatrixImage.cpp
${SOFAMATRIX_SRC_DIR}/BaseMatrixImageViewerWidget.cpp
)
list(APPEND MOC_HEADER_FILES
${SOFAMATRIX_SRC_DIR}/BaseMatrixImageViewerWidget.h
)
list(APPEND SOFA_MODULES
Sofa.GUI.Qt
)

find_package(Qt6 COMPONENTS Core CoreTools QUIET)
if (NOT Qt6Core_FOUND)
find_package(Qt5 COMPONENTS Core QUIET)
endif()
if(Qt5Core_FOUND)
qt5_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES})
elseif (Qt6Core_FOUND)
qt6_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES})
endif()
endif()

# Create the plugin library.
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES} ${MOC_HEADER_FILES} ${MOC_FILES})

Expand All @@ -101,6 +69,9 @@ sofa_create_package_with_targets(
RELOCATABLE "plugins"
)

sofa_add_subdirectory(plugin extensions/Qt SofaMatrix.Qt)


# Tests
# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
# cmake_dependent_option(SOFAMATRIX_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
Expand Down
13 changes: 0 additions & 13 deletions applications/plugins/SofaMatrix/SofaMatrixConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,12 @@
@PACKAGE_GUARD@
@PACKAGE_INIT@

set(SOFAMATRIX_HAVE_SOFA_GUI_QT @SOFAMATRIX_HAVE_SOFA_GUI_QT@)
set(SOFAMATRIX_HAVE_QT5CORE @SOFAMATRIX_HAVE_QT5CORE@)
set(SOFAMATRIX_HAVE_QT6CORE @SOFAMATRIX_HAVE_QT6CORE@)

find_package(Sofa.Core QUIET REQUIRED)
find_package(Sofa.Component.Constraint.Lagrangian.Solver QUIET REQUIRED)
find_package(Sofa.Component.LinearSolver.Direct QUIET REQUIRED)
find_package(Eigen3 QUIET REQUIRED)

if(SOFAMATRIX_HAVE_SOFA_GUI_QT )
find_package(Sofa.GUI.Qt QUIET REQUIRED)
endif()
if(SOFAMATRIX_HAVE_QT5CORE)
find_package(Qt5 COMPONENTS Core QUIET REQUIRED)
endif()
if(SOFAMATRIX_HAVE_QT6CORE)
find_package(Qt6 COMPONENTS Core CoreTools QUIET)
endif()

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [EdgeSetGeometryAlgorithms EdgeSetTopologyContainer] -->
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] -->
<RequiredPlugin name="SofaMatrix"/> <!-- Needed to use components [ComplianceMatrixImage] -->
<RequiredPlugin name="SofaMatrix.Qt"/> <!-- Needed to use components [ComplianceMatrixImage] -->

<VisualStyle displayFlags="hideVisualModels showBehaviorModels showMappings showForceFields" />
<FreeMotionAnimationLoop solveVelocityConstraintFirst="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ The scene compares two simulations in which only the vertices order differs:
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [TetrahedronSetGeometryAlgorithms TetrahedronSetTopologyContainer] -->
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] -->
<RequiredPlugin name="Sofa.GL.Component.Rendering2D"/> <!-- Needed to use components [OglLabel] -->
<RequiredPlugin name="SofaMatrix"/> <!-- Needed to use components [FillReducingOrdering GlobalSystemMatrixImage] -->
<RequiredPlugin name="SofaMatrix"/> <!-- Needed to use components [FillReducingOrdering] -->
<RequiredPlugin name="SofaMatrix.Qt"/> <!-- Needed to use components [GlobalSystemMatrixImage] -->

<VisualStyle displayFlags="showForceFields hideVisualModels showBehaviorModels" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
<RequiredPlugin name="Sofa.Component.Topology.Container.Grid"/> <!-- Needed to use components [RegularGridTopology] -->
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] -->
<RequiredPlugin name="SofaMatrix"/> <!-- Needed to use components [GlobalSystemMatrixImage] -->
<RequiredPlugin name="SofaMatrix.Qt"/> <!-- Needed to use components [GlobalSystemMatrixImage] -->

<VisualStyle displayFlags="showBehaviorModels showForceFields" />

Expand Down
75 changes: 75 additions & 0 deletions applications/plugins/SofaMatrix/extensions/Qt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
cmake_minimum_required(VERSION 3.22)
project(SofaMatrix.Qt VERSION 1.0 LANGUAGES CXX)

sofa_find_package(Sofa.Core REQUIRED)
sofa_find_package(Sofa.Component.Constraint.Lagrangian.Solver REQUIRED)
sofa_find_package(Sofa.Component.LinearSolver.Direct REQUIRED)
sofa_find_package(Eigen3 REQUIRED)
sofa_find_package(Sofa.GUI.Qt REQUIRED)

set(SOFA_MODULES
Sofa.Component.Constraint.Lagrangian.Solver
Sofa.Component.LinearSolver.Direct
Sofa.Core
Eigen3::Eigen
Sofa.GUI.Qt
SofaMatrix
)

set(SOFAMATRIX_SRC_DIR src/SofaMatrix/Qt)

set(HEADER_FILES
${SOFAMATRIX_SRC_DIR}/config.h.in
${SOFAMATRIX_SRC_DIR}/ComplianceMatrixImage.h
${SOFAMATRIX_SRC_DIR}/GlobalSystemMatrixImage.h
${SOFAMATRIX_SRC_DIR}/BaseMatrixImageProxy.h
)

set(SOURCE_FILES
${SOFAMATRIX_SRC_DIR}/ComplianceMatrixImage.cpp
${SOFAMATRIX_SRC_DIR}/GlobalSystemMatrixImage.cpp
${SOFAMATRIX_SRC_DIR}/BaseMatrixImageViewerWidget.cpp
${SOFAMATRIX_SRC_DIR}/initSofaMatrixQt.cpp
)

set(MOC_FILES
)

set(MOC_HEADER_FILES
${SOFAMATRIX_SRC_DIR}/BaseMatrixImageViewerWidget.h
)

find_package(Qt6 COMPONENTS Core CoreTools QUIET)
if (NOT Qt6Core_FOUND)
find_package(Qt5 COMPONENTS Core QUIET)
endif()
if(Qt5Core_FOUND)
qt5_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES})
set(SOFAMATRIX_HAVE_QT5 1)
elseif (Qt6Core_FOUND)
qt6_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES})
set(SOFAMATRIX_HAVE_QT6 1)
endif()

# Create the plugin library.
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${MOC_HEADER_FILES} ${MOC_FILES})

# Link the plugin library to its dependency(ies).
target_link_libraries(${PROJECT_NAME} PUBLIC ${SOFA_MODULES})

sofa_create_package_with_targets(
PACKAGE_NAME ${PROJECT_NAME}
PACKAGE_VERSION ${PROJECT_VERSION}
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
INCLUDE_SOURCE_DIR "src"
INCLUDE_INSTALL_DIR ${PROJECT_NAME}
RELOCATABLE "plugins"
)

# Tests
# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
# cmake_dependent_option(SOFAMATRIX_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
#if(SOFAMATRIX_BUILD_TESTS)
# enable_testing()
# add_subdirectory(SofaMatrix_test)
# endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# CMake package configuration file for the plugin @PROJECT_NAME@

@PACKAGE_GUARD@
@PACKAGE_INIT@



set(SOFAMATRIX_QT_HAVE_QT5 @SOFAMATRIX_HAVE_QT5@)
set(SOFAMATRIX_QT_HAVE_QT6 @SOFAMATRIX_HAVE_QT6@)

find_package(Sofa.Core QUIET REQUIRED)
find_package(Sofa.Component.Constraint.Lagrangian.Solver QUIET REQUIRED)
find_package(Sofa.Component.LinearSolver.Direct QUIET REQUIRED)
find_package(Eigen3 QUIET REQUIRED)
find_package(Sofa.GUI.Qt QUIET REQUIRED)
find_package(SofaMatrix QUIET REQUIRED)

if(SOFAMATRIX_QT_HAVE_QT5)
find_package(Qt5 COMPONENTS Core QUIET REQUIRED)
endif()
if(SOFAMATRIX_QT_HAVE_QT6)
find_package(Qt6 COMPONENTS Core CoreTools QUIET)
endif()

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
endif()

check_required_components(@PROJECT_NAME@)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Contact information: [email protected] *
******************************************************************************/
#pragma once
#include <SofaMatrix/config.h>
#include <SofaMatrix/Qt/config.h>
#include <sofa/linearalgebra/BaseMatrix.h>

namespace sofa::type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *
* Contact information: [email protected] *
******************************************************************************/
#include <SofaMatrix/BaseMatrixImageViewerWidget.h>
#include <SofaMatrix/Qt/BaseMatrixImageViewerWidget.h>

namespace sofa::gui::qt
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
* Contact information: [email protected] *
******************************************************************************/
#pragma once
#include <SofaMatrix/config.h>
#include <SofaMatrix/Qt/config.h>

#include <QGraphicsView>
#include <sofa/gui/qt/SimpleDataWidget.h>

#include <SofaMatrix/BaseMatrixImageProxy.h>
#include <SofaMatrix/Qt/BaseMatrixImageProxy.h>

namespace sofa::gui::qt
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *
* Contact information: [email protected] *
******************************************************************************/
#include <SofaMatrix/ComplianceMatrixImage.h>
#include <SofaMatrix/Qt/ComplianceMatrixImage.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/simulation/AnimateEndEvent.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* Contact information: [email protected] *
******************************************************************************/
#pragma once
#include <SofaMatrix/config.h>
#include <SofaMatrix/Qt/config.h>

#include <sofa/core/objectmodel/BaseObject.h>
#include <SofaMatrix/BaseMatrixImageProxy.h>
#include <SofaMatrix/Qt/BaseMatrixImageProxy.h>
#include <sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.h>

namespace sofa::component::constraintset
Expand All @@ -35,7 +35,7 @@ namespace sofa::component::constraintset
*
* Note that the compliance matrix is dense. It means all the entries will proably be non-zero
*/
class SOFA_SOFAMATRIX_API ComplianceMatrixImage : public core::objectmodel::BaseObject
class SOFA_SOFAMATRIX_QT_API ComplianceMatrixImage : public core::objectmodel::BaseObject
{
public:
SOFA_CLASS(ComplianceMatrixImage, core::objectmodel::BaseObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *
* Contact information: [email protected] *
******************************************************************************/
#include <SofaMatrix/GlobalSystemMatrixImage.h>
#include <SofaMatrix/Qt/GlobalSystemMatrixImage.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/core/behavior/LinearSolver.h>
#include <sofa/simulation/AnimateEndEvent.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* Contact information: [email protected] *
******************************************************************************/
#pragma once
#include <SofaMatrix/config.h>
#include <SofaMatrix/Qt/config.h>

#include <sofa/core/objectmodel/BaseObject.h>
#include <SofaMatrix/BaseMatrixImageProxy.h>
#include <SofaMatrix/Qt/BaseMatrixImageProxy.h>

#include <sofa/core/behavior/BaseMatrixLinearSystem.h>

Expand All @@ -34,7 +34,7 @@ namespace sofa::component::linearsolver
* Component to convert a BaseMatrix from the linear solver into an image that can be visualized in the GUI.
* Use GlobalSystemMatrixExporter in order to save an image on the disk.
*/
class SOFA_SOFAMATRIX_API GlobalSystemMatrixImage : public core::objectmodel::BaseObject
class SOFA_SOFAMATRIX_QT_API GlobalSystemMatrixImage : public core::objectmodel::BaseObject
{
public:
SOFA_CLASS(GlobalSystemMatrixImage, core::objectmodel::BaseObject);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 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 Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: [email protected] *
******************************************************************************/
#pragma once

#include <sofa/config.h>

#define SOFAMATRIX_QT_VERSION @PROJECT_VERSION@

#ifdef SOFA_BUILD_SOFAMATRIX_QT
# define SOFA_TARGET @PROJECT_NAME@
# define SOFA_SOFAMATRIX_QT_API SOFA_EXPORT_DYNAMIC_LIBRARY
#else
# define SOFA_SOFAMATRIX_QT_API SOFA_IMPORT_DYNAMIC_LIBRARY
#endif

Loading

0 comments on commit 66b9fd0

Please sign in to comment.