fw4spl
SConfigLauncher.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "gui/action/SConfigLauncher.hpp"
8 
9 #include <fwCom/Signal.hxx>
10 #include <fwCom/Slots.hxx>
11 
12 #include <fwServices/macros.hpp>
13 #include <fwServices/registry/Proxy.hpp>
14 
15 #include <boost/make_unique.hpp>
16 
17 namespace gui
18 {
19 namespace action
20 {
21 
22 //------------------------------------------------------------------------------
23 
24 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::gui::action::SConfigLauncher );
25 
26 const ::fwCom::Signals::SignalKeyType SConfigLauncher::s_LAUNCHED_SIG = "launched";
27 
28 static const ::fwCom::Slots::SlotKeyType s_STOP_CONFIG_SLOT = "stopConfig";
29 
30 static const std::string s_CLOSE_CONFIG_CHANNEL_ID = "CLOSE_CONFIG_CHANNEL";
31 
32 //------------------------------------------------------------------------------
33 
35 {
36  m_configLauncher = ::boost::make_unique< ::fwServices::helper::ConfigLauncher>();
37 
38  m_sigLaunched = newSignal<LaunchedSignalType>(s_LAUNCHED_SIG);
39 
40  newSlot(s_STOP_CONFIG_SLOT, &SConfigLauncher::stopConfig, this);
41 }
42 
43 //------------------------------------------------------------------------------
44 
46 {
47 }
48 
49 //------------------------------------------------------------------------------
50 
52 {
53  m_proxychannel = this->getID() + "_stopConfig";
54 
55  this->actionServiceStarting();
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 {
62  this->stopConfig();
63  this->actionServiceStopping();
64 }
65 
66 //------------------------------------------------------------------------------
67 
69 {
70  this->initialize();
71 
72  m_configLauncher->parseConfig(this->getConfigTree(), this->getSptr());
73 }
74 
75 //-----------------------------------------------------------------------------
76 
77 void SConfigLauncher::setIsActive(bool isActive)
78 {
79  this->::fwGui::IActionSrv::setIsActive(isActive);
80  if ( isActive )
81  {
82  ::fwServices::registry::Proxy::sptr proxies = ::fwServices::registry::Proxy::getDefault();
83  proxies->connect(m_proxychannel, this->slot(s_STOP_CONFIG_SLOT));
84  ::fwServices::helper::ConfigLauncher::FieldAdaptorType replaceMap;
85  replaceMap[s_CLOSE_CONFIG_CHANNEL_ID] = m_proxychannel;
86  m_configLauncher->startConfig(this->getSptr(), replaceMap);
87  m_sigLaunched->asyncEmit();
88  }
89  else
90  {
91  this->stopConfig();
92  }
93 }
94 
95 //------------------------------------------------------------------------------
96 
98 {
99 }
100 
101 //------------------------------------------------------------------------------
102 
104 {
105  if (m_configLauncher->configIsRunning())
106  {
107  m_configLauncher->stopConfig();
108  ::fwServices::registry::Proxy::sptr proxies = ::fwServices::registry::Proxy::getDefault();
109  proxies->disconnect(m_proxychannel, this->slot(s_STOP_CONFIG_SLOT));
110  this->setIsActive(false);
111  }
112 }
113 
114 //------------------------------------------------------------------------------
115 
116 }
117 }
virtual GUI_API ~SConfigLauncher() noexcept
Destructor. Do nothing.
virtual void stopping() override
This method launches the IAction::stopping method.
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
std::string m_proxychannel
Name of the channel used to connect stopConfig slot to the config frame closing.
static FWSERVICES_API Proxy::sptr getDefault()
Returns an instance of Proxy.
Definition: Proxy.cpp:33
The namespace gui contains the basic services to build the application IHM.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
virtual GUI_API void setIsActive(bool isActive) override
Set the action service is activated/disable.
virtual void starting() override
This method launches the IAction::starting method.
This action starts/stops a template configuration.
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
virtual void updating() override
Starts the view and initialize the operator.
virtual FWGUI_API void setIsActive(bool isActive)
Set the action service is active/inactive.
Definition: IActionSrv.cpp:168
FWTOOLS_API IDType getID(Policy policy=GENERATE) const
Returns the id of the object. If it is not set and the policy value is.
Definition: fwID.cpp:78
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
virtual void configuring() override
Declare the configuration to associate with an operator type and a view config.
GUI_API SConfigLauncher() noexcept
Constructor. Do nothing.
void stopConfig()
Slot: stop the config.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247