From 092394d10d5971a966e0281d77ed880c698412a9 Mon Sep 17 00:00:00 2001 From: epernod Date: Mon, 5 Jan 2026 16:05:57 +0100 Subject: [PATCH 1/3] Fix keyboard event to change tool --- .../controller/InterventionalRadiologyController.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl index 658da1003..cfcbeeab9 100644 --- a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl +++ b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl @@ -308,13 +308,13 @@ void InterventionalRadiologyController::onKeyPressedEvent(KeypressedE case 'D': applyAction(BeamAdapterAction::DROP_TOOL); break; - case '2': + case '3': applyAction(BeamAdapterAction::USE_TOOL_2); break; - case '1': + case '2': applyAction(BeamAdapterAction::USE_TOOL_1); break; - case '0': + case '1': applyAction(BeamAdapterAction::USE_TOOL_0); break; case 20: // droite = 20 From 0d0e01806019839b0c896b7074fe56fcc01e9cbd Mon Sep 17 00:00:00 2001 From: epernod Date: Mon, 9 Feb 2026 22:40:21 +0100 Subject: [PATCH 2/3] Fix event to export actions --- .../component/controller/BeamAdapterActionController.inl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/BeamAdapter/component/controller/BeamAdapterActionController.inl b/src/BeamAdapter/component/controller/BeamAdapterActionController.inl index 16c4249eb..660e81370 100644 --- a/src/BeamAdapter/component/controller/BeamAdapterActionController.inl +++ b/src/BeamAdapter/component/controller/BeamAdapterActionController.inl @@ -77,7 +77,8 @@ void BeamAdapterActionController::onKeyPressedEvent(core::objectmodel case 'E': m_currAction = BeamAdapterAction::NO_ACTION; - m_exportActions = !m_exportActions; + std::cout << "timeSteps='" << d_timeSteps.getValue() << "'" << std::endl; + std::cout << "actions='" << d_actions.getValue() << "'" << std::endl; break; case 'D': m_currAction = BeamAdapterAction::DROP_TOOL; @@ -138,12 +139,6 @@ void BeamAdapterActionController::onBeginAnimationStep(const double / times.push_back(currentTime); actions.push_back(int(m_currAction)); - if (m_exportActions) - { - std::cout << "timeSteps='" << times.wref() << "'" << std::endl; - std::cout << "actions='" << actions.wref() << "'" << std::endl; - } - m_lastAction = m_currAction; } else From 3690563d43d83e73cd296c21657c2ad0ca508962 Mon Sep 17 00:00:00 2001 From: epernod Date: Fri, 3 Jul 2026 15:41:03 +0200 Subject: [PATCH 3/3] [src] Add new actions to be able to record and replay actions such as drilling, inflate, deflate --- .../controller/BeamAdapterActionController.h | 1 + .../controller/BeamAdapterActionController.inl | 18 +++++++++++++++--- src/BeamAdapter/utils/BeamActions.h | 7 ++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/BeamAdapter/component/controller/BeamAdapterActionController.h b/src/BeamAdapter/component/controller/BeamAdapterActionController.h index 9a98263f6..79d0d9e87 100644 --- a/src/BeamAdapter/component/controller/BeamAdapterActionController.h +++ b/src/BeamAdapter/component/controller/BeamAdapterActionController.h @@ -68,6 +68,7 @@ class BeamAdapterActionController : public sofa::component::controller::Mechanic Data > d_actions; ///< List of actions to import or export. Data > d_actionString; ///< List of actions to import or export as string. Data > d_timeSteps; ///< List of key times corresponding to BeamActions in @sa d_actions or @sa d_actionString + Data < int > d_currentAction; ///< current action status for read only from outside of the component. Will be updated at each timestep. /// Link to the InterventionalRadiologyController, controlling the Beam, to script. SingleLink, InterventionalRadiologyController, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_interventionController; diff --git a/src/BeamAdapter/component/controller/BeamAdapterActionController.inl b/src/BeamAdapter/component/controller/BeamAdapterActionController.inl index 660e81370..1f238c3c1 100644 --- a/src/BeamAdapter/component/controller/BeamAdapterActionController.inl +++ b/src/BeamAdapter/component/controller/BeamAdapterActionController.inl @@ -34,9 +34,10 @@ BeamAdapterActionController::BeamAdapterActionController() , d_actions(initData(&d_actions, "actions", "List of actions to script the BeamAdapter")) , d_actionString(initData(&d_actionString, "actionString", "List of actions as string to script the BeamAdapter")) , d_timeSteps(initData(&d_timeSteps, "timeSteps", "List of key times corresponding to the actions")) + , d_currentAction(initData(&d_currentAction, 0, "currentAction", "Current action applied to the BeamAdapter")) , l_interventionController(initLink("interventionController", "Path to the InterventionalRadiologyController component on scene")) { - + d_currentAction.setReadOnly(true); } template @@ -104,6 +105,12 @@ void BeamAdapterActionController::onKeyPressedEvent(core::objectmodel case 21: // bas = 21 m_currAction = BeamAdapterAction::MOVE_BACKWARD; break; + case 'I': + m_currAction = BeamAdapterAction::ACTIVATE_TOOL; + break; + case 'O': + m_currAction = BeamAdapterAction::DEACTIVATE_TOOL; + break; default: m_currAction = BeamAdapterAction::NO_ACTION; break; @@ -134,10 +141,13 @@ void BeamAdapterActionController::onBeginAnimationStep(const double / ctrl->applyAction(m_currAction); + int currentActionInt = int(m_currAction); + d_currentAction.setValue(currentActionInt); + auto times = sofa::helper::WriteAccessor(d_timeSteps); auto actions = sofa::helper::WriteAccessor(d_actions); times.push_back(currentTime); - actions.push_back(int(m_currAction)); + actions.push_back(currentActionInt); m_lastAction = m_currAction; } @@ -150,10 +160,12 @@ void BeamAdapterActionController::onBeginAnimationStep(const double / if (currentTime >= time) // check if another key time has been reached and change action { - m_currAction = BeamAdapterAction(d_actions.getValue()[m_readStep]); + int currentActionInt = d_actions.getValue()[m_readStep]; + m_currAction = BeamAdapterAction(currentActionInt); m_readStep++; ctrl->applyAction(m_currAction); + d_currentAction.setValue(currentActionInt); } } } diff --git a/src/BeamAdapter/utils/BeamActions.h b/src/BeamAdapter/utils/BeamActions.h index 531a1cc0c..69ef7bae9 100644 --- a/src/BeamAdapter/utils/BeamActions.h +++ b/src/BeamAdapter/utils/BeamActions.h @@ -41,6 +41,8 @@ namespace beamadapter USE_TOOL_0, USE_TOOL_1, USE_TOOL_2, + ACTIVATE_TOOL, + DEACTIVATE_TOOL }; /// \brief map of action as string keyword instead of int for better clarity in scene scripting @@ -49,12 +51,15 @@ namespace beamadapter {"fwd", BeamAdapterAction::MOVE_FORWARD}, {"bwd", BeamAdapterAction::MOVE_BACKWARD}, {"right", BeamAdapterAction::SPIN_RIGHT}, + {"left", BeamAdapterAction::SPIN_LEFT}, {"nextT", BeamAdapterAction::SWITCH_NEXT_TOOL}, {"prevT", BeamAdapterAction::SWITCH_PREVIOUS_TOOL}, {"dropT", BeamAdapterAction::DROP_TOOL}, {"tool0", BeamAdapterAction::USE_TOOL_0}, {"tool1", BeamAdapterAction::USE_TOOL_1}, - {"tool2", BeamAdapterAction::USE_TOOL_2} + {"tool2", BeamAdapterAction::USE_TOOL_2}, + {"activate", BeamAdapterAction::ACTIVATE_TOOL}, + {"deactivate", BeamAdapterAction::DEACTIVATE_TOOL} }; /// static method to convert an action as string into enum class using @sa beamActionNames