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