fw4spl
ui/uiVisu/src/uiVisu/action/SSnapshot.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 <fwCom/Signal.hpp>
8 #include <fwCom/Signal.hxx>
9 
10 #include <fwCore/base.hpp>
11 
12 #include <fwData/location/SingleFile.hpp>
13 
14 #include <fwRuntime/ConfigurationElement.hpp>
15 #include <fwRuntime/operations.hpp>
16 
17 #include <fwServices/macros.hpp>
18 
19 #include <fwGui/dialog/LocationDialog.hpp>
20 
21 #include "uiVisu/action/SSnapshot.hpp"
22 
23 namespace uiVisu
24 {
25 namespace action
26 {
27 
28 const ::fwCom::Signals::SignalKeyType SSnapshot::s_SNAPPED_SIG = "snapped";
29 
30 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::uiVisu::action::SSnapshot, ::fwData::Object );
31 
32 
33 SSnapshot::SSnapshot() noexcept
34 {
35  m_sigSnapped = newSignal< SnappedSignalType >(s_SNAPPED_SIG);
36 }
37 
38 //------------------------------------------------------------------------------
39 
41 {
42 }
43 
44 //------------------------------------------------------------------------------
45 
47 {
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 {
63 }
64 
65 //------------------------------------------------------------------------------
66 
68 {
69  std::string filename = this->requestFileName();
70 
71  if(!filename.empty())
72  {
73  m_sigSnapped->asyncEmit(filename);
74  }
75 }
76 
77 //------------------------------------------------------------------------------
78 
80 {
81 
82 }
83 
84 //------------------------------------------------------------------------------
85 
86 void SSnapshot::info( std::ostream &_sstream )
87 {
88 }
89 
90 //------------------------------------------------------------------------------
91 
92 std::string SSnapshot::requestFileName()
93 {
94  std::string fileName = "";
95 
97  dialogFile.setTitle("Save snapshot as");
98  dialogFile.addFilter("Image file","*.jpg *.jpeg *.bmp *.png *.tiff");
99  dialogFile.addFilter("jpeg","*.jpg *.jpeg");
100  dialogFile.addFilter("bmp","*.bmp");
101  dialogFile.addFilter("png","*.png");
102  dialogFile.addFilter("tiff","*.tiff");
103  dialogFile.addFilter("all","*.*");
104  dialogFile.setOption(::fwGui::dialog::ILocationDialog::WRITE);
105 
106  ::fwData::location::SingleFile::sptr result;
107  result = ::fwData::location::SingleFile::dynamicCast( dialogFile.show() );
108  if (result)
109  {
110  fileName = result->getPath().string();
111  }
112 
113  return fileName;
114 }
115 
116 //------------------------------------------------------------------------------
117 
118 } // action
119 } // uiVisu
120 
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
virtual void info(std::ostream &_sstream) override
Write information in a stream.
virtual void stopping() override
Stops action.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
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.
void updating() override
Show a file dialog and notify the scene which must be printed.
FWGUI_API void addFilter(const std::string &filterName, const std::string &wildcardList) override
specify some filtering when browsing files:
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
The namespace uiVisu contains action to modifies cross type and 3D camera orientation.
virtual UIVISU_API ~SSnapshot() noexcept
Destructor. Do nothing.
virtual void starting() override
Starts action.
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
Base class for each data object.
This action allows to snapshot a generic scene.
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
Defines the generic file/folder selector dialog for IHM.
UIVISU_API SSnapshot() noexcept
Constructor. Do nothing.
void configuring() override
Configure action.