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: Juha.Ruokolainen@csc.fi * 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 #include <QGLWidget> 75 #include <QHash> 76 #include <QMap> 77 #include <QVector> 78 #include "helpers.h" 79 #include "meshutils.h" 80 81 #define DUMMY_NAME 0xffffffff 82 83 class list_t { 84 public: 85 list_t(); 86 ~list_t(); 87 88 void setNature(int); 89 int getNature() const; 90 void setType(int); 91 int getType() const; 92 void setIndex(int); 93 int getIndex() const; 94 void setObject(GLuint); 95 GLuint getObject() const; 96 void setChild(int); 97 int getChild() const; 98 void setParent(int); 99 int getParent() const; 100 void setSelected(bool); 101 bool isSelected() const; 102 void setVisible(bool); 103 bool isVisible() const; 104 105 private: 106 int nature; // PDE_UNKNOWN, PDE_BOUNDARY, PDE_BULK, ... 107 int type; // POINTLIST, EDGELIST, SURFACELIST, ... 108 int index; // Boundary condition as defined in input file 109 GLuint object; // GL list index as returned by glGenLists() 110 int child; // Index to the child list (-1 = no child) 111 int parent; // Index to the parent list (-1 = no parent) 112 bool selected; // Currently selected? 113 bool visible; // Currently visible? 114 }; 115 116 class GLWidget : public QGLWidget 117 { 118 Q_OBJECT 119 120 public: 121 GLWidget(QWidget *parent = 0); 122 ~GLWidget(); 123 124 QSize minimumSizeHint() const; 125 QSize sizeHint() const; 126 127 void setMesh(mesh_t*); 128 mesh_t* getMesh() const; 129 void newMesh(); 130 void deleteMesh(); 131 bool hasMesh() const; 132 133 list_t* getList(int) const; 134 int getLists() const; 135 136 void rebuildLists(); 137 void rebuildSurfaceLists(); 138 void rebuildEdgeLists(); 139 void changeProjection(); 140 141 bool toggleCoordinates(); 142 143 static void indexColors(double *, int); 144 static void indexColors(int *, int); 145 146 // public state variables: 147 bool stateOrtho; 148 bool stateFlatShade; 149 bool stateDrawSurfaceMesh; 150 bool stateDrawVolumeMesh; 151 bool stateDrawSharpEdges; 152 bool stateDrawSurfaceElements; 153 bool stateDrawEdgeElements; 154 bool stateDrawCoordinates; 155 bool stateDrawSurfaceNumbers; 156 bool stateDrawEdgeNumbers; 157 bool stateDrawNodeNumbers; 158 bool stateDrawBoundaryIndex; 159 bool stateDrawBodyIndex; 160 bool stateBcColors; 161 bool stateBodyColors; 162 bool ctrlPressed; 163 bool shiftPressed; 164 bool altPressed; 165 bool bodyEditActive; 166 bool stateUseBgImage; 167 bool stateStretchBgImage; 168 bool stateAlignRightBgImage; 169 QString bgImageFileName; 170 int currentlySelectedBody; 171 QColor backgroundColor; 172 QColor surfaceColor; 173 QColor edgeColor; 174 QColor surfaceMeshColor; 175 QColor sharpEdgeColor; 176 177 // public hash tables: 178 QMap<int, int> boundaryMap; // QHash<int, int> boundaryMap; 179 QMap<int, int> bodyMap; // QHash<int, int> bodyMap; 180 181 public slots: 182 183 signals: 184 void signalBoundarySelected(list_t*); 185 void escPressed(); 186 187 protected: 188 void initializeGL(); 189 void paintGL(); 190 void resizeGL(int, int); 191 192 void focusInEvent(QFocusEvent*); 193 void mouseDoubleClickEvent(QMouseEvent*); 194 void mousePressEvent(QMouseEvent*); 195 void mouseMoveEvent(QMouseEvent*); 196 void wheelEvent(QWheelEvent*); 197 void keyPressEvent(QKeyEvent*); 198 void keyReleaseEvent(QKeyEvent*); 199 200 private: 201 QVector<list_t*> list; 202 203 mesh_t *mesh; 204 205 Helpers *helpers; 206 Meshutils *meshutils; 207 208 GLuint makeLists(); 209 210 qreal matrix[16]; 211 qreal invmatrix[16]; 212 void getMatrix(); 213 214 QPoint lastPos; 215 216 GLuint generateSurfaceList(int, QColor); 217 GLuint generateSurfaceMeshList(int, QColor); 218 GLuint generateVolumeMeshList(QColor); 219 GLuint generateEdgeList(int, QColor); 220 GLuint generateSharpEdgeList(QColor); 221 222 GLUquadricObj *quadric_axis; 223 void drawCoordinates(); 224 225 double drawTranslate[3]; 226 double drawScale; 227 228 int bgSizeX; 229 int bgSizeY; 230 GLuint bgTexture; 231 void drawBgImage(); 232 233 void changeNormalDirection(double*, double*); 234 }; 235 236 #endif 237