fw4spl
SPacsConfigurationEditor.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "ioPacs/SPacsConfigurationEditor.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Signals.hpp>
12 
13 #include <fwGui/dialog/MessageDialog.hpp>
14 
15 #include <fwGuiQt/container/QtContainer.hpp>
16 
17 #include <fwPacsIO/exceptions/Base.hpp>
18 
19 #include <fwServices/macros.hpp>
20 
21 #include <boost/foreach.hpp>
22 
23 #include <QGridLayout>
24 #include <QHBoxLayout>
25 #include <QLabel>
26 #include <QVBoxLayout>
27 
28 namespace ioPacs
29 {
30 
31 fwServicesRegisterMacro( ::fwGui::editor::IEditor, ::ioPacs::SPacsConfigurationEditor,
33 
34 static const ::fwServices::IService::KeyType s_CONFIG_INOUT = "config";
35 
36 //------------------------------------------------------------------------------
37 
39 {
40 }
41 //------------------------------------------------------------------------------
42 
44 {
45 }
46 
47 //------------------------------------------------------------------------------
48 
49 void SPacsConfigurationEditor::info(std::ostream& _sstream )
50 {
51  _sstream << "SPacsConfigurationEditor::info";
52 }
53 
54 //------------------------------------------------------------------------------
55 
57 {
59 
60  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
61  s_CONFIG_INOUT);
62  if (!pacsConfiguration)
63  {
64  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
65  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
66  }
67  SLM_ASSERT("Pacs configuration object should not be null.", pacsConfiguration);
68 
70  ::fwGuiQt::container::QtContainer::sptr qtContainer = fwGuiQt::container::QtContainer::dynamicCast(getContainer());
71 
72  QGridLayout* gridLayout = new QGridLayout();
73 
74  // Local application title
75  m_localApplicationTitleWidget = new QLineEdit();
76  m_localApplicationTitleWidget->setText(pacsConfiguration->getLocalApplicationTitle().c_str());
77  gridLayout->addWidget(new QLabel("Local application title:"), 0, 0);
78  gridLayout->addWidget(m_localApplicationTitleWidget, 0, 1);
79 
80  // Pacs host name
81  m_pacsHostNameWidget = new QLineEdit();
82  m_pacsHostNameWidget->setText(pacsConfiguration->getPacsHostName().c_str());
83  gridLayout->addWidget(new QLabel("Pacs host name:"), 2, 0);
84  gridLayout->addWidget(m_pacsHostNameWidget, 2, 1);
85 
86  // Pacs application title
87  m_pacsApplicationTitleWidget = new QLineEdit();
88  m_pacsApplicationTitleWidget->setText(pacsConfiguration->getPacsApplicationTitle().c_str());
89  gridLayout->addWidget(new QLabel("Pacs application title:"), 3, 0);
90  gridLayout->addWidget(m_pacsApplicationTitleWidget, 3, 1);
91 
92  // Pacs application port
93  m_pacsApplicationPortWidget = new QSpinBox();
94  m_pacsApplicationPortWidget->setRange(0, 65535);
95  m_pacsApplicationPortWidget->setValue(pacsConfiguration->getPacsApplicationPort());
96  gridLayout->addWidget(new QLabel("Pacs application port:"), 4, 0);
97  gridLayout->addWidget(m_pacsApplicationPortWidget, 4, 1);
98 
99  // Move application title
100  m_moveApplicationTitleWidget = new QLineEdit();
101  m_moveApplicationTitleWidget->setText(pacsConfiguration->getMoveApplicationTitle().c_str());
102  gridLayout->addWidget(new QLabel("Move application title:"), 5, 0);
103  gridLayout->addWidget(m_moveApplicationTitleWidget, 5, 1);
104 
105  // Move application port
106  m_moveApplicationPortWidget = new QSpinBox();
107  m_moveApplicationPortWidget->setRange(0, 65535);
108  m_moveApplicationPortWidget->setValue(pacsConfiguration->getMoveApplicationPort());
109  gridLayout->addWidget(new QLabel("Move application port:"), 6, 0);
110  gridLayout->addWidget(m_moveApplicationPortWidget, 6, 1);
111 
112  // Retrieve method
113  m_retrieveMethodWidget = new QComboBox();
114  m_retrieveMethodWidget->addItem("Move");
115  m_retrieveMethodWidget->addItem("Get");
116  m_retrieveMethodWidget->setCurrentIndex(
117  (pacsConfiguration->getRetrieveMethod() == ::fwPacsIO::data::PacsConfiguration::MOVE_RETRIEVE_METHOD) ? 0 : 1);
118  gridLayout->addWidget(new QLabel("Retrieve method:"), 7, 0);
119  gridLayout->addWidget(m_retrieveMethodWidget, 7, 1);
120 
121  // Test button
122  m_pingPacsButtonWidget = new QPushButton("Ping Pacs");
123  gridLayout->addWidget(m_pingPacsButtonWidget, 8, 0, 1, 2);
124 
125  qtContainer->setLayout(gridLayout);
126 
127  // Connect the signals
128  QObject::connect(m_pingPacsButtonWidget, SIGNAL(clicked()), this, SLOT(pingPacs()));
129  QObject::connect(m_localApplicationTitleWidget, SIGNAL(editingFinished()), this, SLOT(
130  localApplicationTitleChanged()));
131  QObject::connect(m_pacsHostNameWidget, SIGNAL(editingFinished()), this, SLOT(pacsHostNameChanged()));
132  QObject::connect(m_pacsApplicationTitleWidget, SIGNAL(editingFinished()), this,
133  SLOT(pacsApplicationTitleChanged()));
134  QObject::connect(m_pacsApplicationPortWidget, SIGNAL(valueChanged(int)), this,
135  SLOT(pacsApplicationPortChanged(int)));
136  QObject::connect(m_moveApplicationTitleWidget, SIGNAL(editingFinished()), this,
137  SLOT(moveApplicationTitleChanged()));
138  QObject::connect(m_moveApplicationPortWidget, SIGNAL(valueChanged(int)), this,
139  SLOT(moveApplicationPortChanged(int)));
140  QObject::connect(m_retrieveMethodWidget, SIGNAL(currentIndexChanged(int)), this, SLOT(retrieveMethodChanged(int)));
141 
142 }
143 
144 //------------------------------------------------------------------------------
145 
147 {
148  SLM_TRACE_FUNC();
149 
150  // Disconnect the signals
151  QObject::disconnect(m_pingPacsButtonWidget, SIGNAL(clicked()), this, SLOT(pingPacs()));
152  QObject::disconnect(m_localApplicationTitleWidget, SIGNAL(editingFinished()), this,
153  SLOT(localApplicationTitleChanged()));
154  QObject::disconnect(m_pacsHostNameWidget, SIGNAL(editingFinished()), this, SLOT(pacsHostNameChanged()));
155  QObject::disconnect(m_pacsApplicationTitleWidget, SIGNAL(editingFinished()), this,
156  SLOT(pacsApplicationTitleChanged()));
157  QObject::disconnect(m_pacsApplicationPortWidget, SIGNAL(valueChanged(int)), this,
158  SLOT(pacsApplicationPortChanged(int)));
159  QObject::disconnect(m_moveApplicationTitleWidget, SIGNAL(editingFinished()), this,
160  SLOT(moveApplicationTitleChanged()));
161  QObject::disconnect(m_moveApplicationPortWidget, SIGNAL(valueChanged(int)), this,
162  SLOT(moveApplicationPortChanged(int)));
163  QObject::disconnect(m_retrieveMethodWidget, SIGNAL(currentIndexChanged(int)), this,
164  SLOT(retrieveMethodChanged(int)));
165 
166  this->destroy();
167 }
168 
169 //------------------------------------------------------------------------------
170 
172 {
173  SLM_TRACE_FUNC();
175 }
176 
177 //------------------------------------------------------------------------------
178 
180 {
181  SLM_TRACE_FUNC();
182 }
183 
184 //------------------------------------------------------------------------------
185 
186 void SPacsConfigurationEditor::pingPacs()
187 {
188  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
189  s_CONFIG_INOUT);
190  if (!pacsConfiguration)
191  {
192  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
193  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
194  }
195 
196  ::fwPacsIO::SeriesEnquirer::sptr seriesEnquirer = ::fwPacsIO::SeriesEnquirer::New();
197 
198  bool success = false;
199  try
200  {
201  seriesEnquirer->initialize(
202  pacsConfiguration->getLocalApplicationTitle(),
203  pacsConfiguration->getPacsHostName(),
204  pacsConfiguration->getPacsApplicationPort(),
205  pacsConfiguration->getPacsApplicationTitle(),
206  pacsConfiguration->getMoveApplicationTitle());
207  seriesEnquirer->connect();
208  success = seriesEnquirer->pingPacs();
209  seriesEnquirer->disconnect();
210  }
211  catch (::fwPacsIO::exceptions::Base& exception)
212  {
213  SLM_TRACE(exception.what());
214  success = false;
215  }
216 
217  // Display a message with the ping result.
219  messageBox.setTitle("Ping Pacs");
220  if(success)
221  {
222  messageBox.setMessage( "Ping succeed !" );
223  }
224  else
225  {
226  messageBox.setMessage( "Ping failed !" );
227  }
228  messageBox.setIcon(::fwGui::dialog::IMessageDialog::INFO);
229  messageBox.addButton(::fwGui::dialog::IMessageDialog::OK);
230  messageBox.show();
231 
232 }
233 
234 //------------------------------------------------------------------------------
235 
236 void SPacsConfigurationEditor::modifiedNotify(::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration)
237 {
238  auto sig = pacsConfiguration->signal< ::fwData::Object::ModifiedSignalType >(::fwData::Object::s_MODIFIED_SIG);
239  {
240  ::fwCom::Connection::Blocker block(sig->getConnection(m_slotUpdate));
241  sig->asyncEmit();
242  }
243 }
244 
245 //------------------------------------------------------------------------------
246 
247 void SPacsConfigurationEditor::localApplicationTitleChanged()
248 {
249  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
250  s_CONFIG_INOUT);
251  if (!pacsConfiguration)
252  {
253  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
254  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
255  }
256  pacsConfiguration->setLocalApplicationTitle(m_localApplicationTitleWidget->text().toStdString());
257 
258  modifiedNotify(pacsConfiguration);
259 }
260 
261 //------------------------------------------------------------------------------
262 
263 void SPacsConfigurationEditor::pacsHostNameChanged()
264 {
265  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
266  s_CONFIG_INOUT);
267  if (!pacsConfiguration)
268  {
269  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
270  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
271  }
272  pacsConfiguration->setPacsHostName(m_pacsHostNameWidget->text().toStdString());
273 
274  modifiedNotify(pacsConfiguration);
275 }
276 
277 //------------------------------------------------------------------------------
278 
279 void SPacsConfigurationEditor::pacsApplicationTitleChanged()
280 {
281  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
282  s_CONFIG_INOUT);
283  if (!pacsConfiguration)
284  {
285  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
286  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
287  }
288  pacsConfiguration->setPacsApplicationTitle(m_pacsApplicationTitleWidget->text().toStdString());
289 
290  modifiedNotify(pacsConfiguration);
291 }
292 
293 //------------------------------------------------------------------------------
294 
295 void SPacsConfigurationEditor::pacsApplicationPortChanged(int value)
296 {
297  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
298  s_CONFIG_INOUT);
299  if (!pacsConfiguration)
300  {
301  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
302  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
303  }
304  pacsConfiguration->setPacsApplicationPort(static_cast<unsigned short>(value));
305 
306  modifiedNotify(pacsConfiguration);
307 }
308 
309 //------------------------------------------------------------------------------
310 
311 void SPacsConfigurationEditor::moveApplicationTitleChanged()
312 {
313  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
314  s_CONFIG_INOUT);
315  if (!pacsConfiguration)
316  {
317  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
318  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
319  }
320  pacsConfiguration->setMoveApplicationTitle(m_moveApplicationTitleWidget->text().toStdString());
321 
322  modifiedNotify(pacsConfiguration);
323 }
324 
325 //------------------------------------------------------------------------------
326 
327 void SPacsConfigurationEditor::moveApplicationPortChanged(int value)
328 {
329  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
330  s_CONFIG_INOUT);
331  if (!pacsConfiguration)
332  {
333  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
334  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
335  }
336  pacsConfiguration->setMoveApplicationPort(static_cast<unsigned short>(value));
337 
338  modifiedNotify(pacsConfiguration);
339 }
340 
341 //------------------------------------------------------------------------------
342 
343 void SPacsConfigurationEditor::retrieveMethodChanged(int index)
344 {
345  ::fwPacsIO::data::PacsConfiguration::sptr pacsConfiguration = this->getInOut< ::fwPacsIO::data::PacsConfiguration >(
346  s_CONFIG_INOUT);
347  if (!pacsConfiguration)
348  {
349  FW_DEPRECATED_KEY(s_CONFIG_INOUT, "inout", "fw4spl_18.0");
350  pacsConfiguration = this->getObject< ::fwPacsIO::data::PacsConfiguration >();
351  }
352  pacsConfiguration->setRetrieveMethod(
353  (index ==
354  0) ? (::fwPacsIO::data::PacsConfiguration::MOVE_RETRIEVE_METHOD): (::fwPacsIO::data::PacsConfiguration::
355  GET_RETRIEVE_METHOD));
356 
357  modifiedNotify(pacsConfiguration);
358 }
359 
360 } // namespace ioPacs
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Definition: spyLog.hpp:366
virtual IOPACS_API void starting() override
Override.
Class allowing to block a Connection.
Definition: Connection.hpp:20
ioPacs contains services use to deal with PACS using DCMTK library.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
QPointer< QLineEdit > m_pacsApplicationTitleWidget
Pacs application title.
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
Defines the service interface managing the editor service for object.
Definition: IEditor.hpp:25
IOPACS_API void info(std::ostream &_sstream) override
Override.
Defines the generic message box for IHM. Use the Delegate design pattern.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
virtual IOPACS_API ~SPacsConfigurationEditor() noexcept
Destructor.
This class defines a Pacs configuration.
virtual IOPACS_API void configuring() override
Configuring method. This method is used to configure the service.
virtual IOPACS_API void stopping() override
Override.
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
Definition: IService.hpp:690
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
QPointer< QLineEdit > m_localApplicationTitleWidget
Local application title.
IOPACS_API SPacsConfigurationEditor() noexcept
Constructor.
This editor service is used to edit a pacs configuration.
QPointer< QComboBox > m_retrieveMethodWidget
Retrieve method.
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
QPointer< QLineEdit > m_pacsHostNameWidget
Pacs host name.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
#define SLM_TRACE(message)
Definition: spyLog.hpp:228
QPointer< QPushButton > m_pingPacsButtonWidget
Test button.
QPointer< QSpinBox > m_pacsApplicationPortWidget
Pacs application port.
QPointer< QSpinBox > m_moveApplicationPortWidget
Move application port.
QPointer< QLineEdit > m_moveApplicationTitleWidget
Move application title.
IOPACS_API void updating() override
Override.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
FWGUI_API void initialize()
Initialize managers.