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