diff --git a/src/BeamAdapter/component/controller/BeamAdapterActionController.h b/src/BeamAdapter/component/controller/BeamAdapterActionController.h index 6564e5d1b..d487c906a 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 82f45d019..16d59bcfc 100644 --- a/src/BeamAdapter/component/controller/BeamAdapterActionController.inl +++ b/src/BeamAdapter/component/controller/BeamAdapterActionController.inl @@ -34,8 +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); this->f_printLog.setValue(true); } @@ -104,6 +106,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 +142,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 +161,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