1 | /*
|
---|
2 | * TextDialog.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 5, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include <iostream>
|
---|
11 |
|
---|
12 | #include <Descriptors/AtomDescriptor.hpp>
|
---|
13 | #include <Descriptors/AtomIdDescriptor.hpp>
|
---|
14 | #include <Descriptors/MoleculeDescriptor.hpp>
|
---|
15 | #include <Descriptors/MoleculeIdDescriptor.hpp>
|
---|
16 | #include "TextUI/TextDialog.hpp"
|
---|
17 |
|
---|
18 | #include "World.hpp"
|
---|
19 | #include "periodentafel.hpp"
|
---|
20 | #include "log.hpp"
|
---|
21 | #include "verbose.hpp"
|
---|
22 |
|
---|
23 | #include "atom.hpp"
|
---|
24 | #include "element.hpp"
|
---|
25 | #include "molecule.hpp"
|
---|
26 | #include "vector.hpp"
|
---|
27 | #include "Matrix.hpp"
|
---|
28 | #include "Box.hpp"
|
---|
29 |
|
---|
30 | using namespace std;
|
---|
31 |
|
---|
32 | using boost::lexical_cast;
|
---|
33 | using boost::bad_lexical_cast;
|
---|
34 |
|
---|
35 |
|
---|
36 | TextDialog::TextDialog()
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | TextDialog::~TextDialog()
|
---|
41 | {
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | void TextDialog::queryEmpty(const char* title, string description){
|
---|
46 | registerQuery(new EmptyTextQuery(title,description));
|
---|
47 | }
|
---|
48 |
|
---|
49 | void TextDialog::queryBoolean(const char* title, string description){
|
---|
50 | registerQuery(new BooleanTextQuery(title,description));
|
---|
51 | }
|
---|
52 |
|
---|
53 | void TextDialog::queryInt(const char* title, string description){
|
---|
54 | registerQuery(new IntTextQuery(title,description));
|
---|
55 | }
|
---|
56 |
|
---|
57 | void TextDialog::queryInts(const char* title, string description){
|
---|
58 | registerQuery(new IntsTextQuery(title,description));
|
---|
59 | }
|
---|
60 |
|
---|
61 | void TextDialog::queryDouble(const char* title, string description){
|
---|
62 | registerQuery(new DoubleTextQuery(title,description));
|
---|
63 | }
|
---|
64 |
|
---|
65 | void TextDialog::queryDoubles(const char* title, string description){
|
---|
66 | registerQuery(new DoublesTextQuery(title,description));
|
---|
67 | }
|
---|
68 |
|
---|
69 | void TextDialog::queryString(const char* title, string description){
|
---|
70 | registerQuery(new StringTextQuery(title,description));
|
---|
71 | }
|
---|
72 |
|
---|
73 | void TextDialog::queryStrings(const char* title, string description){
|
---|
74 | registerQuery(new StringsTextQuery(title,description));
|
---|
75 | }
|
---|
76 |
|
---|
77 | void TextDialog::queryAtom(const char* title, string description) {
|
---|
78 | registerQuery(new AtomTextQuery(title,description));
|
---|
79 | }
|
---|
80 |
|
---|
81 | void TextDialog::queryAtoms(const char* title, string description) {
|
---|
82 | registerQuery(new AtomsTextQuery(title,description));
|
---|
83 | }
|
---|
84 |
|
---|
85 | void TextDialog::queryMolecule(const char* title, string description) {
|
---|
86 | registerQuery(new MoleculeTextQuery(title,description));
|
---|
87 | }
|
---|
88 |
|
---|
89 | void TextDialog::queryMolecules(const char* title, string description) {
|
---|
90 | registerQuery(new MoleculesTextQuery(title,description));
|
---|
91 | }
|
---|
92 |
|
---|
93 | void TextDialog::queryVector(const char* title, bool check, string description) {
|
---|
94 | registerQuery(new VectorTextQuery(title,check,description));
|
---|
95 | }
|
---|
96 |
|
---|
97 | void TextDialog::queryVectors(const char* title, bool check, string description) {
|
---|
98 | registerQuery(new VectorsTextQuery(title,check,description));
|
---|
99 | }
|
---|
100 |
|
---|
101 | void TextDialog::queryBox(const char* title, string description) {
|
---|
102 | registerQuery(new BoxTextQuery(title,description));
|
---|
103 | }
|
---|
104 |
|
---|
105 | void TextDialog::queryElement(const char* title, string description){
|
---|
106 | registerQuery(new ElementTextQuery(title,description));
|
---|
107 | }
|
---|
108 |
|
---|
109 | void TextDialog::queryElements(const char* title, string description){
|
---|
110 | registerQuery(new ElementsTextQuery(title,description));
|
---|
111 | }
|
---|
112 |
|
---|
113 | /************************** Query Infrastructure ************************/
|
---|
114 |
|
---|
115 | TextDialog::EmptyTextQuery::EmptyTextQuery(string title, std::string _description) :
|
---|
116 | Dialog::EmptyQuery(title,_description)
|
---|
117 | {}
|
---|
118 |
|
---|
119 | TextDialog::EmptyTextQuery::~EmptyTextQuery() {}
|
---|
120 |
|
---|
121 | bool TextDialog::EmptyTextQuery::handle() {
|
---|
122 | cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
|
---|
123 | return true;
|
---|
124 | }
|
---|
125 |
|
---|
126 | TextDialog::IntTextQuery::IntTextQuery(string title, std::string _description) :
|
---|
127 | Dialog::IntQuery(title,_description)
|
---|
128 | {}
|
---|
129 |
|
---|
130 | TextDialog::IntTextQuery::~IntTextQuery() {}
|
---|
131 |
|
---|
132 | bool TextDialog::IntTextQuery::handle() {
|
---|
133 | bool badInput = false;
|
---|
134 | do{
|
---|
135 | badInput = false;
|
---|
136 | Log() << Verbose(0) << getTitle();
|
---|
137 | cin >> tmp;
|
---|
138 | if(cin.fail()){
|
---|
139 | badInput=true;
|
---|
140 | cin.clear();
|
---|
141 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
142 | Log() << Verbose(0) << "Input was not a number!" << endl;
|
---|
143 | }
|
---|
144 | } while(badInput);
|
---|
145 | // clear the input buffer of anything still in the line
|
---|
146 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
147 | return true;
|
---|
148 | }
|
---|
149 |
|
---|
150 | TextDialog::IntsTextQuery::IntsTextQuery(string title, std::string _description) :
|
---|
151 | Dialog::IntsQuery(title,_description)
|
---|
152 | {}
|
---|
153 |
|
---|
154 | TextDialog::IntsTextQuery::~IntsTextQuery() {}
|
---|
155 |
|
---|
156 | bool TextDialog::IntsTextQuery::handle() {
|
---|
157 | Log() << Verbose(0) << getTitle();
|
---|
158 | std::string line;
|
---|
159 | getline(cin,line);
|
---|
160 | // dissect by " "
|
---|
161 | string::iterator olditer = line.begin();
|
---|
162 | for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
|
---|
163 | if (*iter == ' ') {
|
---|
164 | std::istringstream stream(string(iter, olditer));
|
---|
165 | stream >> temp;
|
---|
166 | tmp.push_back(temp);
|
---|
167 | olditer = iter;
|
---|
168 | }
|
---|
169 | }
|
---|
170 | if (olditer != line.begin()) { // insert last part also
|
---|
171 | std::istringstream stream(string(olditer, line.end()));
|
---|
172 | stream >> temp;
|
---|
173 | tmp.push_back(temp);
|
---|
174 | }
|
---|
175 |
|
---|
176 | return true;
|
---|
177 | }
|
---|
178 |
|
---|
179 | TextDialog::BooleanTextQuery::BooleanTextQuery(string title, std::string _description) :
|
---|
180 | Dialog::BooleanQuery(title,_description)
|
---|
181 | {}
|
---|
182 |
|
---|
183 | TextDialog::BooleanTextQuery::~BooleanTextQuery() {}
|
---|
184 |
|
---|
185 | bool TextDialog::BooleanTextQuery::handle() {
|
---|
186 | bool badInput = false;
|
---|
187 | char input = ' ';
|
---|
188 | do{
|
---|
189 | badInput = false;
|
---|
190 | Log() << Verbose(0) << getTitle();
|
---|
191 | cin >> input;
|
---|
192 | if ((input == 'y' ) || (input == 'Y')) {
|
---|
193 | tmp = true;
|
---|
194 | } else if ((input == 'n' ) || (input == 'N')) {
|
---|
195 | tmp = false;
|
---|
196 | } else {
|
---|
197 | badInput=true;
|
---|
198 | cin.clear();
|
---|
199 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
200 | Log() << Verbose(0) << "Input was not of [yYnN]!" << endl;
|
---|
201 | }
|
---|
202 | } while(badInput);
|
---|
203 | // clear the input buffer of anything still in the line
|
---|
204 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
205 | return true;
|
---|
206 | }
|
---|
207 |
|
---|
208 | TextDialog::StringTextQuery::StringTextQuery(string title, std::string _description) :
|
---|
209 | Dialog::StringQuery(title,_description)
|
---|
210 | {}
|
---|
211 |
|
---|
212 | TextDialog::StringTextQuery::~StringTextQuery() {}
|
---|
213 |
|
---|
214 | bool TextDialog::StringTextQuery::handle() {
|
---|
215 | Log() << Verbose(0) << getTitle();
|
---|
216 | getline(cin,tmp);
|
---|
217 | return true;
|
---|
218 | }
|
---|
219 |
|
---|
220 | TextDialog::StringsTextQuery::StringsTextQuery(string title, std::string _description) :
|
---|
221 | Dialog::StringsQuery(title,_description)
|
---|
222 | {}
|
---|
223 |
|
---|
224 | TextDialog::StringsTextQuery::~StringsTextQuery() {}
|
---|
225 |
|
---|
226 | bool TextDialog::StringsTextQuery::handle() {
|
---|
227 | Log() << Verbose(0) << getTitle();
|
---|
228 | getline(cin,temp);
|
---|
229 | // dissect by " "
|
---|
230 | string::iterator olditer = temp.begin();
|
---|
231 | for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
|
---|
232 | if (*iter == ' ') {
|
---|
233 | tmp.push_back(string(iter, olditer));
|
---|
234 | olditer = iter;
|
---|
235 | }
|
---|
236 | }
|
---|
237 | if (olditer != temp.begin()) // insert last part also
|
---|
238 | tmp.push_back(string(olditer, temp.end()));
|
---|
239 |
|
---|
240 | return true;
|
---|
241 | }
|
---|
242 |
|
---|
243 | TextDialog::DoubleTextQuery::DoubleTextQuery(string title, std::string _description) :
|
---|
244 | Dialog::DoubleQuery(title,_description)
|
---|
245 | {}
|
---|
246 |
|
---|
247 | TextDialog::DoubleTextQuery::~DoubleTextQuery() {}
|
---|
248 |
|
---|
249 | bool TextDialog::DoubleTextQuery::handle() {
|
---|
250 | bool badInput = false;
|
---|
251 | do{
|
---|
252 | badInput = false;
|
---|
253 | Log() << Verbose(0) << getTitle();
|
---|
254 | cin >> tmp;
|
---|
255 | if(cin.fail()){
|
---|
256 | badInput = true;
|
---|
257 | cin.clear();
|
---|
258 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
259 | Log() << Verbose(0) << "Input was not a number!" << endl;
|
---|
260 | }
|
---|
261 | }while(badInput);
|
---|
262 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
263 | return true;
|
---|
264 | }
|
---|
265 |
|
---|
266 |
|
---|
267 | TextDialog::DoublesTextQuery::DoublesTextQuery(string title, std::string _description) :
|
---|
268 | Dialog::DoublesQuery(title,_description)
|
---|
269 | {}
|
---|
270 |
|
---|
271 | TextDialog::DoublesTextQuery::~DoublesTextQuery() {}
|
---|
272 |
|
---|
273 | bool TextDialog::DoublesTextQuery::handle() {
|
---|
274 | Log() << Verbose(0) << getTitle();
|
---|
275 | std::string line;
|
---|
276 | getline(cin,line);
|
---|
277 | // dissect by " "
|
---|
278 | string::iterator olditer = line.begin();
|
---|
279 | for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
|
---|
280 | if (*iter == ' ') {
|
---|
281 | std::istringstream stream(string(iter, olditer));
|
---|
282 | stream >> temp;
|
---|
283 | tmp.push_back(temp);
|
---|
284 | olditer = iter;
|
---|
285 | }
|
---|
286 | }
|
---|
287 | if (olditer != line.begin()) { // insert last part also
|
---|
288 | std::istringstream stream(string(olditer, line.end()));
|
---|
289 | stream >> temp;
|
---|
290 | tmp.push_back(temp);
|
---|
291 | }
|
---|
292 |
|
---|
293 | return true;
|
---|
294 | }
|
---|
295 |
|
---|
296 | TextDialog::AtomTextQuery::AtomTextQuery(string title, std::string _description) :
|
---|
297 | Dialog::AtomQuery(title,_description)
|
---|
298 | {}
|
---|
299 |
|
---|
300 | TextDialog::AtomTextQuery::~AtomTextQuery() {}
|
---|
301 |
|
---|
302 | bool TextDialog::AtomTextQuery::handle() {
|
---|
303 | int idxOfAtom=-1;
|
---|
304 | bool badInput = false;
|
---|
305 | do{
|
---|
306 | badInput = false;
|
---|
307 | Log() << Verbose(0) << getTitle();
|
---|
308 | cin >> idxOfAtom;
|
---|
309 | if(cin.fail()){
|
---|
310 | badInput = true;
|
---|
311 | cin.clear();
|
---|
312 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
313 | Log() << Verbose(0) << "Input was not a number!" << endl;
|
---|
314 | continue;
|
---|
315 | }
|
---|
316 |
|
---|
317 | tmp = World::getInstance().getAtom(AtomById(idxOfAtom));
|
---|
318 | if(!tmp && idxOfAtom!=-1){
|
---|
319 | Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
|
---|
320 | badInput = true;
|
---|
321 | }
|
---|
322 |
|
---|
323 | } while(badInput);
|
---|
324 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
325 | return (idxOfAtom!=-1);
|
---|
326 | }
|
---|
327 |
|
---|
328 |
|
---|
329 | TextDialog::AtomsTextQuery::AtomsTextQuery(string title, std::string _description) :
|
---|
330 | Dialog::AtomsQuery(title,_description)
|
---|
331 | {}
|
---|
332 |
|
---|
333 | TextDialog::AtomsTextQuery::~AtomsTextQuery() {}
|
---|
334 |
|
---|
335 | bool TextDialog::AtomsTextQuery::handle() {
|
---|
336 | int idxOfAtom=-1;
|
---|
337 | Log() << Verbose(0) << getTitle();
|
---|
338 | std::string line;
|
---|
339 | getline(cin,line);
|
---|
340 | // dissect by " "
|
---|
341 | string::iterator olditer = line.begin();
|
---|
342 | for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
|
---|
343 | if (*iter == ' ') {
|
---|
344 | std::istringstream stream(string(iter, olditer));
|
---|
345 | stream >> idxOfAtom;
|
---|
346 | temp = World::getInstance().getAtom(AtomById(idxOfAtom));
|
---|
347 | if(!temp && idxOfAtom!=-1){
|
---|
348 | Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
|
---|
349 | break;
|
---|
350 | }
|
---|
351 | tmp.push_back(temp);
|
---|
352 | olditer = iter;
|
---|
353 | }
|
---|
354 | }
|
---|
355 | if (olditer != line.begin()) { // insert last part also
|
---|
356 | std::istringstream stream(string(olditer, line.end()));
|
---|
357 | stream >> idxOfAtom;
|
---|
358 | temp = World::getInstance().getAtom(AtomById(idxOfAtom));
|
---|
359 | if(!temp && idxOfAtom!=-1) {
|
---|
360 | Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
|
---|
361 | tmp.push_back(temp);
|
---|
362 | }
|
---|
363 | }
|
---|
364 |
|
---|
365 | return (idxOfAtom!=-1);
|
---|
366 | }
|
---|
367 |
|
---|
368 | TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, std::string _description) :
|
---|
369 | Dialog::MoleculeQuery(title,_description)
|
---|
370 | {}
|
---|
371 |
|
---|
372 | TextDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
|
---|
373 |
|
---|
374 | bool TextDialog::MoleculeTextQuery::handle() {
|
---|
375 | int idxOfMol=0;
|
---|
376 | bool badInput = false;
|
---|
377 | do{
|
---|
378 | badInput = false;
|
---|
379 | Log() << Verbose(0) << getTitle();
|
---|
380 | cin >> idxOfMol;
|
---|
381 | if(cin.fail()){
|
---|
382 | badInput = true;
|
---|
383 | cin.clear();
|
---|
384 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
385 | Log() << Verbose(0) << "Input was not a number!" << endl;
|
---|
386 | continue;
|
---|
387 | }
|
---|
388 |
|
---|
389 | tmp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
|
---|
390 | if(!tmp && idxOfMol!=-1){
|
---|
391 | Log() << Verbose(0) << "Invalid Molecule Index" << endl;
|
---|
392 | badInput = true;
|
---|
393 | }
|
---|
394 |
|
---|
395 | } while(badInput);
|
---|
396 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
397 | return (idxOfMol!=-1);
|
---|
398 | }
|
---|
399 |
|
---|
400 |
|
---|
401 | TextDialog::MoleculesTextQuery::MoleculesTextQuery(string title, std::string _description) :
|
---|
402 | Dialog::MoleculesQuery(title,_description)
|
---|
403 | {}
|
---|
404 |
|
---|
405 | TextDialog::MoleculesTextQuery::~MoleculesTextQuery() {}
|
---|
406 |
|
---|
407 | bool TextDialog::MoleculesTextQuery::handle() {
|
---|
408 | int idxOfMol=-1;
|
---|
409 | Log() << Verbose(0) << getTitle();
|
---|
410 | std::string line;
|
---|
411 | getline(cin,line);
|
---|
412 | // dissect by " "
|
---|
413 | string::iterator olditer = line.begin();
|
---|
414 | for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
|
---|
415 | if (*iter == ' ') {
|
---|
416 | std::istringstream stream(string(iter, olditer));
|
---|
417 | stream >> idxOfMol;
|
---|
418 | temp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
|
---|
419 | if(!temp && idxOfMol!=-1){
|
---|
420 | Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl;
|
---|
421 | break;
|
---|
422 | }
|
---|
423 | tmp.push_back(temp);
|
---|
424 | olditer = iter;
|
---|
425 | }
|
---|
426 | }
|
---|
427 | if (olditer != line.begin()) { // insert last part also
|
---|
428 | std::istringstream stream(string(olditer, line.end()));
|
---|
429 | stream >> idxOfMol;
|
---|
430 | temp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
|
---|
431 | if(!temp && idxOfMol!=-1){
|
---|
432 | Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl;
|
---|
433 | tmp.push_back(temp);
|
---|
434 | }
|
---|
435 | }
|
---|
436 |
|
---|
437 | return (idxOfMol!=-1);
|
---|
438 | }
|
---|
439 |
|
---|
440 | TextDialog::VectorTextQuery::VectorTextQuery(std::string title, bool _check, std::string _description) :
|
---|
441 | Dialog::VectorQuery(title,_check,_description)
|
---|
442 | {}
|
---|
443 |
|
---|
444 | TextDialog::VectorTextQuery::~VectorTextQuery()
|
---|
445 | {}
|
---|
446 |
|
---|
447 | bool TextDialog::VectorTextQuery::handle() {
|
---|
448 | std::cout << getTitle();
|
---|
449 | const Matrix &M = World::getInstance().getDomain().getM();
|
---|
450 | char coords[3] = {'x', 'y', 'z'};
|
---|
451 | for (int i=0;i<3;i++)
|
---|
452 | std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
|
---|
453 |
|
---|
454 | std::string line;
|
---|
455 | getline(cin,line);
|
---|
456 |
|
---|
457 | // dissect by ","
|
---|
458 | double coord = 0.;
|
---|
459 | int counter = 0;
|
---|
460 | string::iterator olditer = line.begin();
|
---|
461 | for(string::iterator iter = line.begin(); (iter != line.end()) && (counter != 3); ++iter) {
|
---|
462 | if (*iter == ',') {
|
---|
463 | std::istringstream stream(string(iter, olditer));
|
---|
464 | stream >> coord;
|
---|
465 | tmp[counter++] = coord;
|
---|
466 | olditer = iter;
|
---|
467 | }
|
---|
468 | }
|
---|
469 | if ((olditer != line.begin()) && (counter != 3)) { // insert last part also
|
---|
470 | std::istringstream stream(string(olditer, line.end()));
|
---|
471 | stream >> coord;
|
---|
472 | tmp[counter++] = coord;
|
---|
473 | }
|
---|
474 |
|
---|
475 | // check vector
|
---|
476 | return World::getInstance().getDomain().isInside(tmp);
|
---|
477 | }
|
---|
478 |
|
---|
479 | TextDialog::VectorsTextQuery::VectorsTextQuery(std::string title, bool _check, std::string _description) :
|
---|
480 | Dialog::VectorsQuery(title,_check,_description)
|
---|
481 | {}
|
---|
482 |
|
---|
483 | TextDialog::VectorsTextQuery::~VectorsTextQuery()
|
---|
484 | {}
|
---|
485 |
|
---|
486 | bool TextDialog::VectorsTextQuery::handle() {
|
---|
487 | std::cout << getTitle();
|
---|
488 | char coords[3] = {'x', 'y', 'z'};
|
---|
489 | const Matrix &M = World::getInstance().getDomain().getM();
|
---|
490 | for (int i=0;i<3;i++)
|
---|
491 | std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
|
---|
492 |
|
---|
493 | std::string line;
|
---|
494 | getline(cin,line);
|
---|
495 |
|
---|
496 | // dissect by ","
|
---|
497 | double coord = 0.;
|
---|
498 | string::iterator olditerspace = line.begin();
|
---|
499 | string::iterator olditercomma = line.begin();
|
---|
500 | int counter = 0;
|
---|
501 | for(string::iterator vectoriter = line.begin(); vectoriter != line.end(); ++vectoriter) {
|
---|
502 | if (*vectoriter == ',')
|
---|
503 | counter++;
|
---|
504 | if ((*vectoriter == ' ') && (counter == 2)) {
|
---|
505 | counter = 0;
|
---|
506 | for(string::iterator componentiter = olditerspace; (componentiter != vectoriter) && (counter !=3); ++componentiter) {
|
---|
507 | if (*componentiter == ',') {
|
---|
508 | std::istringstream stream(string(componentiter, olditercomma));
|
---|
509 | stream >> coord;
|
---|
510 | temp[counter++] = coord;
|
---|
511 | olditercomma = componentiter;
|
---|
512 | }
|
---|
513 | }
|
---|
514 | if ((olditercomma != line.begin()) && (counter != 3)) { // insert last part also
|
---|
515 | std::istringstream stream(string(olditercomma, vectoriter));
|
---|
516 | stream >> coord;
|
---|
517 | temp[counter++] = coord;
|
---|
518 | }
|
---|
519 | if (World::getInstance().getDomain().isInside(temp))
|
---|
520 | tmp.push_back(temp);
|
---|
521 | olditerspace = vectoriter;
|
---|
522 | }
|
---|
523 | }
|
---|
524 | }
|
---|
525 |
|
---|
526 | TextDialog::BoxTextQuery::BoxTextQuery(std::string title, std::string _description) :
|
---|
527 | Dialog::BoxQuery(title,_description)
|
---|
528 | {}
|
---|
529 |
|
---|
530 | TextDialog::BoxTextQuery::~BoxTextQuery()
|
---|
531 | {}
|
---|
532 |
|
---|
533 | bool TextDialog::BoxTextQuery::handle() {
|
---|
534 | Log() << Verbose(0) << getTitle();
|
---|
535 |
|
---|
536 | std::string coords[6] = {"xx","xy","xz", "yy", "yz", "zz"};
|
---|
537 | for (int i=0;i<6;i++) {
|
---|
538 | Log() << Verbose(0) << coords[i] << ": ";
|
---|
539 | cin >> tmp[i];
|
---|
540 | }
|
---|
541 | return true;
|
---|
542 | }
|
---|
543 |
|
---|
544 | TextDialog::ElementTextQuery::ElementTextQuery(std::string title, std::string _description) :
|
---|
545 | Dialog::ElementQuery(title,_description)
|
---|
546 | {}
|
---|
547 |
|
---|
548 | TextDialog::ElementTextQuery::~ElementTextQuery()
|
---|
549 | {}
|
---|
550 |
|
---|
551 | bool TextDialog::ElementTextQuery::handle() {
|
---|
552 | bool badInput=false;
|
---|
553 | bool aborted = false;
|
---|
554 | element * temp = NULL;
|
---|
555 | do{
|
---|
556 | badInput = false;
|
---|
557 | Log() << Verbose(0) << getTitle();
|
---|
558 |
|
---|
559 | // try to read as Atomic number
|
---|
560 | int Z;
|
---|
561 | cin >> Z;
|
---|
562 | if(!cin.fail()){
|
---|
563 | if(Z==-1){
|
---|
564 | aborted = true;
|
---|
565 | }
|
---|
566 | else{
|
---|
567 | temp = World::getInstance().getPeriode()->FindElement(Z);
|
---|
568 | if(!temp){
|
---|
569 | Log() << Verbose(0) << "No element with this atomic number!" << endl;
|
---|
570 | badInput = true;
|
---|
571 | }
|
---|
572 | }
|
---|
573 | continue;
|
---|
574 | }
|
---|
575 | else{
|
---|
576 | cin.clear();
|
---|
577 | }
|
---|
578 |
|
---|
579 | // Try to read as shorthand
|
---|
580 | // the last buffer content was not removed, so we read the
|
---|
581 | // same thing again, this time as a string
|
---|
582 | string shorthand;
|
---|
583 | cin >> shorthand;
|
---|
584 | if(!cin.fail()){
|
---|
585 | if(shorthand.empty()){
|
---|
586 | aborted = true;
|
---|
587 | }
|
---|
588 | else{
|
---|
589 | temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
|
---|
590 | if(!temp){
|
---|
591 | Log() << Verbose(0) << "No element with this shorthand!" << endl;
|
---|
592 | badInput = true;
|
---|
593 | }
|
---|
594 | }
|
---|
595 | }
|
---|
596 | else{
|
---|
597 | Log() << Verbose(0) << "Could not read input. Try Again." << endl;
|
---|
598 | cin.clear();
|
---|
599 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
600 | badInput = true;
|
---|
601 | }
|
---|
602 |
|
---|
603 | }while(badInput);
|
---|
604 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
---|
605 | return !aborted;
|
---|
606 | }
|
---|
607 |
|
---|
608 | TextDialog::ElementsTextQuery::ElementsTextQuery(std::string title, std::string _description) :
|
---|
609 | Dialog::ElementsQuery(title,_description)
|
---|
610 | {}
|
---|
611 |
|
---|
612 | TextDialog::ElementsTextQuery::~ElementsTextQuery()
|
---|
613 | {}
|
---|
614 |
|
---|
615 | bool TextDialog::ElementsTextQuery::handle() {
|
---|
616 | std::string shorthand;
|
---|
617 | int Z=-1;
|
---|
618 | Log() << Verbose(0) << getTitle();
|
---|
619 | std::string line;
|
---|
620 | getline(cin,line);
|
---|
621 | // dissect by " "
|
---|
622 | string::iterator olditer = line.begin();
|
---|
623 | for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
|
---|
624 | if (*iter == ' ') {
|
---|
625 | std::istringstream stream(string(iter, olditer));
|
---|
626 | stream >> shorthand;
|
---|
627 | try {
|
---|
628 | Z = lexical_cast<int>(shorthand);
|
---|
629 | temp = World::getInstance().getPeriode()->FindElement(Z);
|
---|
630 | } catch (bad_lexical_cast) {
|
---|
631 | temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
|
---|
632 | };
|
---|
633 | if(!temp && Z!=-1){
|
---|
634 | Log() << Verbose(0) << "Invalid Element" << shorthand << endl;
|
---|
635 | break;
|
---|
636 | }
|
---|
637 | tmp.push_back(temp);
|
---|
638 | olditer = iter;
|
---|
639 | }
|
---|
640 | }
|
---|
641 | if (olditer != line.begin()) { // insert last part also
|
---|
642 | std::istringstream stream(string(olditer, line.end()));
|
---|
643 | stream >> shorthand;
|
---|
644 | try {
|
---|
645 | Z = lexical_cast<int>(shorthand);
|
---|
646 | temp = World::getInstance().getPeriode()->FindElement(Z);
|
---|
647 | } catch (bad_lexical_cast) {
|
---|
648 | temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
|
---|
649 | };
|
---|
650 | if(!temp && Z!=-1) {
|
---|
651 | Log() << Verbose(0) << "Invalid Element" << shorthand << endl;
|
---|
652 | tmp.push_back(temp);
|
---|
653 | }
|
---|
654 | }
|
---|
655 |
|
---|
656 | return (Z!=-1);
|
---|
657 | }
|
---|