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

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 Candidate_v1.7.0 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 7e6b00 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
RevLine 
[a2ab15]1/*
2 * CommandLineDialog.cpp
3 *
4 * Created on: May 8, 2010
5 * Author: heber
6 */
7
8
9#include <iostream>
[104524]10#include <vector>
[a2ab15]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]34using namespace std;
35
36
37CommandLineDialog::CommandLineDialog()
38{
39}
40
41CommandLineDialog::~CommandLineDialog()
42{
43}
44
45
[86466e]46void CommandLineDialog::queryEmpty(const char* title, string _description){
47 registerQuery(new EmptyCommandLineQuery(title, _description));
[a2ab15]48}
49
[86466e]50void CommandLineDialog::queryInt(const char* title, int* target, string _description){
51 registerQuery(new IntCommandLineQuery(title,target, _description));
[a2ab15]52}
53
[97ebf8]54void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){
55 registerQuery(new BooleanCommandLineQuery(title,target, _description));
56}
57
[86466e]58void CommandLineDialog::queryDouble(const char* title, double* target, string _description){
59 registerQuery(new DoubleCommandLineQuery(title,target, _description));
[a2ab15]60}
61
[86466e]62void CommandLineDialog::queryString(const char* title, string* target, string _description){
63 registerQuery(new StringCommandLineQuery(title,target, _description));
[a2ab15]64}
65
[97ebf8]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));
[a2ab15]72}
73
[86466e]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
[97ebf8]78void CommandLineDialog::queryBox(const char* title, double ** const cellSize, string _description) {
79 registerQuery(new BoxCommandLineQuery(title,cellSize,_description));
80}
81
[104524]82void CommandLineDialog::queryElement(const char* title, std::vector<element *> *target, string _description){
[86466e]83 registerQuery(new ElementCommandLineQuery(title,target, _description));
[a2ab15]84}
85
86/************************** Query Infrastructure ************************/
87
[86466e]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)
[a2ab15]101{}
102
[86466e]103CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
[a2ab15]104
[86466e]105bool CommandLineDialog::IntCommandLineQuery::handle() {
[d90762]106 if (CommandLineParser::getInstance().vm.count(getTitle())) {
107 tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
108 return true;
[94d131]109 } else {
110 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl);
[d90762]111 return false;
[94d131]112 }
[a2ab15]113}
114
[97ebf8]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() {
[0286bc]122 if (CommandLineParser::getInstance().vm.count(getTitle())) {
123 tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>();
124 return true;
[94d131]125 } else {
126 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl);
[0286bc]127 return false;
[94d131]128 }
[97ebf8]129}
130
[86466e]131CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
132 Dialog::StringQuery(title,_target, _description)
[a2ab15]133{}
134
[86466e]135CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
[a2ab15]136
[86466e]137bool CommandLineDialog::StringCommandLineQuery::handle() {
[d90762]138 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[86466e]139 tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
[d90762]140 return true;
[94d131]141 } else {
142 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
[d90762]143 return false;
[94d131]144 }
[a2ab15]145}
146
[86466e]147CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
148 Dialog::DoubleQuery(title,_target, _description)
[a2ab15]149{}
150
[86466e]151CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
[a2ab15]152
[86466e]153bool CommandLineDialog::DoubleCommandLineQuery::handle() {
[d90762]154 if (CommandLineParser::getInstance().vm.count(getTitle())) {
155 tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
156 return true;
[94d131]157 } else {
158 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl);
[d90762]159 return false;
[94d131]160 }
[a2ab15]161}
162
[97ebf8]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;
[94d131]175 } else {
176 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl);
[97ebf8]177 return false;
[94d131]178 }
[97ebf8]179}
180
181CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) :
182 Dialog::MoleculeQuery(title,_target, _description)
[a2ab15]183{}
184
[86466e]185CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
[a2ab15]186
[86466e]187bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
[d90762]188 int IdxOfMol = -1;
189 if (CommandLineParser::getInstance().vm.count(getTitle())) {
190 IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
[e30ce8]191 cout << "IdxOfMol " << IdxOfMol << endl;
192 if (IdxOfMol >= 0)
193 tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
194 else
195 tmp = NULL;
[d90762]196 return true;
[94d131]197 } else {
198 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl);
[d90762]199 return false;
[94d131]200 }
[a2ab15]201}
202
[86466e]203CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) :
204 Dialog::VectorQuery(title,_target,_cellSize,_check, _description)
[a2ab15]205{}
206
[86466e]207CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
[a2ab15]208{}
209
[86466e]210bool CommandLineDialog::VectorCommandLineQuery::handle() {
[0286bc]211 VectorValue temp;
[d90762]212 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[0286bc]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;
[d90762]217 return true;
[94d131]218 } else {
219 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl);
[d90762]220 return false;
[94d131]221 }
[a2ab15]222}
223
224
[97ebf8]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() {
[0286bc]233 BoxValue temp;
[97ebf8]234 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[0286bc]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;
[97ebf8]242 return true;
[94d131]243 } else {
244 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl);
[97ebf8]245 return false;
[94d131]246 }
[97ebf8]247}
248
[104524]249CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, std::vector<element *> *target, string _description) :
[86466e]250 Dialog::ElementQuery(title,target, _description)
[a2ab15]251{}
252
[86466e]253CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
[a2ab15]254{}
255
[86466e]256bool CommandLineDialog::ElementCommandLineQuery::handle() {
[97ebf8]257 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
[104524]258 periodentafel *periode = World::getInstance().getPeriode();
259 element *elemental = NULL;
[d90762]260 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[97ebf8]261 vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
[104524]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 }
[d90762]267 return true;
[94d131]268 } else {
269 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl);
[d90762]270 return false;
[94d131]271 }
[a2ab15]272}
Note: See TracBrowser for help on using the repository browser.