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