diff --git a/src/sofa/igtlink/utils/iGTLinkMouseInteractor.cpp b/src/sofa/igtlink/utils/iGTLinkMouseInteractor.cpp new file mode 100644 index 0000000..32e4577 --- /dev/null +++ b/src/sofa/igtlink/utils/iGTLinkMouseInteractor.cpp @@ -0,0 +1,11 @@ +#include +#include + +namespace sofa::openigtlink { + +SOFA_DECL_CLASS(iGTLinkMouseInteractor) + +int iGTLinkMouseInteractorClass = core::RegisterObject("") + .add(true); + +} \ No newline at end of file diff --git a/src/sofa/igtlink/utils/iGTLinkMouseInteractor.h b/src/sofa/igtlink/utils/iGTLinkMouseInteractor.h new file mode 100644 index 0000000..ea5a4a1 --- /dev/null +++ b/src/sofa/igtlink/utils/iGTLinkMouseInteractor.h @@ -0,0 +1,44 @@ +#pragma once +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +namespace sofa::openigtlink { + +class iGTLinkMouseInteractor : public sofa::gui::component::performer::MouseInteractor { +public: + SOFA_CLASS(iGTLinkMouseInteractor, SOFA_TEMPLATE(sofa::gui::component::performer::MouseInteractor, defaulttype::Vec3Types)); + + Data d_positions; + Data< sofa::helper::OptionsGroup > d_pickingType; + Data< double > d_springStiffness; + Data< unsigned > d_reactionTime; + + iGTLinkMouseInteractor(); + + void updatePosition( SReal dt) override; + + void positionChanged(); + void attachmentChanged(); + void handleEvent(sofa::core::objectmodel::Event *event); + +private: + sofa::core::objectmodel::DataCallback c_positions; + sofa::core::objectmodel::DataCallback c_attachmentType; + std::chrono::high_resolution_clock::time_point m_lastChange; + + + +}; + +} \ No newline at end of file diff --git a/src/sofa/igtlink/utils/iGTLinkMouseInteractor.inl b/src/sofa/igtlink/utils/iGTLinkMouseInteractor.inl new file mode 100644 index 0000000..96b76ae --- /dev/null +++ b/src/sofa/igtlink/utils/iGTLinkMouseInteractor.inl @@ -0,0 +1,70 @@ +#pragma once + +#include +#include + + +namespace sofa::openigtlink +{ + +iGTLinkMouseInteractor::iGTLinkMouseInteractor() +: d_pickingType(initData(&d_pickingType,"pickingType","Mouse interaction type, could be \'constraint\' or \'spring\'")) +, d_positions(initData(&d_positions, "position", "Position")) +, d_springStiffness(initData(&d_springStiffness,10.0,"springStiffness","Stiffness of attachment spring used for interaction")) +, d_reactionTime(initData(&d_reactionTime,20u, "reactionTime", "Time in milisecond of no change in the position to output a null stiffness")) +{ + sofa::helper::OptionsGroup m_newoptiongroup{"constraint","spring"}; + m_newoptiongroup.setSelectedItem("spring"); + d_pickingType.setValue(m_newoptiongroup); + + this->f_listening.setValue(true); + + c_positions.addInput(&d_positions); + c_positions.addCallback(std::bind(&iGTLinkMouseInteractor::positionChanged,this)); + + c_attachmentType.addInput(&d_pickingType); + c_attachmentType.addCallback(std::bind(&iGTLinkMouseInteractor::attachmentChanged,this)); + + m_lastChange = std::chrono::high_resolution_clock::now(); + //Make sure the constraint is inactive + +} + + +void iGTLinkMouseInteractor::positionChanged() +{ + m_lastChange = std::chrono::high_resolution_clock::now(); +} + +void iGTLinkMouseInteractor::attachmentChanged() +{ + //Change performer +} + + +void iGTLinkMouseInteractor::updatePosition( SReal dt) +{ + SOFA_UNUSED(dt); + //Do nothing +} + + +void iGTLinkMouseInteractor::handleEvent(sofa::core::objectmodel::Event *event) +{ + if (dynamic_cast(event)) + { + std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); + if (std::chrono::duration_cast(now - m_lastChange).count() > d_reactionTime.getValue()) + { + //Deactivate the constraint + //Reproduce the start emthod from performer here. + } + else + { + //Activate the constraint + //Clear the performer + } + } +} + +} \ No newline at end of file