added possibility to merge volumes
[engrid.git] / src / guimainwindow.h
blob25081da707bde5a8d5b562e4eba9cb139c7396ac
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>
36 #include <QDomDocument>
38 #include <vtkUnstructuredGrid.h>
39 #include <vtkActor.h>
40 #include <vtkPolyDataMapper.h>
41 #include <vtkGeometryFilter.h>
42 #include <vtkCubeAxesActor2D.h>
43 #include <vtkCellPicker.h>
44 #include <vtkPointPicker.h>
45 #include <vtkSphereSource.h>
46 #include <vtkTextActor.h>
47 #include <vtkVectorText.h>
48 #include <vtkFollower.h>
49 #include <vtkScalarBarActor.h>
50 #include <vtkLookupTable.h>
52 #include "ui_guimainwindow.h"
53 #include "vtkEgBoundaryCodesFilter.h"
54 #include "vtkEgExtractVolumeCells.h"
55 #include "egvtkobject.h"
56 #include "boundarycondition.h"
57 #include "volumedefinition.h"
58 #include "physicalboundarycondition.h"
59 #include "checksurfaceintegrity.h"
60 #include "surfaceprojection.h"
61 #include "openfoamcase.h"
62 #include "guitransform.h"
63 #include "openfoamtools.h"
64 #include "std_includes.h"
65 #include "fixcadgeometry.h"
66 #include "projection_test.h"
67 #include "xmlhandler.h"
69 /**
70 * This is the main GUI class of enGrid.
72 class GuiMainWindow : public QMainWindow, public EgVtkObject
75 Q_OBJECT;
77 private: // attributes
79 XmlHandler* m_XmlHandler;
81 Ui::GuiMainWindow ui; ///< The user interface definition -- created by QtDesigner.
82 vtkUnstructuredGrid *m_Grid; ///< The current state of the grid that is being generated.
84 vtkRenderer *m_Renderer; ///< The VTK renderer object, used for visualising the grid
86 vtkActor* m_SurfaceActor;
87 vtkActor* m_SurfaceWireActor;
88 vtkActor* m_TetraActor;
89 vtkActor* m_WedgeActor;
90 vtkActor* m_PyramidActor;
91 vtkActor* m_HexaActor;
92 vtkActor* m_VolumeWireActor;
94 vtkProperty* m_BackfaceProperty;
95 vtkLookupTable* m_LookupTable;
96 vtkScalarBarActor* m_LegendActor;
98 vtkPolyDataMapper* m_SurfaceMapper;
99 vtkPolyDataMapper* m_SurfaceWireMapper;
100 vtkPolyDataMapper* m_TetraMapper;
101 vtkPolyDataMapper* m_PyramidMapper;
102 vtkPolyDataMapper* m_WedgeMapper;
103 vtkPolyDataMapper* m_HexaMapper;
104 vtkPolyDataMapper* m_VolumeWireMapper;
106 vtkEgExtractVolumeCells *m_ExtrVol;
107 vtkEgExtractVolumeCells *m_ExtrTetras;
108 vtkEgExtractVolumeCells *m_ExtrPyramids;
109 vtkEgExtractVolumeCells *m_ExtrWedges;
110 vtkEgExtractVolumeCells *m_ExtrHexes;
112 vtkGeometryFilter *m_VolumeGeometry;
113 vtkGeometryFilter *m_TetraGeometry;
114 vtkGeometryFilter *m_PyramidGeometry;
115 vtkGeometryFilter *m_WedgeGeometry;
116 vtkGeometryFilter *m_HexaGeometry;
118 vtkIdType m_PickedPoint; ///< Picked point
119 vtkIdType m_PickedCell; ///< Picked cell
120 bool m_UseVTKInteractor; ///< Boolean value specifying whether the VTK Interactor should be used or not
122 static QMutex m_Mutex;
124 vtkGeometryFilter* m_SurfaceFilter; ///< VTK filter to extract the surface of the current grid.
125 double m_ReferenceSize; ///< Size to use for picker objects and annotations
127 vector <vtkTextActor*> m_NodeText; ///< 2D Text actor to display node IDs
128 vector <vtkTextActor*> m_CellText; ///< 2D Text actor to display cell IDs
129 vector <vtkVectorText*> m_NodeTextVectorText; ///< 3D Text actor to display node IDs
130 vector <vtkPolyDataMapper*> m_NodeTextPolyDataMapper;
131 vector <vtkFollower*> m_NodeTextFollower;
132 vector <vtkVectorText*> m_CellTextVectorText; ///< 3D Text actor to display cell IDs
133 vector <vtkPolyDataMapper*> m_CellTextPolyDataMapper;
134 vector <vtkFollower*> m_CellTextFollower;
136 vtkPolyDataMapper* m_PickMapper; ///< VTK mapper to map pick marker
137 vtkActor* m_PickActor; ///< VTK actor to display pick marker
138 vtkSphereSource* m_PickSphere; ///< sphere to mark picked cell/points
139 vtkCubeAxesActor2D* m_Axes; ///< VTK actor to display the coordinate system
140 vtkEgBoundaryCodesFilter* m_BCodesFilter; ///< VTK filter to extract boundary elements with certain codes
141 vtkCellPicker* m_CellPicker; ///< VTK CellPicker to pick cells for various user interactions
142 vtkPointPicker* m_PointPicker; ///< VTK PointPicker to pick points for various user interactions
143 int m_PickedObject; ///< 0=none, 1=node, 2=cell
145 QString m_CurrentFilename; ///< The current file name of the grid.
146 int m_CurrentOperation; ///< The current operation number. (used for undo/redo)
147 bool m_undo_redo_enabled; ///< if true, undo/redo operations will be usable.
148 int m_LastOperation; ///< The last operation number. (used for undo/redo)
149 QString m_LogDir; ///< the log directory
150 QLabel* m_StatusLabel; ///< Label for the information in the status bar
151 QSet<int> m_DisplayBoundaryCodes; ///< A QList with all active boundary codes.
152 QSet<int> m_AllBoundaryCodes; ///< A QList with all boundary codes.
153 bool m_Busy; ///< flag to indicate that enGrid is busy with an operation
154 QString m_LogFileName; ///< log file to collect program output for display in the output window
155 long int m_N_chars; ///< number of lines that have been read from the log file
156 FILE* m_SystemStdout;
157 QTimer m_GarbageTimer;
158 QTimer m_LogTimer;
160 QMap<int, BoundaryCondition> m_bcmap; ///< mapping between numerical and symbolic boundary codes
161 QMap<QString, VolumeDefinition> m_VolMap; ///< all volume definitions
162 QMap<QString, PhysicalBoundaryCondition> m_PhysicalBoundaryConditionsMap; ///< all physical boundary conditions definitions
164 QMap<int, SurfaceProjection*> m_SurfProj; ///< all surface projectors for surface meshing
166 int m_SolverIndex;// deprecated
167 OpenFOAMTools m_OpenFoamTools;
169 // recent file list support
170 private:
171 QMap<QString,QDateTime> m_RecentFiles;
172 QMenu* recentFileMenu() { return ui.menuOpen_recent; }
173 void readRecentFiles();
174 void writeRecentFiles();
175 void addRecentFile(QString file_name, QDateTime date);
176 private slots:
177 void openRecent(QAction *action);
179 public:
180 void resetXmlDoc();
182 private: // static attributes
185 * Platform independant access to application settings.
186 * For a UNIX system the user preferences will be stored in the file
187 * folder ".config/enGits/enGrid.conf" in the user's home directory;
188 * on Windows preferences will be stored in the registry.
190 static QSettings m_qset;
193 * The current working directory of enGrid
195 static QString m_cwd;
198 * Is the current case unsaved?
200 static bool m_UnSaved;
202 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
203 static GuiMainWindow* THIS;
205 private: // methods
207 void setupVtk();
208 static void pickCallBack( vtkObject *caller, unsigned long int eid, void *clientdata, void *calldata );
209 void updateSurfaceActors( bool forced );
210 void updateVolumeActors( bool forced );
212 private slots:
214 void setClipX( const QString &txt );
215 void setClipY( const QString &txt );
216 void setClipZ( const QString &txt );
217 void setClipNX( const QString &txt );
218 void setClipNY( const QString &txt );
219 void setClipNZ( const QString &txt );
221 void openBC();
222 void saveBC();
224 void openPhysicalBoundaryConditions();
225 void savePhysicalBoundaryConditions();
227 void openGrid( QString file_name );
229 public: // methods
230 GuiMainWindow();///< Default constructor.
231 GuiMainWindow(QString file_name);///< Constructor which opens a file directly.
233 private:
235 * This function connects the menu and toolbar actions and
236 * the VTK basics(i.e. renderer, actor, ...) will be set up.
237 * Furthermore preferences will be read from qset.
239 void setupGuiMainWindow();
240 bool m_open_last;
242 public:
244 * Preferences will be written back.
246 virtual ~GuiMainWindow();
249 * Get the VTK render window
250 * @return the VTK render window
252 vtkRenderWindow* getRenderWindow();
255 * Get the VTK renderer
256 * @return the VTK renderer
258 vtkRenderer* getRenderer();
261 * Get the Qt-VTK interactor
262 * @return the Qt-VTK interactor
264 QVTKInteractor* getInteractor();
267 * Get a pointer to the current grid object
268 * @return a pointer to the current vtkUnstructuredGrid object
270 vtkUnstructuredGrid* getGrid() { return m_Grid; }
272 void setBusy() { m_Busy = true; updateStatusBar(); }
273 void setIdle() { m_Busy = false; updateStatusBar(); }
275 /// Returns log directory
276 QString getLogDir() { return m_LogDir; }
278 /// Returns the path to the currently loaded file
279 QString getFilePath();
281 /// Returns the index of the solver to use. The index corresponds to the position in solvers.txt .
282 void setSolverIndex(int x) {m_SolverIndex = x;}
283 int getSolverIndex() {return m_SolverIndex;}
285 public: // static methods
288 * Get the current working directory.
289 * @return the current working directory
291 static QString getCwd();
294 * Set the current working directory
295 * @param dir the current working directory
297 static void setCwd( QString dir );
300 * Set m_UnSaved.
301 * @param unsaved Do you want to be asked where to save when clicking on save next time?
303 static void setUnsaved( bool unsaved );
306 * Get the currently picked cell.
307 * @return the picked cell ID or -1 if no cell has been picked
309 vtkIdType getPickedCell();
312 * Get the currently picked point.
313 * @return the picked point ID or -1 if no point has been picked
315 vtkIdType getPickedPoint();
317 vtkIdType getPickedObject() { return m_PickedObject; }
320 * Access to the QSettings object
322 static QSettings* settings() { return &m_qset; }
324 BoundaryCondition getBC( int bc ) { return m_bcmap[bc]; }
325 VolumeDefinition getVol( QString volname ) { return m_VolMap[volname]; }
326 void clearBCs() { m_bcmap.clear(); }
327 void addBC(int bc, BoundaryCondition BC) { m_bcmap[bc] = BC; }
329 QList<VolumeDefinition> getAllVols();
330 void setAllVols( QList<VolumeDefinition> vols );
331 void createDefaultVol();
333 QList<PhysicalBoundaryCondition> getAllPhysicalBoundaryConditions();
334 void setAllPhysicalBoundaryConditions (QList<PhysicalBoundaryCondition> physical_boundary_conditions);
335 void setAllPhysicalBoundaryConditions (QMap<QString, PhysicalBoundaryCondition> physical_boundary_conditions);
336 bool physicalTypeDefined(QString name) { return m_PhysicalBoundaryConditionsMap.contains(name); };
337 PhysicalBoundaryCondition getPhysicalBoundaryCondition(QString name) { return m_PhysicalBoundaryConditionsMap[name]; }
339 static GuiMainWindow* pointer() { return THIS; }
340 static void lock() { m_Mutex.lock(); }
341 static void unlock() { m_Mutex.unlock(); }
342 static bool tryLock() { return m_Mutex.tryLock(); }
343 void getAllBoundaryCodes( QSet<int> &bcs );
344 QSet<int> getAllBoundaryCodes();
345 void getDisplayBoundaryCodes( QSet<int> &bcs );
346 vtkPointPicker* getPointPicker() { return ( m_PointPicker );}
347 vtkSphereSource* getPickSphere() { return ( m_PickSphere );}
348 bool pickPoint( vtkIdType id_point );
349 bool pickCell( vtkIdType id_cell );
351 QString getFilename() { return( m_CurrentFilename ); }
352 void setFilename(QString filename) { m_CurrentFilename = filename; }
354 SurfaceProjection* getSurfProj(int bc);
355 bool checkSurfProj();
357 public slots:
359 void setUseVTKInteractor( int a_UseVTKInteractor );
360 void setPickMode( bool a_UseVTKInteractor, bool a_CellPickerMode );
362 void exit(); ///< Exit the application
363 void importSTL(); ///< Import an STL file (ASCII or binary)
364 void importGmsh1Ascii(); ///< Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format
365 void exportGmsh1Ascii(); ///< Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format
366 void importGmsh2Ascii(); ///< Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format
367 void exportGmsh2Ascii(); ///< Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format
368 void exportNeutral(); ///< Export a grid to neutral format for NETGEN
369 void updateActors( bool force = false ); ///< Update the VTK output
370 void forceUpdateActors(); ///< Force an update of the VTK output
371 void scaleToData(); ///< Scale to data
372 void zoomAll(); ///< Move the camera in order to show everything on the screen
373 void zoomOnPickedObject();
374 void deselectAll();
375 void printGrid() {cout << "PrintGrid() called!" << endl; cout_grid( cout, m_Grid, true, true, true, true );}
376 void info();
378 void undo();
379 void redo();
381 void resetOperationCounter();
383 void open(); ///< Open an existing case
384 void open( QString file_name, bool update_current_filename = true ); ///< Open case file_name
385 void save(); ///< Save the current case
386 void saveAs(); ///< Save the current case -- using a different file name
387 QString saveAs( QString file_name, bool update_current_filename = true ); ///< Save the current case as file_name. Returns name under which file was saved (with missing .egc extension for example).
389 int quickSave(); ///< Save the current grid as a_filename_a_operation
390 void quickLoad( int a_operation ); ///< Load a_filename_a_operation
391 void updateStatusBar(); ///< Update the status bar
392 void selectBoundaryCodes(); ///< Select the boundary codes to be displayed/hidden
393 void updateBoundaryCodes( bool all_on ); ///< Update the boundary code book keeping (e.g. after reading a mesh).
394 void normalExtrusion(); ///< Normal extrusion of boundary elements (no validity check).
395 void setAxesVisibility(); ///< Toggle the visibility of the axes annotation.
396 void setViewingMode(); ///< Toggle orthogonal viewing mode.
397 void viewNodeIDs(); ///< Toggle node ID viewing mode.
398 void viewCellIDs(); ///< Toggle cell ID viewing mode.
399 void changeSurfaceOrientation(); ///< Change the orientation of all surface elements
400 void checkSurfaceOrientation(); ///< Check and, if required, change the orientation of all surface elements
401 void improveAspectRatio(); ///< Eliminate edges in order to improve the aspect ratio of the cells
402 void exportAsciiStl(); ///< Write surface elements to an ASCII STL file.
403 void exportBinaryStl(); ///< Write surface elements to a binary STL file.
404 void exportAsciiPly(); ///< Write surface elements to an ASCII PLY file.
405 void exportBinaryPly(); ///< Write surface elements to a binary PLY file.
406 void editBoundaryConditions(); ///< Edit boundary conditions (names and types)
407 void configure(); ///< Edit settings
408 void about(); ///< Display an about message
409 void markOutputLine(); ///< Mark the current position in the output window
411 QString getXmlSection( QString name ); ///< Get a section from the XML case description
412 void setXmlSection( QString name, QString contents ); ///< Set a section of the XML case description
414 void viewXP();
415 void viewXM();
416 void viewYP();
417 void viewYM();
418 void viewZP();
419 void viewZM();
421 void appendOutput( QString txt ) { ui.textEditOutput->append( txt ); }
422 void clearOutput() { ui.textEditOutput->clear(); }
423 void updateOutput();
424 void periodicUpdate();
426 void storeSurfaceProjection();
428 // SLOTS for all standard operations should be defined below;
429 // entries should look like this:
430 // void callOperationName() { EG_STDSLOT(OperationName); };
431 // The actual class name in this case, however, would be GuiOperationName.
433 // the following line can be used as a template:
434 // void call() { EG_STDSLOT(); };
435 // IMPORTANT: Using EG_STDSLOT sets lock_gui to true, while EG_STDINTERSLOT does not (default is lock_gui = false)
436 // This is important to determine whether an operation should try to lock the main mutex or not.
437 // If lock_gui is true, the operation will try to lock the main mutex. If it fails (mutex locked by other operation), the operation is stopped.
438 // SUMMARY:
439 // EG_STDSLOT = background operation (There can not be more than one background operation!)
440 // EG_STDINTERSLOT = foreground operation
441 // Note: In practice, EG_STDINTERSLOT locks everything, while EG_STDSLOT prevents other operations, but doesn't lock the text output or prevent minimizing the window.
443 void callCreateSurfaceMesh() { EG_STDSLOT( GuiCreateSurfaceMesh ); }
444 void callCreateBoundaryLayer() { EG_STDSLOT( GuiCreateBoundaryLayer ); }
445 void callDivideBoundaryLayer() { EG_STDSLOT( GuiDivideBoundaryLayer ); }
446 void callDeleteVolumeGrid() { EG_STDSLOT( DeleteVolumeGrid ); }
447 void callDeleteTetras() { EG_STDSLOT( DeleteTetras ); }
448 void callCreateVolumeMesh() { EG_STDSLOT( GuiCreateVolumeMesh ); }
449 void callSmoothVolumeGrid() { EG_STDSLOT( SmoothVolumeGrid ); }
450 void callSetBoundaryCode() { EG_STDINTERSLOT( GuiSetBoundaryCode ); }
451 void callDeleteBadAspectTris() { EG_STDINTERSLOT( GuiDeleteBadAspectTris ); }
452 void callDeletePickedCell() { EG_STDSLOT( DeletePickedCell ); }
453 void callMergeNodes();
454 void callInsertNewCell();
455 void callDeletePickedPoint();
456 void callBoxSelect() { EG_STDINTERSLOT( BoxSelect ); }
457 void callCheckSurfaceIntegrity() { EG_STDINTERSLOT( CheckSurfaceIntegrity ); }
458 void callPick_cell_point() { EG_STDINTERSLOT( GuiPick ); }
459 void callTransform() { EG_STDINTERSLOT( GuiTransform ); }
460 void callUpdateSurfProj() { EG_STDSLOT( UpdateSurfProj ); }
461 void callImportOpenFoamCase() { EG_STDREADERSLOT(FoamReader); }
462 void callMergeVolumes() { EG_STDSLOT(GuiMergeVolumes); }
464 void callFixSTL();
466 void callFoamWriter() { EG_STDINTERSLOT( FoamWriter ); }
467 void callSimpleFoamWriter() { EG_STDINTERSLOT( SimpleFoamWriter ); }
468 void callFoamCaseWriter() { EG_STDINTERSLOT( OpenFOAMcase ); }
469 void callCgnsWriter() { EG_STDINTERSLOT( CgnsWriter ); }
470 void callVtkReader() { EG_STDREADERSLOT( VtkReader ); }
471 void callBlenderReader() { EG_STDREADERSLOT( BlenderReader ); }
472 void callBlenderWriter() { EG_STDREADERSLOT( BlenderWriter ); }
473 void callPolyDataReader() { EG_STDREADERSLOT( PolyDataReader ); }
474 void callReducedPolyDataReader() { EG_STDREADERSLOT( ReducedPolyDataReader ); }
475 void callSeligAirfoilReader() { EG_STDREADERSLOT( SeligAirfoilReader ); }
476 void callSurfaceMesher() { EG_STDSLOT(SurfaceMesher); }
477 void callReduceSurfaceTriangulation() { EG_STDSLOT(ReduceSurfaceTriangulation); }
478 void callEliminateSmallBranches() { EG_STDSLOT(EliminateSmallBranches); }
479 void callSmoothAndSwapSurface() { EG_STDSLOT(SmoothAndSwapSurface); }
481 void callFixCADGeometry() { EG_STDSLOT(FixCadGeometry); }
482 void callProjection_test() { EG_STDSLOT(Projection_test); }
486 #endif