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