| [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 |  | 
|---|
| [97ebf8] | 67 | void CommandLineDialog::queryAtom(const char* title, atom **target, string _description) { | 
|---|
|  | 68 | registerQuery(new AtomCommandLineQuery(title,target, _description)); | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | void CommandLineDialog::queryMolecule(const char* title, molecule **target, string _description) { | 
|---|
|  | 72 | registerQuery(new MoleculeCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 73 | } | 
|---|
|  | 74 |  | 
|---|
| [86466e] | 75 | void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check, string _description) { | 
|---|
|  | 76 | registerQuery(new VectorCommandLineQuery(title,target,cellSize,check, _description)); | 
|---|
|  | 77 | } | 
|---|
|  | 78 |  | 
|---|
| [97ebf8] | 79 | void CommandLineDialog::queryBox(const char* title, double ** const cellSize, string _description) { | 
|---|
|  | 80 | registerQuery(new BoxCommandLineQuery(title,cellSize,_description)); | 
|---|
|  | 81 | } | 
|---|
|  | 82 |  | 
|---|
| [104524] | 83 | void CommandLineDialog::queryElement(const char* title, std::vector<element *> *target, string _description){ | 
|---|
| [86466e] | 84 | registerQuery(new ElementCommandLineQuery(title,target, _description)); | 
|---|
| [a2ab15] | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 | /************************** Query Infrastructure ************************/ | 
|---|
|  | 88 |  | 
|---|
| [86466e] | 89 | CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) : | 
|---|
|  | 90 | Dialog::EmptyQuery(title, _description) | 
|---|
|  | 91 | {} | 
|---|
|  | 92 |  | 
|---|
|  | 93 | CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {} | 
|---|
|  | 94 |  | 
|---|
|  | 95 | bool CommandLineDialog::EmptyCommandLineQuery::handle() { | 
|---|
|  | 96 | cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n"; | 
|---|
|  | 97 | return true; | 
|---|
|  | 98 | } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) : | 
|---|
|  | 101 | Dialog::IntQuery(title,_target, _description) | 
|---|
| [a2ab15] | 102 | {} | 
|---|
|  | 103 |  | 
|---|
| [86466e] | 104 | CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {} | 
|---|
| [a2ab15] | 105 |  | 
|---|
| [86466e] | 106 | bool CommandLineDialog::IntCommandLineQuery::handle() { | 
|---|
| [d90762] | 107 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 108 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
|  | 109 | return true; | 
|---|
| [94d131] | 110 | } else { | 
|---|
|  | 111 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 112 | return false; | 
|---|
| [94d131] | 113 | } | 
|---|
| [a2ab15] | 114 | } | 
|---|
|  | 115 |  | 
|---|
| [97ebf8] | 116 | CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) : | 
|---|
|  | 117 | Dialog::BooleanQuery(title,_target, _description) | 
|---|
|  | 118 | {} | 
|---|
|  | 119 |  | 
|---|
|  | 120 | CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {} | 
|---|
|  | 121 |  | 
|---|
|  | 122 | bool CommandLineDialog::BooleanCommandLineQuery::handle() { | 
|---|
| [0286bc] | 123 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 124 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>(); | 
|---|
|  | 125 | return true; | 
|---|
| [94d131] | 126 | } else { | 
|---|
|  | 127 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl); | 
|---|
| [0286bc] | 128 | return false; | 
|---|
| [94d131] | 129 | } | 
|---|
| [97ebf8] | 130 | } | 
|---|
|  | 131 |  | 
|---|
| [86466e] | 132 | CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) : | 
|---|
|  | 133 | Dialog::StringQuery(title,_target, _description) | 
|---|
| [a2ab15] | 134 | {} | 
|---|
|  | 135 |  | 
|---|
| [86466e] | 136 | CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {} | 
|---|
| [a2ab15] | 137 |  | 
|---|
| [86466e] | 138 | bool CommandLineDialog::StringCommandLineQuery::handle() { | 
|---|
| [d90762] | 139 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [86466e] | 140 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>(); | 
|---|
| [d90762] | 141 | return true; | 
|---|
| [94d131] | 142 | } else { | 
|---|
|  | 143 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 144 | return false; | 
|---|
| [94d131] | 145 | } | 
|---|
| [a2ab15] | 146 | } | 
|---|
|  | 147 |  | 
|---|
| [86466e] | 148 | CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) : | 
|---|
|  | 149 | Dialog::DoubleQuery(title,_target, _description) | 
|---|
| [a2ab15] | 150 | {} | 
|---|
|  | 151 |  | 
|---|
| [86466e] | 152 | CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {} | 
|---|
| [a2ab15] | 153 |  | 
|---|
| [86466e] | 154 | bool CommandLineDialog::DoubleCommandLineQuery::handle() { | 
|---|
| [d90762] | 155 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 156 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>(); | 
|---|
|  | 157 | return true; | 
|---|
| [94d131] | 158 | } else { | 
|---|
|  | 159 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 160 | return false; | 
|---|
| [94d131] | 161 | } | 
|---|
| [a2ab15] | 162 | } | 
|---|
|  | 163 |  | 
|---|
| [97ebf8] | 164 | CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) : | 
|---|
|  | 165 | Dialog::AtomQuery(title,_target, _description) | 
|---|
|  | 166 | {} | 
|---|
|  | 167 |  | 
|---|
|  | 168 | CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {} | 
|---|
|  | 169 |  | 
|---|
|  | 170 | bool CommandLineDialog::AtomCommandLineQuery::handle() { | 
|---|
|  | 171 | int IdxOfAtom = -1; | 
|---|
|  | 172 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 173 | IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
|  | 174 | tmp = World::getInstance().getAtom(AtomById(IdxOfAtom)); | 
|---|
|  | 175 | return true; | 
|---|
| [94d131] | 176 | } else { | 
|---|
|  | 177 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl); | 
|---|
| [97ebf8] | 178 | return false; | 
|---|
| [94d131] | 179 | } | 
|---|
| [97ebf8] | 180 | } | 
|---|
|  | 181 |  | 
|---|
|  | 182 | CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) : | 
|---|
|  | 183 | Dialog::MoleculeQuery(title,_target, _description) | 
|---|
| [a2ab15] | 184 | {} | 
|---|
|  | 185 |  | 
|---|
| [86466e] | 186 | CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {} | 
|---|
| [a2ab15] | 187 |  | 
|---|
| [86466e] | 188 | bool CommandLineDialog::MoleculeCommandLineQuery::handle() { | 
|---|
| [d90762] | 189 | int IdxOfMol = -1; | 
|---|
|  | 190 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
|  | 191 | IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>(); | 
|---|
| [e30ce8] | 192 | cout << "IdxOfMol " << IdxOfMol << endl; | 
|---|
|  | 193 | if (IdxOfMol >= 0) | 
|---|
|  | 194 | tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol)); | 
|---|
|  | 195 | else | 
|---|
|  | 196 | tmp = NULL; | 
|---|
| [d90762] | 197 | return true; | 
|---|
| [94d131] | 198 | } else { | 
|---|
|  | 199 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 200 | return false; | 
|---|
| [94d131] | 201 | } | 
|---|
| [a2ab15] | 202 | } | 
|---|
|  | 203 |  | 
|---|
| [86466e] | 204 | CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) : | 
|---|
|  | 205 | Dialog::VectorQuery(title,_target,_cellSize,_check, _description) | 
|---|
| [a2ab15] | 206 | {} | 
|---|
|  | 207 |  | 
|---|
| [86466e] | 208 | CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery() | 
|---|
| [a2ab15] | 209 | {} | 
|---|
|  | 210 |  | 
|---|
| [86466e] | 211 | bool CommandLineDialog::VectorCommandLineQuery::handle() { | 
|---|
| [0286bc] | 212 | VectorValue temp; | 
|---|
| [d90762] | 213 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [0286bc] | 214 | temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >(); | 
|---|
|  | 215 | tmp->at(0) = temp.x; | 
|---|
|  | 216 | tmp->at(1) = temp.y; | 
|---|
|  | 217 | tmp->at(2) = temp.z; | 
|---|
| [d90762] | 218 | return true; | 
|---|
| [94d131] | 219 | } else { | 
|---|
|  | 220 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 221 | return false; | 
|---|
| [94d131] | 222 | } | 
|---|
| [a2ab15] | 223 | } | 
|---|
|  | 224 |  | 
|---|
|  | 225 |  | 
|---|
| [97ebf8] | 226 | CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, double ** const _cellSize, string _description) : | 
|---|
|  | 227 | Dialog::BoxQuery(title,_cellSize, _description) | 
|---|
|  | 228 | {} | 
|---|
|  | 229 |  | 
|---|
|  | 230 | CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery() | 
|---|
|  | 231 | {} | 
|---|
|  | 232 |  | 
|---|
|  | 233 | bool CommandLineDialog::BoxCommandLineQuery::handle() { | 
|---|
| [0286bc] | 234 | BoxValue temp; | 
|---|
| [97ebf8] | 235 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [0286bc] | 236 | temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >(); | 
|---|
|  | 237 | tmp[0] = temp.xx; | 
|---|
|  | 238 | tmp[1] = temp.xy; | 
|---|
|  | 239 | tmp[2] = temp.xz; | 
|---|
|  | 240 | tmp[3] = temp.yy; | 
|---|
|  | 241 | tmp[4] = temp.yz; | 
|---|
|  | 242 | tmp[5] = temp.zz; | 
|---|
| [97ebf8] | 243 | return true; | 
|---|
| [94d131] | 244 | } else { | 
|---|
|  | 245 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl); | 
|---|
| [97ebf8] | 246 | return false; | 
|---|
| [94d131] | 247 | } | 
|---|
| [97ebf8] | 248 | } | 
|---|
|  | 249 |  | 
|---|
| [104524] | 250 | CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, std::vector<element *> *target, string _description) : | 
|---|
| [86466e] | 251 | Dialog::ElementQuery(title,target, _description) | 
|---|
| [a2ab15] | 252 | {} | 
|---|
|  | 253 |  | 
|---|
| [86466e] | 254 | CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery() | 
|---|
| [a2ab15] | 255 | {} | 
|---|
|  | 256 |  | 
|---|
| [86466e] | 257 | bool CommandLineDialog::ElementCommandLineQuery::handle() { | 
|---|
| [97ebf8] | 258 | // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector? | 
|---|
| [104524] | 259 | periodentafel *periode = World::getInstance().getPeriode(); | 
|---|
|  | 260 | element *elemental = NULL; | 
|---|
| [d90762] | 261 | if (CommandLineParser::getInstance().vm.count(getTitle())) { | 
|---|
| [97ebf8] | 262 | vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >(); | 
|---|
| [104524] | 263 | for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) { | 
|---|
|  | 264 | elemental = periode->FindElement(*ZRunner); | 
|---|
|  | 265 | ASSERT(elemental != NULL, "Invalid element specified in ElementCommandLineQuery"); | 
|---|
|  | 266 | elements.push_back(elemental); | 
|---|
|  | 267 | } | 
|---|
| [d90762] | 268 | return true; | 
|---|
| [94d131] | 269 | } else { | 
|---|
|  | 270 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl); | 
|---|
| [d90762] | 271 | return false; | 
|---|
| [94d131] | 272 | } | 
|---|
| [a2ab15] | 273 | } | 
|---|