fw4spl
V4ToV3.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2015-2016.
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 "fwStructuralPatch/fwData/Material/V4ToV3.hpp"
8 
9 #include <fwAtoms/Boolean.hpp>
10 #include <fwAtoms/Numeric.hpp>
11 #include <fwAtoms/Numeric.hxx>
12 #include <fwAtoms/Object.hpp>
13 #include <fwAtoms/Object.hxx>
14 #include <fwAtoms/Sequence.hpp>
15 #include <fwAtoms/String.hpp>
16 
17 namespace fwStructuralPatch
18 {
19 
20 namespace fwData
21 {
22 
23 namespace Material
24 {
25 
26 V4ToV3::V4ToV3() : ::fwAtomsPatch::IStructuralPatch()
27 {
28  m_originClassname = "::fwData::Material";
29  m_targetClassname = "::fwData::Material";
30  m_originVersion = "4";
31  m_targetVersion = "3";
32 }
33 
34 // ----------------------------------------------------------------------------
35 
37 {
38 }
39 
40 // ----------------------------------------------------------------------------
41 
43 {
44 }
45 
46 // ----------------------------------------------------------------------------
47 
48 void V4ToV3::apply( const ::fwAtoms::Object::sptr& previous,
49  const ::fwAtoms::Object::sptr& current,
50  ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
51 {
52  IStructuralPatch::apply(previous, current, newVersions);
53 
54  // Update object version
55  this->updateVersion(current);
56 
57  ::fwAtomsPatch::helper::Object helper(current);
58 
59  // Retrieve shading_mode and replace AMBIENT mode with PHONG
60  // add lighting attribute (false if mode is AMBIENT, else true)
61  ::fwAtoms::String::sptr shadingMode = previous->getAttribute< ::fwAtoms::String >("shading_mode");
62  std::string shading = shadingMode->getValue();
63 
64  bool lighting = true;
65  if (shading == "AMBIENT")
66  {
67  lighting = false;
68  helper.replaceAttribute("shading_mode", ::fwAtoms::String::New("PHONG"));
69  }
70  helper.addAttribute("lighting", ::fwAtoms::Boolean::New(lighting));
71 
72 
73 
74  // Switch diffuse and ambient
75  ::fwAtoms::Object::sptr ambient = current->getAttribute< ::fwAtoms::Object >("ambient");
76  ::fwAtoms::Object::sptr diffuse = current->getAttribute< ::fwAtoms::Object >("diffuse");
77 
78  // Replace diffuse by previous ambient
79  helper.replaceAttribute("diffuse", ambient);
80  helper.replaceAttribute("ambient", diffuse);
81 
82  // Replace options_mode "CELLS_NORMALS" by "NORMALS"
83  ::fwAtoms::String::sptr optionMode = previous->getAttribute< ::fwAtoms::String >("options_mode");
84  std::string option = optionMode->getValue();
85  if (option == "CELLS_NORMALS")
86  {
87  helper.replaceAttribute("options_mode", ::fwAtoms::String::New("NORMALS"));
88  }
89 
90 }
91 
92 } // namespace Material
93 
94 } // namespace fwData
95 
96 } // namespace fwStructuralPatch
FWSTRUCTURALPATCH_API V4ToV3()
Constructor.
Definition: V4ToV3.cpp:26
FWATOMSPATCH_API void updateVersion(std::shared_ptr< ::fwAtoms::Object > current)
Updates the version of the patched object.
static FWATOMS_API String::sptr New(std::string value)
Construct a new Object represented a string.
FWATOMS_API Base::sptr getAttribute(const std::string &key) const
Returns requested attribute if exists, empty sptr else.
virtual FWSTRUCTURALPATCH_API void apply(const ::fwAtoms::Object::sptr &previous, const ::fwAtoms::Object::sptr &current,::fwAtomsPatch::IPatch::NewVersionsType &newVersions) override
Applies patch.
Definition: V4ToV3.cpp:48
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
Class represented a fwData::Object.
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
Structural patch to convert a fwData::Material from version &#39;4&#39; to version &#39;3&#39;.
Definition: V4ToV3.hpp:24
FWSTRUCTURALPATCH_API ~V4ToV3()
Destructor.
Definition: V4ToV3.cpp:36
FWATOMSPATCH_API void replaceAttribute(const std::string &name,::fwAtoms::Base::sptr newValue, conditions::Abstract::sptr condition=conditions::Abstract::New())
Replaces an attribute.
std::string m_originVersion
Origin version of the object.
Definition: IPatch.hpp:67
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.
Class represented a String.
static FWATOMS_API Boolean::sptr New(std::string value)
Construct an object storing a bool value.