| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * TextDialog.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: Jan 5, 2010
|
|---|
| 12 | * Author: crueger
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | // include config.h
|
|---|
| 16 | #ifdef HAVE_CONFIG_H
|
|---|
| 17 | #include <config.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #include "Helpers/MemDebug.hpp"
|
|---|
| 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 | #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 |
|
|---|
| 46 | using namespace std;
|
|---|
| 47 |
|
|---|
| 48 | using boost::lexical_cast;
|
|---|
| 49 | using boost::bad_lexical_cast;
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | TextDialog::TextDialog()
|
|---|
| 53 | {
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | TextDialog::~TextDialog()
|
|---|
| 57 | {
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | void TextDialog::queryEmpty(const char* title, std::string description){
|
|---|
| 61 | registerQuery(new EmptyTextQuery(title,description));
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void TextDialog::queryBoolean(const char* title, std::string description){
|
|---|
| 65 | registerQuery(new BooleanTextQuery(title,description));
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void TextDialog::queryInt(const char* title, std::string description){
|
|---|
| 69 | registerQuery(new IntTextQuery(title,description));
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | void TextDialog::queryInts(const char* title, std::string description){
|
|---|
| 73 | registerQuery(new IntsTextQuery(title,description));
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | void TextDialog::queryDouble(const char* title, std::string description){
|
|---|
| 77 | registerQuery(new DoubleTextQuery(title,description));
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | void TextDialog::queryDoubles(const char* title, std::string description){
|
|---|
| 81 | registerQuery(new DoublesTextQuery(title,description));
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | void TextDialog::queryString(const char* title, std::string description){
|
|---|
| 85 | registerQuery(new StringTextQuery(title,description));
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | void TextDialog::queryStrings(const char* title, std::string description){
|
|---|
| 89 | registerQuery(new StringsTextQuery(title,description));
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | void TextDialog::queryAtom(const char* title, std::string description) {
|
|---|
| 93 | registerQuery(new AtomTextQuery(title,description));
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | void TextDialog::queryAtoms(const char* title, std::string description) {
|
|---|
| 97 | registerQuery(new AtomsTextQuery(title,description));
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | void TextDialog::queryMolecule(const char* title, std::string description) {
|
|---|
| 101 | registerQuery(new MoleculeTextQuery(title,description));
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | void TextDialog::queryMolecules(const char* title, std::string description) {
|
|---|
| 105 | registerQuery(new MoleculesTextQuery(title,description));
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | void TextDialog::queryVector(const char* title, bool check, std::string description) {
|
|---|
| 109 | registerQuery(new VectorTextQuery(title,check,description));
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | void TextDialog::queryVectors(const char* title, bool check, std::string description) {
|
|---|
| 113 | registerQuery(new VectorsTextQuery(title,check,description));
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | void TextDialog::queryBox(const char* title, std::string description) {
|
|---|
| 117 | registerQuery(new BoxTextQuery(title,description));
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | void TextDialog::queryElement(const char* title, std::string description){
|
|---|
| 121 | registerQuery(new ElementTextQuery(title,description));
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | void TextDialog::queryElements(const char* title, std::string description){
|
|---|
| 125 | registerQuery(new ElementsTextQuery(title,description));
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | void TextDialog::queryFile(const char* title, std::string description){
|
|---|
| 129 | registerQuery(new FileTextQuery(title,description));
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | /************************** Query Infrastructure ************************/
|
|---|
| 133 |
|
|---|
| 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 line
|
|---|
| 165 | 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 also
|
|---|
| 190 | 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 line
|
|---|
| 223 | 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 also
|
|---|
| 257 | 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 also
|
|---|
| 307 | 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 also
|
|---|
| 375 | 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 also
|
|---|
| 447 | 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 also
|
|---|
| 489 | std::istringstream stream(string(olditer, line.end()));
|
|---|
| 490 | stream >> coord;
|
|---|
| 491 | tmp[counter++] = coord;
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | // check vector
|
|---|
| 495 | 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 also
|
|---|
| 534 | 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 number
|
|---|
| 593 | 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 shorthand
|
|---|
| 613 | // the last buffer content was not removed, so we read the
|
|---|
| 614 | // same thing again, this time as a std::string
|
|---|
| 615 | 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 also
|
|---|
| 675 | 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 |
|
|---|