GuiPick class mostly done.
[engrid.git] / guimainwindow.h
blob02dc094225cb4a6a3cf1e0541643b221c5e127d1
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>
37 #include <vtkUnstructuredGrid.h>
38 #include <vtkActor.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;
64 Q_OBJECT;
66 private: // attributes
68 Ui::GuiOutputWindow ui;
70 public: // methods
72 GuiOutputWindow();
79 /**
80 * This is the main GUI class of enGrid.
82 class GuiMainWindow : public QMainWindow, public EgVtkObject
85 Q_OBJECT;
87 private: // attributes
89 /** The user interface definition -- created by QtDesigner. */
90 Ui::GuiMainWindow ui;
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 */
199 bool busy;
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 */
205 long int N_chars;
207 FILE *system_stdout;
208 static QMutex mutex;
209 QTimer garbage_timer;
210 QTimer log_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
230 static QString cwd;
232 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
233 static GuiMainWindow *THIS;
235 private: // methods
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);
246 public: // methods
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.
253 GuiMainWindow();
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();
272 /**
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);};
326 vtkSphereSource* getPickSphere(){return(pick_sphere);};
327 bool pickPoint(vtkIdType Point);
328 bool pickCell(vtkIdType cellId);
330 public slots:
332 /** Exit the application */
333 void exit();
335 /** Import an STL file (ASCII or binary) */
336 void importSTL();
338 /** Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format */
339 void importGmsh1Ascii();
341 /** Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format */
342 void exportGmsh1Ascii();
344 /** Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format */
345 void importGmsh2Ascii();
347 /** Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format */
348 void exportGmsh2Ascii();
350 /** Export a grid to neutral format for NETGEN */
351 void exportNeutral();
353 /** Update the VTK output */
354 void updateActors();
356 /** Move the camera in order to show everything on the screen */
357 void zoomAll();
359 /** Open an existing grid */
360 void open();
362 void openBC();
363 void saveBC();
365 void undo();
366 void redo();
368 /** Save the current grid */
369 void save();
371 /** Save the current grid -- using a different file name */
372 void saveAs();
374 /** Update the status bar */
375 void updateStatusBar();
377 /** Select the boundary codes to be diplayed/hidden */
378 void selectBoundaryCodes();
380 /** Update the boundary code book keeping (e.g. after reading a mesh). */
381 void updateBoundaryCodes(bool all_on);
383 /** Normal extrusion of boundary elements (no validity check). */
384 void normalExtrusion();
386 /** Toggle the visibility of the axes annotation. */
387 void setAxesVisibility();
389 /** Toggle orthogonal viewing mode. */
390 void setViewingMode();
392 /** Toggle node ID viewing mode. */
393 void ViewNodeIDs();
395 /** Toggle cell ID viewing mode. */
396 void ViewCellIDs();
398 /** Change the orientation of all surface elements */
399 void changeSurfaceOrientation();
401 /** Check and, if required, change the orientation of all surface elements */
402 void checkSurfaceOrientation();
404 /** Eliminate edges in order to improve the aspect ratio of the cells */
405 void improveAspectRatio();
407 /** Write surface elements to an ASCII STL file. */
408 void exportAsciiStl();
410 /** Write surface elements to a binary STL file. */
411 void exportBinaryStl();
413 /** Edit boundary conditions (names and types) */
414 void editBoundaryConditions();
416 /** Edit settings */
417 void configure();
419 /** Display an about message */
420 void about();
422 void viewXP();
423 void viewXM();
424 void viewYP();
425 void viewYM();
426 void viewZP();
427 void viewZM();
429 void appendOutput(QString txt) { output_window->ui.textEditOutput->append(txt); };
430 void clearOutput() { output_window->ui.textEditOutput->clear(); };
431 void updateOutput();
432 void periodicUpdate();
434 // SLOTS for all standard operations should be defined below;
435 // entries should look like this:
436 // void callOperationName() { EG_STDSLOT(OperationName); };
437 // The actual class name in this case, however, would be GuiOperationName.
439 // the following line can be used as a template:
440 // void call() { EG_STDSLOT(); };
442 void callSmoothSurface() { EG_STDINTERSLOT(GuiSmoothSurface); };
443 void callCreateBoundaryLayer() { EG_STDSLOT(GuiCreateBoundaryLayer); };
444 void callDivideBoundaryLayer() { EG_STDSLOT(GuiDivideBoundaryLayer); };
445 void callDeleteVolumeGrid() { EG_STDSLOT(DeleteVolumeGrid); };
446 void callDeleteTetras() { EG_STDSLOT(DeleteTetras); };
447 void callCreateVolumeMesh() { EG_STDSLOT(CreateVolumeMesh); };
448 void callSmoothVolumeGrid() { EG_STDSLOT(SmoothVolumeGrid); };
449 void callSetBoundaryCode() { EG_STDINTERSLOT(GuiSetBoundaryCode); };
450 void callDeleteBadAspectTris() { EG_STDINTERSLOT(GuiDeleteBadAspectTris); };
451 void callDeletePickedCell() { EG_STDSLOT(DeletePickedCell); };
452 void callDeletePickedPoint() { EG_STDINTERSLOT(DeletePickedPoint); };
453 void callPick_cell_point() { EG_STDINTERSLOT(GuiPick); };
454 void callTransform() { EG_STDINTERSLOT(GuiTransform); };
456 void callFixSTL();
458 void callFoamReader() { EG_STDREADERSLOT(FoamReader); };
459 void callFoamWriter() { EG_STDINTERSLOT(FoamWriter); };
460 void callSimpleFoamWriter() { EG_STDINTERSLOT(SimpleFoamWriter); };
461 void callVtkReader() { EG_STDREADERSLOT(VtkReader); };
462 void callPolyDataReader() { EG_STDREADERSLOT(PolyDataReader); };
466 #endif