added deselect all button
[engrid.git] / src / guimainwindow.h
blob0638a5ad7047b041c02d7e44ef5b441cced1dd57
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 /** The current operation number. (used for undo/redo) */
192 int current_operation;
194 /** The last operation number. (used for undo/redo) */
195 int last_operation;
197 /** the temporary directory used to save anything temporary */
198 QString m_tmpdir;
200 /** Status bar of the main window and application */
201 QStatusBar *status_bar;
203 /** Label for the information in the status bar */
204 QLabel *status_label;
206 /** A QList with all active boundary codes. */
207 QSet<int> display_boundary_codes;
209 /** A QList with all boundary codes. */
210 QSet<int> all_boundary_codes;
212 /** VTK filter to extract boundary elements with certain codes */
213 vtkEgBoundaryCodesFilter *bcodes_filter;
215 /** VTK CellPicker to pick cells for various user interactions */
216 vtkCellPicker *CellPicker;
218 /** VTK PointPicker to pick points for various user interactions */
219 vtkPointPicker *PointPicker;
221 /** flag to indicate that enGrid is busy with an operation */
222 bool busy;
224 /** log file to collect program output for display in the output window */
225 QString log_file_name;
227 /** number of lines that have been read from the log file */
228 long int N_chars;
230 FILE *system_stdout;
231 static QMutex mutex;
232 QTimer garbage_timer;
233 QTimer log_timer;
234 // GuiOutputWindow *output_window;
235 QDockWidget *dock_widget;
237 /** mapping between numerical and symbolic boundary codes */
238 QMap<int,BoundaryCondition> bcmap;
240 private: // static attributes
243 * Platform independant access to application settings.
244 * For a UNIX system the user preferences will be stored in the file
245 * folder ".config/enGits/enGrid.conf" in the user's home directory;
246 * on Windows preferences will be stored in the registry.
248 static QSettings qset;
251 * The current working directory of enGrid
253 static QString cwd;
255 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
256 static GuiMainWindow *THIS;
258 private: // methods
260 /** Add VTK type information to the grid (useful for visualisation with ParaView). */
261 void addVtkTypeInfo();
263 /** callback for cell picking */
264 static void pickCellCallBack(vtkObject *caller, unsigned long int eid, void *clientdata, void *calldata);
266 /** callback for point picking */
267 static void pickPointCallBack(vtkObject *caller, unsigned long int eid, void *clientdata, void *calldata);
269 public: // methods
272 * The constructor connects the menu and toolbar actions and
273 * the VTK basics(i.e. renderer, actor, ...) will be set up.
274 * Furthermore preferences will be read from qset.
276 GuiMainWindow();
279 * Preferences will be written back.
281 virtual ~GuiMainWindow();
284 * Get the VTK render window
285 * @return the VTK render window
287 vtkRenderWindow* getRenderWindow();
290 * Get the VTK renderer
291 * @return the VTK renderer
293 vtkRenderer* getRenderer();
295 /**
296 * Get the Qt-VTK interactor
297 * @return the Qt-VTK interactor
299 QVTKInteractor* getInteractor();
302 * Get a pointer to the current grid object
303 * @return a pointer to the current vtkUnstructuredGrid object
305 vtkUnstructuredGrid* getGrid() { return grid; };
307 void setBusy() { busy = true; updateStatusBar(); };
308 void setIdle() { busy = false; updateStatusBar(); };
310 public: // static methods
313 * Get the current working directory.
314 * @return the current working directory
316 static QString getCwd();
319 * Set the current working directory
320 * @param cwd the current working directory
322 static void setCwd(QString dir);
325 * Get the currently picked cell.
326 * @return the picked cell ID or -1 if no cell has been picked
328 static vtkIdType getPickedCell();
331 * Get the currently picked point.
332 * @return the picked point ID or -1 if no point has been picked
334 static vtkIdType getPickedPoint();
337 * Access to the QSettings object/
339 static QSettings* settings() { return &qset; };
341 BoundaryCondition getBC(int bc) { return bcmap[bc]; };
343 static GuiMainWindow* pointer() { return THIS; };
344 static void lock() { mutex.lock(); };
345 static void unlock() { mutex.unlock(); };
346 static bool tryLock() { return mutex.tryLock(); };
347 void getAllBoundaryCodes(QSet<int> &bcs);
348 void getDisplayBoundaryCodes(QSet<int> &bcs);
349 vtkPointPicker* getPointPicker(){return(PointPicker);};
350 vtkSphereSource* getPickSphere(){return(pick_sphere);};
351 bool pickPoint(vtkIdType Point);
352 bool pickCell(vtkIdType cellId);
354 QString GetFilename() {return(current_filename);};
356 public slots:
357 void setUseVTKInteractor(int a_UseVTKInteractor);
358 void setPickMode(bool a_UseVTKInteractor,bool a_CellPickerMode);
360 /** Exit the application */
361 void exit();
363 /** Import an STL file (ASCII or binary) */
364 void importSTL();
366 /** Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format */
367 void importGmsh1Ascii();
369 /** Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format */
370 void exportGmsh1Ascii();
372 /** Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format */
373 void importGmsh2Ascii();
375 /** Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format */
376 void exportGmsh2Ascii();
378 /** Export a grid to neutral format for NETGEN */
379 void exportNeutral();
381 /** Update the VTK output */
382 void updateActors();
384 /** Scale to data */
385 void ScaleToData();
387 /** Move the camera in order to show everything on the screen */
388 void zoomAll();
389 void ZoomOnPickedObject();
390 void DeselectAll();
392 void openBC();
393 void saveBC();
394 void openBC(QString a_file);
395 void saveBC(QString a_file);
397 void Undo();
398 void Redo();
400 void ResetOperationCounter();
402 //TODO: Simplify available save/load functions
403 /** Open an existing grid */
404 void open();
406 /** Save the current grid */
407 void save();
409 /** Save the current grid -- using a different file name */
410 void saveAs();
412 /** Save the current grid as a_filename */
413 void QuickSave(QString a_filename);
415 /** Load the current grid from a_filename */
416 void QuickLoad(QString a_filename);
418 /** Save the current grid as a_filename_a_operation */
419 void QuickSave();
421 /** Load a_filename_a_operation */
422 void QuickLoad(int a_operation);
424 /** Update the status bar */
425 void updateStatusBar();
427 /** Select the boundary codes to be displayed/hidden */
428 void selectBoundaryCodes();
430 /** Update the boundary code book keeping (e.g. after reading a mesh). */
431 void updateBoundaryCodes(bool all_on);
433 /** Normal extrusion of boundary elements (no validity check). */
434 void normalExtrusion();
436 /** Toggle the visibility of the axes annotation. */
437 void setAxesVisibility();
439 /** Toggle orthogonal viewing mode. */
440 void setViewingMode();
442 /** Toggle node ID viewing mode. */
443 void ViewNodeIDs();
445 /** Toggle cell ID viewing mode. */
446 void ViewCellIDs();
448 /** Change the orientation of all surface elements */
449 void changeSurfaceOrientation();
451 /** Check and, if required, change the orientation of all surface elements */
452 void checkSurfaceOrientation();
454 /** Eliminate edges in order to improve the aspect ratio of the cells */
455 void improveAspectRatio();
457 /** Write surface elements to an ASCII STL file. */
458 void exportAsciiStl();
460 /** Write surface elements to a binary STL file. */
461 void exportBinaryStl();
463 /** Edit boundary conditions (names and types) */
464 void editBoundaryConditions();
466 /** Edit settings */
467 void configure();
469 /** Display an about message */
470 void about();
472 void viewXP();
473 void viewXM();
474 void viewYP();
475 void viewYM();
476 void viewZP();
477 void viewZM();
479 void appendOutput(QString txt) { ui.textEditOutput->append(txt); };
480 void clearOutput() { ui.textEditOutput->clear(); };
481 void updateOutput();
482 void periodicUpdate();
484 // SLOTS for all standard operations should be defined below;
485 // entries should look like this:
486 // void callOperationName() { EG_STDSLOT(OperationName); };
487 // The actual class name in this case, however, would be GuiOperationName.
489 // the following line can be used as a template:
490 // void call() { EG_STDSLOT(); };
491 // IMPORTANT: Using EG_STDSLOT sets gui to true, while EG_STDINTERSLOT does not (default is gui = false)
492 // This is important to determine whether an operation is a GUI operation or not.
493 // If it's a GUI operation, it locks everything.
495 void callSmoothSurface() { EG_STDINTERSLOT(GuiSmoothSurface); }
496 void callCreateBoundaryLayer() { EG_STDSLOT(GuiCreateBoundaryLayer); }
497 void callDivideBoundaryLayer() { EG_STDSLOT(GuiDivideBoundaryLayer); }
498 void callDeleteVolumeGrid() { EG_STDSLOT(DeleteVolumeGrid); }
499 void callDeleteTetras() { EG_STDSLOT(DeleteTetras); }
500 void callCreateVolumeMesh() { EG_STDSLOT(CreateVolumeMesh); }
501 void callSmoothVolumeGrid() { EG_STDSLOT(SmoothVolumeGrid); }
502 void callSetBoundaryCode() { EG_STDINTERSLOT(GuiSetBoundaryCode); }
503 void callDeleteBadAspectTris() { EG_STDINTERSLOT(GuiDeleteBadAspectTris); }
504 void callDeletePickedCell() { EG_STDSLOT(DeletePickedCell); }
505 void callDeletePickedPoint() { EG_STDINTERSLOT(DeletePickedPoint); }
506 void callPick_cell_point() { EG_STDINTERSLOT(GuiPick); }
507 void callTransform() { EG_STDINTERSLOT(GuiTransform); }
509 void callFixSTL();
511 void callFoamReader() { EG_STDREADERSLOT(FoamReader); }
512 void callFoamWriter() { EG_STDINTERSLOT(FoamWriter); }
513 void callSimpleFoamWriter() { EG_STDINTERSLOT(SimpleFoamWriter); }
514 void callCgnsWriter() { EG_STDINTERSLOT(CgnsWriter); };
515 void callVtkReader() { EG_STDREADERSLOT(VtkReader); }
516 void callPolyDataReader() { EG_STDREADERSLOT(PolyDataReader); }
520 #endif