7 #include "ioTuto/ExternalDataReaderService.hpp" 9 #include <fwData/Composite.hpp> 10 #include <fwData/location/Folder.hpp> 11 #include <fwData/location/SingleFile.hpp> 12 #include <fwData/String.hpp> 13 #include <fwData/TransformationMatrix3D.hpp> 15 #include <fwDataTools/helper/Composite.hpp> 17 #include <fwGui/dialog/LocationDialog.hpp> 18 #include <fwGui/dialog/MessageDialog.hpp> 20 #include <fwServices/macros.hpp> 22 #include <boost/filesystem/operations.hpp> 43 _sstream << std::endl <<
" External data file reader";
50 std::vector< std::string > extensions;
51 extensions.push_back(
".us");
67 std::string filename =
m_configuration->findConfigurationElement(
"filename")->getValue();
68 OSLM_INFO(
"ExternalDataReaderService::configure filename: " << filename );
77 static ::boost::filesystem::path _sDefaultPath;
80 dialogFile.
setTitle(
"Choose an external data file");
83 dialogFile.
setOption(::fwGui::dialog::ILocationDialog::READ);
84 dialogFile.
setOption(::fwGui::dialog::ILocationDialog::FILE_MUST_EXIST);
86 ::fwData::location::SingleFile::sptr result;
87 result = ::fwData::location::SingleFile::dynamicCast( dialogFile.
show() );
90 _sDefaultPath = result->getPath();
91 this->
setFile(result->getPath());
105 std::string imageName;
106 ::fwData::Composite::sptr dataComposite = this->getObject< ::fwData::Composite >();
108 SLM_ASSERT(
"dataComposite not instanced", dataComposite);
115 file.open(this->
getFile().
string().c_str(), std::fstream::in);
119 std::string str =
"Unable to open ";
120 str += this->
getFile().string();
121 throw std::ios_base::failure(str);
126 ::fwData::TransformationMatrix3D::sptr transformation1 = ::fwData::TransformationMatrix3D::New();
127 ::fwData::TransformationMatrix3D::sptr transformation2 = ::fwData::TransformationMatrix3D::New();
131 while ( !file.eof() && readedValue < 32 )
134 if (readedValue < 16)
136 transformation1->getCoefficients()[readedValue] = value;
140 transformation2->getCoefficients()[readedValue] = value;
147 if(dataComposite->find(
"TF1") == dataComposite->end() )
149 compositeHelper.add(
"TF1", transformation1);
153 compositeHelper.swap(
"TF1", transformation1);
156 if(dataComposite->find(
"TF2") == dataComposite->end() )
158 compositeHelper.add(
"TF2", transformation2);
162 compositeHelper.swap(
"TF2", transformation2);
164 ::fwData::String::sptr imageNameStr = ::fwData::String::New(imageName);
165 if(dataComposite->find(
"filename") == dataComposite->end() )
167 compositeHelper.add(
"filename", imageNameStr);
171 compositeHelper.swap(
"filename", imageNameStr);
173 SLM_ASSERT(
"Unable to open '"+this->
getFile().
string()+
"'.", readedValue == 32 );
176 catch(std::ios_base::failure& exception)
178 OSLM_ERROR(
"External data file loading error for " << exception.what());
FWIO_API bool hasLocationDefined() const
Returns if a location has been defined ( by the configuration process or directly by user ) ...
IOTUTO_API ExternalDataReaderService()
Constructor : does nothing.
virtual FWGUI_API void setDefaultLocation(::fwData::location::ILocation::sptr loc) override
Set the initial location for the dialog.
#define OSLM_INFO(message)
virtual IOTUTO_API void configuring() override
Configure service. This method is called by configure() from base service ( fwServices::IService ) ...
FWGUI_API::fwGui::dialog::ILocationDialog & setOption(::fwGui::dialog::ILocationDialog::Options option) override
allow to set option to the file dialog mode=READ/WRITE, check=FILE_MUST_EXIST
FWGUI_API::fwData::location::ILocation::sptr show() override
Display the dialog.
FWGUI_API void addFilter(const std::string &filterName, const std::string &wildcardList) override
specify some filtering when browsing files:
IOTUTO_API::fwIO::IOPathType getIOPathType() const override
Returns managed path type, here service manages only single file.
FWIO_APIconst::boost::filesystem::path & getFile() const
Returns the file path set by the user or set during service configuration.
FWIO_API void setFile(const ::boost::filesystem::path &file)
Sets file path.
#define OSLM_ERROR(message)
IOTUTO_API ~ExternalDataReaderService() noexcept
Destructor.
Reader service API. It manages extension points definition and extension configuration.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
virtual IOTUTO_API std::vector< std::string > getSupportedExtensions() override
returns (filename) extension
IOPathType
IOPathType defines different type of paths used by service readers/writers.
IOTUTO_API void updating() override
Updating method. This method is called by update() from base service ( fwServices::IService ) ...
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
Defines the generic file/folder selector dialog for IHM.
This class defines a composite object.
IOTUTO_API void configureWithIHM() override
Configure the image path.
virtual IOTUTO_API void info(std::ostream &_sstream) override
Info method.
FWIO_API void clearLocations()
Clear any location set by the setFile/setFiles/setFolder setter.
virtual FWSERVICES_API void info(std::ostream &_sstream)
Write information in a stream.