2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28 #include <QMainWindow>
32 #include <QFileSystemWatcher>
35 #include <QDockWidget>
36 #include <QDomDocument>
38 #include <vtkUnstructuredGrid.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"
68 * This is the main GUI class of enGrid.
70 class GuiMainWindow
: public QMainWindow
, public EgVtkObject
75 private: // attributes
77 QDomDocument m_XmlDoc
; ///< XML document describing the complete case
79 Ui::GuiMainWindow ui
; ///< The user interface definition -- created by QtDesigner.
80 vtkUnstructuredGrid
*grid
; ///< The current state of the grid that is being generated.
82 vtkRenderer
*m_Renderer
; ///< The VTK renderer object, used for visualising the grid
84 vtkActor
* m_SurfaceActor
;
85 vtkActor
* m_SurfaceWireActor
;
86 vtkActor
* m_TetraActor
;
87 vtkActor
* m_WedgeActor
;
88 vtkActor
* m_PyramidActor
;
89 vtkActor
* m_HexaActor
;
90 vtkActor
* m_VolumeWireActor
;
92 vtkProperty
* m_BackfaceProperty
;
93 vtkLookupTable
* m_LookupTable
;
94 vtkScalarBarActor
* m_LegendActor
;
96 vtkPolyDataMapper
* m_SurfaceMapper
;
97 vtkPolyDataMapper
* m_SurfaceWireMapper
;
98 vtkPolyDataMapper
* m_TetraMapper
;
99 vtkPolyDataMapper
* m_PyramidMapper
;
100 vtkPolyDataMapper
* m_WedgeMapper
;
101 vtkPolyDataMapper
* m_HexaMapper
;
102 vtkPolyDataMapper
* m_VolumeWireMapper
;
104 vtkEgExtractVolumeCells
*m_ExtrVol
;
105 vtkEgExtractVolumeCells
*m_ExtrTetras
;
106 vtkEgExtractVolumeCells
*m_ExtrPyramids
;
107 vtkEgExtractVolumeCells
*m_ExtrWedges
;
108 vtkEgExtractVolumeCells
*m_ExtrHexes
;
110 vtkGeometryFilter
*m_VolumeGeometry
;
111 vtkGeometryFilter
*m_TetraGeometry
;
112 vtkGeometryFilter
*m_PyramidGeometry
;
113 vtkGeometryFilter
*m_WedgeGeometry
;
114 vtkGeometryFilter
*m_HexaGeometry
;
116 vtkIdType m_PickedPoint
; ///< Picked point
117 vtkIdType m_PickedCell
; ///< Picked cell
118 bool m_UseVTKInteractor
; ///< Boolean value specifying whether the VTK Interactor should be used or not
120 static QMutex m_Mutex
;
122 vtkGeometryFilter
* m_SurfaceFilter
; ///< VTK filter to extract the surface of the current grid.
123 double m_ReferenceSize
; ///< Size to use for picker objects and annotations
125 vector
<vtkTextActor
*> m_NodeText
; ///< 2D Text actor to display node IDs
126 vector
<vtkTextActor
*> m_CellText
; ///< 2D Text actor to display cell IDs
127 vector
<vtkVectorText
*> m_NodeTextVectorText
; ///< 3D Text actor to display node IDs
128 vector
<vtkPolyDataMapper
*> m_NodeTextPolyDataMapper
;
129 vector
<vtkFollower
*> m_NodeTextFollower
;
130 vector
<vtkVectorText
*> m_CellTextVectorText
; ///< 3D Text actor to display cell IDs
131 vector
<vtkPolyDataMapper
*> m_CellTextPolyDataMapper
;
132 vector
<vtkFollower
*> m_CellTextFollower
;
134 vtkPolyDataMapper
* m_PickMapper
; ///< VTK mapper to map pick marker
135 vtkActor
* m_PickActor
; ///< VTK actor to display pick marker
136 vtkSphereSource
* m_PickSphere
; ///< sphere to mark picked cell/points
137 vtkCubeAxesActor2D
* m_Axes
; ///< VTK actor to display the coordinate system
138 vtkEgBoundaryCodesFilter
* m_BCodesFilter
; ///< VTK filter to extract boundary elements with certain codes
139 vtkCellPicker
* m_CellPicker
; ///< VTK CellPicker to pick cells for various user interactions
140 vtkPointPicker
* m_PointPicker
; ///< VTK PointPicker to pick points for various user interactions
142 QString m_CurrentFilename
; ///< The current file name of the grid.
143 int m_CurrentOperation
; ///< The current operation number. (used for undo/redo)
144 int m_LastOperation
; ///< The last operation number. (used for undo/redo)
145 QString m_LogDir
; ///< the log directory
146 QLabel
* m_StatusLabel
; ///< Label for the information in the status bar
147 QSet
<int> m_DisplayBoundaryCodes
; ///< A QList with all active boundary codes.
148 QSet
<int> m_AllBoundaryCodes
; ///< A QList with all boundary codes.
149 bool m_Busy
; ///< flag to indicate that enGrid is busy with an operation
150 QString m_LogFileName
; ///< log file to collect program output for display in the output window
151 long int m_N_chars
; ///< number of lines that have been read from the log file
152 FILE* m_SystemStdout
;
153 QTimer m_GarbageTimer
;
156 QMap
<int, BoundaryCondition
> m_bcmap
; ///< mapping between numerical and symbolic boundary codes
157 QMap
<QString
, VolumeDefinition
> m_VolMap
; ///< all volume definitions
158 QMap
<QString
, PhysicalBoundaryCondition
> m_PhysicalBoundaryConditionsMap
; ///< all physical boundary conditions definitions
160 QMap
<int, SurfaceProjection
*> m_SurfProj
; ///< all surface projectors for surface meshing
162 int m_SolverIndex
;// deprecated
163 OpenFOAMTools m_OpenFoamTools
;
165 private: // static attributes
168 * Platform independant access to application settings.
169 * For a UNIX system the user preferences will be stored in the file
170 * folder ".config/enGits/enGrid.conf" in the user's home directory;
171 * on Windows preferences will be stored in the registry.
173 static QSettings m_qset
;
176 * The current working directory of enGrid
178 static QString m_cwd
;
181 * Is the current case unsaved?
183 static bool m_UnSaved
;
185 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
186 static GuiMainWindow
* THIS
;
191 void addVtkTypeInfo(); ///< Add VTK type information to the grid (useful for visualisation with ParaView).
192 static void pickCallBack( vtkObject
*caller
, unsigned long int eid
, void *clientdata
, void *calldata
);
193 void updateSurfaceActors( bool forced
);
194 void updateVolumeActors( bool forced
);
198 void setClipX( const QString
&txt
);
199 void setClipY( const QString
&txt
);
200 void setClipZ( const QString
&txt
);
201 void setClipNX( const QString
&txt
);
202 void setClipNY( const QString
&txt
);
203 void setClipNZ( const QString
&txt
);
208 void openPhysicalBoundaryConditions();
209 void savePhysicalBoundaryConditions();
211 void openGrid( QString file_name
);
212 void saveGrid( QString file_name
);
219 * The constructor connects the menu and toolbar actions and
220 * the VTK basics(i.e. renderer, actor, ...) will be set up.
221 * Furthermore preferences will be read from qset.
226 * Preferences will be written back.
228 virtual ~GuiMainWindow();
231 * Get the VTK render window
232 * @return the VTK render window
234 vtkRenderWindow
* getRenderWindow();
237 * Get the VTK renderer
238 * @return the VTK renderer
240 vtkRenderer
* getRenderer();
243 * Get the Qt-VTK interactor
244 * @return the Qt-VTK interactor
246 QVTKInteractor
* getInteractor();
249 * Get a pointer to the current grid object
250 * @return a pointer to the current vtkUnstructuredGrid object
252 vtkUnstructuredGrid
* getGrid() { return grid
; }
254 void setBusy() { m_Busy
= true; updateStatusBar(); }
255 void setIdle() { m_Busy
= false; updateStatusBar(); }
257 /// Returns log directory
258 QString
getLogDir() { return m_LogDir
; }
260 /// Returns the path to the currently loaded file
261 QString
getFilePath();
263 /// Returns the index of the solver to use. The index corresponds to the position in solvers.txt .
264 void setSolverIndex(int x
) {m_SolverIndex
= x
;}
265 int getSolverIndex() {return m_SolverIndex
;}
267 public: // static methods
270 * Get the current working directory.
271 * @return the current working directory
273 static QString
getCwd();
276 * Set the current working directory
277 * @param dir the current working directory
279 static void setCwd( QString dir
);
283 * @param unsaved Do you want to be asked where to save when clicking on save next time?
285 static void setUnsaved( bool unsaved
);
288 * Get the currently picked cell.
289 * @return the picked cell ID or -1 if no cell has been picked
291 vtkIdType
getPickedCell();
294 * Get the currently picked point.
295 * @return the picked point ID or -1 if no point has been picked
297 vtkIdType
getPickedPoint();
300 * Access to the QSettings object
302 static QSettings
* settings() { return &m_qset
; }
304 BoundaryCondition
getBC( int bc
) { return m_bcmap
[bc
]; }
305 VolumeDefinition
getVol( QString volname
) { return m_VolMap
[volname
]; }
306 void clearBCs() { m_bcmap
.clear(); }
307 void addBC(int bc
, BoundaryCondition BC
) { m_bcmap
[bc
] = BC
; }
309 QList
<VolumeDefinition
> getAllVols();
310 void setAllVols( QList
<VolumeDefinition
> vols
);
311 void createDefaultVol();
313 QList
<PhysicalBoundaryCondition
> getAllPhysicalBoundaryConditions();
314 void setAllPhysicalBoundaryConditions (QList
<PhysicalBoundaryCondition
> physical_boundary_conditions
);
315 void setAllPhysicalBoundaryConditions (QMap
<QString
, PhysicalBoundaryCondition
> physical_boundary_conditions
);
316 bool physicalTypeDefined(QString name
) { return m_PhysicalBoundaryConditionsMap
.contains(name
); };
317 PhysicalBoundaryCondition
getPhysicalBoundaryCondition(QString name
) { return m_PhysicalBoundaryConditionsMap
[name
]; }
319 static GuiMainWindow
* pointer() { return THIS
; }
320 static void lock() { m_Mutex
.lock(); }
321 static void unlock() { m_Mutex
.unlock(); }
322 static bool tryLock() { return m_Mutex
.tryLock(); }
323 void getAllBoundaryCodes( QSet
<int> &bcs
);
324 void getDisplayBoundaryCodes( QSet
<int> &bcs
);
325 vtkPointPicker
* getPointPicker() { return ( m_PointPicker
);}
326 vtkSphereSource
* getPickSphere() { return ( m_PickSphere
);}
327 bool pickPoint( vtkIdType id_point
);
328 bool pickCell( vtkIdType id_cell
);
330 QString
getFilename() { return( m_CurrentFilename
); }
331 void setFilename(QString filename
) { m_CurrentFilename
= filename
; }
333 SurfaceProjection
* getSurfProj(int bc
);
334 bool checkSurfProj();
338 void setUseVTKInteractor( int a_UseVTKInteractor
);
339 void setPickMode( bool a_UseVTKInteractor
, bool a_CellPickerMode
);
341 void exit(); ///< Exit the application
342 void importSTL(); ///< Import an STL file (ASCII or binary)
343 void importGmsh1Ascii(); ///< Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format
344 void exportGmsh1Ascii(); ///< Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format
345 void importGmsh2Ascii(); ///< Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format
346 void exportGmsh2Ascii(); ///< Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format
347 void exportNeutral(); ///< Export a grid to neutral format for NETGEN
348 void updateActors( bool force
= false ); ///< Update the VTK output
349 void forceUpdateActors(); ///< Force an update of the VTK output
350 void scaleToData(); ///< Scale to data
351 void zoomAll(); ///< Move the camera in order to show everything on the screen
352 void zoomOnPickedObject();
354 void printGrid() {cout
<< "PrintGrid() called!" << endl
; cout_grid( cout
, grid
, true, true, true, true );}
360 void resetOperationCounter();
362 void openXml( QString file_name
); ///< Open the case from an XML file
363 void saveXml( QString file_name
); ///< Save the case in an XML file
364 void open(); ///< Open an existing case
365 void open( QString file_name
, bool update_current_filename
= true ); ///< Open case file_name
366 void save(); ///< Save the current case
367 void saveAs(); ///< Save the current case -- using a different file name
368 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).
370 int quickSave(); ///< Save the current grid as a_filename_a_operation
371 void quickLoad( int a_operation
); ///< Load a_filename_a_operation
372 void updateStatusBar(); ///< Update the status bar
373 void selectBoundaryCodes(); ///< Select the boundary codes to be displayed/hidden
374 void updateBoundaryCodes( bool all_on
); ///< Update the boundary code book keeping (e.g. after reading a mesh).
375 void normalExtrusion(); ///< Normal extrusion of boundary elements (no validity check).
376 void setAxesVisibility(); ///< Toggle the visibility of the axes annotation.
377 void setViewingMode(); ///< Toggle orthogonal viewing mode.
378 void viewNodeIDs(); ///< Toggle node ID viewing mode.
379 void viewCellIDs(); ///< Toggle cell ID viewing mode.
380 void changeSurfaceOrientation(); ///< Change the orientation of all surface elements
381 void checkSurfaceOrientation(); ///< Check and, if required, change the orientation of all surface elements
382 void improveAspectRatio(); ///< Eliminate edges in order to improve the aspect ratio of the cells
383 void exportAsciiStl(); ///< Write surface elements to an ASCII STL file.
384 void exportBinaryStl(); ///< Write surface elements to a binary STL file.
385 void editBoundaryConditions(); ///< Edit boundary conditions (names and types)
386 void configure(); ///< Edit settings
387 void about(); ///< Display an about message
388 void markOutputLine(); ///< Mark the current position in the output window
390 QString
getXmlSection( QString name
); ///< Get a section from the XML case description
391 void setXmlSection( QString name
, QString contents
); ///< Set a section of the XML case description
400 void appendOutput( QString txt
) { ui
.textEditOutput
->append( txt
); }
401 void clearOutput() { ui
.textEditOutput
->clear(); }
403 void periodicUpdate();
405 void storeSurfaceProjection();
407 // SLOTS for all standard operations should be defined below;
408 // entries should look like this:
409 // void callOperationName() { EG_STDSLOT(OperationName); };
410 // The actual class name in this case, however, would be GuiOperationName.
412 // the following line can be used as a template:
413 // void call() { EG_STDSLOT(); };
414 // IMPORTANT: Using EG_STDSLOT sets gui to true, while EG_STDINTERSLOT does not (default is gui = false)
415 // This is important to determine whether an operation is a GUI operation or not.
416 // If it's a GUI operation, it locks everything.
417 // 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?
419 void callCreateSurfaceMesh() { EG_STDSLOT( GuiCreateSurfaceMesh
); }
420 void callCreateBoundaryLayer() { EG_STDSLOT( GuiCreateBoundaryLayer
); }
421 void callDivideBoundaryLayer() { EG_STDSLOT( GuiDivideBoundaryLayer
); }
422 void callDeleteVolumeGrid() { EG_STDSLOT( DeleteVolumeGrid
); }
423 void callDeleteTetras() { EG_STDSLOT( DeleteTetras
); }
424 void callCreateVolumeMesh() { EG_STDSLOT( GuiCreateVolumeMesh
); }
425 void callSmoothVolumeGrid() { EG_STDSLOT( SmoothVolumeGrid
); }
426 void callSetBoundaryCode() { EG_STDINTERSLOT( GuiSetBoundaryCode
); }
427 void callDeleteBadAspectTris() { EG_STDINTERSLOT( GuiDeleteBadAspectTris
); }
428 void callDeletePickedCell() { EG_STDSLOT( DeletePickedCell
); }
429 void callDeletePickedPoint();
430 void callBoxSelect() { EG_STDINTERSLOT( BoxSelect
); }
431 void callCheckSurfaceIntegrity() { EG_STDINTERSLOT( CheckSurfaceIntegrity
); }
432 void callPick_cell_point() { EG_STDINTERSLOT( GuiPick
); }
433 void callTransform() { EG_STDINTERSLOT( GuiTransform
); }
434 void callUpdateSurfProj() { EG_STDSLOT( UpdateSurfProj
); }
435 void callImportOpenFoamCase() { EG_STDREADERSLOT(FoamReader
); }
439 void callFoamWriter() { EG_STDINTERSLOT( FoamWriter
); }
440 void callSimpleFoamWriter() { EG_STDINTERSLOT( SimpleFoamWriter
); }
441 void callFoamCaseWriter() { EG_STDINTERSLOT( OpenFOAMcase
); }
442 void callCgnsWriter() { EG_STDINTERSLOT( CgnsWriter
); }
443 void callVtkReader() { EG_STDREADERSLOT( VtkReader
); }
444 void callPolyDataReader() { EG_STDREADERSLOT( PolyDataReader
); }
445 void callReducedPolyDataReader() { EG_STDREADERSLOT( ReducedPolyDataReader
); }
446 void callSeligAirfoilReader() { EG_STDREADERSLOT( SeligAirfoilReader
); }
447 void callSurfaceMesher() { EG_STDSLOT(SurfaceMesher
); }
448 void callReduceSurfaceTriangulation() { EG_STDSLOT(ReduceSurfaceTriangulation
); }
449 void callEliminateSmallBranches() { EG_STDSLOT(EliminateSmallBranches
); }
450 void callSmoothAndSwapSurface() { EG_STDSLOT(SmoothAndSwapSurface
); }
452 void callFixCADGeometry() { EG_STDSLOT(FixCadGeometry
); }