fw4spl
SActivityView.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2017-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 "guiQt/editor/SActivityView.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Signals.hpp>
12 
13 #include <fwGui/dialog/MessageDialog.hpp>
14 #include <fwGui/GuiRegistry.hpp>
15 
16 #include <fwGuiQt/container/QtContainer.hpp>
17 
18 #include <fwServices/macros.hpp>
19 #include <fwServices/registry/AppConfig.hpp>
20 
21 #include <QVBoxLayout>
22 #include <QWidget>
23 
24 namespace guiQt
25 {
26 namespace editor
27 {
28 
29 fwServicesRegisterMacro( ::fwGui::view::IActivityView, ::guiQt::editor::SActivityView );
30 
31 const fwCom::Signals::SignalKeyType s_ACTIVITY_LAUNCHED_SIG = "activityLaunched";
32 
33 //------------------------------------------------------------------------------
34 
36 {
37  m_sigActivityLaunched = newSignal< ActivityLaunchedSignalType >(s_ACTIVITY_LAUNCHED_SIG);
38 }
39 
40 //------------------------------------------------------------------------------
41 
43 {
44 }
45 
46 //------------------------------------------------------------------------------
47 
49 {
51 
52  ::fwGuiQt::container::QtContainer::sptr parentContainer
53  = ::fwGuiQt::container::QtContainer::dynamicCast( this->getContainer() );
54 
55  QVBoxLayout* layout = new QVBoxLayout();
56  QWidget* widget = new QWidget();
57  layout->addWidget( widget );
58 
59  ::fwGuiQt::container::QtContainer::sptr subContainer = ::fwGuiQt::container::QtContainer::New();
60 
61  subContainer->setQtContainer(widget);
62  m_wid = this->getID() + "_container";
63  ::fwGui::GuiRegistry::registerWIDContainer(m_wid, subContainer);
64 
65  parentContainer->setLayout(layout);
66 
67  m_configManager = ::fwServices::IAppConfigManager::New();
68 
69  if (!m_mainActivityId.empty())
70  {
71  ::fwMedData::ActivitySeries::sptr activity = this->createMainActivity();
72  if (activity)
73  {
74  this->launchActivity(activity);
75  }
76  }
77 }
78 
79 //------------------------------------------------------------------------------
80 
82 {
83  if (m_configManager && m_configManager->isStarted())
84  {
85  m_configManager->stopAndDestroy();
86  }
87 
88  ::fwGui::container::fwContainer::sptr subContainer = ::fwGui::GuiRegistry::getWIDContainer(m_wid);
90 
91  subContainer->destroyContainer();
92 
93  this->destroy();
94 }
95 
96 //------------------------------------------------------------------------------
97 
99 {
100 }
101 
102 //------------------------------------------------------------------------------
103 
104 void SActivityView::launchActivity(::fwMedData::ActivitySeries::sptr activitySeries)
105 {
106  if (this->validateActivity(activitySeries))
107  {
108  if (m_configManager->isStarted())
109  {
110  m_configManager->stopAndDestroy();
111  }
113  info = ::fwActivities::registry::Activities::getDefault()->getInfo(activitySeries->getActivityConfigId());
114 
115  ReplaceMapType replaceMap;
116  this->translateParameters(m_parameters, replaceMap);
117  this->translateParameters(activitySeries->getData(), info.appConfig.parameters, replaceMap);
118  replaceMap["AS_UID"] = activitySeries->getID();
119  replaceMap[ "WID_PARENT" ] = m_wid;
120  std::string genericUidAdaptor = ::fwServices::registry::AppConfig::getUniqueIdentifier(info.appConfig.id);
121  replaceMap["GENERIC_UID"] = genericUidAdaptor;
122  try
123  {
124  m_configManager->setConfig( info.appConfig.id, replaceMap );
125  m_configManager->launch();
126 
127  m_sigActivityLaunched->asyncEmit(activitySeries);
128  }
129  catch( std::exception& e )
130  {
131  ::fwGui::dialog::MessageDialog::showMessageDialog("Activity launch failed",
132  e.what(),
133  ::fwGui::dialog::IMessageDialog::CRITICAL);
134  OSLM_ERROR(e.what());
135  }
136  }
137 }
138 
139 //------------------------------------------------------------------------------
140 
141 }// namespace editor
142 }// namespace guiQt
static FWGUI_API::fwGui::container::fwContainer::sptr getWIDContainer(std::string wid)
Returns fwContainer associate with window ID, null if not found.
static FWGUI_API void unregisterWIDContainer(std::string wid)
Unregisters container associate with window ID.
Definition: GuiRegistry.cpp:96
Holds Activities configuration.
Definition: Activities.hpp:175
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
static FWACTIVITIES_API Activities::sptr getDefault()
Return the default global instance of Activities.
Definition: Activities.cpp:226
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
std::string m_mainActivityId
configuration id of the main activity
ParametersType m_parameters
parameters given in configuration
virtual FWGUI_API bool validateActivity(::fwMedData::ActivitySeries::sptr activitySeries) const
Check if the activity is valid by calling the activity validator.
virtual void updating() override
Do nothing.
virtual FWGUI_API::fwMedData::ActivitySeries::sptr createMainActivity() const
Create the activity series given in &#39;mainActivity&#39; configuration.
static FWGUI_API void registerWIDContainer(std::string wid,::fwGui::container::fwContainer::sptr container)
Registers container associate with window ID.
Definition: GuiRegistry.cpp:87
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
GUIQT_API SActivityView()
Constructor. Do nothing.
#define OSLM_ERROR(message)
Definition: spyLog.hpp:274
This editor displays activities in a single view (when a new activity is launched, it replaces the previous one).
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
virtual GUIQT_API ~SActivityView()
Destructor. Do nothing.
static FWSERVICES_API std::shared_ptr< IAppConfigManager > New()
Defines the base class for services displaying activity view.
static FWSERVICES_API std::string getUniqueIdentifier(const std::string &serviceUid="")
Create an unique identifier.
Definition: AppConfig.cpp:269
virtual void starting() override
Install the container.
The namespace guiQt contains the basic services to build the application IHM with Qt...
Definition: Code.hpp:21
virtual void stopping() override
Destroy the container.
virtual FWGUI_API void translateParameters(::fwData::Object::sptr sourceObj, const ParametersType &parameters, ReplaceMapType &replaceMap)
Translate parameters from source object.
virtual FWSERVICES_API void info(std::ostream &_sstream)
Write information in a stream.
Definition: IService.cpp:74