- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/CommandLineUI/CommandLineDialog.cpp
r84c494 r112b09 8 8 #include "Helpers/MemDebug.hpp" 9 9 10 #include <cassert> 10 11 #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"20 18 21 19 #include "element.hpp" … … 27 25 #include "verbose.hpp" 28 26 #include "World.hpp" 29 #include "Box.hpp"30 27 31 28 #include "atom.hpp" … … 74 71 } 75 72 76 void CommandLineDialog::queryVector(const char* title, Vector *target, bool check, string _description) {77 registerQuery(new VectorCommandLineQuery(title,target,c heck, _description));78 } 79 80 void CommandLineDialog::queryBox(const char* title, Box*cellSize, string _description) {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) { 81 78 registerQuery(new BoxCommandLineQuery(title,cellSize,_description)); 82 79 } 83 80 84 void CommandLineDialog::queryElement(const char* title, std::vector<element *>*target, string _description){81 void CommandLineDialog::queryElement(const char* title, const element **target, string _description){ 85 82 registerQuery(new ElementCommandLineQuery(title,target, _description)); 86 83 } … … 109 106 tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>(); 110 107 return true; 111 } else { 112 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl); 113 return false; 114 } 108 } else 109 return false; 115 110 } 116 111 … … 122 117 123 118 bool CommandLineDialog::BooleanCommandLineQuery::handle() { 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 } 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; 131 139 } 132 140 … … 141 149 tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>(); 142 150 return true; 143 } else { 144 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl); 145 return false; 146 } 151 } else 152 return false; 147 153 } 148 154 … … 157 163 tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>(); 158 164 return true; 159 } else { 160 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl); 161 return false; 162 } 165 } else 166 return false; 163 167 } 164 168 … … 175 179 tmp = World::getInstance().getAtom(AtomById(IdxOfAtom)); 176 180 return true; 177 } else { 178 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl); 179 return false; 180 } 181 } else 182 return false; 181 183 } 182 184 … … 197 199 tmp = NULL; 198 200 return true; 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) 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) 207 207 {} 208 208 … … 211 211 212 212 bool CommandLineDialog::VectorCommandLineQuery::handle() { 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) : 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) : 228 226 Dialog::BoxQuery(title,_cellSize, _description) 229 227 {} … … 233 231 234 232 bool CommandLineDialog::BoxCommandLineQuery::handle() { 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) : 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) : 252 246 Dialog::ElementQuery(title,target, _description) 253 247 {} … … 258 252 bool CommandLineDialog::ElementCommandLineQuery::handle() { 259 253 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector? 260 periodentafel *periode = World::getInstance().getPeriode(); 261 element *elemental = NULL; 254 int Z; 262 255 if (CommandLineParser::getInstance().vm.count(getTitle())) { 263 256 vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >(); 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 } 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 }
Note:
See TracChangeset
for help on using the changeset viewer.