2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 enGits GmbH +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "iooperation.h"
24 #include "guimainwindow.h"
26 #include <QFileDialog>
28 IOOperation::IOOperation()
31 setResetOperationCounter(true);
34 m_FileNameSet
= false;
37 void IOOperation::setFormat(QString format
)
42 void IOOperation::setExtension(QString extension
)
44 m_ExtensionTxt
= extension
;
47 void IOOperation::readInputFileName(QString default_filename
, bool reset
)
53 QApplication::restoreOverrideCursor();
55 QFileDialog
dialog(NULL
, "read file", GuiMainWindow::getCwd(), m_FormatTxt
);
56 dialog
.selectFile(default_filename
);
58 QStringList selected_files
= dialog
.selectedFiles();
59 m_FileName
= selected_files
[0];
60 if (!m_FileName
.isNull()) {
61 GuiMainWindow::setCwd(QFileInfo(m_FileName
).absolutePath());
62 GuiMainWindow::setUnsaved(true);
63 GuiMainWindow::pointer()->setFilename(m_FileName
);
65 GuiMainWindow::pointer()->resetXmlDoc();
74 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
77 void IOOperation::readOutputFileName(QString default_filename
)
79 QApplication::restoreOverrideCursor();
81 QFileDialog
dialog(NULL
, "write file", GuiMainWindow::getCwd(), m_FormatTxt
);
82 dialog
.selectFile(default_filename
);
83 dialog
.setAcceptMode(QFileDialog::AcceptSave
);
84 dialog
.setConfirmOverwrite(true);
86 QStringList selected_files
= dialog
.selectedFiles();
87 m_FileName
= selected_files
[0];
88 if (!m_FileName
.isNull()) {
89 GuiMainWindow::setCwd(QFileInfo(m_FileName
).absolutePath());
90 if (m_FileName
.right(4) != m_ExtensionTxt
.toLower()) {
91 if (m_FileName
.right(4) != m_ExtensionTxt
.toUpper()) {
92 m_FileName
+= m_ExtensionTxt
.toLower();
100 else m_Valid
= false;
102 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
105 void IOOperation::readOutputDirectory()
107 QApplication::restoreOverrideCursor();
108 m_FileName
= QFileDialog::getExistingDirectory(NULL
, "write OpenFOAM mesh", GuiMainWindow::getCwd());
109 if (!m_FileName
.isNull()) {
110 GuiMainWindow::setCwd(QFileInfo(m_FileName
).absolutePath());
115 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
118 void IOOperation::readInputDirectory(QString title_txt
)
120 QApplication::restoreOverrideCursor();
121 m_FileName
= QFileDialog::getExistingDirectory(NULL
, title_txt
, GuiMainWindow::getCwd());
122 if (!m_FileName
.isNull()) {
123 GuiMainWindow::setCwd(QFileInfo(m_FileName
).absolutePath());
128 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
131 bool IOOperation::isValid()
136 const char* IOOperation::getCFileName()
138 //NOTE: The char pointer will be invalid after the statement in which qPrintable() is used.
139 qstrcpy(m_FileName_cc
,qPrintable(m_FileName
));
140 return const_cast<const char *>(m_FileName_cc
); //type cast needed for proper output. Technically it will be constant until the next change...
143 QString
IOOperation::getFileName()
148 void IOOperation::setFileName(QString file_name
)
150 if (QFileInfo(file_name
).exists()) {
151 m_FileName
= file_name
;
152 m_FileNameSet
= true;