7 #include "ioGdcm/SSeriesDBReader.hpp" 9 #include <fwCom/Signal.hxx> 11 #include <fwData/location/Folder.hpp> 12 #include <fwData/mt/ObjectWriteLock.hpp> 13 #include <fwData/String.hpp> 15 #include <fwGdcmIO/reader/SeriesDB.hpp> 17 #include <fwGui/Cursor.hpp> 18 #include <fwGui/dialog/LocationDialog.hpp> 19 #include <fwGui/dialog/LoggerDialog.hpp> 20 #include <fwGui/dialog/MessageDialog.hpp> 21 #include <fwGui/dialog/ProgressDialog.hpp> 22 #include <fwGui/dialog/PulseProgressDialog.hpp> 24 #include <fwIO/IReader.hpp> 26 #include <fwJobs/IJob.hpp> 27 #include <fwJobs/Observer.hpp> 29 #include <fwLog/Logger.hpp> 31 #include <fwMedData/SeriesDB.hpp> 33 #include <fwMedDataTools/helper/SeriesDB.hpp> 35 #include <fwServices/macros.hpp> 36 #include <fwServices/op/Add.hpp> 37 #include <fwServices/registry/ServiceConfig.hpp> 39 #include <fwTools/ProgressToLogger.hpp> 46 static const ::fwCom::Signals::SignalKeyType JOB_CREATED_SIGNAL =
"jobCreated";
51 m_showLogDialog(true),
52 m_enableBufferRotation(true),
53 m_dicomDirSupport(USER_SELECTION)
55 m_sigJobCreated = newSignal<JobCreatedSignal>(JOB_CREATED_SIGNAL);
68 return ::fwIO::FOLDER;
75 static ::boost::filesystem::path _sDefaultPath;
80 dialogFile.
setOption(::fwGui::dialog::ILocationDialog::READ);
81 dialogFile.
setType(::fwGui::dialog::LocationDialog::FOLDER);
83 ::fwData::location::Folder::sptr result;
84 result = ::fwData::location::Folder::dynamicCast( dialogFile.
show() );
87 _sDefaultPath = result->getFolder();
97 if(!m_filterConfig.empty())
100 ::fwRuntime::ConfigurationElement::csptr filterSelectorConfig;
102 m_filterConfig,
"::ioDicom::SFilterSelectorDialog");
104 SLM_ASSERT(
"Sorry, there is no service configuration " 106 <<
" for ::ioDicom::SFilterSelectorDialog", filterSelectorConfig);
109 ::fwServices::IService::sptr filterSelectorSrv;
110 ::fwData::String::sptr key = ::fwData::String::New();
111 filterSelectorSrv = ::fwServices::add(key,
112 "::fwGui::editor::IDialogEditor",
113 "::ioDicom::SFilterSelectorDialog");
114 filterSelectorSrv->setConfiguration( ::fwRuntime::ConfigurationElement::constCast(filterSelectorConfig) );
115 filterSelectorSrv->configure();
116 filterSelectorSrv->start();
117 filterSelectorSrv->update();
118 filterSelectorSrv->stop();
119 ::fwServices::OSR::unregisterService( filterSelectorSrv );
121 m_filterType = key->getValue();
131 const ::fwServices::IService::ConfigType config = this->
getConfigTree();
134 m_filterConfig = config.get<std::string>(
"filterConfig",
"");
137 m_filterType = config.get<std::string>(
"filterConfig",
"");
140 m_showLogDialog = config.get<
bool>(
"showLogDialog",
true);
143 m_enableBufferRotation = config.get<
bool>(
"enableBufferRotation",
true);
146 const std::string dicomDirStr = config.get<std::string>(
"dicomdirSupport",
"user_selection");
147 SLM_ASSERT(
"<dicomdirSupport> value must be 'always' or 'never' or 'user_selection'",
148 dicomDirStr ==
"always" || dicomDirStr ==
"never" || dicomDirStr ==
"user_selection");
149 if(dicomDirStr ==
"always")
151 m_dicomDirSupport = ALWAYS;
153 else if(dicomDirStr ==
"never")
155 m_dicomDirSupport = NEVER;
157 else if(dicomDirStr ==
"user_selection")
159 m_dicomDirSupport = USER_SELECTION;
163 if(config.count(
"SOPClassSelection") == 1 )
165 const auto sopClassSelectionConfig = config.get_child(
"SOPClassSelection");
166 const auto sopClassRange = sopClassSelectionConfig.equal_range(
"SOPClass");
167 for(
auto sopClassIter = sopClassRange.first; sopClassIter != sopClassRange.second; ++sopClassIter)
169 const ::fwServices::IService::ConfigType& sopClassConfig = sopClassIter->second;
170 const ::fwServices::IService::ConfigType& sopClassAttr = sopClassConfig.get_child(
"<xmlattr>");
172 SLM_ASSERT(
"Missing attribute 'uid' in element '<SOPClass>'", sopClassAttr.count(
"uid") == 1);
173 m_supportedSOPClassSelection.push_back(sopClassAttr.get<std::string>(
"uid"));
196 _sstream <<
"SSeriesDBReader::info";
203 return "Choose a directory with DICOM images";
208 ::fwMedData::SeriesDB::sptr SSeriesDBReader::createSeriesDB( const ::boost::filesystem::path& dicomDir)
211 ::fwGdcmIO::reader::SeriesDB::sptr reader = ::fwGdcmIO::reader::SeriesDB::New();
212 ::fwMedData::SeriesDB::sptr dummy = ::fwMedData::SeriesDB::New();
213 reader->setObject(dummy);
214 reader->setFolder(dicomDir);
215 reader->setDicomFilterType(m_filterType);
216 reader->setBufferRotationEnabled(m_enableBufferRotation);
217 reader->setSupportedSOPClassContainer(m_supportedSOPClassSelection);
218 auto job = reader->getJob();
219 m_sigJobCreated->emit(job);
221 if(m_dicomDirSupport == USER_SELECTION && reader->isDicomDirAvailable())
224 messageBox.
setTitle(
"Dicomdir file");
225 messageBox.
setMessage(
"There is a dicomdir file in the root folder. " 226 "Would you like to use it for the reading process ?" );
227 messageBox.
setIcon(::fwGui::dialog::IMessageDialog::QUESTION);
228 messageBox.
addButton(::fwGui::dialog::IMessageDialog::YES_NO);
231 reader->setDicomdirActivated(button == ::fwGui::dialog::IMessageDialog::YES);
233 else if(m_dicomDirSupport == ALWAYS)
235 reader->setDicomdirActivated(
true);
239 reader->setDicomdirActivated(
false);
247 ::fwLog::Logger::sptr logger = reader->getLogger();
255 if(m_showLogDialog && !logger->empty())
258 std::stringstream ss;
259 if(dummy->size() > 1)
261 ss <<
"The reading process is over : <b>" << dummy->size() <<
" series</b> have been found. " 262 "<br>Please verify the log report to be informed of the potential errors.";
266 ss <<
"The reading process is over : <b>" << dummy->size() <<
" series</b> has been found. " 267 "<br>Please verify the log report to be informed of the potential errors.";
271 if(!job->cancelRequested())
277 if(!result || job->cancelRequested())
284 catch (
const std::exception& e)
286 std::stringstream ss;
287 ss <<
"Warning during loading : " << e.what();
289 "Warning", ss.str(), ::fwGui::dialog::IMessageDialog::WARNING);
294 "Warning",
"Warning during loading", ::fwGui::dialog::IMessageDialog::WARNING);
307 ::fwMedData::SeriesDB::sptr localSeriesDB = this->createSeriesDB(this->
getFolder());
309 if( !localSeriesDB->empty() )
312 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(::fwIO::s_DATA_KEY);
322 seriesDB->shallowCopy(localSeriesDB);
325 ::fwMedData::SeriesDB::ContainerType addedSeries = seriesDB->getContainer();
329 sig->asyncEmit(addedSeries);
virtual IOGDCM_API void starting() override
Override.
virtual IOGDCM_API void configuring() override
Configuring method. This method is used to configure the service.
std::string m_windowTitle
Title of the window that will open when the configureWithIHM slot is called.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
IOGDCM_API::fwIO::IOPathType getIOPathType() const override
Return managed file type, here FOLDER.
FWIO_API bool hasLocationDefined() const
Returns if a location has been defined ( by the configuration process or directly by user ) ...
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
virtual FWIO_API void configuring() override
This method proposes to parse xml configuration to retrieve file/files/folder paths.
Defines the generic message box for IHM. Use the Delegate design pattern.
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
virtual IOGDCM_API void stopping() override
Override.
virtual IOGDCM_API void configureWithIHM() override
Override.
virtual FWGUI_API void setDefaultLocation(::fwData::location::ILocation::sptr loc) override
Set the initial location for the dialog.
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.
A helper to lock object on exclusive mode.
FWIO_APIconst::boost::filesystem::path & getFolder() const
Returns folder path set by the user or set during service configuration.
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_SERIES_SIG
Type of signal when series are added.
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
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) ...
Read DICOM (ImageSeries/ModelSeries) with gdcm reader.
virtual IOGDCM_API ~SSeriesDBReader() noexcept override
destructor
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
virtual IOGDCM_API std::string getSelectorDialogTitle() override
Override.
IOPathType
IOPathType defines different type of paths used by service readers/writers.
ioGdcm contains services use to deal with DICOM using the GDCM library.
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
Defines the generic file/folder selector dialog for IHM.
Defines the generic cursor for IHM. Use the Delegate design pattern.
static FWSERVICES_API ServiceConfig::sptr getDefault()
Return the default global instance of ServiceConfig.
FWIO_API void setFolder(const ::boost::filesystem::path &folder)
Sets folder path.
FWGUI_API void setType(::fwGui::dialog::ILocationDialog::Types type) override
Set the type of location for the dialog (SINGLE_FILE, FORLDER, MULTI_FILES)
static FWGUI_API bool showLoggerDialog(const std::string &title, const std::string &message, const ::fwLog::Logger::sptr &logger)
FWIO_API void clearLocations()
Clear any location set by the setFile/setFiles/setFolder setter.
FWGUI_API void saveDefaultLocation(::fwData::location::ILocation::sptr loc) override
Save the specified default location for the dialog in preferences (if available)
IOGDCM_API void info(std::ostream &_sstream) override
Override.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
virtual FWGUI_API void setDefaultCursor() override
Set the default cursor.
IOGDCM_API void updating() override
Override.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
IOGDCM_API SSeriesDBReader() noexcept
constructor