7 #include "fwAtomConversion/mapper/Graph.hpp" 9 #include "fwAtomConversion/convert.hpp" 10 #include "fwAtomConversion/exception/ConversionNotManaged.hpp" 11 #include "fwAtomConversion/mapper/registry/macros.hpp" 13 #include <fwAtoms/Map.hpp> 14 #include <fwAtoms/Sequence.hpp> 15 #include <fwAtoms/String.hpp> 17 #include <fwData/Graph.hpp> 19 #include <fwTools/UUID.hpp> 32 ::fwAtoms::Object::sptr
Graph::convert( ::fwData::Object::sptr
object,
33 DataVisitor::AtomCacheType& cache )
35 const camp::Class& metaclass = ::camp::classByName( object->getClassname() );
37 metaclass.visit(visitor);
38 ::fwAtoms::Object::sptr atom = visitor.getAtomObject();
40 ::fwData::Graph::sptr graph = ::fwData::Graph::dynamicCast(
object);
42 ::fwAtoms::Sequence::sptr sequence = ::fwAtoms::Sequence::New();
44 typedef ::fwData::Graph::ConnectionContainer GraphConnections;
45 ::fwAtoms::Object::sptr value;
46 for( GraphConnections::value_type elem : graph->getConnections() )
48 value = ::fwAtoms::Object::New();
56 sequence->push_back(value);
59 atom->setAttribute(
"connections", sequence );
66 ::fwData::Object::sptr
Graph::convert( ::fwAtoms::Object::sptr atom,
67 AtomVisitor::DataCacheType& cache,
68 const AtomVisitor::IReadPolicy& uuidPolicy
73 ::fwData::Object::sptr data = visitor.getDataObject();
74 ::fwData::Graph::sptr graph = ::fwData::Graph::dynamicCast(data);
76 ::fwAtoms::Sequence::sptr seqAtom = ::fwAtoms::Sequence::dynamicCast( atom->getAttribute(
"connections") );
77 for( ::fwAtoms::Base::sptr elemAtom : seqAtom->getValue() )
79 FW_RAISE_EXCEPTION_IF( exception::ConversionNotManaged(
80 "sub atoms stored in fwAtom::Sequence 'connections' must be atom objects"),
81 elemAtom->type() != ::fwAtoms::Base::OBJECT );
83 ::fwAtoms::Object::sptr objectAtom = ::fwAtoms::Object::dynamicCast( elemAtom );
84 ::fwAtoms::Object::sptr edgeAtom = ::fwAtoms::Object::dynamicCast( objectAtom->getAttribute(
"edge") );
85 ::fwData::Edge::sptr edge =
88 ::fwAtoms::Object::sptr srcAtom = ::fwAtoms::Object::dynamicCast( objectAtom->getAttribute(
"source") );
89 ::fwData::Node::sptr src =
92 ::fwAtoms::Object::sptr destAtom = ::fwAtoms::Object::dynamicCast( objectAtom->getAttribute(
"destination") );
93 ::fwData::Node::sptr dest =
96 graph->addEdge( edge, src, dest );
This class defines a graph object.
This namespace contains the necessary class for fwData <-> fwAtoms conversion.
Specific mapper used to convert a fwData::Graph.
FWATOMCONVERSION_API std::shared_ptr< ::fwAtoms::Object > convert(const std::shared_ptr< ::fwData::Object > &data)
Helper to 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 ...
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.
This class is used to convert a fwAtoms to a fwData.