-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportDesorption.cpp
217 lines (180 loc) · 5.79 KB
/
ExportDesorption.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
File: ExportDesorption.cpp
Description: Do the photon dose -> outgassing conversion before exporting
Program: SynRad
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "ExportDesorption.h"
#include "Facet.h"
#include "GLApp/GLTitledPanel.h"
#include "GLApp/GLToolkit.h"
#include "GLApp/GLWindowManager.h"
#include "GLApp/GLMessageBox.h"
#include "SynRad.h"
#include "GLApp/GLFileBox.h"
extern SynRad *mApp;
ExportDesorption::ExportDesorption(Geometry *g,Worker *w):GLWindow() {
int wD = 500;
int hD = 220;
fileName = NULL;
fileLoaded = false;
mode=2; //default mode: use equation
//conversionDistr = new Distribution2D(); //placeholder
conversionDistr.isLogLog = true;
SetTitle("Export desorption map");
toggle1=new GLToggle(0,"No conversion");
toggle1->SetBounds(10,5,170,18);
Add(toggle1);
toggle2=new GLToggle(0,"Eta = * Dose ^");
toggle2->SetBounds(10,40,170,18);
toggle2->SetState(true);
Add(toggle2);
eta0Field = new GLTextField(0,"1");
eta0Field->SetBounds(60,40,30,18);
Add(eta0Field);
alphaField = new GLTextField(0,"-1");
alphaField->SetBounds(145,40,30,18);
Add(alphaField);
toggle3 = new GLToggle(0,"File");
toggle3->SetBounds(10,75,40,18);
Add(toggle3);
browseButton = new GLButton(0,"Browse...");
browseButton->SetBounds(60,73,60,21);
Add(browseButton);
fileNameLabel = new GLLabel("No file loaded.");
fileNameLabel->SetBounds(60,100,170,18);
Add(fileNameLabel);
fileInfoLabel = new GLLabel("");
fileInfoLabel->SetBounds(60,125,170,18);
Add(fileInfoLabel);
selectedToggle = new GLToggle(0,"Export selected facets only");
selectedToggle->SetBounds(10,150,170,18);
Add(selectedToggle);
exportButton = new GLButton(0,"Export");
exportButton->SetBounds(10,hD-44,85,21);
Add(exportButton);
cancelButton = new GLButton(0,"Cancel");
cancelButton->SetBounds(100,hD-44,85,21);
Add(cancelButton);
// Center dialog
int wS,hS;
GLToolkit::GetScreenSize(&wS,&hS);
int xD = (wS-wD)/2;
int yD = (hS-hD)/2;
SetBounds(xD,yD,wD,hD);
RestoreDeviceObjects();
geom = g;
work = w;
}
void ExportDesorption::ProcessMessage(GLComponent *src,int message) {
switch(message) {
case MSG_BUTTON:
if(src==cancelButton) {
GLWindow::ProcessMessage(NULL,MSG_CLOSE);
} else if (src==exportButton) {
//do checks
if (selectedToggle->GetState() && geom->GetNbSelectedFacets()==0) {
GLMessageBox::Display("No facets selected","Nothing to export",GLDLG_OK,GLDLG_ICONERROR);
return;
}
if( mode==2 && !eta0Field->GetNumber(&eta0) ) {
GLMessageBox::Display("Invalid eta0 value","Error",GLDLG_OK,GLDLG_ICONERROR);
return;
}
if( mode==2 && !alphaField->GetNumber(&alpha) ) {
GLMessageBox::Display("Invalid alpha value","Error",GLDLG_OK,GLDLG_ICONERROR);
return;
}
if( mode==3 && !fileLoaded ) {
GLMessageBox::Display("No conversion file loaded","Error",GLDLG_OK,GLDLG_ICONERROR);
return;
}
bool meshExists = false;
for (int i=0;i<geom->GetNbFacet() && !meshExists;i++) {
if (geom->GetFacet(i)->hasMesh) meshExists = true;
}
if (!meshExists) {
GLMessageBox::Display("There are no textures to convert to desorption","Error",GLDLG_OK,GLDLG_ICONERROR);
return;
}
FILENAME *fn = GLFileBox::SaveFile(mApp->currentDir,NULL,"Save Desorption File","DES files\0*.des\0All files\0*.*\0",2);
if( fn ) {
try {
work->ExportDesorption(fn->fullName,selectedToggle->GetState(),mode,eta0,alpha,conversionDistr);
GLWindow::ProcessMessage(NULL,MSG_CLOSE);
} catch (Error &e) {
char errMsg[512];
sprintf(errMsg,"%s\nFile:%s",e.GetMsg(),fn->fullName);
GLMessageBox::Display(errMsg,"Error",GLDLG_OK,GLDLG_ICONERROR);
}
}
} else if (src==browseButton) {
toggle1->SetState(false);
toggle2->SetState(false);
toggle3->SetState(true);
//load file dialog
FILENAME *convFile=GLFileBox::OpenFile(mApp->currentDir,NULL,"Open conversion file","CONV files\0*.conv\0All files\0*.*\0",2);
if (!convFile) return;
fileName=convFile->fullName;
if (!fileName) return;
//load file
int nbPt=LoadConvFile(fileName);
if (nbPt>0) {
fileNameLabel->SetText(fileName);
char tmp[256];
sprintf(tmp,"%d points loaded.",nbPt);
fileInfoLabel->SetText(tmp);
} else {
GLMessageBox::Display("Couldn't load conversion file","Error",GLDLG_OK,GLDLG_ICONERROR);
return;
}
}
break;
case MSG_TOGGLE:
if (src!=selectedToggle) {
toggle1->SetState(src==toggle1);
toggle2->SetState(src==toggle2);
toggle3->SetState(src==toggle3);
if (src==toggle1) mode=1;
if (src==toggle2) mode=2;
if (src==toggle3) mode=3;
}
break;
}
GLWindow::ProcessMessage(src,message);
}
int ExportDesorption::LoadConvFile(char *fileName) {
int nbPoints=0;
FileReader *f = NULL;
try {
f=new FileReader(fileName);
//count number of entries
while (!f->IsEof()) {
f->ReadDouble();
f->ReadDouble();
nbPoints++;
}
if (!(nbPoints>0)) throw Error("Invalid number of entries in file");
//conversionDistr=new Distribution2D(nbPoints);
f->SeekStart(); //restart from the beginning
/*for (int i=0;i<nbPoints;i++) {
conversionDistr->valuesX[i]=f->ReadDouble();
conversionDistr->valuesY[i]=f->ReadDouble();
}*/
SAFE_DELETE(f);
} catch (Error &e) {
SAFE_DELETE(f);
char errMsg[512];
sprintf(errMsg,"%s\nFile:%s",e.GetMsg(),fileName);
GLMessageBox::Display(errMsg,"Error",GLDLG_OK,GLDLG_ICONERROR);
}
fileLoaded=true;
return nbPoints;
}