- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/CommandLineUI/CommandLineDialog.cpp
r112b09 r84c494 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> … … 16 16 #include <Descriptors/MoleculeIdDescriptor.hpp> 17 17 #include "CommandLineUI/CommandLineDialog.hpp" 18 19 #include "Actions/Values.hpp" 18 20 19 21 #include "element.hpp" … … 25 27 #include "verbose.hpp" 26 28 #include "World.hpp" 29 #include "Box.hpp" 27 30 28 31 #include "atom.hpp" … … 71 74 } 72 75 73 void CommandLineDialog::queryVector(const char* title, Vector *target, const double *const cellSize,bool check, string _description) {74 registerQuery(new VectorCommandLineQuery(title,target,c ellSize,check, _description));75 } 76 77 void CommandLineDialog::queryBox(const char* title, double ** constcellSize, string _description) {76 void CommandLineDialog::queryVector(const char* title, Vector *target, bool check, string _description) { 77 registerQuery(new VectorCommandLineQuery(title,target,check, _description)); 78 } 79 80 void CommandLineDialog::queryBox(const char* title, Box* cellSize, string _description) { 78 81 registerQuery(new BoxCommandLineQuery(title,cellSize,_description)); 79 82 } 80 83 81 void CommandLineDialog::queryElement(const char* title, const element **target, string _description){84 void CommandLineDialog::queryElement(const char* title, std::vector<element *> *target, string _description){ 82 85 registerQuery(new ElementCommandLineQuery(title,target, _description)); 83 86 } … … 106 109 tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>(); 107 110 return true; 108 } else 109 return false; 111 } else { 112 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl); 113 return false; 114 } 110 115 } 111 116 … … 117 122 118 123 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; 124 if (CommandLineParser::getInstance().vm.count(getTitle())) { 125 tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>(); 126 return true; 127 } else { 128 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl); 129 return false; 130 } 139 131 } 140 132 … … 149 141 tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>(); 150 142 return true; 151 } else 152 return false; 143 } else { 144 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl); 145 return false; 146 } 153 147 } 154 148 … … 163 157 tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>(); 164 158 return true; 165 } else 166 return false; 159 } else { 160 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl); 161 return false; 162 } 167 163 } 168 164 … … 179 175 tmp = World::getInstance().getAtom(AtomById(IdxOfAtom)); 180 176 return true; 181 } else 182 return false; 177 } else { 178 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl); 179 return false; 180 } 183 181 } 184 182 … … 199 197 tmp = NULL; 200 198 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) 199 } else { 200 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl); 201 return false; 202 } 203 } 204 205 CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, bool _check, string _description) : 206 Dialog::VectorQuery(title,_target,_check, _description) 207 207 {} 208 208 … … 211 211 212 212 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) : 213 VectorValue temp; 214 if (CommandLineParser::getInstance().vm.count(getTitle())) { 215 temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >(); 216 tmp->at(0) = temp.x; 217 tmp->at(1) = temp.y; 218 tmp->at(2) = temp.z; 219 return true; 220 } else { 221 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl); 222 return false; 223 } 224 } 225 226 227 CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, Box* _cellSize, string _description) : 226 228 Dialog::BoxQuery(title,_cellSize, _description) 227 229 {} … … 231 233 232 234 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) : 235 BoxValue temp; 236 if (CommandLineParser::getInstance().vm.count(getTitle())) { 237 temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >(); 238 tmp[0] = temp.xx; 239 tmp[1] = temp.xy; 240 tmp[2] = temp.xz; 241 tmp[3] = temp.yy; 242 tmp[4] = temp.yz; 243 tmp[5] = temp.zz; 244 return true; 245 } else { 246 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl); 247 return false; 248 } 249 } 250 251 CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, std::vector<element *> *target, string _description) : 246 252 Dialog::ElementQuery(title,target, _description) 247 253 {} … … 252 258 bool CommandLineDialog::ElementCommandLineQuery::handle() { 253 259 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector? 254 int Z; 260 periodentafel *periode = World::getInstance().getPeriode(); 261 element *elemental = NULL; 255 262 if (CommandLineParser::getInstance().vm.count(getTitle())) { 256 263 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 } 264 for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) { 265 elemental = periode->FindElement(*ZRunner); 266 ASSERT(elemental != NULL, "Invalid element specified in ElementCommandLineQuery"); 267 elements.push_back(elemental); 268 } 269 return true; 270 } else { 271 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl); 272 return false; 273 } 274 }
Note:
See TracChangeset
for help on using the changeset viewer.