Skip to content

Commit

Permalink
[IRCtrl] Unactive InterventionalRadiologyController events if a BeamA…
Browse files Browse the repository at this point in the history
…dapterActionController is already linked to it. For backward compatinility
  • Loading branch information
epernod committed Aug 28, 2023
1 parent 695ec39 commit 0a33048
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void BeamAdapterActionController<DataTypes>::init()
{
msg_error() << "No l_interventionController given. Component will be set to Invalid.";
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
return;
}

// the controller must listen to the event (in particular BeginAnimationStep event)
Expand All @@ -58,6 +59,9 @@ void BeamAdapterActionController<DataTypes>::init()
msg_warning() << "WriteMode is set to on but a list of actions has been set as input. The list will be overwritten.";
}

interventionCtrl* ctrl = l_interventionController.get();
ctrl->useBeamAction(true);

this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class InterventionalRadiologyController : public MechanicalStateController<DataT
int getTotalNbEdges()const;

void applyAction(sofa::beamadapter::BeamAdapterAction action);
/// Method to warn this controller that a BeamActionController is controlling the scene. Will bypass the event handling in this component.
void useBeamAction(bool value) { m_useBeamActions = value; }

/// Getter to the tools curviline abscisses sorted @sa m_nodeCurvAbs at the current timestep.
[[nodiscard]] const type::vector<Real>& getCurrentCurvAbscisses() const { return m_nodeCurvAbs; }
Expand Down Expand Up @@ -153,7 +155,7 @@ class InterventionalRadiologyController : public MechanicalStateController<DataT
Data<unsigned int> d_indexFirstNode; // First Node simulated



bool m_useBeamActions = false;
bool m_FF, m_RW, m_sensored;
FixedConstraint<DataTypes> * m_fixedConstraint;
type::vector<int> m_droppedInstruments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ void InterventionalRadiologyController<DataTypes>::onMouseEvent(MouseEvent * mev
template <class DataTypes>
void InterventionalRadiologyController<DataTypes>::onKeyPressedEvent(KeypressedEvent *kev)
{
if (m_useBeamActions)
return;

/// Control keys for interventonal Radiology simulations:
switch(kev->getKey())
{
Expand Down Expand Up @@ -309,6 +312,9 @@ void InterventionalRadiologyController<DataTypes>::onBeginAnimationStep(const do
{
SOFA_UNUSED(dt);

if (m_useBeamActions)
return applyInterventionalRadiologyController();

BaseContext* context = getContext();
auto xInstrTip = sofa::helper::getWriteOnlyAccessor(d_xTip);
if(m_FF || m_RW)
Expand Down

0 comments on commit 0a33048

Please sign in to comment.