OGS
SaveMeshDialog Class Reference

Detailed Description

A dialog window for managing properties for writing meshes to files.

Definition at line 27 of file SaveMeshDialog.h.

#include <SaveMeshDialog.h>

Inheritance diagram for SaveMeshDialog:
[legend]
Collaboration diagram for SaveMeshDialog:
[legend]

Public Member Functions

 SaveMeshDialog (MeshLib::Mesh const &mesh, QDialog *parent=nullptr)
 
 ~SaveMeshDialog () override=default
 

Private Slots

void on_selectDirButton_clicked ()
 Selection of path to save file.
 
void on_dataModeBox_currentIndexChanged (int index)
 
void accept () override
 Instructions if the OK-Button has been pressed.
 
void reject () override
 Instructions if the Cancel-Button has been pressed.
 

Private Attributes

MeshLib::Mesh const & _mesh
 

Constructor & Destructor Documentation

◆ SaveMeshDialog()

SaveMeshDialog::SaveMeshDialog ( MeshLib::Mesh const & mesh,
QDialog * parent = nullptr )
explicit

Definition at line 26 of file SaveMeshDialog.cpp.

27 : QDialog(parent), _mesh(mesh)
28{
29 setupUi(this);
30 this->fileNameEdit->setText(LastSavedFileDirectory::getDir() +
31 QString::fromStdString(_mesh.getName()) +
32 ".vtu");
33}
static const QString getDir()
Returns the directory last used for saving a file.
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
MeshLib::Mesh const & _mesh

References _mesh, LastSavedFileDirectory::getDir(), and MeshLib::Mesh::getName().

◆ ~SaveMeshDialog()

SaveMeshDialog::~SaveMeshDialog ( )
overridedefault

Member Function Documentation

◆ accept

void SaveMeshDialog::accept ( )
overrideprivateslot

Instructions if the OK-Button has been pressed.

Definition at line 71 of file SaveMeshDialog.cpp.

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}
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.
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:434
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
static void box(const QString &e)
Definition OGSError.cpp:23
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:45

References _mesh, OGSError::box(), LastSavedFileDirectory::setDir(), MeshLib::IO::Legacy::MeshIO::setMesh(), BaseLib::IO::writeStringToFile(), MeshLib::IO::VtuInterface::writeToFile(), and BaseLib::IO::Writer::writeToString().

◆ on_dataModeBox_currentIndexChanged

void SaveMeshDialog::on_dataModeBox_currentIndexChanged ( int index)
privateslot

Definition at line 55 of file SaveMeshDialog.cpp.

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}

◆ on_selectDirButton_clicked

void SaveMeshDialog::on_selectDirButton_clicked ( )
privateslot

Selection of path to save file.

Definition at line 35 of file SaveMeshDialog.cpp.

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}

References _mesh, LastSavedFileDirectory::getDir(), and MeshLib::Mesh::getName().

◆ reject

void SaveMeshDialog::reject ( )
inlineoverrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 46 of file SaveMeshDialog.h.

46{ this->done(QDialog::Rejected); };

Member Data Documentation

◆ _mesh

MeshLib::Mesh const& SaveMeshDialog::_mesh
private

Definition at line 49 of file SaveMeshDialog.h.

Referenced by SaveMeshDialog(), accept(), and on_selectDirButton_clicked().


The documentation for this class was generated from the following files: