DGtal  1.5.beta
Board2D.ih
1 /**
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU Lesser General Public License as
4  * published by the Free Software Foundation, either version 3 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  **/
16 
17 /**
18  * @file Board2D.ih
19  * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20  * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
21  *
22  * @date 2010/10/11
23  *
24  * Implementation of inline methods defined in Board2D.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 // IMPLEMENTATION of inline methods.
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 //////////////////////////////////////////////////////////////////////////////
34 #include <cstdlib>
35 #include "DGtal/io/boards/CDrawableWithBoard2D.h"
36 //////////////////////////////////////////////////////////////////////////////
37 
38 
39 
40 ///////////////////////////////////////////////////////////////////////////////
41 // Implementation of inline methods //
42 
43 /**
44  * @return the current mode for the given object name or "" if no
45  * specific mode has been set.
46  */
47 inline
48 std::string
49 DGtal::Board2D::getMode( const std::string & objectName ) const
50 {
51  ModeMapping::const_iterator itm = myModes.find( objectName );
52  return itm == myModes.end() ? "" : itm->second;
53 }
54 
55 /**
56  * Draws the drawable [object] in this board. It should satisfy
57  * the concept CDrawableWithBoard2D, which requires for instance a
58  * method setStyle( LibBoard::Board ).
59  *
60  * @param object the drawable object.
61  * @return a reference on 'this'.
62  */
63 template <typename TDrawableWithBoard2D>
64 inline
65 DGtal::Board2D &
66 DGtal::Board2D::operator<<( const TDrawableWithBoard2D & object )
67 {
68 
69  BOOST_CONCEPT_ASSERT((concepts::CDrawableWithBoard2D<TDrawableWithBoard2D>));
70 
71  CountedPtr<DrawableWithBoard2D> style( defaultStyle(object) );
72 #ifdef DEBUG_VERBOSE
73  trace.info() << "[operator<<] " << object.className();
74 #endif
75 
76  // Apply default style
77  if ( style.get() )
78  {
79 #ifdef DEBUG_VERBOSE
80  trace.info() << " [default style]";
81 #endif
82  DGtal::Style2DFactory::draw(*this, style.get());
83  }
84  // Apply Customized style
85  StyleMapping::const_iterator it = myStyles.find( object.className() );
86  if ( it != myStyles.end() )
87  if ( it->second.get() != 0 )
88  {
89 #ifdef DEBUG_VERBOSE
90  trace.info() << " [specific style]";
91 #endif
92  DGtal::Style2DFactory::draw(*this, it->second.get());
93  }
94  // Check for specific mode.
95  ModeMapping::const_iterator itm = myModes.find( object.className() );
96  if ( itm != myModes.end() )
97  {
98  #ifdef DEBUG_VERBOSE
99  trace.info() << " [mode]";
100  #endif
101 
102  // Apply default style for specific mode.
103  CountedPtr<DrawableWithBoard2D> style_mode
104  ( defaultStyle(object, itm->second) );
105  if ( style_mode.get() )
106  {
107 #ifdef DEBUG_VERBOSE
108  trace.info() << " [default style for mode]";
109 #endif
110  DGtal::Style2DFactory::draw(*this, style_mode.get());
111  }
112  // Apply customized style for specific mode.
113  std::string specific_style = object.className() + "/" + itm->second;
114  it = myStyles.find( specific_style );
115  if ( it != myStyles.end() )
116  if ( it->second.get() != 0 )
117  {
118 #ifdef DEBUG_VERBOSE
119  trace.info() << " [specific style for mode: "
120  << specific_style << "]";
121 #endif
122  DGtal::Style2DFactory::draw(*this, it->second.get());
123  }
124  }
125 #ifdef DEBUG_VERBOSE
126  trace.info() << " [draw]";
127 #endif
128 
129  DGtal::Display2DFactory::draw(*this, object);
130 #ifdef DEBUG_VERBOSE
131  std::cerr << std::endl;
132 #endif
133  return *this;
134 }
135 
136 
137 ///////////////////////////////////////////////////////////////////////////////
138 // Implementation of inline functions and external operators //
139 
140 /**
141  * Overloads 'operator<<' for displaying objects of class 'Board2D'.
142  * @param out the output stream where the object is written.
143  * @param object the object of class 'Board2D' to write.
144  * @return the output stream after the writing.
145  */
146 inline
147 std::ostream&
148 DGtal::operator<< ( std::ostream & out,
149  const Board2D & object )
150 {
151  object.selfDisplay ( out );
152  return out;
153 }
154 
155 // //
156 ///////////////////////////////////////////////////////////////////////////////
157 
158