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>
37 #include <vtkUnstructuredGrid.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 "ui_guioutputwindow.h"
53 #include "vtkEgBoundaryCodesFilter.h"
54 #include "vtkEgExtractVolumeCells.h"
55 #include "egvtkobject.h"
56 #include "boundarycondition.h"
58 #include "std_includes.h"
59 #include "guitransform.h"
61 class GuiOutputWindow
: public QWidget
64 friend class GuiMainWindow
;
68 private: // attributes
70 Ui::GuiOutputWindow ui
;
82 * This is the main GUI class of enGrid.
84 class GuiMainWindow
: public QMainWindow
, public EgVtkObject
89 private: // attributes
91 /** The user interface definition -- created by QtDesigner. */
94 /** The current state of the grid that is being generated. */
95 vtkUnstructuredGrid
*grid
;
97 vtkPolyData
*boundary_pd
;
98 vtkPolyData
*tetras_pd
;
99 vtkPolyData
*wedges_pd
;
100 vtkPolyData
*pyras_pd
;
101 vtkPolyData
*hexas_pd
;
102 vtkPolyData
*volume_pd
;
104 /** The VTK renderer object, used for visualising the grid */
105 vtkRenderer
*renderer
;
107 vtkActor
*surface_actor
;
108 vtkActor
*surface_wire_actor
;
109 vtkActor
*tetra_actor
;
110 vtkActor
*wedge_actor
;
111 vtkActor
*pyramid_actor
;
112 vtkActor
*hexa_actor
;
113 vtkActor
*volume_wire_actor
;
114 vtkProperty
*backface_property
;
117 vtkScalarBarActor
*iamlegend_actor
;
119 vtkPolyDataMapper
*field_mapper
;
120 vtkPolyDataMapper
*surface_mapper
;
121 vtkPolyDataMapper
*surface_wire_mapper
;
122 vtkPolyDataMapper
*tetra_mapper
;
123 vtkPolyDataMapper
*pyramid_mapper
;
124 vtkPolyDataMapper
*wedge_mapper
;
125 vtkPolyDataMapper
*hexa_mapper
;
126 vtkPolyDataMapper
*volume_wire_mapper
;
128 vtkEgExtractVolumeCells
*extr_vol
;
129 vtkEgExtractVolumeCells
*extr_tetras
;
130 vtkEgExtractVolumeCells
*extr_pyramids
;
131 vtkEgExtractVolumeCells
*extr_wedges
;
132 vtkEgExtractVolumeCells
*extr_hexas
;
134 vtkGeometryFilter
*volume_geometry
;
135 vtkGeometryFilter
*tetra_geometry
;
136 vtkGeometryFilter
*pyramid_geometry
;
137 vtkGeometryFilter
*wedge_geometry
;
138 vtkGeometryFilter
*hexa_geometry
;
140 /** VTK filter to extract the surface of the current grid. */
141 vtkGeometryFilter
*surface_filter
;
143 /** sphere to mark picked cell/points */
144 vtkSphereSource
*pick_sphere
;
146 /** Size to use for picker objects and annotations */
147 double ReferenceSize
;
149 /** 2D Text actor to display node IDs */
150 vector
<vtkTextActor
*> NodeText
;
152 /** 2D Text actor to display cell IDs */
153 vector
<vtkTextActor
*> CellText
;
155 /** 3D Text actor to display node IDs */
156 vector
<vtkVectorText
*> NodeText_VectorText
;
157 vector
<vtkPolyDataMapper
*> NodeText_PolyDataMapper
;
158 vector
<vtkFollower
*> NodeText_Follower
;
160 /** 3D Text actor to display cell IDs */
161 vector
<vtkVectorText
*> CellText_VectorText
;
162 vector
<vtkPolyDataMapper
*> CellText_PolyDataMapper
;
163 vector
<vtkFollower
*> CellText_Follower
;
166 static vtkIdType PickedPoint
;
169 static vtkIdType PickedCell
;
171 /** Boolean value specifying wether the VTK Interactor should be used or not to determine picked points/cells */
172 static bool m_UseVTKInteractor
;
174 /* vtkTextActor* textActor[3];
176 vtkVectorText* atext[3];
177 vtkPolyDataMapper* textMapper[3];
178 vtkFollower* textActor2[3];*/
180 /** VTK mapper to map pick marker */
181 vtkPolyDataMapper
*pick_mapper
;
183 /** VTK actor to display pick marker */
184 vtkActor
*pick_actor
;
186 /** VTK actor to display the coordinate system */
187 vtkCubeAxesActor2D
*axes
;
189 /** The current file name of the grid. */
190 QString current_filename
;
192 /** Status bar of the main window and application */
193 QStatusBar
*status_bar
;
195 /** Label for the information in the status bar */
196 QLabel
*status_label
;
198 /** A QList with all active boundary codes. */
199 QSet
<int> display_boundary_codes
;
201 /** A QList with all boundary codes. */
202 QSet
<int> all_boundary_codes
;
204 /** VTK filter to extract boundary elements with certain codes */
205 vtkEgBoundaryCodesFilter
*bcodes_filter
;
207 /** VTK CellPicker to pick cells for various user interactions */
208 vtkCellPicker
*CellPicker
;
210 /** VTK PointPicker to pick points for various user interactions */
211 vtkPointPicker
*PointPicker
;
213 /** flag to indicate that enGrid is busy with an operation */
216 /** log file to collect program output for display in the output window */
217 QString log_file_name
;
219 /** number of lines that have been read from the log file */
224 QTimer garbage_timer
;
226 GuiOutputWindow
*output_window
;
227 QDockWidget
*dock_widget
;
229 /** mapping between numerical and symbolic boundary codes */
230 QMap
<int,BoundaryCondition
> bcmap
;
232 private: // static attributes
235 * Platform independant access to application settings.
236 * For a UNIX system the user preferences will be stored in the file
237 * folder ".config/enGits/enGrid.conf" in the user's home directory;
238 * on Windows preferences will be stored in the registry.
240 static QSettings qset
;
243 * The current working directory of enGrid
247 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
248 static GuiMainWindow
*THIS
;
252 /** Add VTK type information to the grid (useful for visualisation with ParaView). */
253 void addVtkTypeInfo();
255 /** callback for cell picking */
256 static void pickCellCallBack(vtkObject
*caller
, unsigned long int eid
, void *clientdata
, void *calldata
);
258 /** callback for point picking */
259 static void pickPointCallBack(vtkObject
*caller
, unsigned long int eid
, void *clientdata
, void *calldata
);
264 * The constructor connects the menu and toolbar actions and
265 * the VTK basics(i.e. renderer, actor, ...) will be set up.
266 * Furthermore preferences will be read from qset.
271 * Preferences will be written back.
273 virtual ~GuiMainWindow();
276 * Get the VTK render window
277 * @return the VTK render window
279 vtkRenderWindow
* getRenderWindow();
282 * Get the VTK renderer
283 * @return the VTK renderer
285 vtkRenderer
* getRenderer();
288 * Get the Qt-VTK interactor
289 * @return the Qt-VTK interactor
291 QVTKInteractor
* getInteractor();
294 * Get a pointer to the current grid object
295 * @return a pointer to the current vtkUnstructuredGrid object
297 vtkUnstructuredGrid
* getGrid() { return grid
; };
299 void setBusy() { busy
= true; updateStatusBar(); };
300 void setIdle() { busy
= false; updateStatusBar(); };
302 public: // static methods
305 * Get the current working directory.
306 * @return the current working directory
308 static QString
getCwd();
311 * Set the current working directory
312 * @param cwd the current working directory
314 static void setCwd(QString dir
);
317 * Get the currently picked cell.
318 * @return the picked cell ID or -1 if no cell has been picked
320 static vtkIdType
getPickedCell();
323 * Get the currently picked point.
324 * @return the picked point ID or -1 if no point has been picked
326 static vtkIdType
getPickedPoint();
329 * Access to the QSettings object/
331 static QSettings
* settings() { return &qset
; };
333 BoundaryCondition
getBC(int bc
) { return bcmap
[bc
]; };
335 static GuiMainWindow
* pointer() { return THIS
; };
336 static void lock() { mutex
.lock(); };
337 static void unlock() { mutex
.unlock(); };
338 static bool tryLock() { return mutex
.tryLock(); };
339 void getAllBoundaryCodes(QSet
<int> &bcs
);
340 vtkPointPicker
* getPointPicker(){return(PointPicker
);};
341 vtkSphereSource
* getPickSphere(){return(pick_sphere
);};
342 bool pickPoint(vtkIdType Point
);
343 bool pickCell(vtkIdType cellId
);
345 QString
GetFilename() {return(current_filename
);};
348 void setUseVTKInteractor(int a_UseVTKInteractor
);
349 void setPickMode(bool a_UseVTKInteractor
,bool a_CellPickerMode
);
351 /** Exit the application */
354 /** Import an STL file (ASCII or binary) */
357 /** Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format */
358 void importGmsh1Ascii();
360 /** Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format */
361 void exportGmsh1Ascii();
363 /** Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format */
364 void importGmsh2Ascii();
366 /** Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format */
367 void exportGmsh2Ascii();
369 /** Export a grid to neutral format for NETGEN */
370 void exportNeutral();
372 /** Update the VTK output */
378 /** Move the camera in order to show everything on the screen */
381 /** Open an existing grid */
390 /** Save the current grid */
393 /** Save the current grid -- using a different file name */
396 /** Save the current grid as a_filename */
397 void QuickSave(QString a_filename
);
399 /** Update the status bar */
400 void updateStatusBar();
402 /** Select the boundary codes to be diplayed/hidden */
403 void selectBoundaryCodes();
405 /** Update the boundary code book keeping (e.g. after reading a mesh). */
406 void updateBoundaryCodes(bool all_on
);
408 /** Normal extrusion of boundary elements (no validity check). */
409 void normalExtrusion();
411 /** Toggle the visibility of the axes annotation. */
412 void setAxesVisibility();
414 /** Toggle orthogonal viewing mode. */
415 void setViewingMode();
417 /** Toggle node ID viewing mode. */
420 /** Toggle cell ID viewing mode. */
423 /** Change the orientation of all surface elements */
424 void changeSurfaceOrientation();
426 /** Check and, if required, change the orientation of all surface elements */
427 void checkSurfaceOrientation();
429 /** Eliminate edges in order to improve the aspect ratio of the cells */
430 void improveAspectRatio();
432 /** Write surface elements to an ASCII STL file. */
433 void exportAsciiStl();
435 /** Write surface elements to a binary STL file. */
436 void exportBinaryStl();
438 /** Edit boundary conditions (names and types) */
439 void editBoundaryConditions();
444 /** Display an about message */
454 void appendOutput(QString txt
) { output_window
->ui
.textEditOutput
->append(txt
); };
455 void clearOutput() { output_window
->ui
.textEditOutput
->clear(); };
457 void periodicUpdate();
459 // SLOTS for all standard operations should be defined below;
460 // entries should look like this:
461 // void callOperationName() { EG_STDSLOT(OperationName); };
462 // The actual class name in this case, however, would be GuiOperationName.
464 // the following line can be used as a template:
465 // void call() { EG_STDSLOT(); };
467 void callSmoothSurface() { EG_STDINTERSLOT(GuiSmoothSurface
); };
468 void callCreateBoundaryLayer() { EG_STDSLOT(GuiCreateBoundaryLayer
); };
469 void callDivideBoundaryLayer() { EG_STDSLOT(GuiDivideBoundaryLayer
); };
470 void callDeleteVolumeGrid() { EG_STDSLOT(DeleteVolumeGrid
); };
471 void callDeleteTetras() { EG_STDSLOT(DeleteTetras
); };
472 void callCreateVolumeMesh() { EG_STDSLOT(CreateVolumeMesh
); };
473 void callSmoothVolumeGrid() { EG_STDSLOT(SmoothVolumeGrid
); };
474 void callSetBoundaryCode() { EG_STDINTERSLOT(GuiSetBoundaryCode
); };
475 void callDeleteBadAspectTris() { EG_STDINTERSLOT(GuiDeleteBadAspectTris
); };
476 void callDeletePickedCell() { EG_STDSLOT(DeletePickedCell
); };
477 void callDeletePickedPoint() { EG_STDINTERSLOT(DeletePickedPoint
); };
478 void callPick_cell_point() { EG_STDINTERSLOT(GuiPick
); };
479 void callTransform() { EG_STDINTERSLOT(GuiTransform
); };
483 void callFoamReader() { EG_STDREADERSLOT(FoamReader
); };
484 void callFoamWriter() { EG_STDINTERSLOT(FoamWriter
); };
485 void callSimpleFoamWriter() { EG_STDINTERSLOT(SimpleFoamWriter
); };
486 void callVtkReader() { EG_STDREADERSLOT(VtkReader
); };
487 void callPolyDataReader() { EG_STDREADERSLOT(PolyDataReader
); };