7 #include "ioDicom/SFilterSelectorDialog.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 13 #include <fwCore/base.hpp> 15 #include <fwData/Composite.hpp> 16 #include <fwData/String.hpp> 18 #include <fwDataTools/helper/Composite.hpp> 20 #include <fwDicomIOFilter/IFilter.hpp> 22 #include <fwGui/Cursor.hpp> 23 #include <fwGui/dialog/MessageDialog.hpp> 24 #include <fwGui/dialog/SelectorDialog.hpp> 26 #include <fwRuntime/ConfigurationElement.hpp> 27 #include <fwRuntime/helper.hpp> 29 #include <fwServices/macros.hpp> 31 #include <boost/foreach.hpp> 43 static const ::fwServices::IService::KeyType s_FILTER_INOUT =
"filter";
48 m_filtersAreExcluded( true )
66 m_selectedFilters.clear();
76 SLM_INFO(
"SFilterSelectorDialog " + (*iter)->getName());
78 if( (*iter)->getName() ==
"selection" )
80 SLM_ASSERT(
"The xml element <selection> must have the attribute 'mode'.", (*iter)->hasAttribute(
"mode"));
81 const std::string mode = (*iter)->getExistingAttributeValue(
"mode");
82 m_filtersAreExcluded = ( mode ==
"exclude" );
83 SLM_ASSERT(
"The xml attribute <mode> must be either 'exclude' or 'include'.", mode ==
"exclude" ||
88 if( (*iter)->getName() ==
"addSelection" )
90 SLM_ASSERT(
"The xml element <addSelection> must have the attribute 'filter'.",
91 (*iter)->hasAttribute(
"filter"));
92 m_selectedFilters.push_back( (*iter)->getExistingAttributeValue(
"filter") );
93 SLM_DEBUG(
"add selection => " + (*iter)->getExistingAttributeValue(
"filter") );
121 std::vector< ::fwDicomIOFilter::IFilter::sptr > registredFilters;
122 for(std::string key: ::fwDicomIOFilter::registry::get()->getFactoryKeys())
124 ::fwDicomIOFilter::IFilter::sptr filter = ::fwDicomIOFilter::factory::New(key);
125 registredFilters.push_back(filter);
129 std::map< std::string, ::fwDicomIOFilter::IFilter::sptr > availableFiltersMap;
130 std::vector< std::string > availableFilterNames;
132 for( ::fwDicomIOFilter::IFilter::sptr filter: registredFilters )
134 const bool filterIsSelectedByUser = std::find( m_selectedFilters.begin(), m_selectedFilters.end(),
135 filter->getClassname() ) != m_selectedFilters.end();
140 if( (m_filtersAreExcluded && !filterIsSelectedByUser) ||
141 (!m_filtersAreExcluded && filterIsSelectedByUser) )
144 std::string filterName = filter->getName();
145 filterName = (filterName.empty()) ? filter->getClassname() : filterName;
146 availableFiltersMap[filterName] = filter;
147 availableFilterNames.push_back( filterName );
152 std::sort( availableFilterNames.begin(), availableFilterNames.end() );
155 if ( !availableFilterNames.empty() )
157 std::string filterName = *availableFilterNames.begin();
158 bool filterSelectionIsCanceled =
false;
161 if ( availableFilterNames.size() > 1 )
163 ::fwGui::dialog::SelectorDialog::sptr selector = ::fwGui::dialog::SelectorDialog::New();
165 selector->setTitle(
"Filter to use");
166 selector->setSelections(availableFilterNames);
167 filterName = selector->show();
168 filterSelectionIsCanceled = filterName.empty();
170 SLM_ASSERT(
"Unable to find the selected filter name in the filter map.",
171 filterSelectionIsCanceled || availableFiltersMap.find(filterName) != availableFiltersMap.end() );
174 if ( !filterSelectionIsCanceled )
177 ::fwDicomIOFilter::IFilter::sptr filter = availableFiltersMap[filterName];
179 ::fwData::String::sptr obj = this->getInOut< ::fwData::String >(s_FILTER_INOUT);
183 obj = this->getObject< ::fwData::String >();
185 SLM_ASSERT(
"The filter selector service must work on a ::fwData::String object.", obj);
186 obj->setValue(filter->getClassname());
198 SLM_WARN(
"SFilterSelectorDialog::load : availableFilters is empty.");
200 messageBox.
setTitle(
"Filter not found");
201 messageBox.
setMessage(
"There is no available filter for this reader." );
202 messageBox.
setIcon(::fwGui::dialog::IMessageDialog::WARNING);
203 messageBox.
addButton(::fwGui::dialog::IMessageDialog::OK);
213 _sstream <<
"SFilterSelectorDialog";
IODICOM_API SFilterSelectorDialog()
Constructor. Do nothing (Just initialize parameters).
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
IODICOM_API void starting() override
Starts the service. Do nothing.
Class allowing to block a Connection.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
Defines the generic message box for IHM. Use the Delegate design pattern.
IODICOM_API void updating() override
#define SLM_WARN(message)
#define SLM_DEBUG(message)
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
Display a dialog to select a dicom filter.
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
IODICOM_API void configuring() override
This method initializes class member parameters from configuration elements.
ioDicom contains services used to deal with the DICOM standard.
#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...
IODICOM_API void stopping() override
Stops the service. Do nothing.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
Defines the service interface managing the editor service which create their own container.
#define SLM_INFO(message)
IODICOM_API void info(std::ostream &_sstream) override
Gives the name of the class. Do nothing.
Container::iterator Iterator
Defines the configuration element container type.
virtual IODICOM_API ~SFilterSelectorDialog() noexcept
Destructor. Do nothing.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
This class contains an std::string value.