Changeset 7cd6e7 for src/UIElements/TextUI
- Timestamp:
- Jul 25, 2010, 3:07:42 PM (14 years ago)
- Branches:
- 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
- Children:
- e2f3114
- Parents:
- 0ff6b5
- Location:
- src/UIElements/TextUI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/TextUI/TextDialog.cpp
r0ff6b5 r7cd6e7 30 30 using namespace std; 31 31 32 using boost::lexical_cast; 33 using boost::bad_lexical_cast; 34 32 35 33 36 TextDialog::TextDialog() … … 52 55 } 53 56 57 void TextDialog::queryInts(const char* title, string description){ 58 registerQuery(new IntsTextQuery(title,description)); 59 } 60 54 61 void TextDialog::queryDouble(const char* title, string description){ 55 62 registerQuery(new DoubleTextQuery(title,description)); 56 63 } 57 64 65 void TextDialog::queryDoubles(const char* title, string description){ 66 registerQuery(new DoublesTextQuery(title,description)); 67 } 68 58 69 void TextDialog::queryString(const char* title, string description){ 59 70 registerQuery(new StringTextQuery(title,description)); … … 68 79 } 69 80 81 void TextDialog::queryAtoms(const char* title, string description) { 82 registerQuery(new AtomsTextQuery(title,description)); 83 } 84 70 85 void TextDialog::queryMolecule(const char* title, string description) { 71 86 registerQuery(new MoleculeTextQuery(title,description)); 72 87 } 73 88 89 void TextDialog::queryMolecules(const char* title, string description) { 90 registerQuery(new MoleculesTextQuery(title,description)); 91 } 92 74 93 void TextDialog::queryVector(const char* title, bool check, string description) { 75 94 registerQuery(new VectorTextQuery(title,check,description)); 76 95 } 77 96 97 void TextDialog::queryVectors(const char* title, bool check, string description) { 98 registerQuery(new VectorsTextQuery(title,check,description)); 99 } 100 78 101 void TextDialog::queryBox(const char* title, string description) { 79 102 registerQuery(new BoxTextQuery(title,description)); … … 82 105 void TextDialog::queryElement(const char* title, string description){ 83 106 registerQuery(new ElementTextQuery(title,description)); 107 } 108 109 void TextDialog::queryElements(const char* title, string description){ 110 registerQuery(new ElementsTextQuery(title,description)); 84 111 } 85 112 … … 118 145 // clear the input buffer of anything still in the line 119 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 120 176 return true; 121 177 } … … 171 227 Log() << Verbose(0) << getTitle(); 172 228 getline(cin,temp); 173 // dissect by " ,"229 // dissect by " " 174 230 string::iterator olditer = temp.begin(); 175 231 for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) { … … 208 264 } 209 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 210 296 TextDialog::AtomTextQuery::AtomTextQuery(string title, std::string _description) : 211 297 Dialog::AtomQuery(title,_description) … … 215 301 216 302 bool TextDialog::AtomTextQuery::handle() { 217 int idxOfAtom= 0;303 int idxOfAtom=-1; 218 304 bool badInput = false; 219 305 do{ … … 231 317 tmp = World::getInstance().getAtom(AtomById(idxOfAtom)); 232 318 if(!tmp && idxOfAtom!=-1){ 233 Log() << Verbose(0) << "Invalid Atom Index" << endl;319 Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl; 234 320 badInput = true; 235 321 } … … 237 323 } while(badInput); 238 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 239 365 return (idxOfAtom!=-1); 240 366 } … … 272 398 } 273 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 274 440 TextDialog::VectorTextQuery::VectorTextQuery(std::string title, bool _check, std::string _description) : 275 441 Dialog::VectorQuery(title,_check,_description) … … 280 446 281 447 bool TextDialog::VectorTextQuery::handle() { 282 Log() << Verbose(0) << getTitle(); 283 448 std::cout << getTitle(); 284 449 const Matrix &M = World::getInstance().getDomain().getM(); 285 char coords[3] = {'x','y','z'}; 286 for (int i=0;i<3;i++) { 287 do { 288 Log() << Verbose(0) << coords[i] << "[0.." << M.at(i,i) << "]: "; 289 cin >> (*tmp)[i]; 290 } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= M.at(i,i))) && (check)); 291 } 292 return true; 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 } 293 524 } 294 525 … … 338 569 Log() << Verbose(0) << "No element with this atomic number!" << endl; 339 570 badInput = true; 340 } else {341 tmp.push_back(temp);342 571 } 343 572 } … … 362 591 Log() << Verbose(0) << "No element with this shorthand!" << endl; 363 592 badInput = true; 364 } else {365 tmp.push_back(temp);366 593 } 367 594 } … … 378 605 return !aborted; 379 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 } -
src/UIElements/TextUI/TextDialog.hpp
r0ff6b5 r7cd6e7 27 27 virtual void queryBoolean(const char *, std::string = ""); 28 28 virtual void queryInt(const char *, std::string = ""); 29 virtual void queryInts(const char *, std::string = ""); 29 30 virtual void queryString(const char*, std::string = ""); 30 31 virtual void queryStrings(const char*, std::string = ""); 31 32 virtual void queryDouble(const char*, std::string = ""); 33 virtual void queryDoubles(const char*, std::string = ""); 32 34 virtual void queryAtom(const char*,std::string = ""); 35 virtual void queryAtoms(const char*,std::string = ""); 33 36 virtual void queryMolecule(const char*,std::string = ""); 37 virtual void queryMolecules(const char*,std::string = ""); 34 38 virtual void queryVector(const char*,bool, std::string = ""); 39 virtual void queryVectors(const char*,bool, std::string = ""); 35 40 virtual void queryBox(const char*, std::string = ""); 36 41 virtual void queryElement(const char*, std::string = ""); 42 virtual void queryElements(const char*, std::string = ""); 37 43 38 44 protected: … … 59 65 }; 60 66 67 class IntsTextQuery : public Dialog::IntsQuery { 68 public: 69 IntsTextQuery(std::string title, std::string _description = NULL); 70 virtual ~IntsTextQuery(); 71 virtual bool handle(); 72 }; 73 61 74 class DoubleTextQuery : public Dialog::DoubleQuery { 62 75 public: 63 76 DoubleTextQuery(std::string title, std::string _description = NULL); 64 77 virtual ~DoubleTextQuery(); 78 virtual bool handle(); 79 }; 80 81 class DoublesTextQuery : public Dialog::DoublesQuery { 82 public: 83 DoublesTextQuery(std::string title, std::string _description = NULL); 84 virtual ~DoublesTextQuery(); 65 85 virtual bool handle(); 66 86 }; … … 87 107 }; 88 108 109 class AtomsTextQuery : public Dialog::AtomsQuery { 110 public: 111 AtomsTextQuery(std::string title, std::string _description = NULL); 112 virtual ~AtomsTextQuery(); 113 virtual bool handle(); 114 }; 115 89 116 class MoleculeTextQuery : public Dialog::MoleculeQuery { 90 117 public: … … 94 121 }; 95 122 123 class MoleculesTextQuery : public Dialog::MoleculesQuery { 124 public: 125 MoleculesTextQuery(std::string title, std::string _description = NULL); 126 virtual ~MoleculesTextQuery(); 127 virtual bool handle(); 128 }; 129 96 130 class VectorTextQuery : public Dialog::VectorQuery { 97 131 public: 98 132 VectorTextQuery(std::string title,bool _check, std::string _description = NULL); 99 133 virtual ~VectorTextQuery(); 134 virtual bool handle(); 135 }; 136 137 class VectorsTextQuery : public Dialog::VectorsQuery { 138 public: 139 VectorsTextQuery(std::string title,bool _check, std::string _description = NULL); 140 virtual ~VectorsTextQuery(); 100 141 virtual bool handle(); 101 142 }; … … 114 155 virtual bool handle(); 115 156 }; 157 158 class ElementsTextQuery : public Dialog::ElementsQuery { 159 public: 160 ElementsTextQuery(std::string title, std::string _description = NULL); 161 virtual ~ElementsTextQuery(); 162 virtual bool handle(); 163 }; 116 164 }; 117 165
Note:
See TracChangeset
for help on using the changeset viewer.