fw4spl
CardinalLayoutManagerBase.cpp
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 
15 #include "fwGui/layoutManager/CardinalLayoutManagerBase.hpp"
16 
17 #include <fwCore/base.hpp>
18 
19 #include <boost/assign/list_of.hpp>
20 #include <boost/lexical_cast.hpp>
21 
22 namespace fwGui
23 {
24 
25 namespace layoutManager
26 {
27 //-----------------------------------------------------------------------------
28 
29 const CardinalLayoutManagerBase::RegistryKeyType CardinalLayoutManagerBase::REGISTRY_KEY =
30  "::fwGui::CardinalLayoutManager";
31 
32 //-----------------------------------------------------------------------------
33 
34 const std::map<std::string, CardinalLayoutManagerBase::Align> CardinalLayoutManagerBase::STRING_TO_ALIGN =
35  ::boost::assign::map_list_of("center",CENTER)
36  ("right",RIGHT)
37  ("left",LEFT)
38  ("bottom",BOTTOM)
39  ("top",TOP);
40 
41 //-----------------------------------------------------------------------------
42 
44 {
45 }
46 
47 //-----------------------------------------------------------------------------
48 
50 {
51 }
52 
53 //-----------------------------------------------------------------------------
54 
55 void CardinalLayoutManagerBase::initialize( ConfigurationType configuration)
56 {
57  OSLM_ASSERT("Bad configuration name "<<configuration->getName()<< ", must be layout",
58  configuration->getName() == "layout");
59 
60  std::vector < ConfigurationType > vectViews = configuration->find("view");
61  SLM_TRACE_IF("No view define.", vectViews.empty() );
62  m_views.clear();
63  for (ConfigurationType view : vectViews)
64  {
65  ViewInfo vi;
66  if( view->hasAttribute("align") )
67  {
68  std::string align = view->getExistingAttributeValue("align");
69  OSLM_ASSERT("Align "<<align<<" unknown", STRING_TO_ALIGN.find(align) != STRING_TO_ALIGN.end() );
70  vi.m_align = STRING_TO_ALIGN.find(align)->second;
71  }
72 
73  if( view->hasAttribute("minWidth") )
74  {
75  std::string width = view->getExistingAttributeValue("minWidth");
76  vi.m_minSize.first = ::boost::lexical_cast< int >(width);
77  }
78 
79  if( view->hasAttribute("minHeight") )
80  {
81  std::string height = view->getExistingAttributeValue("minHeight");
82  vi.m_minSize.second = ::boost::lexical_cast< int >(height);
83  }
84 
85  if( view->hasAttribute("resizable") )
86  {
87  std::string resizable = view->getExistingAttributeValue("resizable");
88  OSLM_ASSERT("Incorrect value for \"resizable\" attribute "<<resizable,
89  (resizable == "yes") || (resizable == "no"));
90  vi.m_isResizable = (resizable=="yes");
91  }
92 
93  if( view->hasAttribute("position") )
94  {
95  std::string position = view->getExistingAttributeValue("position");
96  vi.m_position = ::boost::lexical_cast< int >(position);
97  }
98 
99  if( view->hasAttribute("layer") )
100  {
101  std::string layer = view->getExistingAttributeValue("layer");
102  vi.m_layer = ::boost::lexical_cast< int >(layer);
103  }
104 
105  if( view->hasAttribute("row") )
106  {
107  std::string row = view->getExistingAttributeValue("row");
108  vi.m_row = ::boost::lexical_cast< int >(row);
109  }
110 
111  if( view->hasAttribute("visible") )
112  {
113  std::string visible = view->getExistingAttributeValue("visible");
114  OSLM_ASSERT("Incorrect value for \"visible\" attribute "<<visible,
115  (visible == "true") || (visible == "false") ||
116  (visible == "yes") || (visible == "no"));
117  vi.m_visible = ((visible == "true") || (visible == "yes"));
118  }
119 
120  if( view->hasAttribute("caption") )
121  {
122  vi.m_caption.first = true;
123  vi.m_caption.second = view->getExistingAttributeValue("caption");
124  }
125 
126  if( view->hasAttribute("useScrollBar") )
127  {
128  std::string useScrollBar = view->getExistingAttributeValue("useScrollBar");
129  OSLM_ASSERT("Incorrect value for \"useScrollBar\" attribute "<<useScrollBar,
130  (useScrollBar == "yes") || (useScrollBar == "no"));
131  vi.m_useScrollBar = (useScrollBar=="yes");
132  }
133 
134  m_views.push_back(vi);
135  }
136 }
137 
138 //-----------------------------------------------------------------------------
139 
140 } // namespace layoutManager
141 } // namespace fwGui
142 
143 
144 
#define SLM_TRACE_IF(message, cond)
Definition: spyLog.hpp:232
virtual FWGUI_API void initialize(ConfigurationType configuration) override
Initialize cardinal layout manager before the creation of layout.
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
FWGUI_API CardinalLayoutManagerBase()
Constructor. Do nothing.
virtual FWGUI_API ~CardinalLayoutManagerBase()
Destructor. Do nothing.