source: src/UIElements/TextUI/TextDialog.cpp@ 3731b4

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 3731b4 was 3731b4, checked in by Frederik Heber <heber@…>, 14 years ago

Fixed remainder of Dialog and derived classes for still present _target's.

  • Property mode set to 100644
File size: 9.8 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, string description){
47 registerQuery(new BooleanTextQuery(title,description));
48}
49
50void TextDialog::queryInt(const char* title, string description){
51 registerQuery(new IntTextQuery(title,description));
52}
53
54void TextDialog::queryDouble(const char* title, string description){
55 registerQuery(new DoubleTextQuery(title,description));
56}
57
58void TextDialog::queryString(const char* title, string description){
59 registerQuery(new StringTextQuery(title,description));
60}
61
62void TextDialog::queryStrings(const char* title, string description){
63 registerQuery(new StringsTextQuery(title,description));
64}
65
66void TextDialog::queryAtom(const char* title, string description) {
67 registerQuery(new AtomTextQuery(title,description));
68}
69
70void TextDialog::queryMolecule(const char* title, string description) {
71 registerQuery(new MoleculeTextQuery(title,description));
72}
73
74void TextDialog::queryVector(const char* title, bool check, string description) {
75 registerQuery(new VectorTextQuery(title,check,description));
76}
77
78void TextDialog::queryBox(const char* title, string description) {
79 registerQuery(new BoxTextQuery(title,description));
80}
81
82void TextDialog::queryElement(const char* title, string description){
83 registerQuery(new ElementTextQuery(title,description));
84}
85
86/************************** Query Infrastructure ************************/
87
88TextDialog::EmptyTextQuery::EmptyTextQuery(string title, std::string _description) :
89 Dialog::EmptyQuery(title,_description)
90{}
91
92TextDialog::EmptyTextQuery::~EmptyTextQuery() {}
93
94bool TextDialog::EmptyTextQuery::handle() {
95 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
96 return true;
97}
98
99TextDialog::IntTextQuery::IntTextQuery(string title, std::string _description) :
100 Dialog::IntQuery(title,_description)
101{}
102
103TextDialog::IntTextQuery::~IntTextQuery() {}
104
105bool TextDialog::IntTextQuery::handle() {
106 bool badInput = false;
107 do{
108 badInput = false;
109 Log() << Verbose(0) << getTitle();
110 cin >> tmp;
111 if(cin.fail()){
112 badInput=true;
113 cin.clear();
114 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
115 Log() << Verbose(0) << "Input was not a number!" << endl;
116 }
117 } while(badInput);
118 // clear the input buffer of anything still in the line
119 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
120 return true;
121}
122
123TextDialog::BooleanTextQuery::BooleanTextQuery(string title, std::string _description) :
124 Dialog::BooleanQuery(title,_description)
125{}
126
127TextDialog::BooleanTextQuery::~BooleanTextQuery() {}
128
129bool TextDialog::BooleanTextQuery::handle() {
130 bool badInput = false;
131 char input = ' ';
132 do{
133 badInput = false;
134 Log() << Verbose(0) << getTitle();
135 cin >> input;
136 if ((input == 'y' ) || (input == 'Y')) {
137 tmp = true;
138 } else if ((input == 'n' ) || (input == 'N')) {
139 tmp = false;
140 } else {
141 badInput=true;
142 cin.clear();
143 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
144 Log() << Verbose(0) << "Input was not of [yYnN]!" << endl;
145 }
146 } while(badInput);
147 // clear the input buffer of anything still in the line
148 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
149 return true;
150}
151
152TextDialog::StringTextQuery::StringTextQuery(string title, std::string _description) :
153 Dialog::StringQuery(title,_description)
154{}
155
156TextDialog::StringTextQuery::~StringTextQuery() {}
157
158bool TextDialog::StringTextQuery::handle() {
159 Log() << Verbose(0) << getTitle();
160 getline(cin,tmp);
161 return true;
162}
163
164TextDialog::StringsTextQuery::StringsTextQuery(string title, std::string _description) :
165 Dialog::StringsQuery(title,_description)
166{}
167
168TextDialog::StringsTextQuery::~StringsTextQuery() {}
169
170bool TextDialog::StringsTextQuery::handle() {
171 Log() << Verbose(0) << getTitle();
172 getline(cin,temp);
173 // dissect by ","
174 string::iterator olditer = temp.begin();
175 for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
176 if (*iter == ' ') {
177 tmp.push_back(string(iter, olditer));
178 olditer = iter;
179 }
180 }
181 if (olditer != temp.begin()) // insert last part also
182 tmp.push_back(string(olditer, temp.end()));
183
184 return true;
185}
186
187TextDialog::DoubleTextQuery::DoubleTextQuery(string title, std::string _description) :
188 Dialog::DoubleQuery(title,_description)
189{}
190
191TextDialog::DoubleTextQuery::~DoubleTextQuery() {}
192
193bool TextDialog::DoubleTextQuery::handle() {
194 bool badInput = false;
195 do{
196 badInput = false;
197 Log() << Verbose(0) << getTitle();
198 cin >> tmp;
199 if(cin.fail()){
200 badInput = true;
201 cin.clear();
202 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
203 Log() << Verbose(0) << "Input was not a number!" << endl;
204 }
205 }while(badInput);
206 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
207 return true;
208}
209
210TextDialog::AtomTextQuery::AtomTextQuery(string title, std::string _description) :
211 Dialog::AtomQuery(title,_description)
212{}
213
214TextDialog::AtomTextQuery::~AtomTextQuery() {}
215
216bool TextDialog::AtomTextQuery::handle() {
217 int idxOfAtom=0;
218 bool badInput = false;
219 do{
220 badInput = false;
221 Log() << Verbose(0) << getTitle();
222 cin >> idxOfAtom;
223 if(cin.fail()){
224 badInput = true;
225 cin.clear();
226 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
227 Log() << Verbose(0) << "Input was not a number!" << endl;
228 continue;
229 }
230
231 tmp = World::getInstance().getAtom(AtomById(idxOfAtom));
232 if(!tmp && idxOfAtom!=-1){
233 Log() << Verbose(0) << "Invalid Atom Index" << endl;
234 badInput = true;
235 }
236
237 } while(badInput);
238 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
239 return (idxOfAtom!=-1);
240}
241
242TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, std::string _description) :
243 Dialog::MoleculeQuery(title,_description)
244{}
245
246TextDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
247
248bool TextDialog::MoleculeTextQuery::handle() {
249 int idxOfMol=0;
250 bool badInput = false;
251 do{
252 badInput = false;
253 Log() << Verbose(0) << getTitle();
254 cin >> idxOfMol;
255 if(cin.fail()){
256 badInput = true;
257 cin.clear();
258 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
259 Log() << Verbose(0) << "Input was not a number!" << endl;
260 continue;
261 }
262
263 tmp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
264 if(!tmp && idxOfMol!=-1){
265 Log() << Verbose(0) << "Invalid Molecule Index" << endl;
266 badInput = true;
267 }
268
269 } while(badInput);
270 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
271 return (idxOfMol!=-1);
272}
273
274TextDialog::VectorTextQuery::VectorTextQuery(std::string title, bool _check, std::string _description) :
275 Dialog::VectorQuery(title,_check,_description)
276{}
277
278TextDialog::VectorTextQuery::~VectorTextQuery()
279{}
280
281bool TextDialog::VectorTextQuery::handle() {
282 Log() << Verbose(0) << getTitle();
283
284 const Matrix &M = World::getInstance().getDomain().getM();
285 char coords[3] = {'x','y','z'};
286 for (int i=0;i<3;i++) {
287 do {
288 Log() << Verbose(0) << coords[i] << "[0.." << M.at(i,i) << "]: ";
289 cin >> (*tmp)[i];
290 } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= M.at(i,i))) && (check));
291 }
292 return true;
293}
294
295TextDialog::BoxTextQuery::BoxTextQuery(std::string title, std::string _description) :
296 Dialog::BoxQuery(title,_description)
297{}
298
299TextDialog::BoxTextQuery::~BoxTextQuery()
300{}
301
302bool TextDialog::BoxTextQuery::handle() {
303 Log() << Verbose(0) << getTitle();
304
305 std::string coords[6] = {"xx","xy","xz", "yy", "yz", "zz"};
306 for (int i=0;i<6;i++) {
307 Log() << Verbose(0) << coords[i] << ": ";
308 cin >> tmp[i];
309 }
310 return true;
311}
312
313TextDialog::ElementTextQuery::ElementTextQuery(std::string title, std::string _description) :
314 Dialog::ElementQuery(title,_description)
315{}
316
317TextDialog::ElementTextQuery::~ElementTextQuery()
318{}
319
320bool TextDialog::ElementTextQuery::handle() {
321 bool badInput=false;
322 bool aborted = false;
323 element * temp = NULL;
324 do{
325 badInput = false;
326 Log() << Verbose(0) << getTitle();
327
328 // try to read as Atomic number
329 int Z;
330 cin >> Z;
331 if(!cin.fail()){
332 if(Z==-1){
333 aborted = true;
334 }
335 else{
336 temp = World::getInstance().getPeriode()->FindElement(Z);
337 if(!temp){
338 Log() << Verbose(0) << "No element with this atomic number!" << endl;
339 badInput = true;
340 } else {
341 tmp.push_back(temp);
342 }
343 }
344 continue;
345 }
346 else{
347 cin.clear();
348 }
349
350 // Try to read as shorthand
351 // the last buffer content was not removed, so we read the
352 // same thing again, this time as a string
353 string shorthand;
354 cin >> shorthand;
355 if(!cin.fail()){
356 if(shorthand.empty()){
357 aborted = true;
358 }
359 else{
360 temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
361 if(!temp){
362 Log() << Verbose(0) << "No element with this shorthand!" << endl;
363 badInput = true;
364 } else {
365 tmp.push_back(temp);
366 }
367 }
368 }
369 else{
370 Log() << Verbose(0) << "Could not read input. Try Again." << endl;
371 cin.clear();
372 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
373 badInput = true;
374 }
375
376 }while(badInput);
377 cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
378 return !aborted;
379}
Note: See TracBrowser for help on using the repository browser.