fw4spl
MedicalWorkspacePatcher.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 "fwMDSemanticPatch/V1/V2/MedicalWorkspacePatcher.hpp"
8 
9 #include <fwAtoms/Object.hpp>
10 #include <fwAtoms/Object.hxx>
11 #include <fwAtoms/Map.hpp>
12 
13 #include <fwAtomsPatch/IPatch.hpp>
14 #include <fwAtomsPatch/IStructuralPatch.hpp>
15 #include <fwAtomsPatch/StructuralPatchDB.hpp>
16 #include <fwAtomsPatch/patcher/registry/macros.hpp>
17 #include <fwAtomsPatch/helper/functions.hpp>
18 
19 namespace fwMDSemanticPatch
20 {
21 namespace V1
22 {
23 namespace V2
24 {
25 
26 patcherRegisterMacro(::fwMDSemanticPatch::V1::V2::MedicalWorkspacePatcher, "MedicalWorkspacePatcher");
27 
29  ::fwAtomsPatch::patcher::DefaultPatcher(key)
30 {
31 }
32 
33 // ----------------------------------------------------------------------------
34 
36 {
37 }
38 
39 // ----------------------------------------------------------------------------
40 
41 ::fwAtoms::Object::sptr MedicalWorkspacePatcher::transformObject(::fwAtoms::Object::sptr object,
42  const std::string &context,
43  const std::string &currentVersion,
44  const std::string &targetVersion)
45 {
46  this->addCompositeTypes(object);
47  return ::fwAtomsPatch::patcher::DefaultPatcher::transformObject(object,context,currentVersion, targetVersion);
48 }
49 
50 // ----------------------------------------------------------------------------
51 
52 void MedicalWorkspacePatcher::addCompositeTypes(::fwAtoms::Object::sptr object)
53 {
54  if( ::fwAtomsPatch::helper::getClassname( object ) == "::fwData::Composite")
55  {
56  ::fwAtoms::Map::sptr values = object->getAttribute< ::fwAtoms::Map >("values");
57  if((*values)["patientDB"] && (*values)["planningDB"] && (*values)["processingDB"])
58  {
59  object->setMetaInfo("compositeType", "MedicalWorkspace");
60  }
61  }
62 
63  for( ::fwAtoms::Object::AttributesType::value_type elem : object->getAttributes() )
64  {
65  ::fwAtoms::Object::sptr att = ::fwAtoms::Object::dynamicCast(elem.second);
66  if(att)
67  {
68  this->addCompositeTypes(att);
69  }
70  }
71 }
72 
73 } // namespace V2
74 } // namespace V1
75 } // namespace fwMDSemanticPatch
76 
FWATOMSPATCH_API std::string getClassname(const ::fwAtoms::Object::sptr &obj)
Get classname of an object.
FWMDSEMANTICPATCH_API void addCompositeTypes(::fwAtoms::Object::sptr object)
Adds a meta info "compositeType" if the object is a composite with a special type.
Contains the semantic patches within the context "MedicalData".
virtual FWMDSEMANTICPATCH_API ~MedicalWorkspacePatcher()
Destructor.
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
virtual FWMDSEMANTICPATCH_API::fwAtoms::Object::sptr transformObject(::fwAtoms::Object::sptr object, const std::string &context, const std::string &currentVersion, const std::string &targetVersion) override
Applies the patch to the specified object.
Map is a container for mapping representation.
Definition: Map.hpp:31
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
This patcher adds required meta infos on composites describing a &#39;Medical workspace&#39;.
FWMDSEMANTICPATCH_API MedicalWorkspacePatcher(::fwAtomsPatch::patcher::IPatcher::Key key)
Constructor.