fw4spl
Activities.hpp
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 #pragma once
8 
9 #include "fwActivities/config.hpp"
10 
11 #include <fwCore/BaseObject.hpp>
12 #include <fwCore/mt/types.hpp>
13 
14 #include <fwRuntime/ConfigurationElement.hpp>
15 #include <fwRuntime/EConfigurationElement.hpp>
16 
17 #include <boost/property_tree/ptree.hpp>
18 
19 #include <map>
20 #include <string>
21 
22 namespace fwData
23 {
24 class Vector;
25 }
26 
27 namespace fwRuntime
28 {
29 struct Extension;
30 }
31 
32 namespace fwActivities
33 {
34 
35 namespace registry
36 {
37 
38 typedef ::boost::property_tree::ptree ConfigType;
39 
40 struct FWACTIVITIES_CLASS_API ActivityAppConfigParam
41 {
43  {
44  }
45  FWACTIVITIES_API ActivityAppConfigParam(const ConfigType& config);
46 
47  //------------------------------------------------------------------------------
48 
49  bool isSeshat() const
50  {
51  return (by.substr(0, 1) == "@") || (by.substr(0, 1) == "!");
52  }
53 
54  std::string replace;
55  std::string by;
56 };
57 
58 struct FWACTIVITIES_CLASS_API ActivityAppConfig
59 {
60  typedef std::vector< ActivityAppConfigParam > ActivityAppConfigParamsType;
61 
63  {
64  }
65  FWACTIVITIES_API ActivityAppConfig(const ConfigType& config);
66 
67  std::string id;
68  ActivityAppConfigParamsType parameters;
69 };
70 
71 struct FWACTIVITIES_CLASS_API ActivityRequirementKey
72 {
74  {
75  }
76  FWACTIVITIES_API ActivityRequirementKey(const ConfigType& config);
77 
78  std::string key;
79  std::string path;
80 };
81 
82 struct FWACTIVITIES_CLASS_API ActivityRequirement
83 {
85  {
86  }
87  FWACTIVITIES_API ActivityRequirement(const ConfigType& config);
88 
89  typedef std::vector< ActivityRequirementKey > KeyType;
90 
91  std::string name;
92  std::string type;
93  std::string container;
94  std::string description;
95  std::string validator;
96  unsigned int minOccurs;
97  unsigned int maxOccurs;
98  bool create;
99  KeyType keys;
100 };
101 
175 struct FWACTIVITIES_CLASS_API ActivityInfo
176 {
177  typedef std::vector< ActivityRequirement > RequirementsType;
178  typedef std::pair<unsigned int, unsigned int> MinMaxType;
179  typedef std::map< std::string, MinMaxType > RequirementsMinMaxCount;
180  typedef std::map< std::string, unsigned int > DataCountType;
181 
182  ActivityInfo()
183  {
184  }
185 
186  FWACTIVITIES_API ActivityInfo(const SPTR(::fwRuntime::Extension)& ext);
187 
188  FWACTIVITIES_API bool usableWith(DataCountType dataCount) const;
189 
190  std::string id;
191  std::string title;
192  std::string description;
193  std::string icon;
194  std::string tabInfo;
195  RequirementsType requirements;
196  std::string builderImpl;
197  std::string bundleId;
198  std::string bundleVersion;
199 
201  std::vector< std::string > validatorsImpl;
202 
203  ActivityAppConfig appConfig;
204 
205  protected:
206 
207  RequirementsMinMaxCount m_requirementCount;
208 };
209 
216 class FWACTIVITIES_CLASS_API Activities : public ::fwCore::BaseObject
217 {
218 
219 public:
220  typedef std::vector< ActivityInfo > ActivitiesType;
221 
223 
225  FWACTIVITIES_API static Activities::sptr getDefault();
226 
228  FWACTIVITIES_API virtual ~Activities();
229 
236  FWACTIVITIES_API void parseBundleInformation();
237  FWACTIVITIES_API void parseBundleInformation(const std::vector< SPTR( ::fwRuntime::Extension ) >& extensions);
239 
244  FWACTIVITIES_API const ActivityInfo getInfo( const std::string& extensionId ) const;
245 
250  FWACTIVITIES_API bool hasInfo( const std::string& extensionId ) const;
251 
255  FWACTIVITIES_API ActivityInfo::DataCountType getDataCount( const CSPTR(::fwData::Vector)& data ) const;
256 
261  FWACTIVITIES_API ActivitiesType getInfos() const;
262 
267  FWACTIVITIES_API ActivitiesType getInfos( const CSPTR(::fwData::Vector)& data ) const;
268 
273  FWACTIVITIES_API std::vector< std::string > getKeys() const;
274 
279  FWACTIVITIES_API void clearRegistry();
280 
281 protected:
282 
283  typedef std::map< std::string, ActivityInfo > Registry;
284 
286  Registry m_reg;
287 
289  FWACTIVITIES_API Activities();
290 
292  mutable ::fwCore::mt::ReadWriteMutex m_registryMutex;
293 
295  static Activities::sptr s_activities;
296 
297 };
298 
299 } // namespace registry
300 
301 } // namespace fwActivities
std::string description
data container if maxOccurs > 1 ("vector" or "composite", default: "composite")
Definition: Activities.hpp:94
mutable::fwCore::mt::ReadWriteMutex m_registryMutex
Used to protect the registry access.
Definition: Activities.hpp:292
#define SPTR(_cls_)
#define CSPTR(_cls_)
Contains fwAtomsFilter::registry details.
Base class for all FW4SPL&#39;s classes.
Definition: BaseObject.hpp:22
Holds Activities configuration.
Definition: Activities.hpp:175
Defines the extension class.
Definition: Extension.hpp:30
unsigned int maxOccurs
minimum number of data required
Definition: Activities.hpp:97
Registry m_reg
Container of parameter information.
Definition: Activities.hpp:286
std::string bundleVersion
Version of the bundle containing the activity.
Definition: Activities.hpp:198
std::string validator
parameter description
Definition: Activities.hpp:95
std::string bundleId
Identifier of the bundle containing the activity.
Definition: Activities.hpp:197
This class defines a vector of objects.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
KeyType keys
True if the data must be created if it is not present (only if minOccurs = 0 and maxOccurs = 1) ...
Definition: Activities.hpp:99
unsigned int minOccurs
Implementation of data validator.
Definition: Activities.hpp:96
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
This class allows to register all the configuration parameters which has the point extension "::activ...
Definition: Activities.hpp:216
static Activities::sptr s_activities
The global instance of the app config parameters.
Definition: Activities.hpp:295
std::string container
parameter type (ie. fwMedData::ImageSeries)
Definition: Activities.hpp:93
Namespace containing activities data and builder.
Contains the representation of the data objects used in the framework.
std::vector< std::string > validatorsImpl
Validator implementations.
Definition: Activities.hpp:201
bool create
maximum number of data required
Definition: Activities.hpp:98