fw4spl
ActivityMsg.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2015-2017.
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 "fwActivities/registry/ActivityMsg.hpp"
8 
9 #include <fwData/Composite.hpp>
10 #include <fwData/String.hpp>
11 
12 #include <fwDataCamp/getObject.hpp>
13 
14 #include <fwTools/UUID.hpp>
15 
16 #include <boost/algorithm/string/replace.hpp>
17 #include <boost/regex.hpp>
18 
19 namespace fwActivities
20 {
21 namespace registry
22 {
23 
24 //-----------------------------------------------------------------------------
25 
26 ActivityMsg::ActivityMsg(const ::fwMedData::ActivitySeries::sptr& series,
27  const ::fwActivities::registry::ActivityInfo& info,
28  const ParametersType& parameters)
29 {
30  SLM_ASSERT("ActivitySeries instantiation failed", series);
31 
32  const std::string asUID = "AS_UID";
33 
34  m_title = info.title;
35  m_appConfigID = info.appConfig.id;
36  m_closable = true;
37  m_tabID = "TABID_" + ::fwTools::UUID::generateUUID();
38 
39  if(info.tabInfo.empty())
40  {
41  m_tabInfo = info.title;
42  }
43  else
44  {
45  std::string newTabInfo = info.tabInfo;
46  ::boost::regex e("(!(([[:word:]]+\\.?)+[[:word:]]))");
47  ::boost::smatch what;
48  if(boost::regex_search(newTabInfo, what, e))
49  {
50  std::string submatch(what[1].first, what[1].second);
51 
52  submatch.replace(0, 1, "@");
53 
54  ::fwData::Object::sptr obj = ::fwDataCamp::getObject(series->getData(), submatch);
55  OSLM_ASSERT("Invalid seshat path : '" << submatch <<"'", obj);
56 
57  ::fwData::String::sptr stringParameter = ::fwData::String::dynamicCast(obj);
58 
59  std::string tabInfoSeshat;
60 
61  if(stringParameter)
62  {
63  tabInfoSeshat = stringParameter->getValue();
64  }
65  else
66  {
67  OSLM_WARN("Seshat path '" << submatch << "' doesn't reference an fwData::String");
68  }
69 
70  submatch.replace(0, 1, "!");
71  ::boost::algorithm::replace_all(newTabInfo, submatch, tabInfoSeshat);
72 
73  }
74  m_tabInfo = newTabInfo;
75  }
76  m_iconPath = info.icon;
77  m_tooltip = m_tabInfo;
78  m_series = series;
79 
80  namespace ActiReg = ::fwActivities::registry;
81  ActiReg::ActivityAppConfig::ActivityAppConfigParamsType params = info.appConfig.parameters;
82  params.reserve(params.size() + parameters.size() + 1);
83  params.insert(params.end(), parameters.begin(), parameters.end());
84  ActiReg::ActivityAppConfigParam asConfigParam;
85  asConfigParam.replace = asUID;
86  asConfigParam.by = series->getID();
87  params.push_back(asConfigParam);
88  for(const ActiReg::ActivityAppConfigParam& param : params)
89  {
90  if(!param.isSeshat())
91  {
92  m_replaceMap[param.replace] = param.by;
93  }
94  else
95  {
96  std::string parameterToReplace = param.by;
97  if (parameterToReplace.substr(0, 1) == "!")
98  {
99  parameterToReplace.replace(0, 1, "@");
100  }
101 
102  ::fwData::Object::sptr obj = ::fwDataCamp::getObject(series->getData(), parameterToReplace);
103  OSLM_ASSERT("Invalid seshat path : '"<<param.by<<"'", obj);
104 
105  ::fwData::String::sptr stringParameter = ::fwData::String::dynamicCast(obj);
106 
107  std::string parameterValue = obj->getID();
108 
109  if(stringParameter && param.by.substr(0, 1) == "!")
110  {
111  parameterValue = stringParameter->getValue();
112  }
113  m_replaceMap[param.replace] = parameterValue;
114  }
115  }
116 }
117 
118 //-----------------------------------------------------------------------------
119 
120 } // namespace registry
121 
122 } // namespace fwActivities
Contains fwAtomsFilter::registry details.
#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 OSLM_WARN(message)
Definition: spyLog.hpp:263
#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
Namespace containing activities data and builder.
static FWTOOLS_API UUIDType generateUUID()
Return a new extended UUID;.
Definition: UUID.cpp:114