7 #include "fwGui/IGuiContainerSrv.hpp" 9 #include "fwGui/builder/IContainerBuilder.hpp" 10 #include "fwGui/builder/ISlideViewBuilder.hpp" 11 #include "fwGui/builder/IToolBarBuilder.hpp" 12 #include "fwGui/container/fwContainer.hpp" 14 #include "fwGui/registrar/ViewRegistrar.hpp" 16 #include <fwCom/Slot.hpp> 17 #include <fwCom/Slot.hxx> 18 #include <fwCom/Slots.hpp> 19 #include <fwCom/Slots.hxx> 21 #include <fwCore/base.hpp> 23 #include <fwServices/macros.hpp> 24 #include <fwServices/registry/ActiveWorkers.hpp> 26 #include <fwTools/fwID.hpp> 40 IGuiContainerSrv::IGuiContainerSrv() :
41 m_viewLayoutManagerIsCreated(false),
54 IGuiContainerSrv::~IGuiContainerSrv()
65 m_viewRegistrar = ::fwGui::registrar::ViewRegistrar::New( this->
getID() );
67 std::vector < ConfigurationType > vectViewMng =
m_configuration->find(
"registry");
68 if ( !vectViewMng.empty() )
70 m_viewRegistrarConfig = vectViewMng.at(0);
71 m_viewRegistrar->initialize(m_viewRegistrarConfig);
76 std::vector < ConfigurationType > vectGui =
m_configuration->find(
"gui");
77 if( !vectGui.empty() )
79 SLM_ASSERT(
"No <registry> tag is allowed in the <gui> section", vectGui.at(0)->find(
"registry").empty());
82 std::vector < ConfigurationType > vectLayoutMng = vectGui.at(0)->find(
"layout");
83 if( !vectLayoutMng.empty() )
85 m_viewLayoutConfig = vectLayoutMng.at(0);
86 this->initializeLayoutManager( m_viewLayoutConfig );
87 m_viewLayoutManagerIsCreated =
true;
91 std::vector < ConfigurationType > vectTBBuilder = vectGui.at(0)->find(
"toolBar");
92 if(!vectTBBuilder.empty())
94 m_toolBarConfig = vectTBBuilder.at(0);
95 this->initializeToolBarBuilder(m_toolBarConfig);
101 std::vector < ConfigurationType > vectSlideCfg = vectGui.at(0)->find(
"slideView");
102 for (
const auto& slideCfg : vectSlideCfg)
104 this->initializeSlideViewBuilder(slideCfg);
113 SLM_ASSERT(
"ViewRegistrar must be initialized.", m_viewRegistrar);
114 ::fwGui::container::fwContainer::sptr parent = m_viewRegistrar->getParent();
115 SLM_ASSERT(
"Parent container is unknown.", parent);
119 SLM_ASSERT(
"ViewRegistrar must be initialized.", m_viewRegistrar);
121 ::fwGui::GuiBaseObject::sptr guiObj =
122 ::fwGui::factory::New(::fwGui::builder::IContainerBuilder::REGISTRY_KEY);
123 m_containerBuilder = ::fwGui::builder::IContainerBuilder::dynamicCast(guiObj);
125 SLM_ASSERT(
"ClassFactoryRegistry failed for class "+ ::fwGui::builder::IContainerBuilder::REGISTRY_KEY,
127 m_containerBuilder->createContainer(parent);
129 ::fwGui::container::fwContainer::sptr container = m_containerBuilder->getContainer();
131 if ( m_viewLayoutManagerIsCreated )
137 m_toolBarBuilder->createToolBar(parent);
140 m_viewRegistrar->manageToolBar(m_toolBarBuilder->getToolBar());
145 m_viewLayoutManager->createLayout(container);
148 std::vector< ::fwGui::container::fwContainer::sptr > views = m_viewLayoutManager->getSubViews();
150 for (
const auto& slideBuilder : m_slideViewBuilders)
152 SLM_ASSERT(
"Slide builder is not instantiated", slideBuilder);
155 slideBuilder->createContainer(container);
157 views.push_back(slideBuilder->getContainer());
160 m_viewRegistrar->manage(views);
169 SLM_ASSERT(
"ViewRegistrar must be initialized.", m_viewRegistrar);
171 if ( m_viewLayoutManagerIsCreated )
175 m_viewRegistrar->unmanageToolBar();
176 SLM_ASSERT(
"ToolBarBuilder must be initialized.", m_toolBarBuilder);
180 m_toolBarBuilder->destroyToolBar();
184 m_viewRegistrar->unmanage();
185 SLM_ASSERT(
"ViewLayoutManager must be initialized.", m_viewLayoutManager);
189 m_viewLayoutManager->destroyLayout();
193 for (
const auto& slideBuilder : m_slideViewBuilders)
195 SLM_ASSERT(
"Slide builder is not instantiated", slideBuilder);
198 slideBuilder->destroyContainer();
202 m_containerBuilder->destroyContainer();
207 void IGuiContainerSrv::initializeLayoutManager(ConfigurationType layoutConfig)
209 SLM_ASSERT(
"Bad configuration name "+layoutConfig->getName()+
", must be layout",
210 layoutConfig->getName() ==
"layout");
211 SLM_ASSERT(
"<layout> tag must have type attribute", layoutConfig->hasAttribute(
"type"));
212 const std::string layoutManagerClassName = layoutConfig->getAttributeValue(
"type");
214 ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(layoutManagerClassName);
215 m_viewLayoutManager = ::fwGui::layoutManager::IViewLayoutManager::dynamicCast(guiObj);
216 SLM_ASSERT(
"ClassFactoryRegistry failed for class "+ layoutManagerClassName, m_viewLayoutManager);
218 m_viewLayoutManager->initialize(layoutConfig);
223 void IGuiContainerSrv::initializeToolBarBuilder(ConfigurationType toolBarConfig)
225 SLM_ASSERT(
"Bad configuration name "+toolBarConfig->getName()+
", must be toolBar",
226 toolBarConfig->getName() ==
"toolBar");
228 ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(::fwGui::builder::IToolBarBuilder::REGISTRY_KEY);
229 m_toolBarBuilder = ::fwGui::builder::IToolBarBuilder::dynamicCast(guiObj);
230 SLM_ASSERT(
"ClassFactoryRegistry failed for class "+ ::fwGui::builder::IToolBarBuilder::REGISTRY_KEY,
233 m_toolBarBuilder->initialize(toolBarConfig);
238 void IGuiContainerSrv::initializeSlideViewBuilder(ConfigurationType slideViewConfig)
240 SLM_ASSERT(
"Bad configuration name " + slideViewConfig->getName() +
", must be layout",
241 slideViewConfig->getName() ==
"slideView");
243 ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(
244 ::fwGui::builder::ISlideViewBuilder::REGISTRY_KEY);
245 ::fwGui::builder::ISlideViewBuilder::sptr slideViewBuildfer = ::fwGui::builder::ISlideViewBuilder::dynamicCast(
247 SLM_ASSERT(
"ClassFactoryRegistry failed for class "+ ::fwGui::builder::ISlideViewBuilder::REGISTRY_KEY,
250 slideViewBuildfer->initialize(slideViewConfig);
252 m_slideViewBuilders.push_back(slideViewBuildfer);
257 ::fwGui::container::fwContainer::sptr IGuiContainerSrv::getContainer()
259 return m_containerBuilder->getContainer();
264 void IGuiContainerSrv::setParent(std::string wid)
268 m_viewRegistrar->setParent(wid);
269 ::fwGui::container::fwContainer::sptr parent = m_viewRegistrar->getParent();
270 SLM_ASSERT(
"Parent container is unknown.", parent);
271 m_containerBuilder->setParent(parent);
279 ::fwGui::container::fwContainer::sptr container = m_viewRegistrar->getParent();
280 container->setEnabled(isEnabled);
287 this->setEnabled(
true);
294 this->setEnabled(
false);
301 ::fwGui::container::fwContainer::sptr container = m_viewRegistrar->getParent();
302 container->setVisible(isVisible);
309 this->setVisible(
true);
316 this->setVisible(
false);
static FWGUI_APIconst::fwCom::Slots::SlotKeyType s_SET_VISIBLE_SLOT
Slot to show/hide the container.
FWGUI_API void setEnabled(bool isEnabled)
SLOT: enable/disable the container.
The namespace fwGui contains the base interface for IHM services.
static const ::fwCom::Slots::SlotKeyType s_SHOW_SLOT
Slot to show the container.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
This file defines the interface of the base class for managing a layout geometry. ...
static FWGUI_APIconst::fwCom::Slots::SlotKeyType s_HIDE_SLOT
Slot to hide the container.
static FWGUI_APIconst::fwCom::Slots::SlotKeyType s_DISABLE_SLOT
Slot to disable the container.
static const ::fwCom::Slots::SlotKeyType s_HIDE_SLOT
Slot to hide the container.
static FWGUI_APIconst::fwCom::Slots::SlotKeyType s_ENABLE_SLOT
Slot to enable the container.
FWGUI_API void setVisible(bool isVisible)
SLOT: show/hide the container.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGUI_API void enable()
SLOT: enable the container.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.
static FWGUI_APIconst::fwCom::Slots::SlotKeyType s_SET_ENABLED_SLOT
Slot to enable/disable the action.
static FWGUI_APIconst::fwCom::Slots::SlotKeyType s_SHOW_SLOT
Slot to show the container.
FWGUI_API void disable()
SLOT: disable the container.
FWGUI_API void hide()
SLOT: hide the container.
static const ::fwCom::Slots::SlotKeyType s_SET_VISIBLE_SLOT
Slot to show/hide the container.
FWGUI_API void show()
SLOT: show the container.
FWGUI_API void initialize()
Initialize managers.