- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/CommandLineUI/CommandLineDialog.cpp
r112b09 r8467df 8 8 #include "Helpers/MemDebug.hpp" 9 9 10 #include <cassert>11 10 #include <iostream> 11 #include <vector> 12 12 13 13 #include <Descriptors/AtomDescriptor.hpp> … … 17 17 #include "CommandLineUI/CommandLineDialog.hpp" 18 18 19 #include "Actions/Values.hpp" 20 19 21 #include "element.hpp" 20 22 #include "periodentafel.hpp" … … 22 24 #include "defs.hpp" 23 25 #include "log.hpp" 26 #include "Matrix.hpp" 24 27 #include "periodentafel.hpp" 25 28 #include "verbose.hpp" 26 29 #include "World.hpp" 30 #include "Box.hpp" 27 31 28 32 #include "atom.hpp" … … 47 51 } 48 52 49 void CommandLineDialog::queryInt(const char* title, int* target, string _description){ 50 registerQuery(new IntCommandLineQuery(title,target, _description)); 51 } 52 53 void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){ 54 registerQuery(new BooleanCommandLineQuery(title,target, _description)); 55 } 56 57 void CommandLineDialog::queryDouble(const char* title, double* target, string _description){ 58 registerQuery(new DoubleCommandLineQuery(title,target, _description)); 59 } 60 61 void CommandLineDialog::queryString(const char* title, string* target, string _description){ 62 registerQuery(new StringCommandLineQuery(title,target, _description)); 63 } 64 65 void CommandLineDialog::queryAtom(const char* title, atom **target, string _description) { 66 registerQuery(new AtomCommandLineQuery(title,target, _description)); 67 } 68 69 void CommandLineDialog::queryMolecule(const char* title, molecule **target, string _description) { 70 registerQuery(new MoleculeCommandLineQuery(title,target, _description)); 71 } 72 73 void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check, string _description) { 74 registerQuery(new VectorCommandLineQuery(title,target,cellSize,check, _description)); 75 } 76 77 void CommandLineDialog::queryBox(const char* title, double ** const cellSize, string _description) { 78 registerQuery(new BoxCommandLineQuery(title,cellSize,_description)); 79 } 80 81 void CommandLineDialog::queryElement(const char* title, const element **target, string _description){ 82 registerQuery(new ElementCommandLineQuery(title,target, _description)); 53 void CommandLineDialog::queryInt(const char* title, string _description){ 54 registerQuery(new IntCommandLineQuery(title, _description)); 55 } 56 57 void CommandLineDialog::queryInts(const char* title, string _description){ 58 registerQuery(new IntsCommandLineQuery(title, _description)); 59 } 60 61 void CommandLineDialog::queryBoolean(const char* title, string _description){ 62 registerQuery(new BooleanCommandLineQuery(title, _description)); 63 } 64 65 void CommandLineDialog::queryDouble(const char* title, string _description){ 66 registerQuery(new DoubleCommandLineQuery(title, _description)); 67 } 68 69 void CommandLineDialog::queryDoubles(const char* title, string _description){ 70 registerQuery(new DoublesCommandLineQuery(title, _description)); 71 } 72 73 void CommandLineDialog::queryString(const char* title, string _description){ 74 registerQuery(new StringCommandLineQuery(title, _description)); 75 } 76 77 void CommandLineDialog::queryStrings(const char* title, string _description){ 78 registerQuery(new StringsCommandLineQuery(title, _description)); 79 } 80 81 void CommandLineDialog::queryAtom(const char* title, string _description) { 82 registerQuery(new AtomCommandLineQuery(title, _description)); 83 } 84 85 void CommandLineDialog::queryAtoms(const char* title, string _description) { 86 registerQuery(new AtomsCommandLineQuery(title, _description)); 87 } 88 89 void CommandLineDialog::queryMolecule(const char* title, string _description) { 90 registerQuery(new MoleculeCommandLineQuery(title, _description)); 91 } 92 93 void CommandLineDialog::queryMolecules(const char* title, string _description) { 94 registerQuery(new MoleculesCommandLineQuery(title, _description)); 95 } 96 97 void CommandLineDialog::queryVector(const char* title, bool check, string _description) { 98 registerQuery(new VectorCommandLineQuery(title,check, _description)); 99 } 100 101 void CommandLineDialog::queryVectors(const char* title, bool check, string _description) { 102 registerQuery(new VectorsCommandLineQuery(title,check, _description)); 103 } 104 105 void CommandLineDialog::queryBox(const char* title, string _description) { 106 registerQuery(new BoxCommandLineQuery(title,_description)); 107 } 108 109 void CommandLineDialog::queryElement(const char* title, string _description){ 110 registerQuery(new ElementCommandLineQuery(title, _description)); 111 } 112 113 void CommandLineDialog::queryElements(const char* title, string _description){ 114 registerQuery(new ElementsCommandLineQuery(title, _description)); 83 115 } 84 116 … … 96 128 } 97 129 98 CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title, int *_target,string _description) :99 Dialog::IntQuery(title, _target,_description)130 CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title, string _description) : 131 Dialog::IntQuery(title, _description) 100 132 {} 101 133 … … 106 138 tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>(); 107 139 return true; 108 } else 109 return false; 110 } 111 112 CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) : 113 Dialog::BooleanQuery(title,_target, _description) 140 } else { 141 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl); 142 return false; 143 } 144 } 145 146 CommandLineDialog::IntsCommandLineQuery::IntsCommandLineQuery(string title, string _description) : 147 Dialog::IntsQuery(title, _description) 148 {} 149 150 CommandLineDialog::IntsCommandLineQuery::~IntsCommandLineQuery() {} 151 152 bool CommandLineDialog::IntsCommandLineQuery::handle() { 153 if (CommandLineParser::getInstance().vm.count(getTitle())) { 154 tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >(); 155 return true; 156 } else { 157 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integers for " << getTitle() << "." << endl); 158 return false; 159 } 160 } 161 162 CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title, string _description) : 163 Dialog::BooleanQuery(title, _description) 114 164 {} 115 165 … … 117 167 118 168 bool CommandLineDialog::BooleanCommandLineQuery::handle() { 119 bool badInput = false; 120 char input = ' '; 121 do{ 122 badInput = false; 123 Log() << Verbose(0) << getTitle(); 124 cin >> input; 125 if ((input == 'y' ) || (input == 'Y')) { 126 tmp = true; 127 } else if ((input == 'n' ) || (input == 'N')) { 128 tmp = false; 129 } else { 130 badInput=true; 131 cin.clear(); 132 cin.ignore(std::numeric_limits<streamsize>::max(),'\n'); 133 Log() << Verbose(0) << "Input was not of [yYnN]!" << endl; 134 } 135 } while(badInput); 136 // clear the input buffer of anything still in the line 137 cin.ignore(std::numeric_limits<streamsize>::max(),'\n'); 138 return true; 139 } 140 141 CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) : 142 Dialog::StringQuery(title,_target, _description) 169 if (CommandLineParser::getInstance().vm.count(getTitle())) { 170 tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>(); 171 return true; 172 } else { 173 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl); 174 return false; 175 } 176 } 177 178 CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title, string _description) : 179 Dialog::StringQuery(title, _description) 143 180 {} 144 181 … … 149 186 tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>(); 150 187 return true; 151 } else 152 return false; 153 } 154 155 CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) : 156 Dialog::DoubleQuery(title,_target, _description) 188 } else { 189 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl); 190 return false; 191 } 192 } 193 194 CommandLineDialog::StringsCommandLineQuery::StringsCommandLineQuery(string title, string _description) : 195 Dialog::StringsQuery(title, _description) 196 {} 197 198 CommandLineDialog::StringsCommandLineQuery::~StringsCommandLineQuery() {} 199 200 bool CommandLineDialog::StringsCommandLineQuery::handle() { 201 if (CommandLineParser::getInstance().vm.count(getTitle())) { 202 tmp = CommandLineParser::getInstance().vm[getTitle()].as< vector<string> >(); 203 return true; 204 } else { 205 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing strings for " << getTitle() << "." << endl); 206 return false; 207 } 208 } 209 210 CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title, string _description) : 211 Dialog::DoubleQuery(title, _description) 157 212 {} 158 213 … … 163 218 tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>(); 164 219 return true; 165 } else 166 return false; 167 } 168 169 CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) : 170 Dialog::AtomQuery(title,_target, _description) 220 } else { 221 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl); 222 return false; 223 } 224 } 225 226 CommandLineDialog::DoublesCommandLineQuery::DoublesCommandLineQuery(string title, string _description) : 227 Dialog::DoublesQuery(title, _description) 228 {} 229 230 CommandLineDialog::DoublesCommandLineQuery::~DoublesCommandLineQuery() {} 231 232 bool CommandLineDialog::DoublesCommandLineQuery::handle() { 233 if (CommandLineParser::getInstance().vm.count(getTitle())) { 234 tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<double> >(); 235 return true; 236 } else { 237 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing doubles for " << getTitle() << "." << endl); 238 return false; 239 } 240 } 241 242 CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, string _description) : 243 Dialog::AtomQuery(title, _description) 171 244 {} 172 245 … … 179 252 tmp = World::getInstance().getAtom(AtomById(IdxOfAtom)); 180 253 return true; 181 } else 182 return false; 183 } 184 185 CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) : 186 Dialog::MoleculeQuery(title,_target, _description) 254 } else { 255 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl); 256 return false; 257 } 258 } 259 260 CommandLineDialog::AtomsCommandLineQuery::AtomsCommandLineQuery(string title, string _description) : 261 Dialog::AtomsQuery(title, _description) 262 {} 263 264 CommandLineDialog::AtomsCommandLineQuery::~AtomsCommandLineQuery() {} 265 266 bool CommandLineDialog::AtomsCommandLineQuery::handle() { 267 std::vector<int> IdxOfAtom; 268 if (CommandLineParser::getInstance().vm.count(getTitle())) { 269 IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >(); 270 for (std::vector<int>::iterator iter = IdxOfAtom.begin(); iter != IdxOfAtom.end(); ++iter) { 271 temp = World::getInstance().getAtom(AtomById(*iter)); 272 if (temp) 273 tmp.push_back(temp); 274 } 275 return true; 276 } else { 277 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atoms for " << getTitle() << "." << endl); 278 return false; 279 } 280 } 281 282 CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, string _description) : 283 Dialog::MoleculeQuery(title, _description) 187 284 {} 188 285 … … 193 290 if (CommandLineParser::getInstance().vm.count(getTitle())) { 194 291 IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>(); 195 cout << "IdxOfMol " << IdxOfMol << endl; 196 if (IdxOfMol >= 0) 197 tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol)); 198 else 199 tmp = NULL; 200 return true; 201 } else 202 return false; 203 } 204 205 CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) : 206 Dialog::VectorQuery(title,_target,_cellSize,_check, _description) 292 tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol)); 293 return true; 294 } else { 295 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl); 296 return false; 297 } 298 } 299 300 CommandLineDialog::MoleculesCommandLineQuery::MoleculesCommandLineQuery(string title, string _description) : 301 Dialog::MoleculesQuery(title, _description) 302 {} 303 304 CommandLineDialog::MoleculesCommandLineQuery::~MoleculesCommandLineQuery() {} 305 306 bool CommandLineDialog::MoleculesCommandLineQuery::handle() { 307 std::vector<int> IdxOfMol; 308 if (CommandLineParser::getInstance().vm.count(getTitle())) { 309 IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >(); 310 for (std::vector<int>::iterator iter = IdxOfMol.begin(); iter != IdxOfMol.end(); ++iter) { 311 temp = World::getInstance().getMolecule(MoleculeById(*iter)); 312 if (temp) 313 tmp.push_back(temp); 314 } 315 return true; 316 } else { 317 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecules for " << getTitle() << "." << endl); 318 return false; 319 } 320 } 321 322 CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, bool _check, string _description) : 323 Dialog::VectorQuery(title,_check, _description) 207 324 {} 208 325 … … 211 328 212 329 bool CommandLineDialog::VectorCommandLineQuery::handle() { 213 vector<double> temp; 214 if (CommandLineParser::getInstance().vm.count(getTitle())) { 215 temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >(); 216 assert((temp.size() == 3) && "Vector from command line does not have three components."); 217 for (int i=0;i<NDIM;i++) 218 tmp->at(i) = temp[i]; 219 return true; 220 } else 221 return false; 222 } 223 224 225 CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, double ** const _cellSize, string _description) : 226 Dialog::BoxQuery(title,_cellSize, _description) 330 VectorValue temp; 331 if (CommandLineParser::getInstance().vm.count(getTitle())) { 332 temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >(); 333 tmp[0] = temp.x; 334 tmp[1] = temp.y; 335 tmp[2] = temp.z; 336 if ((check) && (!World::getInstance().getDomain().isInside(tmp))) { 337 DoeLog(1) && (eLog() << Verbose(1) << "Vector " << tmp << " would be outside of box domain." << endl); 338 return false; 339 } 340 return true; 341 } else { 342 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl); 343 return false; 344 } 345 } 346 347 CommandLineDialog::VectorsCommandLineQuery::VectorsCommandLineQuery(string title, bool _check, string _description) : 348 Dialog::VectorsQuery(title,_check, _description) 349 {} 350 351 CommandLineDialog::VectorsCommandLineQuery::~VectorsCommandLineQuery() 352 {} 353 354 bool CommandLineDialog::VectorsCommandLineQuery::handle() { 355 std::vector<VectorValue> temporary; 356 if (CommandLineParser::getInstance().vm.count(getTitle())) { 357 temporary = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<VectorValue> >(); 358 for(std::vector<VectorValue>::iterator iter = temporary.begin(); iter != temporary.end(); ++iter) { 359 temp[0] = (*iter).x; 360 temp[1] = (*iter).y; 361 temp[2] = (*iter).z; 362 if ((!check) || (World::getInstance().getDomain().isInside(temp))) 363 tmp.push_back(temp); 364 else 365 DoeLog(1) && (eLog() << Verbose(1) << "Vector " << temp << " would be outside of box domain." << endl); 366 } 367 return true; 368 } else { 369 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vectors for " << getTitle() << "." << endl); 370 return false; 371 } 372 } 373 374 CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, string _description) : 375 Dialog::BoxQuery(title, _description) 227 376 {} 228 377 … … 231 380 232 381 bool CommandLineDialog::BoxCommandLineQuery::handle() { 233 vector<double> temp; 234 if (CommandLineParser::getInstance().vm.count(getTitle())) { 235 temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >(); 236 assert((temp.size() == 6) && "Symmetric box matrix from command line does not have six components."); 237 for (int i=0;i<6;i++) { 238 tmp[i] = temp[i]; 239 } 240 return true; 241 } else 242 return false; 243 } 244 245 CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, const element **target, string _description) : 246 Dialog::ElementQuery(title,target, _description) 382 BoxValue temp; 383 if (CommandLineParser::getInstance().vm.count(getTitle())) { 384 temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >(); 385 Matrix M; 386 M.set(0,0, temp.xx); 387 M.set(0,1, temp.yx); 388 M.set(0,2, temp.zx); 389 M.set(1,0, temp.yx); 390 M.set(1,1, temp.yy); 391 M.set(1,2, temp.zy); 392 M.set(2,0, temp.zx); 393 M.set(2,1, temp.zy); 394 M.set(2,2, temp.zz); 395 tmp.setM(M); 396 return true; 397 } else { 398 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl); 399 return false; 400 } 401 } 402 403 CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, string _description) : 404 Dialog::ElementQuery(title, _description) 247 405 {} 248 406 … … 252 410 bool CommandLineDialog::ElementCommandLineQuery::handle() { 253 411 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector? 254 int Z; 412 periodentafel *periode = World::getInstance().getPeriode(); 413 if (CommandLineParser::getInstance().vm.count(getTitle())) { 414 int Z = CommandLineParser::getInstance().vm[getTitle()].as< int >(); 415 tmp = periode->FindElement(Z); 416 ASSERT(tmp != NULL, "Invalid element specified in ElementCommandLineQuery"); 417 return true; 418 } else { 419 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl); 420 return false; 421 } 422 } 423 424 CommandLineDialog::ElementsCommandLineQuery::ElementsCommandLineQuery(string title, string _description) : 425 Dialog::ElementsQuery(title, _description) 426 {} 427 428 CommandLineDialog::ElementsCommandLineQuery::~ElementsCommandLineQuery() 429 {} 430 431 bool CommandLineDialog::ElementsCommandLineQuery::handle() { 432 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector? 433 periodentafel *periode = World::getInstance().getPeriode(); 255 434 if (CommandLineParser::getInstance().vm.count(getTitle())) { 256 435 vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >(); 257 vector<int>::iterator ElementRunner = AllElements.begin(); 258 Z = *ElementRunner; 259 // TODO: So far, this does not really erase the element in the parsed list. 260 AllElements.erase(ElementRunner); 261 tmp = World::getInstance().getPeriode()->FindElement(Z); 262 return true; 263 } else 264 return false; 265 } 436 for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) { 437 temp = periode->FindElement(*ZRunner); 438 ASSERT(temp != NULL, "Invalid element specified in ElementCommandLineQuery"); 439 tmp.push_back(temp); 440 } 441 return true; 442 } else { 443 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing elements for " << getTitle() << "." << endl); 444 return false; 445 } 446 }
Note:
See TracChangeset
for help on using the changeset viewer.