set version number back to "dev"
[engrid.git] / src / libengrid / iooperation.cpp
blob5f089112719908f250f3a7cbfbf34eec6483274b
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2013 enGits GmbH +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 #include "iooperation.h"
24 #include "guimainwindow.h"
26 #include <QFileDialog>
28 IOOperation::IOOperation()
30 EG_TYPENAME;
31 setResetOperationCounter(true);
32 setQuickSave(true);
33 m_FileName = "";
34 m_FileNameSet = false;
37 void IOOperation::setFormat(QString format)
39 m_FormatTxt = format;
42 void IOOperation::setExtension(QString extension)
44 m_ExtensionTxt = extension;
47 void IOOperation::readInputFileName(QString default_filename, bool reset)
49 if (m_FileNameSet) {
50 return;
53 QApplication::restoreOverrideCursor();
55 QFileDialog dialog(NULL, "read file", GuiMainWindow::getCwd(), m_FormatTxt);
56 dialog.selectFile(default_filename);
57 if (dialog.exec()) {
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);
64 if (reset) {
65 GuiMainWindow::pointer()->resetXmlDoc();
67 m_Valid = true;
68 } else {
69 m_Valid = false;
72 else m_Valid = false;
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);
85 if (dialog.exec()) {
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();
95 m_Valid = true;
96 } else {
97 m_Valid = false;
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());
111 m_Valid = true;
112 } else {
113 m_Valid = false;
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());
124 m_Valid = true;
125 } else {
126 m_Valid = false;
128 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
131 bool IOOperation::isValid()
133 return m_Valid;
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()
145 return m_FileName;
148 void IOOperation::setFileName(QString file_name)
150 if (QFileInfo(file_name).exists()) {
151 m_FileName = file_name;
152 m_FileNameSet = true;
153 m_Valid = true;