source: src/UIElements/TextUI/TextDialog.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.5 KB
Line 
1/*
2 * TextDialog.cpp
3 *
4 * Created on: Jan 5, 2010
5 * Author: crueger
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include <iostream>
11
12#include <Descriptors/AtomDescriptor.hpp>
13#include <Descriptors/AtomIdDescriptor.hpp>
14#include <Descriptors/MoleculeDescriptor.hpp>
15#include <Descriptors/MoleculeIdDescriptor.hpp>
16#include "TextUI/TextDialog.hpp"
17
18#include "World.hpp"
19#include "periodentafel.hpp"
20#include "log.hpp"
21#include "verbose.hpp"
22
23#include "atom.hpp"
24#include "element.hpp"
25#include "molecule.hpp"
26#include "vector.hpp"
27#include "Matrix.hpp"
28#include "Box.hpp"
29
30using namespace std;
31
32
33TextDialog::TextDialog()
34{
35}
36
37TextDialog::~TextDialog()
38{
39}
40
41
42void TextDialog::queryEmpty(const char* title, string description){
43 registerQuery(new EmptyTextQuery(title,description));
44}
45
46void TextDialog::queryBoolean(const char* title, bool* target, string description){
47 registerQuery(new BooleanTextQuery(title,target,description));
48}
49
50void TextDialog::queryInt(const char* title, int* target, string description){
51 registerQuery(new IntTextQuery(title,target,description));
52}
53
54void TextDialog::queryDouble(const char* title, double* target, string description){
55 registerQuery(new DoubleTextQuery(title,target,description));
56}
57
58void TextDialog::queryString(const char* title, string* target, string description){
59 registerQuery(new StringTextQuery(title,target,description));
60}
61
62void TextDialog::queryAtom(const char* title, atom **target, string description) {
63 registerQuery(new AtomTextQuery(title,target,description));
64}
65
66void TextDialog::queryMolecule(const char* title, molecule **target, string description) {
67 registerQuery(new MoleculeTextQuery(title,target,description));
68}
69
70void TextDialog::queryVector(const char* title, Vector *target, bool check, string description) {
71 registerQuery(new VectorTextQuery(title,target,check,description));
72}
73
74void TextDialog::queryBox(const char* title,Box* cellSize, string description) {
75 registerQuery(new BoxTextQuery(title,cellSize,description));
76}
77
78void TextDialog::queryElement(const char* title, std::vector<element *> *target, string description){
79 registerQuery(new ElementTextQuery(title,target,description));
80}
81
82/************************** Query Infrastructure ************************/
83
84TextDialog::EmptyTextQuery::EmptyTextQuery(string title, std::string _description) :
85 Dialog::EmptyQuery(title,_description)
86{}
87
88TextDialog::EmptyTextQuery::~EmptyTextQuery() {}
89
90bool TextDialog::EmptyTextQuery::handle() {
91 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
92 return true;
93}
94
95TextDialog::IntTextQuery::IntTextQuery(string title, int * _target, std::string _description) :
96 Dialog::IntQuery(title,_target,_description)
97{}
98
99TextDialog::IntTextQuery::~IntTextQuery() {}
100
101bool TextDialog::IntTextQuery::handle() {
102 bool badInput = false;
103 do{
104 badInput = false;
105 Log() << Verbose(0) << getTitle();
106 cin >> tmp;
107 if(cin.fail()){
108 badInput=true;
109 cin.clear();
110 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
111 Log() << Verbose(0) << "Input was not a number!" << endl;
112 }
113 } while(badInput);
114 // clear the input buffer of anything still in the line
115 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
116 return true;
117}
118
119TextDialog::BooleanTextQuery::BooleanTextQuery(string title, bool * _target, std::string _description) :
120 Dialog::BooleanQuery(title,_target,_description)
121{}
122
123TextDialog::BooleanTextQuery::~BooleanTextQuery() {}
124
125bool TextDialog::BooleanTextQuery::handle() {
126 bool badInput = false;
127 char input = ' ';
128 do{
129 badInput = false;
130 Log() << Verbose(0) << getTitle();
131 cin >> input;
132 if ((input == 'y' ) || (input == 'Y')) {
133 tmp = true;
134 } else if ((input == 'n' ) || (input == 'N')) {
135 tmp = false;
136 } else {
137 badInput=true;
138 cin.clear();
139 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
140 Log() << Verbose(0) << "Input was not of [yYnN]!" << endl;
141 }
142 } while(badInput);
143 // clear the input buffer of anything still in the line
144 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
145 return true;
146}
147
148TextDialog::StringTextQuery::StringTextQuery(string title,string *_target, std::string _description) :
149 Dialog::StringQuery(title,_target,_description)
150{}
151
152TextDialog::StringTextQuery::~StringTextQuery() {}
153
154bool TextDialog::StringTextQuery::handle() {
155 Log() << Verbose(0) << getTitle();
156 getline(cin,tmp);
157 return true;
158}
159
160TextDialog::DoubleTextQuery::DoubleTextQuery(string title,double *_target, std::string _description) :
161 Dialog::DoubleQuery(title,_target,_description)
162{}
163
164TextDialog::DoubleTextQuery::~DoubleTextQuery() {}
165
166bool TextDialog::DoubleTextQuery::handle() {
167 bool badInput = false;
168 do{
169 badInput = false;
170 Log() << Verbose(0) << getTitle();
171 cin >> tmp;
172 if(cin.fail()){
173 badInput = true;
174 cin.clear();
175 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
176 Log() << Verbose(0) << "Input was not a number!" << endl;
177 }
178 }while(badInput);
179 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
180 return true;
181}
182
183TextDialog::AtomTextQuery::AtomTextQuery(string title, atom **_target, std::string _description) :
184 Dialog::AtomQuery(title,_target,_description)
185{}
186
187TextDialog::AtomTextQuery::~AtomTextQuery() {}
188
189bool TextDialog::AtomTextQuery::handle() {
190 int idxOfAtom=0;
191 bool badInput = false;
192 do{
193 badInput = false;
194 Log() << Verbose(0) << getTitle();
195 cin >> idxOfAtom;
196 if(cin.fail()){
197 badInput = true;
198 cin.clear();
199 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
200 Log() << Verbose(0) << "Input was not a number!" << endl;
201 continue;
202 }
203
204 tmp = World::getInstance().getAtom(AtomById(idxOfAtom));
205 if(!tmp && idxOfAtom!=-1){
206 Log() << Verbose(0) << "Invalid Atom Index" << endl;
207 badInput = true;
208 }
209
210 } while(badInput);
211 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
212 return (idxOfAtom!=-1);
213}
214
215TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, molecule **_target, std::string _description) :
216 Dialog::MoleculeQuery(title,_target,_description)
217{}
218
219TextDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
220
221bool TextDialog::MoleculeTextQuery::handle() {
222 int idxOfMol=0;
223 bool badInput = false;
224 do{
225 badInput = false;
226 Log() << Verbose(0) << getTitle();
227 cin >> idxOfMol;
228 if(cin.fail()){
229 badInput = true;
230 cin.clear();
231 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
232 Log() << Verbose(0) << "Input was not a number!" << endl;
233 continue;
234 }
235
236 tmp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
237 if(!tmp && idxOfMol!=-1){
238 Log() << Verbose(0) << "Invalid Molecule Index" << endl;
239 badInput = true;
240 }
241
242 } while(badInput);
243 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
244 return (idxOfMol!=-1);
245}
246
247TextDialog::VectorTextQuery::VectorTextQuery(std::string title, Vector *_target, bool _check, std::string _description) :
248 Dialog::VectorQuery(title,_target,_check,_description)
249{}
250
251TextDialog::VectorTextQuery::~VectorTextQuery()
252{}
253
254bool TextDialog::VectorTextQuery::handle() {
255 Log() << Verbose(0) << getTitle();
256
257 const Matrix &M = World::getInstance().getDomain().getM();
258 char coords[3] = {'x','y','z'};
259 for (int i=0;i<3;i++) {
260 do {
261 Log() << Verbose(0) << coords[i] << "[0.." << M.at(i,i) << "]: ";
262 cin >> (*tmp)[i];
263 } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= M.at(i,i))) && (check));
264 }
265 return true;
266}
267
268TextDialog::BoxTextQuery::BoxTextQuery(std::string title, Box* _cellSize, std::string _description) :
269 Dialog::BoxQuery(title,_cellSize,_description)
270{}
271
272TextDialog::BoxTextQuery::~BoxTextQuery()
273{}
274
275bool TextDialog::BoxTextQuery::handle() {
276 Log() << Verbose(0) << getTitle();
277
278 std::string coords[6] = {"xx","xy","xz", "yy", "yz", "zz"};
279 for (int i=0;i<6;i++) {
280 Log() << Verbose(0) << coords[i] << ": ";
281 cin >> tmp[i];
282 }
283 return true;
284}
285
286TextDialog::ElementTextQuery::ElementTextQuery(std::string title, std::vector<element *> *_target, std::string _description) :
287 Dialog::ElementQuery(title,_target,_description)
288{}
289
290TextDialog::ElementTextQuery::~ElementTextQuery()
291{}
292
293bool TextDialog::ElementTextQuery::handle() {
294 bool badInput=false;
295 bool aborted = false;
296 element * tmp = NULL;
297 do{
298 badInput = false;
299 Log() << Verbose(0) << getTitle();
300
301 // try to read as Atomic number
302 int Z;
303 cin >> Z;
304 if(!cin.fail()){
305 if(Z==-1){
306 aborted = true;
307 }
308 else{
309 tmp = World::getInstance().getPeriode()->FindElement(Z);
310 if(!tmp){
311 Log() << Verbose(0) << "No element with this atomic number!" << endl;
312 badInput = true;
313 } else {
314 elements.push_back(tmp);
315 }
316 }
317 continue;
318 }
319 else{
320 cin.clear();
321 }
322
323 // Try to read as shorthand
324 // the last buffer content was not removed, so we read the
325 // same thing again, this time as a string
326 string shorthand;
327 cin >> shorthand;
328 if(!cin.fail()){
329 if(shorthand.empty()){
330 aborted = true;
331 }
332 else{
333 tmp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
334 if(!tmp){
335 Log() << Verbose(0) << "No element with this shorthand!" << endl;
336 badInput = true;
337 } else {
338 elements.push_back(tmp);
339 }
340 }
341 }
342 else{
343 Log() << Verbose(0) << "Could not read input. Try Again." << endl;
344 cin.clear();
345 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
346 badInput = true;
347 }
348
349 }while(badInput);
350 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
351 return !aborted;
352}
Note: See TracBrowser for help on using the repository browser.