source: src/UIElements/TextUI/TextDialog.cpp@ 492279

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

Broken: Merge commit 'Gitosis/stable' into stable

Conflicts:

molecuilder/src/Actions/AnalysisAction/PairCorrelationToPointAction.cpp
molecuilder/src/Actions/AnalysisAction/PairCorrelationToSurfaceAction.cpp
molecuilder/src/Makefile.am

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