GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Drawable.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 #ifndef _libCore_Drawable_hpp_
31 #define _libCore_Drawable_hpp_
32 
33 #include <iosfwd>
34 #include <map>
35 
36 #ifndef SERVER
37  #if defined OSX
38  #include <OpenGL/gl.h>
39  #else
40  #include <GL/gl.h>
41  #endif
42 #endif
43 
44 #include "GranOO3/Core/Color.hpp"
45 
46 namespace GranOO3
47 {
48  namespace Core
49  {
50  class Drawable;
51 
52  std::ostream& operator<< (std::ostream &, const Drawable &);
53 
54  class Drawable
55  {
56 
57  public:
59  // Methodes used for OpenGL drawing:
60  static void set_draw_precision(unsigned int p);
61  static void increase_draw_precision();
62  static void decrease_draw_precision();
63  static unsigned int get_draw_precision();
64 
65  public:
66  Drawable();
67  virtual ~Drawable();
68 
69  virtual void draw();
70  virtual void draw_edge();
71  virtual void init_default_color();
72  virtual std::ostream& get_info(std::ostream &os) const {return os;}
73  virtual const Color& default_color() const;
74 
75  Color& get_color();
76  const Color& get_color() const;
77  virtual void set_color(const Color&);
78  virtual void set_alpha(float alpha);
79 
80  void apply_color() const;
81  void apply_edge_color() const;
82  void apply_default_color();
83  void apply_selected_color();
84 
85  void set_line_width(float);
86  float get_line_width() const;
87  float& get_line_width();
88  void apply_line_width() const;
89 
90  bool is_visible() const;
91  void set_visible(bool);
92 
93  void paint();
94  void paint_edge();
95  unsigned int get_item_glkey() const;
96 
97  private:
99  static std::map<int, Drawable*> _map;
100  static unsigned int _draw_precision;
101  static unsigned int _draw_precision_max;
102  static unsigned int _draw_precision_min;
103 
104  private:
105  const unsigned int _item_glkey;
108  float _line_width;
109  bool _visible;
110 
111  };
112 
113  inline void
115  }
116 
117  inline void
119  }
120 
121  inline void
123  }
124 
125  inline const Color&
127  static const Color* c = new Color(1., 0., 0.);
128  return *c;
129  }
130 
131  }
132 }
133 
134 #endif
Definition: Color.hpp:44
Definition: Drawable.hpp:55
bool is_visible() const
Definition: Drawable.cpp:175
static unsigned int get_draw_precision()
Definition: Drawable.cpp:73
virtual void set_color(const Color &)
Definition: Drawable.cpp:123
void set_visible(bool)
Definition: Drawable.cpp:180
Color _color
Definition: Drawable.hpp:106
bool _visible
Definition: Drawable.hpp:109
unsigned int get_item_glkey() const
Definition: Drawable.cpp:207
virtual void set_alpha(float alpha)
Definition: Drawable.cpp:128
virtual void init_default_color()
Definition: Drawable.hpp:122
static unsigned int _draw_precision_min
Definition: Drawable.hpp:102
virtual const Color & default_color() const
Definition: Drawable.hpp:126
Color & get_color()
Definition: Drawable.cpp:113
static std::map< int, Drawable * > _map
Definition: Drawable.hpp:99
virtual void draw_edge()
Definition: Drawable.hpp:118
const unsigned int _item_glkey
Definition: Drawable.hpp:105
void apply_default_color()
Definition: Drawable.cpp:97
void set_line_width(float)
Definition: Drawable.cpp:153
static Drawable & get_drawable_item_by_glkey(int)
Definition: Drawable.cpp:78
virtual void draw()
Definition: Drawable.hpp:114
void apply_selected_color()
Definition: Drawable.cpp:102
Color _edge_color
Definition: Drawable.hpp:107
static void set_draw_precision(unsigned int p)
Definition: Drawable.cpp:51
virtual ~Drawable()
Definition: Drawable.cpp:93
static unsigned int _draw_precision_max
Definition: Drawable.hpp:101
virtual std::ostream & get_info(std::ostream &os) const
Definition: Drawable.hpp:72
void apply_edge_color() const
Definition: Drawable.cpp:143
void apply_line_width() const
Definition: Drawable.cpp:168
void paint_edge()
Definition: Drawable.cpp:196
Drawable()
Definition: Drawable.cpp:83
float _line_width
Definition: Drawable.hpp:108
static int _drawable_item_counter
Definition: Drawable.hpp:98
void paint()
Definition: Drawable.cpp:185
static unsigned int _draw_precision
Definition: Drawable.hpp:100
float get_line_width() const
Definition: Drawable.cpp:158
static void decrease_draw_precision()
Definition: Drawable.cpp:65
static void increase_draw_precision()
Definition: Drawable.cpp:57
void apply_color() const
Definition: Drawable.cpp:133
std::ostream & operator<<(std::ostream &os, const Color &color)
Definition: Color.cpp:38
Definition: Common.hpp:198