From bd1eb54302d454dc27fc29310811d0ddc6430b3b Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Thu, 10 Jul 2025 14:02:11 +0200 Subject: [PATCH 1/2] [Response] Clean init of CollisionResponse --- .../response/contact/CollisionResponse.cpp | 22 +++++++++++++++---- .../response/contact/CollisionResponse.h | 1 - 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp index c225ffa731c..043c7f0c620 100644 --- a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp +++ b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp @@ -62,19 +62,34 @@ sofa::helper::OptionsGroup CollisionResponse::initializeResponseOptions(sofa::co } sofa::helper::OptionsGroup responseOptions(listResponse); - if (listResponse.contains("PenalityContactForceField")) - responseOptions.setSelectedItem("PenalityContactForceField"); - return responseOptions; } void CollisionResponse::init() { + Inherit1::init(); + + if(!d_response.isSet()) + { + msg_error() << "No response method has been set. Default response=\"PenalityContactForceField\""; + setDefaultResponseType("PenalityContactForceField"); + return; + } + if (d_response.getValue().size() == 0) { + msg_error() << "Response method is empty and may have been wrongly set. Option list is: " << initializeResponseOptions(getContext()); d_response.setValue(initializeResponseOptions(getContext())); } + else + { + sofa::helper::OptionsGroup responseOptions = initializeResponseOptions(getContext()); + if(!responseOptions.isInOptionsList(d_response.getValue().getSelectedItem())) + { + msg_error() << "response \"" << d_response.getValue().getSelectedItem() << "\" is not a valid response method. Response can be among the list: " << responseOptions; + } + } } void CollisionResponse::cleanup() @@ -111,7 +126,6 @@ void CollisionResponse::setDefaultResponseType(const std::string &responseT) } } - void CollisionResponse::changeInstance(Instance inst) { core::collision::ContactManager::changeInstance(inst); diff --git a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.h b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.h index 9a6ee36d869..b6123be8ff3 100644 --- a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.h +++ b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.h @@ -112,7 +112,6 @@ public : /// The number of contacts corresponds to the number of collision models /// currently in contact with a collision model. void setNumberOfContacts() const; - }; From cce486762567e56271f363b991048e2bfbf9b97d Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Thu, 10 Jul 2025 15:26:04 +0200 Subject: [PATCH 2/2] [Helper] Remove default value on OptionGroup --- .../collision/response/contact/CollisionResponse.cpp | 6 +++++- Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp | 6 ++++-- Sofa/framework/Helper/src/sofa/helper/OptionsGroup.h | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp index 043c7f0c620..f62192f7f1c 100644 --- a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp +++ b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/CollisionResponse.cpp @@ -87,7 +87,11 @@ void CollisionResponse::init() sofa::helper::OptionsGroup responseOptions = initializeResponseOptions(getContext()); if(!responseOptions.isInOptionsList(d_response.getValue().getSelectedItem())) { - msg_error() << "response \"" << d_response.getValue().getSelectedItem() << "\" is not a valid response method. Response can be among the list: " << responseOptions; + msg_error() << "response method is not a valid response method. Response can be among the list: " << responseOptions.getItemNames(); + } + else + { + msg_info() << "Valid response method: " << d_response.getValue().getSelectedItem(); } } } diff --git a/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp b/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp index daf5e8afda8..bd673fa2335 100644 --- a/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp @@ -31,7 +31,6 @@ class OptionsGroup; ////////////////////////////////////////////////////////////////////////////////////////////////////// OptionsGroup::OptionsGroup() : textItems() { - selectedItem=0; } /////////////////////////////////////// OptionsGroup::OptionsGroup(const OptionsGroup & m_radiotrick) : textItems(m_radiotrick.textItems) @@ -42,12 +41,15 @@ OptionsGroup::OptionsGroup(const OptionsGroup & m_radiotrick) : textItems(m_radi void OptionsGroup::setNbItems(const size_type nbofRadioButton ) { textItems.resize( nbofRadioButton ); - selectedItem = 0; } /////////////////////////////////////// void OptionsGroup::setItemName(const unsigned int id_item, const std::string& name ) { textItems[id_item] = name; +}/////////////////////////////////////// +type::vector OptionsGroup::getItemNames() +{ + return textItems; } /////////////////////////////////////// int OptionsGroup::isInOptionsList(const std::string & tempostring) const diff --git a/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.h b/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.h index c1a84dad32a..a86ac7f59a4 100644 --- a/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.h +++ b/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.h @@ -71,6 +71,9 @@ public : ///Set the name of the id-th item void setItemName( unsigned int id_item, const std::string& name ); + ///Get the vector of names available + type::vector getItemNames(); + template void setNames(const std::initializer_list& list);