Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/src/glwidget.h
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI glwidget *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter RÃ¥back *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
41
#ifndef GLWIDGET_H
42
#define GLWIDGET_H
43
44
enum ListTypes {
45
POINTLIST,
46
EDGELIST,
47
SURFACELIST,
48
SURFACEMESHLIST,
49
SHARPEDGELIST,
50
VOLUMEMESHLIST,
51
UNKNOWNLIST
52
};
53
54
#ifndef WIN32
55
#ifndef __APPLE__
56
#include <GL/glu.h>
57
#else
58
#include <OpenGL/glu.h>
59
#endif
60
#endif
61
62
#ifdef __MINGW32__
63
#include <GL/glu.h>
64
#endif
65
66
#ifdef WIN32
67
#ifndef __MINGW32__
68
#ifdef _CONSOLE
69
#include <GL/glut.h> // when compiling with MSVC
70
#endif
71
#endif
72
#endif
73
74
#if WITH_QT6
75
#include <QOpenGLWidget>
76
#else
77
#include <QGLWidget>
78
#endif
79
#include <QHash>
80
#include <QMap>
81
#include <QVector>
82
#include "helpers.h"
83
#include "meshutils.h"
84
85
#define DUMMY_NAME 0xffffffff
86
87
class list_t {
88
public:
89
list_t();
90
~list_t();
91
92
void setNature(int);
93
int getNature() const;
94
void setType(int);
95
int getType() const;
96
void setIndex(int);
97
int getIndex() const;
98
void setObject(GLuint);
99
GLuint getObject() const;
100
void setChild(int);
101
int getChild() const;
102
void setParent(int);
103
int getParent() const;
104
void setSelected(bool);
105
bool isSelected() const;
106
void setVisible(bool);
107
bool isVisible() const;
108
109
private:
110
int nature; // PDE_UNKNOWN, PDE_BOUNDARY, PDE_BULK, ...
111
int type; // POINTLIST, EDGELIST, SURFACELIST, ...
112
int index; // Boundary condition as defined in input file
113
GLuint object; // GL list index as returned by glGenLists()
114
int child; // Index to the child list (-1 = no child)
115
int parent; // Index to the parent list (-1 = no parent)
116
bool selected; // Currently selected?
117
bool visible; // Currently visible?
118
};
119
120
#if WITH_QT6
121
class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
122
{
123
Q_OBJECT
124
public:
125
void updateGL(); // just to replace updateGL() in .cpp file to update() for Qt6 compatibility;
126
void renderText(double x, double y, double z, const QString & str, const QFont & font = QFont(), int listBase = 2000);
127
inline GLint project(GLdouble objx, GLdouble objy, GLdouble objz,
128
const GLdouble model[16], const GLdouble proj[16],
129
const GLint viewport[4],
130
GLdouble * winx, GLdouble * winy, GLdouble * winz);
131
inline void transformPoint(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]);
132
#else
133
class GLWidget : public QGLWidget
134
{
135
Q_OBJECT
136
#endif
137
138
public:
139
GLWidget(QWidget *parent = 0);
140
~GLWidget();
141
142
QSize minimumSizeHint() const;
143
QSize sizeHint() const;
144
145
void setMesh(mesh_t*);
146
mesh_t* getMesh() const;
147
void newMesh();
148
void deleteMesh();
149
bool hasMesh() const;
150
151
list_t* getList(int) const;
152
int getLists() const;
153
154
void rebuildLists();
155
void rebuildSurfaceLists();
156
void rebuildEdgeLists();
157
void changeProjection();
158
159
bool toggleCoordinates();
160
161
static void indexColors(double *, int);
162
static void indexColors(int *, int);
163
164
// public state variables:
165
bool stateOrtho;
166
bool stateFlatShade;
167
bool stateDrawSurfaceMesh;
168
bool stateDrawVolumeMesh;
169
bool stateDrawSharpEdges;
170
bool stateDrawSurfaceElements;
171
bool stateDrawEdgeElements;
172
bool stateDrawCoordinates;
173
bool stateDrawSurfaceNumbers;
174
bool stateDrawEdgeNumbers;
175
bool stateDrawNodeNumbers;
176
bool stateDrawBoundaryIndex;
177
bool stateDrawBodyIndex;
178
bool stateBcColors;
179
bool stateBodyColors;
180
bool bodyEditActive;
181
bool stateUseBgImage;
182
bool stateStretchBgImage;
183
bool stateAlignRightBgImage;
184
QString bgImageFileName;
185
int currentlySelectedBody;
186
QColor backgroundColor;
187
QColor surfaceColor;
188
QColor edgeColor;
189
QColor surfaceMeshColor;
190
QColor sharpEdgeColor;
191
QColor selectionColor;
192
193
// public hash tables:
194
QMap<int, int> boundaryMap; // QHash<int, int> boundaryMap;
195
QMap<int, int> bodyMap; // QHash<int, int> bodyMap;
196
197
public slots:
198
199
signals:
200
void signalBoundarySelected(list_t*, Qt::KeyboardModifiers);
201
void escPressed();
202
203
protected:
204
void initializeGL();
205
void paintGL();
206
void resizeGL(int, int);
207
208
void focusInEvent(QFocusEvent*);
209
void mouseDoubleClickEvent(QMouseEvent*);
210
void mousePressEvent(QMouseEvent*);
211
void mouseReleaseEvent(QMouseEvent*);
212
void mouseMoveEvent(QMouseEvent*);
213
void wheelEvent(QWheelEvent*);
214
void keyPressEvent(QKeyEvent*);
215
void keyReleaseEvent(QKeyEvent*);
216
217
private:
218
QVector<list_t*> list;
219
220
mesh_t *mesh;
221
222
Helpers *helpers;
223
Meshutils *meshutils;
224
225
GLuint makeLists();
226
227
QREAL_OR_FLOAT matrix[16];
228
QREAL_OR_FLOAT invmatrix[16];
229
void getMatrix();
230
231
QPoint lastPos;
232
233
/* lastPressPos declared below is used to identify whether to show contextmenu or
234
not when releasing right mouse button*/
235
QPoint lastPressPos;
236
237
GLuint generateSurfaceList(int, QColor);
238
GLuint generateSurfaceMeshList(int, QColor);
239
GLuint generateVolumeMeshList(QColor);
240
GLuint generateEdgeList(int, QColor);
241
GLuint generateSharpEdgeList(QColor);
242
243
GLUquadricObj *quadric_axis;
244
void drawCoordinates();
245
246
double drawTranslate[3];
247
double drawScale;
248
249
int bgSizeX;
250
int bgSizeY;
251
GLuint bgTexture;
252
void drawBgImage();
253
254
void changeNormalDirection(double*, double*);
255
256
void setMeshVisibility(bool, bool, bool);
257
258
public:
259
int mostVisibleBody(int, bool*);
260
};
261
262
#endif
263
264