source: src/UIElements/TextDialog.cpp@ 498c519

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 498c519 was 86466e, checked in by Frederik Heber <heber@…>, 15 years ago

new query class EmptyQuery for showing text messages.

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

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