tychoGUI  1.0
 All Data Structures Namespaces Files Functions Variables
open_initial_conditions.cpp
Go to the documentation of this file.
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include <QFileDialog>
4 #include <QFile>
5 #include <QTextStream>
6 #include <QString>
7 #include <iostream>
8 #include <QDebug>
9 #include <sstream>
10 #include <string>
11 #include <QMessageBox>
12 
13 
18 {
19  QString ic_dens = QFileDialog::getOpenFileName(this, tr("The initial density file"), QString::null);
20  if (ic_dens.size()==0) ic_dens = "dummy";
21  ic_density_file = ic_dens;
22 
23  //to read out the size of the computational domain
24  if (ic_dens.size()>0){
25  check_resolution(ic_dens);
26  }
27 }
28 
33 {
34 
35  QString ic_temp = QFileDialog::getOpenFileName(this, tr("The initial temperature file"), QString::null);
36 
37  if (ic_temp.size()==0) ic_temp ="dummy";
38 
39  ic_temperature_file = ic_temp;
40 
41  //to read out the size of the computational domain
42  if (ic_temp.size()>0){
43  check_resolution(ic_temp);
44  }
45 }
46 
51 {
52 
53  QString ic_velo = QFileDialog::getOpenFileName(this, tr("The initial velocity file"), QString::null);
54 
55  if (ic_velo.size()==0) ic_velo = "dummy";
56 
57  ic_velocity_file = ic_velo;
58 
59  //to read out the size of the computational domain
60  if (ic_velo.size()>0){
61  check_resolution(ic_velo);
62  }
63 }
64 
69 {
70 
71  QString ic_wind = QFileDialog::getOpenFileName(this, tr("The initial wind-emitter file"), QString::null);
72 
73  if (ic_wind.size()==0) ic_wind = "dummy";
74 
76 
77  //to read out the size of the computational domain
78  if (ic_wind.size()>0){
79  check_resolution(ic_wind);
80  }
81 }
82 
87 {
88 
89  QString ic_obstacle = QFileDialog::getOpenFileName(this, tr("The initial obstacles-distribution file"), QString::null);
90 
91  if (ic_obstacle.size()==0) ic_obstacle = "dummy";
92 
94 
95  //to read out the size of the computational domain
96  if (ic_obstacle.size()>0){
97  check_resolution(ic_obstacle);
98  }
99 }
100 
105 {
106 
107  QString ic_marker = QFileDialog::getOpenFileName(this, tr("The initial marker-field distribution file"), QString::null);
108 
109  if (ic_marker.size()==0) ic_marker = "dummy";
110 
112 
113  //to read out the size of the computational domain
114  if (ic_marker.size()>0){
115  check_resolution(ic_marker);
116  }
117 }
118 
123 {
124 
125  QString ic_soundemitter = QFileDialog::getOpenFileName(this, tr("The initial soundemitter file"), QString::null);
126 
127  if (ic_soundemitter.size()==0) ic_soundemitter = "dummy";
128 
130 
131  //to read out the size of the computational domain
132  if (ic_soundemitter.size()>0){
133  check_resolution(ic_soundemitter);
134  }
135 }
136 
137 
142 {
143 
144  QString output_path = QFileDialog::getExistingDirectory(this, tr("The output directory"), QString::null);
145 
146  if (output_path.size()==0) output_path = "/tmp/";
147 
148  output_path = output_path.append("/");
149 
151 
153 }
154 
159 
160  ic_density_file = "dummy";
161  ic_temperature_file = "dummy";
162  ic_velocity_file = "dummy";
163  ic_windemitter_file = "dummy";
164  ic_obstacle_file = "dummy";
165  ic_soundemitter_file = "dummy";
166  ic_marker_file = "dummy";
167  output_directory= "/tmp/";
168 
170 }
171 
175 void MainWindow::check_resolution(QString filename){
176 
177  int read_x_res = 0;
178  int read_y_res = 0;
179  int read_z_res = 0;
180 
181  QFile file(filename);
182  file.open(QIODevice::ReadOnly | QIODevice::Text);
183  QTextStream in(&file);
184  int i = 0;
185  while(i<4)
186  {
187  QString line = in.readLine();
188  std::istringstream iss(line.toStdString());
189  std::string name;
190  if (i == 1) iss >> name >> read_x_res;
191  if (i == 2) iss >> name >> read_y_res;
192  if (i == 3) iss >> name >> read_z_res;
193  i++;
194  }
195 
197 
198  if ((read_x_res != MainWindow::x_res)||
199  (read_y_res != MainWindow::y_res)||
200  (read_z_res != MainWindow::z_res)){
201 
202 
203  ui->res_x->setValue(0);
204  ui->res_y->setValue(0);
205  ui->res_z->setValue(0);
206 
207  QMessageBox msgBox;
208  msgBox.setText("Attention!");
209  msgBox.setInformativeText("The file has a different resolution as a already loaded, plaese check the IC files.");
210  msgBox.exec();
211  }
212  }
213 
214  MainWindow::x_res = read_x_res;
215  MainWindow::y_res = read_y_res;
216  MainWindow::z_res = read_z_res;
217 
218  ui->res_x->setValue(read_x_res);
219  ui->res_y->setValue(read_y_res);
220  ui->res_z->setValue(read_z_res);
221 
222  if ((read_y_res==1)&&(read_z_res==1)) ui->dimension->setCurrentIndex(0);
223  if (read_z_res ==1) ui->dimension->setCurrentIndex(1);
224  if ((read_y_res!=1)&&(read_z_res!=1)) ui->dimension->setCurrentIndex(2);
225 
227 
228 }