7 #include "fwGui/IFrameSrv.hpp" 9 #include "fwGui/Application.hpp" 11 #include <fwCom/Signal.hpp> 12 #include <fwCom/Signal.hxx> 13 #include <fwCom/Slot.hxx> 14 #include <fwCom/Slots.hxx> 16 #include <fwServices/macros.hpp> 17 #include <fwServices/registry/ActiveWorkers.hpp> 19 #include <fwThread/Worker.hpp> 20 #include <fwThread/Worker.hxx> 22 #include <fwTools/fwID.hpp> 24 #include <boost/foreach.hpp> 25 #include <boost/lambda/lambda.hpp> 30 const std::string IFrameSrv::CLOSE_POLICY_EXIT =
"exit";
31 const std::string IFrameSrv::CLOSE_POLICY_NOTIFY =
"notify";
32 const std::string IFrameSrv::CLOSE_POLICY_MESSAGE =
"message";
41 std::weak_ptr< ::fwGui::container::fwContainer >();
43 IFrameSrv::IFrameSrv() :
48 m_sigClosed = newSignal< ClosedSignalType >(s_CLOSED_SIG);
50 newSlot(s_SET_VISIBLE_SLOT, &IFrameSrv::setVisible,
this);
51 newSlot(s_SHOW_SLOT, &IFrameSrv::show,
this);
52 newSlot(s_HIDE_SLOT, &IFrameSrv::hide,
this);
57 IFrameSrv::~IFrameSrv()
66 std::vector < ConfigurationType > vectGui = m_configuration->find(
"gui");
67 std::vector < ConfigurationType > vectWindow = m_configuration->find(
"window");
72 std::vector < ConfigurationType > vectLayoutMng = vectGui.at(0)->find(
"frame");
73 SLM_ASSERT(
"<frame> xml element must exist", !vectLayoutMng.empty());
74 m_frameConfig = vectLayoutMng.at(0);
75 this->initializeLayoutManager(m_frameConfig);
78 std::vector < ConfigurationType > vectMBBuilder = vectGui.at(0)->find(
"menuBar");
79 if(!vectMBBuilder.empty())
81 m_menuBarConfig = vectMBBuilder.at(0);
82 this->initializeMenuBarBuilder(m_menuBarConfig);
88 std::vector < ConfigurationType > vectTBBuilder = vectGui.at(0)->find(
"toolBar");
89 if(!vectTBBuilder.empty())
91 m_toolBarConfig = vectTBBuilder.at(0);
92 this->initializeToolBarBuilder(m_toolBarConfig);
98 if(!vectWindow.empty())
100 ConfigurationType window = vectWindow.at(0);
101 std::string onclose = window->getAttributeValue(
"onclose");
102 if ( !onclose.empty() )
104 m_closePolicy = onclose;
106 SLM_ASSERT(
"Invalid onclose value : " << m_closePolicy <<
". Should be 'exit', 'notify' or 'message'",
107 m_closePolicy == CLOSE_POLICY_NOTIFY || m_closePolicy == CLOSE_POLICY_EXIT
108 || m_closePolicy == CLOSE_POLICY_MESSAGE);
111 m_viewRegistrar = ::fwGui::registrar::ViewRegistrar::New(this->getID());
113 std::vector < ConfigurationType > vectRegistrar = m_configuration->find(
"registry");
114 if(!vectRegistrar.empty())
116 m_registrarConfig = vectRegistrar.at(0);
117 m_viewRegistrar->initialize(m_registrarConfig);
125 SLM_ASSERT(
"FrameLayoutManager must be initialized.", m_frameLayoutManager);
129 m_frameLayoutManager->createFrame();
132 ::fwGui::container::fwContainer::sptr frame = m_frameLayoutManager->getFrame();
133 if ( m_progressWidget.expired() )
135 m_progressWidget = frame;
138 ::fwGui::container::fwContainer::sptr container = m_frameLayoutManager->getContainer();
139 std::vector< ::fwGui::container::fwContainer::sptr > subViews;
140 subViews.push_back(container);
141 m_viewRegistrar->manage(subViews);
143 ::fwGui::layoutManager::IFrameLayoutManager::CloseCallback fct;
145 if (m_closePolicy == CLOSE_POLICY_EXIT)
147 fct = std::bind( &::fwGui::IFrameSrv::onCloseExit,
this);
149 else if (m_closePolicy == CLOSE_POLICY_NOTIFY)
151 fct = std::bind( &::fwGui::IFrameSrv::onCloseNotify,
this);
153 else if(m_closePolicy == CLOSE_POLICY_MESSAGE)
155 fct = std::bind( &::fwGui::IFrameSrv::onCloseMessage,
this);
156 auto app = ::fwGui::Application::New();
157 app->setConfirm(
true);
160 m_frameLayoutManager->setCloseCallback(fct);
166 m_menuBarBuilder->createMenuBar(frame);
169 m_viewRegistrar->manageMenuBar(m_menuBarBuilder->getMenuBar());
176 m_toolBarBuilder->createToolBar(frame);
179 m_viewRegistrar->manageToolBar(m_toolBarBuilder->getToolBar());
187 SLM_ASSERT(
"ViewRegistrar must be initialized.", m_viewRegistrar);
191 m_viewRegistrar->unmanageToolBar();
192 SLM_ASSERT(
"ToolBarBuilder must be initialized.", m_toolBarBuilder);
196 m_toolBarBuilder->destroyToolBar();
202 m_viewRegistrar->unmanageMenuBar();
203 SLM_ASSERT(
"MenuBarBuilder must be initialized.", m_menuBarBuilder);
207 m_menuBarBuilder->destroyMenuBar();
211 m_viewRegistrar->unmanage();
212 SLM_ASSERT(
"FrameLayoutManager must be initialized.", m_frameLayoutManager);
216 m_frameLayoutManager->destroyFrame();
222 void IFrameSrv::initializeLayoutManager(ConfigurationType frameConfig)
224 OSLM_ASSERT(
"Bad configuration name "<<frameConfig->getName()<<
", must be frame",
225 frameConfig->getName() ==
"frame");
226 ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(
227 ::fwGui::layoutManager::IFrameLayoutManager::REGISTRY_KEY);
228 m_frameLayoutManager = ::fwGui::layoutManager::IFrameLayoutManager::dynamicCast(guiObj);
229 OSLM_ASSERT(
"ClassFactoryRegistry failed for class "<< ::fwGui::layoutManager::IFrameLayoutManager::REGISTRY_KEY,
230 m_frameLayoutManager);
232 m_frameLayoutManager->initialize(frameConfig);
237 void IFrameSrv::initializeMenuBarBuilder(ConfigurationType menuBarConfig)
239 OSLM_ASSERT(
"Bad configuration name "<<menuBarConfig->getName()<<
", must be menuBar",
240 menuBarConfig->getName() ==
"menuBar");
242 ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(::fwGui::builder::IMenuBarBuilder::REGISTRY_KEY);
243 m_menuBarBuilder = ::fwGui::builder::IMenuBarBuilder::dynamicCast(guiObj);
244 OSLM_ASSERT(
"ClassFactoryRegistry failed for class "<< ::fwGui::builder::IMenuBarBuilder::REGISTRY_KEY,
247 m_menuBarBuilder->initialize(menuBarConfig);
252 void IFrameSrv::initializeToolBarBuilder(ConfigurationType toolBarConfig)
254 OSLM_ASSERT(
"Bad configuration name "<<toolBarConfig->getName()<<
", must be toolBar",
255 toolBarConfig->getName() ==
"toolBar");
257 ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(::fwGui::builder::IToolBarBuilder::REGISTRY_KEY);
258 m_toolBarBuilder = ::fwGui::builder::IToolBarBuilder::dynamicCast(guiObj);
259 OSLM_ASSERT(
"ClassFactoryRegistry failed for class "<< ::fwGui::builder::IToolBarBuilder::REGISTRY_KEY,
262 m_toolBarBuilder->initialize(toolBarConfig);
267 void IFrameSrv::onCloseExit()
270 ::fwGui::Application::New()->exit(0);
275 void IFrameSrv::onCloseNotify()
278 m_sigClosed->asyncEmit();
283 void IFrameSrv::onCloseMessage()
286 auto app = ::fwGui::Application::New();
294 return m_progressWidget.lock();
299 void IFrameSrv::setVisible(
bool isVisible)
301 ::fwGui::container::fwContainer::sptr container = m_frameLayoutManager->getFrame();
302 container->setVisible(isVisible);
307 void IFrameSrv::show()
309 this->setVisible(
true);
314 void IFrameSrv::hide()
316 this->setVisible(
false);
FWGUI_API void create()
Creates frame, sub-view, menubar and toolbar containers. Manages sub-view, menubar and toobar service...
#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.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
static const ::fwCom::Slots::SlotKeyType s_SHOW_SLOT
Slot to show the container.
FWGUI_API void destroy()
Stops sub-view, menubar and toobar services. Destroys frame, sub-view, menubar and toolbar containers...
FWGUI_API void initialize()
Initialize frame managers.
static const ::fwCom::Slots::SlotKeyType s_HIDE_SLOT
Slot to hide the container.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWGUI_API::fwGui::container::fwContainer::sptr getProgressWidget()
Get widget defined for progress bar.
static const ::fwCom::Signals::SignalKeyType s_CLOSED_SIG
Signal emitted when frame is closed and onclose policy is notify.
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.
static const ::fwCom::Slots::SlotKeyType s_SET_VISIBLE_SLOT
Slot to show/hide the container.
static FWGUI_API::fwGui::container::fwContainer::wptr m_progressWidget
Static reference on a widget defined for progress bar installation.