canvas.hh
Go to the documentation of this file.
1 
2 #include "option.hh"
3 #include "stage.hh"
4 
5 #include <map>
6 #include <stack>
7 
8 namespace Stg {
9 class Canvas : public Fl_Gl_Window {
10  friend class WorldGui; // allow access to private members
11  friend class Model;
12 
13 private:
14  class GlColorStack {
15  public:
18  void Push(double r, double g, double b, double a = 1.0) { Push(Color(r, g, b, a)); }
19  void Push(Color col)
20  {
21  colorstack.push(col);
22  glColor4f(col.r, col.g, col.b, col.a);
23  }
24 
25  void Pop()
26  {
27  if (colorstack.size() < 1)
28  PRINT_WARN1("Attempted to ColorStack.Pop() but ColorStack %p is empty",
29  static_cast<void *>(this));
30  else {
31  Color &old = colorstack.top();
32  colorstack.pop();
33  glColor4f(old.r, old.g, old.b, old.a);
34  }
35  }
36 
37  unsigned int Length() { return colorstack.size(); }
38  private:
39  std::stack<Color> colorstack;
40  } colorstack;
41 
42  std::list<Model *> models_sorted;
43 
49 
50  int startx, starty;
54  std::list<Model *> selected_models;
56 
58  msec_t interval; // window refresh interval in ms
59 
60  void RecordRay(double x1, double y1, double x2, double y2);
61  void DrawRays();
62  void ClearRays();
63  void DrawGlobalGrid();
64 
65  void AddModel(Model *mod);
66  void RemoveModel(Model *mod);
67 
68  Option // showBlinken,
73 
74 public:
75  Canvas(WorldGui *world, int x, int y, int width, int height);
76  ~Canvas();
77 
78  bool graphics;
80  unsigned long frames_rendered_count;
82 
83  std::map<std::string, Option *> _custom_options;
84 
85  void Screenshot();
86  void InitGl();
87  void InitTextures();
88  void createMenuItems(Fl_Menu_Bar *menu, std::string path);
89 
90  void FixViewport(int W, int H);
91  void DrawFloor(); // simpler floor compared to grid
92  void DrawBlocks();
93  void DrawBoundingBoxes();
94  void resetCamera();
95  virtual void renderFrame();
96  virtual void draw();
97  virtual int handle(int event);
98  void resize(int X, int Y, int W, int H);
99 
100  void CanvasToWorld(int px, int py, double *wx, double *wy, double *wz);
101 
102  Model *getModel(int x, int y);
103  bool selected(Model *mod);
104  void select(Model *mod);
105  void unSelect(Model *mod);
106  void unSelectAll();
107 
108  inline void setDirtyBuffer(void) { dirty_buffer = true; }
109  inline bool dirtyBuffer(void) const { return dirty_buffer; }
110  void PushColor(Color col) { colorstack.Push(col); }
111  void PushColor(double r, double g, double b, double a) { colorstack.Push(r, g, b, a); }
112  void PopColor() { colorstack.Pop(); }
113  void InvertView(uint32_t invertflags);
114 
115  bool VisualizeAll() { return !visualizeAll; }
116  static void TimerCallback(Canvas *canvas);
117  static void perspectiveCb(Fl_Widget *w, void *p);
118 
119  void EnterScreenCS();
120  void LeaveScreenCS();
121 
122  void Load(Worldfile *wf, int section);
123  void Save(Worldfile *wf, int section);
124 
125  bool IsTopView() { return ((fabs(camera.yaw()) < 0.1) && (fabs(camera.pitch()) < 0.1)); }
126 };
127 
128 } // namespace Stg
std::list< Model * > models_sorted
Definition: canvas.hh:42
Model class
Definition: stage.hh:1651
int starty
Definition: canvas.hh:50
bool selectedModel
Definition: canvas.hh:51
double a
Definition: stage.hh:216
Option showClock
Definition: canvas.hh:69
WorldGui * world
Definition: canvas.hh:79
OrthoCamera camera
Definition: canvas.hh:45
The Stage library uses its own namespace.
Definition: canvas.hh:8
void InitTextures()
Definition: canvas.cc:129
void select(Model *mod)
Definition: canvas.cc:281
void EnterScreenCS()
Definition: canvas.cc:1036
void ClearRays()
void setDirtyBuffer(void)
Definition: canvas.hh:108
Option showScreenshots
Definition: canvas.hh:69
void DrawRays()
void DrawFloor()
Definition: canvas.cc:668
Option showStatus
Definition: canvas.hh:69
void DrawGlobalGrid()
Definition: canvas.cc:595
virtual int handle(int event)
Definition: canvas.cc:345
bool dirty_buffer
Definition: canvas.hh:47
void createMenuItems(Fl_Menu_Bar *menu, std::string path)
Definition: canvas.cc:1130
Model * last_selection
Definition: canvas.hh:55
void DrawBoundingBoxes()
Definition: canvas.cc:691
Canvas(WorldGui *world, int x, int y, int width, int height)
Definition: canvas.cc:53
PerspectiveCamera perspective_camera
Definition: canvas.hh:46
void DrawBlocks()
Definition: canvas.cc:685
std::map< std::string, Option * > _custom_options
Definition: canvas.hh:83
bool graphics
Definition: canvas.hh:78
Option visualizeAll
Definition: canvas.hh:69
void resetCamera()
Definition: canvas.cc:705
void PushColor(Color col)
Definition: canvas.hh:110
Camera * current_camera
Definition: canvas.hh:44
void Push(Color col)
Definition: canvas.hh:19
void Screenshot()
Definition: canvas.cc:1059
void FixViewport(int W, int H)
Definition: canvas.cc:577
int screenshot_frame_skip
Definition: canvas.hh:81
std::stack< Color > colorstack
Definition: canvas.hh:39
void CanvasToWorld(int px, int py, double *wx, double *wy, double *wz)
Definition: canvas.cc:306
double r
Definition: stage.hh:216
Option showTrailRise
Definition: canvas.hh:69
Option showFootprints
Definition: canvas.hh:69
void unSelectAll()
Definition: canvas.cc:300
void RemoveModel(Model *mod)
Definition: canvas.cc:589
virtual void draw()
Definition: canvas.cc:1214
int empty_space_starty
Definition: canvas.hh:53
std::list< Model * > selected_models
Definition: canvas.hh:54
Option showBBoxes
Definition: canvas.hh:69
int startx
Definition: canvas.hh:50
double b
Definition: stage.hh:216
Worldfile * wf
Definition: canvas.hh:48
double g
Definition: stage.hh:216
void LeaveScreenCS()
Definition: canvas.cc:1050
Option showTrails
Definition: canvas.hh:69
unsigned long msec_t
Definition: stage.hh:200
Option showFollow
Definition: canvas.hh:69
Option showBlur
Definition: canvas.hh:69
void Push(double r, double g, double b, double a=1.0)
Definition: canvas.hh:18
Model * getModel(int x, int y)
Definition: canvas.cc:203
void AddModel(Model *mod)
Definition: canvas.cc:583
Option showData
Definition: canvas.hh:69
void PopColor()
Definition: canvas.hh:112
static void perspectiveCb(Fl_Widget *w, void *p)
Definition: canvas.cc:1116
void Save(Worldfile *wf, int section)
Definition: canvas.cc:1189
void PushColor(double r, double g, double b, double a)
Definition: canvas.hh:111
Option showTrailArrows
Definition: canvas.hh:69
Option showGrid
Definition: canvas.hh:69
void Load(Worldfile *wf, int section)
Definition: canvas.cc:1153
bool dirtyBuffer(void) const
Definition: canvas.hh:109
Option showFlags
Definition: canvas.hh:69
Option showBlocks
Definition: canvas.hh:69
void InitGl()
Definition: canvas.cc:96
double pitch(void) const
Definition: stage.hh:1284
unsigned long frames_rendered_count
Definition: canvas.hh:80
Option showVoxels
Definition: canvas.hh:69
bool VisualizeAll()
Definition: canvas.hh:115
Option pCamOn
Definition: canvas.hh:69
msec_t interval
(even if it is now unselected).
Definition: canvas.hh:58
double yaw(void) const
Definition: stage.hh:1283
bool selected(Model *mod)
Definition: canvas.cc:276
void resize(int X, int Y, int W, int H)
Definition: canvas.cc:1254
virtual void renderFrame()
Definition: canvas.cc:756
#define PRINT_WARN1(m, a)
Definition: stage.hh:604
void RecordRay(double x1, double y1, double x2, double y2)
unsigned int Length()
Definition: canvas.hh:37
bool IsTopView()
Definition: canvas.hh:125
Option showOccupancy
Definition: canvas.hh:69
static void TimerCallback(Canvas *canvas)
Definition: canvas.cc:42
void InvertView(uint32_t invertflags)
bool clicked_empty_space
Definition: canvas.hh:52
void unSelect(Model *mod)
Definition: canvas.cc:292
int empty_space_startx
Definition: canvas.hh:53


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Feb 28 2022 23:48:55