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