source: src/UIElements/CommandLineUI/CommandLineDialog.cpp@ 7cd6e7

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 7cd6e7 was 7cd6e7, checked in by Frederik Heber <heber@…>, 14 years ago

Add all possible versions of queries where the user is asked for multiples of the same.

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