source: src/UIElements/TextUI/TextDialog.cpp@ 6f5dfe

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 6f5dfe was 6f5dfe, checked in by Frederik Heber <heber@…>, 14 years ago

Added boost::filesystem usage for input files.

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