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