fw4spl
fwData/TransformationMatrix3D/V1ToV2.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 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 <fwAtoms/String.hpp>
8 #include <fwAtoms/Map.hpp>
9 #include <fwAtoms/Numeric.hpp>
10 #include <fwAtoms/Sequence.hpp>
11 #include <fwAtoms/Object.hxx>
12 #include <fwAtomsPatch/StructuralCreatorDB.hpp>
13 
14 #include "fwStructuralPatch/fwData/TransformationMatrix3D/V1ToV2.hpp"
15 
16 namespace fwStructuralPatch
17 {
18 
19 namespace fwData
20 {
21 
22 namespace TransformationMatrix3D
23 {
24 
25 V1ToV2::V1ToV2() : ::fwAtomsPatch::IStructuralPatch()
26 {
27  m_originClassname = "::fwData::TransformationMatrix3D";
28  m_targetClassname = "::fwData::TransformationMatrix3D";
29  m_originVersion = "1";
30  m_targetVersion = "2";
31 }
32 
33 // ----------------------------------------------------------------------------
34 
36 {
37 }
38 
39 // ----------------------------------------------------------------------------
40 
42 {
43 }
44 
45 // ----------------------------------------------------------------------------
46 
47 void V1ToV2::apply( const ::fwAtoms::Object::sptr& previous,
48  const ::fwAtoms::Object::sptr& current,
49  ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
50 {
51  IStructuralPatch::apply(previous, current, newVersions);
52 
53  // Update object version
54  this->updateVersion(current);
55 
56  // Create helper
57  ::fwAtomsPatch::helper::Object helper(current);
58 
59  ::fwAtoms::Sequence::sptr oldCoefs = previous->getAttribute< ::fwAtoms::Sequence >("coefficient");
60  ::fwAtoms::Sequence::sptr newCoefs = ::fwAtoms::Sequence::New();
61 
62  for(size_t i = 0; i < 16; ++i)
63  {
64  newCoefs->push_back((*oldCoefs)[i]);
65  }
66 
67  helper.removeAttribute("coefficient");
68  helper.addAttribute("coefficient", newCoefs);
69 }
70 
71 } // namespace TransformationMatrix3D
72 
73 } // namespace fwData
74 
75 } // namespace fwStructuralPatch
76 
FWATOMSPATCH_API void updateVersion(std::shared_ptr< ::fwAtoms::Object > current)
Updates the version of the patched object.
FWATOMSPATCH_API void removeAttribute(const std::string &name, conditions::Abstract::sptr condition=conditions::Abstract::New())
Removes an attribute.
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
virtual FWSTRUCTURALPATCH_API void apply(const ::fwAtoms::Object::sptr &previous, const ::fwAtoms::Object::sptr &current,::fwAtomsPatch::IPatch::NewVersionsType &newVersions) override
Applies patch.
std::string m_targetClassname
Target type.
FWATOMSPATCH_API IStructuralPatch()
Constructor.
std::string m_originClassname
Origin classname of the object.
Definition: IPatch.hpp:64
Contains creators and structural patches.
Definition: Landmarks1.hpp:13
std::string m_originVersion
Origin version of the object.
Definition: IPatch.hpp:67
Structural patch to convert a fwData::Mesh from version &#39;1&#39; to version &#39;2&#39;.
FWATOMSPATCH_API void addAttribute(const std::string &name,::fwAtoms::Base::sptr value, conditions::Abstract::sptr condition=conditions::Abstract::New())
Adds a new attribute in the current object.
std::string m_targetVersion
Target version.
Contains the representation of the data objects used in the framework.
Sequence represented a list of meta object.
Definition: Sequence.hpp:22