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
;
160 static vtkIdType PickedPoint
;
163 static vtkIdType PickedCell
;
165 /** Boolean value specifying wether the VTK Interactor should be used or not to determine picked points/cells */
166 static bool m_UseVTKInteractor
;
168 /* vtkTextActor* textActor[3];
170 vtkVectorText* atext[3];
171 vtkPolyDataMapper* textMapper[3];
172 vtkFollower* textActor2[3];*/
174 /** VTK mapper to map pick marker */
175 vtkPolyDataMapper
*pick_mapper
;
177 /** VTK actor to display pick marker */
178 vtkActor
*pick_actor
;
180 /** VTK actor to display the coordinate system */
181 vtkCubeAxesActor2D
*axes
;
183 /** The current file name of the grid. */
184 QString current_filename
;
186 /** Status bar of the main window and application */
187 QStatusBar
*status_bar
;
189 /** Label for the information in the status bar */
190 QLabel
*status_label
;
192 /** A QList with all active boundary codes. */
193 QSet
<int> display_boundary_codes
;
195 /** A QList with all boundary codes. */
196 QSet
<int> all_boundary_codes
;
198 /** VTK filter to extract boundary elements with certain codes */
199 vtkEgBoundaryCodesFilter
*bcodes_filter
;
201 /** VTK CellPicker to pick cells for various user interactions */
202 vtkCellPicker
*CellPicker
;
204 /** VTK PointPicker to pick points for various user interactions */
205 vtkPointPicker
*PointPicker
;
207 /** flag to indicate that enGrid is busy with an operation */
210 /** log file to collect program output for display in the output window */
211 QString log_file_name
;
213 /** number of lines that have been read from the log file */
218 QTimer garbage_timer
;
220 GuiOutputWindow
*output_window
;
221 QDockWidget
*dock_widget
;
223 /** mapping between numerical and symbolic boundary codes */
224 QMap
<int,BoundaryCondition
> bcmap
;
226 private: // static attributes
229 * Platform independant access to application settings.
230 * For a UNIX system the user preferences will be stored in the file
231 * folder ".config/enGits/enGrid.conf" in the user's home directory;
232 * on Windows preferences will be stored in the registry.
234 static QSettings qset
;
237 * The current working directory of enGrid
241 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
242 static GuiMainWindow
*THIS
;
246 /** Add VTK type information to the grid (useful for visualisation with ParaView). */
247 void addVtkTypeInfo();
249 /** callback for cell picking */
250 static void pickCellCallBack(vtkObject
*caller
, unsigned long int eid
, void *clientdata
, void *calldata
);
252 /** callback for point picking */
253 static void pickPointCallBack(vtkObject
*caller
, unsigned long int eid
, void *clientdata
, void *calldata
);
258 * The constructor connects the menu and toolbar actions and
259 * the VTK basics(i.e. renderer, actor, ...) will be set up.
260 * Furthermore preferences will be read from qset.
265 * Preferences will be written back.
267 virtual ~GuiMainWindow();
270 * Get the VTK render window
271 * @return the VTK render window
273 vtkRenderWindow
* getRenderWindow();
276 * Get the VTK renderer
277 * @return the VTK renderer
279 vtkRenderer
* getRenderer();
282 * Get the Qt-VTK interactor
283 * @return the Qt-VTK interactor
285 QVTKInteractor
* getInteractor();
288 * Get a pointer to the current grid object
289 * @return a pointer to the current vtkUnstructuredGrid object
291 vtkUnstructuredGrid
* getGrid() { return grid
; };
293 void setBusy() { busy
= true; updateStatusBar(); };
294 void setIdle() { busy
= false; updateStatusBar(); };
296 public: // static methods
299 * Get the current working directory.
300 * @return the current working directory
302 static QString
getCwd();
305 * Set the current working directory
306 * @param cwd the current working directory
308 static void setCwd(QString dir
);
311 * Get the currently picked cell.
312 * @return the picked cell ID or -1 if no cell has been picked
314 static vtkIdType
getPickedCell();
317 * Get the currently picked point.
318 * @return the picked point ID or -1 if no point has been picked
320 static vtkIdType
getPickedPoint();
323 * Access to the QSettings object/
325 static QSettings
* settings() { return &qset
; };
327 BoundaryCondition
getBC(int bc
) { return bcmap
[bc
]; };
329 static GuiMainWindow
* pointer() { return THIS
; };
330 static void lock() { mutex
.lock(); };
331 static void unlock() { mutex
.unlock(); };
332 static bool tryLock() { return mutex
.tryLock(); };
333 void getAllBoundaryCodes(QSet
<int> &bcs
);
334 vtkPointPicker
* getPointPicker(){return(PointPicker
);};
335 vtkSphereSource
* getPickSphere(){return(pick_sphere
);};
336 bool pickPoint(vtkIdType Point
);
337 bool pickCell(vtkIdType cellId
);
340 void setUseVTKInteractor(int a_UseVTKInteractor
);
341 void setPickMode(bool a_UseVTKInteractor
,bool a_CellPickerMode
);
343 /** Exit the application */
346 /** Import an STL file (ASCII or binary) */
349 /** Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format */
350 void importGmsh1Ascii();
352 /** Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format */
353 void exportGmsh1Ascii();
355 /** Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format */
356 void importGmsh2Ascii();
358 /** Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format */
359 void exportGmsh2Ascii();
361 /** Export a grid to neutral format for NETGEN */
362 void exportNeutral();
364 /** Update the VTK output */
367 /** Move the camera in order to show everything on the screen */
370 /** Open an existing grid */
379 /** Save the current grid */
382 /** Save the current grid -- using a different file name */
385 /** Save the current grid as a_filename */
386 void QuickSave(QString a_filename
);
388 /** Update the status bar */
389 void updateStatusBar();
391 /** Select the boundary codes to be diplayed/hidden */
392 void selectBoundaryCodes();
394 /** Update the boundary code book keeping (e.g. after reading a mesh). */
395 void updateBoundaryCodes(bool all_on
);
397 /** Normal extrusion of boundary elements (no validity check). */
398 void normalExtrusion();
400 /** Toggle the visibility of the axes annotation. */
401 void setAxesVisibility();
403 /** Toggle orthogonal viewing mode. */
404 void setViewingMode();
406 /** Toggle node ID viewing mode. */
409 /** Toggle cell ID viewing mode. */
412 /** Change the orientation of all surface elements */
413 void changeSurfaceOrientation();
415 /** Check and, if required, change the orientation of all surface elements */
416 void checkSurfaceOrientation();
418 /** Eliminate edges in order to improve the aspect ratio of the cells */
419 void improveAspectRatio();
421 /** Write surface elements to an ASCII STL file. */
422 void exportAsciiStl();
424 /** Write surface elements to a binary STL file. */
425 void exportBinaryStl();
427 /** Edit boundary conditions (names and types) */
428 void editBoundaryConditions();
433 /** Display an about message */
443 void appendOutput(QString txt
) { output_window
->ui
.textEditOutput
->append(txt
); };
444 void clearOutput() { output_window
->ui
.textEditOutput
->clear(); };
446 void periodicUpdate();
448 // SLOTS for all standard operations should be defined below;
449 // entries should look like this:
450 // void callOperationName() { EG_STDSLOT(OperationName); };
451 // The actual class name in this case, however, would be GuiOperationName.
453 // the following line can be used as a template:
454 // void call() { EG_STDSLOT(); };
456 void callSmoothSurface() { EG_STDINTERSLOT(GuiSmoothSurface
); };
457 void callCreateBoundaryLayer() { EG_STDSLOT(GuiCreateBoundaryLayer
); };
458 void callDivideBoundaryLayer() { EG_STDSLOT(GuiDivideBoundaryLayer
); };
459 void callDeleteVolumeGrid() { EG_STDSLOT(DeleteVolumeGrid
); };
460 void callDeleteTetras() { EG_STDSLOT(DeleteTetras
); };
461 void callCreateVolumeMesh() { EG_STDSLOT(CreateVolumeMesh
); };
462 void callSmoothVolumeGrid() { EG_STDSLOT(SmoothVolumeGrid
); };
463 void callSetBoundaryCode() { EG_STDINTERSLOT(GuiSetBoundaryCode
); };
464 void callDeleteBadAspectTris() { EG_STDINTERSLOT(GuiDeleteBadAspectTris
); };
465 void callDeletePickedCell() { EG_STDSLOT(DeletePickedCell
); };
466 void callDeletePickedPoint() { EG_STDINTERSLOT(DeletePickedPoint
); };
467 void callPick_cell_point() { EG_STDINTERSLOT(GuiPick
); };
468 void callTransform() { EG_STDINTERSLOT(GuiTransform
); };
472 void callFoamReader() { EG_STDREADERSLOT(FoamReader
); };
473 void callFoamWriter() { EG_STDINTERSLOT(FoamWriter
); };
474 void callSimpleFoamWriter() { EG_STDINTERSLOT(SimpleFoamWriter
); };
475 void callVtkReader() { EG_STDREADERSLOT(VtkReader
); };
476 void callPolyDataReader() { EG_STDREADERSLOT(PolyDataReader
); };