| 1 | /*
 | 
|---|
| 2 |  * CommandLineDialog.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: May 8, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | // include config.h
 | 
|---|
| 9 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 10 | #include <config.h>
 | 
|---|
| 11 | #endif
 | 
|---|
| 12 | 
 | 
|---|
| 13 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include <iostream>
 | 
|---|
| 16 | #include <vector>
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <Descriptors/AtomDescriptor.hpp>
 | 
|---|
| 19 | #include <Descriptors/AtomIdDescriptor.hpp>
 | 
|---|
| 20 | #include <Descriptors/MoleculeDescriptor.hpp>
 | 
|---|
| 21 | #include <Descriptors/MoleculeIdDescriptor.hpp>
 | 
|---|
| 22 | #include "CommandLineUI/CommandLineDialog.hpp"
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include "Actions/Values.hpp"
 | 
|---|
| 25 | 
 | 
|---|
| 26 | #include "element.hpp"
 | 
|---|
| 27 | #include "periodentafel.hpp"
 | 
|---|
| 28 | #include "CommandLineParser.hpp"
 | 
|---|
| 29 | #include "defs.hpp"
 | 
|---|
| 30 | #include "Helpers/Log.hpp"
 | 
|---|
| 31 | #include "LinearAlgebra/Matrix.hpp"
 | 
|---|
| 32 | #include "periodentafel.hpp"
 | 
|---|
| 33 | #include "Helpers/Verbose.hpp"
 | 
|---|
| 34 | #include "World.hpp"
 | 
|---|
| 35 | #include "Box.hpp"
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #include "atom.hpp"
 | 
|---|
| 38 | #include "element.hpp"
 | 
|---|
| 39 | #include "molecule.hpp"
 | 
|---|
| 40 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| 41 | 
 | 
|---|
| 42 | using namespace std;
 | 
|---|
| 43 | 
 | 
|---|
| 44 | 
 | 
|---|
| 45 | CommandLineDialog::CommandLineDialog()
 | 
|---|
| 46 | {
 | 
|---|
| 47 | }
 | 
|---|
| 48 | 
 | 
|---|
| 49 | CommandLineDialog::~CommandLineDialog()
 | 
|---|
| 50 | {
 | 
|---|
| 51 | }
 | 
|---|
| 52 | 
 | 
|---|
| 53 | 
 | 
|---|
| 54 | void CommandLineDialog::queryEmpty(const char* title, string _description){
 | 
|---|
| 55 |   registerQuery(new EmptyCommandLineQuery(title, _description));
 | 
|---|
| 56 | }
 | 
|---|
| 57 | 
 | 
|---|
| 58 | void CommandLineDialog::queryInt(const char* title, string _description){
 | 
|---|
| 59 |   registerQuery(new IntCommandLineQuery(title, _description));
 | 
|---|
| 60 | }
 | 
|---|
| 61 | 
 | 
|---|
| 62 | void CommandLineDialog::queryInts(const char* title, string _description){
 | 
|---|
| 63 |   registerQuery(new IntsCommandLineQuery(title, _description));
 | 
|---|
| 64 | }
 | 
|---|
| 65 | 
 | 
|---|
| 66 | void CommandLineDialog::queryBoolean(const char* title, string _description){
 | 
|---|
| 67 |   registerQuery(new BooleanCommandLineQuery(title, _description));
 | 
|---|
| 68 | }
 | 
|---|
| 69 | 
 | 
|---|
| 70 | void CommandLineDialog::queryDouble(const char* title, string _description){
 | 
|---|
| 71 |   registerQuery(new DoubleCommandLineQuery(title, _description));
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | void CommandLineDialog::queryDoubles(const char* title, string _description){
 | 
|---|
| 75 |   registerQuery(new DoublesCommandLineQuery(title, _description));
 | 
|---|
| 76 | }
 | 
|---|
| 77 | 
 | 
|---|
| 78 | void CommandLineDialog::queryString(const char* title, string _description){
 | 
|---|
| 79 |   registerQuery(new StringCommandLineQuery(title, _description));
 | 
|---|
| 80 | }
 | 
|---|
| 81 | 
 | 
|---|
| 82 | void CommandLineDialog::queryStrings(const char* title, string _description){
 | 
|---|
| 83 |   registerQuery(new StringsCommandLineQuery(title, _description));
 | 
|---|
| 84 | }
 | 
|---|
| 85 | 
 | 
|---|
| 86 | void CommandLineDialog::queryAtom(const char* title, string _description) {
 | 
|---|
| 87 |   registerQuery(new AtomCommandLineQuery(title, _description));
 | 
|---|
| 88 | }
 | 
|---|
| 89 | 
 | 
|---|
| 90 | void CommandLineDialog::queryAtoms(const char* title, string _description) {
 | 
|---|
| 91 |   registerQuery(new AtomsCommandLineQuery(title, _description));
 | 
|---|
| 92 | }
 | 
|---|
| 93 | 
 | 
|---|
| 94 | void CommandLineDialog::queryMolecule(const char* title, string _description) {
 | 
|---|
| 95 |   registerQuery(new MoleculeCommandLineQuery(title, _description));
 | 
|---|
| 96 | }
 | 
|---|
| 97 | 
 | 
|---|
| 98 | void CommandLineDialog::queryMolecules(const char* title, string _description) {
 | 
|---|
| 99 |   registerQuery(new MoleculesCommandLineQuery(title, _description));
 | 
|---|
| 100 | }
 | 
|---|
| 101 | 
 | 
|---|
| 102 | void CommandLineDialog::queryVector(const char* title, bool check, string _description) {
 | 
|---|
| 103 |   registerQuery(new VectorCommandLineQuery(title,check, _description));
 | 
|---|
| 104 | }
 | 
|---|
| 105 | 
 | 
|---|
| 106 | void CommandLineDialog::queryVectors(const char* title, bool check, string _description) {
 | 
|---|
| 107 |   registerQuery(new VectorsCommandLineQuery(title,check, _description));
 | 
|---|
| 108 | }
 | 
|---|
| 109 | 
 | 
|---|
| 110 | void CommandLineDialog::queryBox(const char* title, string _description) {
 | 
|---|
| 111 |   registerQuery(new BoxCommandLineQuery(title,_description));
 | 
|---|
| 112 | }
 | 
|---|
| 113 | 
 | 
|---|
| 114 | void CommandLineDialog::queryElement(const char* title, string _description){
 | 
|---|
| 115 |   registerQuery(new ElementCommandLineQuery(title, _description));
 | 
|---|
| 116 | }
 | 
|---|
| 117 | 
 | 
|---|
| 118 | void CommandLineDialog::queryElements(const char* title, string _description){
 | 
|---|
| 119 |   registerQuery(new ElementsCommandLineQuery(title, _description));
 | 
|---|
| 120 | }
 | 
|---|
| 121 | 
 | 
|---|
| 122 | /************************** Query Infrastructure ************************/
 | 
