source: src/UIElements/CommandLineUI/CommandLineDialog.cpp@ f8e486

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

Added #include "Helpers/MemDebug.hpp" to all .cpp files

  • Property mode set to 100644
File size: 8.7 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 <cassert>
11#include <iostream>
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 "element.hpp"
20#include "periodentafel.hpp"
21#include "CommandLineParser.hpp"
22#include "defs.hpp"
23#include "log.hpp"
24#include "periodentafel.hpp"
25#include "verbose.hpp"
26#include "World.hpp"
27
28#include "atom.hpp"
29#include "element.hpp"
30#include "molecule.hpp"
31#include "vector.hpp"
32
33using namespace std;
34
35
36CommandLineDialog::CommandLineDialog()
37{
38}
39
40CommandLineDialog::~CommandLineDialog()
41{
42}
43
44
45void CommandLineDialog::queryEmpty(const char* title, string _description){
46 registerQuery(new EmptyCommandLineQuery(title, _description));
47}
48
49void CommandLineDialog::queryInt(const char* title, int* target, string _description){
50 registerQuery(new IntCommandLineQuery(title,target, _description));
51}
52
53void CommandLineDialog::queryBoolean(const char* title, bool* target, string _description){
54 registerQuery(new BooleanCommandLineQuery(title,target, _description));
55}
56
57void CommandLineDialog::queryDouble(const char* title, double* target, string _description){
58 registerQuery(new DoubleCommandLineQuery(title,target, _description));
59}
60
61void CommandLineDialog::queryString(const char* title, string* target, string _description){
62 registerQuery(new StringCommandLineQuery(title,target, _description));
63}
64
65void CommandLineDialog::queryAtom(const char* title, atom **target, string _description) {
66 registerQuery(new AtomCommandLineQuery(title,target, _description));
67}
68
69void CommandLineDialog::queryMolecule(const char* title, molecule **target, string _description) {
70 registerQuery(new MoleculeCommandLineQuery(title,target, _description));
71}
72
73void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check, string _description) {
74 registerQuery(new VectorCommandLineQuery(title,target,cellSize,check, _description));
75}
76
77void CommandLineDialog::queryBox(const char* title, double ** const cellSize, string _description) {
78 registerQuery(new BoxCommandLineQuery(title,cellSize,_description));
79}
80
81void CommandLineDialog::queryElement(const char* title, const element **target, string _description){
82 registerQuery(new ElementCommandLineQuery(title,target, _description));
83}
84
85/************************** Query Infrastructure ************************/
86
87CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
88 Dialog::EmptyQuery(title, _description)
89{}
90
91CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
92
93bool CommandLineDialog::EmptyCommandLineQuery::handle() {
94 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
95 return true;
96}
97
98CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) :
99 Dialog::IntQuery(title,_target, _description)
100{}
101
102CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
103
104bool CommandLineDialog::IntCommandLineQuery::handle() {
105 if (CommandLineParser::getInstance().vm.count(getTitle())) {
106 tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
107 return true;
108 } else
109 return false;
110}
111
112CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title,bool *_target, string _description) :
113 Dialog::BooleanQuery(title,_target, _description)
114{}
115
116CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
117
118bool CommandLineDialog::BooleanCommandLineQuery::handle() {
119 bool badInput = false;
120 char input = ' ';
121 do{
122 badInput = false;
123 Log() << Verbose(0) << getTitle();
124 cin >> input;
125 if ((input == 'y' ) || (input == 'Y')) {
126 tmp = true;
127 } else if ((input == 'n' ) || (input == 'N')) {
128 tmp = false;
129 } else {
130 badInput=true;
131 cin.clear();
132 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
133 Log() << Verbose(0) << "Input was not of [yYnN]!" << endl;
134 }
135 } while(badInput);
136 // clear the input buffer of anything still in the line
137 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
138 return true;
139}
140
141CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
142 Dialog::StringQuery(title,_target, _description)
143{}
144
145CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
146
147bool CommandLineDialog::StringCommandLineQuery::handle() {
148 if (CommandLineParser::getInstance().vm.count(getTitle())) {
149 tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
150 return true;
151 } else
152 return false;
153}
154
155CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
156 Dialog::DoubleQuery(title,_target, _description)
157{}
158
159CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
160
161bool CommandLineDialog::DoubleCommandLineQuery::handle() {
162 if (CommandLineParser::getInstance().vm.count(getTitle())) {
163 tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
164 return true;
165 } else
166 return false;
167}
168
169CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, atom **_target, string _description) :
170 Dialog::AtomQuery(title,_target, _description)
171{}
172
173CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {}
174
175bool CommandLineDialog::AtomCommandLineQuery::handle() {
176 int IdxOfAtom = -1;
177 if (CommandLineParser::getInstance().vm.count(getTitle())) {
178 IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>();
179 tmp = World::getInstance().getAtom(AtomById(IdxOfAtom));
180 return true;
181 } else
182 return false;
183}
184
185CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, string _description) :
186 Dialog::MoleculeQuery(title,_target, _description)
187{}
188
189CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
190
191bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
192 int IdxOfMol = -1;
193 if (CommandLineParser::getInstance().vm.count(getTitle())) {
194 IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
195 cout << "IdxOfMol " << IdxOfMol << endl;
196 if (IdxOfMol >= 0)
197 tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
198 else
199 tmp = NULL;
200 return true;
201 } else
202 return false;
203}
204
205CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) :
206 Dialog::VectorQuery(title,_target,_cellSize,_check, _description)
207{}
208
209CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
210{}
211
212bool CommandLineDialog::VectorCommandLineQuery::handle() {
213 vector<double> temp;
214 if (CommandLineParser::getInstance().vm.count(getTitle())) {
215 temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >();
216 assert((temp.size() == 3) && "Vector from command line does not have three components.");
217 for (int i=0;i<NDIM;i++)
218 tmp->at(i) = temp[i];
219 return true;
220 } else
221 return false;
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 vector<double> temp;
234 if (CommandLineParser::getInstance().vm.count(getTitle())) {
235 temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >();
236 assert((temp.size() == 6) && "Symmetric box matrix from command line does not have six components.");
237 for (int i=0;i<6;i++) {
238 tmp[i] = temp[i];
239 }
240 return true;
241 } else
242 return false;
243}
244
245CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, const element **target, string _description) :
246 Dialog::ElementQuery(title,target, _description)
247{}
248
249CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
250{}
251
252bool CommandLineDialog::ElementCommandLineQuery::handle() {
253 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
254 int Z;
255 if (CommandLineParser::getInstance().vm.count(getTitle())) {
256 vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
257 vector<int>::iterator ElementRunner = AllElements.begin();
258 Z = *ElementRunner;
259 // TODO: So far, this does not really erase the element in the parsed list.
260 AllElements.erase(ElementRunner);
261 tmp = World::getInstance().getPeriode()->FindElement(Z);
262 return true;
263 } else
264 return false;
265}
Note: See TracBrowser for help on using the repository browser.