fw4spl
SModifyLayout.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/SModifyLayout.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <fwGui/dialog/MessageDialog.hpp>
12 #include <fwGui/GuiRegistry.hpp>
13 #include <fwGui/IGuiContainerSrv.hpp>
14 
15 #include <fwRuntime/Extension.hpp>
16 #include <fwRuntime/helper.hpp>
17 
18 #include <fwServices/macros.hpp>
19 #include <fwServices/op/Get.hpp>
20 
21 #include <fwTools/fwID.hpp>
22 
23 namespace gui
24 {
25 namespace action
26 {
27 
28 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::gui::action::SModifyLayout );
29 
30 //-----------------------------------------------------------------------------
31 
33 {
34 }
35 
36 //-----------------------------------------------------------------------------
37 
39 {
40 }
41 
42 //-----------------------------------------------------------------------------
43 
45 {
47  this->actionServiceStarting();
48 }
49 
50 //-----------------------------------------------------------------------------
51 
53 {
55  this->actionServiceStopping();
56 }
57 
58 //-----------------------------------------------------------------------------
59 
60 void SModifyLayout::info(std::ostream& _sstream )
61 {
62  _sstream << "Starter Action" << std::endl;
63 }
64 
65 //-----------------------------------------------------------------------------
66 
68 {
70 
71  for(MoveSrvVectType::value_type elt : m_moveSrv )
72  {
73  std::string uid = elt.first;
74  std::string wid = elt.second;
75  OSLM_ASSERT( uid << " doesn't exist", ::fwTools::fwID::exist(uid) );
76  ::fwServices::IService::sptr service = ::fwServices::get( uid );
77  SLM_ASSERT("service not found", service);
78  ::fwGui::IGuiContainerSrv::sptr container = ::fwGui::IGuiContainerSrv::dynamicCast(service);
79  SLM_ASSERT("::fwGui::IGuiContainerSrv dynamicCast failed", container);
80 
81  container->setParent(wid);
82  service->update();
83  }
84 
85  for(EnableSrvVectType::value_type elt : m_enableSrv )
86  {
87  std::string uid = elt.first;
88  bool isEnable = elt.second;
89  OSLM_ASSERT( uid << " doesn't exist", ::fwTools::fwID::exist(uid) );
90  ::fwServices::IService::sptr service = ::fwServices::get( uid );
91  SLM_ASSERT("service not found", service);
92  if(service->isStarted())
93  {
94  ::fwGui::IGuiContainerSrv::sptr containerSrv = ::fwGui::IGuiContainerSrv::dynamicCast(service);
95  if(containerSrv)
96  {
97  containerSrv->getContainer()->setEnabled(isEnable);
98  }
99  ::fwGui::IActionSrv::sptr actionSrv = ::fwGui::IActionSrv::dynamicCast(service);
100  if(actionSrv)
101  {
102  actionSrv->setIsExecutable(isEnable);
103  }
104  }
105  }
106 
107  for(ShowSrvVectType::value_type elt : m_showSrvWid)
108  {
109  std::string wid = elt.first;
110  ::boost::logic::tribool isVisible = elt.second;
111  ::fwGui::container::fwContainer::sptr container = ::fwGui::GuiRegistry::getWIDContainer(wid);
112  OSLM_ASSERT("::fwGui::IGuiContainerSrv " << wid << " is unknown", container);
113 
114  if(isVisible)
115  {
116  container->setVisible(true);
117  }
118  else if(!isVisible)
119  {
120  container->setVisible(false);
121  }
122  else
123  {
124  container->setVisible(this->getIsActive());
125  }
126  }
127 
128  for(ShowSrvVectType::value_type elt : m_showSrvSid)
129  {
130  std::string uid = elt.first;
131  ::boost::logic::tribool isVisible = elt.second;
132  OSLM_ASSERT( uid << " doesn't exist", ::fwTools::fwID::exist(uid) );
133  ::fwServices::IService::sptr service = ::fwServices::get( uid );
134 
135  ::fwGui::IGuiContainerSrv::sptr containerSrv = ::fwGui::IGuiContainerSrv::dynamicCast(service);
136  SLM_ASSERT("::fwGui::IGuiContainerSrv dynamicCast failed", containerSrv);
137 
138  ::fwGui::container::fwContainer::sptr container = containerSrv->getContainer();
139 
140  if(isVisible)
141  {
142  container->setVisible(true);
143  }
144  else if(!isVisible)
145  {
146  container->setVisible(false);
147  }
148  else
149  {
150  container->setVisible(this->getIsActive());
151  }
152  }
153 }
154 
155 //-----------------------------------------------------------------------------
156 
158 {
159  SLM_TRACE_FUNC();
160  this->initialize();
161  std::vector < ConfigurationType > vectConfig = m_configuration->find("config");
162  if( !vectConfig.empty() )
163  {
164  ConfigurationType config = vectConfig.at(0);
165  for(ConfigurationType actionCfg : config->getElements() )
166  {
167  if(actionCfg->getName() == "move")
168  {
169  SLM_ASSERT("Attribute uid missing", actionCfg->hasAttribute("uid"));
170  std::string uuid = actionCfg->getExistingAttributeValue("uid");
171  SLM_ASSERT("Attribute wid missing", actionCfg->hasAttribute("wid"));
172  std::string wid = actionCfg->getExistingAttributeValue("wid");
173 
174  m_moveSrv.push_back( std::make_pair(uuid, wid) );
175  }
176  else if(actionCfg->getName() == "show"
177  || actionCfg->getName() == "hide"
178  || actionCfg->getName() == "show_or_hide")
179  {
180  ::boost::logic::tribool isVisible;
181  if (actionCfg->getName() == "show")
182  {
183  isVisible = true;
184  }
185  else if (actionCfg->getName() == "hide")
186  {
187  isVisible = false;
188  }
189  else
190  {
191  isVisible = ::boost::logic::indeterminate;
192  }
193 
194  if(actionCfg->hasAttribute("wid"))
195  {
196  std::string wid = actionCfg->getExistingAttributeValue("wid");
197  m_showSrvWid.push_back( std::make_pair(wid, isVisible) );
198  }
199  else if(actionCfg->hasAttribute("sid"))
200  {
201  std::string sid = actionCfg->getExistingAttributeValue("sid");
202  m_showSrvSid.push_back( std::make_pair(sid, isVisible) );
203  }
204  else
205  {
206  SLM_ERROR("Attribute wid or sid missing");
207  }
208  }
209  else if(actionCfg->getName() == "enable" || actionCfg->getName() == "disable")
210  {
211  SLM_ASSERT("Attribute uid missing", actionCfg->hasAttribute("uid"));
212  std::string uuid = actionCfg->getExistingAttributeValue("uid");
213  bool isEnable = (actionCfg->getName() == "enable");
214 
215  m_enableSrv.push_back( std::make_pair(uuid, isEnable) );
216  }
217  else
218  {
219  OSLM_FATAL( "Invalid tag name "<<actionCfg->getName());
220  }
221  }
222  }
223 }
224 
225 //-----------------------------------------------------------------------------
226 
227 } // namespace action
228 } // namespace gui
static FWGUI_API::fwGui::container::fwContainer::sptr getWIDContainer(std::string wid)
Returns fwContainer associate with window ID, null if not found.
virtual GUI_API ~SModifyLayout() noexcept
Destructor. Do nothing.
virtual GUI_API void starting() override
Initialize the service activity.
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
The namespace gui contains the basic services to build the application IHM.
FWGUI_API bool isVisible() const
Returns true if action is visible.
Definition: IActionSrv.cpp:264
static FWTOOLS_API bool exist(IDType _id)
Definition: fwID.cpp:33
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
This action is used to modify the layout configuration.
FWGUI_API bool getIsActive() const
Return true if action service is active.
Definition: IActionSrv.cpp:198
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
#define SLM_ERROR(message)
Definition: spyLog.hpp:272
virtual GUI_API void info(std::ostream &_sstream) override
This method gives information about the class. Do nothing.
GUI_API void configuring() override
This method is used to configure the service parameters: specifies which views to show/hide/mode...
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
#define OSLM_FATAL(message)
Definition: spyLog.hpp:285
GUI_API SModifyLayout() noexcept
Constructor. Do nothing.
virtual GUI_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
GUI_API void updating() override
This method starts-updates or stops the specified services.