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>
49 #include "ui_guimainwindow.h"
50 #include "ui_guioutputwindow.h"
51 #include "vtkEgBoundaryCodesFilter.h"
52 #include "vtkEgExtractVolumeCells.h"
53 #include "egvtkobject.h"
54 #include "boundarycondition.h"
56 #include "std_includes.h"
57 #include "guitransform.h"
59 class GuiOutputWindow
: public QWidget
62 friend class GuiMainWindow
;
66 private: // attributes
68 Ui::GuiOutputWindow ui
;
80 * This is the main GUI class of enGrid.
82 class GuiMainWindow
: public QMainWindow
, public EgVtkObject
87 private: // attributes
89 /** The user interface definition -- created by QtDesigner. */
92 /** The current state of the grid that is being generated. */
93 vtkUnstructuredGrid
*grid
;
95 vtkPolyData
*boundary_pd
;
96 vtkPolyData
*tetras_pd
;
97 vtkPolyData
*wedges_pd
;
98 vtkPolyData
*pyras_pd
;
99 vtkPolyData
*hexas_pd
;
100 vtkPolyData
*volume_pd
;
102 /** The VTK renderer object, used for visualising the grid */
103 vtkRenderer
*renderer
;
105 vtkActor
*surface_actor
;
106 vtkActor
*surface_wire_actor
;
107 vtkActor
*tetra_actor
;
108 vtkActor
*wedge_actor
;
109 vtkActor
*pyramid_actor
;
110 vtkActor
*hexa_actor
;
111 vtkActor
*volume_wire_actor
;
112 vtkProperty
*backface_property
;
114 vtkPolyDataMapper
*surface_mapper
;
115 vtkPolyDataMapper
*surface_wire_mapper
;
116 vtkPolyDataMapper
*tetra_mapper
;
117 vtkPolyDataMapper
*pyramid_mapper
;
118 vtkPolyDataMapper
*wedge_mapper
;
119 vtkPolyDataMapper
*hexa_mapper
;
120 vtkPolyDataMapper
*volume_wire_mapper
;
122 vtkEgExtractVolumeCells
*extr_vol
;
123 vtkEgExtractVolumeCells
*extr_tetras
;
124 vtkEgExtractVolumeCells
*extr_pyramids
;
125 vtkEgExtractVolumeCells
*extr_wedges
;
126 vtkEgExtractVolumeCells
*extr_hexas
;
128 vtkGeometryFilter
*volume_geometry
;
129 vtkGeometryFilter
*tetra_geometry
;
130 vtkGeometryFilter
*pyramid_geometry
;
131 vtkGeometryFilter
*wedge_geometry
;
132 vtkGeometryFilter
*hexa_geometry
;
134 /** VTK filter to extract the surface of the current grid. */
135 vtkGeometryFilter
*surface_filter
;
137 /** sphere to mark picked cell/points */
138 vtkSphereSource
*pick_sphere
;
140 /** Size to use for picker objects and annotations */
141 double ReferenceSize
;
143 /** 2D Text actor to display node IDs */
144 vector
<vtkTextActor
*> NodeText
;
146 /** 2D Text actor to display cell IDs */
147 vector
<vtkTextActor
*> CellText
;
149 /** 3D Text actor to display node IDs */
150 vector
<vtkVectorText
*> NodeText_VectorText
;
151 vector
<vtkPolyDataMapper
*> NodeText_PolyDataMapper
;
152 vector
<vtkFollower
*> NodeText_Follower
;
154 /** 3D Text actor to display cell IDs */
155 vector
<vtkVectorText
*> CellText_VectorText
;
156 vector
<vtkPolyDataMapper
*> CellText_PolyDataMapper
;
157 vector
<vtkFollower
*> CellText_Follower
;
159 vtkTextActor
* textActor
[3];
161 vtkVectorText
* atext
[3];
162 vtkPolyDataMapper
* textMapper
[3];
163 vtkFollower
* textActor2
[3];
165 /** VTK mapper to map pick marker */
166 vtkPolyDataMapper
*pick_mapper
;
168 /** VTK actor to display pick marker */
169 vtkActor
*pick_actor
;
171 /** VTK actor to display the coordinate system */
172 vtkCubeAxesActor2D
*axes
;
174 /** The current file name of the grid. */
175 QString current_filename
;
177 /** Status bar of the main window and application */
178 QStatusBar
*status_bar
;
180 /** Label for the information in the status bar */
181 QLabel
*status_label
;
183 /** A QList with all active boundary codes. */
184 QSet
<int> display_boundary_codes
;
186 /** A QList with all boundary codes. */
187 QSet
<int> all_boundary_codes
;
189 /** VTK filter to extract boundary elements with certain codes */
190 vtkEgBoundaryCodesFilter
*bcodes_filter
;
192 /** VTK CellPicker to pick cells for various user interactions */
193 vtkCellPicker
*CellPicker
;
195 /** VTK PointPicker to pick points for various user interactions */
196 vtkPointPicker
*PointPicker
;
198 /** flag to indicate that enGrid is busy with an operation */
201 /** log file to collect program output for display in the output window */
202 QString log_file_name
;
204 /** number of lines that have been read from the log file */
209 QTimer garbage_timer
;
211 GuiOutputWindow
*output_window
;
212 QDockWidget
*dock_widget
;
214 /** mapping between numerical and symbolic boundary codes */
215 QMap
<int,BoundaryCondition
> bcmap
;
217 private: // static attributes
220 * Platform independant access to application settings.
221 * For a UNIX system the user preferences will be stored in the file
222 * folder ".config/enGits/enGrid.conf" in the user's home directory;
223 * on Windows preferences will be stored in the registry.
225 static QSettings qset
;
228 * The current working directory of enGrid
232 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
233 static GuiMainWindow
*THIS
;
237 /** Add VTK type information to the grid (useful for visualisation with ParaView). */
238 void addVtkTypeInfo();
240 /** callback for cell picking */
241 static void pickCellCallBack(vtkObject
*caller
, unsigned long int eid
, void *clientdata
, void *calldata
);
243 /** callback for point picking */
244 static void pickPointCallBack(vtkObject
*caller
, unsigned long int eid
, void *clientdata
, void *calldata
);
249 * The constructor connects the menu and toolbar actions and
250 * the VTK basics(i.e. renderer, actor, ...) will be set up.
251 * Furthermore preferences will be read from qset.
256 * Preferences will be written back.
258 virtual ~GuiMainWindow();
261 * Get the VTK render window
262 * @return the VTK render window
264 vtkRenderWindow
* getRenderWindow();
267 * Get the VTK renderer
268 * @return the VTK renderer
270 vtkRenderer
* getRenderer();
273 * Get the Qt-VTK interactor
274 * @return the Qt-VTK interactor
276 QVTKInteractor
* getInteractor();
279 * Get a pointer to the current grid object
280 * @return a pointer to the current vtkUnstructuredGrid object
282 vtkUnstructuredGrid
* getGrid() { return grid
; };
284 void setBusy() { busy
= true; updateStatusBar(); };
285 void setIdle() { busy
= false; updateStatusBar(); };
287 public: // static methods
290 * Get the current working directory.
291 * @return the current working directory
293 static QString
getCwd();
296 * Set the current working directory
297 * @param cwd the current working directory
299 static void setCwd(QString dir
);
302 * Get the currently picked cell.
303 * @return the picked cell ID or -1 if no cell has been picked
305 static vtkIdType
getPickedCell();
308 * Get the currently picked point.
309 * @return the picked point ID or -1 if no point has been picked
311 static vtkIdType
getPickedPoint();
314 * Access to the QSettings object/
316 static QSettings
* settings() { return &qset
; };
318 BoundaryCondition
getBC(int bc
) { return bcmap
[bc
]; };
320 static GuiMainWindow
* pointer() { return THIS
; };
321 static void lock() { mutex
.lock(); };
322 static void unlock() { mutex
.unlock(); };
323 static bool tryLock() { return mutex
.tryLock(); };
324 void getAllBoundaryCodes(QSet
<int> &bcs
);
325 vtkPointPicker
* getPointPicker(){return(PointPicker
);};
329 /** Exit the application */
332 /** Import an STL file (ASCII or binary) */
335 /** Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format */
336 void importGmsh1Ascii();
338 /** Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format */
339 void exportGmsh1Ascii();
341 /** Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format */
342 void importGmsh2Ascii();
344 /** Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format */
345 void exportGmsh2Ascii();
347 /** Export a grid to neutral format for NETGEN */
348 void exportNeutral();
350 /** Update the VTK output */
353 /** Move the camera in order to show everything on the screen */
356 /** Open an existing grid */
365 /** Save the current grid */
368 /** Save the current grid -- using a different file name */
371 /** Update the status bar */
372 void updateStatusBar();
374 /** Select the boundary codes to be diplayed/hidden */
375 void selectBoundaryCodes();
377 /** Update the boundary code book keeping (e.g. after reading a mesh). */
378 void updateBoundaryCodes(bool all_on
);
380 /** Normal extrusion of boundary elements (no validity check). */
381 void normalExtrusion();
383 /** Toggle the visibility of the axes annotation. */
384 void setAxesVisibility();
386 /** Toggle orthogonal viewing mode. */
387 void setViewingMode();
389 /** Toggle node ID viewing mode. */
392 /** Toggle cell ID viewing mode. */
395 /** Change the orientation of all surface elements */
396 void changeSurfaceOrientation();
398 /** Check and, if required, change the orientation of all surface elements */
399 void checkSurfaceOrientation();
401 /** Eliminate edges in order to improve the aspect ratio of the cells */
402 void improveAspectRatio();
404 /** Write surface elements to an ASCII STL file. */
405 void exportAsciiStl();
407 /** Write surface elements to a binary STL file. */
408 void exportBinaryStl();
410 /** Edit boundary conditions (names and types) */
411 void editBoundaryConditions();
416 /** Display an about message */
426 void appendOutput(QString txt
) { output_window
->ui
.textEditOutput
->append(txt
); };
427 void clearOutput() { output_window
->ui
.textEditOutput
->clear(); };
429 void periodicUpdate();
431 // SLOTS for all standard operations should be defined below;
432 // entries should look like this:
433 // void callOperationName() { EG_STDSLOT(OperationName); };
434 // The actual class name in this case, however, would be GuiOperationName.
436 // the following line can be used as a template:
437 // void call() { EG_STDSLOT(); };
439 void callSmoothSurface() { EG_STDINTERSLOT(GuiSmoothSurface
); };
440 void callCreateBoundaryLayer() { EG_STDSLOT(GuiCreateBoundaryLayer
); };
441 void callDivideBoundaryLayer() { EG_STDSLOT(GuiDivideBoundaryLayer
); };
442 void callDeleteVolumeGrid() { EG_STDSLOT(DeleteVolumeGrid
); };
443 void callDeleteTetras() { EG_STDSLOT(DeleteTetras
); };
444 void callCreateVolumeMesh() { EG_STDSLOT(CreateVolumeMesh
); };
445 void callSmoothVolumeGrid() { EG_STDSLOT(SmoothVolumeGrid
); };
446 void callSetBoundaryCode() { EG_STDINTERSLOT(GuiSetBoundaryCode
); };
447 void callDeleteBadAspectTris() { EG_STDINTERSLOT(GuiDeleteBadAspectTris
); };
448 void callDeletePickedCell() { EG_STDSLOT(DeletePickedCell
); };
449 void callDeletePickedPoint() { EG_STDINTERSLOT(DeletePickedPoint
); };
450 void callTransform() { EG_STDINTERSLOT(GuiTransform
); };
454 void callFoamReader() { EG_STDREADERSLOT(FoamReader
); };
455 void callFoamWriter() { EG_STDINTERSLOT(FoamWriter
); };
456 void callSimpleFoamWriter() { EG_STDINTERSLOT(SimpleFoamWriter
); };
457 void callVtkReader() { EG_STDREADERSLOT(VtkReader
); };
458 void callPolyDataReader() { EG_STDREADERSLOT(PolyDataReader
); };