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

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

Merge branch 'stable' into StructureRefactoring

Conflicts:

src/Actions/WorldAction/CenterOnEdgeAction.cpp
src/Actions/WorldAction/ChangeBoxAction.cpp
src/Actions/WorldAction/RepeatBoxAction.cpp
src/Actions/WorldAction/ScaleBoxAction.cpp
src/World.cpp
src/boundary.cpp

  • Property mode set to 100644
File size: 10.4 KB
RevLine 
[f5a86a]1/*
2 * TextDialog.cpp
3 *
4 * Created on: Jan 5, 2010
5 * Author: crueger
6 */
7
[112b09]8#include "Helpers/MemDebug.hpp"
9
[f5a86a]10#include <iostream>
11
[97ebf8]12#include <Descriptors/AtomDescriptor.hpp>
13#include <Descriptors/AtomIdDescriptor.hpp>
14#include <Descriptors/MoleculeDescriptor.hpp>
15#include <Descriptors/MoleculeIdDescriptor.hpp>
[5079a0]16#include "TextUI/TextDialog.hpp"
[7aa000]17
[5a7243]18#include "World.hpp"
19#include "periodentafel.hpp"
[f5a86a]20#include "log.hpp"
21#include "verbose.hpp"
22
[97ebf8]23#include "atom.hpp"
24#include "element.hpp"
25#include "molecule.hpp"
26#include "vector.hpp"
[84c494]27#include "Matrix.hpp"
28#include "Box.hpp"
[97ebf8]29
[f5a86a]30using namespace std;
31
32
33TextDialog::TextDialog()
34{
35}
36
37TextDialog::~TextDialog()
38{
39}
40
[7aa000]41
[86466e]42void TextDialog::queryEmpty(const char* title, string description){
43 registerQuery(new EmptyTextQuery(title,description));
44}
45
[97ebf8]46void TextDialog::queryBoolean(const char* title, bool* target, string description){
47 registerQuery(new BooleanTextQuery(title,target,description));
48}
49
[a2ab15]50void TextDialog::queryInt(const char* title, int* target, string description){
51 registerQuery(new IntTextQuery(title,target,description));
[45f5d6]52}
53
[a2ab15]54void TextDialog::queryDouble(const char* title, double* target, string description){
55 registerQuery(new DoubleTextQuery(title,target,description));
[2ededc2]56}
57
[a2ab15]58void TextDialog::queryString(const char* title, string* target, string description){
59 registerQuery(new StringTextQuery(title,target,description));
[f5a86a]60}
61
[cd8e55]62void TextDialog::queryStrings(const char* title, vector<string>* target, string description){
63 registerQuery(new StringsTextQuery(title,target,description));
64}
65
[97ebf8]66void TextDialog::queryAtom(const char* title, atom **target, string description) {
67 registerQuery(new AtomTextQuery(title,target,description));
68}
69
70void TextDialog::queryMolecule(const char* title, molecule **target, string description) {
71 registerQuery(new MoleculeTextQuery(title,target,description));
[7aa000]72}
73
[84c494]74void TextDialog::queryVector(const char* title, Vector *target, bool check, string description) {
75 registerQuery(new VectorTextQuery(title,target,check,description));
[2ededc2]76}
77
[84c494]78void TextDialog::queryBox(const char* title,Box* cellSize, string description) {
[97ebf8]79 registerQuery(new BoxTextQuery(title,cellSize,description));
80}
81
[104524]82void TextDialog::queryElement(const char* title, std::vector<element *> *target, string description){
[a2ab15]83 registerQuery(new ElementTextQuery(title,target,description));
[5a7243]84}
85
[7aa000]86/************************** Query Infrastructure ************************/
87
[86466e]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, int * _target, std::string _description) :
[a2ab15]100 Dialog::IntQuery(title,_target,_description)
[45f5d6]101{}
102
103TextDialog::IntTextQuery::~IntTextQuery() {}
104
105bool TextDialog::IntTextQuery::handle() {
[8de8f7]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');
[45f5d6]120 return true;
121}
122
[97ebf8]123TextDialog::BooleanTextQuery::BooleanTextQuery(string title, bool * _target, std::string _description) :
124 Dialog::BooleanQuery(title,_target,_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
[a2ab15]152TextDialog::StringTextQuery::StringTextQuery(string title,string *_target, std::string _description) :
153 Dialog::StringQuery(title,_target,_description)
[45f5d6]154{}
155
156TextDialog::StringTextQuery::~StringTextQuery() {}
157
158bool TextDialog::StringTextQuery::handle() {
[7aa000]159 Log() << Verbose(0) << getTitle();
[8de8f7]160 getline(cin,tmp);
[45f5d6]161 return true;
[f5a86a]162}
[7aa000]163
[cd8e55]164TextDialog::StringsTextQuery::StringsTextQuery(string title,vector<string> *_target, std::string _description) :
165 Dialog::StringsQuery(title,_target,_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
[a2ab15]187TextDialog::DoubleTextQuery::DoubleTextQuery(string title,double *_target, std::string _description) :
188 Dialog::DoubleQuery(title,_target,_description)
[2ededc2]189{}
190
191TextDialog::DoubleTextQuery::~DoubleTextQuery() {}
192
193bool TextDialog::DoubleTextQuery::handle() {
[8de8f7]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');
[2ededc2]207 return true;
208}
209
[97ebf8]210TextDialog::AtomTextQuery::AtomTextQuery(string title, atom **_target, std::string _description) :
211 Dialog::AtomQuery(title,_target,_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, molecule **_target, std::string _description) :
243 Dialog::MoleculeQuery(title,_target,_description)
[7aa000]244{}
245
246TextDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
247
248bool TextDialog::MoleculeTextQuery::handle() {
[8de8f7]249 int idxOfMol=0;
250 bool badInput = false;
251 do{
252 badInput = false;
[7aa000]253 Log() << Verbose(0) << getTitle();
254 cin >> idxOfMol;
[8de8f7]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
[97ebf8]263 tmp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
[8de8f7]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');
[7aa000]271 return (idxOfMol!=-1);
272}
[2ededc2]273
[84c494]274TextDialog::VectorTextQuery::VectorTextQuery(std::string title, Vector *_target, bool _check, std::string _description) :
275 Dialog::VectorQuery(title,_target,_check,_description)
[2ededc2]276{}
277
278TextDialog::VectorTextQuery::~VectorTextQuery()
279{}
280
281bool TextDialog::VectorTextQuery::handle() {
[0a4f7f]282 Log() << Verbose(0) << getTitle();
283
[84c494]284 const Matrix &M = World::getInstance().getDomain().getM();
[0a4f7f]285 char coords[3] = {'x','y','z'};
286 for (int i=0;i<3;i++) {
287 do {
[84c494]288 Log() << Verbose(0) << coords[i] << "[0.." << M.at(i,i) << "]: ";
[0a4f7f]289 cin >> (*tmp)[i];
[84c494]290 } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= M.at(i,i))) && (check));
[0a4f7f]291 }
292 return true;
[5a7243]293}
294
[84c494]295TextDialog::BoxTextQuery::BoxTextQuery(std::string title, Box* _cellSize, std::string _description) :
[97ebf8]296 Dialog::BoxQuery(title,_cellSize,_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}
[5a7243]312
[104524]313TextDialog::ElementTextQuery::ElementTextQuery(std::string title, std::vector<element *> *_target, std::string _description) :
314 Dialog::ElementQuery(title,_target,_description)
[5a7243]315{}
316
317TextDialog::ElementTextQuery::~ElementTextQuery()
318{}
319
320bool TextDialog::ElementTextQuery::handle() {
[8de8f7]321 bool badInput=false;
322 bool aborted = false;
[104524]323 element * tmp = NULL;
[8de8f7]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 tmp = World::getInstance().getPeriode()->FindElement(Z);
337 if(!tmp){
338 Log() << Verbose(0) << "No element with this atomic number!" << endl;
339 badInput = true;
[104524]340 } else {
341 elements.push_back(tmp);
[8de8f7]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 tmp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
361 if(!tmp){
362 Log() << Verbose(0) << "No element with this shorthand!" << endl;
363 badInput = true;
[104524]364 } else {
365 elements.push_back(tmp);
[8de8f7]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;
[2ededc2]379}
Note: See TracBrowser for help on using the repository browser.