7 #include "fwGui/layoutManager/IFrameLayoutManager.hpp" 9 #include <fwCore/base.hpp> 11 #include <fwData/Integer.hpp> 12 #include <fwData/String.hpp> 14 #include <fwPreferences/helper.hpp> 16 #include <fwRuntime/operations.hpp> 18 #include <fwServices/macros.hpp> 19 #include <fwServices/registry/ObjectService.hpp> 21 #include <boost/filesystem/operations.hpp> 22 #include <boost/lexical_cast.hpp> 27 namespace layoutManager
31 const IFrameLayoutManager::RegistryKeyType IFrameLayoutManager::REGISTRY_KEY =
"::fwGui::FrameLayoutManager";
33 const std::string IFrameLayoutManager::SOFTWARE_UI =
"SOFTWARE_UI";
34 const std::string IFrameLayoutManager::FRAME_STATE_UI =
"FRAME_STATE_UI";
35 const std::string IFrameLayoutManager::FRAME_SIZE_W_UI =
"FRAME_SIZE_W_UI";
36 const std::string IFrameLayoutManager::FRAME_SIZE_H_UI =
"FRAME_SIZE_H_UI";
37 const std::string IFrameLayoutManager::FRAME_POSITION_X_UI =
"FRAME_POSITION_X_UI";
38 const std::string IFrameLayoutManager::FRAME_POSITION_Y_UI =
"FRAME_POSITION_Y_UI";
44 CloseCallback fct = std::bind( &::fwGui::layoutManager::IFrameLayoutManager::defaultCloseCallback,
this);
45 this->setCloseCallback(fct);
58 OSLM_ASSERT(
"Bad configuration name "<<configuration->getName()<<
", must be frame",
59 configuration->getName() ==
"frame");
61 std::vector < ConfigurationType > name = configuration->find(
"name");
62 std::vector < ConfigurationType > icon = configuration->find(
"icon");
63 std::vector < ConfigurationType > minSize = configuration->find(
"minSize");
64 std::vector < ConfigurationType > styles = configuration->find(
"style");
68 m_frameInfo.
m_name = name.at(0)->getValue();
73 m_frameInfo.
m_iconPath = ::fwRuntime::getBundleResourceFilePath(icon.at(0)->getValue());
74 OSLM_ASSERT(
"The icon "<< m_frameInfo.
m_iconPath <<
" doesn't exist, please ensure that the path is correct",
75 ::boost::filesystem::exists(m_frameInfo.
m_iconPath));
80 if(minSize.at(0)->hasAttribute(
"width"))
83 ::boost::lexical_cast<
int >(minSize.at(0)->getExistingAttributeValue(
"width"));
85 if(minSize.at(0)->hasAttribute(
"height"))
87 m_frameInfo.
m_minSize.second = ::boost::lexical_cast<
int >(minSize.at(0)->getExistingAttributeValue(
94 ::fwRuntime::ConfigurationElement::sptr stylesCfgElt = styles.at(0);
95 SLM_FATAL_IF(
"<style> node must contain mode attribute", !stylesCfgElt->hasAttribute(
"mode") );
96 const std::string style = stylesCfgElt->getExistingAttributeValue(
"mode");
98 if (style ==
"DEFAULT")
102 else if (style ==
"STAY_ON_TOP")
104 m_frameInfo.
m_style = STAY_ON_TOP;
106 else if (style ==
"MODAL")
112 OSLM_FATAL(
"The style "<<style<<
" is unknown, it should be DEFAULT, STAY_ON_TOP or MODAL.");
120 void IFrameLayoutManager::setCloseCallback(CloseCallback fct)
122 this->m_closeCallback = fct;
127 void IFrameLayoutManager::defaultCloseCallback()
129 SLM_WARN(
"No specific close callback defined");
134 void IFrameLayoutManager::readConfig()
136 ::fwData::Composite::sptr prefUI = this->getPreferenceUI();
139 if ( prefUI->find( IFrameLayoutManager::FRAME_STATE_UI ) != prefUI->end() )
141 ::fwData::Integer::sptr state =
142 ::fwData::Integer::dynamicCast( (*prefUI)[ IFrameLayoutManager::FRAME_STATE_UI ] );
146 if ( prefUI->find( IFrameLayoutManager::FRAME_SIZE_W_UI ) != prefUI->end() )
148 ::fwData::Integer::sptr sizew =
149 ::fwData::Integer::dynamicCast( (*prefUI)[ IFrameLayoutManager::FRAME_SIZE_W_UI ] );
151 m_frameInfo.
m_size.first = *sizew;
153 if ( prefUI->find( IFrameLayoutManager::FRAME_SIZE_H_UI ) != prefUI->end() )
155 ::fwData::Integer::sptr sizeh =
156 ::fwData::Integer::dynamicCast( (*prefUI)[ IFrameLayoutManager::FRAME_SIZE_H_UI ] );
158 m_frameInfo.
m_size.second = *sizeh;
160 if ( prefUI->find( IFrameLayoutManager::FRAME_POSITION_X_UI ) != prefUI->end() )
162 ::fwData::Integer::sptr posx =
163 ::fwData::Integer::dynamicCast( (*prefUI)[ IFrameLayoutManager::FRAME_POSITION_X_UI ] );
167 if ( prefUI->find( IFrameLayoutManager::FRAME_POSITION_Y_UI ) != prefUI->end() )
169 ::fwData::Integer::sptr posy =
170 ::fwData::Integer::dynamicCast( (*prefUI)[ IFrameLayoutManager::FRAME_POSITION_Y_UI ] );
179 void IFrameLayoutManager::writeConfig()
181 ::fwData::Composite::sptr prefUI = this->getPreferenceUI();
186 ::fwData::Integer::sptr state = ::fwData::Integer::New(m_frameInfo.
m_state);
187 (*prefUI)[ IFrameLayoutManager::FRAME_STATE_UI ] = state;
190 ::fwData::Integer::sptr sizew = ::fwData::Integer::New(m_frameInfo.
m_size.first);
191 (*prefUI)[ IFrameLayoutManager::FRAME_SIZE_W_UI ] = sizew;
193 ::fwData::Integer::sptr sizeh = ::fwData::Integer::New(m_frameInfo.
m_size.second);
194 (*prefUI)[ IFrameLayoutManager::FRAME_SIZE_H_UI ] = sizeh;
196 ::fwData::Integer::sptr posx = ::fwData::Integer::New(m_frameInfo.
m_position.first);
197 (*prefUI)[ IFrameLayoutManager::FRAME_POSITION_X_UI ] = posx;
199 ::fwData::Integer::sptr posy = ::fwData::Integer::New(m_frameInfo.
m_position.second);
200 (*prefUI)[ IFrameLayoutManager::FRAME_POSITION_Y_UI ] = posy;
206 ::fwData::Composite::sptr IFrameLayoutManager::getPreferenceUI()
208 ::fwData::Composite::sptr prefUI;
209 ::fwData::Composite::sptr prefs = ::fwPreferences::getPreferences();
214 ::fwData::Composite::sptr framesUI;
216 if ( prefs->find( IFrameLayoutManager::SOFTWARE_UI ) == prefs->end() )
218 framesUI = ::fwData::Composite::New();
219 (*prefs)[ IFrameLayoutManager::SOFTWARE_UI ] = framesUI;
223 framesUI = ::fwData::Composite::dynamicCast( (*prefs)[ IFrameLayoutManager::SOFTWARE_UI ]);
226 if ( framesUI->find( this->m_frameInfo.m_name ) != framesUI->end() )
228 prefUI = ::fwData::Composite::dynamicCast( (*framesUI)[ this->m_frameInfo.
m_name ] );
232 prefUI = ::fwData::Composite::New();
233 (*framesUI)[ this->m_frameInfo.
m_name ] = prefUI;
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
The namespace fwGui contains the base interface for IHM services.
Style m_style
Frame style.
std::string m_name
Frame name.
FWGUI_API IFrameLayoutManager()
Constructor. Do nothing.
#define SLM_WARN(message)
virtual FWGUI_API void initialize(ConfigurationType configuration)
Configure the layout before creation.
std::pair< int, int > m_minSize
Frame minimum size (min width and min height)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual FWGUI_API ~IFrameLayoutManager()
Destructor. Do nothing.
std::pair< int, int > m_position
Frame position.
#define SLM_FATAL_IF(message, cond)
#define OSLM_FATAL(message)
::boost::filesystem::path m_iconPath
Frame icon.
std::pair< int, int > m_size
Frame size.
FrameState m_state
Frame state (maximize, minized, full screen)