faster surface smoothing. :)
[engrid.git] / guimainwindow.h
blobc8190d2c6b7f0a00bf3f68d10472917afb8fe291
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #ifndef mainwindow_H
24 #define mainwindow_H
26 class GuiMainWindow;
28 #include <QMainWindow>
29 #include <QSettings>
30 #include <QLabel>
31 #include <QSet>
32 #include <QFileSystemWatcher>
33 #include <QMutex>
34 #include <QTimer>
35 #include <QDockWidget>
37 #include <vtkUnstructuredGrid.h>
38 #include <vtkActor.h>
39 #include <vtkPolyDataMapper.h>
40 #include <vtkGeometryFilter.h>
41 #include <vtkCubeAxesActor2D.h>
42 #include <vtkCellPicker.h>
43 #include <vtkPointPicker.h>
44 #include <vtkSphereSource.h>
45 #include <vtkTextActor.h>
46 #include <vtkVectorText.h>
47 #include <vtkFollower.h>
48 #include <vtkScalarBarActor.h>
49 #include <vtkLookupTable.h>
51 #include "ui_guimainwindow.h"
52 #include "vtkEgBoundaryCodesFilter.h"
53 #include "vtkEgExtractVolumeCells.h"
54 #include "egvtkobject.h"
55 #include "boundarycondition.h"
57 #include "std_includes.h"
58 #include "guitransform.h"
60 // class GuiOutputWindow : public QWidget
61 // {
62 //
63 // friend class GuiMainWindow;
64 //
65 // Q_OBJECT;
66 //
67 // private: // attributes
68 //
69 // Ui::GuiOutputWindow ui;
70 //
71 // public: // methods
72 //
73 // GuiOutputWindow();
74 //
75 // };
80 /**
81 * This is the main GUI class of enGrid.
83 class GuiMainWindow : public QMainWindow, public EgVtkObject
86 Q_OBJECT;
88 private: // attributes
90 /** The user interface definition -- created by QtDesigner. */
91 Ui::GuiMainWindow ui;
93 /** The current state of the grid that is being generated. */
94 vtkUnstructuredGrid *grid;
96 vtkPolyData *boundary_pd;
97 vtkPolyData *tetras_pd;
98 vtkPolyData *wedges_pd;
99 vtkPolyData *pyras_pd;
100 vtkPolyData *hexas_pd;
101 vtkPolyData *volume_pd;
103 /** The VTK renderer object, used for visualising the grid */
104 vtkRenderer *renderer;
106 vtkActor *surface_actor;
107 vtkActor *surface_wire_actor;
108 vtkActor *tetra_actor;
109 vtkActor *wedge_actor;
110 vtkActor *pyramid_actor;
111 vtkActor *hexa_actor;
112 vtkActor *volume_wire_actor;
113 vtkProperty *backface_property;
115 vtkLookupTable *lut;
116 vtkScalarBarActor *iamlegend_actor;
118 vtkPolyDataMapper *field_mapper;
119 vtkPolyDataMapper *surface_mapper;
120 vtkPolyDataMapper *surface_wire_mapper;
121 vtkPolyDataMapper *tetra_mapper;
122 vtkPolyDataMapper *pyramid_mapper;
123 vtkPolyDataMapper *wedge_mapper;
124 vtkPolyDataMapper *hexa_mapper;
125 vtkPolyDataMapper *volume_wire_mapper;
127 vtkEgExtractVolumeCells *extr_vol;
128 vtkEgExtractVolumeCells *extr_tetras;
129 vtkEgExtractVolumeCells *extr_pyramids;
130 vtkEgExtractVolumeCells *extr_wedges;
131 vtkEgExtractVolumeCells *extr_hexas;
133 vtkGeometryFilter *volume_geometry;
134 vtkGeometryFilter *tetra_geometry;
135 vtkGeometryFilter *pyramid_geometry;
136 vtkGeometryFilter *wedge_geometry;
137 vtkGeometryFilter *hexa_geometry;
139 /** VTK filter to extract the surface of the current grid. */
140 vtkGeometryFilter *surface_filter;
142 /** sphere to mark picked cell/points */
143 vtkSphereSource *pick_sphere;
145 /** Size to use for picker objects and annotations */
146 double ReferenceSize;
148 /** 2D Text actor to display node IDs */
149 vector <vtkTextActor*> NodeText;
151 /** 2D Text actor to display cell IDs */
152 vector <vtkTextActor*> CellText;
154 /** 3D Text actor to display node IDs */
155 vector <vtkVectorText*> NodeText_VectorText;
156 vector <vtkPolyDataMapper*> NodeText_PolyDataMapper;
157 vector <vtkFollower*> NodeText_Follower;
159 /** 3D Text actor to display cell IDs */
160 vector <vtkVectorText*> CellText_VectorText;
161 vector <vtkPolyDataMapper*> CellText_PolyDataMapper;
162 vector <vtkFollower*> CellText_Follower;
164 /** Picked point */
165 static vtkIdType PickedPoint;
167 /** Picked cell */
168 static vtkIdType PickedCell;
170 /** Boolean value specifying wether the VTK Interactor should be used or not to determine picked points/cells */
171 static bool m_UseVTKInteractor;
173 /* vtkTextActor* textActor[3];
175 vtkVectorText* atext[3];
176 vtkPolyDataMapper* textMapper[3];
177 vtkFollower* textActor2[3];*/
179 /** VTK mapper to map pick marker */
180 vtkPolyDataMapper *pick_mapper;
182 /** VTK actor to display pick marker */
183 vtkActor *pick_actor;
185 /** VTK actor to display the coordinate system */
186 vtkCubeAxesActor2D *axes;
188 /** The current file name of the grid. */
189 QString current_filename;
191 /** Status bar of the main window and application */
192 QStatusBar *status_bar;
194 /** Label for the information in the status bar */
195 QLabel *status_label;
197 /** A QList with all active boundary codes. */
198 QSet<int> display_boundary_codes;
200 /** A QList with all boundary codes. */
201 QSet<int> all_boundary_codes;
203 /** VTK filter to extract boundary elements with certain codes */
204 vtkEgBoundaryCodesFilter *bcodes_filter;
206 /** VTK CellPicker to pick cells for various user interactions */
207 vtkCellPicker *CellPicker;
209 /** VTK PointPicker to pick points for various user interactions */
210 vtkPointPicker *PointPicker;
212 /** flag to indicate that enGrid is busy with an operation */
213 bool busy;
215 /** log file to collect program output for display in the output window */
216 QString log_file_name;
218 /** number of lines that have been read from the log file */
219 long int N_chars;
221 FILE *system_stdout;
222 static QMutex mutex;
223 QTimer garbage_timer;
224 QTimer log_timer;
225 // GuiOutputWindow *output_window;
226 QDockWidget *dock_widget;
228 /** mapping between numerical and symbolic boundary codes */
229 QMap<int,BoundaryCondition> bcmap;
231 private: // static attributes
234 * Platform independant access to application settings.
235 * For a UNIX system the user preferences will be stored in the file
236 * folder ".config/enGits/enGrid.conf" in the user's home directory;
237 * on Windows preferences will be stored in the registry.
239 static QSettings qset;
242 * The current working directory of enGrid
244 static QString cwd;
246 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
247 static GuiMainWindow *THIS;
249 private: // methods
251 /** Add VTK type information to the grid (useful for visualisation with ParaView). */
252 void addVtkTypeInfo();
254 /** callback for cell picking */
255 static void pickCellCallBack(vtkObject *caller, unsigned long int eid, void *clientdata, void *calldata);
257 /** callback for point picking */
258 static void pickPointCallBack(vtkObject *caller, unsigned long int eid, void *clientdata, void *calldata);
260 public: // methods
263 * The constructor connects the menu and toolbar actions and
264 * the VTK basics(i.e. renderer, actor, ...) will be set up.
265 * Furthermore preferences will be read from qset.
267 GuiMainWindow();
270 * Preferences will be written back.
272 virtual ~GuiMainWindow();
275 * Get the VTK render window
276 * @return the VTK render window
278 vtkRenderWindow* getRenderWindow();
281 * Get the VTK renderer
282 * @return the VTK renderer
284 vtkRenderer* getRenderer();
286 /**
287 * Get the Qt-VTK interactor
288 * @return the Qt-VTK interactor
290 QVTKInteractor* getInteractor();
293 * Get a pointer to the current grid object
294 * @return a pointer to the current vtkUnstructuredGrid object
296 vtkUnstructuredGrid* getGrid() { return grid; };
298 void setBusy() { busy = true; updateStatusBar(); };
299 void setIdle() { busy = false; updateStatusBar(); };
301 public: // static methods
304 * Get the current working directory.
305 * @return the current working directory
307 static QString getCwd();
310 * Set the current working directory
311 * @param cwd the current working directory
313 static void setCwd(QString dir);
316 * Get the currently picked cell.
317 * @return the picked cell ID or -1 if no cell has been picked
319 static vtkIdType getPickedCell();
322 * Get the currently picked point.
323 * @return the picked point ID or -1 if no point has been picked
325 static vtkIdType getPickedPoint();
328 * Access to the QSettings object/
330 static QSettings* settings() { return &qset; };
332 BoundaryCondition getBC(int bc) { return bcmap[bc]; };
334 static GuiMainWindow* pointer() { return THIS; };
335 static void lock() { mutex.lock(); };
336 static void unlock() { mutex.unlock(); };
337 static bool tryLock() { return mutex.tryLock(); };
338 void getAllBoundaryCodes(QSet<int> &bcs);
339 vtkPointPicker* getPointPicker(){return(PointPicker);};
340 vtkSphereSource* getPickSphere(){return(pick_sphere);};
341 bool pickPoint(vtkIdType Point);
342 bool pickCell(vtkIdType cellId);
344 QString GetFilename() {return(current_filename);};
346 public slots:
347 void setUseVTKInteractor(int a_UseVTKInteractor);
348 void setPickMode(bool a_UseVTKInteractor,bool a_CellPickerMode);
350 /** Exit the application */
351 void exit();
353 /** Import an STL file (ASCII or binary) */
354 void importSTL();
356 /** Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format */
357 void importGmsh1Ascii();
359 /** Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format */
360 void exportGmsh1Ascii();
362 /** Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format */
363 void importGmsh2Ascii();
365 /** Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format */
366 void exportGmsh2Ascii();
368 /** Export a grid to neutral format for NETGEN */
369 void exportNeutral();
371 /** Update the VTK output */
372 void updateActors();
374 /** Scale to data */
375 void ScaleToData();
377 /** Move the camera in order to show everything on the screen */
378 void zoomAll();
380 /** Open an existing grid */
381 void open();
383 void openBC();
384 void saveBC();
386 void undo();
387 void redo();
389 /** Save the current grid */
390 void save();
392 /** Save the current grid -- using a different file name */
393 void saveAs();
395 /** Save the current grid as a_filename */
396 void QuickSave(QString a_filename);
398 /** Update the status bar */
399 void updateStatusBar();
401 /** Select the boundary codes to be diplayed/hidden */
402 void selectBoundaryCodes();
404 /** Update the boundary code book keeping (e.g. after reading a mesh). */
405 void updateBoundaryCodes(bool all_on);
407 /** Normal extrusion of boundary elements (no validity check). */
408 void normalExtrusion();
410 /** Toggle the visibility of the axes annotation. */
411 void setAxesVisibility();
413 /** Toggle orthogonal viewing mode. */
414 void setViewingMode();
416 /** Toggle node ID viewing mode. */
417 void ViewNodeIDs();
419 /** Toggle cell ID viewing mode. */
420 void ViewCellIDs();
422 /** Change the orientation of all surface elements */
423 void changeSurfaceOrientation();
425 /** Check and, if required, change the orientation of all surface elements */
426 void checkSurfaceOrientation();
428 /** Eliminate edges in order to improve the aspect ratio of the cells */
429 void improveAspectRatio();
431 /** Write surface elements to an ASCII STL file. */
432 void exportAsciiStl();
434 /** Write surface elements to a binary STL file. */
435 void exportBinaryStl();
437 /** Edit boundary conditions (names and types) */
438 void editBoundaryConditions();
440 /** Edit settings */
441 void configure();
443 /** Display an about message */
444 void about();
446 void viewXP();
447 void viewXM();
448 void viewYP();
449 void viewYM();
450 void viewZP();
451 void viewZM();
453 void appendOutput(QString txt) { ui.textEditOutput->append(txt); };
454 void clearOutput() { ui.textEditOutput->clear(); };
455 void updateOutput();
456 void periodicUpdate();
458 // SLOTS for all standard operations should be defined below;
459 // entries should look like this:
460 // void callOperationName() { EG_STDSLOT(OperationName); };
461 // The actual class name in this case, however, would be GuiOperationName.
463 // the following line can be used as a template:
464 // void call() { EG_STDSLOT(); };
466 void callSmoothSurface() { EG_STDINTERSLOT(GuiSmoothSurface); };
467 void callCreateBoundaryLayer() { EG_STDSLOT(GuiCreateBoundaryLayer); };
468 void callDivideBoundaryLayer() { EG_STDSLOT(GuiDivideBoundaryLayer); };
469 void callDeleteVolumeGrid() { EG_STDSLOT(DeleteVolumeGrid); };
470 void callDeleteTetras() { EG_STDSLOT(DeleteTetras); };
471 void callCreateVolumeMesh() { EG_STDSLOT(CreateVolumeMesh); };
472 void callSmoothVolumeGrid() { EG_STDSLOT(SmoothVolumeGrid); };
473 void callSetBoundaryCode() { EG_STDINTERSLOT(GuiSetBoundaryCode); };
474 void callDeleteBadAspectTris() { EG_STDINTERSLOT(GuiDeleteBadAspectTris); };
475 void callDeletePickedCell() { EG_STDSLOT(DeletePickedCell); };
476 void callDeletePickedPoint() { EG_STDINTERSLOT(DeletePickedPoint); };
477 void callPick_cell_point() { EG_STDINTERSLOT(GuiPick); };
478 void callTransform() { EG_STDINTERSLOT(GuiTransform); };
480 void callFixSTL();
482 void callFoamReader() { EG_STDREADERSLOT(FoamReader); };
483 void callFoamWriter() { EG_STDINTERSLOT(FoamWriter); };
484 void callSimpleFoamWriter() { EG_STDINTERSLOT(SimpleFoamWriter); };
485 void callVtkReader() { EG_STDREADERSLOT(VtkReader); };
486 void callPolyDataReader() { EG_STDREADERSLOT(PolyDataReader); };
490 #endif