- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/TextUI/TextDialog.cpp
r112b09 r680470 14 14 #include <Descriptors/MoleculeDescriptor.hpp> 15 15 #include <Descriptors/MoleculeIdDescriptor.hpp> 16 #include <boost/lexical_cast.hpp> 16 17 #include "TextUI/TextDialog.hpp" 17 18 … … 25 26 #include "molecule.hpp" 26 27 #include "vector.hpp" 28 #include "Matrix.hpp" 29 #include "Box.hpp" 27 30 28 31 using namespace std; 32 33 using boost::lexical_cast; 34 using boost::bad_lexical_cast; 29 35 30 36 … … 42 48 } 43 49 44 void TextDialog::queryBoolean(const char* title, bool* target, string description){ 45 registerQuery(new BooleanTextQuery(title,target,description)); 46 } 47 48 void TextDialog::queryInt(const char* title, int* target, string description){ 49 registerQuery(new IntTextQuery(title,target,description)); 50 } 51 52 void TextDialog::queryDouble(const char* title, double* target, string description){ 53 registerQuery(new DoubleTextQuery(title,target,description)); 54 } 55 56 void TextDialog::queryString(const char* title, string* target, string description){ 57 registerQuery(new StringTextQuery(title,target,description)); 58 } 59 60 void TextDialog::queryAtom(const char* title, atom **target, string description) { 61 registerQuery(new AtomTextQuery(title,target,description)); 62 } 63 64 void TextDialog::queryMolecule(const char* title, molecule **target, string description) { 65 registerQuery(new MoleculeTextQuery(title,target,description)); 66 } 67 68 void TextDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check, string description) { 69 registerQuery(new VectorTextQuery(title,target,cellSize,check,description)); 70 } 71 72 void TextDialog::queryBox(const char* title,double ** const cellSize, string description) { 73 registerQuery(new BoxTextQuery(title,cellSize,description)); 74 } 75 76 void TextDialog::queryElement(const char* title, const element **target, string description){ 77 registerQuery(new ElementTextQuery(title,target,description)); 50 void TextDialog::queryBoolean(const char* title, string description){ 51 registerQuery(new BooleanTextQuery(title,description)); 52 } 53 54 void TextDialog::queryInt(const char* title, string description){ 55 registerQuery(new IntTextQuery(title,description)); 56 } 57 58 void TextDialog::queryInts(const char* title, string description){ 59 registerQuery(new IntsTextQuery(title,description)); 60 } 61 62 void TextDialog::queryDouble(const char* title, string description){ 63 registerQuery(new DoubleTextQuery(title,description)); 64 } 65 66 void TextDialog::queryDoubles(const char* title, string description){ 67 registerQuery(new DoublesTextQuery(title,description)); 68 } 69 70 void TextDialog::queryString(const char* title, string description){ 71 registerQuery(new StringTextQuery(title,description)); 72 } 73 74 void TextDialog::queryStrings(const char* title, string description){ 75 registerQuery(new StringsTextQuery(title,description)); 76 } 77 78 void TextDialog::queryAtom(const char* title, string description) { 79 registerQuery(new AtomTextQuery(title,description)); 80 } 81 82 void TextDialog::queryAtoms(const char* title, string description) { 83 registerQuery(new AtomsTextQuery(title,description)); 84 } 85 86 void TextDialog::queryMolecule(const char* title, string description) { 87 registerQuery(new MoleculeTextQuery(title,description)); 88 } 89 90 void TextDialog::queryMolecules(const char* title, string description) { 91 registerQuery(new MoleculesTextQuery(title,description)); 92 } 93 94 void TextDialog::queryVector(const char* title, bool check, string description) { 95 registerQuery(new VectorTextQuery(title,check,description)); 96 } 97 98 void TextDialog::queryVectors(const char* title, bool check, string description) { 99 registerQuery(new VectorsTextQuery(title,check,description)); 100 } 101 102 void TextDialog::queryBox(const char* title, string description) { 103 registerQuery(new BoxTextQuery(title,description)); 104 } 105 106 void TextDialog::queryElement(const char* title, string description){ 107 registerQuery(new ElementTextQuery(title,description)); 108 } 109 110 void TextDialog::queryElements(const char* title, string description){ 111 registerQuery(new ElementsTextQuery(title,description)); 78 112 } 79 113 … … 91 125 } 92 126 93 TextDialog::IntTextQuery::IntTextQuery(string title, int * _target,std::string _description) :94 Dialog::IntQuery(title,_ target,_description)127 TextDialog::IntTextQuery::IntTextQuery(string title, std::string _description) : 128 Dialog::IntQuery(title,_description) 95 129 {} 96 130 … … 115 149 } 116 150 117 TextDialog::BooleanTextQuery::BooleanTextQuery(string title, bool * _target, std::string _description) : 118 Dialog::BooleanQuery(title,_target,_description) 151 TextDialog::IntsTextQuery::IntsTextQuery(string title, std::string _description) : 152 Dialog::IntsQuery(title,_description) 153 {} 154 155 TextDialog::IntsTextQuery::~IntsTextQuery() {} 156 157 bool TextDialog::IntsTextQuery::handle() { 158 Log() << Verbose(0) << getTitle(); 159 std::string line; 160 getline(cin,line); 161 // dissect by " " 162 string::iterator olditer = line.begin(); 163 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) { 164 if (*iter == ' ') { 165 std::istringstream stream(string(iter, olditer)); 166 stream >> temp; 167 tmp.push_back(temp); 168 olditer = iter; 169 } 170 } 171 if (olditer != line.begin()) { // insert last part also 172 std::istringstream stream(string(olditer, line.end())); 173 stream >> temp; 174 tmp.push_back(temp); 175 } 176 177 return true; 178 } 179 180 TextDialog::BooleanTextQuery::BooleanTextQuery(string title, std::string _description) : 181 Dialog::BooleanQuery(title,_description) 119 182 {} 120 183 … … 144 207 } 145 208 146 TextDialog::StringTextQuery::StringTextQuery(string title, string *_target,std::string _description) :147 Dialog::StringQuery(title,_ target,_description)209 TextDialog::StringTextQuery::StringTextQuery(string title, std::string _description) : 210 Dialog::StringQuery(title,_description) 148 211 {} 149 212 … … 156 219 } 157 220 158 TextDialog::DoubleTextQuery::DoubleTextQuery(string title,double *_target, std::string _description) : 159 Dialog::DoubleQuery(title,_target,_description) 221 TextDialog::StringsTextQuery::StringsTextQuery(string title, std::string _description) : 222 Dialog::StringsQuery(title,_description) 223 {} 224 225 TextDialog::StringsTextQuery::~StringsTextQuery() {} 226 227 bool TextDialog::StringsTextQuery::handle() { 228 Log() << Verbose(0) << getTitle(); 229 getline(cin,temp); 230 // dissect by " " 231 string::iterator olditer = temp.begin(); 232 for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) { 233 if (*iter == ' ') { 234 tmp.push_back(string(iter, olditer)); 235 olditer = iter; 236 } 237 } 238 if (olditer != temp.begin()) // insert last part also 239 tmp.push_back(string(olditer, temp.end())); 240 241 return true; 242 } 243 244 TextDialog::DoubleTextQuery::DoubleTextQuery(string title, std::string _description) : 245 Dialog::DoubleQuery(title,_description) 160 246 {} 161 247 … … 179 265 } 180 266 181 TextDialog::AtomTextQuery::AtomTextQuery(string title, atom **_target, std::string _description) : 182 Dialog::AtomQuery(title,_target,_description) 267 268 TextDialog::DoublesTextQuery::DoublesTextQuery(string title, std::string _description) : 269 Dialog::DoublesQuery(title,_description) 270 {} 271 272 TextDialog::DoublesTextQuery::~DoublesTextQuery() {} 273 274 bool TextDialog::DoublesTextQuery::handle() { 275 Log() << Verbose(0) << getTitle(); 276 std::string line; 277 getline(cin,line); 278 // dissect by " " 279 string::iterator olditer = line.begin(); 280 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) { 281 if (*iter == ' ') { 282 std::istringstream stream(string(iter, olditer)); 283 stream >> temp; 284 tmp.push_back(temp); 285 olditer = iter; 286 } 287 } 288 if (olditer != line.begin()) { // insert last part also 289 std::istringstream stream(string(olditer, line.end())); 290 stream >> temp; 291 tmp.push_back(temp); 292 } 293 294 return true; 295 } 296 297 TextDialog::AtomTextQuery::AtomTextQuery(string title, std::string _description) : 298 Dialog::AtomQuery(title,_description) 183 299 {} 184 300 … … 186 302 187 303 bool TextDialog::AtomTextQuery::handle() { 188 int idxOfAtom= 0;304 int idxOfAtom=-1; 189 305 bool badInput = false; 190 306 do{ … … 202 318 tmp = World::getInstance().getAtom(AtomById(idxOfAtom)); 203 319 if(!tmp && idxOfAtom!=-1){ 204 Log() << Verbose(0) << "Invalid Atom Index" << endl;320 Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl; 205 321 badInput = true; 206 322 } … … 211 327 } 212 328 213 TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, molecule **_target, std::string _description) : 214 Dialog::MoleculeQuery(title,_target,_description) 329 330 TextDialog::AtomsTextQuery::AtomsTextQuery(string title, std::string _description) : 331 Dialog::AtomsQuery(title,_description) 332 {} 333 334 TextDialog::AtomsTextQuery::~AtomsTextQuery() {} 335 336 bool TextDialog::AtomsTextQuery::handle() { 337 int idxOfAtom=-1; 338 Log() << Verbose(0) << getTitle(); 339 std::string line; 340 getline(cin,line); 341 // dissect by " " 342 string::iterator olditer = line.begin(); 343 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) { 344 if (*iter == ' ') { 345 std::istringstream stream(string(iter, olditer)); 346 stream >> idxOfAtom; 347 temp = World::getInstance().getAtom(AtomById(idxOfAtom)); 348 if(!temp && idxOfAtom!=-1){ 349 Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl; 350 break; 351 } 352 tmp.push_back(temp); 353 olditer = iter; 354 } 355 } 356 if (olditer != line.begin()) { // insert last part also 357 std::istringstream stream(string(olditer, line.end())); 358 stream >> idxOfAtom; 359 temp = World::getInstance().getAtom(AtomById(idxOfAtom)); 360 if(!temp && idxOfAtom!=-1) { 361 Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl; 362 tmp.push_back(temp); 363 } 364 } 365 366 return (idxOfAtom!=-1); 367 } 368 369 TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, std::string _description) : 370 Dialog::MoleculeQuery(title,_description) 215 371 {} 216 372 … … 243 399 } 244 400 245 TextDialog::VectorTextQuery::VectorTextQuery(std::string title, Vector *_target, const double *const _cellSize, bool _check, std::string _description) : 246 Dialog::VectorQuery(title,_target,_cellSize,_check,_description) 401 402 TextDialog::MoleculesTextQuery::MoleculesTextQuery(string title, std::string _description) : 403 Dialog::MoleculesQuery(title,_description) 404 {} 405 406 TextDialog::MoleculesTextQuery::~MoleculesTextQuery() {} 407 408 bool TextDialog::MoleculesTextQuery::handle() { 409 int idxOfMol=-1; 410 Log() << Verbose(0) << getTitle(); 411 std::string line; 412 getline(cin,line); 413 // dissect by " " 414 string::iterator olditer = line.begin(); 415 for(string::iterator iter = line.begin(); iter != line.end(); ++iter) { 416 if (*iter == ' ') { 417 std::istringstream stream(string(iter, olditer)); 418 stream >> idxOfMol; 419 temp = World::getInstance().getMolecule(MoleculeById(idxOfMol)); 420 if(!temp && idxOfMol!=-1){ 421 Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl; 422 break; 423 } 424 tmp.push_back(temp); 425 olditer = iter; 426 } 427 } 428 if (olditer != line.begin()) { // insert last part also 429 std::istringstream stream(string(olditer, line.end())); 430 stream >> idxOfMol; 431 temp = World::getInstance().getMolecule(MoleculeById(idxOfMol)); 432 if(!temp && idxOfMol!=-1){ 433 Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl; 434 tmp.push_back(temp); 435 } 436 } 437 438 return (idxOfMol!=-1); 439 } 440 441 TextDialog::VectorTextQuery::VectorTextQuery(std::string title, bool _check, std::string _description) : 442 Dialog::VectorQuery(title,_check,_description) 247 443 {} 248 444 … … 251 447 252 448 bool TextDialog::VectorTextQuery::handle() { 253 Log() << Verbose(0) << getTitle(); 254 255 char coords[3] = {'x','y','z'}; 256 int j = -1; 257 for (int i=0;i<3;i++) { 258 j += i+1; 259 do { 260 Log() << Verbose(0) << coords[i] << "[0.." << cellSize[j] << "]: "; 261 cin >> (*tmp)[i]; 262 } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= cellSize[j])) && (check)); 263 } 264 return true; 265 } 266 267 TextDialog::BoxTextQuery::BoxTextQuery(std::string title, double ** const _cellSize, std::string _description) : 268 Dialog::BoxQuery(title,_cellSize,_description) 449 std::cout << getTitle(); 450 const Matrix &M = World::getInstance().getDomain().getM(); 451 char coords[3] = {'x', 'y', 'z'}; 452 for (int i=0;i<3;i++) 453 std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: "); 454 455 std::string line; 456 getline(cin,line); 457 458 // dissect by "," 459 double coord = 0.; 460 int counter = 0; 461 string::iterator olditer = line.begin(); 462 for(string::iterator iter = line.begin(); (iter != line.end()) && (counter != 3); ++iter) { 463 if (*iter == ',') { 464 std::istringstream stream(string(iter, olditer)); 465 stream >> coord; 466 tmp[counter++] = coord; 467 olditer = iter; 468 } 469 } 470 if ((olditer != line.begin()) && (counter != 3)) { // insert last part also 471 std::istringstream stream(string(olditer, line.end())); 472 stream >> coord; 473 tmp[counter++] = coord; 474 } 475 476 // check vector 477 return World::getInstance().getDomain().isInside(tmp); 478 } 479 480 TextDialog::VectorsTextQuery::VectorsTextQuery(std::string title, bool _check, std::string _description) : 481 Dialog::VectorsQuery(title,_check,_description) 482 {} 483 484 TextDialog::VectorsTextQuery::~VectorsTextQuery() 485 {} 486 487 bool TextDialog::VectorsTextQuery::handle() { 488 std::cout << getTitle(); 489 char coords[3] = {'x', 'y', 'z'}; 490 const Matrix &M = World::getInstance().getDomain().getM(); 491 for (int i=0;i<3;i++) 492 std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: "); 493 494 std::string line; 495 getline(cin,line); 496 497 // dissect by "," 498 double coord = 0.; 499 string::iterator olditerspace = line.begin(); 500 string::iterator olditercomma = line.begin(); 501 int counter = 0; 502 for(string::iterator vectoriter = line.begin(); vectoriter != line.end(); ++vectoriter) { 503 if (*vectoriter == ',') 504 counter++; 505 if ((*vectoriter == ' ') && (counter == 2)) { 506 counter = 0; 507 for(string::iterator componentiter = olditerspace; (componentiter != vectoriter) && (counter !=3); ++componentiter) { 508 if (*componentiter == ',') { 509 std::istringstream stream(string(componentiter, olditercomma)); 510 stream >> coord; 511 temp[counter++] = coord; 512 olditercomma = componentiter; 513 } 514 } 515 if ((olditercomma != line.begin()) && (counter != 3)) { // insert last part also 516 std::istringstream stream(string(olditercomma, vectoriter)); 517 stream >> coord; 518 temp[counter++] = coord; 519 } 520 if (World::getInstance().getDomain().isInside(temp)) 521 tmp.push_back(temp); 522 olditerspace = vectoriter; 523 } 524 } 525 return true; 526 } 527 528 TextDialog::BoxTextQuery::BoxTextQuery(std::string title, std::string _description) : 529 Dialog::BoxQuery(title,_description) 269 530 {} 270 531 … … 275 536 Log() << Verbose(0) << getTitle(); 276 537 277 std::string coords[6] = {"xx","xy","xz", "yy", "yz", "zz"}; 538 double temp[6]; 539 std::string coords[6] = {"xx","yx","yy", "zx", "zy", "zz"}; 278 540 for (int i=0;i<6;i++) { 279 541 Log() << Verbose(0) << coords[i] << ": "; 280 cin >> tmp[i]; 281 } 282 return true; 283 } 284 285 TextDialog::ElementTextQuery::ElementTextQuery(std::string title, const element **target, std::string _description) : 286 Dialog::ElementQuery(title,target,_description) 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) 287 560 {} 288 561 … … 293 566 bool badInput=false; 294 567 bool aborted = false; 568 element * temp = NULL; 295 569 do{ 296 570 badInput = false; … … 305 579 } 306 580 else{ 307 t mp = World::getInstance().getPeriode()->FindElement(Z);308 if(!t mp){581 temp = World::getInstance().getPeriode()->FindElement(Z); 582 if(!temp){ 309 583 Log() << Verbose(0) << "No element with this atomic number!" << endl; 310 584 badInput = true; … … 327 601 } 328 602 else{ 329 t mp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());330 if(!t mp){603 temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str()); 604 if(!temp){ 331 605 Log() << Verbose(0) << "No element with this shorthand!" << endl; 332 606 badInput = true; … … 345 619 return !aborted; 346 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 }
Note:
See TracChangeset
for help on using the changeset viewer.