OGS
SaveMeshDialog.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 "SaveMeshDialog.h"
5
6#include <QFileDialog>
7#include <QSettings>
8
10#include "Base/OGSError.h"
13#include "MeshLib/Mesh.h"
14
15SaveMeshDialog::SaveMeshDialog(MeshLib::Mesh const& mesh, QDialog* parent)
16 : QDialog(parent), _mesh(mesh)
17{
18 setupUi(this);
19 this->fileNameEdit->setText(LastSavedFileDirectory::getDir() +
20 QString::fromStdString(_mesh.getName()) +
21 ".vtu");
22}
23
25{
26 QString file_type("VTK Unstructured Grid (*.vtu)");
27#ifndef NDEBUG
28 file_type.append(";;Legacy geometry file (*.msh)");
29#endif // DEBUG
30 QSettings settings;
31 QString const file_name = QFileDialog::getSaveFileName(
32 this,
33 "Save mesh as...",
35 QString::fromStdString(_mesh.getName()),
36 file_type);
37
38 if (!file_name.isEmpty())
39 {
40 this->fileNameEdit->setText(file_name);
41 }
42}
43
45{
46 // Disable compression on Ascii
47 if (index == 0)
48 {
49 this->compressionCheckBox->setChecked(false);
50 this->compressionCheckBox->setEnabled(false);
51 this->compressionLabel->setEnabled(false);
52 }
53 else
54 {
55 this->compressionCheckBox->setEnabled(true);
56 this->compressionLabel->setEnabled(true);
57 }
58}
59
61{
62 QString const& file_name(this->fileNameEdit->text());
63 if (file_name.isEmpty())
64 {
65 OGSError::box("No file name entered.");
66 return;
67 }
68
69 QFileInfo fi(file_name);
70 if (fi.suffix().toLower() == "vtu")
71 {
72 int dataMode = this->dataModeBox->currentIndex();
73 bool compress(this->compressionCheckBox->isChecked());
74 MeshLib::IO::VtuInterface vtkIO(&_mesh, dataMode, compress);
75 vtkIO.writeToFile(file_name.toStdString());
76 }
77 if (fi.suffix().toLower() == "msh")
78 {
80 meshIO.setMesh(&_mesh);
82 file_name.toStdString());
83 }
85
86 this->done(QDialog::Accepted);
87}
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:20
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.
Interface for handling mesh files from OGS-5 and below. (*.msh files)
Definition MeshIO.h:26
void setMesh(const MeshLib::Mesh *mesh)
Set mesh for writing.
Definition MeshIO.cpp:427
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
static void box(const QString &e)
Definition OGSError.cpp:13
void accept() override
Instructions if the OK-Button has been pressed.
void on_dataModeBox_currentIndexChanged(int index)
void on_selectDirButton_clicked()
Selection of path to save file.
SaveMeshDialog(MeshLib::Mesh const &mesh, QDialog *parent=nullptr)
MeshLib::Mesh const & _mesh
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:34