Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/src/newprojectdialog.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program 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 this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI newproject *
27
* *
28
*****************************************************************************
29
* *
30
* Author: Saeki Takayuki *
31
* Original Date: 15 Feb 2020 *
32
* *
33
*****************************************************************************/
34
35
#include <QtGui>
36
#include <QFileDialog>
37
#include <iostream>
38
#include <QDomDocument>
39
#include "newprojectdialog.h"
40
41
using namespace std;
42
43
NewProjectDialog::NewProjectDialog(QWidget *parent)
44
: QDialog(parent)
45
{
46
ui.setupUi(this);
47
48
setWindowIcon(QIcon(":/icons/Mesh3D.png"));
49
50
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
51
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
52
connect(ui.radioButton_elmerMesh, SIGNAL(toggled(bool)), this, SLOT(elmerMeshToggled(bool)));
53
connect(ui.radioButton_geometryFile, SIGNAL(toggled(bool)), this, SLOT(geometryFileToggled(bool)));
54
connect(ui.radioButton_later, SIGNAL(toggled(bool)), this, SLOT(laterToggled(bool)));
55
connect(ui.pushButton_projectDir, SIGNAL(clicked(bool)), this, SLOT(projectDirClicked(bool)));
56
connect(ui.pushButton_meshDir, SIGNAL(clicked(bool)), this, SLOT(meshDirClicked(bool)));
57
connect(ui.pushButton_geometryFile, SIGNAL(clicked(bool)), this, SLOT(geometryFileClicked(bool)));
58
connect(ui.pushButton_addSolver, SIGNAL(clicked(bool)), this, SLOT(addSolverClicked(bool)));
59
connect(ui.pushButton_removeSolver, SIGNAL(clicked(bool)), this, SLOT(removeSolverClicked(bool)));
60
connect(ui.listWidget_selectedSolvers, SIGNAL(currentRowChanged(int)), this, SLOT(selectedSolverChanged(int)));
61
connect(ui.listWidget_unselectedSolvers, SIGNAL(currentRowChanged(int)), this, SLOT(unselectedSolverChanged(int)));
62
ui.pushButton_addSolver->setEnabled(false);
63
ui.pushButton_removeSolver->setEnabled(false);
64
65
ui.radioButton_later->setChecked(true);
66
geometryFileToggled(false);
67
elmerMeshToggled(false);
68
69
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
70
}
71
72
NewProjectDialog::~NewProjectDialog()
73
{
74
}
75
76
void NewProjectDialog::elmerMeshToggled(bool b){
77
ui.pushButton_meshDir->setEnabled(b);
78
ui.label_meshDir->setEnabled(b);
79
}
80
81
void NewProjectDialog::geometryFileToggled(bool b){
82
ui.pushButton_geometryFile->setEnabled(b);
83
ui.label_geometryFile->setEnabled(b);
84
}
85
86
void NewProjectDialog::laterToggled(bool b){
87
}
88
89
void NewProjectDialog::projectDirClicked(bool b){
90
QString dirName = QFileDialog::getExistingDirectory(this, tr("Select directory to store the new project"), defaultDirName);
91
if (!dirName.isEmpty()){
92
ui.label_projectDir->setText(dirName);
93
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
94
}
95
}
96
97
void NewProjectDialog::meshDirClicked(bool b){
98
QString dirName = QFileDialog::getExistingDirectory(this, tr("Select Elmer mesh directory"), defaultDirName);
99
if (!dirName.isEmpty()){
100
ui.label_meshDir->setText(dirName);
101
}
102
}
103
104
void NewProjectDialog::geometryFileClicked(bool b){
105
QString fileName = QFileDialog::getOpenFileName(this, tr("Select geometry input file"), defaultDirName);
106
if (!fileName.isEmpty()) {
107
ui.label_geometryFile->setText(fileName);
108
}
109
}
110
111
void NewProjectDialog::setDirectories(QString& defaultDir, QString& extraDirName){
112
defaultDirName = defaultDir;
113
extraDirPath = extraDirName;
114
115
QString name;
116
QDir extraDir(extraDirPath);
117
QStringList nameFilters;
118
nameFilters << "*.xml";
119
QStringList fileNameList = extraDir.entryList(nameFilters, QDir::Files | QDir::Readable);
120
121
for(int i=0; i < fileNameList.size(); i++){
122
if(isEdfFile( extraDirPath + "/" + fileNameList.at(i))) ui.listWidget_unselectedSolvers->addItem(fileNameList.at(i));
123
}
124
125
QString labelString;
126
QDir edfDir(extraDirPath + "/../edf");
127
fileNameList = edfDir.entryList(nameFilters, QDir::Files | QDir::Readable);
128
for(int i=0; i<fileNameList.size(); i++){
129
if( fileNameList[i] != "edf.xml" && fileNameList[i] != "egini.xml" && fileNameList[i] != "egmaterials.xml" )
130
{
131
if(isEdfFile( extraDirPath + "/../edf/" + fileNameList.at(i))) labelString += " " + fileNameList[i] + "\n";
132
}
133
}
134
ui.label_defaultSolvers->setText(labelString);
135
}
136
137
void NewProjectDialog::addSolverClicked(bool b){
138
int i = ui.listWidget_unselectedSolvers->currentRow();
139
if(i < 0) return;
140
QListWidgetItem* item = ui.listWidget_unselectedSolvers->takeItem(i);
141
if(item != NULL) ui.listWidget_selectedSolvers->addItem(item->text());
142
}
143
144
void NewProjectDialog::removeSolverClicked(bool b){
145
int i = ui.listWidget_selectedSolvers->currentRow();
146
if(i < 0) return;
147
QListWidgetItem* item = ui.listWidget_selectedSolvers->takeItem(i);
148
if(item != NULL) ui.listWidget_unselectedSolvers->addItem(item->text());
149
}
150
151
void NewProjectDialog::selectedSolverChanged(int i){
152
ui.pushButton_removeSolver->setEnabled(i >= 0);
153
}
154
155
void NewProjectDialog::unselectedSolverChanged(int i){
156
ui.pushButton_addSolver->setEnabled(i >= 0);
157
}
158
159
bool NewProjectDialog::isEdfFile(QString path){
160
QString errStr;
161
int errRow;
162
int errCol;
163
QFile file(path);
164
QDomDocument doc;
165
166
if(!file.exists()) {
167
return false;
168
169
} else {
170
171
if(!doc.setContent(&file, true, &errStr, &errRow, &errCol)) {
172
file.close();
173
return false;
174
}
175
}
176
177
file.close();
178
179
if(doc.documentElement().tagName() != "edf") {
180
return false;
181
}
182
183
return true;
184
}
185