source: src/UIElements/CommandLineUI/CommandLineDialog.cpp@ 94d131

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 94d131 was 94d131, checked in by Frederik Heber <heber@…>, 15 years ago

Helpful messages added to find failing queries in CommandLineUI.

  • all ..CommandLineQuery() functions give missing warning on failure
  • Dialog::display() admonished which query failed (and needed to friend of its own Query subclass for that ...)
  • Property mode set to 100644
File size: 9.4 KB
Line 
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
34using namespace std;
35
36
37CommandLineDialog::CommandLineDialog()
38{
39}
40
41CommandLineDialog::~CommandLineDialog()
42{
43}
44
45
46void CommandLineDialog::queryEmpty(const char* title, string _description){
47 registerQuery(new EmptyCommandLineQuery(title, _description));
48}
49
50void CommandLineDialog::queryInt(const char* title, int* target, string _description){
51 registerQuery(new IntCommandLineQuery(title,target, _description));
52}
53
54void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){
55 registerQuery(new BooleanCommandLineQuery(title,target, _description));
56}
57
58void CommandLineDialog::queryDouble(const char* title, double* target, string _description){
59 registerQuery(new DoubleCommandLineQuery(title,target, _description));
60}
61
62void CommandLineDialog::queryString(const char* title, string* target, string _description){
63 registerQuery(new StringCommandLineQuery(title,target, _description));
64}
65
66void CommandLineDialog::queryAtom(const char* title, atom **target, string _description) {
67 registerQuery(new AtomCommandLineQuery(title,target, _description));
68}
69
70void CommandLineDialog::queryMolecule(const char* title, molecule **target, string _description) {
71 registerQuery(new MoleculeCommandLineQuery(title,target, _description));
72}
73
74void 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
78void CommandLineDialog::queryBox(const char* title, double ** const cellSize, string _description) {
79 registerQuery(new BoxCommandLineQuery(title,cellSize,_description));
80}
81
82void CommandLineDialog::queryElement(const char* title, std::vector<element *> *target, string _description){
83 registerQuery(new ElementCommandLineQuery(title,target, _description));
84}
85
86/************************** Query Infrastructure ************************/
87
88CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
89 Dialog::EmptyQuery(title, _description)
90{}
91
92CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
93
94bool CommandLineDialog::EmptyCommandLineQuery::handle() {
95 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
96 return true;
97}
98
99CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) :
100 Dialog::IntQuery(title,_target, _description)
101{}
102
103CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
104
105bool 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
115CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) :
116 Dialog::BooleanQuery(title,_target, _description)
117{}
118
119CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
120
121bool 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
131CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
132 Dialog::StringQuery(title,_target, _description)
133{}
134
135CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
136
137bool 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
147CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
148 Dialog::DoubleQuery(title,_target, _description)
149{}
150
151CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
152
153bool 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
163CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) :
164 Dialog::AtomQuery(title,_target, _description)
165{}
166
167CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {}
168
169bool 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
181CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) :
182 Dialog::MoleculeQuery(title,_target, _description)
183{}
184
185CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
186
187bool 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
203CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) :
204 Dialog::VectorQuery(title,_target,_cellSize,_check, _description)
205{}
206
207CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
208{}
209
210bool 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
225CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, double ** const _cellSize, string _description) :
226 Dialog::BoxQuery(title,_cellSize, _description)
227{}
228
229CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery()
230{}
231
232bool 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
249CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, std::vector<element *> *target, string _description) :
250 Dialog::ElementQuery(title,target, _description)
251{}
252
253CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
254{}
255
256bool 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}
Note: See TracBrowser for help on using the repository browser.