|---|
| 123 | 
 | 
|---|
| 124 | CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
 | 
|---|
| 125 |     Dialog::EmptyQuery(title, _description)
 | 
|---|
| 126 | {}
 | 
|---|
| 127 | 
 | 
|---|
| 128 | CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
 | 
|---|
| 129 | 
 | 
|---|
| 130 | bool CommandLineDialog::EmptyCommandLineQuery::handle() {
 | 
|---|
| 131 |   cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
 | 
|---|
| 132 |   return true;
 | 
|---|
| 133 | }
 | 
|---|
| 134 | 
 | 
|---|
| 135 | CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title, string _description) :
 | 
|---|
| 136 |     Dialog::IntQuery(title, _description)
 | 
|---|
| 137 | {}
 | 
|---|
| 138 | 
 | 
|---|
| 139 | CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
 | 
|---|
| 140 | 
 | 
|---|
| 141 | bool CommandLineDialog::IntCommandLineQuery::handle() {
 | 
|---|
| 142 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 143 |     tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
 | 
|---|
| 144 |     return true;
 | 
|---|
| 145 |   } else {
 | 
|---|
| 146 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl);
 | 
|---|
| 147 |     return false;
 | 
|---|
| 148 |   }
 | 
|---|
| 149 | }
 | 
|---|
| 150 | 
 | 
|---|
| 151 | CommandLineDialog::IntsCommandLineQuery::IntsCommandLineQuery(string title, string _description) :
 | 
|---|
| 152 |     Dialog::IntsQuery(title, _description)
 | 
|---|
| 153 | {}
 | 
|---|
| 154 | 
 | 
