source: src/UIElements/CommandLineUI/CommandLineDialog.cpp@ 84c494

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 84c494 was 84c494, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Made the world store the cell_size within a Box object.

  • 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#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, int* target, string _description){
53 registerQuery(new IntCommandLineQuery(title,target, _description));
54}
55
56void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){
57 registerQuery(new BooleanCommandLineQuery(title,target, _description));
58}
59
60void CommandLineDialog::queryDouble(const char* title, double* target, string _description){
61 registerQuery(new DoubleCommandLineQuery(title,target, _description));
62}
63
64void CommandLineDialog::queryString(const char* title, string* target, string _description){
65 registerQuery(new StringCommandLineQuery(title,target, _description));
66}
67
68void CommandLineDialog::queryAtom(const char* title, atom **target, string _description) {
69 registerQuery(new AtomCommandLineQuery(title,target, _description));
70}
71
72void CommandLineDialog::queryMolecule(const char* title, molecule **target, string _description) {
73 registerQuery(new MoleculeCommandLineQuery(title,target, _description));
74}
75
76void CommandLineDialog::queryVector(const char* title, Vector *target, bool check, string _description) {
77 registerQuery(new VectorCommandLineQuery(title,target,check, _description));
78}
79
80void CommandLineDialog::queryBox(const char* title, Box* cellSize, string _description) {
81 registerQuery(new BoxCommandLineQuery(title,cellSize,_description));
82}
83
84void CommandLineDialog::queryElement(const char* title, std::vector<element *> *target, string _description){
85 registerQuery(new ElementCommandLineQuery(title,target, _description));
86}
87
88/************************** Query Infrastructure ************************/
89
90CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
91 Dialog::EmptyQuery(title, _description)
92{}
93
94CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
95
96bool CommandLineDialog::EmptyCommandLineQuery::handle() {
97 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
98 return true;
99}
100
101CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) :
102 Dialog::IntQuery(title,_target, _description)
103{}
104
105CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
106
107bool CommandLineDialog::IntCommandLineQuery::handle() {
108 if (CommandLineParser::getInstance().vm.count(getTitle())) {
109 tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
110 return true;
111 } else {
112 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl);
113 return false;
114 }
115}
116
117CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) :
118 Dialog::BooleanQuery(title,_target, _description)
119{}
120
121CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
122
123bool CommandLineDialog::BooleanCommandLineQuery::handle() {
124 if (CommandLineParser::getInstance().vm.count(getTitle())) {
125 tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>();
126 return true;
127 } else {
128 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl);
129 return false;
130 }
131}
132
133CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
134 Dialog::StringQuery(title,_target, _description)
135{}
136
137CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
138
139bool CommandLineDialog::StringCommandLineQuery::handle() {
140 if (CommandLineParser::getInstance().vm.count(getTitle())) {
141 tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
142 return true;
143 } else {
144 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
145 return false;
146 }
147}
148
149CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
150 Dialog::DoubleQuery(title,_target, _description)
151{}
152
153CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
154
155bool CommandLineDialog::DoubleCommandLineQuery::handle() {
156 if (CommandLineParser::getInstance().vm.count(getTitle())) {
157 tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
158 return true;
159 } else {
160 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl);
161 return false;
162 }
163}
164
165CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) :
166 Dialog::AtomQuery(title,_target, _description)
167{}
168
169CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {}
170
171bool CommandLineDialog::AtomCommandLineQuery::handle() {
172 int IdxOfAtom = -1;
173 if (CommandLineParser::getInstance().vm.count(getTitle())) {
174 IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>();
175 tmp = World::getInstance().getAtom(AtomById(IdxOfAtom));
176 return true;
177 } else {
178 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl);
179 return false;
180 }
181}
182
183CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) :
184 Dialog::MoleculeQuery(title,_target, _description)
185{}
186
187CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
188
189bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
190 int IdxOfMol = -1;
191 if (CommandLineParser::getInstance().vm.count(getTitle())) {
192 IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
193 cout << "IdxOfMol " << IdxOfMol << endl;
194 if (IdxOfMol >= 0)
195 tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
196 else
197 tmp = NULL;
198 return true;
199 } else {
200 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl);
201 return false;
202 }
203}
204
205CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, bool _check, string _description) :
206 Dialog::VectorQuery(title,_target,_check, _description)
207{}
208
209CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
210{}
211
212bool CommandLineDialog::VectorCommandLineQuery::handle() {
213 VectorValue temp;
214 if (CommandLineParser::getInstance().vm.count(getTitle())) {
215 temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
216 tmp->at(0) = temp.x;
217 tmp->at(1) = temp.y;
218 tmp->at(2) = temp.z;
219 return true;
220 } else {
221 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl);
222 return false;
223 }
224}
225
226
227CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, Box* _cellSize, string _description) :
228 Dialog::BoxQuery(title,_cellSize, _description)
229{}
230
231CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery()
232{}
233
234bool CommandLineDialog::BoxCommandLineQuery::handle() {
235 BoxValue temp;
236 if (CommandLineParser::getInstance().vm.count(getTitle())) {
237 temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >();
238 tmp[0] = temp.xx;
239 tmp[1] = temp.xy;
240 tmp[2] = temp.xz;
241 tmp[3] = temp.yy;
242 tmp[4] = temp.yz;
243 tmp[5] = temp.zz;
244 return true;
245 } else {
246 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl);
247 return false;
248 }
249}
250
251CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, std::vector<element *> *target, string _description) :
252 Dialog::ElementQuery(title,target, _description)
253{}
254
255CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
256{}
257
258bool CommandLineDialog::ElementCommandLineQuery::handle() {
259 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
260 periodentafel *periode = World::getInstance().getPeriode();
261 element *elemental = NULL;
262 if (CommandLineParser::getInstance().vm.count(getTitle())) {
263 vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
264 for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) {
265 elemental = periode->FindElement(*ZRunner);
266 ASSERT(elemental != NULL, "Invalid element specified in ElementCommandLineQuery");
267 elements.push_back(elemental);
268 }
269 return true;
270 } else {
271 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl);
272 return false;
273 }
274}
Note: See TracBrowser for help on using the repository browser.