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