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