| 1 | /*
|
|---|
| 2 | * CommandLineDialog.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 8, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include <cassert>
|
|---|
| 11 | #include <iostream>
|
|---|
| 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 "element.hpp"
|
|---|
| 20 | #include "periodentafel.hpp"
|
|---|
| 21 | #include "CommandLineParser.hpp"
|
|---|
| 22 | #include "defs.hpp"
|
|---|
| 23 | #include "log.hpp"
|
|---|
| 24 | #include "periodentafel.hpp"
|
|---|
| 25 | #include "verbose.hpp"
|
|---|
| 26 | #include "World.hpp"
|
|---|
| 27 |
|
|---|
| 28 | #include "atom.hpp"
|
|---|
| 29 | #include "element.hpp"
|
|---|
| 30 | #include "molecule.hpp"
|
|---|
| 31 | #include "vector.hpp"
|
|---|
| 32 |
|
|---|
| 33 | using namespace std;
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | CommandLineDialog::CommandLineDialog()
|
|---|
| 37 | {
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | CommandLineDialog::~CommandLineDialog()
|
|---|
| 41 | {
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | void CommandLineDialog::queryEmpty(const char* title, string _description){
|
|---|
| 46 | registerQuery(new EmptyCommandLineQuery(title, _description));
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | void CommandLineDialog::queryInt(const char* title, int* target, string _description){
|
|---|
| 50 | registerQuery(new IntCommandLineQuery(title,target, _description));
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){
|
|---|
| 54 | registerQuery(new BooleanCommandLineQuery(title,target, _description));
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | void CommandLineDialog::queryDouble(const char* title, double* target, string _description){
|
|---|
| 58 | registerQuery(new DoubleCommandLineQuery(title,target, _description));
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | void CommandLineDialog::queryString(const char* title, string* target, string _description){
|
|---|
| 62 | registerQuery(new StringCommandLineQuery(title,target, _description));
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | void CommandLineDialog::queryAtom(const char* title, atom **target, string _description) {
|
|---|
| 66 | registerQuery(new AtomCommandLineQuery(title,target, _description));
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | void CommandLineDialog::queryMolecule(const char* title, molecule **target, string _description) {
|
|---|
| 70 | registerQuery(new MoleculeCommandLineQuery(title,target, _description));
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check, string _description) {
|
|---|
| 74 | registerQuery(new VectorCommandLineQuery(title,target,cellSize,check, _description));
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void CommandLineDialog::queryBox(const char* title, double ** const cellSize, string _description) {
|
|---|
| 78 | registerQuery(new BoxCommandLineQuery(title,cellSize,_description));
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void CommandLineDialog::queryElement(const char* title, const element **target, string _description){
|
|---|
| 82 | registerQuery(new ElementCommandLineQuery(title,target, _description));
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | /************************** Query Infrastructure ************************/
|
|---|
| 86 |
|
|---|
| 87 | CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
|
|---|
| 88 | Dialog::EmptyQuery(title, _description)
|
|---|
| 89 | {}
|
|---|
| 90 |
|
|---|
| 91 | CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
|
|---|
| 92 |
|
|---|
| 93 | bool CommandLineDialog::EmptyCommandLineQuery::handle() {
|
|---|
| 94 | cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
|
|---|
| 95 | return true;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) :
|
|---|
| 99 | Dialog::IntQuery(title,_target, _description)
|
|---|
| 100 | {}
|
|---|
| 101 |
|
|---|
| 102 | CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
|
|---|
| 103 |
|
|---|
| 104 | bool CommandLineDialog::IntCommandLineQuery::handle() {
|
|---|
| 105 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 106 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
|---|
| 107 | return true;
|
|---|
| 108 | } else
|
|---|
| 109 | return false;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) :
|
|---|
| 113 | Dialog::BooleanQuery(title,_target, _description)
|
|---|
| 114 | {}
|
|---|
| 115 |
|
|---|
| 116 | CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
|
|---|
| 117 |
|
|---|
| 118 | bool CommandLineDialog::BooleanCommandLineQuery::handle() {
|
|---|
| 119 | bool badInput = false;
|
|---|
| 120 | char input = ' ';
|
|---|
| 121 | do{
|
|---|
| 122 | badInput = false;
|
|---|
| 123 | Log() << Verbose(0) << getTitle();
|
|---|
| 124 | cin >> input;
|
|---|
| 125 | if ((input == 'y' ) || (input == 'Y')) {
|
|---|
| 126 | tmp = true;
|
|---|
| 127 | } else if ((input == 'n' ) || (input == 'N')) {
|
|---|
| 128 | tmp = false;
|
|---|
| 129 | } else {
|
|---|
| 130 | badInput=true;
|
|---|
| 131 | cin.clear();
|
|---|
| 132 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
|---|
| 133 | Log() << Verbose(0) << "Input was not of [yYnN]!" << endl;
|
|---|
| 134 | }
|
|---|
| 135 | } while(badInput);
|
|---|
| 136 | // clear the input buffer of anything still in the line
|
|---|
| 137 | cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
|
|---|
| 138 | return true;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
|
|---|
| 142 | Dialog::StringQuery(title,_target, _description)
|
|---|
| 143 | {}
|
|---|
| 144 |
|
|---|
| 145 | CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
|
|---|
| 146 |
|
|---|
| 147 | bool CommandLineDialog::StringCommandLineQuery::handle() {
|
|---|
| 148 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 149 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
|
|---|
| 150 | return true;
|
|---|
| 151 | } else
|
|---|
| 152 | return false;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
|
|---|
| 156 | Dialog::DoubleQuery(title,_target, _description)
|
|---|
| 157 | {}
|
|---|
| 158 |
|
|---|
| 159 | CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
|
|---|
| 160 |
|
|---|
| 161 | bool CommandLineDialog::DoubleCommandLineQuery::handle() {
|
|---|
| 162 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 163 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
|
|---|
| 164 | return true;
|
|---|
| 165 | } else
|
|---|
| 166 | return false;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) :
|
|---|
| 170 | Dialog::AtomQuery(title,_target, _description)
|
|---|
| 171 | {}
|
|---|
| 172 |
|
|---|
| 173 | CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {}
|
|---|
| 174 |
|
|---|
| 175 | bool CommandLineDialog::AtomCommandLineQuery::handle() {
|
|---|
| 176 | int IdxOfAtom = -1;
|
|---|
| 177 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 178 | IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
|---|
| 179 | tmp = World::getInstance().getAtom(AtomById(IdxOfAtom));
|
|---|
| 180 | return true;
|
|---|
| 181 | } else
|
|---|
| 182 | return false;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) :
|
|---|
| 186 | Dialog::MoleculeQuery(title,_target, _description)
|
|---|
| 187 | {}
|
|---|
| 188 |
|
|---|
| 189 | CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
|
|---|
| 190 |
|
|---|
| 191 | bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
|
|---|
| 192 | int IdxOfMol = -1;
|
|---|
| 193 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 194 | IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
|---|
| 195 | cout << "IdxOfMol " << IdxOfMol << endl;
|
|---|
| 196 | if (IdxOfMol >= 0)
|
|---|
| 197 | tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
|
|---|
| 198 | else
|
|---|
| 199 | tmp = NULL;
|
|---|
| 200 | return true;
|
|---|
| 201 | } else
|
|---|
| 202 | return false;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) :
|
|---|
| 206 | Dialog::VectorQuery(title,_target,_cellSize,_check, _description)
|
|---|
| 207 | {}
|
|---|
| 208 |
|
|---|
| 209 | CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
|
|---|
| 210 | {}
|
|---|
| 211 |
|
|---|
| 212 | bool CommandLineDialog::VectorCommandLineQuery::handle() {
|
|---|
| 213 | vector<double> temp;
|
|---|
| 214 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 215 | temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >();
|
|---|
| 216 | assert((temp.size() == 3) && "Vector from command line does not have three components.");
|
|---|
| 217 | for (int i=0;i<NDIM;i++)
|
|---|
| 218 | tmp->at(i) = temp[i];
|
|---|
| 219 | return true;
|
|---|
| 220 | } else
|
|---|
| 221 | return false;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 | CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, double ** const _cellSize, string _description) :
|
|---|
| 226 | Dialog::BoxQuery(title,_cellSize, _description)
|
|---|
| 227 | {}
|
|---|
| 228 |
|
|---|
| 229 | CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery()
|
|---|
| 230 | {}
|
|---|
| 231 |
|
|---|
| 232 | bool CommandLineDialog::BoxCommandLineQuery::handle() {
|
|---|
| 233 | vector<double> temp;
|
|---|
| 234 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 235 | temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >();
|
|---|
| 236 | assert((temp.size() == 6) && "Symmetric box matrix from command line does not have six components.");
|
|---|
| 237 | for (int i=0;i<6;i++) {
|
|---|
| 238 | tmp[i] = temp[i];
|
|---|
| 239 | }
|
|---|
| 240 | return true;
|
|---|
| 241 | } else
|
|---|
| 242 | return false;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, const element **target, string _description) :
|
|---|
| 246 | Dialog::ElementQuery(title,target, _description)
|
|---|
| 247 | {}
|
|---|
| 248 |
|
|---|
| 249 | CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
|
|---|
| 250 | {}
|
|---|
| 251 |
|
|---|
| 252 | bool CommandLineDialog::ElementCommandLineQuery::handle() {
|
|---|
| 253 | // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
|
|---|
| 254 | int Z;
|
|---|
| 255 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 256 | vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
|
|---|
| 257 | vector<int>::iterator ElementRunner = AllElements.begin();
|
|---|
| 258 | Z = *ElementRunner;
|
|---|
| 259 | // TODO: So far, this does not really erase the element in the parsed list.
|
|---|
| 260 | AllElements.erase(ElementRunner);
|
|---|
| 261 | tmp = World::getInstance().getPeriode()->FindElement(Z);
|
|---|
| 262 | return true;
|
|---|
| 263 | } else
|
|---|
| 264 | return false;
|
|---|
| 265 | }
|
|---|