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