source: src/UIElements/CommandLineDialog.cpp@ 4a75d9

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

Extended UIFactory to a CommandLine derivate.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * CommandLineDialog.cpp
3 *
4 * Created on: May 8, 2010
5 * Author: heber
6 */
7
8
9#include <iostream>
10
11#include "UIElements/CommandLineDialog.hpp"
12
13#include "World.hpp"
14#include "periodentafel.hpp"
15#include "atom.hpp"
16#include "molecule.hpp"
17#include "log.hpp"
18#include "verbose.hpp"
19
20using namespace std;
21
22
23CommandLineDialog::CommandLineDialog()
24{
25}
26
27CommandLineDialog::~CommandLineDialog()
28{
29}
30
31
32void CommandLineDialog::queryInt(const char* title, int* target){
33 registerQuery(new IntTextQuery(title,target));
34}
35
36void CommandLineDialog::queryDouble(const char* title, double* target){
37 registerQuery(new DoubleTextQuery(title,target));
38}
39
40void CommandLineDialog::queryString(const char* title, string* target){
41 registerQuery(new StringTextQuery(title,target));
42}
43
44void CommandLineDialog::queryMolecule(const char* title, molecule **target, MoleculeListClass *molecules) {
45 registerQuery(new MoleculeTextQuery(title,target,molecules));
46}
47
48void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check) {
49 registerQuery(new VectorTextQuery(title,target,cellSize,check));
50}
51
52void CommandLineDialog::queryElement(const char* title, const element **target){
53 registerQuery(new ElementTextQuery(title,target));
54}
55
56/************************** Query Infrastructure ************************/
57
58CommandLineDialog::IntTextQuery::IntTextQuery(string title,int *_target) :
59 Dialog::IntQuery(title,_target)
60{}
61
62CommandLineDialog::IntTextQuery::~IntTextQuery() {}
63
64bool CommandLineDialog::IntTextQuery::handle() {
65 bool badInput = false;
66 do{
67 badInput = false;
68 Log() << Verbose(0) << getTitle();
69 cin >> tmp;
70 if(cin.fail()){
71 badInput=true;
72 cin.clear();
73 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
74 Log() << Verbose(0) << "Input was not a number!" << endl;
75 }
76 } while(badInput);
77 // clear the input buffer of anything still in the line
78 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
79 return true;
80}
81
82CommandLineDialog::StringTextQuery::StringTextQuery(string title,string *_target) :
83 Dialog::StringQuery(title,_target)
84{}
85
86CommandLineDialog::StringTextQuery::~StringTextQuery() {}
87
88bool CommandLineDialog::StringTextQuery::handle() {
89 Log() << Verbose(0) << getTitle();
90 getline(cin,tmp);
91 return true;
92}
93
94CommandLineDialog::DoubleTextQuery::DoubleTextQuery(string title,double *_target) :
95 Dialog::DoubleQuery(title,_target)
96{}
97
98CommandLineDialog::DoubleTextQuery::~DoubleTextQuery() {}
99
100bool CommandLineDialog::DoubleTextQuery::handle() {
101 bool badInput = false;
102 do{
103 badInput = false;
104 Log() << Verbose(0) << getTitle();
105 cin >> tmp;
106 if(cin.fail()){
107 badInput = true;
108 cin.clear();
109 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
110 Log() << Verbose(0) << "Input was not a number!" << endl;
111 }
112 }while(badInput);
113 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
114 return true;
115}
116
117CommandLineDialog::MoleculeTextQuery::MoleculeTextQuery(string title, molecule **_target, MoleculeListClass *_molecules) :
118 Dialog::MoleculeQuery(title,_target,_molecules)
119{}
120
121CommandLineDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
122
123bool CommandLineDialog::MoleculeTextQuery::handle() {
124 int idxOfMol=0;
125 bool badInput = false;
126 do{
127 badInput = false;
128 Log() << Verbose(0) << getTitle();
129 cin >> idxOfMol;
130 if(cin.fail()){
131 badInput = true;
132 cin.clear();
133 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
134 Log() << Verbose(0) << "Input was not a number!" << endl;
135 continue;
136 }
137
138 tmp = molecules->ReturnIndex(idxOfMol);
139 if(!tmp && idxOfMol!=-1){
140 Log() << Verbose(0) << "Invalid Molecule Index" << endl;
141 badInput = true;
142 }
143
144 } while(badInput);
145 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
146 return (idxOfMol!=-1);
147}
148
149CommandLineDialog::VectorTextQuery::VectorTextQuery(std::string title, Vector *_target, const double *const _cellSize, bool _check) :
150 Dialog::VectorQuery(title,_target,_cellSize,_check)
151{}
152
153CommandLineDialog::VectorTextQuery::~VectorTextQuery()
154{}
155
156bool CommandLineDialog::VectorTextQuery::handle() {
157 Log() << Verbose(0) << getTitle();
158
159 char coords[3] = {'x','y','z'};
160 int j = -1;
161 for (int i=0;i<3;i++) {
162 j += i+1;
163 do {
164 Log() << Verbose(0) << coords[i] << "[0.." << cellSize[j] << "]: ";
165 cin >> (*tmp)[i];
166 } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= cellSize[j])) && (check));
167 }
168 return true;
169}
170
171
172CommandLineDialog::ElementTextQuery::ElementTextQuery(std::string title, const element **target) :
173 Dialog::ElementQuery(title,target)
174{}
175
176CommandLineDialog::ElementTextQuery::~ElementTextQuery()
177{}
178
179bool CommandLineDialog::ElementTextQuery::handle() {
180 bool badInput=false;
181 bool aborted = false;
182 do{
183 badInput = false;
184 Log() << Verbose(0) << getTitle();
185
186 // try to read as Atomic number
187 int Z;
188 cin >> Z;
189 if(!cin.fail()){
190 if(Z==-1){
191 aborted = true;
192 }
193 else{
194 tmp = World::getInstance().getPeriode()->FindElement(Z);
195 if(!tmp){
196 Log() << Verbose(0) << "No element with this atomic number!" << endl;
197 badInput = true;
198 }
199 }
200 continue;
201 }
202 else{
203 cin.clear();
204 }
205
206 // Try to read as shorthand
207 // the last buffer content was not removed, so we read the
208 // same thing again, this time as a string
209 string shorthand;
210 cin >> shorthand;
211 if(!cin.fail()){
212 if(shorthand.empty()){
213 aborted = true;
214 }
215 else{
216 tmp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
217 if(!tmp){
218 Log() << Verbose(0) << "No element with this shorthand!" << endl;
219 badInput = true;
220 }
221 }
222 }
223 else{
224 Log() << Verbose(0) << "Could not read input. Try Again." << endl;
225 cin.clear();
226 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
227 badInput = true;
228 }
229
230 }while(badInput);
231 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
232 return !aborted;
233}
Note: See TracBrowser for help on using the repository browser.