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