| [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" | 
|---|
| [84c494] | 29 | #include "Box.hpp" | 
|---|
| [a2ab15] | 30 |  | 
|---|
| [97ebf8] | 31 | #include "atom.hpp" | 
|---|
|  | 32 | #include "element.hpp" | 
|---|
|  | 33 | #include "molecule.hpp" | 
|---|
|  | 34 | #include "vector.hpp" | 
|---|
|  | 35 |  | 
|---|
| [a2ab15] | 36 | using namespace std; | 
|---|
|  | 37 |  | 
|---|
|  | 38 |  | 
|---|
|  | 39 | CommandLineDialog::CommandLineDialog() | 
|---|
|  | 40 | { | 
|---|
|  | 41 | } | 
|---|
|  | 42 |  | 
|---|
|  | 43 | CommandLineDialog::~CommandLineDialog() | 
|---|
|  | 44 | { | 
|---|
|  | 45 | } | 
|---|
|  | 46 |  | 
|---|
|  | 47 |  | 
|---|
| [86466e] | 48 | void CommandLineDialog::queryEmpty(const char* title, string _description){ | 
|---|
|  | 49 | registerQuery(new EmptyCommandLineQuery(title, _description)); | 
|---|
| [a2ab15] | 50 | } | 
|---|
|  | 51 |  | 
|---|
| [86466e] | 52 | void CommandLineDialog::queryInt(const char* title, int* target, string _description){ | 
|---|
|  | 53 | registerQuery(new IntCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 54 | } | 
|---|
|  | 55 |  | 
|---|
| [97ebf8] | 56 | void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){ | 
|---|
|  | 57 | registerQuery(new BooleanCommandLineQuery(title,target, _description)); | 
|---|
|  | 58 | } | 
|---|
|  | 59 |  | 
|---|
| [86466e] | 60 | void CommandLineDialog::queryDouble(const char* title, double* target, string _description){ | 
|---|
|  | 61 | registerQuery(new DoubleCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 62 | } | 
|---|
|  | 63 |  | 
|---|
| [86466e] | 64 | void CommandLineDialog::queryString(const char* title, string* target, string _description){ | 
|---|
|  | 65 | registerQuery(new StringCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 66 | } | 
|---|
|  | 67 |  | 
|---|
| [97ebf8] | 68 | void CommandLineDialog::queryAtom(const char* title, atom **target, string _description) { | 
|---|
|  | 69 | registerQuery(new AtomCommandLineQuery(title,target, _description)); | 
|---|
|  | 70 | } | 
|---|
|  | 71 |  | 
|---|
|  | 72 | void CommandLineDialog::queryMolecule(const char* title, molecule **target, string _description) { | 
|---|
|  | 73 | registerQuery(new MoleculeCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 74 | } | 
|---|
|  | 75 |  | 
|---|
| [84c494] | 76 | void CommandLineDialog::queryVector(const char* title, Vector *target, bool check, string _description) { | 
|---|
|  | 77 | registerQuery(new VectorCommandLineQuery(title,target,check, _description)); | 
|---|
| [86466e] | 78 | } | 
|---|
|  | 79 |  | 
|---|
| [84c494] | 80 | void CommandLineDialog::queryBox(const char* title, Box* cellSize, string _description) { | 
|---|
| [97ebf8] | 81 | registerQuery(new BoxCommandLineQuery(title,cellSize,_description)); | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
| [104524] | 84 | void CommandLineDialog::queryElement(const char* title, std::vector<element *> *target, string _description){ | 
|---|
| [86466e] | 85 | registerQuery(new ElementCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | /************************** Query Infrastructure ************************/ | 
|---|
|  | 89 |  | 
|---|
| [86466e] | 90 | CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) : | 
|---|
|  | 91 | Dialog::EmptyQuery(title, _description) | 
|---|
|  | 92 | {} | 
|---|
|  | 93 |  | 
|---|
|  | 94 | CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {} | 
|---|
|  | 95 |  | 
|---|
|  | 96 | bool CommandLineDialog::EmptyCommandLineQuery::handle() { | 
|---|
|  | 97 | cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n"; | 
|---|
|  | 98 | return true; | 
|---|
|  | 99 | } | 
|---|
|  | 100 |  | 
|---|
|  | 101 | CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) : | 
|---|
|  | 102 | Dialog::IntQuery(title,_target, _description) | 
|---|
| [a2ab15] | 103 | {} | 
|---|
|  | 104 |  | 
|---|
| [86466e] | 105 | CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {} | 
|---|
| [a2ab15] | 106 |  | 
|---|
| [86466e] | 107 | bool CommandLineDialog::IntCommandLineQuery::handle() { | 
|---|
| [d90762] | 108 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 109 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
|  | 110 | return true; | 
|---|
| [94d131] | 111 | } else { | 
|---|
|  | 112 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 113 | return false; | 
|---|
| [94d131] | 114 | } | 
|---|
| [a2ab15] | 115 | } | 
|---|
|  | 116 |  | 
|---|
| [97ebf8] | 117 | CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) : | 
|---|
|  | 118 | Dialog::BooleanQuery(title,_target, _description) | 
|---|
|  | 119 | {} | 
|---|
|  | 120 |  | 
|---|
|  | 121 | CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {} | 
|---|
|  | 122 |  | 
|---|
|  | 123 | bool CommandLineDialog::BooleanCommandLineQuery::handle() { | 
|---|
| [0286bc] | 124 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 125 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>(); | 
|---|
|  | 126 | return true; | 
|---|
| [94d131] | 127 | } else { | 
|---|
|  | 128 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl); | 
|---|
| [0286bc] | 129 | return false; | 
|---|
| [94d131] | 130 | } | 
|---|
| [97ebf8] | 131 | } | 
|---|
|  | 132 |  | 
|---|
| [86466e] | 133 | CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) : | 
|---|
|  | 134 | Dialog::StringQuery(title,_target, _description) | 
|---|
| [a2ab15] | 135 | {} | 
|---|
|  | 136 |  | 
|---|
| [86466e] | 137 | CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {} | 
|---|
| [a2ab15] | 138 |  | 
|---|
| [86466e] | 139 | bool CommandLineDialog::StringCommandLineQuery::handle() { | 
|---|
| [d90762] | 140 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [86466e] | 141 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>(); | 
|---|
| [d90762] | 142 | return true; | 
|---|
| [94d131] | 143 | } else { | 
|---|
|  | 144 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 145 | return false; | 
|---|
| [94d131] | 146 | } | 
|---|
| [a2ab15] | 147 | } | 
|---|
|  | 148 |  | 
|---|
| [86466e] | 149 | CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) : | 
|---|
|  | 150 | Dialog::DoubleQuery(title,_target, _description) | 
|---|
| [a2ab15] | 151 | {} | 
|---|
|  | 152 |  | 
|---|
| [86466e] | 153 | CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {} | 
|---|
| [a2ab15] | 154 |  | 
|---|
| [86466e] | 155 | bool CommandLineDialog::DoubleCommandLineQuery::handle() { | 
|---|
| [d90762] | 156 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 157 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>(); | 
|---|
|  | 158 | return true; | 
|---|
| [94d131] | 159 | } else { | 
|---|
|  | 160 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 161 | return false; | 
|---|
| [94d131] | 162 | } | 
|---|
| [a2ab15] | 163 | } | 
|---|
|  | 164 |  | 
|---|
| [97ebf8] | 165 | CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) : | 
|---|
|  | 166 | Dialog::AtomQuery(title,_target, _description) | 
|---|
|  | 167 | {} | 
|---|
|  | 168 |  | 
|---|
|  | 169 | CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {} | 
|---|
|  | 170 |  | 
|---|
|  | 171 | bool CommandLineDialog::AtomCommandLineQuery::handle() { | 
|---|
|  | 172 | int IdxOfAtom = -1; | 
|---|
|  | 173 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 174 | IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
|  | 175 | tmp = World::getInstance().getAtom(AtomById(IdxOfAtom)); | 
|---|
|  | 176 | return true; | 
|---|
| [94d131] | 177 | } else { | 
|---|
|  | 178 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl); | 
|---|
| [97ebf8] | 179 | return false; | 
|---|
| [94d131] | 180 | } | 
|---|
| [97ebf8] | 181 | } | 
|---|
|  | 182 |  | 
|---|
|  | 183 | CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) : | 
|---|
|  | 184 | Dialog::MoleculeQuery(title,_target, _description) | 
|---|
| [a2ab15] | 185 | {} | 
|---|
|  | 186 |  | 
|---|
| [86466e] | 187 | CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {} | 
|---|
| [a2ab15] | 188 |  | 
|---|
| [86466e] | 189 | bool CommandLineDialog::MoleculeCommandLineQuery::handle() { | 
|---|
| [d90762] | 190 | int IdxOfMol = -1; | 
|---|
|  | 191 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 192 | IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
| [e30ce8] | 193 | cout << "IdxOfMol " << IdxOfMol << endl; | 
|---|
|  | 194 | if (IdxOfMol >= 0) | 
|---|
|  | 195 | tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol)); | 
|---|
|  | 196 | else | 
|---|
|  | 197 | tmp = NULL; | 
|---|
| [d90762] | 198 | return true; | 
|---|
| [94d131] | 199 | } else { | 
|---|
|  | 200 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 201 | return false; | 
|---|
| [94d131] | 202 | } | 
|---|
| [a2ab15] | 203 | } | 
|---|
|  | 204 |  | 
|---|
| [84c494] | 205 | CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, bool _check, string _description) : | 
|---|
|  | 206 | Dialog::VectorQuery(title,_target,_check, _description) | 
|---|
| [a2ab15] | 207 | {} | 
|---|
|  | 208 |  | 
|---|
| [86466e] | 209 | CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery() | 
|---|
| [a2ab15] | 210 | {} | 
|---|
|  | 211 |  | 
|---|
| [86466e] | 212 | bool CommandLineDialog::VectorCommandLineQuery::handle() { | 
|---|
| [0286bc] | 213 | VectorValue temp; | 
|---|
| [d90762] | 214 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [0286bc] | 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; | 
|---|
| [d90762] | 219 | return true; | 
|---|
| [94d131] | 220 | } else { | 
|---|
|  | 221 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 222 | return false; | 
|---|
| [94d131] | 223 | } | 
|---|
| [a2ab15] | 224 | } | 
|---|
|  | 225 |  | 
|---|
|  | 226 |  | 
|---|
| [84c494] | 227 | CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, Box* _cellSize, string _description) : | 
|---|
| [97ebf8] | 228 | Dialog::BoxQuery(title,_cellSize, _description) | 
|---|
|  | 229 | {} | 
|---|
|  | 230 |  | 
|---|
|  | 231 | CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery() | 
|---|
|  | 232 | {} | 
|---|
|  | 233 |  | 
|---|
|  | 234 | bool CommandLineDialog::BoxCommandLineQuery::handle() { | 
|---|
| [0286bc] | 235 | BoxValue temp; | 
|---|
| [97ebf8] | 236 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [0286bc] | 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; | 
|---|
| [97ebf8] | 244 | return true; | 
|---|
| [94d131] | 245 | } else { | 
|---|
|  | 246 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl); | 
|---|
| [97ebf8] | 247 | return false; | 
|---|
| [94d131] | 248 | } | 
|---|
| [97ebf8] | 249 | } | 
|---|
|  | 250 |  | 
|---|
| [104524] | 251 | CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, std::vector<element *> *target, string _description) : | 
|---|
| [86466e] | 252 | Dialog::ElementQuery(title,target, _description) | 
|---|
| [a2ab15] | 253 | {} | 
|---|
|  | 254 |  | 
|---|
| [86466e] | 255 | CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery() | 
|---|
| [a2ab15] | 256 | {} | 
|---|
|  | 257 |  | 
|---|
| [86466e] | 258 | bool CommandLineDialog::ElementCommandLineQuery::handle() { | 
|---|
| [97ebf8] | 259 | // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector? | 
|---|
| [104524] | 260 | periodentafel *periode = World::getInstance().getPeriode(); | 
|---|
|  | 261 | element *elemental = NULL; | 
|---|
| [d90762] | 262 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [97ebf8] | 263 | vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >(); | 
|---|
| [104524] | 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 | } | 
|---|
| [d90762] | 269 | return true; | 
|---|
| [94d131] | 270 | } else { | 
|---|
|  | 271 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 272 | return false; | 
|---|
| [94d131] | 273 | } | 
|---|
| [a2ab15] | 274 | } | 
|---|