| 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 "atom.hpp"
 | 
|---|
| 13 | #include "molecule.hpp"
 | 
|---|
| 14 | #include "log.hpp"
 | 
|---|
| 15 | #include "verbose.hpp"
 | 
|---|
| 16 | 
 | 
|---|
| 17 | using namespace std;
 | 
|---|
| 18 | 
 | 
|---|
| 19 | 
 | 
|---|
| 20 | TextDialog::TextDialog()
 | 
|---|
| 21 | {
 | 
|---|
| 22 | }
 | 
|---|
| 23 | 
 | 
|---|
| 24 | TextDialog::~TextDialog()
 | 
|---|
| 25 | {
 | 
|---|
| 26 | }
 | 
|---|
| 27 | 
 | 
|---|
| 28 | 
 | 
|---|
| 29 | void TextDialog::queryInt(const char* title, int* target){
 | 
|---|
| 30 |   registerQuery(new IntTextQuery(title,target));
 | 
|---|
| 31 | }
 | 
|---|
| 32 | 
 | 
|---|
| 33 | void TextDialog::queryString(const char* title, string* target){
 | 
|---|
| 34 |   registerQuery(new StringTextQuery(title,target));
 | 
|---|
| 35 | }
 | 
|---|
| 36 | 
 | 
|---|
| 37 | void TextDialog::queryMolecule(const char* title, molecule **target, MoleculeListClass *molecules) {
 | 
|---|
| 38 |   registerQuery(new MoleculeTextQuery(title,target,molecules));
 | 
|---|
| 39 | }
 | 
|---|
| 40 | 
 | 
|---|
| 41 | /************************** Query Infrastructure ************************/
 | 
|---|
| 42 | 
 | 
|---|
| 43 | TextDialog::IntTextQuery::IntTextQuery(string title,int *_target) :
 | 
|---|
| 44 |     Dialog::IntQuery(title,_target)
 | 
|---|
| 45 | {}
 | 
|---|
| 46 | 
 | 
|---|
| 47 | TextDialog::IntTextQuery::~IntTextQuery() {}
 | 
|---|
| 48 | 
 | 
|---|
| 49 | bool TextDialog::IntTextQuery::handle() {
 | 
|---|
| 50 |   Log() << Verbose(0) << getTitle();
 | 
|---|
| 51 |   cin >> tmp;
 | 
|---|
| 52 |   return true;
 | 
|---|
| 53 | }
 | 
|---|
| 54 | 
 | 
|---|
| 55 | TextDialog::StringTextQuery::StringTextQuery(string title,string *_target) :
 | 
|---|
| 56 |     Dialog::StringQuery(title,_target)
 | 
|---|
| 57 | {}
 | 
|---|
| 58 | 
 | 
|---|
| 59 | TextDialog::StringTextQuery::~StringTextQuery() {}
 | 
|---|
| 60 | 
 | 
|---|
| 61 | bool TextDialog::StringTextQuery::handle() {
 | 
|---|
| 62 |   Log() << Verbose(0) << getTitle();
 | 
|---|
| 63 |   cin >> tmp;
 | 
|---|
| 64 |   return true;
 | 
|---|
| 65 | }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | TextDialog::MoleculeTextQuery::MoleculeTextQuery(string title, molecule **_target, MoleculeListClass *_molecules) :
 | 
|---|
| 68 |     Dialog::MoleculeQuery(title,_target,_molecules)
 | 
|---|
| 69 | {}
 | 
|---|
| 70 | 
 | 
|---|
| 71 | TextDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
 | 
|---|
| 72 | 
 | 
|---|
| 73 | bool TextDialog::MoleculeTextQuery::handle() {
 | 
|---|
| 74 |   int idxOfMol;
 | 
|---|
| 75 |   Log() << Verbose(0) << getTitle();
 | 
|---|
| 76 |   cin >> idxOfMol;
 | 
|---|
| 77 |   tmp = molecules->ReturnIndex(idxOfMol);
 | 
|---|
| 78 |   while(!tmp && (idxOfMol !=-1)) {
 | 
|---|
| 79 |     Log() << Verbose(0) << "Invalid Molecule Index" << endl;
 | 
|---|
| 80 |     Log() << Verbose(0) << getTitle();
 | 
|---|
| 81 |     cin >> idxOfMol;
 | 
|---|
| 82 |     tmp = molecules->ReturnIndex(idxOfMol);
 | 
|---|
| 83 |   }
 | 
|---|
| 84 |   return (idxOfMol!=-1);
 | 
|---|
| 85 | }
 | 
|---|