7 #include "fwIO/IReader.hpp" 9 #include <fwCom/Slots.hxx> 11 #include <fwRuntime/operations.hpp> 13 #include <fwServices/macros.hpp> 21 const ::fwCom::Slots::SlotKeyType IReader::s_SET_FILE_FOLDER =
"setFileFolder";
24 static const ::fwCom::Slots::SlotKeyType s_READ_FOLDER_SLOT =
"readFolder";
25 static const ::fwCom::Slots::SlotKeyType s_READ_FILE_SLOT =
"readFile";
26 static const ::fwCom::Slots::SlotKeyType s_READ_FILES_SLOT =
"readFiles";
27 static const ::fwCom::Slots::SlotKeyType s_CONFIGURE_WITH_IHM =
"configureWithIHM";
31 IReader::IReader() noexcept
33 newSlot(s_READ_FOLDER_SLOT, &IReader::readFolder,
this);
34 newSlot(s_READ_FILE_SLOT, &IReader::readFile,
this);
35 newSlot(s_READ_FILES_SLOT, &IReader::readFiles,
this);
42 IReader::~IReader() noexcept
50 return "Choose a file";
57 return std::vector< std::string >();
65 FW_RAISE_IF(
"Exactly one file must be defined in location", m_locations.size() != 1);
66 return m_locations.front();
75 m_locations.push_back(file);
83 FW_RAISE_IF(
"At least one file must be define in location", m_locations.empty() );
100 FW_RAISE_IF(
"Exactly one folder must be define in location", m_locations.size() != 1 );
101 return m_locations.front();
110 m_locations.push_back(folder);
117 FW_RAISE_IF(
"This reader doesn't manage file or files",
120 for(
auto& file : m_locations)
122 file = file.filename();
123 file = folder / file;
131 FW_RAISE_IF(
"At least one path must be define in location", m_locations.empty() );
148 SLM_ASSERT(
"Generic configuring method is only available for io service that use paths.",
151 SLM_ASSERT(
"This reader does not manage folders and a folder path is given in the configuration",
154 SLM_ASSERT(
"This reader does not manage files and a file path is given in the configuration",
156 (config.count(
"file") == 0));
163 FW_RAISE_IF(
"At least one file must be defined in configuration", config.count(
"file") > 1 );
164 if (config.count(
"file") == 1)
166 const std::string file = config.get<std::string>(
"file");
167 this->
setFile(::boost::filesystem::path(file));
169 else if (config.count(
"resource") == 1)
171 const std::string resource = config.get<std::string>(
"resource");
172 const auto file = ::fwRuntime::getResourceFilePath(resource);
183 const auto filesCfg = config.equal_range(
"file");
184 for (
auto fileCfg = filesCfg.first; fileCfg != filesCfg.second; ++fileCfg)
186 const std::string location = fileCfg->second.get_value<std::string>();
187 locations.push_back(::boost::filesystem::path(location));
190 const auto resourcesCfg = config.equal_range(
"resource");
191 for (
auto resourceCfg = resourcesCfg.first; resourceCfg != resourcesCfg.second; ++resourceCfg)
193 const std::string resource = resourceCfg->second.get_value<std::string>();
194 const auto file = ::fwRuntime::getResourceFilePath(resource);
195 locations.push_back(file);
202 FW_RAISE_IF(
"At least one folder must be defined in configuration", config.count(
"folder") > 1 );
203 if (config.count(
"folder") == 1)
205 const std::string folder = config.get<std::string>(
"folder");
206 this->
setFolder(::boost::filesystem::path(folder));
208 else if (config.count(
"resource") == 1)
210 const std::string resource = config.get<std::string>(
"resource");
211 auto folder = ::fwRuntime::getBundleResourceFilePath(resource);
215 folder = ::fwRuntime::getLibraryResourceFilePath(resource);
216 SLM_ERROR_IF(
"Resource '" + resource +
"' has not been found in any bundle or library", folder.empty());
228 return ::fwIO::TYPE_NOT_DEFINED;
235 return m_locations.size() > 0;
240 void IReader::readFolder(::boost::filesystem::path folder)
248 void IReader::readFile(::boost::filesystem::path file)
FWIO_API void setFileFolder(::boost::filesystem::path folder)
Slot: Sets the folder when a path is configured in FILE or FILES mode This is ignored if a path is no...
std::string m_windowTitle
Title of the window that will open when the configureWithIHM slot is called.
FWIO_API bool hasLocationDefined() const
Returns if a location has been defined ( by the configuration process or directly by user ) ...
virtual FWIO_API void configuring() override
This method proposes to parse xml configuration to retrieve file/files/folder paths.
FWIO_API void setFiles(const ::fwIO::LocationsType &files)
Sets file paths.
virtual FWSERVICES_API void updating()=0
Perform some computations according to object (this service is attached to) attribute values and its ...
virtual FWIO_API void configureWithIHM()=0
Configure the image path (by default does nothing).
FWIO_APIconst::boost::filesystem::path & getFolder() const
Returns folder path set by the user or set during service configuration.
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.
virtual FWIO_API::fwIO::IOPathType getIOPathType() const
This method must be implemented by concrete service readers that use path file system to read data...
virtual FWIO_API std::string getSelectorDialogTitle()
returns the title of selector dialog box
#define SLM_ERROR_IF(message, cond)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWIO_APIconst::fwIO::LocationsType & getFiles() const
Returns file paths set by the user or set during service configuration.
IOPathType
IOPathType defines different type of paths used by service readers/writers.
FWIO_APIconst::fwIO::LocationsType & getLocations() const
Returns file/files/folder paths set by the user or set during service configuration.
The namespace fwIO contains the base interface for reader and writer services.
Defines the generic configuration element container class.
virtual FWIO_API std::vector< std::string > getSupportedExtensions()
returns (filename) extension
FWIO_API void setFolder(const ::boost::filesystem::path &folder)
Sets folder path.
std::vector< ::boost::filesystem::path > LocationsType
List of paths managed by io services.
FWIO_API void clearLocations()
Clear any location set by the setFile/setFiles/setFolder setter.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.