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