Commit 01bba262 authored by Emilie Harquel's avatar Emilie Harquel
Browse files

see #1947 : Added action to snapshot the generic scene

--HG--
branch : fw4spl_0.7.9
parent 69a7bb47
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2012.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
#ifndef __UIVISU_ACTION_SSNAPSHOT_HPP__
#define __UIVISU_ACTION_SSNAPSHOT_HPP__
#include <string>
#include <map>
#include <fwTools/Failed.hpp>
#include <fwGui/IActionSrv.hpp>
#include "uiVisu/config.hpp"
namespace uiVisu
{
namespace action
{
/**
* @brief This action allows to snapshot a generic scene
* @class SSnapshot.
* @author IRCAD (Research and Development Team).
* @date 2012.
*
* Send a CompositeMsg with SNAP event containing the uid of the scene to the scene's composite.
*/
class UIVISU_CLASS_API SSnapshot : public ::fwGui::IActionSrv
{
public :
fwCoreServiceClassDefinitionsMacro ( (SSnapshot)(::fwGui::IActionSrv) ) ;
/// Constructor. Do nothing.
UIVISU_API SSnapshot() throw() ;
/// Destructor. Do nothing.
UIVISU_API virtual ~SSnapshot() throw() ;
protected:
typedef ::fwRuntime::ConfigurationElement::sptr Configuration;
/// Starts action
virtual void starting() throw(::fwTools::Failed);
/// Stops action
virtual void stopping() throw(::fwTools::Failed);
/// Does nothing
virtual void updating( ::boost::shared_ptr< const fwServices::ObjectMsg > _msg ) throw(::fwTools::Failed);
/// Show a file dialog and notify the scene which must be printed.
void updating() throw(::fwTools::Failed);
/// Does nothing
void swapping() throw(::fwTools::Failed);
/**
* @brief Configure action.
* @verbatim
<service type="::fwGui::IActionSrv" implementation="::uiData::action::SSnapshot" autoComChannel="no">
<snap>
<scene uid="genericScene" />
</snap>
</service>
@endverbatim
* - \b genericScene is the uid of the ::fwRenderVTK::VtkRenderService representing the generic scene which will be printed.
*/
void configuring() throw(fwTools::Failed);
virtual void info( std::ostream &_sstream ) ;
private:
std::string requestFileName();
std::vector< std::string > m_scenesUID;
};
} // action
} // uiVisu
#endif // __UIVISU_ACTION_SSNAPSHOT_HPP__
......@@ -16,6 +16,12 @@
<service>::uiVisu::action::CameraOrientationAction</service>
<object>::fwData::Image</object>
</extension>
<extension implements="::fwServices::registry::ServiceFactory">
<type>::fwGui::IActionSrv</type>
<service>::uiVisu::action::SSnapshot</service>
<object>::fwTools::Object</object>
</extension>
</plugin>
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2012.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
#include <fwCore/base.hpp>
#include <fwData/Composite.hpp>
#include <fwData/String.hpp>
#include <fwData/location/SingleFile.hpp>
#include <fwComEd/CompositeMsg.hpp>
#include <fwRuntime/ConfigurationElement.hpp>
#include <fwRuntime/operations.hpp>
#include <fwServices/Base.hpp>
#include <fwServices/IEditionService.hpp>
#include <fwGui/dialog/LocationDialog.hpp>
#include "uiVisu/action/SSnapshot.hpp"
namespace uiVisu
{
namespace action
{
REGISTER_SERVICE( ::fwGui::IActionSrv , ::uiVisu::action::SSnapshot , ::fwTools::Object ) ;
SSnapshot::SSnapshot() throw()
{
this->handlingEventOff();
}
//------------------------------------------------------------------------------
SSnapshot::~SSnapshot() throw()
{}
//------------------------------------------------------------------------------
void SSnapshot::starting() throw(::fwTools::Failed)
{
SLM_TRACE_FUNC();
::fwGui::IActionSrv::actionServiceStarting();
}
//------------------------------------------------------------------------------
void SSnapshot::stopping() throw(::fwTools::Failed)
{
SLM_TRACE_FUNC();
::fwGui::IActionSrv::actionServiceStopping();
}
//------------------------------------------------------------------------------
void SSnapshot::configuring() throw(fwTools::Failed)
{
SLM_TRACE_FUNC();
::fwGui::IActionSrv::initialize();
std::vector < Configuration > snapConfig = m_configuration->find("snap");
if(!snapConfig.empty())
{
std::vector < Configuration > sceneConfig = snapConfig.at(0)->find("scene");
for(unsigned int i =0; i < sceneConfig.size(); i++)
{
OSLM_ASSERT("Wrong tag name: " << sceneConfig.at(i)->getName(), sceneConfig.at(i)->getName() == "scene");
SLM_ASSERT("UID attribute is missing", sceneConfig.at(i)->hasAttribute("uid"));
std::string value(sceneConfig.at(i)->getAttributeValue("uid"));
m_scenesUID.push_back(value);
}
}
}
//------------------------------------------------------------------------------
void SSnapshot::updating() throw(::fwTools::Failed)
{
SLM_TRACE_FUNC();
for(unsigned int i=0; i < m_scenesUID.size(); i++)
{
::fwServices::IService::sptr service = ::fwServices::get(m_scenesUID.at(i));
::fwData::Composite::sptr composite = service->getObject< ::fwData::Composite >();
SLM_ASSERT("SnapshotEditor sceneUID " << m_scenesUID.at(i) <<" isn't a GenericScene?" , composite);
::fwData::Object::NewSptr dataInfo;
::fwData::String::NewSptr sceneID;
sceneID->value() = m_scenesUID.at(i);
::fwData::String::NewSptr filename;
filename->value() = this->requestFileName();
if(!filename->value().empty())
{
dataInfo->setFieldSingleElement("sceneID", sceneID);
dataInfo->setFieldSingleElement("filename", filename);
::fwComEd::CompositeMsg::NewSptr compositeMsg;
compositeMsg->addEvent( "SNAP", dataInfo );
::fwServices::IEditionService::notify(this->getSptr(), composite, compositeMsg);
}
}
}
//------------------------------------------------------------------------------
void SSnapshot::swapping() throw(::fwTools::Failed)
{
}
//------------------------------------------------------------------------------
void SSnapshot::updating( ::fwServices::ObjectMsg::csptr _msg ) throw(::fwTools::Failed)
{
}
//------------------------------------------------------------------------------
void SSnapshot::info( std::ostream &_sstream )
{
}
//------------------------------------------------------------------------------
std::string SSnapshot::requestFileName()
{
std::string fileName = "";
::fwGui::dialog::LocationDialog dialogFile;
dialogFile.setTitle("Save snapshot as");
dialogFile.addFilter("Image file","*.jpg *.jpeg *.bmp *.png *.tiff");
dialogFile.addFilter("jpeg","*.jpg *.jpeg");
dialogFile.addFilter("bmp","*.bmp");
dialogFile.addFilter("png","*.png");
dialogFile.addFilter("tiff","*.tiff");
dialogFile.addFilter("all","*.*");
dialogFile.setOption(::fwGui::dialog::ILocationDialog::WRITE);
::fwData::location::SingleFile::sptr result;
result= ::fwData::location::SingleFile::dynamicCast( dialogFile.show() );
if (result)
{
fileName = result->getPath().string();
}
return fileName;
}
//------------------------------------------------------------------------------
} // action
} // uiVisu
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment