DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Board2D.h
1 
17 #pragma once
18 
31 #if defined(Board2D_RECURSES)
32 #error Recursive header files inclusion detected in Board2D.h
33 #else // defined(Board2D_RECURSES)
34 
35 #define Board2D_RECURSES
36 
37 #if !defined Board2D_h
38 
39 #define Board2D_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "Board/Board.h"
45 #include "DGtal/base/Common.h"
46 #include "DGtal/base/CountedPtr.h"
47 #include "DGtal/io/Color.h"
49 
50 
51 
52 namespace DGtal
53 {
57  enum DomainDrawMode { GRID = 0, PAVING = 1 };
58 
59 
61  // class Board2D
70  class Board2D : public LibBoard::Board
71  {
72  // ----------------------- local types ------------------------------
73  public:
78  typedef std::map< std::string,CountedPtr<DrawableWithBoard2D> > StyleMapping;
79 
84  typedef std::map< std::string, std::string > ModeMapping;
85 
87 
88  // ----------------------- Standard services ------------------------------
89  public:
90 
94  ~Board2D();
95 
101  Board2D( const Color & backgroundColor
102  = Color::None );
103 
109  Board2D( const Board2D & other );
110 
116  Board2D & operator= ( const Board2D & other );
117 
125  std::string getMode( const std::string & objectName ) const;
126 
135  template <typename TDrawableWithBoard2D>
136  Board2D & operator<<( const TDrawableWithBoard2D & object );
137 
138 
139  // ----------------------- Interface --------------------------------------
140  public:
141 
146  void selfDisplay ( std::ostream & out ) const;
147 
152  bool isValid() const;
153 
154  // ------------------------- Public Datas ------------------------------
155  public:
161 
167 
179 
189  // ------------------------- Private Datas --------------------------------
190  private:
191 
192  }; // end of class Board2D
193 
194 
201  std::ostream&
202  operator<< ( std::ostream & out, const Board2D & object );
203 
210  std::string className() const
211  {
212  return "DrawWithBoardModifier";
213  }
214 
215  /*DrawableWithBoard2D* defaultStyle( std::string = "" ) const
216  {
217  return 0;
218  }*/
219 
220  /*virtual void setStyle( Board2D & ) const
221  {}*/
222  };
223 
224 
237  CustomStyle( std::string classname, DrawableWithBoard2D* style )
238  : myClassname( classname ), myStyle( style )
239  {}
240 
241  std::string className() const
242  {
243  return "CustomStyle";
244  }
245 
246  /*void setStyle( Board2D & board ) const
247  {
248  board.myStyles[ myClassname ] = myStyle;
249  }*/
250 
251  std::string myClassname;
253  };
254 
260  struct SetMode : public DrawWithBoardModifier {
267  SetMode( std::string classname, std::string mode )
268  : myClassname( classname ), myMode( mode )
269  {}
270 
271  /*void setStyle( Board2D & board ) const
272  {
273  board.myModes[ myClassname ] = myMode;
274  }*/
275 
276  std::string myClassname;
277  std::string myMode;
278  };
279 
292  {
295 
302  CustomColors( const Color & penColor,
303  const Color & fillColor )
304  : myPenColor( penColor ), myFillColor( fillColor )
305  {}
306 
307  virtual void setStyle( Board2D & aboard) const
308  {
309  aboard.setFillColor( myFillColor);
310  aboard.setPenColor( myPenColor );
311  }
312  };
313 
326  {
328 
334  CustomPenColor( const Color & penColor )
335  : myPenColor( penColor )
336  {}
337 
338  virtual void setStyle( Board2D & aboard) const
339  {
340  aboard.setPenColor( myPenColor );
341  }
342  };
343 
356  {
358 
364  CustomFillColor( const Color & fillColor )
365  : myFillColor( fillColor )
366  {}
367 
368  virtual void setStyle( Board2D & aboard) const
369  {
370  aboard.setFillColor( myFillColor );
371  }
372  };
373 
387  {
390  double myLineWidth;
394  int myDepth;
413  CustomPen( const Color & penColor,
414  const Color & fillColor,
415  double lineWidth = 1.0,
419  : myPenColor( penColor ), myFillColor( fillColor ),
420  myLineWidth( lineWidth ),
421  myLineStyle( lineStyle ), myLineCap ( lineCap ), myLineJoin( lineJoin )
422  {}
423 
424  virtual void setStyle( Board2D & aboard) const
425  {
426  aboard.setPenColor( myPenColor );
427  aboard.setFillColor( myFillColor );
428  aboard.setLineWidth( myLineWidth );
429  aboard.setLineStyle( myLineStyle );
430  aboard.setLineCap( myLineCap );
431  aboard.setLineJoin( myLineJoin );
432  }
433  };
434 
435 } // namespace DGtal
436 
437 
439 // Includes inline functions.
440 
441 #include "DGtal/io/Display2DFactory.h"
442 #include "DGtal/io/Style2DFactory.h"
443 #include "DGtal/io/boards/Board2D.ih"
444 
445 // //
447 
448 #endif // !defined Board2D_h
449 
450 #undef Board2D_RECURSES
451 #endif // else defined(Board2D_RECURSES)