Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Dialog.cpp

    r112b09 rc508ef5  
    88#include "Helpers/MemDebug.hpp"
    99
    10 #include <cassert>
    11 
    1210#include "Dialog.hpp"
    13 
     11#include "ValueStorage.hpp"
     12
     13#include "verbose.hpp"
    1414#include "atom.hpp"
    1515#include "element.hpp"
    1616#include "molecule.hpp"
    1717#include "vector.hpp"
     18#include "Matrix.hpp"
     19#include "Box.hpp"
    1820
    1921using namespace std;
     
    3638
    3739bool Dialog::display(){
     40  if(checkAll()){
     41    setAll();
     42    return true;
     43  }
     44  else{
     45    return false;
     46  }
     47}
     48
     49bool Dialog::checkAll(){
    3850  list<Query*>::iterator iter;
    3951  bool retval = true;
     
    4153    retval &= (*iter)->handle();
    4254    // if any query fails (is canceled), we can end the handling process
    43     if(!retval)
     55    if(!retval) {
     56      DoeLog(1) && (eLog() << Verbose(1) << "The following query failed: " << (**iter).getTitle() << "." << endl);
    4457      break;
    45   }
    46   if (retval){
    47     // if all queries succeeded we can set the targets to appropriate values
    48     for(iter=queries.begin(); iter!=queries.end(); iter++) {
    49       (*iter)->setResult();
    5058    }
    5159  }
    5260  return retval;
     61}
     62
     63void Dialog::setAll(){
     64  list<Query*>::iterator iter;
     65  for(iter=queries.begin(); iter!=queries.end(); iter++) {
     66    (*iter)->setResult();
     67  }
     68}
     69
     70bool Dialog::hasQueries(){
     71  return queries.size();
    5372}
    5473
     
    83102// Int Queries
    84103
    85 Dialog::IntQuery::IntQuery(string title,int *_target, std::string description) :
    86     Query(title, description), target(_target)
     104Dialog::IntQuery::IntQuery(string title, std::string description) :
     105    Query(title, description)
    87106{}
    88107
     
    90109
    91110void Dialog::IntQuery::setResult() {
    92   *target = tmp;
    93 }
    94 
    95 // Int Queries
    96 
    97 Dialog::BooleanQuery::BooleanQuery(string title,bool *_target, std::string description) :
    98     Query(title, description), target(_target)
     111  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     112}
     113
     114// Ints Queries
     115
     116Dialog::IntsQuery::IntsQuery(string title, std::string description) :
     117    Query(title, description)
     118{}
     119
     120Dialog::IntsQuery::~IntsQuery() {}
     121
     122void Dialog::IntsQuery::setResult() {
     123  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     124}
     125
     126// Bool Queries
     127
     128Dialog::BooleanQuery::BooleanQuery(string title,std::string description) :
     129    Query(title, description)
    99130{}
    100131
     
    102133
    103134void Dialog::BooleanQuery::setResult() {
    104   *target = tmp;
     135  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    105136}
    106137
    107138// String Queries
    108139
    109 Dialog::StringQuery::StringQuery(string title,string *_target, std::string _description) :
    110     Query(title, _description), target(_target)
     140Dialog::StringQuery::StringQuery(string title,std::string _description) :
     141    Query(title, _description)
    111142{}
    112143
     
    114145
    115146void Dialog::StringQuery::setResult() {
    116   *target = tmp;
     147  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     148}
     149
     150// Strings Queries
     151
     152Dialog::StringsQuery::StringsQuery(string title,std::string _description) :
     153    Query(title, _description)
     154{}
     155
     156Dialog::StringsQuery::~StringsQuery() {};
     157
     158void Dialog::StringsQuery::setResult() {
     159  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    117160}
    118161
    119162// Double Queries
    120163
    121 Dialog::DoubleQuery::DoubleQuery(string title,double *_target, std::string _description) :
    122     Query(title, _description), target(_target)
     164Dialog::DoubleQuery::DoubleQuery(string title, std::string _description) :
     165    Query(title, _description)
    123166{}
    124167
     
    126169
    127170void Dialog::DoubleQuery::setResult() {
    128   *target = tmp;
     171  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     172}
     173
     174// Doubles Queries
     175
     176Dialog::DoublesQuery::DoublesQuery(string title, std::string _description) :
     177    Query(title, _description)
     178{}
     179
     180Dialog::DoublesQuery::~DoublesQuery() {};
     181
     182void Dialog::DoublesQuery::setResult() {
     183  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    129184}
    130185
     
    132187// Atom Queries
    133188
    134 Dialog::AtomQuery::AtomQuery(string title, atom **_target, std::string _description) :
     189Dialog::AtomQuery::AtomQuery(string title, std::string _description) :
    135190    Query(title, _description),
    136     tmp(0),
    137     target(_target)
    138 
     191    tmp(0)
    139192{}
    140193
     
    142195
    143196void Dialog::AtomQuery::setResult() {
    144   *target = tmp;
     197  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     198}
     199
     200// Atoms Queries
     201
     202Dialog::AtomsQuery::AtomsQuery(string title, std::string _description) :
     203    Query(title, _description),
     204    tmp(0)
     205{}
     206
     207Dialog::AtomsQuery::~AtomsQuery() {}
     208
     209void Dialog::AtomsQuery::setResult() {
     210  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    145211}
    146212
    147213// Molecule Queries
    148214
    149 Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, std::string _description) :
     215Dialog::MoleculeQuery::MoleculeQuery(string title, std::string _description) :
    150216    Query(title, _description),
    151     tmp(0),
    152     target(_target)
    153 
     217    tmp(0)
    154218{}
    155219
     
    157221
    158222void Dialog::MoleculeQuery::setResult() {
    159   *target = tmp;
     223  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     224}
     225
     226// Molecules Queries
     227
     228Dialog::MoleculesQuery::MoleculesQuery(string title, std::string _description) :
     229    Query(title, _description),
     230    tmp(0)
     231{}
     232
     233Dialog::MoleculesQuery::~MoleculesQuery() {}
     234
     235void Dialog::MoleculesQuery::setResult() {
     236  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    160237}
    161238
    162239// Vector Queries
    163240
    164 Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check, std::string _description) :
     241Dialog::VectorQuery::VectorQuery(std::string title,bool _check, std::string _description) :
    165242  Query(title, _description),
    166   cellSize(_cellSize),
    167   check(_check),
    168   target(_target)
    169 {
    170   tmp = new Vector();
    171 }
     243  check(_check)
     244{}
    172245
    173246Dialog::VectorQuery::~VectorQuery()
    174 {
    175   delete tmp;
    176 }
     247{}
    177248
    178249void Dialog::VectorQuery::setResult() {
    179   *target = *tmp;
     250  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     251}
     252
     253// Vectors Queries
     254
     255Dialog::VectorsQuery::VectorsQuery(std::string title,bool _check, std::string _description) :
     256  Query(title, _description),
     257  check(_check)
     258{}
     259
     260Dialog::VectorsQuery::~VectorsQuery()
     261{}
     262
     263void Dialog::VectorsQuery::setResult() {
     264  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    180265}
    181266
    182267// Box Queries
    183268
    184 Dialog::BoxQuery::BoxQuery(std::string title, double ** const _cellSize, std::string _description) :
    185   Query(title, _description),
    186   target(_cellSize)
    187 {
    188     tmp = new double[6];
    189 }
     269Dialog::BoxQuery::BoxQuery(std::string title, std::string _description) :
     270  Query(title, _description)
     271{}
    190272
    191273Dialog::BoxQuery::~BoxQuery()
    192 {
    193   delete[] tmp;
    194 }
     274{}
    195275
    196276void Dialog::BoxQuery::setResult() {
    197   for (int i=0;i<6;i++) {
    198     (*target)[i] = tmp[i];
    199   }
     277  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    200278}
    201279
    202280// Element Queries
    203 Dialog::ElementQuery::ElementQuery(std::string title, const element **_target, std::string _description) :
    204   Query(title, _description),
    205   tmp(0),
    206   target(_target)
     281Dialog::ElementQuery::ElementQuery(std::string title, std::string _description) :
     282  Query(title, _description)
    207283  {}
    208284
     
    210286
    211287void Dialog::ElementQuery::setResult(){
    212   *target=tmp;
    213 }
     288  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     289}
     290
     291// Elements Queries
     292Dialog::ElementsQuery::ElementsQuery(std::string title, std::string _description) :
     293  Query(title, _description)
     294  {}
     295
     296Dialog::ElementsQuery::~ElementsQuery(){}
     297
     298void Dialog::ElementsQuery::setResult(){
     299  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     300}
Note: See TracChangeset for help on using the changeset viewer.