openPSTD  2.0
Open source simulation for sound propagation in urban environments
Viewer2D.h
1 // This file is part of openPSTD. //
3 // //
4 // openPSTD is free software: you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation, either version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // openPSTD is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with openPSTD. If not, see <http://www.gnu.org/licenses/>. //
16 // //
18 
20 //
21 // Date:
22 //
23 //
24 // Authors:
25 //
26 //
27 // Purpose:
28 //
29 //
31 
32 //
33 // Created by michiel on 18-7-2015.
34 //
35 
36 #ifndef OPENPSTD_VIEWER2D_H
37 #define OPENPSTD_VIEWER2D_H
38 
39 #include <QOpenGLWidget>
40 #include <vector>
41 #include <boost/numeric/ublas/vector.hpp>
42 #include <algorithm>
43 #include "Model.h"
44 #include <QOpenGLFunctions>
45 #include <QOpenGLShaderProgram>
46 #include <QOpenGLTexture>
47 #include "operations/BaseOperation.h"
48 #include <QOpenGLBuffer>
49 
50 namespace OpenPSTD
51 {
52  namespace GUI
53  {
54 
55  class Layer;
56 
58  {
59  public:
60  MinMaxValue();
61 
62  MinMaxValue(QVector2D min, QVector2D max);
63 
64  QVector2D min;
65  QVector2D max;
66  bool Active;
67 
68  static MinMaxValue Combine(MinMaxValue first, MinMaxValue second);
69 
70  static MinMaxValue CombineList(std::vector<MinMaxValue> list);
71  };
72 
73  void DeleteNothing(void *ptr);
74 
75  void DeleteTexture(void *ptr);
76 
77  class Viewer2D : public QOpenGLWidget
78  {
79  Q_OBJECT
80 
81  public:
82  explicit Viewer2D(QWidget *parent = 0);
83 
84  virtual QSize sizeHint() const override;
85 
86  virtual QSize minimumSizeHint() const override;
87 
88  void UpdateFromModel(std::shared_ptr<Model> const &model);
89 
90  void SetOperationRunner(std::shared_ptr<OperationRunner> operationRunner);
91 
92 
93  protected:
94  virtual void resizeGL(int w, int h) override;
95 
96  virtual void initializeGL() override;
97 
98  virtual void paintGL() override;
99 
100  virtual void mousePressEvent(QMouseEvent *mouseEvent) override;
101 
102  virtual void mouseReleaseEvent(QMouseEvent *mouseEvent) override;
103 
104  virtual void mouseMoveEvent(QMouseEvent *mouseEvent) override;
105 
106  virtual void wheelEvent(QWheelEvent *qWheelEvent) override;
107 
108  private:
109  std::vector<std::shared_ptr<Layer>> layers;
110  std::shared_ptr<OperationRunner> operationRunner;
111  };
112 
113  void GLError(std::string name);
114 
115  class Layer
116  {
117  protected:
118  bool visible;
119 
120  public:
121  virtual bool GetVisible()
122  { return visible; };
123 
124  virtual void SetVisible(bool value)
125  { visible = value; };
126 
127  virtual void InitializeGL(QObject *context,
128  std::unique_ptr<QOpenGLFunctions, void (*)(void *)> const &f) = 0;
129 
130  virtual void PaintGLVisibilityCheck(QObject *context,
131  std::unique_ptr<QOpenGLFunctions, void (*)(void *)> const &f)
132  {
133  if (visible)
134  { this->PaintGL(context, f); }
135  };
136 
137  virtual void PaintGL(QObject *context, std::unique_ptr<QOpenGLFunctions, void (*)(void *)> const &f) = 0;
138 
139  virtual void UpdateScene(std::shared_ptr<Model> const &m,
140  std::unique_ptr<QOpenGLFunctions, void (*)(void *)> const &f) = 0;
141 
142  virtual MinMaxValue GetMinMax() = 0;
143  };
144 
145  }
146 }
147 
149 
150 
151 #endif //OPENPSTD_VIEWER2D_H
This is the general namespace of the OpenPSTD application.
Definition: Boundary.cpp:33
Definition: Viewer2D.h:148
Definition: Viewer2D.h:115
Definition: Viewer2D.h:57
Definition: Viewer2D.h:77