|---|
| 155 | CommandLineDialog::IntsCommandLineQuery::~IntsCommandLineQuery() {}
 | 
|---|
| 156 | 
 | 
|---|
| 157 | bool CommandLineDialog::IntsCommandLineQuery::handle() {
 | 
|---|
| 158 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 159 |     tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
 | 
|---|
| 160 |     return true;
 | 
|---|
| 161 |   } else {
 | 
|---|
| 162 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integers for " << getTitle() << "." << endl);
 | 
|---|
| 163 |     return false;
 | 
|---|
| 164 |   }
 | 
|---|
| 165 | }
 | 
|---|
| 166 | 
 | 
|---|
| 167 | CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title, string _description) :
 | 
|---|
| 168 |     Dialog::BooleanQuery(title, _description)
 | 
|---|
| 169 | {}
 | 
|---|
| 170 | 
 | 
|---|
| 171 | CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
 | 
|---|
| 172 | 
 | 
|---|
| 173 | bool CommandLineDialog::BooleanCommandLineQuery::handle() {
 | 
|---|
| 174 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 175 |     tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>();
 | 
|---|
| 176 |     return true;
 | 
|---|
| 177 |   } else {
 | 
|---|
| 178 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl);
 | 
|---|
| 179 |     return false;
 | 
|---|
| 180 |   }
 | 
|---|
| 181 | }
 | 
|---|
| 182 | 
 | 
|---|
| 183 | CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title, string _description) :
 | 
|---|
| 184 |     Dialog::StringQuery(title, _description)
 | 
|---|
| 185 | {}
 | 
|---|
| 186 | 
 | 
|---|
| 187 | CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
 | 
|---|
| 188 | 
 | 
|---|
| 189 | bool CommandLineDialog::StringCommandLineQuery::handle() {
 | 
|---|
| 190 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 191 |     tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
 | 
|---|
| 192 |     return true;
 | 
|---|
| 193 |   } else {
 | 
|---|
| 194 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
 | 
|---|
| 195 |     return false;
 | 
|---|
| 196 |   }
 | 
|---|
| 197 | }
 | 
|---|
| 198 | 
 | 
|---|
| 199 | CommandLineDialog::StringsCommandLineQuery::StringsCommandLineQuery(string title, string _description) :
 | 
|---|
| 200 |     Dialog::StringsQuery(title, _description)
 | 
|---|
| 201 | {}
 | 
|---|
| 202 | 
 | 
|---|
| 203 | CommandLineDialog::StringsCommandLineQuery::~StringsCommandLineQuery() {}
 | 
|---|
| 204 | 
 | 
|---|
| 205 | bool CommandLineDialog::StringsCommandLineQuery::handle() {
 | 
|---|
| 206 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 207 |     tmp = CommandLineParser::getInstance().vm[getTitle()].as< vector<string> >();
 | 
|---|
| 208 |     return true;
 | 
|---|
| 209 |   } else {
 | 
|---|
| 210 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing strings for " << getTitle() << "." << endl);
 | 
|---|
| 211 |     return false;
 | 
|---|
| 212 |   }
 | 
|---|
| 213 | }
 | 
|---|
| 214 | 
 | 
|---|
| 215 | CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title, string _description) :
 | 
|---|
| 216 |     Dialog::DoubleQuery(title, _description)
 | 
|---|
| 217 | {}
 | 
|---|
| 218 | 
 | 
|---|
| 219 | CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
 | 
|---|
| 220 | 
 | 
|---|
| 221 | bool CommandLineDialog::DoubleCommandLineQuery::handle() {
 | 
|---|
| 222 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 223 |     tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
 | 
|---|
| 224 |     return true;
 | 
|---|
| 225 |   } else {
 | 
|---|
| 226 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl);
 | 
|---|
| 227 |     return false;
 | 
|---|
| 228 |   }
 | 
|---|
| 229 | }
 | 
|---|
| 230 | 
 | 
|---|
| 231 | CommandLineDialog::DoublesCommandLineQuery::DoublesCommandLineQuery(string title, string _description) :
 | 
|---|
| 232 |     Dialog::DoublesQuery(title, _description)
 | 
|---|
| 233 | {}
 | 
|---|
| 234 | 
 | 
|---|
| 235 | CommandLineDialog::DoublesCommandLineQuery::~DoublesCommandLineQuery() {}
 | 
