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 Candidate_v1.7.0 Candidate_v1.7.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@…>, 15 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
RevLine 
[a2ab15]1/*
2 * CommandLineDialog.cpp
3 *
4 * Created on: May 8, 2010
5 * Author: heber
6 */
7
[112b09]8#include "Helpers/MemDebug.hpp"
[a2ab15]9
10#include <iostream>
[104524]11#include <vector>
[a2ab15]12
[97ebf8]13#include <Descriptors/AtomDescriptor.hpp>
14#include <Descriptors/AtomIdDescriptor.hpp>
[d90762]15#include <Descriptors/MoleculeDescriptor.hpp>
16#include <Descriptors/MoleculeIdDescriptor.hpp>
[5079a0]17#include "CommandLineUI/CommandLineDialog.hpp"
[a2ab15]18
[0286bc]19#include "Actions/Values.hpp"
20
[97ebf8]21#include "element.hpp"
[a2ab15]22#include "periodentafel.hpp"
[d90762]23#include "CommandLineParser.hpp"
24#include "defs.hpp"
[a2ab15]25#include "log.hpp"
[97ebf8]26#include "periodentafel.hpp"
[a2ab15]27#include "verbose.hpp"
[d90762]28#include "World.hpp"
[84c494]29#include "Box.hpp"
[a2ab15]30
[97ebf8]31#include "atom.hpp"
32#include "element.hpp"
33#include "molecule.hpp"
34#include "vector.hpp"
35
[a2ab15]36using namespace std;
37
38
39CommandLineDialog::CommandLineDialog()
40{
41}
42
43CommandLineDialog::~CommandLineDialog()
44{
45}
46
47
[86466e]48void CommandLineDialog::queryEmpty(const char* title, string _description){
49 registerQuery(new EmptyCommandLineQuery(title, _description));
[a2ab15]50}
51
[75dc28]52void CommandLineDialog::queryInt(const char* title, string _description){
53 registerQuery(new IntCommandLineQuery(title, _description));
[a2ab15]54}
55
[7cd6e7]56void CommandLineDialog::queryInts(const char* title, string _description){
57 registerQuery(new IntsCommandLineQuery(title, _description));
58}
59
[75dc28]60void CommandLineDialog::queryBoolean(const char* title, string _description){
61 registerQuery(new BooleanCommandLineQuery(title, _description));
[97ebf8]62}
63
[75dc28]64void CommandLineDialog::queryDouble(const char* title, string _description){
65 registerQuery(new DoubleCommandLineQuery(title, _description));
[a2ab15]66}
67
[7cd6e7]68void CommandLineDialog::queryDoubles(const char* title, string _description){
69 registerQuery(new DoublesCommandLineQuery(title, _description));
70}
71
[75dc28]72void CommandLineDialog::queryString(const char* title, string _description){
73 registerQuery(new StringCommandLineQuery(title, _description));
[a2ab15]74}
75
[75dc28]76void CommandLineDialog::queryStrings(const char* title, string _description){
77 registerQuery(new StringsCommandLineQuery(title, _description));
[cd8e55]78}
79
[75dc28]80void CommandLineDialog::queryAtom(const char* title, string _description) {
81 registerQuery(new AtomCommandLineQuery(title, _description));
[97ebf8]82}
83
[7cd6e7]84void CommandLineDialog::queryAtoms(const char* title, string _description) {
85 registerQuery(new AtomsCommandLineQuery(title, _description));
86}
87
[75dc28]88void CommandLineDialog::queryMolecule(const char* title, string _description) {
89 registerQuery(new MoleculeCommandLineQuery(title, _description));
[a2ab15]90}
91
[7cd6e7]92void CommandLineDialog::queryMolecules(const char* title, string _description) {
93 registerQuery(new MoleculesCommandLineQuery(title, _description));
94}
95
[75dc28]96void CommandLineDialog::queryVector(const char* title, bool check, string _description) {
97 registerQuery(new VectorCommandLineQuery(title,check, _description));
[86466e]98}
99
[7cd6e7]100void CommandLineDialog::queryVectors(const char* title, bool check, string _description) {
101 registerQuery(new VectorsCommandLineQuery(title,check, _description));
102}
103
[75dc28]104void CommandLineDialog::queryBox(const char* title, string _description) {
105 registerQuery(new BoxCommandLineQuery(title,_description));
[97ebf8]106}
107
[75dc28]108void CommandLineDialog::queryElement(const char* title, string _description){
109 registerQuery(new ElementCommandLineQuery(title, _description));
[a2ab15]110}
111
[7cd6e7]112void CommandLineDialog::queryElements(const char* title, string _description){
113 registerQuery(new ElementsCommandLineQuery(title, _description));
114}
115
[a2ab15]116/************************** Query Infrastructure ************************/
117
[86466e]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
[75dc28]129CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title, string _description) :
130 Dialog::IntQuery(title, _description)
[a2ab15]131{}
132
[86466e]133CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
[a2ab15]134
[86466e]135bool CommandLineDialog::IntCommandLineQuery::handle() {
[d90762]136 if (CommandLineParser::getInstance().vm.count(getTitle())) {
137 tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
138 return true;
[94d131]139 } else {
140 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl);
[d90762]141 return false;
[94d131]142 }
[a2ab15]143}
144
[7cd6e7]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
[75dc28]161CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title, string _description) :
162 Dialog::BooleanQuery(title, _description)
[97ebf8]163{}
164
165CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
166
167bool CommandLineDialog::BooleanCommandLineQuery::handle() {
[0286bc]168 if (CommandLineParser::getInstance().vm.count(getTitle())) {
169 tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>();
170 return true;
[94d131]171 } else {
172 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl);
[0286bc]173 return false;
[94d131]174 }
[97ebf8]175}
176
[75dc28]177CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title, string _description) :
178 Dialog::StringQuery(title, _description)
[a2ab15]179{}
180
[86466e]181CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
[a2ab15]182
[86466e]183bool CommandLineDialog::StringCommandLineQuery::handle() {
[d90762]184 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[86466e]185 tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
[d90762]186 return true;
[94d131]187 } else {
188 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
[d90762]189 return false;
[94d131]190 }
[a2ab15]191}
192
[75dc28]193CommandLineDialog::StringsCommandLineQuery::StringsCommandLineQuery(string title, string _description) :
194 Dialog::StringsQuery(title, _description)
[cd8e55]195{}
196
197CommandLineDialog::StringsCommandLineQuery::~StringsCommandLineQuery() {}
198
199bool CommandLineDialog::StringsCommandLineQuery::handle() {
200 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[b9c847]201 tmp = CommandLineParser::getInstance().vm[getTitle()].as< vector<string> >();
[cd8e55]202 return true;
203 } else {
[7cd6e7]204 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing strings for " << getTitle() << "." << endl);
[cd8e55]205 return false;
206 }
207}
208
[75dc28]209CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title, string _description) :
210 Dialog::DoubleQuery(title, _description)
[a2ab15]211{}
212
[86466e]213CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
[a2ab15]214
[86466e]215bool CommandLineDialog::DoubleCommandLineQuery::handle() {
[d90762]216 if (CommandLineParser::getInstance().vm.count(getTitle())) {
217 tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
218 return true;
[94d131]219 } else {
220 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl);
[d90762]221 return false;
[94d131]222 }
[a2ab15]223}
224
[7cd6e7]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
[75dc28]241CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, string _description) :
242 Dialog::AtomQuery(title, _description)
[97ebf8]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;
[94d131]253 } else {
254 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl);
[97ebf8]255 return false;
[94d131]256 }
[97ebf8]257}
258
[7cd6e7]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
[75dc28]281CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, string _description) :
282 Dialog::MoleculeQuery(title, _description)
[a2ab15]283{}
284
[86466e]285CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
[a2ab15]286
[86466e]287bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
[d90762]288 int IdxOfMol = -1;
289 if (CommandLineParser::getInstance().vm.count(getTitle())) {
290 IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
[7cd6e7]291 tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
[d90762]292 return true;
[94d131]293 } else {
294 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl);
[d90762]295 return false;
[94d131]296 }
[a2ab15]297}
298
[7cd6e7]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
[75dc28]321CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, bool _check, string _description) :
322 Dialog::VectorQuery(title,_check, _description)
[a2ab15]323{}
324
[86466e]325CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
[a2ab15]326{}
327
[86466e]328bool CommandLineDialog::VectorCommandLineQuery::handle() {
[0286bc]329 VectorValue temp;
[d90762]330 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[0286bc]331 temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
[7cd6e7]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 }
[d90762]339 return true;
[94d131]340 } else {
341 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl);
[d90762]342 return false;
[94d131]343 }
[a2ab15]344}
345
[7cd6e7]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}
[a2ab15]372
[75dc28]373CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, string _description) :
374 Dialog::BoxQuery(title, _description)
[97ebf8]375{}
376
377CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery()
378{}
379
380bool CommandLineDialog::BoxCommandLineQuery::handle() {
[0286bc]381 BoxValue temp;
[97ebf8]382 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[0286bc]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;
[97ebf8]390 return true;
[94d131]391 } else {
392 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl);
[97ebf8]393 return false;
[94d131]394 }
[97ebf8]395}
396
[75dc28]397CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, string _description) :
[3731b4]398 Dialog::ElementQuery(title, _description)
[a2ab15]399{}
400
[86466e]401CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
[a2ab15]402{}
403
[86466e]404bool CommandLineDialog::ElementCommandLineQuery::handle() {
[97ebf8]405 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
[104524]406 periodentafel *periode = World::getInstance().getPeriode();
[7cd6e7]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();
[d90762]428 if (CommandLineParser::getInstance().vm.count(getTitle())) {
[97ebf8]429 vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
[104524]430 for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) {
[7cd6e7]431 temp = periode->FindElement(*ZRunner);
432 ASSERT(temp != NULL, "Invalid element specified in ElementCommandLineQuery");
433 tmp.push_back(temp);
[104524]434 }
[d90762]435 return true;
[94d131]436 } else {
[7cd6e7]437 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing elements for " << getTitle() << "." << endl);
[d90762]438 return false;
[94d131]439 }
[a2ab15]440}
Note: See TracBrowser for help on using the repository browser.