7 #include "fwGui/IActionSrv.hpp" 9 #include "fwGui/dialog/IMessageDialog.hpp" 10 #include "fwGui/dialog/MessageDialog.hpp" 12 #include <fwCom/Signal.hxx> 13 #include <fwCom/Slot.hxx> 14 #include <fwCom/Slots.hxx> 16 #include <fwServices/macros.hpp> 18 #include <fwTools/fwID.hpp> 38 IActionSrv::IActionSrv() :
39 m_activeStateValue(true),
43 m_confirmAction(false)
45 newSlot(s_SET_IS_ACTIVE_SLOT, &IActionSrv::setIsActive,
this);
46 newSlot(s_ACTIVATE_SLOT, &IActionSrv::activate,
this);
47 newSlot(s_DEACTIVATE_SLOT, &IActionSrv::deactivate,
this);
48 newSlot(s_SET_IS_EXECUTABLE_SLOT, &IActionSrv::setIsExecutable,
this);
49 newSlot(s_SET_EXECUTABLE_SLOT, &IActionSrv::setExecutable,
this);
50 newSlot(s_SET_INEXECUTABLE_SLOT, &IActionSrv::setInexecutable,
this);
51 newSlot(s_SET_VISIBLE_SLOT, &IActionSrv::setVisible,
this);
52 newSlot(s_SHOW_SLOT, &IActionSrv::show,
this);
53 newSlot(s_HIDE_SLOT, &IActionSrv::hide,
this);
55 m_sigEnabled = newSignal< EnabledSignalType >(s_ENABLED_SIG);
56 m_sigDisabled = newSignal< DisabledSignalType >(s_DISABLED_SIG);
57 m_sigChecked = newSignal< CheckedSignalType >(s_CHECKED_SIG);
58 m_sigUnchecked = newSignal< UncheckedSignalType >(s_UNCHECKED_SIG);
63 IActionSrv::~IActionSrv()
69 void IActionSrv::initialize()
71 m_registrar = ::fwGui::registrar::ActionRegistrar::New(this->getID());
73 OSLM_ASSERT(
"Depreciated tag <name> in "<< this->getID() <<
" configuration.", !m_configuration->hasAttribute(
75 OSLM_ASSERT(
"Depreciated tag <shortcut> in "<< this->getID() <<
" configuration.",
76 !m_configuration->hasAttribute(
"shortcut"));
77 OSLM_ASSERT(
"Depreciated tag <enable> in "<< this->getID() <<
" configuration.",
78 !m_configuration->hasAttribute(
"enable"));
80 "Depreciated tag <specialAction> in "<< this->getID() <<
" configuration.",
81 !m_configuration->hasAttribute(
"specialAction"));
82 OSLM_ASSERT(
"Depreciated tag <style> in "<< this->getID() <<
" configuration.",
83 !m_configuration->hasAttribute(
"style"));
84 OSLM_ASSERT(
"Depreciated tag <state> in "<< this->getID() <<
" configuration.",
85 !m_configuration->hasAttribute(
"state"));
88 for( iter = m_configuration->begin(); iter != m_configuration->end(); ++iter )
90 if( (*iter)->getName() ==
"state" )
92 ConfigurationType stateCfg = *iter;
94 if( stateCfg->hasAttribute(
"inverse") )
96 std::string invertState = stateCfg->getExistingAttributeValue(
"inverse");
97 SLM_ASSERT(
"Wrong attribute value : must be 'true' or 'false'",
98 (invertState ==
"true") || (invertState ==
"false"));
99 m_activeStateValue = !(invertState ==
"true");
102 if( stateCfg->hasAttribute(
"active") )
104 std::string isActive = stateCfg->getExistingAttributeValue(
"active");
105 SLM_ASSERT(
"Wrong attribute value : must be 'true' or 'false'",
106 (isActive ==
"true") || (isActive ==
"false"));
107 m_isActive = (isActive ==
"true");
110 if( stateCfg->hasAttribute(
"executable") )
112 std::string isExecutable = stateCfg->getExistingAttributeValue(
"executable");
113 SLM_ASSERT(
"Wrong attribute value : must be 'true' or 'false'",
114 (isExecutable ==
"true") || (isExecutable ==
"false"));
115 m_isExecutable = (isExecutable ==
"true");
118 if( stateCfg->hasAttribute(
"visible") )
120 std::string isVisible = stateCfg->getExistingAttributeValue(
"visible");
121 SLM_ASSERT(
"Wrong attribute value : must be 'true' or 'false'",
122 (isVisible ==
"true") || (isVisible ==
"false"));
123 m_isVisible = (isVisible ==
"true");
127 if( (*iter)->getName() ==
"confirmation" )
129 ConfigurationType cfg = *iter;
131 SLM_ASSERT(
"Missing attribute 'value'", cfg->hasAttribute(
"value"));
132 std::string confirm = cfg->getExistingAttributeValue(
"value");
133 SLM_ASSERT(
"Wrong attribute value : must be 'true' or 'false'",
134 (confirm ==
"true") || (confirm ==
"false"));
135 m_confirmAction = (confirm ==
"true");
137 if( cfg->hasAttribute(
"message") )
139 m_confirmMessage = cfg->getExistingAttributeValue(
"message");
142 if( cfg->hasAttribute(
"defaultbutton") )
144 m_defaultButton = cfg->getExistingAttributeValue(
"defaultbutton");
153 void IActionSrv::actionServiceStopping()
155 this->m_registrar->actionServiceStopping();
160 void IActionSrv::actionServiceStarting()
162 this->m_registrar->actionServiceStarting();
163 this->setIsActive(m_isActive);
168 void IActionSrv::setIsActive(
bool isActive)
170 m_isActive = isActive;
171 this->m_registrar->actionServiceSetActive(m_activeStateValue == isActive);
174 m_sigChecked->asyncEmit();
178 m_sigUnchecked->asyncEmit();
184 void IActionSrv::activate()
186 this->setIsActive(
true);
191 void IActionSrv::deactivate()
193 this->setIsActive(
false);
198 bool IActionSrv::getIsActive()
const 205 void IActionSrv::setIsExecutable(
bool isExecutable)
207 m_isExecutable = isExecutable;
208 this->m_registrar->actionServiceSetExecutable(isExecutable);
211 m_sigEnabled->asyncEmit();
215 m_sigDisabled->asyncEmit();
221 void IActionSrv::setExecutable()
223 this->setIsExecutable(
true);
228 void IActionSrv::setInexecutable()
230 this->setIsExecutable(
false);
235 bool IActionSrv::getIsExecutable()
const 237 return m_isExecutable;
242 void IActionSrv::setVisible(
bool isVisible)
244 m_isVisible = isVisible;
245 this->m_registrar->actionServiceSetVisible(isVisible);
250 void IActionSrv::show()
252 this->setVisible(
true);
257 void IActionSrv::hide()
259 this->setVisible(
false);
264 bool IActionSrv::isVisible()
const 271 bool IActionSrv::confirmAction()
273 bool actionIsConfirmed =
true;
279 std::stringstream ss;
280 ss <<
"Do you really want to execute this action ? ";
281 if (!m_confirmMessage.empty())
283 ss << std::endl << m_confirmMessage;
287 if(m_defaultButton ==
"yes")
291 else if(m_defaultButton ==
"no")
295 else if(!m_defaultButton.empty())
297 SLM_WARN(
"unknown button: " + m_defaultButton);
300 dialog.
setIcon( ::fwGui::dialog::IMessageDialog::QUESTION );
301 dialog.
addButton( ::fwGui::dialog::IMessageDialog::YES_NO );
304 actionIsConfirmed = (button == ::fwGui::dialog::IMessageDialog::YES);
307 return actionIsConfirmed;
static const ::fwCom::Slots::SlotKeyType s_SET_VISIBLE_SLOT
Slot to show/hide the action.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
The namespace fwGui contains the base interface for IHM services.
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
Defines the generic message box for IHM. Use the Delegate design pattern.
static const ::fwCom::Signals::SignalKeyType s_DISABLED_SIG
Signal emitted when action is enabled.
static const ::fwCom::Signals::SignalKeyType s_CHECKED_SIG
Signal emitted when action is enabled.
#define SLM_WARN(message)
static const ::fwCom::Slots::SlotKeyType s_SET_INEXECUTABLE_SLOT
Slot to disable the action.
static const ::fwCom::Slots::SlotKeyType s_HIDE_SLOT
Slot to disable the action.
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
static const ::fwCom::Slots::SlotKeyType s_SET_EXECUTABLE_SLOT
Slot to enable the action.
static const ::fwCom::Slots::SlotKeyType s_SET_IS_ACTIVE_SLOT
Slot to activate/deactivate the action.
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static const ::fwCom::Signals::SignalKeyType s_UNCHECKED_SIG
Signal emitted when action is enabled.
static const ::fwCom::Slots::SlotKeyType s_DEACTIVATE_SLOT
Slot to desactivate the action.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
virtual FWGUI_API void setDefaultButton(IMessageDialog::Buttons button) override
Set the default button.
static const ::fwCom::Slots::SlotKeyType s_ACTIVATE_SLOT
Slot to activate the action.
static const ::fwCom::Slots::SlotKeyType s_SHOW_SLOT
Slot to disable the action.
Container::iterator Iterator
Defines the configuration element container type.
static const ::fwCom::Signals::SignalKeyType s_ENABLED_SIG
Signal emitted when action is enabled.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
static const ::fwCom::Slots::SlotKeyType s_SET_IS_EXECUTABLE_SLOT
Slot to enable/disable the action.