OGS
SaveMeshDialog.cpp
Go to the documentation of this file.
1
15#include "SaveMeshDialog.h"
16
17#include <QFileDialog>
18#include <QSettings>
19
21#include "Base/OGSError.h"
24#include "MeshLib/Mesh.h"
25
26SaveMeshDialog::SaveMeshDialog(MeshLib::Mesh const& mesh, QDialog* parent)
27 : QDialog(parent), _mesh(mesh)
28{
29 setupUi(this);
30 this->fileNameEdit->setText(LastSavedFileDirectory::getDir() +
31 QString::fromStdString(_mesh.getName()) +
32 ".vtu");
33}
34
36{
37 QString file_type("VTK Unstructured Grid (*.vtu)");
38#ifndef NDEBUG
39 file_type.append(";;Legacy geometry file (*.msh)");
40#endif // DEBUG
41 QSettings settings;
42 QString const file_name = QFileDialog::getSaveFileName(
43 this,
44 "Save mesh as...",
46 QString::fromStdString(_mesh.getName()),
47 file_type);
48
49 if (!file_name.isEmpty())
50 {
51 this->fileNameEdit->setText(file_name);
52 }
53}
54
56{
57 // Disable compression on Ascii
58 if (index == 0)
59 {
60 this->compressionCheckBox->setChecked(false);
61 this->compressionCheckBox->setEnabled(false);
62 this->compressionLabel->setEnabled(false);
63 }
64 else
65 {
66 this->compressionCheckBox->setEnabled(true);
67 this->compressionLabel->setEnabled(true);
68 }
69}
70
72{
73 QString const& file_name(this->fileNameEdit->text());
74 if (file_name.isEmpty())
75 {
76 OGSError::box("No file name entered.");
77 return;
78 }
79
80 QFileInfo fi(file_name);
81 if (fi.suffix().toLower() == "vtu")
82 {
83 int dataMode = this->dataModeBox->currentIndex();
84 bool compress(this->compressionCheckBox->isChecked());
85 MeshLib::IO::VtuInterface vtkIO(&_mesh, dataMode, compress);
86 vtkIO.writeToFile(file_name.toStdString());
87 }
88 if (fi.suffix().toLower() == "msh")
89 {
91 meshIO.setMesh(&_mesh);
93 file_name.toStdString());
94 }
96
97 this->done(QDialog::Accepted);
98}
Manages the last directory used for saving a file.
Definition of the MeshIO class.
Definition of the Mesh class.
Definition of the OGSError class.
Definition of the SaveMeshDialog class.
Implementation of the VtuInterface class.
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:31
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:37
void setMesh(const MeshLib::Mesh *mesh)
Set mesh for writing.
Definition MeshIO.cpp:439
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
static void box(const QString &e)
Definition OGSError.cpp:23
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:45