OGS
mainwindow.cpp
Go to the documentation of this file.
1
15#include "mainwindow.h"
16
17#include "BaseLib/Logging.h"
18
19// Qt includes
20#include <QDate>
21#include <QDesktopWidget>
22#include <QFileDialog>
23#include <QMessageBox>
24#include <QObject>
25#include <QScreen>
26#include <QSettings>
27#include <QSignalMapper>
28#ifndef NDEBUG
29#include <QElapsedTimer>
30#endif // NDEBUG
31
32// VTK includes
33#include <vtkImageAlgorithm.h>
34#include <vtkImageData.h>
35#include <vtkOBJExporter.h>
36#include <vtkRenderer.h>
37#include <vtkVRMLExporter.h>
38
50#include "BaseLib/FileTools.h"
51#include "BaseLib/Histogram.h"
56#include "GeoLib/Raster.h"
57#include "InfoLib/GitInfo.h"
62#include "MeshLib/Mesh.h"
63#include "MeshLib/Node.h"
68
69// Dialogs
85#ifdef OGS_USE_NETCDF
87#endif // OGS_USE_NETCDF
89#include "Base/OGSError.h"
90#include "Base/RecentFiles.h"
99#include "VtkVis/VtkRaster.h"
101
102using namespace FileIO;
103
104MainWindow::MainWindow(QWidget* parent /* = 0*/) : QMainWindow(parent)
105{
106 setupUi(this);
107
108 // Setup various models
109 _geo_model = std::make_unique<GEOModels>(_project.getGEOObjects());
110 _meshModel = std::make_unique<MeshModel>(_project);
111 _elementModel = std::make_unique<ElementTreeModel>();
112 _processModel = std::make_unique<ProcessModel>(_project);
113 _conditionModel = std::make_unique<FemConditionModel>();
114
115 geoTabWidget->treeView->setModel(_geo_model->getGeoModel());
116 stationTabWidget->treeView->setModel(_geo_model->getStationModel());
117 meshTabWidget->treeView->setModel(_meshModel.get());
118 meshTabWidget->elementView->setModel(_elementModel.get());
119 modellingTabWidget->treeView->setModel(_processModel.get());
120 modellingTabWidget->conditionView->setModel(_conditionModel.get());
121
122 // vtk visualization pipeline
124 std::make_unique<VtkVisPipeline>(visualizationWidget->renderer());
125
126 // station model connects
127 connect(stationTabWidget->treeView, SIGNAL(openStationListFile(int)), this,
128 SLOT(open(int)));
129 connect(stationTabWidget->treeView,
130 SIGNAL(stationListExportRequested(std::string, std::string)), this,
132 std::string, std::string))); // export Stationlist to GMS
133 connect(stationTabWidget->treeView, SIGNAL(stationListRemoved(std::string)),
134 _geo_model.get(),
135 SLOT(removeStationVec(
136 std::string))); // update model when stations are removed
137 connect(stationTabWidget->treeView,
138 SIGNAL(stationListSaved(QString, QString)), this,
139 SLOT(writeStationListToFile(QString,
140 QString))); // save Stationlist to File
141 connect(
142 _geo_model.get(),
143 SIGNAL(stationVectorRemoved(StationTreeModel*, std::string)), this,
144 SLOT(updateDataViews())); // update data view when stations are removed
145 connect(stationTabWidget->treeView,
146 SIGNAL(requestNameChangeDialog(const std::string&, std::size_t)),
147 this, SLOT(showStationNameDialog(const std::string&, std::size_t)));
148 connect(stationTabWidget->treeView,
149 SIGNAL(geometryMappingRequested(const std::string&)), this,
150 SLOT(mapGeometry(const std::string&)));
151 connect(stationTabWidget->treeView, SIGNAL(diagramRequested(QModelIndex&)),
152 this,
154 QModelIndex&))); // connect treeview to diagramview
155
156 // geo model connects
157 connect(geoTabWidget->treeView, SIGNAL(openGeometryFile(int)), this,
158 SLOT(open(int)));
159 connect(geoTabWidget->treeView,
160 SIGNAL(listRemoved(std::string, GeoLib::GEOTYPE)), _geo_model.get(),
161 SLOT(removeGeometry(std::string, GeoLib::GEOTYPE)));
162 connect(geoTabWidget->treeView,
163 SIGNAL(geometryMappingRequested(const std::string&)), this,
164 SLOT(mapGeometry(const std::string&)));
165 connect(
166 geoTabWidget->treeView, SIGNAL(saveToFileRequested(QString, QString)),
167 this,
168 SLOT(writeGeometryToFile(QString, QString))); // save geometry to file
169 connect(geoTabWidget->treeView,
170 SIGNAL(requestPointToStationConversion(std::string const&)), this,
171 SLOT(convertPointsToStations(std::string const&)));
172 connect(
173 geoTabWidget->treeView,
174 SIGNAL(requestLineEditDialog(const std::string&)), this,
175 SLOT(showLineEditDialog(const std::string&))); // open line edit dialog
176 connect(geoTabWidget->treeView,
177 SIGNAL(requestNameChangeDialog(const std::string&,
178 const GeoLib::GEOTYPE, std::size_t)),
179 this,
180 SLOT(showGeoNameDialog(const std::string&, const GeoLib::GEOTYPE,
181 std::size_t)));
182 connect(_geo_model.get(),
183 SIGNAL(geoDataAdded(GeoTreeModel*, std::string, GeoLib::GEOTYPE)),
184 this, SLOT(updateDataViews()));
185 connect(_geo_model.get(),
186 SIGNAL(geoDataRemoved(GeoTreeModel*, std::string, GeoLib::GEOTYPE)),
187 this, SLOT(updateDataViews()));
188 connect(geoTabWidget->treeView,
189 SIGNAL(geoItemSelected(const vtkPolyDataAlgorithm*, int)),
190 _vtkVisPipeline.get(),
191 SLOT(highlightGeoObject(const vtkPolyDataAlgorithm*, int)));
192 connect(geoTabWidget->treeView, SIGNAL(removeGeoItemSelection()),
193 _vtkVisPipeline.get(), SLOT(removeHighlightedGeoObject()));
194 connect(stationTabWidget->treeView,
195 SIGNAL(geoItemSelected(const vtkPolyDataAlgorithm*, int)),
196 _vtkVisPipeline.get(),
197 SLOT(highlightGeoObject(const vtkPolyDataAlgorithm*, int)));
198 connect(stationTabWidget->treeView, SIGNAL(removeGeoItemSelection()),
199 _vtkVisPipeline.get(), SLOT(removeHighlightedGeoObject()));
200
201 // Setup connections for mesh models to GUI
202 connect(meshTabWidget->treeView, SIGNAL(openMeshFile(int)), this,
203 SLOT(open(int)));
204 connect(meshTabWidget->treeView,
205 SIGNAL(requestMeshRemoval(const QModelIndex&)), _meshModel.get(),
206 SLOT(removeMesh(const QModelIndex&)));
207 connect(meshTabWidget->treeView,
208 SIGNAL(requestMeshRemoval(const QModelIndex&)), _elementModel.get(),
209 SLOT(clearView()));
210 connect(
211 meshTabWidget->treeView,
212 SIGNAL(qualityCheckRequested(MeshLib::VtkMappedMeshSource*)),
213 this,
215 connect(meshTabWidget->treeView,
216 SIGNAL(requestMeshToGeometryConversion(const MeshLib::Mesh*)), this,
218 connect(meshTabWidget->treeView,
219 SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const* const,
220 unsigned, bool)),
221 _vtkVisPipeline.get(),
222 SLOT(highlightMeshComponent(
223 vtkUnstructuredGridAlgorithm const* const, unsigned, bool)));
224 connect(meshTabWidget->treeView, SIGNAL(meshSelected(MeshLib::Mesh const&)),
225 this->_elementModel.get(), SLOT(setMesh(MeshLib::Mesh const&)));
226 connect(meshTabWidget->treeView, SIGNAL(meshSelected(MeshLib::Mesh const&)),
227 meshTabWidget->elementView, SLOT(updateView()));
228 connect(
229 meshTabWidget->treeView,
230 SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const* const,
231 unsigned, bool)),
232 this->_elementModel.get(),
233 SLOT(setElement(vtkUnstructuredGridAlgorithm const* const, unsigned)));
234 connect(meshTabWidget->treeView,
235 SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const* const,
236 unsigned, bool)),
237 meshTabWidget->elementView, SLOT(updateView()));
238 connect(meshTabWidget->treeView,
239 SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const* const,
240 unsigned, bool)),
241 reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
242 SLOT(removeHighlightActor()));
243 connect(meshTabWidget->treeView, SIGNAL(removeSelectedMeshComponent()),
244 _vtkVisPipeline.get(), SLOT(removeHighlightedMeshComponent()));
245 connect(meshTabWidget->elementView,
246 SIGNAL(nodeSelected(vtkUnstructuredGridAlgorithm const* const,
247 unsigned, bool)),
248 reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
249 SLOT(removeHighlightActor()));
250 connect(meshTabWidget->elementView,
251 SIGNAL(nodeSelected(vtkUnstructuredGridAlgorithm const* const,
252 unsigned, bool)),
253 _vtkVisPipeline.get(),
254 SLOT(highlightMeshComponent(
255 vtkUnstructuredGridAlgorithm const* const, unsigned, bool)));
256 connect(meshTabWidget->elementView, SIGNAL(removeSelectedMeshComponent()),
257 _vtkVisPipeline.get(), SLOT(removeHighlightedMeshComponent()));
258
259 // Connection for process model to GUI
260 connect(modellingTabWidget->treeView,
261 SIGNAL(processVarRemoved(QString const&)), _processModel.get(),
262 SLOT(removeProcessVariable(QString const&)));
263 connect(modellingTabWidget->treeView,
264 SIGNAL(conditionRemoved(QString const&, QString const&)),
265 _processModel.get(),
266 SLOT(removeCondition(QString const&, QString const&)));
267 connect(modellingTabWidget->treeView, SIGNAL(clearConditionView()),
268 _conditionModel.get(), SLOT(clearView()));
269 connect(modellingTabWidget->treeView,
270 SIGNAL(processVarSelected(DataHolderLib::FemCondition*)),
271 _conditionModel.get(),
272 SLOT(setProcessVariable(DataHolderLib::FemCondition*)));
273 connect(modellingTabWidget->treeView,
274 SIGNAL(conditionSelected(DataHolderLib::FemCondition*)),
275 _conditionModel.get(),
276 SLOT(setFemCondition(DataHolderLib::FemCondition*)));
277 connect(modellingTabWidget->treeView,
278 SIGNAL(processVarSelected(DataHolderLib::FemCondition*)),
279 modellingTabWidget->conditionView, SLOT(updateView()));
280 connect(modellingTabWidget->treeView,
281 SIGNAL(conditionSelected(DataHolderLib::FemCondition*)),
282 modellingTabWidget->conditionView, SLOT(updateView()));
283
284 // VisPipeline Connects
285 connect(_geo_model.get(),
286 SIGNAL(geoDataAdded(GeoTreeModel*, std::string, GeoLib::GEOTYPE)),
287 _vtkVisPipeline.get(),
288 SLOT(addPipelineItem(GeoTreeModel*, std::string, GeoLib::GEOTYPE)));
289 connect(
290 _geo_model.get(),
291 SIGNAL(geoDataRemoved(GeoTreeModel*, std::string, GeoLib::GEOTYPE)),
292 _vtkVisPipeline.get(),
293 SLOT(removeSourceItem(GeoTreeModel*, std::string, GeoLib::GEOTYPE)));
294
295 connect(_geo_model.get(),
296 SIGNAL(stationVectorAdded(StationTreeModel*, std::string)),
297 _vtkVisPipeline.get(),
298 SLOT(addPipelineItem(StationTreeModel*, std::string)));
299 connect(_geo_model.get(),
300 SIGNAL(stationVectorRemoved(StationTreeModel*, std::string)),
301 _vtkVisPipeline.get(),
302 SLOT(removeSourceItem(StationTreeModel*, std::string)));
303
304 connect(_meshModel.get(), SIGNAL(meshAdded(MeshModel*, QModelIndex)),
305 _vtkVisPipeline.get(),
306 SLOT(addPipelineItem(MeshModel*, QModelIndex)));
307 connect(_meshModel.get(), SIGNAL(meshRemoved(MeshModel*, QModelIndex)),
308 _vtkVisPipeline.get(),
309 SLOT(removeSourceItem(MeshModel*, QModelIndex)));
310
311 connect(_vtkVisPipeline.get(), SIGNAL(vtkVisPipelineChanged()),
312 visualizationWidget->vtkWidget, SLOT(update()));
313 connect(_vtkVisPipeline.get(), SIGNAL(vtkVisPipelineChanged()),
314 vtkVisTabWidget->vtkVisPipelineView, SLOT(expandAll()));
315 connect(_vtkVisPipeline.get(), SIGNAL(itemSelected(const QModelIndex&)),
316 vtkVisTabWidget->vtkVisPipelineView,
317 SLOT(selectItem(const QModelIndex&)));
318
319 vtkVisTabWidget->vtkVisPipelineView->setModel(_vtkVisPipeline.get());
320 connect(vtkVisTabWidget->vtkVisPipelineView,
321 SIGNAL(requestRemovePipelineItem(QModelIndex)),
322 _vtkVisPipeline.get(), SLOT(removePipelineItem(QModelIndex)));
323 connect(vtkVisTabWidget->vtkVisPipelineView,
324 SIGNAL(requestAddPipelineFilterItem(QModelIndex)), this,
325 SLOT(showAddPipelineFilterItemDialog(QModelIndex)));
326 connect(vtkVisTabWidget, SIGNAL(requestViewUpdate()), visualizationWidget,
327 SLOT(updateView()));
328
329 connect(vtkVisTabWidget->vtkVisPipelineView,
330 SIGNAL(actorSelected(vtkProp3D*)),
331 reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
332 SLOT(highlightActor(vtkProp3D*)));
333 connect(_vtkVisPipeline.get(), SIGNAL(vtkVisPipelineChanged()),
334 visualizationWidget, SLOT(updateView()));
335
336 // Propagates selected vtk object in the pipeline to the pick interactor
337 connect(vtkVisTabWidget->vtkVisPipelineView,
338 SIGNAL(dataObjectSelected(vtkDataObject*)),
339 reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
340 SLOT(pickableDataObject(vtkDataObject*)));
341 connect(reinterpret_cast<QObject*>(visualizationWidget->vtkPickCallback()),
342 SIGNAL(actorPicked(vtkProp3D*)),
343 vtkVisTabWidget->vtkVisPipelineView, SLOT(selectItem(vtkProp3D*)));
344 connect(reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
345 SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const* const,
346 const unsigned)),
347 this->_elementModel.get(),
348 SLOT(setElement(vtkUnstructuredGridAlgorithm const* const,
349 const unsigned)));
350 connect(reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
351 SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const* const,
352 const unsigned)),
353 meshTabWidget->elementView, SLOT(updateView()));
354 connect(reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
355 SIGNAL(clearElementView()), this->_elementModel.get(),
356 SLOT(clearView()));
357 connect(reinterpret_cast<QObject*>(visualizationWidget->interactorStyle()),
358 SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const* const,
359 const unsigned)),
360 this->_vtkVisPipeline.get(),
361 SLOT(removeHighlightedMeshComponent()));
362
363 connect(vtkVisTabWidget->vtkVisPipelineView,
364 SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(),
365 SLOT(addMesh(MeshLib::Mesh*)));
366
367 // Stack the data dock widgets together
368 tabifyDockWidget(geoDock, mshDock);
369 tabifyDockWidget(mshDock, modellingDock);
370 tabifyDockWidget(modellingDock, stationDock);
371
372 // Restore window geometry
373 readSettings();
374
375 // Get info on screens geometry(ies)
376 _vtkWidget.reset(visualizationWidget->vtkWidget);
377 for (auto const& screen : QGuiApplication::screens())
378 {
379 _screenGeometries.push_back(screen->availableGeometry());
380 }
381
382 // Setup import files menu
383 QMenu* import_files_menu = createImportFilesMenu(); // owned by MainWindow
384 menu_File->insertMenu(action_Exit, import_files_menu);
385
386 // Setup recent files menu
387 RecentFiles* recentFiles =
388 new RecentFiles(this, SLOT(openRecentFile()), "recentFileList");
389 connect(this, SIGNAL(fileUsed(QString)), recentFiles,
390 SLOT(setCurrentFile(QString)));
391 menu_File->insertMenu(action_Exit, recentFiles->menu());
392
393 // Setup Windows menu
394 QAction* showGeoDockAction = geoDock->toggleViewAction();
395 showGeoDockAction->setStatusTip(tr("Shows / hides the geometry view"));
396 connect(showGeoDockAction, SIGNAL(triggered(bool)), this,
397 SLOT(showGeoDockWidget(bool)));
398 menuWindows->addAction(showGeoDockAction);
399
400 QAction* showStationDockAction = stationDock->toggleViewAction();
401 showStationDockAction->setStatusTip(tr("Shows / hides the station view"));
402 connect(showStationDockAction, SIGNAL(triggered(bool)), this,
403 SLOT(showStationDockWidget(bool)));
404 menuWindows->addAction(showStationDockAction);
405
406 QAction* showMshDockAction = mshDock->toggleViewAction();
407 showMshDockAction->setStatusTip(tr("Shows / hides the mesh view"));
408 connect(showMshDockAction, SIGNAL(triggered(bool)), this,
409 SLOT(showMshDockWidget(bool)));
410 menuWindows->addAction(showMshDockAction);
411
412 QAction* showModellingDockAction = modellingDock->toggleViewAction();
413 showModellingDockAction->setStatusTip(tr("Shows / hides the Process view"));
414 connect(showModellingDockAction, SIGNAL(triggered(bool)), this,
415 SLOT(showConditionDockWidget(bool)));
416 menuWindows->addAction(showModellingDockAction);
417
418 QAction* showVisDockAction = vtkVisDock->toggleViewAction();
419 showVisDockAction->setStatusTip(tr("Shows / hides the VTK Pipeline view"));
420 connect(showVisDockAction, SIGNAL(triggered(bool)), this,
421 SLOT(showVisDockWidget(bool)));
422 menuWindows->addAction(showVisDockAction);
423
424 // Presentation mode
425 auto* presentationMenu = new QMenu(this);
426 presentationMenu->setTitle("Presentation on");
427 connect(presentationMenu, SIGNAL(aboutToShow()), this,
428 SLOT(createPresentationMenu()));
429 menuWindows->insertMenu(showVisDockAction, presentationMenu);
430
431 _visPrefsDialog = std::make_unique<VisPrefsDialog>(*_vtkVisPipeline,
432 *visualizationWidget);
433}
434
435void MainWindow::closeEvent(QCloseEvent* event)
436{
438 QWidget::closeEvent(event);
439}
440
442{
443 if (show)
444 {
445 geoDock->show();
446 }
447 else
448 {
449 geoDock->hide();
450 }
451}
452
454{
455 if (show)
456 {
457 stationDock->show();
458 }
459 else
460 {
461 stationDock->hide();
462 }
463}
464
466{
467 if (show)
468 {
469 mshDock->show();
470 }
471 else
472 {
473 mshDock->hide();
474 }
475}
476
478{
479 if (show)
480 {
481 modellingDock->show();
482 }
483 else
484 {
485 modellingDock->hide();
486 }
487}
488
490{
491 if (show)
492 {
493 vtkVisDock->show();
494 }
495 else
496 {
497 vtkVisDock->hide();
498 }
499}
500
501void MainWindow::open(int file_type)
502{
503 QSettings settings;
504 auto t = static_cast<ImportFileType::type>(file_type);
505 QString type_str = QString::fromStdString(
507 QString fileName = QFileDialog::getOpenFileName(
508 this, "Select " + type_str + " file to import",
509 settings.value("lastOpenedFileDirectory").toString(),
510 QString::fromStdString(ImportFileType::getFileSuffixString(t)));
511 if (!fileName.isEmpty())
512 {
513 loadFile(t, fileName);
514 QDir dir = QDir(fileName);
515 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
516 }
517}
518
520{
521 auto* action = qobject_cast<QAction*>(sender());
522 if (action)
523 {
524 loadFile(ImportFileType::OGS, action->data().toString());
525 }
526}
527
529{
530 QString fileName = QFileDialog::getSaveFileName(
531 this,
532 "Save data as",
534 "GeoSys project (*.prj);;GMSH geometry files (*.geo)");
535
536 if (fileName.isEmpty())
537 {
538 OGSError::box("No filename specified.");
539 return;
540 }
541
542 QFileInfo fi(fileName);
544
545 if (fi.suffix().toLower() == "prj")
546 {
549 fileName.toStdString());
550 }
551 else if (fi.suffix().toLower() == "geo")
552 {
553 auto const selected_geometries =
555
556 // values necessary also for the adaptive meshing
557 const double point_density = 0;
558 const double station_density = point_density;
559 const int max_pnts_per_leaf = 0;
560
562 _project.getGEOObjects(), true,
564 station_density, max_pnts_per_leaf, selected_geometries, false,
565 false);
566 bool const success = BaseLib::IO::writeStringToFile(
567 gmsh_io.writeToString(), fileName.toStdString());
568
569 if (!success)
570 {
571 OGSError::box(" No geometry available\n to write to geo-file");
572 }
573 }
574}
575
576void MainWindow::loadFile(ImportFileType::type t, const QString& fileName)
577{
578 QFile file(fileName);
579 if (!file.exists())
580 {
581 QMessageBox::warning(this, tr("Application"),
582 tr("Cannot read file %1:\n%2.")
583 .arg(fileName)
584 .arg(file.errorString()));
585 return;
586 }
587
588 QApplication::setOverrideCursor(Qt::WaitCursor);
589 QFileInfo fi(fileName);
590 QSettings settings;
591 QDir dir = QDir(fileName);
592 std::string base =
593 fi.absoluteDir().absoluteFilePath(fi.completeBaseName()).toStdString();
594
597 {
598 if (fi.suffix().toLower() == "gli")
599 {
600 std::string unique_name;
601 std::vector<std::string> errors;
602 std::string const gmsh_path =
603 settings.value("DataExplorerGmshPath").toString().toStdString();
604 if (!FileIO::Legacy::readGLIFileV4(fileName.toStdString(),
606 unique_name, errors, gmsh_path))
607 {
608 for (auto& error : errors)
609 {
610 OGSError::box(QString::fromStdString(error));
611 }
612 }
613 }
614 else if (fi.suffix().toLower() == "prj")
615 {
617 if (xml.readFile(fileName))
618 {
619 _meshModel->updateModel();
620 _processModel->updateModel();
621 }
622 else
623 {
625 "Failed to load project file.\n Please see console for "
626 "details.");
627 }
628 }
629 else if (fi.suffix().toLower() == "gml")
630 {
632 try
633 {
634 if (!xml.readFile(fileName))
635 {
637 "Failed to load geometry.\n Please see console for "
638 "details.");
639 }
640 }
641 catch (std::runtime_error const& err)
642 {
643 OGSError::box(err.what(),
644 "Failed to read file `" + fileName + "'");
645 }
646 }
647 // OpenGeoSys observation station files (incl. boreholes)
648 else if (fi.suffix().toLower() == "stn")
649 {
651 if (!xml.readFile(fileName))
652 {
654 "Failed to load station data.\n Please see console for "
655 "details.");
656 }
657 }
658 // OpenGeoSys mesh files
659 else if (fi.suffix().toLower() == "msh" ||
660 fi.suffix().toLower() == "vtu" ||
661 fi.suffix().toLower() == "vtk")
662 {
663#ifndef NDEBUG
664 QElapsedTimer myTimer;
665 myTimer.start();
666#endif
667 std::unique_ptr<MeshLib::Mesh> mesh(
668 MeshLib::IO::readMeshFromFile(fileName.toStdString()));
669#ifndef NDEBUG
670 INFO("Mesh loading time: {:d} ms.", myTimer.restart());
671#endif
672 if (mesh)
673 {
674 _meshModel->addMesh(std::move(mesh));
675 }
676 else
677 {
678 OGSError::box("Failed to load mesh file.");
679 }
680#ifndef NDEBUG
681 INFO("Mesh model setup time: {:d} ms.", myTimer.elapsed());
682#endif
683 }
684
685 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
686 emit fileUsed(fileName);
687 }
688 else if (t == ImportFileType::FEFLOW)
689 {
690 if (fi.suffix().toLower() == "fem") // FEFLOW model files
691 {
692 FileIO::FEFLOWMeshInterface feflowMeshIO;
693 std::unique_ptr<MeshLib::Mesh> mesh(
694 feflowMeshIO.readFEFLOWFile(fileName.toStdString()));
695 if (mesh)
696 {
697 _meshModel->addMesh(std::move(mesh));
698 }
699 else
700 {
701 OGSError::box("Failed to load a FEFLOW mesh.");
702 }
703 FileIO::FEFLOWGeoInterface feflowGeoIO;
704 feflowGeoIO.readFEFLOWFile(fileName.toStdString(),
706 }
707 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
708 }
709 else if (t == ImportFileType::GMS)
710 {
711 if (fi.suffix().toLower() == "txt") // GMS borehole files
712 {
713 std::vector<GeoLib::Point*> boreholes;
714 std::string name = fi.baseName().toStdString();
715
717 fileName.toStdString()))
718 {
719 _project.getGEOObjects().addStationVec(std::move(boreholes),
720 name);
721 }
722 else
723 {
724 OGSError::box("Error reading GMS file.");
725 }
726 }
727 else if (fi.suffix().toLower() == "2dm" ||
728 fi.suffix().toLower() == "3dm") // GMS mesh files
729 {
730 std::string name = fileName.toStdString();
731 std::unique_ptr<MeshLib::Mesh> mesh(GMSInterface::readMesh(name));
732 if (mesh)
733 {
734 _meshModel->addMesh(std::move(mesh));
735 }
736 else
737 {
738 OGSError::box("Failed to load a GMS mesh.");
739 }
740 }
741 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
742 }
743 else if (t == ImportFileType::GMSH)
744 {
745 std::string msh_name(fileName.toStdString());
746 if (FileIO::GMSH::isGMSHMeshFile(msh_name))
747 {
748 std::unique_ptr<MeshLib::Mesh> mesh(FileIO::GMSH::readGMSHMesh(
749 msh_name, false /*is_created_with_gmsh2*/));
750 if (mesh)
751 {
752 _meshModel->addMesh(std::move(mesh));
753 }
754 else
755 {
756 OGSError::box("Failed to load a GMSH mesh.");
757 }
758 }
759 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
760 }
761 else if (t == ImportFileType::GOCAD_TSURF)
762 {
763 std::string file_name(fileName.toStdString());
764 std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
765 if (FileIO::Gocad::GocadAsciiReader::readFile(file_name, meshes))
766 {
767 for (auto& mesh : meshes)
768 {
769 if (mesh != nullptr)
770 {
771 _meshModel->addMesh(std::move(mesh));
772 }
773 }
774 }
775 else
776 {
777 OGSError::box("Error reading file.");
778 }
779 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
780 }
781#ifdef OGS_USE_NETCDF
782 else if (t == ImportFileType::NETCDF) // CH 01.2012
783 {
784 NetCdfConfigureDialog dlg(fileName.toStdString());
785 dlg.exec();
786 if (dlg.getMesh())
787 {
788 std::unique_ptr<MeshLib::Mesh> mesh(dlg.getMesh());
789 mesh->setName(dlg.getName());
790 _meshModel->addMesh(std::move(mesh));
791 }
792 if (dlg.getRaster())
793 _vtkVisPipeline->addPipelineItem(dlg.getRaster());
794
795 settings.setValue("lastOpenedRasterFileDirectory", dir.absolutePath());
796 }
797#endif // OGS_USE_NETCDF
798 else if (t == ImportFileType::RASTER)
799 {
801 if (geoImage->readImage(fileName))
802 {
803 _vtkVisPipeline->addPipelineItem(geoImage);
804 }
805 else
806 {
807 geoImage->Delete();
808 OGSError::box("Error reading raster.");
809 }
810 settings.setValue("lastOpenedRasterFileDirectory", dir.absolutePath());
811 }
812 else if (t == ImportFileType::POLYRASTER)
813 {
814 QImage raster;
815 vtkImageAlgorithm* img = VtkRaster::loadImage(fileName.toStdString());
817 double* origin = img->GetOutput()->GetOrigin();
818 bg->SetRaster(img, origin[0], origin[1],
819 img->GetOutput()->GetSpacing()[0]);
820 bg->SetName(fileName);
821 _vtkVisPipeline->addPipelineItem(bg);
822 settings.setValue("lastOpenedRasterFileDirectory", dir.absolutePath());
823 }
824 else if (t == ImportFileType::SHAPE)
825 {
826 SHPImportDialog dlg(
827 fileName.toStdString(), _project.getGEOObjects(),
828 settings.value("DataExplorerGmshPath").toString().toStdString());
829 dlg.exec();
830 QDir dir = QDir(fileName);
831 settings.setValue("lastOpenedShapeFileDirectory", dir.absolutePath());
832 }
833 else if (t == ImportFileType::TETGEN)
834 {
835 if (fi.suffix().toLower().compare("poly") == 0 ||
836 fi.suffix().toLower().compare("smesh") == 0)
837 {
839 tetgen.readTetGenGeometry(fileName.toStdString(),
841 }
842 else
843 {
844 settings.setValue("lastOpenedTetgenFileDirectory",
845 QFileInfo(fileName).absolutePath());
846 QString element_fname(fi.path() + "/" + fi.completeBaseName() +
847 ".ele");
848
849 if (!fileName.isEmpty())
850 {
852 std::unique_ptr<MeshLib::Mesh> mesh(tetgen.readTetGenMesh(
853 fileName.toStdString(), element_fname.toStdString()));
854 if (mesh)
855 {
856 _meshModel->addMesh(std::move(mesh));
857 }
858 else
859 {
860 OGSError::box("Failed to load a TetGen mesh.");
861 }
862 }
863 }
864 }
865 else if (t == ImportFileType::VTK)
866 {
867 _vtkVisPipeline->loadFromFile(fileName);
868 settings.setValue("lastOpenedVtkFileDirectory", dir.absolutePath());
869 }
870
871 QApplication::restoreOverrideCursor();
873}
874
876{
877 visualizationWidget->updateViewOnLoad();
878 geoTabWidget->treeView->updateView();
879 stationTabWidget->treeView->updateView();
880 meshTabWidget->treeView->updateView();
881}
882
884{
885 QSettings settings;
886
887 restoreGeometry(settings.value("windowGeometry").toByteArray());
888 restoreState(settings.value("windowState").toByteArray());
889}
890
892{
893 QSettings settings;
894
895 settings.setValue("windowGeometry", saveGeometry());
896 settings.setValue("windowState", saveState());
897}
898
900{
901 LicenseDialog dlg;
902 dlg.exec();
903}
904
906{
907 QString about(
908 "<a href='https://www.opengeosys.org'>www.opengeosys.org</a><br /><br "
909 "/>");
910 about.append(
911 QString("Version: %1<br />")
912 .arg(QString::fromStdString(GitInfoLib::GitInfo::ogs_version)));
913
914 about.append(
915 QString("Git commit: <a "
916 "href='https://github.com/ufz/ogs/commit/%1'>%1</a><br />")
917 .arg(QString::fromStdString(
919 about.append(QString("Built date: %1<br />")
920 .arg(QDate::currentDate().toString(Qt::ISODate)));
921
922 QMessageBox::about(this, "About OpenGeoSys 6", about);
923}
924
926{
927 QMenu* importFiles = new QMenu("&Import Files", this);
928 importFiles->addAction("&FEFLOW Files...",
929 [this] { open(ImportFileType::FEFLOW); });
930 importFiles->addAction("SMS/G&MS Files...",
931 [this] { open(ImportFileType::GMS); });
932 importFiles->addAction("&GMSH Files...",
933 [this] { open(ImportFileType::GMSH); });
934 importFiles->addAction("&Gocad TSurface...",
935 [this] { open(ImportFileType::GOCAD_TSURF); });
936#ifdef OGS_USE_NETCDF
937 importFiles->addAction("&NetCDF Files...",
938 [this] { open(ImportFileType::NETCDF); });
939#endif // OGS_USE_NETCDF
940 importFiles->addAction("&Petrel Files...", [this] { loadPetrelFiles(); });
941 importFiles->addAction("&Raster Files...",
942 [this] { open(ImportFileType::RASTER); });
943 importFiles->addAction("&Shape Files...",
944 [this] { open(ImportFileType::SHAPE); });
945 importFiles->addAction("&TetGen Files...",
946 [this] { open(ImportFileType::TETGEN); });
947 importFiles->addAction("&VTK Files...",
948 [this] { open(ImportFileType::VTK); });
949 return importFiles;
950}
951
953{
954 QSettings settings;
955 QStringList sfc_file_names = QFileDialog::getOpenFileNames(
956 this, "Select surface data file(s) to import", "", "Petrel files (*)");
957 QStringList well_path_file_names = QFileDialog::getOpenFileNames(
958 this, "Select well path data file(s) to import", "",
959 "Petrel files (*)");
960 if (!sfc_file_names.empty() || !well_path_file_names.empty())
961 {
962 QStringList::const_iterator it = sfc_file_names.begin();
963 std::list<std::string> sfc_files;
964 while (it != sfc_file_names.end())
965 {
966 sfc_files.push_back((*it).toStdString());
967 ++it;
968 }
969
970 it = well_path_file_names.begin();
971 std::list<std::string> well_path_files;
972 while (it != well_path_file_names.end())
973 {
974 well_path_files.push_back((*it).toStdString());
975 ++it;
976 }
977
978 std::string unique_str(*(sfc_files.begin()));
979
980 PetrelInterface(sfc_files, well_path_files, unique_str,
982
983 QDir dir = QDir(sfc_file_names.at(0));
984 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
985 }
986}
987
989{
990 VtkAddFilterDialog dlg(*_vtkVisPipeline, parentIndex);
991 dlg.exec();
992}
993
994void MainWindow::writeGeometryToFile(QString gliName, QString fileName)
995{
996#ifndef NDEBUG
997 QFileInfo fi(fileName);
998 if (fi.suffix().toLower() == "gli")
999 {
1000 FileIO::Legacy::writeAllDataToGLIFileV4(fileName.toStdString(),
1002 return;
1003 }
1004#endif
1006 xml.export_name = gliName.toStdString();
1007 BaseLib::IO::writeStringToFile(xml.writeToString(), fileName.toStdString());
1008}
1009
1010void MainWindow::writeStationListToFile(QString listName, QString fileName)
1011{
1013 xml.export_name = listName.toStdString();
1014 BaseLib::IO::writeStringToFile(xml.writeToString(), fileName.toStdString());
1015}
1016
1017void MainWindow::mapGeometry(const std::string& geo_name)
1018{
1020 if (dlg.exec() != QDialog::Accepted)
1021 {
1022 return;
1023 }
1024
1025 int choice(dlg.getDataSetChoice());
1026
1027 QString file_name("");
1028 if (choice < 2) // load something from a file
1029 {
1030 QString file_type[2] = {"OpenGeoSys mesh files (*.vtu *.msh)",
1031 "Raster files(*.asc *.grd *.xyz)"};
1032 QSettings settings;
1033 file_name = QFileDialog::getOpenFileName(
1034 this,
1035 "Select file for mapping",
1036 settings.value("lastOpenedFileDirectory").toString(),
1037 file_type[choice]);
1038 if (file_name.isEmpty())
1039 {
1040 return;
1041 }
1042 QDir dir = QDir(file_name);
1043 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
1044 }
1045
1046 MeshGeoToolsLib::GeoMapper geo_mapper(_project.getGEOObjects(), geo_name);
1047 QFileInfo fi(file_name);
1048 if (choice == 1) // load raster from file
1049 {
1050 if (fi.suffix().toLower() == "asc" || fi.suffix().toLower() == "grd")
1051 {
1052 std::unique_ptr<GeoLib::Raster> raster(
1054 file_name.toStdString()));
1055 if (raster)
1056 {
1057 geo_mapper.mapOnDEM(std::move(raster));
1058 }
1059 else
1060 {
1061 OGSError::box("Error reading raster file.");
1062 }
1063 _geo_model->updateGeometry(geo_name);
1064 }
1065 else
1066 {
1067 OGSError::box("The selected file is no supported raster file.");
1068 }
1069 return;
1070 }
1071
1072 MeshLib::Mesh* mesh(nullptr);
1073 if (choice == 0) // load mesh from file
1074 {
1075 if (fi.suffix().toLower() == "vtu" || fi.suffix().toLower() == "vtk" ||
1076 fi.suffix().toLower() == "msh")
1077 {
1078 mesh = MeshLib::IO::readMeshFromFile(file_name.toStdString());
1079 }
1080 else
1081 {
1082 OGSError::box("The selected file is no supported mesh file.");
1083 return;
1084 }
1085 }
1086 else
1087 { // use mesh from ProjectData
1088 mesh = _project.getMeshObjects()[choice - 2].get();
1089 }
1090
1091 std::string new_geo_name = dlg.getNewGeoName();
1092
1093 if (new_geo_name.empty())
1094 {
1095 geo_mapper.mapOnMesh(mesh);
1096 _geo_model->updateGeometry(geo_name);
1097 }
1098 else
1099 {
1101 new_geo_name);
1102 new_geo_name = dup.getFinalizedOutputName();
1104 new_geo_name);
1105 mapper.advancedMapOnMesh(*mesh);
1106 _geo_model->updateGeometry(new_geo_name);
1107 }
1108 if (choice == 0)
1109 {
1110 delete mesh;
1111 }
1112}
1113
1118
1119void MainWindow::exportBoreholesToGMS(std::string listName,
1120 std::string fileName)
1121{
1122 const std::vector<GeoLib::Point*>* stations(
1124 GMSInterface::writeBoreholesToGMS(stations, fileName);
1125}
1126
1127void MainWindow::callGMSH(std::vector<std::string>& selectedGeometries,
1128 unsigned param1, double param2, double param3,
1129 double param4, bool delete_geo_file)
1130{
1131 if (!selectedGeometries.empty())
1132 {
1133 INFO("Start meshing ...");
1134
1135 QString fileName("");
1136 QString dir_str = this->getLastUsedDir();
1137
1138 if (!delete_geo_file)
1139 {
1140 fileName = QFileDialog::getSaveFileName(
1141 this, "Save GMSH-file as",
1142 LastSavedFileDirectory::getDir() + "tmp_gmsh.geo",
1143 "GMSH geometry files (*.geo)");
1144 }
1145 else
1146 {
1147 fileName = "tmp_gmsh.geo";
1148 }
1149
1150 if (!fileName.isEmpty())
1151 {
1152 try
1153 {
1154 if (param4 == -1)
1155 { // adaptive meshing selected
1157 _project.getGEOObjects(), true,
1159 param2, param3, param1, selectedGeometries, false,
1160 false);
1162 fileName.toStdString());
1163 }
1164 else
1165 { // homogeneous meshing selected
1167 _project.getGEOObjects(), true,
1169 param4, param3, param1, selectedGeometries, false,
1170 false);
1172 fileName.toStdString());
1173 }
1174
1175 if (system(nullptr) != 0) // command processor available
1176 {
1177 QSettings settings;
1178 std::string gmsh_path =
1179 settings.value("DataExplorerGmshPath")
1180 .toString()
1181 .toStdString();
1182
1183 if (!gmsh_path.empty())
1184 {
1185 std::string fname(fileName.toStdString());
1186 std::string gmsh_command =
1187 "\"" + gmsh_path + "\" -2 -algo meshadapt " + fname;
1188 std::size_t pos(fname.rfind("."));
1189 if (pos != std::string::npos)
1190 {
1191 fname = fname.substr(0, pos);
1192 }
1193 gmsh_command += " -o " + fname + ".msh";
1194 // Newer gmsh versions write a newer file format for
1195 // meshes per default. At the moment we can't read this
1196 // new format. This is a switch for gmsh to write the
1197 // 'old' file format.
1198 gmsh_command += " -format msh22";
1199 auto const return_value =
1200 std::system(gmsh_command.c_str());
1201 if (return_value != 0)
1202 {
1203 QString const message =
1204 "Execution of gmsh command returned non-zero "
1205 "status, " +
1206 QString::number(return_value);
1207 OGSError::box(message, "Error");
1208 }
1209 else
1210 {
1212 fileName.left(fileName.length() - 3)
1213 .append("msh"));
1214 }
1215 }
1216 else
1217 {
1218 OGSError::box("Location of GMSH not specified.",
1219 "Error");
1220 }
1221 }
1222 else
1223 {
1225 "Error executing command gmsh - no command processor "
1226 "available",
1227 "Error");
1228 }
1229 }
1230 catch (std::runtime_error& error)
1231 {
1232 OGSError::box(QString(error.what()) +
1233 QString("\n Please cleanup the input data."),
1234 "ERROR");
1235 }
1236 if (delete_geo_file)
1237 {
1238 BaseLib::removeFile(fileName.toStdString());
1239 }
1240 }
1241 }
1242 else
1243 INFO("No geometry information selected.");
1244 QApplication::restoreOverrideCursor();
1245}
1246
1248{
1249 QSettings settings;
1250 auto* dlg = new OGSFileConverter(
1251 settings.value("DataExplorerGmshPath").toString().toStdString(), this);
1252 dlg->setAttribute(Qt::WA_DeleteOnClose);
1253 dlg->show();
1254 dlg->raise();
1255}
1256
1258{
1259 QString listName;
1260 GeoLib::Station* stn =
1261 _geo_model->getStationModel()->stationFromIndex(index, listName);
1262
1263 if (dynamic_cast<GeoLib::StationBorehole*>(stn))
1264 {
1265 OGSError::box("No time series data available for borehole.");
1266 }
1267 else if (dynamic_cast<GeoLib::Station*>(stn) && stn->getSensorData())
1268 {
1269 auto* prefs(new DiagramPrefsDialog(stn));
1270 prefs->setAttribute(Qt::WA_DeleteOnClose);
1271 prefs->show();
1272 }
1273}
1274
1276{
1277 QSettings settings;
1278 QString fileName = QFileDialog::getOpenFileName(
1279 this, "Select data file to open",
1280 settings.value("lastOpenedFileDirectory").toString(),
1281 "Text files (*.txt);;All files (* *.*)");
1282 if (!fileName.isEmpty())
1283 {
1284 QDir dir = QDir(fileName);
1285 settings.setValue("lastOpenedFileDirectory", dir.absolutePath());
1286 auto* prefs = new DiagramPrefsDialog(fileName);
1287 prefs->setAttribute(Qt::WA_DeleteOnClose);
1288 prefs->show();
1289 }
1290}
1291
1292void MainWindow::showGeoNameDialog(const std::string& geometry_name,
1293 const GeoLib::GEOTYPE object_type,
1294 std::size_t id)
1295{
1296 std::string old_name = _project.getGEOObjects().getElementNameByID(
1297 geometry_name, object_type, id);
1298 SetNameDialog dlg(GeoLib::convertGeoTypeToString(object_type), id,
1299 old_name);
1300 if (dlg.exec() != QDialog::Accepted)
1301 {
1302 return;
1303 }
1304
1305 _geo_model->addNameForElement(geometry_name, object_type, id,
1306 dlg.getNewName());
1307 static_cast<GeoTreeModel*>(this->geoTabWidget->treeView->model())
1308 ->setNameForItem(geometry_name, object_type, id,
1310 geometry_name, object_type, id));
1311}
1312
1313void MainWindow::showStationNameDialog(const std::string& stn_vec_name,
1314 std::size_t id)
1315{
1316 std::vector<GeoLib::Point*> const* stations =
1317 _project.getGEOObjects().getStationVec(stn_vec_name);
1318 auto* const stn = static_cast<GeoLib::Station*>((*stations)[id]);
1319 SetNameDialog dlg("Station", id, stn->getName());
1320 if (dlg.exec() != QDialog::Accepted)
1321 {
1322 return;
1323 }
1324
1325 stn->setName(dlg.getNewName());
1326 static_cast<StationTreeModel*>(this->stationTabWidget->treeView->model())
1327 ->setNameForItem(stn_vec_name, id, stn->getName());
1328}
1329
1331{
1333 connect(&dlg, SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(),
1334 SLOT(addMesh(MeshLib::Mesh*)));
1335 dlg.exec();
1336}
1337
1339{
1341 connect(&dlg, SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(),
1342 SLOT(addMesh(MeshLib::Mesh*)));
1343 dlg.exec();
1344}
1345
1347{
1348 auto* dlg = new MeshAnalysisDialog(this->_project.getMeshObjects());
1349 dlg->exec();
1350}
1351
1353{
1354 auto dlg = TranslateDataDialog(_meshModel.get(), _geo_model.get());
1355 dlg.exec();
1356}
1357
1359{
1360 if (_meshModel == nullptr)
1361 {
1362 OGSError::box("The given mesh model does not exist.");
1363 }
1364
1365 auto dlg = Layers2GridDialog(*_meshModel);
1366 dlg.exec();
1367}
1368
1370{
1371 if (_meshModel == nullptr)
1372 {
1373 OGSError::box("The given mesh model does not exist.");
1374 }
1375 AddFaultsToVoxelGridDialog(*_meshModel).exec();
1376}
1377
1379{
1380 if (_meshModel == nullptr)
1381 {
1382 OGSError::box("The given mesh model does not exist.");
1383 }
1384 auto dlg = Vtu2GridDialog(*_meshModel);
1385 dlg.exec();
1386}
1387
1388void MainWindow::convertPointsToStations(std::string const& geo_name)
1389{
1390 std::string stn_name = geo_name + " Stations";
1392 stn_name);
1393 if (ret == 1)
1394 {
1395 OGSError::box("No points found to convert.");
1396 }
1397}
1398
1399void MainWindow::showLineEditDialog(const std::string& geoName)
1400{
1401 LineEditDialog lineEdit(
1403 connect(
1404 &lineEdit,
1405 SIGNAL(connectPolylines(const std::string&, std::vector<std::size_t>,
1406 double, std::string, bool, bool)),
1407 _geo_model.get(),
1408 SLOT(connectPolylineSegments(const std::string&,
1409 std::vector<std::size_t>, double,
1410 std::string, bool, bool)));
1411 lineEdit.exec();
1412}
1413
1415{
1417 connect(&dlg,
1418 SIGNAL(requestMeshing(std::vector<std::string>&, unsigned, double,
1419 double, double, bool)),
1420 this,
1421 SLOT(callGMSH(std::vector<std::string>&, unsigned, double, double,
1422 double, bool)));
1423 dlg.exec();
1424}
1425
1427{
1429 if (dlg.exec() != QDialog::Accepted)
1430 {
1431 return;
1432 }
1433 std::string name(dlg.getGeometryName());
1435 name) < 0)
1436 {
1437 OGSError::box("Points are missing for\n at least one geometry.");
1438 }
1439}
1440
1443{
1444 if (mshSource == nullptr)
1445 {
1446 return;
1447 }
1448
1450 if (dlg.exec() != QDialog::Accepted)
1451 {
1452 return;
1453 }
1455 MeshToolsLib::ElementQualityInterface quality_interface(
1456 *mshSource->GetMesh(), type);
1457 _vtkVisPipeline->showMeshElementQuality(
1458 mshSource, type, quality_interface.getQualityVector());
1459
1460 if (dlg.getHistogram())
1461 {
1462 quality_interface.writeHistogram(dlg.getHistogramPath());
1463 }
1464}
1465
1470
1476
1478
1480{
1481 this->show();
1482}
1483
1485{
1486 this->hide();
1487}
1488
1489void MainWindow::loadFileOnStartUp(const QString& fileName)
1490{
1491 QString ext = QFileInfo(fileName).suffix();
1492 if (ext == "msh" || ext == "vtu" || ext == "gli" || ext == "gml")
1493 {
1494 this->loadFile(ImportFileType::OGS, fileName);
1495 }
1496}
1497
1498void MainWindow::on_actionExportVTK_triggered(bool checked /*= false*/)
1499{
1500 Q_UNUSED(checked)
1501 QSettings settings;
1502 int count = 0;
1503 QString const filename = QFileDialog::getSaveFileName(
1504 this,
1505 "Export object to vtk-files",
1506 settings.value("lastExportedFileDirectory").toString(),
1507 "VTK files (*.vtp *.vtu)");
1508 if (!filename.isEmpty())
1509 {
1510 QDir const dir = QDir(filename);
1511 settings.setValue("lastExportedFileDirectory", dir.absolutePath());
1512
1513 std::string const basename =
1514 QFileInfo(filename).path().toStdString() + "/" +
1515 QFileInfo(filename).baseName().toStdString();
1517 ++it;
1518 while (*it)
1519 {
1520 std::string const name = basename + std::to_string(++count) + "-" +
1521 (*it)->data(0).toString().toStdString();
1522 static_cast<VtkVisPipelineItem*>(*it)->writeToFile(name);
1523 ++it;
1524 }
1525 }
1526}
1527
1529{
1530 Q_UNUSED(checked)
1531 QSettings settings;
1532 QString fileName = QFileDialog::getSaveFileName(
1533 this, "Save scene to VRML file",
1534 settings.value("lastExportedFileDirectory").toString(),
1535 "VRML files (*.wrl);;");
1536 if (!fileName.isEmpty())
1537 {
1538 QDir dir = QDir(fileName);
1539 settings.setValue("lastExportedFileDirectory", dir.absolutePath());
1540
1541 vtkVRMLExporter* exporter = vtkVRMLExporter::New();
1542 exporter->SetFileName(fileName.toStdString().c_str());
1543 exporter->SetRenderWindow(
1544 visualizationWidget->vtkWidget->renderWindow());
1545 exporter->Write();
1546 exporter->Delete();
1547 }
1548}
1549
1550void MainWindow::on_actionExportObj_triggered(bool checked /*= false*/)
1551{
1552 Q_UNUSED(checked)
1553 QSettings settings;
1554 QString fileName = QFileDialog::getSaveFileName(
1555 this, "Save scene to Wavefront OBJ files",
1556 settings.value("lastExportedFileDirectory").toString(), ";;");
1557 if (!fileName.isEmpty())
1558 {
1559 QDir dir = QDir(fileName);
1560 settings.setValue("lastExportedFileDirectory", dir.absolutePath());
1561
1562 vtkOBJExporter* exporter = vtkOBJExporter::New();
1563 exporter->SetFilePrefix(fileName.toStdString().c_str());
1564 exporter->SetRenderWindow(
1565 visualizationWidget->vtkWidget->renderWindow());
1566 exporter->Write();
1567 exporter->Delete();
1568 }
1569}
1570
1572{
1573 auto* menu = static_cast<QMenu*>(QObject::sender());
1574 menu->clear();
1575 if (!_vtkWidget->parent())
1576 {
1577 QAction* action = new QAction("Quit presentation mode", menu);
1578 connect(action, SIGNAL(triggered()), this,
1579 SLOT(quitPresentationMode()));
1580 action->setShortcutContext(Qt::WidgetShortcut);
1581 action->setShortcut(QKeySequence(Qt::Key_Escape));
1582 menu->addAction(action);
1583 }
1584 else
1585 {
1586 int count = 0;
1587 const int currentScreen =
1588 QApplication::desktop()->screenNumber(visualizationWidget);
1589 foreach (QRect screenGeo, _screenGeometries)
1590 {
1591 Q_UNUSED(screenGeo);
1592 QAction* action =
1593 new QAction(QString("On screen %1").arg(count), menu);
1594 connect(action, SIGNAL(triggered()), this,
1595 SLOT(startPresentationMode()));
1596 if (count == currentScreen)
1597 {
1598 action->setEnabled(false);
1599 }
1600 menu->addAction(action);
1601 ++count;
1602 }
1603 }
1604}
1605
1607{
1608 // Save the QMainWindow state to restore when quitting presentation mode
1609 _windowState = this->saveState();
1610
1611 // Get the screen number from the QAction which sent the signal
1612 QString actionText = static_cast<QAction*>(QObject::sender())->text();
1613 int screen = actionText.split(" ").back().toInt();
1614
1615 // Move the widget to the screen and maximize it
1616 // Real fullscreen hides the menu
1617 _vtkWidget->setParent(nullptr, Qt::Window);
1618 _vtkWidget->move(
1619 QPoint(_screenGeometries[screen].x(), _screenGeometries[screen].y()));
1620 //_vtkWidget->showFullScreen();
1621 _vtkWidget->showMaximized();
1622
1623 // Create an action which quits the presentation mode when pressing
1624 // ESCAPE when the the window has focus
1625 QAction* action = new QAction("Quit presentation mode", this);
1626 connect(action, SIGNAL(triggered()), this, SLOT(quitPresentationMode()));
1627 action->setShortcutContext(Qt::WidgetShortcut);
1628 action->setShortcut(QKeySequence(Qt::Key_Escape));
1629 _vtkWidget->addAction(action);
1630
1631 // Hide the central widget to maximize the dock widgets
1632 QMainWindow::centralWidget()->hide();
1633}
1634
1636{
1637 // Remove the quit action
1638 QAction* action = _vtkWidget->actions().back();
1639 _vtkWidget->removeAction(action);
1640 delete action;
1641
1642 // Add the widget back to visualization widget
1643 visualizationWidget->layout()->addWidget(_vtkWidget.get());
1644
1645 QMainWindow::centralWidget()->show();
1646
1647 // Restore the previously saved QMainWindow state
1648 this->restoreState(_windowState);
1649}
1650
1652{
1653 QSettings settings;
1654 QString fileName("");
1655 QStringList files = settings.value("recentFileList").toStringList();
1656 if (!files.empty())
1657 {
1658 return QFileInfo(files[0]).absolutePath();
1659 }
1660
1661 return QDir::homePath();
1662}
Definition of the AddFaultsToVoxelGridDialog class.
Definition of the AsciiRasterInterface class.
Definition of the CreateStructuredGridDialog class.
Definition of the DataExplorerSettingsDialog class.
Definition of the DiagramPrefsDialog class.
Definition of the ElementQualityInterface class.
Definition of the Element class.
Filename manipulation routines.
Definition of the GMSHPrefsDialog class.
Definition of the GMSInterface class.
Definition of the GeoMapper class.
Definition of the GeoOnMeshMappingDialog class.
Definition of the GeoTreeModel class.
Git information.
Implementation of Histogram class.
Manages the last directory used for saving a file.
Definition of the Layers2GridDialog class.
Definition of the LicenseDialog class.
Definition of the LineEditDialog class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the MergeGeometriesDialog class.
Definition of the MeshAnalysisDialog class.
Definition of the MeshElementRemovalDialog class.
Definition of the MeshIO class.
Definition of the MshQualitySelectionDialog class.
Definition of the MeshSurfaceExtraction class.
Definition of the Mesh class.
Definition of the Node class.
Definition of the OGSError class.
Definition of OGSFileConverter class.
Definition of the OGSIOVer4 class.
Definition of the PetrelInterface class.
Definition of the GeoLib::Raster class.
Definition of the RecentFiles class.
Definition of the SHPImportDialog class.
Definition of the SetNameDialog class.
Definition of the StationTreeModel class.
Definition of the TetGenInterface class.
Definition of the TranslateDataDialog class.
Definition of the TreeModelIterator class.
Definition of the VtkAddFilterDialog class.
Definition of the VtkBGImageSource class.
Definition of the VtkGeoImageSource class.
VtkMappedMeshSource is a source class to transform OGS meshes into complete vtkUnstructuredGrids....
Definition of the VtkRaster class.
Definition of the VtkVisPipelineItem class.
Definition of the Vtu2GridDialog class.
Definition of the XmlGmlInterface class.
Definition of the XmlStnInterface class.
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:31
A dialog window for managing general Data Explorer settings.
A dialog window for managing general Data Explorer settings.
Base class for boundary conditions, initial conditions and source terms.
const std::vector< std::unique_ptr< MeshLib::Mesh > > & getMeshObjects() const
Returns all the meshes with their respective names.
Definition Project.h:57
GeoLib::GEOObjects & getGEOObjects()
Returns the GEOObjects containing all points, polylines and surfaces.
Definition Project.h:46
A dialog that allows for setting preferences for a requested diagram.
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
void readFEFLOWFile(const std::string &filename, GeoLib::GEOObjects &geo_objects)
MeshLib::Mesh * readFEFLOWFile(const std::string &filename)
Reads and writes GMSH-files to and from OGS data structures.
static int readBoreholesFromGMS(std::vector< GeoLib::Point * > &boreholes, const std::string &filename)
Imports borehole data from a file in GMS-format.
static MeshLib::Mesh * readMesh(const std::string &filename)
Reads a GMS *.3dm file and converts it to an CFEMesh.
static void writeBoreholesToGMS(const std::vector< GeoLib::Point * > *stations, const std::string &filename)
MeshLib::Mesh * readTetGenMesh(std::string const &nodes_fname, std::string const &ele_fname)
bool readTetGenGeometry(std::string const &geo_fname, GeoLib::GEOObjects &geo_objects)
int readFile(const QString &fileName) override
Reads an xml-file containing a project.
A dialog window for setting preferences for GMSH.
std::string const & getFinalizedOutputName() const
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
void addStationVec(std::vector< Point * > &&stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
const PolylineVec * getPolylineVecObj(const std::string &name) const
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
std::string getElementNameByID(const std::string &geometry_name, GeoLib::GEOTYPE type, std::size_t id) const
Reads and writes GeoObjects to and from XML files.
int readFile(const QString &fileName) override
Reads an xml-file containing geometric object definitions into the GEOObjects used in the constructor...
Reads and writes Observation Sites to and from XML files.
int readFile(const QString &fileName) override
Reads an xml-file containing station object definitions into the GEOObjects used in the constructor (...
A borehole as a geometric object.
A Station (observation site) is basically a Point with some additional information.
Definition Station.h:37
const SensorData * getSensorData() const
Returns all the sensor data for this observation site.
Definition Station.h:89
A dialog window for creating DIRECT boundary conditions from raster files.
std::string const & getNewGeoName() const
A model for the GeoTreeView implementing a tree as a double-linked list.
static std::string getFileSuffixString(ImportFileType::type t)
static std::string convertImportFileTypeToString(ImportFileType::type t)
static void setDir(const QString &path)
Sets the directory last used for saving a file.
static const QString getDir()
Returns the directory last used for saving a file.
A dialog window displaying the OGS license information.
A dialog window for manipulation of polylines. Currently included functionality is the concatenation ...
void showConditionDockWidget(bool show)
void closeEvent(QCloseEvent *event) override
void readSettings()
std::unique_ptr< MeshModel > _meshModel
Definition mainwindow.h:134
void callGMSH(std::vector< std::string > &selectedGeometries, unsigned param1, double param2, double param3, double param4, bool delete_geo_file)
Function calls for generating GMSH files from the GUI.
void open(int file_type=0)
Function calls for opening files.
void FEMTestStart()
Testing functionality for connection to FEM lib.
QMenu * createImportFilesMenu()
void showGMSHPrefsDialog()
void quitPresentationMode()
void loadFile(ImportFileType::type t, const QString &fileName)
void on_actionExportObj_triggered(bool checked=false)
void showFileConverter()
Calls the OGSFileConverter as an external tool.
std::unique_ptr< ElementTreeModel > _elementModel
Definition mainwindow.h:135
void showStationNameDialog(const std::string &stn_vec_name, std::size_t id)
Allows setting the name for a station.
void save()
Function calls for saving files.
void writeStationListToFile(QString listName, QString fileName)
void loadFileOnStartUp(const QString &fileName)
void showGeoDockWidget(bool show)
void showLayers2GridDialog()
void writeSettings()
void showGeoNameDialog(const std::string &geometry_name, const GeoLib::GEOTYPE object_type, std::size_t id)
Allows setting the name for a geometric object.
void showLineEditDialog(const std::string &geoName)
void showStationDockWidget(bool show)
std::unique_ptr< VisPrefsDialog > _visPrefsDialog
Definition mainwindow.h:143
void showLicense()
void convertMeshToGeometry(const MeshLib::Mesh *mesh)
void showDiagramPrefsDialog()
Calls the diagram prefs dialog from the Tools menu.
void showMshDockWidget(bool show)
QString getLastUsedDir()
void showMeshAnalysisDialog()
void showAddPipelineFilterItemDialog(QModelIndex parentIndex)
void showCreateStructuredGridDialog()
Creates a structured grid with user-specified parameters.
void ShowWindow()
void showMergeGeometriesDialog()
void showVisDockWidget(bool show)
void showMeshElementRemovalDialog()
Removal of mesh elements based on a number of criteria.
std::unique_ptr< ProcessModel > _processModel
Definition mainwindow.h:136
void showTranslateDataDialog()
void on_actionExportVRML2_triggered(bool checked=false)
void createPresentationMenu()
void openRecentFile()
DataHolderLib::Project _project
Definition mainwindow.h:133
void writeGeometryToFile(QString gliName, QString fileName)
MainWindow(QWidget *parent=nullptr)
std::unique_ptr< GEOModels > _geo_model
Definition mainwindow.h:145
void startPresentationMode()
std::unique_ptr< VtkVisPipeline > _vtkVisPipeline
Definition mainwindow.h:138
void HideWindow()
void loadPetrelFiles()
void on_actionExportVTK_triggered(bool checked=false)
void showAddFaultsToVoxelGridDialog()
void showVisalizationPrefsDialog()
std::unique_ptr< QWidget > _vtkWidget
Definition mainwindow.h:140
void showVtu2GridDialog()
void mapGeometry(const std::string &geo_name)
void showMeshQualitySelectionDialog(MeshLib::VtkMappedMeshSource *mshSource)
QList< QRect > _screenGeometries
Definition mainwindow.h:139
void fileUsed(QString filename)
QByteArray _windowState
Definition mainwindow.h:141
std::unique_ptr< FemConditionModel > _conditionModel
Definition mainwindow.h:137
void updateDataViews()
void showDataExplorerSettingsDialog()
void convertPointsToStations(std::string const &geo_name)
void exportBoreholesToGMS(std::string listName, std::string fileName)
Function calls for GMS export.
A dialog window for setting preferences for GMSH.
std::string getGeometryName() const
Returns the name of the new merged geometry.
std::vector< std::string > getSelectedGeometries() const
Returns a vector of selected geometries.
A dialog window for calling mesh analysis methods.
A dialog window for settung up a database connection.
A set of tools for mapping the elevation of geometric objects.
Definition GeoMapper.h:40
void mapOnDEM(std::unique_ptr< GeoLib::Raster const > raster)
Maps geometry based on a raster file.
Definition GeoMapper.cpp:52
void mapOnMesh(MeshLib::Mesh const *const mesh)
Definition GeoMapper.cpp:73
void advancedMapOnMesh(MeshLib::Mesh const &mesh)
const MeshLib::Mesh * GetMesh() const
Returns the mesh.
A dialog for selecting a mesh quality metric.
std::string getHistogramPath() const
Returns selected path for histogram (or empty string if no histogram is required)
bool getHistogram() const
Returns true if a histogram needs to be calculated.
MeshLib::MeshQualityType getSelectedMetric() const
Returns selected metric.
int writeHistogram(std::string const &file_name, std::size_t n_bins=0) const
Writes a histogram of the quality vector to a specified file.
std::vector< double > const getQualityVector() const
Returns the vector containing a quality measure for each element.
The dialog for converting data from NetCDF-files into OGS data structures. While NetCDF files can inc...
VtkGeoImageSource * getRaster()
static void box(const QString &e)
Definition OGSError.cpp:23
QMenu * menu()
Returns the created menu. Add this menu to your QMainWindow menu.
Dialog for selecting which information should be loaded from a shape file.
Small dialog for setting a name for an object.
std::string getNewName()
A model for the StationTreeView implementing a tree as a double-linked list.
A dialog window for calling translation methods.
TreeModelIterator provides a way to iterate over TreeItems in a TreeModel. Usage:
Dialog for selecting a filter to be applied to a VtkPipelineItem. The dialog lets you select filters ...
void SetName(QString name)
Sets the name.
Uses an image source to create a plane in the 3D with the given image texture mapped on it.
void SetRaster(vtkImageAlgorithm *img, double x0, double y0, double scalingFactor)
Sets the raster/image to be used as a texture map.
static VtkBGImageSource * New()
Create new objects with New() because of VTKs object reference counting.
The VtkVisPipeline source object of a geo-referenced image (file).
static VtkGeoImageSource * New()
Create new objects with New() because of VTKs reference counting.
bool readImage(const QString &filename)
Reads an image from file.
static vtkImageAlgorithm * loadImage(const std::string &fileName)
Loads an image- or raster-file into an vtkImageAlgorithm-Object.
Definition VtkRaster.cpp:43
An item in the VtkVisPipeline containing a graphic object to be visualized.
int writeToFile(const std::string &filename) const
Writes this algorithm's vtkDataSet (i.e. vtkPolyData or vtkUnstructuredGrid) to a vtk-file.
Definition of mesh to geometry conversion.
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:45
void removeFile(std::string const &filename)
@ AdaptiveMeshDensity
computing the mesh density employing a QuadTree
@ FixedMeshDensity
set the parameter with a fixed value
MeshLib::Mesh * readGMSHMesh(std::string const &fname, bool const is_created_with_gmsh2)
bool isGMSHMeshFile(const std::string &fname)
bool readFile(std::string const &file_name, std::vector< std::unique_ptr< MeshLib::Mesh > > &meshes, DataType const export_type)
Reads the specified file and writes data into internal mesh vector.
bool readGLIFileV4(const std::string &fname, GeoLib::GEOObjects &geo, std::string &unique_name, std::vector< std::string > &errors, std::string const &gmsh_path)
void writeAllDataToGLIFileV4(const std::string &fname, const GeoLib::GEOObjects &geo)
std::string convertGeoTypeToString(GEOTYPE geo_type)
Definition GeoType.cpp:23
int geoPointsToStations(GEOObjects &geo_objects, std::string const &geo_name, std::string &stn_name, bool const only_unused_pnts)
Constructs a station-vector based on the points of a given geometry.
GEOTYPE
Definition GeoType.h:23
GITINFOLIB_EXPORT const std::string git_version_sha1_short
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
MeshQualityType
Describes a mesh quality metric.
Definition MeshEnums.h:70
bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects, double const eps)
Definition of readMeshFromFile function.