|---|
| 236 | 
 | 
|---|
| 237 | bool CommandLineDialog::DoublesCommandLineQuery::handle() {
 | 
|---|
| 238 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 239 |     tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<double> >();
 | 
|---|
| 240 |     return true;
 | 
|---|
| 241 |   } else {
 | 
|---|
| 242 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing doubles for " << getTitle() << "." << endl);
 | 
|---|
| 243 |     return false;
 | 
|---|
| 244 |   }
 | 
|---|
| 245 | }
 | 
|---|
| 246 | 
 | 
|---|
| 247 | CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, string _description) :
 | 
|---|
| 248 |     Dialog::AtomQuery(title, _description)
 | 
|---|
| 249 | {}
 | 
|---|
| 250 | 
 | 
|---|
| 251 | CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {}
 | 
|---|
| 252 | 
 | 
|---|
| 253 | bool CommandLineDialog::AtomCommandLineQuery::handle() {
 | 
|---|
| 254 |   int IdxOfAtom = -1;
 | 
|---|
| 255 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 256 |     IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>();
 | 
|---|
| 257 |     tmp = World::getInstance().getAtom(AtomById(IdxOfAtom));
 | 
|---|
| 258 |     return true;
 | 
|---|
| 259 |   } else {
 | 
|---|
| 260 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl);
 | 
|---|
| 261 |     return false;
 | 
|---|
| 262 |   }
 | 
|---|
| 263 | }
 | 
|---|
| 264 | 
 | 
|---|
| 265 | CommandLineDialog::AtomsCommandLineQuery::AtomsCommandLineQuery(string title, string _description) :
 | 
|---|
| 266 |     Dialog::AtomsQuery(title, _description)
 | 
|---|
| 267 | {}
 | 
|---|
| 268 | 
 | 
|---|
| 269 | CommandLineDialog::AtomsCommandLineQuery::~AtomsCommandLineQuery() {}
 | 
|---|
| 270 | 
 | 
|---|
| 271 | bool CommandLineDialog::AtomsCommandLineQuery::handle() {
 | 
|---|
| 272 |   std::vector<int> IdxOfAtom;
 | 
|---|
| 273 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 274 |     IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
 | 
|---|
| 275 |     for (std::vector<int>::iterator iter = IdxOfAtom.begin(); iter != IdxOfAtom.end(); ++iter) {
 | 
|---|
| 276 |       temp = World::getInstance().getAtom(AtomById(*iter));
 | 
|---|
| 277 |       if (temp)
 | 
|---|
| 278 |         tmp.push_back(temp);
 | 
|---|
| 279 |     }
 | 
|---|
| 280 |     return true;
 | 
|---|
| 281 |   } else {
 | 
|---|
| 282 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atoms for " << getTitle() << "." << endl);
 | 
|---|
| 283 |     return false;
 | 
|---|
| 284 |   }
 | 
|---|
| 285 | }
 | 
|---|
| 286 | 
 | 
|---|
| 287 | CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, string _description) :
 | 
|---|
| 288 |     Dialog::MoleculeQuery(title, _description)
 | 
|---|
| 289 | {}
 | 
|---|
| 290 | 
 | 
|---|
| 291 | CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
 | 
|---|
| 292 | 
 | 
|---|
| 293 | bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
 | 
|---|
| 294 |   int IdxOfMol = -1;
 | 
|---|
| 295 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 296 |     IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
 | 
|---|
| 297 |     tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
 | 
|---|
| 298 |     return true;
 | 
|---|
| 299 |   } else {
 | 
|---|
| 300 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl);
 | 
|---|
| 301 |     return false;
 | 
|---|
| 302 |   }
 | 
|---|
| 303 | }
 | 
|---|
| 304 | 
 | 
|---|
| 305 | CommandLineDialog::MoleculesCommandLineQuery::MoleculesCommandLineQuery(string title, string _description) :
 | 
|---|
| 306 |     Dialog::MoleculesQuery(title, _description)
 | 
|---|
| 307 | {}
 | 
|---|
| 308 | 
 | 
|---|
| 309 | CommandLineDialog::MoleculesCommandLineQuery::~MoleculesCommandLineQuery() {}
 | 
|---|
| 310 | 
 | 
