From 326c2d2c4b9ba6345ee855377a2869f2e56fa442 Mon Sep 17 00:00:00 2001 From: bakpaul Date: Mon, 8 Apr 2024 16:37:13 +0200 Subject: [PATCH 01/10] Add virtual destructor for reinit on virtual unique pointer --- .../performer/BaseAttachBodyPerformer.h | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h new file mode 100644 index 00000000000..2f654df8c9f --- /dev/null +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h @@ -0,0 +1,23 @@ +#pragma once + +#include + + +namespace sofa::gui::component::performer +{ +struct BodyPicked; + + +/** + * This class is a virtualization of attachment performer used to allow the blind use of either "AttachBodyPerformer" based on springs and "ConstraintAttachBodyPerformer" based on lagrangian + * constraints. An example of use can be found in the external plugin Sofa.IGTLink in the component "iGTLinkMouseInteractor" + */ +class BaseAttachBodyPerformer +{ +public: + virtual ~BaseAttachBodyPerformer() = default; + virtual sofa::core::objectmodel::BaseObject* getInteractionObject() = 0; + virtual void clear() = 0; + virtual bool start_partial(const BodyPicked& picked) = 0; +}; +} \ No newline at end of file From e205bd422e8fefe88204f27c97f34956efe96f75 Mon Sep 17 00:00:00 2001 From: bakpaul Date: Thu, 28 Mar 2024 11:58:20 +0100 Subject: [PATCH 02/10] ADD Virtualization layer --- Sofa/GUI/Component/CMakeLists.txt | 1 + .../component/performer/AttachBodyPerformer.h | 19 +++++++++++-------- .../performer/AttachBodyPerformer.inl | 7 +++++++ .../performer/BaseAttachBodyPerformer.h | 6 ++++++ .../performer/ConstraintAttachBodyPerformer.h | 10 +++++++--- .../ConstraintAttachBodyPerformer.inl | 6 +++++- 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/Sofa/GUI/Component/CMakeLists.txt b/Sofa/GUI/Component/CMakeLists.txt index b5e837e5fb3..6c5dbe34aa2 100644 --- a/Sofa/GUI/Component/CMakeLists.txt +++ b/Sofa/GUI/Component/CMakeLists.txt @@ -14,6 +14,7 @@ set(HEADER_FILES ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/AddRecordedCameraPerformer.h ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/AttachBodyPerformer.h ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/AttachBodyPerformer.inl + ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/BaseAttachBodyPerformer.h ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/ComponentMouseInteraction.h ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/ComponentMouseInteraction.inl ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/ConstraintAttachBodyPerformer.h diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h index 5e7d93d0fde..f8b8953c9a7 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -34,7 +35,7 @@ namespace sofa::gui::component::performer struct BodyPicked; template -class AttachBodyPerformer: public TInteractionPerformer +class AttachBodyPerformer: public TInteractionPerformer, public BaseAttachBodyPerformer { public: typedef sofa::component::collision::response::mapper::BaseContactMapper< DataTypes > MouseContactMapper; @@ -47,7 +48,14 @@ class AttachBodyPerformer: public TInteractionPerformer void start(); void execute(); void draw(const core::visual::VisualParams* vparams); - void clear(); + virtual sofa::core::objectmodel::BaseObject* getInteractionObject() override; + virtual void clear() override; + virtual bool start_partial(const BodyPicked& picked) override; + /* + initialise MouseForceField according to template. + StiffSpringForceField for Vec3 + JointSpringForceField for Rigid3 + */ void setStiffness(SReal s) {stiffness=s;} void setArrowSize(float s) {size=s;} @@ -69,12 +77,7 @@ class AttachBodyPerformer: public TInteractionPerformer SReal size; SReal showFactorSize; - virtual bool start_partial(const BodyPicked& picked); - /* - initialise MouseForceField according to template. - StiffSpringForceField for Vec3 - JointSpringForceField for Rigid3 - */ + MouseContactMapper *mapper; MouseForceField::SPtr m_forcefield; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl index 34edb675222..f336cf7d8c1 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl @@ -90,6 +90,13 @@ AttachBodyPerformer::AttachBodyPerformer(BaseMouseInteractor *i): flags.setShowInteractionForceFields(true); } + +template +sofa::core::objectmodel::BaseObject* AttachBodyPerformer::getInteractionObject() +{ + return m_forcefield.get(); +} + template void AttachBodyPerformer::clear() { diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h index 2f654df8c9f..6c2af092d14 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h @@ -7,6 +7,7 @@ namespace sofa::gui::component::performer { struct BodyPicked; +<<<<<<< HEAD /** * This class is a virtualization of attachment performer used to allow the blind use of either "AttachBodyPerformer" based on springs and "ConstraintAttachBodyPerformer" based on lagrangian @@ -16,6 +17,11 @@ class BaseAttachBodyPerformer { public: virtual ~BaseAttachBodyPerformer() = default; +======= +class BaseAttachBodyPerformer +{ +public: +>>>>>>> c82a8f7fb0 (ADD Virtualization layer) virtual sofa::core::objectmodel::BaseObject* getInteractionObject() = 0; virtual void clear() = 0; virtual bool start_partial(const BodyPicked& picked) = 0; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h index 42e6bf06bb4..c08f063cb55 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h @@ -26,6 +26,8 @@ #include #include #include +#include + #include @@ -51,7 +53,7 @@ namespace sofa::gui::component::performer struct BodyPicked; template -class ConstraintAttachBodyPerformer: public TInteractionPerformer +class ConstraintAttachBodyPerformer: public TInteractionPerformer, public BaseAttachBodyPerformer { public: typedef typename DataTypes::VecCoord VecCoord; @@ -64,10 +66,13 @@ class ConstraintAttachBodyPerformer: public TInteractionPerformer ConstraintAttachBodyPerformer(BaseMouseInteractor *i); virtual ~ConstraintAttachBodyPerformer(); + void start(); void execute(); void draw(const core::visual::VisualParams* vparams); - void clear(); + virtual sofa::core::objectmodel::BaseObject* getInteractionObject() override; + virtual void clear() override; + virtual bool start_partial(const BodyPicked& picked) override; void setStiffness(SReal s) {stiffness=s;} void setArrowSize(float s) {size=s;} @@ -88,7 +93,6 @@ class ConstraintAttachBodyPerformer: public TInteractionPerformer SReal size; SReal showFactorSize; - virtual bool start_partial(const BodyPicked& picked); MouseContactMapper *mapper; sofa::component::constraint::lagrangian::model::BilateralLagrangianConstraint::SPtr m_constraint; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl index 921a7aacee7..873ebdf7bb4 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl @@ -55,7 +55,11 @@ void ConstraintAttachBodyPerformer::start() this->interactor->setMouseAttached(true); } - +template +sofa::core::objectmodel::BaseObject* ConstraintAttachBodyPerformer::getInteractionObject() +{ + return m_constraint.get(); +} template void ConstraintAttachBodyPerformer::execute() From 713f7e1d9f34a06162d1f678336c39d7b33d2bf9 Mon Sep 17 00:00:00 2001 From: bakpaul Date: Mon, 8 Apr 2024 17:35:12 +0200 Subject: [PATCH 03/10] Remove github merge conficts --- .../gui/component/performer/BaseAttachBodyPerformer.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h index 6c2af092d14..10b8c222bce 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h @@ -7,7 +7,6 @@ namespace sofa::gui::component::performer { struct BodyPicked; -<<<<<<< HEAD /** * This class is a virtualization of attachment performer used to allow the blind use of either "AttachBodyPerformer" based on springs and "ConstraintAttachBodyPerformer" based on lagrangian @@ -17,13 +16,8 @@ class BaseAttachBodyPerformer { public: virtual ~BaseAttachBodyPerformer() = default; -======= -class BaseAttachBodyPerformer -{ -public: ->>>>>>> c82a8f7fb0 (ADD Virtualization layer) virtual sofa::core::objectmodel::BaseObject* getInteractionObject() = 0; virtual void clear() = 0; virtual bool start_partial(const BodyPicked& picked) = 0; }; -} \ No newline at end of file +} From f0c2f9be3e8200bf82f6aab691e51281247d6d91 Mon Sep 17 00:00:00 2001 From: bakpaul Date: Tue, 9 Apr 2024 11:57:31 +0200 Subject: [PATCH 04/10] Refactor the virtualization layer to merge it inside the inheritance tree --- Sofa/GUI/Component/CMakeLists.txt | 1 + .../performer/AttachBodyPerformer.cpp | 1 + .../component/performer/AttachBodyPerformer.h | 24 +--- .../performer/AttachBodyPerformer.inl | 110 ++-------------- .../performer/BaseAttachBodyPerformer.h | 55 +++++++- .../performer/BaseAttachBodyPerformer.inl | 124 ++++++++++++++++++ .../ConstraintAttachBodyPerformer.cpp | 1 + .../performer/ConstraintAttachBodyPerformer.h | 61 +-------- .../ConstraintAttachBodyPerformer.inl | 109 ++------------- 9 files changed, 211 insertions(+), 275 deletions(-) create mode 100644 Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl diff --git a/Sofa/GUI/Component/CMakeLists.txt b/Sofa/GUI/Component/CMakeLists.txt index 6c5dbe34aa2..f31cae53bea 100644 --- a/Sofa/GUI/Component/CMakeLists.txt +++ b/Sofa/GUI/Component/CMakeLists.txt @@ -15,6 +15,7 @@ set(HEADER_FILES ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/AttachBodyPerformer.h ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/AttachBodyPerformer.inl ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/BaseAttachBodyPerformer.h + ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/BaseAttachBodyPerformer.inl ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/ComponentMouseInteraction.h ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/ComponentMouseInteraction.inl ${SOFAGUICOMPONENT_SOURCE_DIR}/performer/ConstraintAttachBodyPerformer.h diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.cpp b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.cpp index 54298c94fa1..b1f48d22d94 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.cpp +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.cpp @@ -21,6 +21,7 @@ ******************************************************************************/ #define SOFA_COMPONENT_COLLISION_ATTACHBODYPERFORMER_CPP +#include #include #include #include diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h index f8b8953c9a7..c651033d35f 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h @@ -22,10 +22,8 @@ #pragma once #include -#include #include #include -#include #include #include @@ -35,22 +33,18 @@ namespace sofa::gui::component::performer struct BodyPicked; template -class AttachBodyPerformer: public TInteractionPerformer, public BaseAttachBodyPerformer +class AttachBodyPerformer: public BaseAttachBodyPerformer { public: + typedef sofa::component::collision::response::mapper::BaseContactMapper< DataTypes > MouseContactMapper; typedef sofa::core::behavior::MechanicalState< DataTypes > MouseContainer; typedef sofa::core::behavior::BaseForceField MouseForceField; AttachBodyPerformer(BaseMouseInteractor *i); - virtual ~AttachBodyPerformer(); + virtual ~AttachBodyPerformer() = default; - void start(); - void execute(); - void draw(const core::visual::VisualParams* vparams); - virtual sofa::core::objectmodel::BaseObject* getInteractionObject() override; - virtual void clear() override; - virtual bool start_partial(const BodyPicked& picked) override; + virtual bool startPartial(const BodyPicked& picked) override; /* initialise MouseForceField according to template. StiffSpringForceField for Vec3 @@ -59,7 +53,6 @@ class AttachBodyPerformer: public TInteractionPerformer, public BaseA void setStiffness(SReal s) {stiffness=s;} void setArrowSize(float s) {size=s;} - void setShowFactorSize(float s) {showFactorSize = s;} virtual void configure(sofa::component::setting::MouseButtonSetting* setting) { @@ -68,21 +61,12 @@ class AttachBodyPerformer: public TInteractionPerformer, public BaseA { setStiffness(s->stiffness.getValue()); setArrowSize((float)s->arrowSize.getValue()); - setShowFactorSize((float)s->showFactorSize.getValue()); } } protected: SReal stiffness; SReal size; - SReal showFactorSize; - - - - MouseContactMapper *mapper; - MouseForceField::SPtr m_forcefield; - - core::visual::DisplayFlags flags; }; #if !defined(SOFA_COMPONENT_COLLISION_ATTACHBODYPERFORMER_CPP) diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl index f336cf7d8c1..dd17c66e4ec 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl @@ -22,133 +22,45 @@ #pragma once #include -#include #include #include -#include #include namespace sofa::gui::component::performer { -template -void AttachBodyPerformer::start() -{ - if (m_forcefield) - { - clear(); - return; - } - const BodyPicked picked=this->interactor->getBodyPicked(); - if (!picked.body && !picked.mstate) return; - - if (!start_partial(picked)) return; //template specialized code is here - - double distanceFromMouse=picked.rayLength; - this->interactor->setDistanceFromMouse(distanceFromMouse); - sofa::component::collision::geometry::Ray ray = this->interactor->getMouseRayModel()->getRay(0); - ray.setOrigin(ray.origin() + ray.direction()*distanceFromMouse); - sofa::core::BaseMapping *mapping; - this->interactor->getContext()->get(mapping); assert(mapping); - mapping->apply(core::mechanicalparams::defaultInstance()); - mapping->applyJ(core::mechanicalparams::defaultInstance()); - m_forcefield->init(); - this->interactor->setMouseAttached(true); -} - - - -template -void AttachBodyPerformer::execute() -{ - sofa::core::BaseMapping *mapping; - this->interactor->getContext()->get(mapping); assert(mapping); - mapping->apply(core::mechanicalparams::defaultInstance()); - mapping->applyJ(core::mechanicalparams::defaultInstance()); - this->interactor->setMouseAttached(true); -} - -template -void AttachBodyPerformer::draw(const core::visual::VisualParams* vparams) -{ - if (m_forcefield) - { - core::visual::VisualParams* vp = const_cast(vparams); - const core::visual::DisplayFlags backup = vp->displayFlags(); - vp->displayFlags() = flags; - m_forcefield->draw(vp); - vp->displayFlags() = backup; - } -} template AttachBodyPerformer::AttachBodyPerformer(BaseMouseInteractor *i): - TInteractionPerformer(i), - mapper(nullptr) -{ - flags.setShowVisualModels(false); - flags.setShowInteractionForceFields(true); -} - - -template -sofa::core::objectmodel::BaseObject* AttachBodyPerformer::getInteractionObject() -{ - return m_forcefield.get(); -} - -template -void AttachBodyPerformer::clear() -{ - if (m_forcefield) - { - m_forcefield->cleanup(); - m_forcefield->getContext()->removeObject(m_forcefield); - m_forcefield.reset(); - } - - if (mapper) - { - mapper->cleanup(); - delete mapper; mapper=nullptr; - } - - this->interactor->setDistanceFromMouse(0); - this->interactor->setMouseAttached(false); -} - + BaseAttachBodyPerformer(i) +{} -template -AttachBodyPerformer::~AttachBodyPerformer() -{ - clear(); -} template -bool AttachBodyPerformer::start_partial(const BodyPicked& picked) +bool AttachBodyPerformer::startPartial(const BodyPicked& picked) { core::behavior::MechanicalState* mstateCollision=nullptr; int index; if (picked.body) { - mapper = MouseContactMapper::Create(picked.body); - if (!mapper) + this->mapper = MouseContactMapper::Create(picked.body); + if (!this->mapper) { msg_warning(this->interactor) << "Problem with Mouse Mapper creation " ; return false; } const std::string name = "contactMouse"; - mstateCollision = mapper->createMapping(name.c_str()); - mapper->resize(1); + mstateCollision = this->mapper->createMapping(name.c_str()); + this->mapper->resize(1); const unsigned int idx=picked.indexCollisionElement; typename DataTypes::CPos pointPicked=(typename DataTypes::CPos)picked.point; typename DataTypes::Real r=0.0; typename DataTypes::Coord dofPicked; DataTypes::setCPos(dofPicked, pointPicked); - index = mapper->addPointB(dofPicked, idx, r); - mapper->update(); + index = this->mapper->addPointB(dofPicked, idx, r); + this->mapper->update(); if (mstateCollision->getContext() != picked.body->getContext()) { @@ -178,8 +90,8 @@ bool AttachBodyPerformer::start_partial(const BodyPicked& picked) using sofa::component::solidmechanics::spring::StiffSpringForceField; - m_forcefield = sofa::core::objectmodel::New< StiffSpringForceField >(dynamic_cast(this->interactor->getMouseContainer()), mstateCollision); - StiffSpringForceField< DataTypes >* stiffspringforcefield = static_cast< StiffSpringForceField< DataTypes >* >(m_forcefield.get()); + this->m_interactionObject = sofa::core::objectmodel::New< StiffSpringForceField >(dynamic_cast(this->interactor->getMouseContainer()), mstateCollision); + auto* stiffspringforcefield = dynamic_cast< StiffSpringForceField< DataTypes >* >(this->m_interactionObject.get()); stiffspringforcefield->setName("Spring-Mouse-Contact"); stiffspringforcefield->setArrowSize((float)this->size); stiffspringforcefield->setDrawMode(2); //Arrow mode if size > 0 diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h index 10b8c222bce..583397947c1 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h @@ -1,6 +1,33 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ #pragma once #include +#include + +#include +#include +#include +#include namespace sofa::gui::component::performer @@ -12,12 +39,30 @@ struct BodyPicked; * This class is a virtualization of attachment performer used to allow the blind use of either "AttachBodyPerformer" based on springs and "ConstraintAttachBodyPerformer" based on lagrangian * constraints. An example of use can be found in the external plugin Sofa.IGTLink in the component "iGTLinkMouseInteractor" */ -class BaseAttachBodyPerformer +template +class BaseAttachBodyPerformer : public TInteractionPerformer { public: - virtual ~BaseAttachBodyPerformer() = default; - virtual sofa::core::objectmodel::BaseObject* getInteractionObject() = 0; - virtual void clear() = 0; - virtual bool start_partial(const BodyPicked& picked) = 0; + typedef typename DataTypes::VecCoord VecCoord; + typedef sofa::component::collision::response::mapper::BaseContactMapper< DataTypes > MouseContactMapper; + typedef sofa::core::behavior::MechanicalState< DataTypes > MouseContainer; + + explicit BaseAttachBodyPerformer(BaseMouseInteractor* i); + virtual ~BaseAttachBodyPerformer(); + + virtual void start(); + virtual void draw(const core::visual::VisualParams* vparams); + virtual void clear(); + virtual void execute(); + sofa::core::objectmodel::BaseObject::SPtr getInteractionObject(); + + virtual bool startPartial(const BodyPicked& picked) = 0; + + +protected: + + sofa::core::objectmodel::BaseObject::SPtr m_interactionObject; + MouseContactMapper *mapper; + core::visual::DisplayFlags flags; }; } diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl new file mode 100644 index 00000000000..99ac869118f --- /dev/null +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl @@ -0,0 +1,124 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include +#include +#include + + +namespace sofa::gui::component::performer +{ + +template +BaseAttachBodyPerformer::BaseAttachBodyPerformer(BaseMouseInteractor* i) + : TInteractionPerformer(i) + , mapper(nullptr) +{ + this->flags.setShowVisualModels(false); + this->flags.setShowInteractionForceFields(true); +}; + +template +BaseAttachBodyPerformer::~BaseAttachBodyPerformer() +{ + clear(); +}; + +template +void BaseAttachBodyPerformer::start() +{ + if (m_interactionObject) + { + clear(); + return; + } + const BodyPicked picked=this->interactor->getBodyPicked(); + if (!picked.body && !picked.mstate) return; + + if (!startPartial(picked)) return; //template specialized code is here + + double distanceFromMouse=picked.rayLength; + this->interactor->setDistanceFromMouse(distanceFromMouse); + sofa::component::collision::geometry::Ray ray = this->interactor->getMouseRayModel()->getRay(0); + ray.setOrigin(ray.origin() + ray.direction()*distanceFromMouse); + sofa::core::BaseMapping *mapping; + this->interactor->getContext()->get(mapping); assert(mapping); + mapping->apply(core::mechanicalparams::defaultInstance()); + mapping->applyJ(core::mechanicalparams::defaultInstance()); + m_interactionObject->init(); + this->interactor->setMouseAttached(true); +} + +template +void BaseAttachBodyPerformer::draw(const core::visual::VisualParams* vparams) +{ + if (m_interactionObject) + { + core::visual::VisualParams* vp = const_cast(vparams); + const core::visual::DisplayFlags backup = vp->displayFlags(); + vp->displayFlags() = flags; + m_interactionObject->draw(vp); + vp->displayFlags() = backup; + } +} + +template +void BaseAttachBodyPerformer::clear() +{ + if (m_interactionObject) + { + m_interactionObject->cleanup(); + m_interactionObject->getContext()->removeObject(m_interactionObject); + m_interactionObject.reset(); + } + + if (mapper) + { + mapper->cleanup(); + delete mapper; + mapper = nullptr; + } + + this->interactor->setDistanceFromMouse(0); + this->interactor->setMouseAttached(false); +} + +template +void BaseAttachBodyPerformer::execute() +{ + sofa::core::BaseMapping *mapping; + this->interactor->getContext()->get(mapping); assert(mapping); + mapping->apply(core::mechanicalparams::defaultInstance()); + mapping->applyJ(core::mechanicalparams::defaultInstance()); + this->interactor->setMouseAttached(true); +} + +template +sofa::core::objectmodel::BaseObject::SPtr BaseAttachBodyPerformer::getInteractionObject() +{ + return m_interactionObject; +}; + + + +} diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.cpp b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.cpp index 78b3ebc87e8..40eed76a114 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.cpp +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.cpp @@ -21,6 +21,7 @@ ******************************************************************************/ #define SOFA_COMPONENT_COLLISION_CONSTRAINTATTACHBODYPERFORMER_CPP +#include #include #include #include diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h index c08f063cb55..b1cde883805 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h @@ -20,32 +20,12 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #pragma once -#include -#include -#include -#include #include #include +#include -#include - -namespace sofa::gui::component -{ - -class ConstraintAttachBodyButtonSetting : public sofa::gui::component::AttachBodyButtonSetting -{ -public: - SOFA_CLASS(ConstraintAttachBodyButtonSetting, sofa::gui::component::AttachBodyButtonSetting); -protected: - ConstraintAttachBodyButtonSetting() {} -public: - // Data snapDistance; - std::string getOperationType() override { return "ConstraintAttachBody"; } -}; - -} // namespace sofa::gui::component namespace sofa::gui::component::performer { @@ -53,51 +33,20 @@ namespace sofa::gui::component::performer struct BodyPicked; template -class ConstraintAttachBodyPerformer: public TInteractionPerformer, public BaseAttachBodyPerformer +class ConstraintAttachBodyPerformer: public BaseAttachBodyPerformer { public: + typedef typename DataTypes::VecCoord VecCoord; typedef sofa::component::collision::response::mapper::BaseContactMapper< DataTypes > MouseContactMapper; typedef sofa::core::behavior::MechanicalState< DataTypes > MouseContainer; -// typedef sofa::component::constraint::lagrangian::model::BilateralLagrangianConstraint< DataTypes > MouseConstraint; - -// typedef sofa::core::behavior::BaseForceField MouseForceField; ConstraintAttachBodyPerformer(BaseMouseInteractor *i); - virtual ~ConstraintAttachBodyPerformer(); - - - void start(); - void execute(); - void draw(const core::visual::VisualParams* vparams); - virtual sofa::core::objectmodel::BaseObject* getInteractionObject() override; - virtual void clear() override; - virtual bool start_partial(const BodyPicked& picked) override; + virtual ~ConstraintAttachBodyPerformer() = default; - void setStiffness(SReal s) {stiffness=s;} - void setArrowSize(float s) {size=s;} - void setShowFactorSize(float s) {showFactorSize = s;} - - virtual void configure(sofa::component::setting::MouseButtonSetting * setting) - { - if (const auto* s = dynamic_cast(setting)) - { - setStiffness((double)s->stiffness.getValue()); - setArrowSize((float)s->arrowSize.getValue()); - setShowFactorSize((float)s->showFactorSize.getValue()); - } - } + virtual bool startPartial(const BodyPicked& picked) override; protected: - SReal stiffness; - SReal size; - SReal showFactorSize; - - - MouseContactMapper *mapper; - sofa::component::constraint::lagrangian::model::BilateralLagrangianConstraint::SPtr m_constraint; - - core::visual::DisplayFlags flags; sofa::core::behavior::MechanicalState *mstate1, *mstate2; }; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl index 873ebdf7bb4..872c89b9415 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl @@ -23,126 +23,42 @@ #include #include -#include #include #include namespace sofa::gui::component::performer { -template -void ConstraintAttachBodyPerformer::start() -{ - if (m_constraint) - { - clear(); - return; - } - const BodyPicked picked=this->interactor->getBodyPicked(); - if (!picked.body && !picked.mstate) return; - - if (!start_partial(picked)) return; //template specialized code is here - - double distanceFromMouse=picked.rayLength; - this->interactor->setDistanceFromMouse(distanceFromMouse); - sofa::component::collision::geometry::Ray ray = this->interactor->getMouseRayModel()->getRay(0); - ray.setOrigin(ray.origin() + ray.direction()*distanceFromMouse); - sofa::core::BaseMapping *mapping; - this->interactor->getContext()->get(mapping); assert(mapping); - mapping->apply(core::mechanicalparams::defaultInstance()); - mapping->applyJ(core::mechanicalparams::defaultInstance()); - m_constraint->init(); - this->interactor->setMouseAttached(true); -} - -template -sofa::core::objectmodel::BaseObject* ConstraintAttachBodyPerformer::getInteractionObject() -{ - return m_constraint.get(); -} - -template -void ConstraintAttachBodyPerformer::execute() -{ - sofa::core::BaseMapping *mapping; - this->interactor->getContext()->get(mapping); assert(mapping); - mapping->apply(core::mechanicalparams::defaultInstance()); - mapping->applyJ(core::mechanicalparams::defaultInstance()); - this->interactor->setMouseAttached(true); -} - -template -void ConstraintAttachBodyPerformer::draw(const core::visual::VisualParams* vparams) -{ - if (m_constraint) - { - core::visual::VisualParams* vp = const_cast(vparams); - const core::visual::DisplayFlags backup = vp->displayFlags(); - vp->displayFlags() = flags; - m_constraint->draw(vp); - vp->displayFlags() = backup; - } -} template ConstraintAttachBodyPerformer::ConstraintAttachBodyPerformer(BaseMouseInteractor *i): - TInteractionPerformer(i), - mapper(nullptr) -{ - flags.setShowVisualModels(false); - flags.setShowInteractionForceFields(true); -} - -template -void ConstraintAttachBodyPerformer::clear() -{ - if (m_constraint) - { - m_constraint->cleanup(); - m_constraint->getContext()->removeObject(m_constraint); - m_constraint.reset(); - } - - if (mapper) - { - mapper->cleanup(); - delete mapper; mapper=nullptr; - } - - this->interactor->setDistanceFromMouse(0); - this->interactor->setMouseAttached(false); -} + BaseAttachBodyPerformer(i) +{} template -ConstraintAttachBodyPerformer::~ConstraintAttachBodyPerformer() -{ - clear(); -} - -template -bool ConstraintAttachBodyPerformer::start_partial(const BodyPicked& picked) +bool ConstraintAttachBodyPerformer::startPartial(const BodyPicked& picked) { core::behavior::MechanicalState* mstateCollision=nullptr; int index; if (picked.body) { - mapper = MouseContactMapper::Create(picked.body); - if (!mapper) + this->mapper = MouseContactMapper::Create(picked.body); + if (!(this->mapper)) { msg_error(this->interactor) << "Problem with Mouse Mapper creation."; return false; } const std::string name = "contactMouse"; - mstateCollision = mapper->createMapping(name.c_str()); - mapper->resize(1); + mstateCollision = this->mapper->createMapping(name.c_str()); + this->mapper->resize(1); const typename DataTypes::Coord pointPicked=picked.point; const int idx=picked.indexCollisionElement; typename DataTypes::Real r=0.0; - index = mapper->addPointB(pointPicked, idx, r); - mapper->update(); + index = this->mapper->addPointB(pointPicked, idx, r); + this->mapper->update(); if (mstateCollision->getContext() != picked.body->getContext()) { @@ -178,8 +94,11 @@ bool ConstraintAttachBodyPerformer::start_partial(const BodyPicked& p using sofa::component::constraint::lagrangian::model::BilateralLagrangianConstraint; - m_constraint = sofa::core::objectmodel::New >(mstate1, mstate2); - BilateralLagrangianConstraint< DataTypes >* bconstraint = static_cast< BilateralLagrangianConstraint< sofa::defaulttype::Vec3Types >* >(m_constraint.get()); + + + this->m_interactionObject = sofa::core::objectmodel::New >(mstate1, mstate2); + auto* bconstraint = dynamic_cast< BilateralLagrangianConstraint< sofa::defaulttype::Vec3Types >* >(this->m_interactionObject.get()); + bconstraint->setName("Constraint-Mouse-Contact"); type::Vec3d normal = point1-point2; From 2b509ffd776172aba94d1ea233705e6e080d0450 Mon Sep 17 00:00:00 2001 From: bakpaul Date: Tue, 9 Apr 2024 14:09:53 +0200 Subject: [PATCH 05/10] First stage of refactoring attribute names --- .../src/sofa/gui/common/MouseOperations.h | 12 ++++++------ .../gui/component/AttachBodyButtonSetting.cpp | 6 +++--- .../gui/component/AttachBodyButtonSetting.h | 6 +++--- .../component/performer/AttachBodyPerformer.h | 12 ++++++------ .../performer/AttachBodyPerformer.inl | 16 ++++++++-------- .../performer/BaseAttachBodyPerformer.h | 4 ++-- .../performer/BaseAttachBodyPerformer.inl | 16 ++++++++-------- .../performer/ConstraintAttachBodyPerformer.h | 2 +- .../ConstraintAttachBodyPerformer.inl | 18 +++++++++--------- .../Qt/src/sofa/gui/qt/QMouseOperations.cpp | 12 ++++++------ 10 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Sofa/GUI/Common/src/sofa/gui/common/MouseOperations.h b/Sofa/GUI/Common/src/sofa/gui/common/MouseOperations.h index 8f2d15d28d7..7fba20a3cd4 100644 --- a/Sofa/GUI/Common/src/sofa/gui/common/MouseOperations.h +++ b/Sofa/GUI/Common/src/sofa/gui/common/MouseOperations.h @@ -101,12 +101,12 @@ class SOFA_GUI_COMMON_API AttachOperation : public Operation {} ~AttachOperation() override {} - void setStiffness(double s) {setting->stiffness.setValue(s);} - double getStiffness() const { return setting->stiffness.getValue();} - void setArrowSize(double s) {setting->arrowSize.setValue(s);} - double getArrowSize() const { return setting->arrowSize.getValue();} - void setShowFactorSize(double s) { setting->showFactorSize.setValue(s); } - double getShowFactorSize() const { return setting->showFactorSize.getValue(); } + void setStiffness(double s) {setting->d_stiffness.setValue(s);} + double getStiffness() const { return setting->d_stiffness.getValue();} + void setArrowSize(double s) {setting->d_arrowSize.setValue(s);} + double getArrowSize() const { return setting->d_arrowSize.getValue();} + void setShowFactorSize(double s) { setting->d_showFactorSize.setValue(s); } + double getShowFactorSize() const { return setting->d_showFactorSize.getValue(); } static std::string getDescription() {return "Attach an object to the Mouse using a spring force field";} diff --git a/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.cpp b/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.cpp index d6abf566ab9..0158b6864b3 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.cpp +++ b/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.cpp @@ -33,9 +33,9 @@ int AttachBodyButtonSettingClass = core::RegisterObject("Attach Body Button conf ; AttachBodyButtonSetting::AttachBodyButtonSetting(): - stiffness(initData(&stiffness, 1000.0_sreal, "stiffness", "Stiffness of the spring to attach a particule")) - , arrowSize(initData(&arrowSize, 0.0_sreal, "arrowSize", "Size of the drawn spring: if >0 an arrow will be drawn")) - , showFactorSize(initData(&showFactorSize, 1.0_sreal, "showFactorSize", "Show factor size of the JointSpringForcefield when interacting with rigids")) + d_stiffness(initData(&d_stiffness, 1000.0_sreal, "stiffness", "Stiffness of the spring to attach a particule")) + , d_arrowSize(initData(&d_arrowSize, 0.0_sreal, "arrowSize", "Size of the drawn spring: if >0 an arrow will be drawn")) + , d_showFactorSize(initData(&d_showFactorSize, 1.0_sreal, "showFactorSize", "Show factor size of the JointSpringForcefield when interacting with rigids")) { } diff --git a/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.h b/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.h index 790de0ce4b7..c8c99125cf1 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.h @@ -37,9 +37,9 @@ class SOFA_GUI_COMPONENT_API AttachBodyButtonSetting: public sofa::component::se AttachBodyButtonSetting(); public: std::string getOperationType() override {return "Attach";} - Data stiffness; ///< Stiffness of the spring to attach a particule - Data arrowSize; ///< Size of the drawn spring: if >0 an arrow will be drawn - Data showFactorSize; ///< Show factor size of the JointSpringForcefield when interacting with rigids + Data d_stiffness; ///< Stiffness of the spring to attach a particule + Data d_arrowSize; ///< Size of the drawn spring: if >0 an arrow will be drawn + Data d_showFactorSize; ///< Show factor size of the JointSpringForcefield when interacting with rigids }; } // namespace sofa::gui::component diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h index c651033d35f..6c206783306 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.h @@ -51,22 +51,22 @@ class AttachBodyPerformer: public BaseAttachBodyPerformer JointSpringForceField for Rigid3 */ - void setStiffness(SReal s) {stiffness=s;} - void setArrowSize(float s) {size=s;} + void setStiffness(SReal s) {m_stiffness=s;} + void setArrowSize(float s) {m_size=s;} virtual void configure(sofa::component::setting::MouseButtonSetting* setting) { const auto* s = dynamic_cast(setting); if (s) { - setStiffness(s->stiffness.getValue()); - setArrowSize((float)s->arrowSize.getValue()); + setStiffness(s->d_stiffness.getValue()); + setArrowSize((float)s->d_arrowSize.getValue()); } } protected: - SReal stiffness; - SReal size; + SReal m_stiffness; + SReal m_size; }; #if !defined(SOFA_COMPONENT_COLLISION_ATTACHBODYPERFORMER_CPP) diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl index dd17c66e4ec..64e0b998e29 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl @@ -44,23 +44,23 @@ bool AttachBodyPerformer::startPartial(const BodyPicked& picked) int index; if (picked.body) { - this->mapper = MouseContactMapper::Create(picked.body); - if (!this->mapper) + this->m_mapper = MouseContactMapper::Create(picked.body); + if (!this->m_mapper) { msg_warning(this->interactor) << "Problem with Mouse Mapper creation " ; return false; } const std::string name = "contactMouse"; - mstateCollision = this->mapper->createMapping(name.c_str()); - this->mapper->resize(1); + mstateCollision = this->m_mapper->createMapping(name.c_str()); + this->m_mapper->resize(1); const unsigned int idx=picked.indexCollisionElement; typename DataTypes::CPos pointPicked=(typename DataTypes::CPos)picked.point; typename DataTypes::Real r=0.0; typename DataTypes::Coord dofPicked; DataTypes::setCPos(dofPicked, pointPicked); - index = this->mapper->addPointB(dofPicked, idx, r); - this->mapper->update(); + index = this->m_mapper->addPointB(dofPicked, idx, r); + this->m_mapper->update(); if (mstateCollision->getContext() != picked.body->getContext()) { @@ -93,11 +93,11 @@ bool AttachBodyPerformer::startPartial(const BodyPicked& picked) this->m_interactionObject = sofa::core::objectmodel::New< StiffSpringForceField >(dynamic_cast(this->interactor->getMouseContainer()), mstateCollision); auto* stiffspringforcefield = dynamic_cast< StiffSpringForceField< DataTypes >* >(this->m_interactionObject.get()); stiffspringforcefield->setName("Spring-Mouse-Contact"); - stiffspringforcefield->setArrowSize((float)this->size); + stiffspringforcefield->setArrowSize((float)this->m_size); stiffspringforcefield->setDrawMode(2); //Arrow mode if size > 0 - stiffspringforcefield->addSpring(0,index, stiffness, 0.0, picked.dist); + stiffspringforcefield->addSpring(0,index, m_stiffness, 0.0, picked.dist); const core::objectmodel::TagSet &tags=mstateCollision->getTags(); for (core::objectmodel::TagSet::const_iterator it=tags.begin(); it!=tags.end(); ++it) stiffspringforcefield->addTag(*it); diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h index 583397947c1..2f21bc80d67 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.h @@ -62,7 +62,7 @@ class BaseAttachBodyPerformer : public TInteractionPerformer protected: sofa::core::objectmodel::BaseObject::SPtr m_interactionObject; - MouseContactMapper *mapper; - core::visual::DisplayFlags flags; + MouseContactMapper *m_mapper; + core::visual::DisplayFlags m_flags; }; } diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl index 99ac869118f..fa844b117bc 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl @@ -32,10 +32,10 @@ namespace sofa::gui::component::performer template BaseAttachBodyPerformer::BaseAttachBodyPerformer(BaseMouseInteractor* i) : TInteractionPerformer(i) - , mapper(nullptr) + , m_mapper(nullptr) { - this->flags.setShowVisualModels(false); - this->flags.setShowInteractionForceFields(true); + this->m_flags.setShowVisualModels(false); + this->m_flags.setShowInteractionForceFields(true); }; template @@ -76,7 +76,7 @@ void BaseAttachBodyPerformer::draw(const core::visual::VisualParams* { core::visual::VisualParams* vp = const_cast(vparams); const core::visual::DisplayFlags backup = vp->displayFlags(); - vp->displayFlags() = flags; + vp->displayFlags() = m_flags; m_interactionObject->draw(vp); vp->displayFlags() = backup; } @@ -92,11 +92,11 @@ void BaseAttachBodyPerformer::clear() m_interactionObject.reset(); } - if (mapper) + if (m_mapper) { - mapper->cleanup(); - delete mapper; - mapper = nullptr; + m_mapper->cleanup(); + delete m_mapper; + m_mapper = nullptr; } this->interactor->setDistanceFromMouse(0); diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h index b1cde883805..8ade312f8cc 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h @@ -48,7 +48,7 @@ class ConstraintAttachBodyPerformer: public BaseAttachBodyPerformer protected: - sofa::core::behavior::MechanicalState *mstate1, *mstate2; + sofa::core::behavior::MechanicalState *m_mstate1, *m_mstate2; }; #if !defined(SOFA_COMPONENT_COLLISION_CONSTRAINTATTACHBODYPERFORMER_CPP) diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl index 872c89b9415..51b603f0b50 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl @@ -43,22 +43,22 @@ bool ConstraintAttachBodyPerformer::startPartial(const BodyPicked& pi int index; if (picked.body) { - this->mapper = MouseContactMapper::Create(picked.body); - if (!(this->mapper)) + this->m_mapper = MouseContactMapper::Create(picked.body); + if (!(this->m_mapper)) { msg_error(this->interactor) << "Problem with Mouse Mapper creation."; return false; } const std::string name = "contactMouse"; - mstateCollision = this->mapper->createMapping(name.c_str()); - this->mapper->resize(1); + mstateCollision = this->m_mapper->createMapping(name.c_str()); + this->m_mapper->resize(1); const typename DataTypes::Coord pointPicked=picked.point; const int idx=picked.indexCollisionElement; typename DataTypes::Real r=0.0; - index = this->mapper->addPointB(pointPicked, idx, r); - this->mapper->update(); + index = this->m_mapper->addPointB(pointPicked, idx, r); + this->m_mapper->update(); if (mstateCollision->getContext() != picked.body->getContext()) { @@ -86,8 +86,8 @@ bool ConstraintAttachBodyPerformer::startPartial(const BodyPicked& pi } } - mstate1 = dynamic_cast(this->interactor->getMouseContainer()); - mstate2 = mstateCollision; + m_mstate1 = dynamic_cast(this->interactor->getMouseContainer()); + m_mstate2 = mstateCollision; type::Vec3d point1; type::Vec3d point2; @@ -96,7 +96,7 @@ bool ConstraintAttachBodyPerformer::startPartial(const BodyPicked& pi - this->m_interactionObject = sofa::core::objectmodel::New >(mstate1, mstate2); + this->m_interactionObject = sofa::core::objectmodel::New >(m_mstate1, m_mstate2); auto* bconstraint = dynamic_cast< BilateralLagrangianConstraint< sofa::defaulttype::Vec3Types >* >(this->m_interactionObject.get()); bconstraint->setName("Constraint-Mouse-Contact"); diff --git a/Sofa/GUI/Qt/src/sofa/gui/qt/QMouseOperations.cpp b/Sofa/GUI/Qt/src/sofa/gui/qt/QMouseOperations.cpp index c98e3fa6ed1..91fca155b71 100644 --- a/Sofa/GUI/Qt/src/sofa/gui/qt/QMouseOperations.cpp +++ b/Sofa/GUI/Qt/src/sofa/gui/qt/QMouseOperations.cpp @@ -67,13 +67,13 @@ QAttachOperation::QAttachOperation() QHBoxLayout *layout=new QHBoxLayout(this); QLabel *label=new QLabel(QString("Stiffness"), this); - stiffnessWidget = createWidgetFromData(&(setting->stiffness)); + stiffnessWidget = createWidgetFromData(&(setting->d_stiffness)); QLabel *labelSize=new QLabel(QString("Arrow Size"), this); - arrowSizeWidget = createWidgetFromData(&(setting->arrowSize)); + arrowSizeWidget = createWidgetFromData(&(setting->d_arrowSize)); QLabel *labelShowFactor=new QLabel(QString("Show Factor Size"), this); - showSizeFactorWidget = createWidgetFromData(&(setting->showFactorSize)); + showSizeFactorWidget = createWidgetFromData(&(setting->d_showFactorSize)); layout->addWidget(label); layout->addWidget(stiffnessWidget); @@ -91,9 +91,9 @@ void QAttachOperation::configure(PickHandler *picker, sofa::component::setting:: if (const sofa::gui::component::AttachBodyButtonSetting* attachSetting=dynamic_cast(button)) { AttachOperation::configure(picker,GetMouseId(button->button.getValue().getSelectedId())); - setting->stiffness.copyValueFrom(&(attachSetting->stiffness)); - setting->arrowSize.copyValueFrom(&(attachSetting->arrowSize) ); - setting->showFactorSize.copyValueFrom(&( attachSetting->showFactorSize) ) ; + setting->d_stiffness.copyValueFrom(&(attachSetting->d_stiffness)); + setting->d_arrowSize.copyValueFrom(&(attachSetting->d_arrowSize) ); + setting->d_showFactorSize.copyValueFrom(&( attachSetting->d_showFactorSize) ) ; stiffnessWidget->updateWidgetValue(); arrowSizeWidget->updateWidgetValue(); From 710790db5ec1e6fa525372e881c86161c6dca712 Mon Sep 17 00:00:00 2001 From: bakpaul Date: Tue, 9 Apr 2024 14:15:36 +0200 Subject: [PATCH 06/10] Refactoring of InteractionPerformer attributes names --- .../performer/AddRecordedCameraPerformer.cpp | 2 +- .../performer/AttachBodyPerformer.inl | 6 +++--- .../performer/BaseAttachBodyPerformer.inl | 18 ++++++++--------- .../ConstraintAttachBodyPerformer.inl | 6 +++--- .../performer/FixParticlePerformer.inl | 2 +- .../performer/InciseAlongPathPerformer.cpp | 18 ++++++++--------- .../performer/InteractionPerformer.h | 8 ++++---- .../performer/RemovePrimitivePerformer.inl | 6 +++--- .../performer/StartNavigationPerformer.cpp | 2 +- .../performer/SuturePointPerformer.inl | 20 +++++++++---------- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AddRecordedCameraPerformer.cpp b/Sofa/GUI/Component/src/sofa/gui/component/performer/AddRecordedCameraPerformer.cpp index 3488e31ba50..ba51bca6857 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AddRecordedCameraPerformer.cpp +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AddRecordedCameraPerformer.cpp @@ -39,7 +39,7 @@ namespace sofa::gui::component::performer void AddRecordedCameraPerformer::start() { - const sofa::simulation::Node::SPtr root = down_cast( interactor->getContext()->getRootContext() ); + const sofa::simulation::Node::SPtr root = down_cast( m_interactor->getContext()->getRootContext() ); if(root) { sofa::component::visual::RecordedCamera* currentCamera = root->getNodeObject(); diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl index 64e0b998e29..39bb6132876 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/AttachBodyPerformer.inl @@ -47,7 +47,7 @@ bool AttachBodyPerformer::startPartial(const BodyPicked& picked) this->m_mapper = MouseContactMapper::Create(picked.body); if (!this->m_mapper) { - msg_warning(this->interactor) << "Problem with Mouse Mapper creation " ; + msg_warning(this->m_interactor) << "Problem with Mouse Mapper creation " ; return false; } const std::string name = "contactMouse"; @@ -83,14 +83,14 @@ bool AttachBodyPerformer::startPartial(const BodyPicked& picked) index = picked.indexCollisionElement; if (!mstateCollision) { - msg_warning(this->interactor) << "incompatible MState during Mouse Interaction " ; + msg_warning(this->m_interactor) << "incompatible MState during Mouse Interaction " ; return false; } } using sofa::component::solidmechanics::spring::StiffSpringForceField; - this->m_interactionObject = sofa::core::objectmodel::New< StiffSpringForceField >(dynamic_cast(this->interactor->getMouseContainer()), mstateCollision); + this->m_interactionObject = sofa::core::objectmodel::New< StiffSpringForceField >(dynamic_cast(this->m_interactor->getMouseContainer()), mstateCollision); auto* stiffspringforcefield = dynamic_cast< StiffSpringForceField< DataTypes >* >(this->m_interactionObject.get()); stiffspringforcefield->setName("Spring-Mouse-Contact"); stiffspringforcefield->setArrowSize((float)this->m_size); diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl index fa844b117bc..3fe9ef74c46 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl @@ -52,21 +52,21 @@ void BaseAttachBodyPerformer::start() clear(); return; } - const BodyPicked picked=this->interactor->getBodyPicked(); + const BodyPicked picked=this->m_interactor->getBodyPicked(); if (!picked.body && !picked.mstate) return; if (!startPartial(picked)) return; //template specialized code is here double distanceFromMouse=picked.rayLength; - this->interactor->setDistanceFromMouse(distanceFromMouse); - sofa::component::collision::geometry::Ray ray = this->interactor->getMouseRayModel()->getRay(0); + this->m_interactor->setDistanceFromMouse(distanceFromMouse); + sofa::component::collision::geometry::Ray ray = this->m_interactor->getMouseRayModel()->getRay(0); ray.setOrigin(ray.origin() + ray.direction()*distanceFromMouse); sofa::core::BaseMapping *mapping; - this->interactor->getContext()->get(mapping); assert(mapping); + this->m_interactor->getContext()->get(mapping); assert(mapping); mapping->apply(core::mechanicalparams::defaultInstance()); mapping->applyJ(core::mechanicalparams::defaultInstance()); m_interactionObject->init(); - this->interactor->setMouseAttached(true); + this->m_interactor->setMouseAttached(true); } template @@ -99,18 +99,18 @@ void BaseAttachBodyPerformer::clear() m_mapper = nullptr; } - this->interactor->setDistanceFromMouse(0); - this->interactor->setMouseAttached(false); + this->m_interactor->setDistanceFromMouse(0); + this->m_interactor->setMouseAttached(false); } template void BaseAttachBodyPerformer::execute() { sofa::core::BaseMapping *mapping; - this->interactor->getContext()->get(mapping); assert(mapping); + this->m_interactor->getContext()->get(mapping); assert(mapping); mapping->apply(core::mechanicalparams::defaultInstance()); mapping->applyJ(core::mechanicalparams::defaultInstance()); - this->interactor->setMouseAttached(true); + this->m_interactor->setMouseAttached(true); } template diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl index 51b603f0b50..02ac9f2e1c9 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl @@ -46,7 +46,7 @@ bool ConstraintAttachBodyPerformer::startPartial(const BodyPicked& pi this->m_mapper = MouseContactMapper::Create(picked.body); if (!(this->m_mapper)) { - msg_error(this->interactor) << "Problem with Mouse Mapper creation."; + msg_error(this->m_interactor) << "Problem with Mouse Mapper creation."; return false; } const std::string name = "contactMouse"; @@ -81,12 +81,12 @@ bool ConstraintAttachBodyPerformer::startPartial(const BodyPicked& pi index = picked.indexCollisionElement; if (!mstateCollision) { - msg_error(this->interactor) << "incompatible MState during Mouse Interaction."; + msg_error(this->m_interactor) << "incompatible MState during Mouse Interaction."; return false; } } - m_mstate1 = dynamic_cast(this->interactor->getMouseContainer()); + m_mstate1 = dynamic_cast(this->m_interactor->getMouseContainer()); m_mstate2 = mstateCollision; type::Vec3d point1; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/FixParticlePerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/FixParticlePerformer.inl index a52c148ef2f..7ac20cb7094 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/FixParticlePerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/FixParticlePerformer.inl @@ -34,7 +34,7 @@ namespace sofa::gui::component::performer template void FixParticlePerformer::start() { - const BodyPicked &picked=this->interactor->getBodyPicked(); + const BodyPicked &picked=this->m_interactor->getBodyPicked(); type::vector points; typename DataTypes::Coord fixPoint; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/InciseAlongPathPerformer.cpp b/Sofa/GUI/Component/src/sofa/gui/component/performer/InciseAlongPathPerformer.cpp index 5fab9bb91a5..61b0594291a 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/InciseAlongPathPerformer.cpp +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/InciseAlongPathPerformer.cpp @@ -33,7 +33,7 @@ helper::Creatorinteractor->getBodyPicked(); + startBody=this->m_interactor->getBodyPicked(); if (startBody.body == 0) return; @@ -50,10 +50,10 @@ void InciseAlongPathPerformer::start() void InciseAlongPathPerformer::execute() { - if (freezePerformer) // This performer has been freezed + if (m_freezePerformer) // This performer has been freezed { if (currentMethod == 1) - startBody=this->interactor->getBodyPicked(); + startBody=this->m_interactor->getBodyPicked(); return; } @@ -85,12 +85,12 @@ void InciseAlongPathPerformer::execute() firstBody = secondBody; secondBody.body = nullptr; - this->interactor->setBodyPicked(secondBody); + this->m_interactor->setBodyPicked(secondBody); } else { - BodyPicked currentBody=this->interactor->getBodyPicked(); + BodyPicked currentBody=this->m_interactor->getBodyPicked(); if (currentBody.body == nullptr || startBody.body == nullptr) return; if (currentBody.indexCollisionElement == startBody.indexCollisionElement) return; @@ -109,14 +109,14 @@ void InciseAlongPathPerformer::execute() firstBody = currentBody; currentBody.body=nullptr; - this->interactor->setBodyPicked(currentBody); + this->m_interactor->setBodyPicked(currentBody); } } void InciseAlongPathPerformer::setPerformerFreeze() { - freezePerformer = true; + m_freezePerformer = true; if (fullcut) this->PerformCompleteIncision(); @@ -207,14 +207,14 @@ InciseAlongPathPerformer::~InciseAlongPathPerformer() if (firstIncisionBody.body) firstIncisionBody.body = nullptr; - this->interactor->setBodyPicked(firstIncisionBody); + this->m_interactor->setBodyPicked(firstIncisionBody); } void InciseAlongPathPerformer::draw(const core::visual::VisualParams* vparams) { if (firstBody.body == nullptr) return; - BodyPicked currentBody=this->interactor->getBodyPicked(); + BodyPicked currentBody=this->m_interactor->getBodyPicked(); sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms* topoGeo; firstBody.body->getContext()->get(topoGeo); diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/InteractionPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/InteractionPerformer.h index b0f6ee0cfc8..7d368ce10e0 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/InteractionPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/InteractionPerformer.h @@ -39,7 +39,7 @@ class SOFA_GUI_COMPONENT_API InteractionPerformer public: typedef helper::Factory InteractionPerformerFactory; - InteractionPerformer(BaseMouseInteractor *i):interactor(i),freezePerformer(0) {} + InteractionPerformer(BaseMouseInteractor *i):m_interactor(i),m_freezePerformer(0) {} virtual ~InteractionPerformer() {} virtual void configure(sofa::component::setting::MouseButtonSetting* /*setting*/) {} @@ -50,15 +50,15 @@ class SOFA_GUI_COMPONENT_API InteractionPerformer virtual void handleEvent(core::objectmodel::Event * ) {} virtual void draw(const core::visual::VisualParams* ) {} - virtual void setPerformerFreeze() {freezePerformer = true;} + virtual void setPerformerFreeze() {m_freezePerformer = true;} template static RealObject* create( RealObject*, BaseMouseInteractor* interactor) { return new RealObject(interactor); } - BaseMouseInteractor *interactor; - bool freezePerformer; + BaseMouseInteractor *m_interactor; + bool m_freezePerformer; }; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/RemovePrimitivePerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/RemovePrimitivePerformer.inl index e6555176610..5dd047b1673 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/RemovePrimitivePerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/RemovePrimitivePerformer.inl @@ -57,7 +57,7 @@ template void RemovePrimitivePerformer::execute() { // - STEP 1: Get body picked and Mstate associated - picked=this->interactor->getBodyPicked(); + picked=this->m_interactor->getBodyPicked(); if (!picked.body) return; mstateCollision = dynamic_cast< core::behavior::MechanicalState* >(picked.body->getContext()->getMechanicalState()); @@ -81,7 +81,7 @@ void RemovePrimitivePerformer::execute() topologyChangeManager.removeItemsFromCollisionModel(model, (int)picked.indexCollisionElement); picked.body=nullptr; - this->interactor->setBodyPicked(picked); + this->m_interactor->setBodyPicked(picked); } else // second case remove a zone of element { @@ -124,7 +124,7 @@ void RemovePrimitivePerformer::execute() // Handle Removing of topological element (from any type of topology) if(topologyModifier) topologyChangeManager.removeItemsFromCollisionModel(model.get(),ElemList_int ); picked.body=nullptr; - this->interactor->setBodyPicked(picked); + this->m_interactor->setBodyPicked(picked); if (surfaceOnVolume) // In the case of deleting a volume from a surface an volumique collision model is needed (only tetra available for the moment) { diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/StartNavigationPerformer.cpp b/Sofa/GUI/Component/src/sofa/gui/component/performer/StartNavigationPerformer.cpp index 162cabdae51..0e61a8f22b1 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/StartNavigationPerformer.cpp +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/StartNavigationPerformer.cpp @@ -35,7 +35,7 @@ namespace sofa::gui::component::performer void StartNavigationPerformer::start() { - const sofa::simulation::Node::SPtr root = down_cast( interactor->getContext()->getRootContext() ); + const sofa::simulation::Node::SPtr root = down_cast( m_interactor->getContext()->getRootContext() ); if(root) { sofa::component::visual::RecordedCamera* currentCamera = root->getNodeObject(); diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/SuturePointPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/SuturePointPerformer.inl index 95a3ce17469..4d51e7d071e 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/SuturePointPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/SuturePointPerformer.inl @@ -44,26 +44,26 @@ void SuturePointPerformer::start() { if (first) //first click { - const BodyPicked picked = this->interactor->getBodyPicked(); + const BodyPicked picked = this->m_interactor->getBodyPicked(); const auto* CollisionModel = dynamic_cast* >(picked.body); if (picked.body == nullptr || CollisionModel == nullptr) { - msg_error(this->interactor) << "No picked body in first clic."; + msg_error(this->m_interactor) << "No picked body in first clic."; return; } - firstPicked = this->interactor->getBodyPicked(); + firstPicked = this->m_interactor->getBodyPicked(); first = false; } else // second click { - const BodyPicked picked = this->interactor->getBodyPicked(); + const BodyPicked picked = this->m_interactor->getBodyPicked(); auto* CollisionModel = dynamic_cast* >(picked.body); if (picked.body == nullptr || CollisionModel == nullptr) { - msg_error(this->interactor) << "No picked body in second clic."; + msg_error(this->m_interactor) << "No picked body in second clic."; return; } @@ -79,27 +79,27 @@ void SuturePointPerformer::start() if (!SpringObject) { - msg_error(this->interactor) << "Can't find StiffSpringForceField."; + msg_error(this->m_interactor) << "Can't find StiffSpringForceField."; return; } else if (!triangleContainer) { - msg_error(this->interactor) << "Can't find a topology."; + msg_error(this->m_interactor) << "Can't find a topology."; return; } else if (triangleContainer->getTriangles().empty()) { - msg_error(this->interactor) << "Can't find a topology with triangles."; + msg_error(this->m_interactor) << "Can't find a topology with triangles."; return; } else if (!MechanicalObject) { - msg_error(this->interactor) << "Can't find MechanicalObject."; + msg_error(this->m_interactor) << "Can't find MechanicalObject."; return; } else if (!FixObject) { - msg_error(this->interactor) << "Can't find FixObject."; + msg_error(this->m_interactor) << "Can't find FixObject."; return; } From f19ca9d1e1378a62e0b4827d6c4d76e41de832b1 Mon Sep 17 00:00:00 2001 From: bakpaul Date: Tue, 9 Apr 2024 16:28:14 +0200 Subject: [PATCH 07/10] Add compatibility layer for attributes renaming --- .../src/sofa/gui/component/AttachBodyButtonSetting.h | 4 ++++ Sofa/GUI/Component/src/sofa/gui/component/config.h.in | 7 +++++++ .../sofa/gui/component/performer/InteractionPerformer.h | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.h b/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.h index c8c99125cf1..36073afc13e 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/AttachBodyButtonSetting.h @@ -40,6 +40,10 @@ class SOFA_GUI_COMPONENT_API AttachBodyButtonSetting: public sofa::component::se Data d_stiffness; ///< Stiffness of the spring to attach a particule Data d_arrowSize; ///< Size of the drawn spring: if >0 an arrow will be drawn Data d_showFactorSize; ///< Show factor size of the JointSpringForcefield when interacting with rigids + + SOFA_ATTRIBUTE_DISABLED__NAMING("v24.06", "v24.06", stiffness, d_stiffness); + SOFA_ATTRIBUTE_DISABLED__NAMING("v24.06", "v24.06", arrowSize, d_arrowSize); + SOFA_ATTRIBUTE_DISABLED__NAMING("v24.06", "v24.06", showFactorSize, d_showFactorSize); }; } // namespace sofa::gui::component diff --git a/Sofa/GUI/Component/src/sofa/gui/component/config.h.in b/Sofa/GUI/Component/src/sofa/gui/component/config.h.in index 191deeb92a0..9f1dd31108c 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/config.h.in +++ b/Sofa/GUI/Component/src/sofa/gui/component/config.h.in @@ -31,6 +31,13 @@ # define SOFA_GUI_COMPONENT_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif +#define SOFA_ATTRIBUTE_DISABLED__NAMING( deprecationDate, disableDate, oldName, newName) \ + SOFA_ATTRIBUTE_DISABLED( \ + deprecationDate, disableDate, \ + "The attribute " sofa_tostring(oldName) " has been renamed to \'" sofa_tostring(newName) "\' to fit naming policy ") \ + DeprecatedAndRemoved oldName + + namespace sofa::gui::component { constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/InteractionPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/InteractionPerformer.h index 7d368ce10e0..c8bbad3f700 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/InteractionPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/InteractionPerformer.h @@ -59,6 +59,10 @@ class SOFA_GUI_COMPONENT_API InteractionPerformer } BaseMouseInteractor *m_interactor; bool m_freezePerformer; + + SOFA_ATTRIBUTE_DISABLED__NAMING("v24.06", "v24.06", interactor,m_interactor); + SOFA_ATTRIBUTE_DISABLED__NAMING("v24.06", "v24.06", freezePerformer,m_freezePerformer); + }; From 68e55e459edaa484ca927cea7501ba317847612e Mon Sep 17 00:00:00 2001 From: bakpaul Date: Tue, 9 Apr 2024 17:42:15 +0200 Subject: [PATCH 08/10] FIX SofaCuda compilation --- .../plugins/SofaCUDA/sofa/gpu/gui/CudaMouseInteraction.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/plugins/SofaCUDA/sofa/gpu/gui/CudaMouseInteraction.cpp b/applications/plugins/SofaCUDA/sofa/gpu/gui/CudaMouseInteraction.cpp index ecda062c638..e016ad089f3 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/gui/CudaMouseInteraction.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/gui/CudaMouseInteraction.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include From b57a8fe403ac826f5e819bb0321453eb2ea897cb Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Fri, 12 Apr 2024 09:31:34 +0200 Subject: [PATCH 09/10] Update Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl Co-authored-by: Hugo --- .../sofa/gui/component/performer/BaseAttachBodyPerformer.inl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl index 3fe9ef74c46..6527bdd96f3 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl @@ -59,12 +59,15 @@ void BaseAttachBodyPerformer::start() double distanceFromMouse=picked.rayLength; this->m_interactor->setDistanceFromMouse(distanceFromMouse); + sofa::component::collision::geometry::Ray ray = this->m_interactor->getMouseRayModel()->getRay(0); ray.setOrigin(ray.origin() + ray.direction()*distanceFromMouse); + sofa::core::BaseMapping *mapping; this->m_interactor->getContext()->get(mapping); assert(mapping); mapping->apply(core::mechanicalparams::defaultInstance()); mapping->applyJ(core::mechanicalparams::defaultInstance()); + m_interactionObject->init(); this->m_interactor->setMouseAttached(true); } From f1643728d860acf193adfa5860adde5218037c66 Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Fri, 12 Apr 2024 09:31:46 +0200 Subject: [PATCH 10/10] Update Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl Co-authored-by: Hugo --- .../gui/component/performer/BaseAttachBodyPerformer.inl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl index 6527bdd96f3..dc9efcc3c2f 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/BaseAttachBodyPerformer.inl @@ -53,9 +53,11 @@ void BaseAttachBodyPerformer::start() return; } const BodyPicked picked=this->m_interactor->getBodyPicked(); - if (!picked.body && !picked.mstate) return; + if (!picked.body && !picked.mstate) + return; - if (!startPartial(picked)) return; //template specialized code is here + if (!startPartial(picked)) //template specialized code is here + return; double distanceFromMouse=picked.rayLength; this->m_interactor->setDistanceFromMouse(distanceFromMouse);