updated to modern VTK
[engrid-github.git] / src / libengrid / iooperation.cpp
blob9662d9420311b7fbaa6b616d8f8a3d87f11d580d
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "iooperation.h"
22 #include "guimainwindow.h"
24 #include <QFileDialog>
26 IOOperation::IOOperation()
28 EG_TYPENAME;
29 setResetOperationCounter(true);
30 setQuickSave(true);
31 m_FileName = "";
32 m_FileNameSet = false;
35 void IOOperation::setFormat(QString format)
37 m_FormatTxt = format;
40 void IOOperation::setExtension(QString extension)
42 m_ExtensionTxt = extension;
45 void IOOperation::readInputFileName(QString default_filename, bool reset)
47 if (m_FileNameSet) {
48 return;
51 QApplication::restoreOverrideCursor();
53 QFileDialog dialog(NULL, "read file", GuiMainWindow::getCwd(), m_FormatTxt);
54 dialog.selectFile(default_filename);
55 if (dialog.exec()) {
56 QStringList selected_files = dialog.selectedFiles();
57 m_FileName = selected_files[0];
58 if (!m_FileName.isNull()) {
59 GuiMainWindow::setCwd(QFileInfo(m_FileName).absolutePath());
60 GuiMainWindow::setUnsaved(true);
61 GuiMainWindow::pointer()->setFilename(m_FileName);
62 if (reset) {
63 GuiMainWindow::pointer()->resetXmlDoc();
65 m_Valid = true;
66 } else {
67 m_Valid = false;
70 else m_Valid = false;
72 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
75 void IOOperation::readOutputFileName(QString default_filename)
77 QApplication::restoreOverrideCursor();
79 QFileDialog dialog(NULL, "write file", GuiMainWindow::getCwd(), m_FormatTxt);
80 dialog.selectFile(default_filename);
81 dialog.setAcceptMode(QFileDialog::AcceptSave);
82 dialog.setConfirmOverwrite(true);
83 if (dialog.exec()) {
84 QStringList selected_files = dialog.selectedFiles();
85 m_FileName = selected_files[0];
86 if (!m_FileName.isNull()) {
87 GuiMainWindow::setCwd(QFileInfo(m_FileName).absolutePath());
88 if (m_FileName.right(4) != m_ExtensionTxt.toLower()) {
89 if (m_FileName.right(4) != m_ExtensionTxt.toUpper()) {
90 m_FileName += m_ExtensionTxt.toLower();
93 m_Valid = true;
94 } else {
95 m_Valid = false;
98 else m_Valid = false;
100 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
103 void IOOperation::readOutputDirectory()
105 QApplication::restoreOverrideCursor();
106 m_FileName = QFileDialog::getExistingDirectory(NULL, "write OpenFOAM mesh", GuiMainWindow::getCwd());
107 if (!m_FileName.isNull()) {
108 GuiMainWindow::setCwd(QFileInfo(m_FileName).absolutePath());
109 m_Valid = true;
110 } else {
111 m_Valid = false;
113 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
116 void IOOperation::readInputDirectory(QString title_txt)
118 QApplication::restoreOverrideCursor();
119 m_FileName = QFileDialog::getExistingDirectory(NULL, title_txt, GuiMainWindow::getCwd());
120 if (!m_FileName.isNull()) {
121 GuiMainWindow::setCwd(QFileInfo(m_FileName).absolutePath());
122 m_Valid = true;
123 } else {
124 m_Valid = false;
126 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
129 bool IOOperation::isValid()
131 return m_Valid;
134 const char* IOOperation::getCFileName()
136 //NOTE: The char pointer will be invalid after the statement in which qPrintable() is used.
137 qstrcpy(m_FileName_cc,qPrintable(m_FileName));
138 return const_cast<const char *>(m_FileName_cc); //type cast needed for proper output. Technically it will be constant until the next change...
141 QString IOOperation::getFileName()
143 return m_FileName;
146 void IOOperation::setFileName(QString file_name)
148 if (QFileInfo(file_name).exists()) {
149 m_FileName = file_name;
150 m_FileNameSet = true;
151 m_Valid = true;