|---|
| 311 | bool CommandLineDialog::MoleculesCommandLineQuery::handle() {
 | 
|---|
| 312 |   std::vector<int> IdxOfMol;
 | 
|---|
| 313 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 314 |     IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
 | 
|---|
| 315 |     for (std::vector<int>::iterator iter = IdxOfMol.begin(); iter != IdxOfMol.end(); ++iter) {
 | 
|---|
| 316 |       temp = World::getInstance().getMolecule(MoleculeById(*iter));
 | 
|---|
| 317 |       if (temp)
 | 
|---|
| 318 |         tmp.push_back(temp);
 | 
|---|
| 319 |     }
 | 
|---|
| 320 |     return true;
 | 
|---|
| 321 |   } else {
 | 
|---|
| 322 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecules for " << getTitle() << "." << endl);
 | 
|---|
| 323 |     return false;
 | 
|---|
| 324 |   }
 | 
|---|
| 325 | }
 | 
|---|
| 326 | 
 | 
|---|
| 327 | CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, bool _check, string _description) :
 | 
|---|
| 328 |     Dialog::VectorQuery(title,_check, _description)
 | 
|---|
| 329 | {}
 | 
|---|
| 330 | 
 | 
|---|
| 331 | CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
 | 
|---|
| 332 | {}
 | 
|---|
| 333 | 
 | 
|---|
| 334 | bool CommandLineDialog::VectorCommandLineQuery::handle() {
 | 
|---|
| 335 |   VectorValue temp;
 | 
|---|
| 336 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 337 |     temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
 | 
|---|
| 338 |     tmp[0] = temp.x;
 | 
|---|
| 339 |     tmp[1] = temp.y;
 | 
|---|
| 340 |     tmp[2] = temp.z;
 | 
|---|
| 341 |     if ((check) && (!World::getInstance().getDomain().isInside(tmp))) {
 | 
|---|
| 342 |       DoeLog(1) && (eLog() << Verbose(1) << "Vector " << tmp << " would be outside of box domain." << endl);
 | 
|---|
| 343 |       return false;
 | 
|---|
| 344 |     }
 | 
|---|
| 345 |     return true;
 | 
|---|
| 346 |   } else {
 | 
|---|
| 347 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl);
 | 
|---|
| 348 |     return false;
 | 
|---|
| 349 |   }
 | 
|---|
| 350 | }
 | 
|---|
| 351 | 
 | 
|---|
| 352 | CommandLineDialog::VectorsCommandLineQuery::VectorsCommandLineQuery(string title, bool _check, string _description) :
 | 
|---|
| 353 |     Dialog::VectorsQuery(title,_check, _description)
 | 
|---|
| 354 | {}
 | 
|---|
| 355 | 
 | 
|---|
| 356 | CommandLineDialog::VectorsCommandLineQuery::~VectorsCommandLineQuery()
 | 
|---|
| 357 | {}
 | 
|---|
| 358 | 
 | 
|---|
| 359 | bool CommandLineDialog::VectorsCommandLineQuery::handle() {
 | 
|---|
| 360 |   std::vector<VectorValue> temporary;
 | 
|---|
| 361 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 362 |     temporary = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<VectorValue> >();
 | 
|---|
| 363 |     for(std::vector<VectorValue>::iterator iter = temporary.begin(); iter != temporary.end(); ++iter) {
 | 
|---|
| 364 |       temp[0] = (*iter).x;
 | 
|---|
| 365 |       temp[1] = (*iter).y;
 | 
|---|
| 366 |       temp[2] = (*iter).z;
 | 
|---|
| 367 |       if ((!check) || (World::getInstance().getDomain().isInside(temp)))
 | 
|---|
| 368 |         tmp.push_back(temp);
 | 
|---|
| 369 |       else
 | 
|---|
| 370 |         DoeLog(1) && (eLog() << Verbose(1) << "Vector " << temp << " would be outside of box domain." << endl);
 | 
|---|
| 371 |     }
 | 
|---|
| 372 |     return true;
 | 
|---|
| 373 |   } else {
 | 
|---|
| 374 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vectors for " << getTitle() << "." << endl);
 | 
|---|
| 375 |     return false;
 | 
|---|
| 376 |   }
 | 
|---|
| 377 | }
 | 
|---|
| 378 | 
 | 
|---|
| 379 | CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, string _description) :
 | 
