fw4spl
fwAtomConversion/src/fwAtomConversion/mapper/AttachmentSeries.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-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 "fwAtomConversion/mapper/AttachmentSeries.hpp"
8 
9 #include "fwAtomConversion/convert.hpp"
10 #include "fwAtomConversion/exception/ConversionNotManaged.hpp"
11 #include "fwAtomConversion/mapper/registry/macros.hpp"
12 
13 #include <fwAtoms/String.hpp>
14 
15 #include <fwMedData/AttachmentSeries.hpp>
16 
17 #include <fwTools/UUID.hpp>
18 
19 namespace fwAtomConversion
20 {
21 namespace mapper
22 {
23 
24 //-----------------------------------------------------------------------------
25 
27 
28 //-----------------------------------------------------------------------------
29 
30 ::fwAtoms::Object::sptr AttachmentSeries::convert( ::fwData::Object::sptr object,
31  DataVisitor::AtomCacheType& cache )
32 {
33  const camp::Class& metaclass = ::camp::classByName( object->getClassname() );
34  ::fwAtomConversion::DataVisitor visitor ( object, cache );
35  metaclass.visit(visitor);
36  ::fwAtoms::Object::sptr atom = visitor.getAtomObject();
37 
38  ::fwMedData::AttachmentSeries::sptr attachment = ::fwMedData::AttachmentSeries::dynamicCast(object);
39 
40  atom->setAttribute("attachment_availability", ::fwAtoms::String::New(std::string("EMBEDDED")));
41  ::boost::filesystem::path attachFile = attachment->getAttachmentPath();
42  atom->setAttribute("attachment_path", ::fwAtoms::String::New(attachFile.filename().string()) );
43 
44  return atom;
45 }
46 
47 //-----------------------------------------------------------------------------
48 
49 ::fwData::Object::sptr AttachmentSeries::convert( ::fwAtoms::Object::sptr atom,
50  AtomVisitor::DataCacheType& cache,
51  const AtomVisitor::IReadPolicy& uuidPolicy
52  )
53 {
54  ::fwAtomConversion::AtomVisitor visitor ( atom, cache, uuidPolicy );
55  visitor.visit();
56  ::fwData::Object::sptr data = visitor.getDataObject();
57  ::fwMedData::AttachmentSeries::sptr attachment = ::fwMedData::AttachmentSeries::dynamicCast(data);
58 
59  return attachment;
60 }
61 
62 //-----------------------------------------------------------------------------
63 
64 } //namespace mapper
65 } //namespace fwAtomConversion
This namespace contains the necessary class for fwData <-> fwAtoms conversion.
static FWATOMS_API String::sptr New(std::string value)
Construct a new Object represented a string.
virtual FWATOMCONVERSION_API std::shared_ptr< ::fwAtoms::Object > convert(std::shared_ptr< ::fwData::Object > object, DataVisitor::AtomCacheType &cache)
Convert a fwData::Object to a fwAtoms::Object.
Visitor used to convert a fwData to a fwAtoms. fwData camp property names are used like key to store ...
Definition: DataVisitor.hpp:38
This class is used to convert a fwAtoms to a fwData.
Definition: AtomVisitor.hpp:31