improved settingssheet saving: it now saves as current_filename+.sp. Loading and...
[engrid.git] / guimainwindow.h
blob5ee3a53a0406f5d8c2cdc5b82b287df9f18d40f2
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 /** Picked point */
160 static vtkIdType PickedPoint;
162 /** Picked cell */
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 */
208 bool busy;
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 */
214 long int N_chars;
216 FILE *system_stdout;
217 static QMutex mutex;
218 QTimer garbage_timer;
219 QTimer log_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
239 static QString cwd;
241 /** a static this pointer (somewhat ugly, but there is only one MainWindow) */
242 static GuiMainWindow *THIS;
244 private: // methods
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);
255 public: // methods
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.
262 GuiMainWindow();
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();
281 /**
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);
339 QString GetFilename() {return(current_filename);};
341 public slots:
342 void setUseVTKInteractor(int a_UseVTKInteractor);
343 void setPickMode(bool a_UseVTKInteractor,bool a_CellPickerMode);
345 /** Exit the application */
346 void exit();
348 /** Import an STL file (ASCII or binary) */
349 void importSTL();
351 /** Import a Gmsh grid from an ASCII file -- using version 1.0 of the Gmsh file format */
352 void importGmsh1Ascii();
354 /** Export a grid from to an ASCII Gmsh file -- using version 1.0 of the Gmsh file format */
355 void exportGmsh1Ascii();
357 /** Import a Gmsh grid from an ASCII file -- using version 2.0 of the Gmsh file format */
358 void importGmsh2Ascii();
360 /** Export a grid from to an ASCII Gmsh file -- using version 2.0 of the Gmsh file format */
361 void exportGmsh2Ascii();
363 /** Export a grid to neutral format for NETGEN */
364 void exportNeutral();
366 /** Update the VTK output */
367 void updateActors();
369 /** Move the camera in order to show everything on the screen */
370 void zoomAll();
372 /** Open an existing grid */
373 void open();
375 void openBC();
376 void saveBC();
378 void undo();
379 void redo();
381 /** Save the current grid */
382 void save();
384 /** Save the current grid -- using a different file name */
385 void saveAs();
387 /** Save the current grid as a_filename */
388 void QuickSave(QString a_filename);
390 /** Update the status bar */
391 void updateStatusBar();
393 /** Select the boundary codes to be diplayed/hidden */
394 void selectBoundaryCodes();
396 /** Update the boundary code book keeping (e.g. after reading a mesh). */
397 void updateBoundaryCodes(bool all_on);
399 /** Normal extrusion of boundary elements (no validity check). */
400 void normalExtrusion();
402 /** Toggle the visibility of the axes annotation. */
403 void setAxesVisibility();
405 /** Toggle orthogonal viewing mode. */
406 void setViewingMode();
408 /** Toggle node ID viewing mode. */
409 void ViewNodeIDs();
411 /** Toggle cell ID viewing mode. */
412 void ViewCellIDs();
414 /** Change the orientation of all surface elements */
415 void changeSurfaceOrientation();
417 /** Check and, if required, change the orientation of all surface elements */
418 void checkSurfaceOrientation();
420 /** Eliminate edges in order to improve the aspect ratio of the cells */
421 void improveAspectRatio();
423 /** Write surface elements to an ASCII STL file. */
424 void exportAsciiStl();
426 /** Write surface elements to a binary STL file. */
427 void exportBinaryStl();
429 /** Edit boundary conditions (names and types) */
430 void editBoundaryConditions();
432 /** Edit settings */
433 void configure();
435 /** Display an about message */
436 void about();
438 void viewXP();
439 void viewXM();
440 void viewYP();
441 void viewYM();
442 void viewZP();
443 void viewZM();
445 void appendOutput(QString txt) { output_window->ui.textEditOutput->append(txt); };
446 void clearOutput() { output_window->ui.textEditOutput->clear(); };
447 void updateOutput();
448 void periodicUpdate();
450 // SLOTS for all standard operations should be defined below;
451 // entries should look like this:
452 // void callOperationName() { EG_STDSLOT(OperationName); };
453 // The actual class name in this case, however, would be GuiOperationName.
455 // the following line can be used as a template:
456 // void call() { EG_STDSLOT(); };
458 void callSmoothSurface() { EG_STDINTERSLOT(GuiSmoothSurface); };
459 void callCreateBoundaryLayer() { EG_STDSLOT(GuiCreateBoundaryLayer); };
460 void callDivideBoundaryLayer() { EG_STDSLOT(GuiDivideBoundaryLayer); };
461 void callDeleteVolumeGrid() { EG_STDSLOT(DeleteVolumeGrid); };
462 void callDeleteTetras() { EG_STDSLOT(DeleteTetras); };
463 void callCreateVolumeMesh() { EG_STDSLOT(CreateVolumeMesh); };
464 void callSmoothVolumeGrid() { EG_STDSLOT(SmoothVolumeGrid); };
465 void callSetBoundaryCode() { EG_STDINTERSLOT(GuiSetBoundaryCode); };
466 void callDeleteBadAspectTris() { EG_STDINTERSLOT(GuiDeleteBadAspectTris); };
467 void callDeletePickedCell() { EG_STDSLOT(DeletePickedCell); };
468 void callDeletePickedPoint() { EG_STDINTERSLOT(DeletePickedPoint); };
469 void callPick_cell_point() { EG_STDINTERSLOT(GuiPick); };
470 void callTransform() { EG_STDINTERSLOT(GuiTransform); };
472 void callFixSTL();
474 void callFoamReader() { EG_STDREADERSLOT(FoamReader); };
475 void callFoamWriter() { EG_STDINTERSLOT(FoamWriter); };
476 void callSimpleFoamWriter() { EG_STDINTERSLOT(SimpleFoamWriter); };
477 void callVtkReader() { EG_STDREADERSLOT(VtkReader); };
478 void callPolyDataReader() { EG_STDREADERSLOT(PolyDataReader); };
482 #endif