replaced abort() with EG_BUG
[engrid.git] / src / guimainwindow.h
blob3207c702d2a50353c0abd58e00b8ef5a86d452cd
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"
66 /**
67 * This is the main GUI class of enGrid.
69 class GuiMainWindow : public QMainWindow, public EgVtkObject
72 Q_OBJECT;
74 private: // attributes
76 QDomDocument m_XmlDoc; ///< XML document describing the complete case
78 Ui::GuiMainWindow ui; ///< The user interface definition -- created by QtDesigner.
79 vtkUnstructuredGrid *grid; ///< The current state of the grid that is being generated.
81 vtkRenderer *m_Renderer; ///< The VTK renderer object, used for visualising the grid
83 vtkActor* m_SurfaceActor;
84 vtkActor* m_SurfaceWireActor;
85 vtkActor* m_TetraActor;
86 vtkActor* m_WedgeActor;
87 vtkActor* m_PyramidActor;
88 vtkActor* m_HexaActor;
89 vtkActor* m_VolumeWireActor;
91 vtkProperty* m_BackfaceProperty;
92 vtkLookupTable* m_LookupTable;
93 vtkScalarBarActor* m_LegendActor;
95 vtkPolyDataMapper* m_SurfaceMapper;
96 vtkPolyDataMapper* m_SurfaceWireMapper;
97 vtkPolyDataMapper* m_TetraMapper;
98 vtkPolyDataMapper* m_PyramidMapper;
99 vtkPolyDataMapper* m_WedgeMapper;
100 vtkPolyDataMapper* m_HexaMapper;
101 vtkPolyDataMapper* m_VolumeWireMapper;
103 vtkEgExtractVolumeCells *m_ExtrVol;
104 vtkEgExtractVolumeCells *m_ExtrTetras;
105 vtkEgExtractVolumeCells *m_ExtrPyramids;
106 vtkEgExtractVolumeCells *m_ExtrWedges;
107 vtkEgExtractVolumeCells *m_ExtrHexes;
109 vtkGeometryFilter *m_VolumeGeometry;
110 vtkGeometryFilter *m_TetraGeometry;
111 vtkGeometryFilter *m_PyramidGeometry;
112 vtkGeometryFilter *m_WedgeGeometry;
113 vtkGeometryFilter *m_HexaGeometry;
115 vtkIdType m_PickedPoint; ///< Picked point
116 vtkIdType m_PickedCell; ///< Picked cell
117 bool m_UseVTKInteractor; ///< Boolean value specifying whether the VTK Interactor should be used or not
119 static QMutex m_Mutex;
121 vtkGeometryFilter* m_SurfaceFilter; ///< VTK filter to extract the surface of the current grid.
122 double m_ReferenceSize; ///< Size to use for picker objects and annotations
124 vector <vtkTextActor*> m_NodeText; ///< 2D Text actor to display node IDs
125 vector <vtkTextActor*> m_CellText; ///< 2D Text actor to display cell IDs
126 vector <vtkVectorText*> m_NodeTextVectorText; ///< 3D Text actor to display node IDs
127 vector <vtkPolyDataMapper*> m_NodeTextPolyDataMapper;
128 vector <vtkFollower*> m_NodeTextFollower;
129 vector <vtkVectorText*> m_CellTextVectorText; ///< 3D Text actor to display cell IDs
130 vector <vtkPolyDataMapper*> m_CellTextPolyDataMapper;
131 vector <vtkFollower*> m_CellTextFollower;
133 vtkPolyDataMapper* m_PickMapper; ///< VTK mapper to map pick marker
134 vtkActor* m_PickActor; ///< VTK actor to display pick marker
135 vtkSphereSource* m_PickSphere; ///< sphere to mark picked cell/points
136 vtkCubeAxesActor2D* m_Axes; ///< VTK actor to display the coordinate system
137 vtkEgBoundaryCodesFilter* m_BCodesFilter; ///< VTK filter to extract boundary elements with certain codes
138 vtkCellPicker* m_CellPicker; ///< VTK CellPicker to pick cells for various user interactions
139 vtkPointPicker* m_PointPicker; ///< VTK PointPicker to pick points for various user interactions
141 QString m_CurrentFilename; ///< The current file name of the grid.
142 int m_CurrentOperation; ///< The current operation number. (used for undo/redo)
143 int m_LastOperation; ///< The last operation number. (used for undo/redo)
144 QString m_LogDir; ///< the log directory
145 QLabel* m_StatusLabel; ///< Label for the information in the status bar
146 QSet<int> m_DisplayBoundaryCodes; ///< A QList with all active boundary codes.
147 QSet<int> m_AllBoundaryCodes; ///< A QList with all boundary codes.
148 bool m_Busy; ///< flag to indicate that enGrid is busy with an operation
149 QString m_LogFileName; ///< log file to collect program output for display in the output window
150 long int m_N_chars; ///< number of lines that have been read from the log file
151 FILE* m_SystemStdout;
152 QTimer m_GarbageTimer;
153 QTimer m_LogTimer;
155 QMap<int, BoundaryCondition> m_bcmap; ///< mapping between numerical and symbolic boundary codes
156 QMap<QString, VolumeDefinition> m_VolMap; ///< all volume definitions
157 QMap<QString, PhysicalBoundaryCondition> m_PhysicalBoundaryConditionsMap; ///< all physical boundary conditions definitions
159 QMap<int, SurfaceProjection*> m_SurfProj; ///< all surface projectors for surface meshing
161 int m_SolverIndex;// deprecated
162 OpenFOAMTools m_OpenFoamTools;
164 private: // static attributes
167 * Platform independant access to application settings.
168 * For a UNIX system the user preferences will be stored in the file
169 * folder ".config/enGits/enGrid.conf" in the user's home directory;
170 * on Windows preferences will be stored in the registry.
172 static QSettings m_qset;
175 * The current working directory of enGrid
177 static QString m_cwd;
180 * Is the current case unsaved?
182 static bool m_UnSaved;
184 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
185 static GuiMainWindow* THIS;
187 private: // methods
189 void setupVtk();
190 void addVtkTypeInfo(); ///< Add VTK type information to the grid (useful for visualisation with ParaView).
191 static void pickCallBack( vtkObject *caller, unsigned long int eid, void *clientdata, void *calldata );
192 void updateSurfaceActors( bool forced );
193 void updateVolumeActors( bool forced );
195 private slots:
197 void setClipX( const QString &txt );
198 void setClipY( const QString &txt );
199 void setClipZ( const QString &txt );
200 void setClipNX( const QString &txt );
201 void setClipNY( const QString &txt );
202 void setClipNZ( const QString &txt );
204 void openBC();
205 void saveBC();
207 void openPhysicalBoundaryConditions();
208 void savePhysicalBoundaryConditions();
210 void openGrid( QString file_name );
211 void saveGrid( QString file_name );
215 public: // methods
218 * The constructor connects the menu and toolbar actions and
219 * the VTK basics(i.e. renderer, actor, ...) will be set up.
220 * Furthermore preferences will be read from qset.
222 GuiMainWindow();
225 * Preferences will be written back.
227 virtual ~GuiMainWindow();
230 * Get the VTK render window
231 * @return the VTK render window
233 vtkRenderWindow* getRenderWindow();
236 * Get the VTK renderer
237 * @return the VTK renderer
239 vtkRenderer* getRenderer();
242 * Get the Qt-VTK interactor
243 * @return the Qt-VTK interactor
245 QVTKInteractor* getInteractor();
248 * Get a pointer to the current grid object
249 * @return a pointer to the current vtkUnstructuredGrid object
251 vtkUnstructuredGrid* getGrid() { return grid; }
253 void setBusy() { m_Busy = true; updateStatusBar(); }
254 void setIdle() { m_Busy = false; updateStatusBar(); }
256 /// Returns log directory
257 QString getLogDir() { return m_LogDir; }
259 /// Returns the path to the currently loaded file
260 QString getFilePath();
262 /// Returns the index of the solver to use. The index corresponds to the position in solvers.txt .
263 void setSolverIndex(int x) {m_SolverIndex = x;}
264 int getSolverIndex() {return m_SolverIndex;}
266 public: // static methods
269 * Get the current working directory.
270 * @return the current working directory
272 static QString getCwd();
275 * Set the current working directory
276 * @param dir the current working directory
278 static void setCwd( QString dir );
281 * Set m_UnSaved.
282 * @param unsaved Do you want to be asked where to save when clicking on save next time?
284 static void setUnsaved( bool unsaved );
287 * Get the currently picked cell.
288 * @return the picked cell ID or -1 if no cell has been picked
290 vtkIdType getPickedCell();
293 * Get the currently picked point.
294 * @return the picked point ID or -1 if no point has been picked
296 vtkIdType getPickedPoint();
299 * Access to the QSettings object
301 static QSettings* settings() { return &m_qset; }
303 BoundaryCondition getBC( int bc ) { return m_bcmap[bc]; }
304 VolumeDefinition getVol( QString volname ) { return m_VolMap[volname]; }
305 void clearBCs() { m_bcmap.clear(); }
306 void addBC(int bc, BoundaryCondition BC) { m_bcmap[bc] = BC; }
308 QList<VolumeDefinition> getAllVols();
309 void setAllVols( QList<VolumeDefinition> vols );
310 void createDefaultVol();
312 QList<PhysicalBoundaryCondition> getAllPhysicalBoundaryConditions();
313 void setAllPhysicalBoundaryConditions (QList<PhysicalBoundaryCondition> physical_boundary_conditions);
314 void setAllPhysicalBoundaryConditions (QMap<QString, PhysicalBoundaryCondition> physical_boundary_conditions);
315 bool physicalTypeDefined(QString name) { return m_PhysicalBoundaryConditionsMap.contains(name); };
316 PhysicalBoundaryCondition getPhysicalBoundaryCondition(QString name) { return m_PhysicalBoundaryConditionsMap[name]; }
318 static GuiMainWindow* pointer() { return THIS; }
319 static void lock() { m_Mutex.lock(); }
320 static void unlock() { m_Mutex.unlock(); }
321 static bool tryLock() { return m_Mutex.tryLock(); }
322 void getAllBoundaryCodes( QSet<int> &bcs );
323 void getDisplayBoundaryCodes( QSet<int> &bcs );
324 vtkPointPicker* getPointPicker() { return ( m_PointPicker );}
325 vtkSphereSource* getPickSphere() { return ( m_PickSphere );}
326 bool pickPoint( vtkIdType id_point );
327 bool pickCell( vtkIdType id_cell );
329 QString getFilename() { return( m_CurrentFilename ); }
330 void setFilename(QString filename) { m_CurrentFilename = filename; }
332 SurfaceProjection* getSurfProj(int bc);
333 bool checkSurfProj();
335 public slots:
337 void setUseVTKInteractor( int a_UseVTKInteractor );
338 void setPickMode( bool a_UseVTKInteractor, bool a_CellPickerMode );
340 void exit(); ///< Exit the application
341 void importSTL(); ///< Import an STL file (ASCII or binary)
342 void importGmsh1Ascii(); ///< Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format
343 void exportGmsh1Ascii(); ///< Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format
344 void importGmsh2Ascii(); ///< Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format
345 void exportGmsh2Ascii(); ///< Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format
346 void exportNeutral(); ///< Export a grid to neutral format for NETGEN
347 void updateActors( bool force = false ); ///< Update the VTK output
348 void forceUpdateActors(); ///< Force an update of the VTK output
349 void scaleToData(); ///< Scale to data
350 void zoomAll(); ///< Move the camera in order to show everything on the screen
351 void zoomOnPickedObject();
352 void deselectAll();
353 void printGrid() {cout << "PrintGrid() called!" << endl; cout_grid( cout, grid, true, true, true, true );}
354 void info();
356 void undo();
357 void redo();
359 void resetOperationCounter();
361 void openXml( QString file_name ); ///< Open the case from an XML file
362 void saveXml( QString file_name ); ///< Save the case in an XML file
363 void open(); ///< Open an existing case
364 void open( QString file_name, bool update_current_filename = true ); ///< Open case file_name
365 void save(); ///< Save the current case
366 void saveAs(); ///< Save the current case -- using a different file name
367 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).
369 int quickSave(); ///< Save the current grid as a_filename_a_operation
370 void quickLoad( int a_operation ); ///< Load a_filename_a_operation
371 void updateStatusBar(); ///< Update the status bar
372 void selectBoundaryCodes(); ///< Select the boundary codes to be displayed/hidden
373 void updateBoundaryCodes( bool all_on ); ///< Update the boundary code book keeping (e.g. after reading a mesh).
374 void normalExtrusion(); ///< Normal extrusion of boundary elements (no validity check).
375 void setAxesVisibility(); ///< Toggle the visibility of the axes annotation.
376 void setViewingMode(); ///< Toggle orthogonal viewing mode.
377 void viewNodeIDs(); ///< Toggle node ID viewing mode.
378 void viewCellIDs(); ///< Toggle cell ID viewing mode.
379 void changeSurfaceOrientation(); ///< Change the orientation of all surface elements
380 void checkSurfaceOrientation(); ///< Check and, if required, change the orientation of all surface elements
381 void improveAspectRatio(); ///< Eliminate edges in order to improve the aspect ratio of the cells
382 void exportAsciiStl(); ///< Write surface elements to an ASCII STL file.
383 void exportBinaryStl(); ///< Write surface elements to a binary STL file.
384 void editBoundaryConditions(); ///< Edit boundary conditions (names and types)
385 void configure(); ///< Edit settings
386 void about(); ///< Display an about message
387 void markOutputLine(); ///< Mark the current position in the output window
389 QString getXmlSection( QString name ); ///< Get a section from the XML case description
390 void setXmlSection( QString name, QString contents ); ///< Set a section of the XML case description
392 void viewXP();
393 void viewXM();
394 void viewYP();
395 void viewYM();
396 void viewZP();
397 void viewZM();
399 void appendOutput( QString txt ) { ui.textEditOutput->append( txt ); }
400 void clearOutput() { ui.textEditOutput->clear(); }
401 void updateOutput();
402 void periodicUpdate();
404 void storeSurfaceProjection();
406 // SLOTS for all standard operations should be defined below;
407 // entries should look like this:
408 // void callOperationName() { EG_STDSLOT(OperationName); };
409 // The actual class name in this case, however, would be GuiOperationName.
411 // the following line can be used as a template:
412 // void call() { EG_STDSLOT(); };
413 // IMPORTANT: Using EG_STDSLOT sets gui to true, while EG_STDINTERSLOT does not (default is gui = false)
414 // This is important to determine whether an operation is a GUI operation or not.
415 // If it's a GUI operation, it locks everything.
416 // 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... Why?
418 void callCreateSurfaceMesh() { EG_STDSLOT( GuiCreateSurfaceMesh ); }
419 void callCreateBoundaryLayer() { EG_STDSLOT( GuiCreateBoundaryLayer ); }
420 void callDivideBoundaryLayer() { EG_STDSLOT( GuiDivideBoundaryLayer ); }
421 void callDeleteVolumeGrid() { EG_STDSLOT( DeleteVolumeGrid ); }
422 void callDeleteTetras() { EG_STDSLOT( DeleteTetras ); }
423 void callCreateVolumeMesh() { EG_STDSLOT( GuiCreateVolumeMesh ); }
424 void callSmoothVolumeGrid() { EG_STDSLOT( SmoothVolumeGrid ); }
425 void callSetBoundaryCode() { EG_STDINTERSLOT( GuiSetBoundaryCode ); }
426 void callDeleteBadAspectTris() { EG_STDINTERSLOT( GuiDeleteBadAspectTris ); }
427 void callDeletePickedCell() { EG_STDSLOT( DeletePickedCell ); }
428 void callDeletePickedPoint();
429 void callBoxSelect() { EG_STDINTERSLOT( BoxSelect ); }
430 void callCheckSurfaceIntegrity() { EG_STDINTERSLOT( CheckSurfaceIntegrity ); }
431 void callPick_cell_point() { EG_STDINTERSLOT( GuiPick ); }
432 void callTransform() { EG_STDINTERSLOT( GuiTransform ); }
433 void callUpdateSurfProj() { EG_STDSLOT( UpdateSurfProj ); }
434 void callImportOpenFoamCase() { EG_STDREADERSLOT(FoamReader); }
436 void callFixSTL();
438 void callFoamWriter() { EG_STDINTERSLOT( FoamWriter ); }
439 void callSimpleFoamWriter() { EG_STDINTERSLOT( SimpleFoamWriter ); }
440 void callFoamCaseWriter() { EG_STDINTERSLOT( OpenFOAMcase ); }
441 void callCgnsWriter() { EG_STDINTERSLOT( CgnsWriter ); }
442 void callVtkReader() { EG_STDREADERSLOT( VtkReader ); }
443 void callPolyDataReader() { EG_STDREADERSLOT( PolyDataReader ); }
444 void callReducedPolyDataReader() { EG_STDREADERSLOT( ReducedPolyDataReader ); }
445 void callSeligAirfoilReader() { EG_STDREADERSLOT( SeligAirfoilReader ); }
446 void callSurfaceMesher() { EG_STDSLOT(SurfaceMesher); }
447 void callReduceSurfaceTriangulation() { EG_STDSLOT(ReduceSurfaceTriangulation); }
448 void callEliminateSmallBranches() { EG_STDSLOT(EliminateSmallBranches); }
449 void callSmoothAndSwapSurface() { EG_STDSLOT(SmoothAndSwapSurface); }
453 #endif