|---|
| 380 |     Dialog::BoxQuery(title, _description)
 | 
|---|
| 381 | {}
 | 
|---|
| 382 | 
 | 
|---|
| 383 | CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery()
 | 
|---|
| 384 | {}
 | 
|---|
| 385 | 
 | 
|---|
| 386 | bool CommandLineDialog::BoxCommandLineQuery::handle() {
 | 
|---|
| 387 |   BoxValue temp;
 | 
|---|
| 388 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 389 |     temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >();
 | 
|---|
| 390 |     Matrix M;
 | 
|---|
| 391 |     M.set(0,0, temp.xx);
 | 
|---|
| 392 |     M.set(0,1, temp.yx);
 | 
|---|
| 393 |     M.set(0,2, temp.zx);
 | 
|---|
| 394 |     M.set(1,0, temp.yx);
 | 
|---|
| 395 |     M.set(1,1, temp.yy);
 | 
|---|
| 396 |     M.set(1,2, temp.zy);
 | 
|---|
| 397 |     M.set(2,0, temp.zx);
 | 
|---|
| 398 |     M.set(2,1, temp.zy);
 | 
|---|
| 399 |     M.set(2,2, temp.zz);
 | 
|---|
| 400 |     tmp.setM(M);
 | 
|---|
| 401 |     return true;
 | 
|---|
| 402 |   } else {
 | 
|---|
| 403 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl);
 | 
|---|
| 404 |     return false;
 | 
|---|
| 405 |   }
 | 
|---|
| 406 | }
 | 
|---|
| 407 | 
 | 
|---|
| 408 | CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, string _description) :
 | 
|---|
| 409 |     Dialog::ElementQuery(title, _description)
 | 
|---|
| 410 | {}
 | 
|---|
| 411 | 
 | 
|---|
| 412 | CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
 | 
|---|
| 413 | {}
 | 
|---|
| 414 | 
 | 
|---|
| 415 | bool CommandLineDialog::ElementCommandLineQuery::handle() {
 | 
|---|
| 416 |   // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
 | 
|---|
| 417 |   periodentafel *periode = World::getInstance().getPeriode();
 | 
|---|
| 418 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 419 |     int Z = CommandLineParser::getInstance().vm[getTitle()].as< int >();
 | 
|---|
| 420 |     tmp = periode->FindElement(Z);
 | 
|---|
| 421 |     ASSERT(tmp != NULL, "Invalid element specified in ElementCommandLineQuery");
 | 
|---|
| 422 |     return true;
 | 
|---|
| 423 |   } else {
 | 
|---|
| 424 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl);
 | 
|---|
| 425 |     return false;
 | 
|---|
| 426 |   }
 | 
|---|
| 427 | }
 | 
|---|
| 428 | 
 | 
|---|
| 429 | CommandLineDialog::ElementsCommandLineQuery::ElementsCommandLineQuery(string title, string _description) :
 | 
|---|
| 430 |     Dialog::ElementsQuery(title, _description)
 | 
|---|
| 431 | {}
 | 
|---|
| 432 | 
 | 
|---|
| 433 | CommandLineDialog::ElementsCommandLineQuery::~ElementsCommandLineQuery()
 | 
|---|
| 434 | {}
 | 
|---|
| 435 | 
 | 
|---|
| 436 | bool CommandLineDialog::ElementsCommandLineQuery::handle() {
 | 
|---|
| 437 |   // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
 | 
|---|
| 438 |   periodentafel *periode = World::getInstance().getPeriode();
 | 
|---|
| 439 |   if (CommandLineParser::getInstance().vm.count(getTitle())) {
 | 
|---|
| 440 |     vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
 | 
|---|
| 441 |     for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) {
 | 
|---|
| 442 |       temp = periode->FindElement(*ZRunner);
 | 
|---|
| 443 |       ASSERT(temp != NULL, "Invalid element specified in ElementCommandLineQuery");
 | 
|---|
| 444 |       tmp.push_back(temp);
 | 
|---|
| 445 |     }
 | 
|---|
| 446 |     return true;
 | 
|---|
| 447 |   } else {
 | 
|---|
| 448 |     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing elements for " << getTitle() << "." << endl);
 | 
|---|
| 449 |     return false;
 | 
|---|
| 450 |   }
 | 
|---|
| 451 | }
 | 
|---|