fw4spl
SSeriesViewer.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 "uiMedDataQt/SSeriesViewer.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <fwData/String.hpp>
12 #include <fwData/Vector.hpp>
13 
14 #include <fwDataCamp/getObject.hpp>
15 
16 #include <fwMedData/Series.hpp>
17 
18 #include <fwServices/macros.hpp>
19 #include <fwServices/registry/AppConfig.hpp>
20 
21 namespace uiMedDataQt
22 {
23 
24 //------------------------------------------------------------------------------
25 
26 fwServicesRegisterMacro( ::fwServices::IController, ::uiMedDataQt::SSeriesViewer, ::fwData::Vector);
27 
28 static const ::fwServices::IService::KeyType s_SERIES_INPUT = "series";
29 
30 //------------------------------------------------------------------------------
31 
33 {
34 }
35 
36 //------------------------------------------------------------------------------
37 
39 {
40 }
41 
42 //------------------------------------------------------------------------------
43 
44 void SSeriesViewer::info(std::ostream& _sstream )
45 {
46  // Update message
47  _sstream << std::string("SSeriesViewer");
48 }
49 
50 //------------------------------------------------------------------------------
51 
53 {
54  this->updating();
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
61  if(m_configTemplateManager)
62  {
63  m_configTemplateManager->stopAndDestroy();
64  m_configTemplateManager.reset();
65  }
66 }
67 
68 //------------------------------------------------------------------------------
69 
71 {
72  ::fwData::Vector::csptr vector = this->getInput< ::fwData::Vector >(s_SERIES_INPUT);
73  if (!vector)
74  {
75  FW_DEPRECATED_KEY(s_SERIES_INPUT, "in", "18.0");
76  vector = this->getObject< ::fwData::Vector >();
77  }
78 
79  if(m_configTemplateManager)
80  {
81  m_configTemplateManager->stopAndDestroy();
82  m_configTemplateManager.reset();
83  }
84 
85  if(vector->size() == 1)
86  {
87  ::fwData::Object::sptr obj = vector->front();
88  std::string classname = obj->getClassname();
89  SeriesConfigMapType::iterator itr = m_seriesConfigs.find(classname);
90 
91  if(itr != m_seriesConfigs.end())
92  {
93  SeriesConfigInfo info = itr->second;
94  std::string configId = info.configId;
95 
96  std::map< std::string, std::string > replaceMap;
97  // Generate generic UID
98  std::string genericUidAdaptor = ::fwServices::registry::AppConfig::getUniqueIdentifier( this->getID() );
99  replaceMap["GENERIC_UID"] = genericUidAdaptor;
100  replaceMap["WID_PARENT"] = m_parentView;
101  replaceMap["objectID"] = obj->getID();
102 
103  for(const ReplaceValuesMapType::value_type& elt : info.extractValues)
104  {
105  ::fwData::Object::sptr object = ::fwDataCamp::getObject( obj, elt.second );
106  OSLM_ASSERT("Object from name "<< elt.second <<" not found", object);
107  replaceMap[elt.first] = object->getID();
108  }
109 
110  for(const ReplaceValuesMapType::value_type& elt : info.parameters)
111  {
112  SLM_ASSERT("Value '" << elt.first << "' already used in extracted values.",
113  replaceMap.find(elt.first) == replaceMap.end());
114  replaceMap[elt.first] = elt.second;
115  }
116 
117  // Init manager
118  m_configTemplateManager = ::fwServices::IAppConfigManager::New();
119  m_configTemplateManager->setConfig( configId, replaceMap );
120 
121  // Launch config
122  m_configTemplateManager->launch();
123  }
124  }
125 }
126 
127 //------------------------------------------------------------------------------
128 
130 {
131  std::vector < ::fwRuntime::ConfigurationElement::sptr > viewCfg = m_configuration->find("parentView");
132  SLM_ASSERT("Missing tag 'parentView'", viewCfg.size() == 1);
133 
134  m_parentView = viewCfg[0]->getAttributeValue("wid");
135  SLM_ASSERT("'wid' attribute missing for tag 'parentView'.", !m_parentView.empty());
136 
137  std::vector < ::fwRuntime::ConfigurationElement::sptr > configsCfg = m_configuration->find("configs");
138  SLM_ASSERT("Missing tag 'configs'", configsCfg.size() == 1);
139 
140  std::vector < ::fwRuntime::ConfigurationElement::sptr > config = configsCfg[0]->find("config");
141  SLM_ASSERT("Missing tag 'config'", !config.empty());
142 
143  for(const ::fwRuntime::ConfigurationElement::sptr& elt : config)
144  {
145  SeriesConfigInfo info;
146  info.configId = elt->getAttributeValue("id");
147  SLM_ASSERT("'id' attribute must not be empty", !info.configId.empty());
148  std::string seriesType = elt->getAttributeValue("type");
149  SLM_ASSERT("'type' attribute must not be empty", !seriesType.empty());
150  OSLM_ASSERT("Type " << seriesType << " is already defined.",
151  m_seriesConfigs.find(seriesType) == m_seriesConfigs.end() );
152 
153  for(const ::fwRuntime::ConfigurationElement::sptr& extractElt : elt->find("extract"))
154  {
155  std::string path = extractElt->getAttributeValue("path");
156  SLM_ASSERT("'path' attribute must not be empty", !path.empty());
157  std::string pattern = extractElt->getAttributeValue("pattern");
158  SLM_ASSERT("'pattern' attribute must not be empty", !pattern.empty());
159  info.extractValues[pattern] = path;
160  }
161 
162  for(const ::fwRuntime::ConfigurationElement::sptr& param : elt->find("parameter"))
163  {
164  std::string replace = param->getAttributeValue("replace");
165  SLM_ASSERT("'replace' attribute must not be empty", !replace.empty());
166  std::string by = param->getAttributeValue("by");
167  if(by.empty())
168  {
169  by = param->getAttributeValue("uid");
170  }
171  SLM_ASSERT("'by' attribute must not be empty", !by.empty());
172  info.parameters[replace] = by;
173  }
174 
175  m_seriesConfigs[seriesType] = info;
176  }
177 
178 }
179 
180 //------------------------------------------------------------------------------
181 
183 {
184  KeyConnectionsType connections;
185  connections.push_back( std::make_pair( ::fwData::Vector::s_ADDED_OBJECTS_SIG, s_UPDATE_SLOT ) );
186  connections.push_back( std::make_pair( ::fwData::Vector::s_REMOVED_OBJECTS_SIG, s_UPDATE_SLOT ) );
187 
188  return connections;
189 }
190 
191 //------------------------------------------------------------------------------
192 
194 {
195  KeyConnectionsMap connections;
196 
197  // FIXME hack to support deprecated getObjSrvConnection (connection to a object with a deprecated key)
198  if (this->getInput< ::fwData::Vector >(s_SERIES_INPUT))
199  {
200  connections.push(s_SERIES_INPUT, ::fwData::Vector::s_ADDED_OBJECTS_SIG, s_UPDATE_SLOT);
201  connections.push(s_SERIES_INPUT, ::fwData::Vector::s_REMOVED_OBJECTS_SIG, s_UPDATE_SLOT);
202  }
203 
204  return connections;
205 }
206 
207 //------------------------------------------------------------------------------
208 
209 } // namespace uiMedDataQt
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Definition: spyLog.hpp:366
The namespace uiMedDataQt contains editors for medical data.
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
virtual void stopping() override
Stops the config if it is running.
#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
virtual void starting() override
Calls updating on starting.
virtual UIMEDDATAQT_API ~SSeriesViewer() noexcept
Destructor.
virtual UIMEDDATAQT_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_OBJECTS_SIG
Type of signal when objects are added.
virtual void configuring() override
Configures the service.
This Service allows to preview the selected series in the Vector. For the moment, it works only on a ...
This class defines a vector of objects.
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
This interface defines control service API. Does nothing particularly, can be considered as a default...
Definition: IController.hpp:23
virtual UIMEDDATAQT_API KeyConnectionsType getObjSrvConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
#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
virtual void info(std::ostream &_sstream) override
Write information in a stream.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
::fwCom::helper::SigSlotConnection::KeyConnectionsType KeyConnectionsType
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Definition: IService.hpp:449
UIMEDDATAQT_API SSeriesViewer()
Constructor.
virtual void updating() override
Launch the config on the object if possible.
static const std::string & classname()
return object&#39;s classname without its namespace, i.e. BaseObject
static FWSERVICES_API std::shared_ptr< IAppConfigManager > New()
static FWSERVICES_API std::string getUniqueIdentifier(const std::string &serviceUid="")
Create an unique identifier.
Definition: AppConfig.cpp:269
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_OBJECTS_SIG
Type of signal when objects are added.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Definition: IService.hpp:177