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