Changeset 8df74d for src/UIElements/TextUI/TextDialog.cpp
- Timestamp:
- Oct 25, 2010, 5:16:19 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:
- 573ca5, b295ca
- Parents:
- 57a6ea1
- git-author:
- Frederik Heber <heber@…> (10/25/10 17:11:33)
- git-committer:
- Frederik Heber <heber@…> (10/25/10 17:16:19)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/TextUI/TextDialog.cpp
r57a6ea1 r8df74d 20 20 #include "Helpers/MemDebug.hpp" 21 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 22 #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 23 46 24 using namespace std; … … 131 109 132 110 /************************** Query Infrastructure ************************/ 111 /* ---> shifted to folder Query */ 112 /************************************************************************/ 133 113 134 TextDialog::EmptyTextQuery::EmptyTextQuery(string title, std::string _description) :135 Dialog::EmptyQuery(title,_description)136 {}137 138 TextDialog::EmptyTextQuery::~EmptyTextQuery() {}139 140 bool TextDialog::EmptyTextQuery::handle() {141 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";142 return true;143 }144 145 TextDialog::IntTextQuery::IntTextQuery(string title, std::string _description) :146 Dialog::IntQuery(title,_description)147 {}148 149 TextDialog::IntTextQuery::~IntTextQuery() {}150 151 bool 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 line165 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');166 return true;167 }168 169 TextDialog::IntsTextQuery::IntsTextQuery(string title, std::string _description) :170 Dialog::IntsQuery(title,_description)171 {}172 173 TextDialog::IntsTextQuery::~IntsTextQuery() {}174 175 bool 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 also190 std::istringstream stream(string(olditer, line.end()));191 stream >> temp;192 tmp.push_back(temp);193 }194 195 return true;196 }197 198 TextDialog::BooleanTextQuery::BooleanTextQuery(string title, std::string _description) :199 Dialog::BooleanQuery(title,_description)200 {}201 202 TextDialog::BooleanTextQuery::~BooleanTextQuery() {}203 204 bool 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 line223 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');224 return true;225 }226 227 TextDialog::StringTextQuery::StringTextQuery(string title, std::string _description) :228 Dialog::StringQuery(title,_description)229 {}230 231 TextDialog::StringTextQuery::~StringTextQuery() {}232 233 bool TextDialog::StringTextQuery::handle() {234 Log() << Verbose(0) << getTitle();235 getline(cin,tmp);236 return true;237 }238 239 TextDialog::StringsTextQuery::StringsTextQuery(string title, std::string _description) :240 Dialog::StringsQuery(title,_description)241 {}242 243 TextDialog::StringsTextQuery::~StringsTextQuery() {}244 245 bool 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 also257 tmp.push_back(string(olditer, temp.end()));258 259 return true;260 }261 262 TextDialog::DoubleTextQuery::DoubleTextQuery(string title, std::string _description) :263 Dialog::DoubleQuery(title,_description)264 {}265 266 TextDialog::DoubleTextQuery::~DoubleTextQuery() {}267 268 bool 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 286 TextDialog::DoublesTextQuery::DoublesTextQuery(string title, std::string _description) :287 Dialog::DoublesQuery(title,_description)288 {}289 290 TextDialog::DoublesTextQuery::~DoublesTextQuery() {}291 292 bool 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 also307 std::istringstream stream(string(olditer, line.end()));308 stream >> temp;309 tmp.push_back(temp);310 }311 312 return true;313 }314 315 TextDialog::AtomTextQuery::AtomTextQuery(string title, std::string _description) :316 Dialog::AtomQuery(title,_description)317 {}318 319 TextDialog::AtomTextQuery::~AtomTextQuery() {}320 321 bool 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 348 TextDialog::AtomsTextQuery::AtomsTextQuery(string title, std::string _description) :349 Dialog::AtomsQuery(title,_description)350 {}351 352 TextDialog::AtomsTextQuery::~AtomsTextQuery() {}353 354 bool 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 also375 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 387 TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, std::string _description) :388 Dialog::MoleculeQuery(title,_description)389 {}390 391 TextDialog::MoleculeTextQuery::~MoleculeTextQuery() {}392 393 bool 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 420 TextDialog::MoleculesTextQuery::MoleculesTextQuery(string title, std::string _description) :421 Dialog::MoleculesQuery(title,_description)422 {}423 424 TextDialog::MoleculesTextQuery::~MoleculesTextQuery() {}425 426 bool 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 also447 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 459 TextDialog::VectorTextQuery::VectorTextQuery(std::string title, bool _check, std::string _description) :460 Dialog::VectorQuery(title,_check,_description)461 {}462 463 TextDialog::VectorTextQuery::~VectorTextQuery()464 {}465 466 bool 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 also489 std::istringstream stream(string(olditer, line.end()));490 stream >> coord;491 tmp[counter++] = coord;492 }493 494 // check vector495 return World::getInstance().getDomain().isInside(tmp);496 }497 498 TextDialog::VectorsTextQuery::VectorsTextQuery(std::string title, bool _check, std::string _description) :499 Dialog::VectorsQuery(title,_check,_description)500 {}501 502 TextDialog::VectorsTextQuery::~VectorsTextQuery()503 {}504 505 bool 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 also534 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 547 TextDialog::BoxTextQuery::BoxTextQuery(std::string title, std::string _description) :548 Dialog::BoxQuery(title,_description)549 {}550 551 TextDialog::BoxTextQuery::~BoxTextQuery()552 {}553 554 bool 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 577 TextDialog::ElementTextQuery::ElementTextQuery(std::string title, std::string _description) :578 Dialog::ElementQuery(title,_description)579 {}580 581 TextDialog::ElementTextQuery::~ElementTextQuery()582 {}583 584 bool 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 number593 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 shorthand613 // the last buffer content was not removed, so we read the614 // same thing again, this time as a std::string615 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 641 TextDialog::ElementsTextQuery::ElementsTextQuery(std::string title, std::string _description) :642 Dialog::ElementsQuery(title,_description)643 {}644 645 TextDialog::ElementsTextQuery::~ElementsTextQuery()646 {}647 648 bool 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 also675 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 692 TextDialog::FileTextQuery::FileTextQuery(string title, std::string _description) :693 Dialog::FileQuery(title,_description)694 {}695 696 TextDialog::FileTextQuery::~FileTextQuery() {}697 698 bool 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 TracChangeset
for help on using the changeset viewer.