OGS
SaveMeshDialog Class Reference

Detailed Description

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

Definition at line 16 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 15 of file SaveMeshDialog.cpp.

16 : QDialog(parent), _mesh(mesh)
17{
18 setupUi(this);
19 this->fileNameEdit->setText(LastSavedFileDirectory::getDir() +
20 QString::fromStdString(_mesh.getName()) +
21 ".vtu");
22}
static const QString getDir()
Returns the directory last used for saving a file.
MeshLib::Mesh const & _mesh

References _mesh, and LastSavedFileDirectory::getDir().

◆ ~SaveMeshDialog()

SaveMeshDialog::~SaveMeshDialog ( )
overridedefault

Member Function Documentation

◆ accept

void SaveMeshDialog::accept ( )
overrideprivateslot

Instructions if the OK-Button has been pressed.

Definition at line 60 of file SaveMeshDialog.cpp.

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 {
79 MeshLib::IO::Legacy::MeshIO meshIO;
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.
void setMesh(const MeshLib::Mesh *mesh)
Set mesh for writing.
Definition MeshIO.cpp:427
static void box(const QString &e)
Definition OGSError.cpp:13
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:34

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 44 of file SaveMeshDialog.cpp.

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}

◆ on_selectDirButton_clicked

void SaveMeshDialog::on_selectDirButton_clicked ( )
privateslot

Selection of path to save file.

Definition at line 24 of file SaveMeshDialog.cpp.

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}

References _mesh, and LastSavedFileDirectory::getDir().

◆ reject

void SaveMeshDialog::reject ( )
inlineoverrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 35 of file SaveMeshDialog.h.

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

Member Data Documentation

◆ _mesh

MeshLib::Mesh const& SaveMeshDialog::_mesh
private

Definition at line 38 of file SaveMeshDialog.h.

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


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