fw4spl
Acquisition.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 <fwTools/UUID.hpp>
8 
9 #include <fwAtoms/Object.hpp>
10 #include <fwAtoms/Object.hxx>
11 #include <fwAtoms/String.hpp>
12 
13 #include <fwAtomsPatch/helper/functions.hpp>
14 
15 #include "fwMDSemanticPatch/V1/V2/fwData/Acquisition.hpp"
16 
17 namespace fwMDSemanticPatch
18 {
19 namespace V1
20 {
21 namespace V2
22 {
23 namespace fwData
24 {
25 
26 Acquisition::Acquisition() : ::fwAtomsPatch::ISemanticPatch()
27 {
28  m_originClassname = "::fwData::Acquisition";
29  m_originVersion = "1";
30  this->addContext("MedicalData", "V1", "V2");
31 }
32 
33 // ----------------------------------------------------------------------------
34 
36 {
37 }
38 
39 // ----------------------------------------------------------------------------
40 
42 {
43 }
44 
45 // ----------------------------------------------------------------------------
46 
48  const ::fwAtoms::Object::sptr& previous,
49  const ::fwAtoms::Object::sptr& current,
50  ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
51 {
52  ISemanticPatch::apply(previous, current, newVersions);
53  ::fwAtomsPatch::helper::cleanFields( current );
54 
55  ::fwAtoms::Object::sptr image = current->getAttribute< ::fwAtoms::Object >("image");
56  ::fwAtoms::Map::sptr fields = image->getAttribute< ::fwAtoms::Map >("fields");
57 
58  ::fwAtoms::Map::ConstIteratorType it = fields->find("m_commentId");
59  ::fwAtomsPatch::helper::Object helper(current);
60  if ( it != fields->end() )
61  {
62  ::fwAtoms::Object::sptr value = ::fwAtoms::Object::dynamicCast( it->second );
63  helper.replaceAttribute("description", ::fwAtoms::String::New(value->getAttribute("value")->getString()));
64  }
65 
66  ::fwAtoms::String::sptr uid = current->getAttribute< ::fwAtoms::String >("instance_uid");
67  if( uid->getValue().empty() )
68  {
69  helper.replaceAttribute("instance_uid", ::fwAtoms::String::New( ::fwTools::UUID::generateUUID() ));
70  }
71 
72 }
73 
74 // ----------------------------------------------------------------------------
75 
76 } // namespace fwData
77 } // namespace V2
78 } // namespace V1
79 } // namespace fwMDSemanticPatch
Contains the semantic patches within the context "MedicalData".
FWMDSEMANTICPATCH_API ~Acquisition()
Destructor.
Definition: Acquisition.cpp:35
static FWATOMS_API String::sptr New(std::string value)
Construct a new Object represented a string.
virtual FWMDSEMANTICPATCH_API void apply(const ::fwAtoms::Object::sptr &previous, const ::fwAtoms::Object::sptr &current,::fwAtomsPatch::IPatch::NewVersionsType &newVersions) override
Applies patch.
Definition: Acquisition.cpp:47
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
Class represented a fwData::Object.
std::string m_originClassname
Origin classname of the object.
Definition: IPatch.hpp:64
virtual FWATOMSPATCH_API void addContext(const std::string &context, const std::string &originVersion, const std::string &targetVersion)
Add a context where the patch can be applied.
FWATOMSPATCH_API void replaceAttribute(const std::string &name,::fwAtoms::Base::sptr newValue, conditions::Abstract::sptr condition=conditions::Abstract::New())
Replaces an attribute.
Map is a container for mapping representation.
Definition: Map.hpp:31
std::string m_originVersion
Origin version of the object.
Definition: IPatch.hpp:67
FWMDSEMANTICPATCH_API Acquisition()
Constructor.
Definition: Acquisition.cpp:26
FWATOMSPATCH_API ISemanticPatch()
Constructor.
Patch an acquisition from version &#39;V1&#39; to &#39;V2&#39; within &#39;MedicalData&#39; context.
Definition: Acquisition.hpp:25
Contains the representation of the data objects used in the framework.
Class represented a String.
static FWTOOLS_API UUIDType generateUUID()
Return a new extended UUID;.
Definition: UUID.cpp:114