| [a2ab15] | 1 | /*
|
|---|
| 2 | * CommandLineDialog.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 8, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| [d90762] | 9 | #include <cassert>
|
|---|
| [a2ab15] | 10 | #include <iostream>
|
|---|
| 11 |
|
|---|
| [97ebf8] | 12 | #include <Descriptors/AtomDescriptor.hpp>
|
|---|
| 13 | #include <Descriptors/AtomIdDescriptor.hpp>
|
|---|
| [d90762] | 14 | #include <Descriptors/MoleculeDescriptor.hpp>
|
|---|
| 15 | #include <Descriptors/MoleculeIdDescriptor.hpp>
|
|---|
| [5079a0] | 16 | #include "CommandLineUI/CommandLineDialog.hpp"
|
|---|
| [a2ab15] | 17 |
|
|---|
| [0286bc] | 18 | #include "Actions/Values.hpp"
|
|---|
| 19 |
|
|---|
| [97ebf8] | 20 | #include "element.hpp"
|
|---|
| [a2ab15] | 21 | #include "periodentafel.hpp"
|
|---|
| [d90762] | 22 | #include "CommandLineParser.hpp"
|
|---|
| 23 | #include "defs.hpp"
|
|---|
| [a2ab15] | 24 | #include "log.hpp"
|
|---|
| [97ebf8] | 25 | #include "periodentafel.hpp"
|
|---|
| [a2ab15] | 26 | #include "verbose.hpp"
|
|---|
| [d90762] | 27 | #include "World.hpp"
|
|---|
| [a2ab15] | 28 |
|
|---|
| [97ebf8] | 29 | #include "atom.hpp"
|
|---|
| 30 | #include "element.hpp"
|
|---|
| 31 | #include "molecule.hpp"
|
|---|
| 32 | #include "vector.hpp"
|
|---|
| 33 |
|
|---|
| [a2ab15] | 34 | using namespace std;
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | CommandLineDialog::CommandLineDialog()
|
|---|
| 38 | {
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | CommandLineDialog::~CommandLineDialog()
|
|---|
| 42 | {
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| [86466e] | 46 | void CommandLineDialog::queryEmpty(const char* title, string _description){
|
|---|
| 47 | registerQuery(new EmptyCommandLineQuery(title, _description));
|
|---|
| [a2ab15] | 48 | }
|
|---|
| 49 |
|
|---|
| [86466e] | 50 | void CommandLineDialog::queryInt(const char* title, int* target, string _description){
|
|---|
| 51 | registerQuery(new IntCommandLineQuery(title,target, _description));
|
|---|
| [a2ab15] | 52 | }
|
|---|
| 53 |
|
|---|
| [97ebf8] | 54 | void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){
|
|---|
| 55 | registerQuery(new BooleanCommandLineQuery(title,target, _description));
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| [86466e] | 58 | void CommandLineDialog::queryDouble(const char* title, double* target, string _description){
|
|---|
| 59 | registerQuery(new DoubleCommandLineQuery(title,target, _description));
|
|---|
| [a2ab15] | 60 | }
|
|---|
| 61 |
|
|---|
| [86466e] | 62 | void CommandLineDialog::queryString(const char* title, string* target, string _description){
|
|---|
| 63 | registerQuery(new StringCommandLineQuery(title,target, _description));
|
|---|
| [a2ab15] | 64 | }
|
|---|
| 65 |
|
|---|
| [97ebf8] | 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));
|
|---|
| [a2ab15] | 72 | }
|
|---|
| 73 |
|
|---|
| [86466e] | 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 |
|
|---|
| [97ebf8] | 78 | void CommandLineDialog::queryBox(const char* title, double ** const cellSize, string _description) {
|
|---|
| 79 | registerQuery(new BoxCommandLineQuery(title,cellSize,_description));
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| [86466e] | 82 | void CommandLineDialog::queryElement(const char* title, const element **target, string _description){
|
|---|
| 83 | registerQuery(new ElementCommandLineQuery(title,target, _description));
|
|---|
| [a2ab15] | 84 | }
|
|---|
| 85 |
|
|---|
| 86 | /************************** Query Infrastructure ************************/
|
|---|
| 87 |
|
|---|
| [86466e] | 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)
|
|---|
| [a2ab15] | 101 | {}
|
|---|
| 102 |
|
|---|
| [86466e] | 103 | CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
|
|---|
| [a2ab15] | 104 |
|
|---|
| [86466e] | 105 | bool CommandLineDialog::IntCommandLineQuery::handle() {
|
|---|
| [d90762] | 106 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 107 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
|---|
| 108 | return true;
|
|---|
| 109 | } else
|
|---|
| 110 | return false;
|
|---|
| [a2ab15] | 111 | }
|
|---|
| 112 |
|
|---|
| [97ebf8] | 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() {
|
|---|
| [0286bc] | 120 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 121 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>();
|
|---|
| 122 | return true;
|
|---|
| 123 | } else
|
|---|
| 124 | return false;
|
|---|
| [97ebf8] | 125 | }
|
|---|
| 126 |
|
|---|
| [86466e] | 127 | CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
|
|---|
| 128 | Dialog::StringQuery(title,_target, _description)
|
|---|
| [a2ab15] | 129 | {}
|
|---|
| 130 |
|
|---|
| [86466e] | 131 | CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
|
|---|
| [a2ab15] | 132 |
|
|---|
| [86466e] | 133 | bool CommandLineDialog::StringCommandLineQuery::handle() {
|
|---|
| [d90762] | 134 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| [86466e] | 135 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
|
|---|
| [d90762] | 136 | return true;
|
|---|
| 137 | } else
|
|---|
| 138 | return false;
|
|---|
| [a2ab15] | 139 | }
|
|---|
| 140 |
|
|---|
| [86466e] | 141 | CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
|
|---|
| 142 | Dialog::DoubleQuery(title,_target, _description)
|
|---|
| [a2ab15] | 143 | {}
|
|---|
| 144 |
|
|---|
| [86466e] | 145 | CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
|
|---|
| [a2ab15] | 146 |
|
|---|
| [86466e] | 147 | bool CommandLineDialog::DoubleCommandLineQuery::handle() {
|
|---|
| [d90762] | 148 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 149 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
|
|---|
| 150 | return true;
|
|---|
| 151 | } else
|
|---|
| 152 | return false;
|
|---|
| [a2ab15] | 153 | }
|
|---|
| 154 |
|
|---|
| [97ebf8] | 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)
|
|---|
| [a2ab15] | 173 | {}
|
|---|
| 174 |
|
|---|
| [86466e] | 175 | CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
|
|---|
| [a2ab15] | 176 |
|
|---|
| [86466e] | 177 | bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
|
|---|
| [d90762] | 178 | int IdxOfMol = -1;
|
|---|
| 179 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 180 | IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
|---|
| [e30ce8] | 181 | cout << "IdxOfMol " << IdxOfMol << endl;
|
|---|
| 182 | if (IdxOfMol >= 0)
|
|---|
| 183 | tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
|
|---|
| 184 | else
|
|---|
| 185 | tmp = NULL;
|
|---|
| [d90762] | 186 | return true;
|
|---|
| 187 | } else
|
|---|
| 188 | return false;
|
|---|
| [a2ab15] | 189 | }
|
|---|
| 190 |
|
|---|
| [86466e] | 191 | CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) :
|
|---|
| 192 | Dialog::VectorQuery(title,_target,_cellSize,_check, _description)
|
|---|
| [a2ab15] | 193 | {}
|
|---|
| 194 |
|
|---|
| [86466e] | 195 | CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
|
|---|
| [a2ab15] | 196 | {}
|
|---|
| 197 |
|
|---|
| [86466e] | 198 | bool CommandLineDialog::VectorCommandLineQuery::handle() {
|
|---|
| [0286bc] | 199 | VectorValue temp;
|
|---|
| [d90762] | 200 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| [0286bc] | 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;
|
|---|
| [d90762] | 205 | return true;
|
|---|
| 206 | } else
|
|---|
| 207 | return false;
|
|---|
| [a2ab15] | 208 | }
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| [97ebf8] | 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() {
|
|---|
| [0286bc] | 219 | BoxValue temp;
|
|---|
| [97ebf8] | 220 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| [0286bc] | 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;
|
|---|
| [97ebf8] | 228 | return true;
|
|---|
| 229 | } else
|
|---|
| 230 | return false;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| [86466e] | 233 | CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, const element **target, string _description) :
|
|---|
| 234 | Dialog::ElementQuery(title,target, _description)
|
|---|
| [a2ab15] | 235 | {}
|
|---|
| 236 |
|
|---|
| [86466e] | 237 | CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
|
|---|
| [a2ab15] | 238 | {}
|
|---|
| 239 |
|
|---|
| [86466e] | 240 | bool CommandLineDialog::ElementCommandLineQuery::handle() {
|
|---|
| [97ebf8] | 241 | // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
|
|---|
| 242 | int Z;
|
|---|
| [d90762] | 243 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| [97ebf8] | 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);
|
|---|
| [d90762] | 249 | tmp = World::getInstance().getPeriode()->FindElement(Z);
|
|---|
| 250 | return true;
|
|---|
| 251 | } else
|
|---|
| 252 | return false;
|
|---|
| [a2ab15] | 253 | }
|
|---|