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