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