1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "iooperation.h"
22 #include "guimainwindow.h"
24 #include <QFileDialog>
26 IOOperation::IOOperation()
29 setResetOperationCounter(true);
32 m_FileNameSet
= false;
35 void IOOperation::setFormat(QString format
)
40 void IOOperation::setExtension(QString extension
)
42 m_ExtensionTxt
= extension
;
45 void IOOperation::readInputFileName(QString default_filename
, bool reset
)
51 QApplication::restoreOverrideCursor();
53 QFileDialog
dialog(NULL
, "read file", GuiMainWindow::getCwd(), m_FormatTxt
);
54 dialog
.selectFile(default_filename
);
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
);
63 GuiMainWindow::pointer()->resetXmlDoc();
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);
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();
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());
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());
126 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
129 bool IOOperation::isValid()
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()
146 void IOOperation::setFileName(QString file_name
)
148 if (QFileInfo(file_name
).exists()) {
149 m_FileName
= file_name
;
150 m_FileNameSet
= true;