1 | /*
|
---|
2 | * CommandLineDialog.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 8, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 |
|
---|
9 | #include <iostream>
|
---|
10 | #include <vector>
|
---|
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, std::vector<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 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl);
|
---|
111 | return false;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) :
|
---|
116 | Dialog::BooleanQuery(title,_target, _description)
|
---|
117 | {}
|
---|
118 |
|
---|
119 | CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
|
---|
120 |
|
---|
121 | bool CommandLineDialog::BooleanCommandLineQuery::handle() {
|
---|
122 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
123 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>();
|
---|
124 | return true;
|
---|
125 | } else {
|
---|
126 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl);
|
---|
127 | return false;
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
|
---|
132 | Dialog::StringQuery(title,_target, _description)
|
---|
133 | {}
|
---|
134 |
|
---|
135 | CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
|
---|
136 |
|
---|
137 | bool CommandLineDialog::StringCommandLineQuery::handle() {
|
---|
138 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
139 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
|
---|
140 | return true;
|
---|
141 | } else {
|
---|
142 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
|
---|
143 | return false;
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
|
---|
148 | Dialog::DoubleQuery(title,_target, _description)
|
---|
149 | {}
|
---|
150 |
|
---|
151 | CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
|
---|
152 |
|
---|
153 | bool CommandLineDialog::DoubleCommandLineQuery::handle() {
|
---|
154 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
155 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
|
---|
156 | return true;
|
---|
157 | } else {
|
---|
158 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl);
|
---|
159 | return false;
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) :
|
---|
164 | Dialog::AtomQuery(title,_target, _description)
|
---|
165 | {}
|
---|
166 |
|
---|
167 | CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {}
|
---|
168 |
|
---|
169 | bool CommandLineDialog::AtomCommandLineQuery::handle() {
|
---|
170 | int IdxOfAtom = -1;
|
---|
171 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
172 | IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
---|
173 | tmp = World::getInstance().getAtom(AtomById(IdxOfAtom));
|
---|
174 | return true;
|
---|
175 | } else {
|
---|
176 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl);
|
---|
177 | return false;
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) :
|
---|
182 | Dialog::MoleculeQuery(title,_target, _description)
|
---|
183 | {}
|
---|
184 |
|
---|
185 | CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
|
---|
186 |
|
---|
187 | bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
|
---|
188 | int IdxOfMol = -1;
|
---|
189 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
190 | IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
---|
191 | cout << "IdxOfMol " << IdxOfMol << endl;
|
---|
192 | if (IdxOfMol >= 0)
|
---|
193 | tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
|
---|
194 | else
|
---|
195 | tmp = NULL;
|
---|
196 | return true;
|
---|
197 | } else {
|
---|
198 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl);
|
---|
199 | return false;
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) :
|
---|
204 | Dialog::VectorQuery(title,_target,_cellSize,_check, _description)
|
---|
205 | {}
|
---|
206 |
|
---|
207 | CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
|
---|
208 | {}
|
---|
209 |
|
---|
210 | bool CommandLineDialog::VectorCommandLineQuery::handle() {
|
---|
211 | VectorValue temp;
|
---|
212 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
213 | temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
|
---|
214 | tmp->at(0) = temp.x;
|
---|
215 | tmp->at(1) = temp.y;
|
---|
216 | tmp->at(2) = temp.z;
|
---|
217 | return true;
|
---|
218 | } else {
|
---|
219 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl);
|
---|
220 | return false;
|
---|
221 | }
|
---|
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 | BoxValue temp;
|
---|
234 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
235 | temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >();
|
---|
236 | tmp[0] = temp.xx;
|
---|
237 | tmp[1] = temp.xy;
|
---|
238 | tmp[2] = temp.xz;
|
---|
239 | tmp[3] = temp.yy;
|
---|
240 | tmp[4] = temp.yz;
|
---|
241 | tmp[5] = temp.zz;
|
---|
242 | return true;
|
---|
243 | } else {
|
---|
244 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl);
|
---|
245 | return false;
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, std::vector<element *> *target, string _description) :
|
---|
250 | Dialog::ElementQuery(title,target, _description)
|
---|
251 | {}
|
---|
252 |
|
---|
253 | CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
|
---|
254 | {}
|
---|
255 |
|
---|
256 | bool CommandLineDialog::ElementCommandLineQuery::handle() {
|
---|
257 | // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
|
---|
258 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
259 | element *elemental = NULL;
|
---|
260 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
261 | vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
|
---|
262 | for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) {
|
---|
263 | elemental = periode->FindElement(*ZRunner);
|
---|
264 | ASSERT(elemental != NULL, "Invalid element specified in ElementCommandLineQuery");
|
---|
265 | elements.push_back(elemental);
|
---|
266 | }
|
---|
267 | return true;
|
---|
268 | } else {
|
---|
269 | DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl);
|
---|
270 | return false;
|
---|
271 | }
|
---|
272 | }
|
---|