fw4spl
src/fwGui/dialog/InputDialog.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 "fwGui/dialog/InputDialog.hpp"
8 
9 #include <fwServices/registry/ActiveWorkers.hpp>
10 
11 namespace fwGui
12 {
13 namespace dialog
14 {
15 //-----------------------------------------------------------------------------
16 
17 std::string InputDialog::showInputDialog(const std::string& title, const std::string& message, const std::string& text)
18 {
19  ::fwGui::dialog::InputDialog inputBox(title, message, text);
20  return inputBox.getInput();
21 }
22 
23 //-----------------------------------------------------------------------------
24 
26 {
27  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >([&]
28  {
29  ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(IInputDialog::REGISTRY_KEY);
30  m_implementation = ::fwGui::dialog::IInputDialog::dynamicCast(guiObj);
31  }));
32 }
33 
34 //-----------------------------------------------------------------------------
35 
36 InputDialog::InputDialog(const std::string& title, const std::string& message, const std::string& text)
37 {
38  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >( [&]
39  {
40  ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(IInputDialog::REGISTRY_KEY);
41  m_implementation = ::fwGui::dialog::IInputDialog::dynamicCast(guiObj);
42  m_implementation->setTitle(title);
43  m_implementation->setMessage(message);
44  m_implementation->setInput(text);
45  }));
46 }
47 
48 //-----------------------------------------------------------------------------
49 
51 {
52 }
53 
54 //-----------------------------------------------------------------------------
55 
56 void InputDialog::setTitle( const std::string& title )
57 {
58  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >([&]
59  {
60  m_implementation->setTitle(title);
61  })).wait();
62 }
63 
64 //-----------------------------------------------------------------------------
65 
66 void InputDialog::setMessage( const std::string& msg )
67 {
68  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >( [&]
69  {
70  m_implementation->setMessage(msg);
71  })).wait();
72 }
73 
74 //-----------------------------------------------------------------------------
75 
76 void InputDialog::setInput(const std::string& text)
77 {
78  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>(std::function< void() >([&]
79  {
80  m_implementation->setInput(text);
81  })).wait();
82 }
83 
84 //-----------------------------------------------------------------------------
85 
86 std::string InputDialog::getInput()
87 {
88  std::function< std::string() > func = std::bind(&IInputDialog::getInput, m_implementation);
89  std::shared_future< std::string > f =
90  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<std::string>(func);
91  f.wait();
92  return f.get();
93 }
94 
95 //-----------------------------------------------------------------------------
96 
97 } //namespace dialog
98 } // namespace fwGui
99 
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the input dialog.
virtual FWGUI_API std::string getInput() override
Get the input text in the input field.
virtual FWGUI_API std::string getInput()=0
Get the input text in the input field.
static FWGUI_API std::string showInputDialog(const std::string &title, const std::string &message, const std::string &text="")
Defines the generic input dialog for IHM. Use the Delegate design pattern.
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.
virtual FWGUI_API ~InputDialog()
Destructor. Do nothing.
FWGUI_API InputDialog()
Constructor. Create the implementation of the specific input dialog box.
::fwGui::dialog::IInputDialog::sptr m_implementation
Implementation of an input dialog in a specific IHM (wx/Qt)
virtual FWGUI_API void setInput(const std::string &text) override
Set the input text in the input field.