7 #include "ioDcmtk/SSeriesDBReader.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 13 #include <fwCore/base.hpp> 15 #include <fwData/String.hpp> 17 #include <fwDcmtkIO/SeriesDBReader.hpp> 19 #include <fwGui/Cursor.hpp> 20 #include <fwGui/dialog/LocationDialog.hpp> 21 #include <fwGui/dialog/MessageDialog.hpp> 22 #include <fwGui/dialog/ProgressDialog.hpp> 24 #include <fwIO/IReader.hpp> 26 #include <fwMedData/SeriesDB.hpp> 28 #include <fwServices/macros.hpp> 29 #include <fwServices/op/Add.hpp> 30 #include <fwServices/registry/ServiceConfig.hpp> 32 #include <fwTools/ProgressToLogger.hpp> 55 static ::boost::filesystem::path _sDefaultPath;
60 dialogFile.
setOption(::fwGui::dialog::ILocationDialog::READ);
61 dialogFile.
setType(::fwGui::dialog::LocationDialog::FOLDER);
63 ::fwData::location::Folder::sptr result;
64 result = ::fwData::location::Folder::dynamicCast( dialogFile.
show() );
67 _sDefaultPath = result->getFolder();
73 if(!m_filterSelectorSrvConfig.empty())
76 ::fwRuntime::ConfigurationElement::csptr filterSelectorConfig;
78 m_filterSelectorSrvConfig,
"::ioDicom::SFilterSelectorDialog");
80 SLM_ASSERT(
"There is no service configuration " 81 + m_filterSelectorSrvConfig
82 +
" for ::ioDicom::SFilterSelectorDialog", filterSelectorConfig);
85 ::fwServices::IService::sptr filterSelectorSrv;
86 ::fwData::String::sptr key = ::fwData::String::New();
87 filterSelectorSrv = ::fwServices::add(key,
88 "::fwGui::editor::IDialogEditor",
89 "::ioDicom::SFilterSelectorDialog");
90 filterSelectorSrv->setConfiguration( ::fwRuntime::ConfigurationElement::constCast(filterSelectorConfig) );
91 filterSelectorSrv->configure();
92 filterSelectorSrv->start();
93 filterSelectorSrv->update();
94 filterSelectorSrv->stop();
95 ::fwServices::OSR::unregisterService( filterSelectorSrv );
97 m_filterType = key->getValue();
109 ::fwRuntime::ConfigurationElement::sptr selectorConfig =
113 SLM_ASSERT(
"Missing 'name' attribute", selectorConfig->hasAttribute(
"name"));
114 m_filterSelectorSrvConfig = selectorConfig->getAttributeValue(
"name");
118 const ::fwRuntime::ConfigurationElement::sptr sopClassSelection =
120 if(sopClassSelection)
126 it != sopClassElements.
end(); ++it)
128 const ::fwRuntime::ConfigurationElement::AttributePair attributePair = (*it)->getSafeAttributeValue(
"uid");
129 if(attributePair.first)
131 SLM_TRACE(
"New SOP class supported : " + attributePair.second);
132 m_supportedSOPClassSelection.push_back(attributePair.second);
138 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"config");
141 m_filterType = config->getAttributeValue(
"filterType");
163 _sstream <<
"SSeriesDBReader::info";
170 return "Choose a directory with DICOM images";
175 ::fwMedData::SeriesDB::sptr SSeriesDBReader::createSeriesDB(const ::boost::filesystem::path& dicomDir)
178 ::fwDcmtkIO::SeriesDBReader::sptr myLoader = ::fwDcmtkIO::SeriesDBReader::New();
179 ::fwMedData::SeriesDB::sptr dummy = ::fwMedData::SeriesDB::New();
180 myLoader->setObject(dummy);
181 myLoader->setFolder(dicomDir);
182 myLoader->setDicomFilterType(m_filterType);
183 myLoader->setSupportedSOPClassContainer(m_supportedSOPClassSelection);
185 if(myLoader->isDicomDirAvailable())
188 messageBox.
setTitle(
"Dicomdir file");
189 messageBox.
setMessage(
"There is a dicomdir file in the root folder. " 190 "Would you like to use it for the reading process ?" );
191 messageBox.
setIcon(::fwGui::dialog::IMessageDialog::QUESTION);
192 messageBox.
addButton(::fwGui::dialog::IMessageDialog::YES_NO);
195 myLoader->setDicomdirActivated(button == ::fwGui::dialog::IMessageDialog::YES);
201 myLoader->addHandler( progressMeterGUI );
204 catch (
const std::exception& e)
206 std::stringstream ss;
207 ss <<
"Warning during loading : " << e.what();
209 "Warning", ss.str(), ::fwGui::dialog::IMessageDialog::WARNING);
214 "Warning",
"Warning during loading", ::fwGui::dialog::IMessageDialog::WARNING);
217 return myLoader->getConcreteObject();
227 ::fwMedData::SeriesDB::sptr seriesDB = createSeriesDB( this->
getFolder() );
229 if( seriesDB->size() > 0 )
232 ::fwMedData::SeriesDB::sptr associatedSeriesDB =
233 this->getInOut< ::fwMedData::SeriesDB >(::fwIO::s_DATA_KEY);
234 SLM_ASSERT(
"associated SeriesDB not instanced", associatedSeriesDB);
235 associatedSeriesDB->shallowCopy( seriesDB );
238 cursor.
setCursor(::fwGui::ICursor::BUSY);
239 this->notificationOfDBUpdate();
245 "Image Reader",
"This file can not be read. Retry with another file reader.",
246 ::fwGui::dialog::IMessageDialog::WARNING);
253 void SSeriesDBReader::notificationOfDBUpdate()
255 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(::fwIO::s_DATA_KEY);
256 SLM_ASSERT(
"Unable to get seriesDB", seriesDB);
258 ::fwMedData::SeriesDB::ContainerType addedSeries;
259 for(const ::fwMedData::Series::sptr& s : seriesDB->getContainer() )
261 addedSeries.push_back(s);
266 sig->asyncEmit(addedSeries);
273 return ::fwIO::FOLDER;
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.
FWRUNTIME_API Iterator begin()
Retrieves the iterator on the first managed configuration element.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
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 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.
FWRUNTIME_API ConfigurationElementContainer findAllConfigurationElement(const std::string &name) const
Retrieves the configurations corresponding to the specified name.
FWIO_APIconst::boost::filesystem::path & getFolder() const
Returns folder path set by the user or set during service configuration.
Defines the generic progress dialog for IHM. Use the Delegate design pattern. The specific implementa...
virtual IODCMTK_API void stopping() override
Override.
virtual IODCMTK_API ~SSeriesDBReader() noexcept
destructor
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
IODCMTK_API::fwIO::IOPathType getIOPathType() const override
Return path type managed by the service, here FOLDER.
virtual IODCMTK_API void configuring() override
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_SERIES_SIG
Type of signal when series are added.
IODCMTK_API SSeriesDBReader() noexcept
constructor
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.
virtual IODCMTK_API std::string getSelectorDialogTitle() override
Override.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
IODCMTK_API void info(std::ostream &_sstream) override
Override.
virtual IODCMTK_API void configureWithIHM() override
Override.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
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.
#define SLM_TRACE(message)
IODCMTK_API void updating() override
Override.
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
virtual IODCMTK_API void starting() override
Override.
Defines the generic file/folder selector dialog for IHM.
Defines the generic configuration element container class.
Defines the generic cursor for IHM. Use the Delegate design pattern.
Read ImageSeries from DICOM with dcmtk.
static FWSERVICES_API ServiceConfig::sptr getDefault()
Return the default global instance of ServiceConfig.
ioDcmtk contains services use to deal with DICOM using the GDCM library.
FWRUNTIME_API Iterator end()
Retrieves the iterator on the end of the configuration element container.
FWIO_API void setFolder(const ::boost::filesystem::path &folder)
Sets folder path.
Container::iterator Iterator
Defines the configuration element container type.
FWGUI_API void setType(::fwGui::dialog::ILocationDialog::Types type) override
Set the type of location for the dialog (SINGLE_FILE, FORLDER, MULTI_FILES)
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.