7 #include "ioGdcm/SDicomSeriesDBReader.hpp" 9 #include <fwCom/Signal.hxx> 11 #include <fwData/mt/ObjectWriteLock.hpp> 13 #include <fwGdcmIO/reader/SeriesDB.hpp> 15 #include <fwGui/Cursor.hpp> 16 #include <fwGui/dialog/LocationDialog.hpp> 17 #include <fwGui/dialog/LoggerDialog.hpp> 18 #include <fwGui/dialog/MessageDialog.hpp> 20 #include <fwIO/IReader.hpp> 22 #include <fwJobs/IJob.hpp> 23 #include <fwJobs/Observer.hpp> 25 #include <fwMedData/SeriesDB.hpp> 27 #include <fwMedDataTools/helper/SeriesDB.hpp> 29 #include <fwServices/macros.hpp> 31 #include <fwTools/System.hpp> 41 static const ::fwCom::Signals::SignalKeyType JOB_CREATED_SIGNAL =
"jobCreated";
47 m_showLogDialog(true),
48 m_dicomDirSupport(USER_SELECTION)
50 m_sigJobCreated = newSignal<JobCreatedSignal>(JOB_CREATED_SIGNAL);
66 ::fwRuntime::ConfigurationElement::sptr logDialog =
m_configuration->findConfigurationElement(
"showLogDialog");
69 std::string logDialogStr = logDialog->getValue();
70 SLM_ASSERT(
"<showLogDialog> value must be 'yes' or 'no'", logDialogStr ==
"yes" || logDialogStr ==
"no");
71 m_showLogDialog = (logDialogStr ==
"yes");
75 ::fwRuntime::ConfigurationElement::sptr dicomDir =
m_configuration->findConfigurationElement(
"dicomdirSupport");
78 std::string dicomDirStr = dicomDir->getValue();
79 SLM_ASSERT(
"<dicomdirSupport> value must be 'always' or 'never' or 'user_selection'",
80 dicomDirStr ==
"always" || dicomDirStr ==
"never" || dicomDirStr ==
"user_selection");
82 if(dicomDirStr ==
"always")
84 m_dicomDirSupport = ALWAYS;
86 else if(dicomDirStr ==
"never")
88 m_dicomDirSupport =
NEVER;
90 else if(dicomDirStr ==
"user_selection")
101 static ::boost::filesystem::path _sDefaultPath;
106 dialogFile.
setOption(::fwGui::dialog::ILocationDialog::READ);
107 dialogFile.
setType(::fwGui::dialog::LocationDialog::FOLDER);
109 ::fwData::location::Folder::sptr result;
110 result = ::fwData::location::Folder::dynamicCast( dialogFile.
show() );
113 _sDefaultPath = result->getFolder();
135 _sstream <<
"SDicomSeriesDBReader::info";
142 return "Choose a directory with DICOM images";
147 ::fwMedData::SeriesDB::sptr SDicomSeriesDBReader::createSeriesDB(const ::boost::filesystem::path& dicomDir)
149 ::fwGdcmIO::reader::SeriesDB::sptr reader = ::fwGdcmIO::reader::SeriesDB::New();
150 ::fwMedData::SeriesDB::sptr seriesDB = ::fwMedData::SeriesDB::New();
151 reader->setObject(seriesDB);
152 reader->setFolder(dicomDir);
154 auto job = reader->getJob();
155 m_sigJobCreated->emit(job);
157 if(m_dicomDirSupport ==
USER_SELECTION && reader->isDicomDirAvailable())
160 messageBox.
setTitle(
"Dicomdir file");
161 messageBox.
setMessage(
"There is a dicomdir file in the root folder. " 162 "Would you like to use it for the reading process ?" );
163 messageBox.
setIcon(::fwGui::dialog::IMessageDialog::QUESTION);
164 messageBox.
addButton(::fwGui::dialog::IMessageDialog::YES_NO);
167 reader->setDicomdirActivated(button == ::fwGui::dialog::IMessageDialog::YES);
169 else if(m_dicomDirSupport == ALWAYS)
171 reader->setDicomdirActivated(
true);
175 reader->setDicomdirActivated(
false);
180 reader->readDicomSeries();
183 ::fwLog::Logger::sptr logger = reader->getLogger();
187 if(m_showLogDialog && !logger->empty())
189 std::stringstream ss;
190 if(seriesDB->size() > 1)
192 ss <<
"The reading process is over : <b>" << seriesDB->size() <<
" series</b> have been found. " 193 "<br>Please verify the log report to be informed of the potential errors.";
197 ss <<
"The reading process is over : <b>" << seriesDB->size() <<
" series</b> has been found. " 198 "<br>Please verify the log report to be informed of the potential errors.";
202 if(!reader->getJob()->cancelRequested())
208 if(!result || reader->getJob()->cancelRequested())
215 catch (
const std::exception& e)
217 std::stringstream ss;
218 ss <<
"Warning during loading : " << e.what();
220 "Warning", ss.str(), ::fwGui::dialog::IMessageDialog::WARNING);
225 "Warning",
"Warning during loading", ::fwGui::dialog::IMessageDialog::WARNING);
228 m_cancelled = job->cancelRequested();
240 cursor.
setCursor(::fwGui::ICursor::BUSY);
242 ::fwMedData::SeriesDB::sptr seriesDB = createSeriesDB(this->
getFolder() );
244 if( seriesDB->size() > 0 && !m_cancelled)
247 ::fwMedData::SeriesDB::sptr associatedSeriesDB =
248 this->getInOut< ::fwMedData::SeriesDB >(::fwIO::s_DATA_KEY);
249 SLM_ASSERT(
"associated SeriesDB not instanced", associatedSeriesDB);
259 associatedSeriesDB->shallowCopy(seriesDB);
262 ::fwMedData::SeriesDB::ContainerType addedSeries = associatedSeriesDB->getContainer();
266 sig->asyncEmit(addedSeries);
276 return ::fwIO::FOLDER;
virtual IOGDCM_API void configuring() override
Configuring method. This method is used to configure the service.
virtual FWGUI_API void setCursor(::fwGui::ICursor::CursorType cursor) override
Set the cursor.
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 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)
IOGDCM_API void updating() override
Override.
virtual IOGDCM_API std::string getSelectorDialogTitle() override
Override.
virtual IOGDCM_API void starting() 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)
virtual IOGDCM_API void stopping() override
Override.
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.
IOGDCM_API void info(std::ostream &_sstream) override
Override.
Reader service API. It manages extension points definition and extension configuration.
IOGDCM_API::fwIO::IOPathType getIOPathType() const override
Return path type managed by the service, here FOLDER.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
Read DicomSeries from DICOM folder with GDCM reader.
IOGDCM_API SDicomSeriesDBReader() noexcept
constructor
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
virtual IOGDCM_API void configureWithIHM() override
Override.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
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.
virtual IOGDCM_API ~SDicomSeriesDBReader() noexcept override
destructor
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)
FWGUI_API void saveDefaultLocation(::fwData::location::ILocation::sptr loc) override
Save the specified default location for the dialog in preferences (if available)
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.