| [a2ab15] | 1 | /* | 
|---|
|  | 2 | * CommandLineDialog.cpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: May 8, 2010 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [112b09] | 8 | #include "Helpers/MemDebug.hpp" | 
|---|
| [a2ab15] | 9 |  | 
|---|
|  | 10 | #include <iostream> | 
|---|
| [104524] | 11 | #include <vector> | 
|---|
| [a2ab15] | 12 |  | 
|---|
| [97ebf8] | 13 | #include <Descriptors/AtomDescriptor.hpp> | 
|---|
|  | 14 | #include <Descriptors/AtomIdDescriptor.hpp> | 
|---|
| [d90762] | 15 | #include <Descriptors/MoleculeDescriptor.hpp> | 
|---|
|  | 16 | #include <Descriptors/MoleculeIdDescriptor.hpp> | 
|---|
| [5079a0] | 17 | #include "CommandLineUI/CommandLineDialog.hpp" | 
|---|
| [a2ab15] | 18 |  | 
|---|
| [0286bc] | 19 | #include "Actions/Values.hpp" | 
|---|
|  | 20 |  | 
|---|
| [97ebf8] | 21 | #include "element.hpp" | 
|---|
| [a2ab15] | 22 | #include "periodentafel.hpp" | 
|---|
| [d90762] | 23 | #include "CommandLineParser.hpp" | 
|---|
|  | 24 | #include "defs.hpp" | 
|---|
| [a2ab15] | 25 | #include "log.hpp" | 
|---|
| [97ebf8] | 26 | #include "periodentafel.hpp" | 
|---|
| [a2ab15] | 27 | #include "verbose.hpp" | 
|---|
| [d90762] | 28 | #include "World.hpp" | 
|---|
| [a2ab15] | 29 |  | 
|---|
| [97ebf8] | 30 | #include "atom.hpp" | 
|---|
|  | 31 | #include "element.hpp" | 
|---|
|  | 32 | #include "molecule.hpp" | 
|---|
|  | 33 | #include "vector.hpp" | 
|---|
|  | 34 |  | 
|---|
| [a2ab15] | 35 | using namespace std; | 
|---|
|  | 36 |  | 
|---|
|  | 37 |  | 
|---|
|  | 38 | CommandLineDialog::CommandLineDialog() | 
|---|
|  | 39 | { | 
|---|
|  | 40 | } | 
|---|
|  | 41 |  | 
|---|
|  | 42 | CommandLineDialog::~CommandLineDialog() | 
|---|
|  | 43 | { | 
|---|
|  | 44 | } | 
|---|
|  | 45 |  | 
|---|
|  | 46 |  | 
|---|
| [86466e] | 47 | void CommandLineDialog::queryEmpty(const char* title, string _description){ | 
|---|
|  | 48 | registerQuery(new EmptyCommandLineQuery(title, _description)); | 
|---|
| [a2ab15] | 49 | } | 
|---|
|  | 50 |  | 
|---|
| [86466e] | 51 | void CommandLineDialog::queryInt(const char* title, int* target, string _description){ | 
|---|
|  | 52 | registerQuery(new IntCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 53 | } | 
|---|
|  | 54 |  | 
|---|
| [97ebf8] | 55 | void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){ | 
|---|
|  | 56 | registerQuery(new BooleanCommandLineQuery(title,target, _description)); | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
| [86466e] | 59 | void CommandLineDialog::queryDouble(const char* title, double* target, string _description){ | 
|---|
|  | 60 | registerQuery(new DoubleCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 61 | } | 
|---|
|  | 62 |  | 
|---|
| [86466e] | 63 | void CommandLineDialog::queryString(const char* title, string* target, string _description){ | 
|---|
|  | 64 | registerQuery(new StringCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 65 | } | 
|---|
|  | 66 |  | 
|---|
| [cd8e55] | 67 | void CommandLineDialog::queryStrings(const char* title, vector<string> * target, string _description){ | 
|---|
|  | 68 | registerQuery(new StringsCommandLineQuery(title,target, _description)); | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
| [97ebf8] | 71 | void CommandLineDialog::queryAtom(const char* title, atom **target, string _description) { | 
|---|
|  | 72 | registerQuery(new AtomCommandLineQuery(title,target, _description)); | 
|---|
|  | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | void CommandLineDialog::queryMolecule(const char* title, molecule **target, string _description) { | 
|---|
|  | 76 | registerQuery(new MoleculeCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 77 | } | 
|---|
|  | 78 |  | 
|---|
| [86466e] | 79 | void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check, string _description) { | 
|---|
|  | 80 | registerQuery(new VectorCommandLineQuery(title,target,cellSize,check, _description)); | 
|---|
|  | 81 | } | 
|---|
|  | 82 |  | 
|---|
| [97ebf8] | 83 | void CommandLineDialog::queryBox(const char* title, double ** const cellSize, string _description) { | 
|---|
|  | 84 | registerQuery(new BoxCommandLineQuery(title,cellSize,_description)); | 
|---|
|  | 85 | } | 
|---|
|  | 86 |  | 
|---|
| [104524] | 87 | void CommandLineDialog::queryElement(const char* title, std::vector<element *> *target, string _description){ | 
|---|
| [86466e] | 88 | registerQuery(new ElementCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | /************************** Query Infrastructure ************************/ | 
|---|
|  | 92 |  | 
|---|
| [86466e] | 93 | CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) : | 
|---|
|  | 94 | Dialog::EmptyQuery(title, _description) | 
|---|
|  | 95 | {} | 
|---|
|  | 96 |  | 
|---|
|  | 97 | CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {} | 
|---|
|  | 98 |  | 
|---|
|  | 99 | bool CommandLineDialog::EmptyCommandLineQuery::handle() { | 
|---|
|  | 100 | cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n"; | 
|---|
|  | 101 | return true; | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) : | 
|---|
|  | 105 | Dialog::IntQuery(title,_target, _description) | 
|---|
| [a2ab15] | 106 | {} | 
|---|
|  | 107 |  | 
|---|
| [86466e] | 108 | CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {} | 
|---|
| [a2ab15] | 109 |  | 
|---|
| [86466e] | 110 | bool CommandLineDialog::IntCommandLineQuery::handle() { | 
|---|
| [d90762] | 111 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 112 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
|  | 113 | return true; | 
|---|
| [94d131] | 114 | } else { | 
|---|
|  | 115 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 116 | return false; | 
|---|
| [94d131] | 117 | } | 
|---|
| [a2ab15] | 118 | } | 
|---|
|  | 119 |  | 
|---|
| [97ebf8] | 120 | CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) : | 
|---|
|  | 121 | Dialog::BooleanQuery(title,_target, _description) | 
|---|
|  | 122 | {} | 
|---|
|  | 123 |  | 
|---|
|  | 124 | CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {} | 
|---|
|  | 125 |  | 
|---|
|  | 126 | bool CommandLineDialog::BooleanCommandLineQuery::handle() { | 
|---|
| [0286bc] | 127 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 128 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>(); | 
|---|
|  | 129 | return true; | 
|---|
| [94d131] | 130 | } else { | 
|---|
|  | 131 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl); | 
|---|
| [0286bc] | 132 | return false; | 
|---|
| [94d131] | 133 | } | 
|---|
| [97ebf8] | 134 | } | 
|---|
|  | 135 |  | 
|---|
| [86466e] | 136 | CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) : | 
|---|
|  | 137 | Dialog::StringQuery(title,_target, _description) | 
|---|
| [a2ab15] | 138 | {} | 
|---|
|  | 139 |  | 
|---|
| [86466e] | 140 | CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {} | 
|---|
| [a2ab15] | 141 |  | 
|---|
| [86466e] | 142 | bool CommandLineDialog::StringCommandLineQuery::handle() { | 
|---|
| [d90762] | 143 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [86466e] | 144 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>(); | 
|---|
| [d90762] | 145 | return true; | 
|---|
| [94d131] | 146 | } else { | 
|---|
|  | 147 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 148 | return false; | 
|---|
| [94d131] | 149 | } | 
|---|
| [a2ab15] | 150 | } | 
|---|
|  | 151 |  | 
|---|
| [cd8e55] | 152 | CommandLineDialog::StringsCommandLineQuery::StringsCommandLineQuery(string title,vector<string> *_target, string _description) : | 
|---|
|  | 153 | Dialog::StringsQuery(title,_target, _description) | 
|---|
|  | 154 | {} | 
|---|
|  | 155 |  | 
|---|
|  | 156 | CommandLineDialog::StringsCommandLineQuery::~StringsCommandLineQuery() {} | 
|---|
|  | 157 |  | 
|---|
|  | 158 | bool CommandLineDialog::StringsCommandLineQuery::handle() { | 
|---|
|  | 159 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [b9c847] | 160 | tmp = CommandLineParser::getInstance().vm[getTitle()].as< vector<string> >(); | 
|---|
| [cd8e55] | 161 | return true; | 
|---|
|  | 162 | } else { | 
|---|
|  | 163 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl); | 
|---|
|  | 164 | return false; | 
|---|
|  | 165 | } | 
|---|
|  | 166 | } | 
|---|
|  | 167 |  | 
|---|
| [86466e] | 168 | CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) : | 
|---|
|  | 169 | Dialog::DoubleQuery(title,_target, _description) | 
|---|
| [a2ab15] | 170 | {} | 
|---|
|  | 171 |  | 
|---|
| [86466e] | 172 | CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {} | 
|---|
| [a2ab15] | 173 |  | 
|---|
| [86466e] | 174 | bool CommandLineDialog::DoubleCommandLineQuery::handle() { | 
|---|
| [d90762] | 175 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 176 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>(); | 
|---|
|  | 177 | return true; | 
|---|
| [94d131] | 178 | } else { | 
|---|
|  | 179 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 180 | return false; | 
|---|
| [94d131] | 181 | } | 
|---|
| [a2ab15] | 182 | } | 
|---|
|  | 183 |  | 
|---|
| [97ebf8] | 184 | CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) : | 
|---|
|  | 185 | Dialog::AtomQuery(title,_target, _description) | 
|---|
|  | 186 | {} | 
|---|
|  | 187 |  | 
|---|
|  | 188 | CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {} | 
|---|
|  | 189 |  | 
|---|
|  | 190 | bool CommandLineDialog::AtomCommandLineQuery::handle() { | 
|---|
|  | 191 | int IdxOfAtom = -1; | 
|---|
|  | 192 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 193 | IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
|  | 194 | tmp = World::getInstance().getAtom(AtomById(IdxOfAtom)); | 
|---|
|  | 195 | return true; | 
|---|
| [94d131] | 196 | } else { | 
|---|
|  | 197 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl); | 
|---|
| [97ebf8] | 198 | return false; | 
|---|
| [94d131] | 199 | } | 
|---|
| [97ebf8] | 200 | } | 
|---|
|  | 201 |  | 
|---|
|  | 202 | CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) : | 
|---|
|  | 203 | Dialog::MoleculeQuery(title,_target, _description) | 
|---|
| [a2ab15] | 204 | {} | 
|---|
|  | 205 |  | 
|---|
| [86466e] | 206 | CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {} | 
|---|
| [a2ab15] | 207 |  | 
|---|
| [86466e] | 208 | bool CommandLineDialog::MoleculeCommandLineQuery::handle() { | 
|---|
| [d90762] | 209 | int IdxOfMol = -1; | 
|---|
|  | 210 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 211 | IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
| [e30ce8] | 212 | cout << "IdxOfMol " << IdxOfMol << endl; | 
|---|
|  | 213 | if (IdxOfMol >= 0) | 
|---|
|  | 214 | tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol)); | 
|---|
|  | 215 | else | 
|---|
|  | 216 | tmp = NULL; | 
|---|
| [d90762] | 217 | return true; | 
|---|
| [94d131] | 218 | } else { | 
|---|
|  | 219 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 220 | return false; | 
|---|
| [94d131] | 221 | } | 
|---|
| [a2ab15] | 222 | } | 
|---|
|  | 223 |  | 
|---|
| [86466e] | 224 | CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) : | 
|---|
|  | 225 | Dialog::VectorQuery(title,_target,_cellSize,_check, _description) | 
|---|
| [a2ab15] | 226 | {} | 
|---|
|  | 227 |  | 
|---|
| [86466e] | 228 | CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery() | 
|---|
| [a2ab15] | 229 | {} | 
|---|
|  | 230 |  | 
|---|
| [86466e] | 231 | bool CommandLineDialog::VectorCommandLineQuery::handle() { | 
|---|
| [0286bc] | 232 | VectorValue temp; | 
|---|
| [d90762] | 233 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [0286bc] | 234 | temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >(); | 
|---|
|  | 235 | tmp->at(0) = temp.x; | 
|---|
|  | 236 | tmp->at(1) = temp.y; | 
|---|
|  | 237 | tmp->at(2) = temp.z; | 
|---|
| [d90762] | 238 | return true; | 
|---|
| [94d131] | 239 | } else { | 
|---|
|  | 240 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 241 | return false; | 
|---|
| [94d131] | 242 | } | 
|---|
| [a2ab15] | 243 | } | 
|---|
|  | 244 |  | 
|---|
|  | 245 |  | 
|---|
| [97ebf8] | 246 | CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, double ** const _cellSize, string _description) : | 
|---|
|  | 247 | Dialog::BoxQuery(title,_cellSize, _description) | 
|---|
|  | 248 | {} | 
|---|
|  | 249 |  | 
|---|
|  | 250 | CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery() | 
|---|
|  | 251 | {} | 
|---|
|  | 252 |  | 
|---|
|  | 253 | bool CommandLineDialog::BoxCommandLineQuery::handle() { | 
|---|
| [0286bc] | 254 | BoxValue temp; | 
|---|
| [97ebf8] | 255 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [0286bc] | 256 | temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >(); | 
|---|
|  | 257 | tmp[0] = temp.xx; | 
|---|
|  | 258 | tmp[1] = temp.xy; | 
|---|
|  | 259 | tmp[2] = temp.xz; | 
|---|
|  | 260 | tmp[3] = temp.yy; | 
|---|
|  | 261 | tmp[4] = temp.yz; | 
|---|
|  | 262 | tmp[5] = temp.zz; | 
|---|
| [97ebf8] | 263 | return true; | 
|---|
| [94d131] | 264 | } else { | 
|---|
|  | 265 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl); | 
|---|
| [97ebf8] | 266 | return false; | 
|---|
| [94d131] | 267 | } | 
|---|
| [97ebf8] | 268 | } | 
|---|
|  | 269 |  | 
|---|
| [104524] | 270 | CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, std::vector<element *> *target, string _description) : | 
|---|
| [86466e] | 271 | Dialog::ElementQuery(title,target, _description) | 
|---|
| [a2ab15] | 272 | {} | 
|---|
|  | 273 |  | 
|---|
| [86466e] | 274 | CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery() | 
|---|
| [a2ab15] | 275 | {} | 
|---|
|  | 276 |  | 
|---|
| [86466e] | 277 | bool CommandLineDialog::ElementCommandLineQuery::handle() { | 
|---|
| [97ebf8] | 278 | // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector? | 
|---|
| [104524] | 279 | periodentafel *periode = World::getInstance().getPeriode(); | 
|---|
|  | 280 | element *elemental = NULL; | 
|---|
| [d90762] | 281 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [97ebf8] | 282 | vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >(); | 
|---|
| [104524] | 283 | for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) { | 
|---|
|  | 284 | elemental = periode->FindElement(*ZRunner); | 
|---|
|  | 285 | ASSERT(elemental != NULL, "Invalid element specified in ElementCommandLineQuery"); | 
|---|
|  | 286 | elements.push_back(elemental); | 
|---|
|  | 287 | } | 
|---|
| [d90762] | 288 | return true; | 
|---|
| [94d131] | 289 | } else { | 
|---|
|  | 290 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 291 | return false; | 
|---|
| [94d131] | 292 | } | 
|---|
| [a2ab15] | 293 | } | 
|---|