Changeset 7cd6e7 for src/UIElements


Ignore:
Timestamp:
Jul 25, 2010, 3:07:42 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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
Children:
e2f3114
Parents:
0ff6b5
Message:

Add all possible versions of queries where the user is asked for multiples of the same.

  • Note that these are correctly implemented in TextUI and CommandLineUI, but not yet in QT4.
Location:
src/UIElements
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/CommandLineUI/CommandLineDialog.cpp

    r0ff6b5 r7cd6e7  
    5454}
    5555
     56void CommandLineDialog::queryInts(const char* title, string _description){
     57  registerQuery(new IntsCommandLineQuery(title, _description));
     58}
     59
    5660void CommandLineDialog::queryBoolean(const char* title, string _description){
    5761  registerQuery(new BooleanCommandLineQuery(title, _description));
     
    6266}
    6367
     68void CommandLineDialog::queryDoubles(const char* title, string _description){
     69  registerQuery(new DoublesCommandLineQuery(title, _description));
     70}
     71
    6472void CommandLineDialog::queryString(const char* title, string _description){
    6573  registerQuery(new StringCommandLineQuery(title, _description));
     
    7482}
    7583
     84void CommandLineDialog::queryAtoms(const char* title, string _description) {
     85  registerQuery(new AtomsCommandLineQuery(title, _description));
     86}
     87
    7688void CommandLineDialog::queryMolecule(const char* title, string _description) {
    7789  registerQuery(new MoleculeCommandLineQuery(title, _description));
    7890}
    7991
     92void CommandLineDialog::queryMolecules(const char* title, string _description) {
     93  registerQuery(new MoleculesCommandLineQuery(title, _description));
     94}
     95
    8096void CommandLineDialog::queryVector(const char* title, bool check, string _description) {
    8197  registerQuery(new VectorCommandLineQuery(title,check, _description));
    8298}
    8399
     100void CommandLineDialog::queryVectors(const char* title, bool check, string _description) {
     101  registerQuery(new VectorsCommandLineQuery(title,check, _description));
     102}
     103
    84104void CommandLineDialog::queryBox(const char* title, string _description) {
    85105  registerQuery(new BoxCommandLineQuery(title,_description));
     
    88108void CommandLineDialog::queryElement(const char* title, string _description){
    89109  registerQuery(new ElementCommandLineQuery(title, _description));
     110}
     111
     112void CommandLineDialog::queryElements(const char* title, string _description){
     113  registerQuery(new ElementsCommandLineQuery(title, _description));
    90114}
    91115
     
    119143}
    120144
     145CommandLineDialog::IntsCommandLineQuery::IntsCommandLineQuery(string title, string _description) :
     146    Dialog::IntsQuery(title, _description)
     147{}
     148
     149CommandLineDialog::IntsCommandLineQuery::~IntsCommandLineQuery() {}
     150
     151bool CommandLineDialog::IntsCommandLineQuery::handle() {
     152  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     153    tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
     154    return true;
     155  } else {
     156    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integers for " << getTitle() << "." << endl);
     157    return false;
     158  }
     159}
     160
    121161CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title, string _description) :
    122162    Dialog::BooleanQuery(title, _description)
     
    162202    return true;
    163203  } else {
    164     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
     204    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing strings for " << getTitle() << "." << endl);
    165205    return false;
    166206  }
     
    183223}
    184224
     225CommandLineDialog::DoublesCommandLineQuery::DoublesCommandLineQuery(string title, string _description) :
     226    Dialog::DoublesQuery(title, _description)
     227{}
     228
     229CommandLineDialog::DoublesCommandLineQuery::~DoublesCommandLineQuery() {}
     230
     231bool CommandLineDialog::DoublesCommandLineQuery::handle() {
     232  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     233    tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<double> >();
     234    return true;
     235  } else {
     236    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing doubles for " << getTitle() << "." << endl);
     237    return false;
     238  }
     239}
     240
    185241CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, string _description) :
    186242    Dialog::AtomQuery(title, _description)
     
    201257}
    202258
     259CommandLineDialog::AtomsCommandLineQuery::AtomsCommandLineQuery(string title, string _description) :
     260    Dialog::AtomsQuery(title, _description)
     261{}
     262
     263CommandLineDialog::AtomsCommandLineQuery::~AtomsCommandLineQuery() {}
     264
     265bool CommandLineDialog::AtomsCommandLineQuery::handle() {
     266  std::vector<int> IdxOfAtom;
     267  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     268    IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
     269    for (std::vector<int>::iterator iter = IdxOfAtom.begin(); iter != IdxOfAtom.end(); ++iter) {
     270      temp = World::getInstance().getAtom(AtomById(*iter));
     271      if (temp)
     272        tmp.push_back(temp);
     273    }
     274    return true;
     275  } else {
     276    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atoms for " << getTitle() << "." << endl);
     277    return false;
     278  }
     279}
     280
    203281CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, string _description) :
    204282    Dialog::MoleculeQuery(title, _description)
     
    211289  if (CommandLineParser::getInstance().vm.count(getTitle())) {
    212290    IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
    213     cout << "IdxOfMol " << IdxOfMol << endl;
    214     if (IdxOfMol >= 0)
    215       tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
    216     else
    217       tmp = NULL;
     291    tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
    218292    return true;
    219293  } else {
    220294    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl);
     295    return false;
     296  }
     297}
     298
     299CommandLineDialog::MoleculesCommandLineQuery::MoleculesCommandLineQuery(string title, string _description) :
     300    Dialog::MoleculesQuery(title, _description)
     301{}
     302
     303CommandLineDialog::MoleculesCommandLineQuery::~MoleculesCommandLineQuery() {}
     304
     305bool CommandLineDialog::MoleculesCommandLineQuery::handle() {
     306  std::vector<int> IdxOfMol;
     307  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     308    IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
     309    for (std::vector<int>::iterator iter = IdxOfMol.begin(); iter != IdxOfMol.end(); ++iter) {
     310      temp = World::getInstance().getMolecule(MoleculeById(*iter));
     311      if (temp)
     312        tmp.push_back(temp);
     313    }
     314    return true;
     315  } else {
     316    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecules for " << getTitle() << "." << endl);
    221317    return false;
    222318  }
     
    234330  if (CommandLineParser::getInstance().vm.count(getTitle())) {
    235331    temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
    236     tmp->at(0) = temp.x;
    237     tmp->at(1) = temp.y;
    238     tmp->at(2) = temp.z;
     332    tmp[0] = temp.x;
     333    tmp[1] = temp.y;
     334    tmp[2] = temp.z;
     335    if ((check) && (World::getInstance().getDomain().isInside(tmp))) {
     336      tmp.Zero();
     337      DoeLog(1) && (eLog() << Verbose(1) << "Vector " << tmp << " would be outside of box domain." << endl);
     338    }
    239339    return true;
    240340  } else {
     
    244344}
    245345
     346CommandLineDialog::VectorsCommandLineQuery::VectorsCommandLineQuery(string title, bool _check, string _description) :
     347    Dialog::VectorsQuery(title,_check, _description)
     348{}
     349
     350CommandLineDialog::VectorsCommandLineQuery::~VectorsCommandLineQuery()
     351{}
     352
     353bool CommandLineDialog::VectorsCommandLineQuery::handle() {
     354  std::vector<VectorValue> temporary;
     355  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     356    temporary = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<VectorValue> >();
     357    for(std::vector<VectorValue>::iterator iter = temporary.begin(); iter != temporary.end(); ++iter) {
     358      temp[0] = (*iter).x;
     359      temp[1] = (*iter).y;
     360      temp[2] = (*iter).z;
     361      if ((!check) || (World::getInstance().getDomain().isInside(temp)))
     362        tmp.push_back(temp);
     363      else
     364        DoeLog(1) && (eLog() << Verbose(1) << "Vector " << temp << " would be outside of box domain." << endl);
     365    }
     366    return true;
     367  } else {
     368    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vectors for " << getTitle() << "." << endl);
     369    return false;
     370  }
     371}
    246372
    247373CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, string _description) :
     
    279405  // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
    280406  periodentafel *periode = World::getInstance().getPeriode();
    281   element *elemental = NULL;
     407  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     408    int Z = CommandLineParser::getInstance().vm[getTitle()].as< int >();
     409    tmp = periode->FindElement(Z);
     410    ASSERT(tmp != NULL, "Invalid element specified in ElementCommandLineQuery");
     411    return true;
     412  } else {
     413    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl);
     414    return false;
     415  }
     416}
     417
     418CommandLineDialog::ElementsCommandLineQuery::ElementsCommandLineQuery(string title, string _description) :
     419    Dialog::ElementsQuery(title, _description)
     420{}
     421
     422CommandLineDialog::ElementsCommandLineQuery::~ElementsCommandLineQuery()
     423{}
     424
     425bool CommandLineDialog::ElementsCommandLineQuery::handle() {
     426  // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
     427  periodentafel *periode = World::getInstance().getPeriode();
    282428  if (CommandLineParser::getInstance().vm.count(getTitle())) {
    283429    vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
    284430    for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) {
    285       elemental = periode->FindElement(*ZRunner);
    286       ASSERT(elemental != NULL, "Invalid element specified in ElementCommandLineQuery");
    287       tmp.push_back(elemental);
     431      temp = periode->FindElement(*ZRunner);
     432      ASSERT(temp != NULL, "Invalid element specified in ElementCommandLineQuery");
     433      tmp.push_back(temp);
    288434    }
    289435    return true;
    290436  } else {
    291     DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl);
    292     return false;
    293   }
    294 }
     437    DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing elements for " << getTitle() << "." << endl);
     438    return false;
     439  }
     440}
  • src/UIElements/CommandLineUI/CommandLineDialog.hpp

    r0ff6b5 r7cd6e7  
    2929  virtual void queryEmpty(const char *, std::string = "");
    3030  virtual void queryInt(const char *, std::string = "");
     31  virtual void queryInts(const char *, std::string = "");
    3132  virtual void queryBoolean(const char *, std::string = "");
    3233  virtual void queryString(const char*, std::string = "");
    3334  virtual void queryStrings(const char*, std::string = "");
    3435  virtual void queryDouble(const char*, std::string = "");
     36  virtual void queryDoubles(const char*, std::string = "");
    3537  virtual void queryAtom(const char*, std::string = "");
     38  virtual void queryAtoms(const char*, std::string = "");
    3639  virtual void queryMolecule(const char*, std::string = "");
     40  virtual void queryMolecules(const char*, std::string = "");
    3741  virtual void queryVector(const char*, bool, std::string = "");
     42  virtual void queryVectors(const char*, bool, std::string = "");
    3843  virtual void queryBox(const char*, std::string = "");
    3944  virtual void queryElement(const char*, std::string = "");
     45  virtual void queryElements(const char*, std::string = "");
    4046
    4147protected:
     
    5561  };
    5662
     63  class IntsCommandLineQuery : public Dialog::IntsQuery {
     64  public:
     65    IntsCommandLineQuery(std::string title, std::string _description = "");
     66    virtual ~IntsCommandLineQuery();
     67    virtual bool handle();
     68  };
     69
    5770  class BooleanCommandLineQuery : public Dialog::BooleanQuery {
    5871  public:
     
    6679    DoubleCommandLineQuery(std::string title, std::string _description = "");
    6780    virtual ~DoubleCommandLineQuery();
     81    virtual bool handle();
     82  };
     83
     84  class DoublesCommandLineQuery : public Dialog::DoublesQuery {
     85  public:
     86    DoublesCommandLineQuery(std::string title, std::string _description = "");
     87    virtual ~DoublesCommandLineQuery();
    6888    virtual bool handle();
    6989  };
     
    90110  };
    91111
     112  class AtomsCommandLineQuery : public Dialog::AtomsQuery {
     113  public:
     114    AtomsCommandLineQuery(std::string title, std::string _description = "");
     115    virtual ~AtomsCommandLineQuery();
     116    virtual bool handle();
     117  };
     118
    92119  class MoleculeCommandLineQuery : public Dialog::MoleculeQuery {
    93120  public:
     
    97124  };
    98125
     126  class MoleculesCommandLineQuery : public Dialog::MoleculesQuery {
     127  public:
     128    MoleculesCommandLineQuery(std::string title, std::string _description = "");
     129    virtual ~MoleculesCommandLineQuery();
     130    virtual bool handle();
     131  };
     132
    99133  class VectorCommandLineQuery : public Dialog::VectorQuery {
    100134  public:
    101135    VectorCommandLineQuery(std::string title,bool _check, std::string _description = "");
    102136    virtual ~VectorCommandLineQuery();
     137    virtual bool handle();
     138  };
     139
     140  class VectorsCommandLineQuery : public Dialog::VectorsQuery {
     141  public:
     142    VectorsCommandLineQuery(std::string title,bool _check, std::string _description = "");
     143    virtual ~VectorsCommandLineQuery();
    103144    virtual bool handle();
    104145  };
     
    117158    virtual bool handle();
    118159  };
     160
     161  class ElementsCommandLineQuery : public Dialog::ElementsQuery {
     162  public:
     163    ElementsCommandLineQuery(std::string title, std::string _description = "");
     164    virtual ~ElementsCommandLineQuery();
     165    virtual bool handle();
     166  };
    119167};
    120168
  • src/UIElements/Dialog.cpp

    r0ff6b5 r7cd6e7  
    108108}
    109109
    110 // Int Queries
     110// Ints Queries
     111
     112Dialog::IntsQuery::IntsQuery(string title, std::string description) :
     113    Query(title, description)
     114{}
     115
     116Dialog::IntsQuery::~IntsQuery() {}
     117
     118void Dialog::IntsQuery::setResult() {
     119  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     120}
     121
     122// Bool Queries
    111123
    112124Dialog::BooleanQuery::BooleanQuery(string title,std::string description) :
     
    153165
    154166void Dialog::DoubleQuery::setResult() {
     167  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     168}
     169
     170// Doubles Queries
     171
     172Dialog::DoublesQuery::DoublesQuery(string title, std::string _description) :
     173    Query(title, _description)
     174{}
     175
     176Dialog::DoublesQuery::~DoublesQuery() {};
     177
     178void Dialog::DoublesQuery::setResult() {
    155179  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    156180}
     
    170194}
    171195
     196// Atoms Queries
     197
     198Dialog::AtomsQuery::AtomsQuery(string title, std::string _description) :
     199    Query(title, _description),
     200    tmp(0)
     201{}
     202
     203Dialog::AtomsQuery::~AtomsQuery() {}
     204
     205void Dialog::AtomsQuery::setResult() {
     206  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     207}
     208
    172209// Molecule Queries
    173210
     
    183220}
    184221
     222// Molecules Queries
     223
     224Dialog::MoleculesQuery::MoleculesQuery(string title, std::string _description) :
     225    Query(title, _description),
     226    tmp(0)
     227{}
     228
     229Dialog::MoleculesQuery::~MoleculesQuery() {}
     230
     231void Dialog::MoleculesQuery::setResult() {
     232  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     233}
     234
    185235// Vector Queries
    186236
     
    188238  Query(title, _description),
    189239  check(_check)
    190 {
    191   tmp = new Vector();
    192 }
     240{}
    193241
    194242Dialog::VectorQuery::~VectorQuery()
    195 {
    196   delete tmp;
    197 }
     243{}
    198244
    199245void Dialog::VectorQuery::setResult() {
     246  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
     247}
     248
     249// Vectors Queries
     250
     251Dialog::VectorsQuery::VectorsQuery(std::string title,bool _check, std::string _description) :
     252  Query(title, _description),
     253  check(_check)
     254{}
     255
     256Dialog::VectorsQuery::~VectorsQuery()
     257{}
     258
     259void Dialog::VectorsQuery::setResult() {
    200260  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    201261}
     
    228288  ValueStorage::getInstance().setCurrentValue(title.c_str(), tmp);
    229289}
     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}
  • src/UIElements/Dialog.hpp

    r0ff6b5 r7cd6e7  
    1313#include<vector>
    1414
     15#include "vector.hpp"
     16
    1517class atom;
    1618class Box;
    1719class element;
    1820class molecule;
    19 class Vector;
    2021
    2122
     
    3940  virtual void queryBoolean(const char *, std::string = "")=0;
    4041  virtual void queryInt(const char *, std::string = "")=0;
     42  virtual void queryInts(const char *, std::string = "")=0;
    4143  virtual void queryDouble(const char*, std::string = "")=0;
     44  virtual void queryDoubles(const char*, std::string = "")=0;
    4245  virtual void queryString(const char*, std::string = "")=0;
    4346  virtual void queryStrings(const char*, std::string = "")=0;
    4447  virtual void queryAtom(const char*,std::string = "")=0;
     48  virtual void queryAtoms(const char*,std::string = "")=0;
    4549  virtual void queryMolecule(const char*, std::string = "")=0;
     50  virtual void queryMolecules(const char*, std::string = "")=0;
    4651  virtual void queryVector(const char*,bool, std::string = "")=0;
     52  virtual void queryVectors(const char*,bool, std::string = "")=0;
    4753  virtual void queryBox(const char*, std::string = "")=0;
    4854  virtual void queryElement(const char*, std::string = "")=0;
     55  virtual void queryElements(const char*, std::string = "")=0;
    4956
    5057  virtual bool display();
     
    110117  };
    111118
     119  class IntsQuery : public Query {
     120  public:
     121    IntsQuery(std::string title, std::string _description = "");
     122    virtual ~IntsQuery();
     123    virtual bool handle()=0;
     124    virtual void setResult();
     125  protected:
     126    int temp;
     127    std::vector<int> tmp;
     128  };
     129
    112130  class DoubleQuery : public Query {
    113131  public:
     
    120138  };
    121139
     140  class DoublesQuery : public Query {
     141  public:
     142    DoublesQuery(std::string title, std::string _description = "");
     143    virtual ~DoublesQuery();
     144    virtual bool handle()=0;
     145    virtual void setResult();
     146  protected:
     147    double temp;
     148    std::vector<double> tmp;
     149  };
     150
    122151  class StringQuery : public Query {
    123152  public:
     
    151180  };
    152181
     182  class MoleculesQuery : public Query {
     183  public:
     184    MoleculesQuery(std::string title, std::string _description = "");
     185    virtual ~MoleculesQuery();
     186    virtual bool handle()=0;
     187    virtual void setResult();
     188  protected:
     189    molecule * temp;
     190    std::vector<molecule *> tmp;
     191  };
     192
    153193  class AtomQuery : public Query {
    154194  public:
     
    159199  protected:
    160200    atom *tmp;
     201  };
     202
     203  class AtomsQuery : public Query {
     204  public:
     205    AtomsQuery(std::string title, std::string _description = "");
     206    virtual ~AtomsQuery();
     207    virtual bool handle()=0;
     208    virtual void setResult();
     209  protected:
     210    atom *temp;
     211    std::vector<atom *> tmp;
    161212  };
    162213
     
    168219      virtual void setResult();
    169220    protected:
    170       Vector *tmp;
     221      Vector tmp;
     222      bool check;
     223  };
     224
     225  class VectorsQuery : public Query {
     226  public:
     227      VectorsQuery(std::string title,bool _check, std::string _description = "");
     228      virtual ~VectorsQuery();
     229      virtual bool handle()=0;
     230      virtual void setResult();
     231    protected:
     232      Vector temp;
     233      std::vector<Vector> tmp;
    171234      bool check;
    172235  };
     
    189252    virtual void setResult();
    190253  protected:
     254    element * tmp;
     255  };
     256
     257  class ElementsQuery : public Query {
     258  public:
     259    ElementsQuery(std::string title, std::string _description = "");
     260    virtual ~ElementsQuery();
     261    virtual bool handle()=0;
     262    virtual void setResult();
     263  protected:
     264    element *temp;
    191265    std::vector<element *> tmp;
    192266  };
  • src/UIElements/QT4/QTDialog.cpp

    r0ff6b5 r7cd6e7  
    1717#include <QtGui/QDoubleSpinBox>
    1818#include <Qt/qlineedit.h>
     19#include <Qt/qlistwidget.h>
    1920#include <Qt/qdialogbuttonbox.h>
    2021#include <Qt/qpushbutton.h>
     
    2829#include "element.hpp"
    2930#include "molecule.hpp"
     31#include "Descriptors/AtomIdDescriptor.hpp"
    3032#include "Descriptors/MoleculeIdDescriptor.hpp"
    3133#include "Matrix.hpp"
     
    9597}
    9698
     99void QTDialog::queryAtoms(char const*, string){
     100  // TODO
     101  ASSERT(false, "Not implemented yet");
     102}
     103
    97104void QTDialog::queryBox(char const*, string){
    98105  // TODO
     
    106113}
    107114
     115void QTDialog::queryInts(const char *title,string)
     116{
     117  registerQuery(new IntsQTQuery(title,inputLayout,this));
     118}
     119
    108120void QTDialog::queryDouble(const char* title,string){
    109121  registerQuery(new DoubleQTQuery(title,inputLayout,this));
    110122}
    111123
     124void QTDialog::queryDoubles(const char* title,string){
     125  registerQuery(new DoublesQTQuery(title,inputLayout,this));
     126}
     127
    112128void QTDialog::queryString(const char* title,string)
    113129{
     
    123139{
    124140  registerQuery(new MoleculeQTQuery(title,inputLayout,this));
     141}
     142
     143void QTDialog::queryMolecules(const char *title,string)
     144{
     145  // TODO
     146  ASSERT(false, "Not implemented yet");
    125147}
    126148
     
    129151}
    130152
     153void QTDialog::queryVectors(const char* title, bool check,string) {
     154  // TODO
     155  ASSERT(false, "Not implemented yet");
     156}
     157
    131158void QTDialog::queryElement(const char* title, string){
    132159  registerQuery(new ElementQTQuery(title,inputLayout,this));
     160}
     161
     162void QTDialog::queryElements(const char* title, string){
     163  // TODO
     164  ASSERT(false, "Not implemented yet");
    133165}
    134166
     
    157189}
    158190
    159 // Handling is easy since the GUI makes it impossible to enter invalid values
    160 bool QTDialog::IntQTQuery::handle()
    161 {
    162   return true;
    163 }
     191bool QTDialog::IntQTQuery::handle() {
     192  return true;
     193}
     194
     195
     196QTDialog::IntsQTQuery::IntsQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
     197    Dialog::IntsQuery(_title),
     198    parent(_parent)
     199{
     200  QHBoxLayout * thisHLayout = new QHBoxLayout();
     201  QVBoxLayout * thisV1Layout = new QVBoxLayout();
     202  QVBoxLayout * thisV2Layout = new QVBoxLayout();
     203
     204  QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
     205  QLabel *inputLabel = new QLabel("Enter to add");
     206  QListWidget* inputList = new QListWidget();
     207  inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
     208  QLineEdit* inputBox = new QLineEdit();
     209  inputLabel->setBuddy(inputBox);
     210  titleLabel->setBuddy(inputList);
     211  QPushButton* AddButton = new QPushButton("Add");
     212  AddButton->setEnabled(false);
     213  QPushButton* RemoveButton = new QPushButton("Remove");
     214  RemoveButton->setEnabled(false);
     215
     216  thisV1Layout->addWidget(titleLabel);
     217  thisV1Layout->addWidget(inputList);
     218  thisV2Layout->addWidget(inputLabel);
     219  thisV2Layout->addWidget(inputBox);
     220  thisV2Layout->addWidget(AddButton);
     221  thisV2Layout->addWidget(RemoveButton);
     222  parent->addLayout(thisHLayout);
     223  thisHLayout->addLayout(thisV1Layout);
     224  thisHLayout->addLayout(thisV2Layout);
     225
     226  pipe = new QTQueryListPipe<int>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
     227  connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
     228  connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
     229  connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
     230  connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));
     231}
     232
     233QTDialog::IntsQTQuery::~IntsQTQuery()
     234{
     235  delete pipe;
     236}
     237
     238bool QTDialog::IntsQTQuery::handle() {
     239  return true;
     240}
     241
    164242
    165243QTDialog::DoubleQTQuery::DoubleQTQuery(string title,QBoxLayout *_parent,QTDialog *_dialog) :
     
    192270
    193271
     272QTDialog::DoublesQTQuery::DoublesQTQuery(string title,QBoxLayout *_parent,QTDialog *_dialog) :
     273    Dialog::DoublesQuery(title),
     274    parent(_parent)
     275{
     276  QHBoxLayout * thisHLayout = new QHBoxLayout();
     277  QVBoxLayout * thisV1Layout = new QVBoxLayout();
     278  QVBoxLayout * thisV2Layout = new QVBoxLayout();
     279
     280  QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
     281  QLabel *inputLabel = new QLabel("Enter to add");
     282  QListWidget* inputList = new QListWidget();
     283  inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
     284  QLineEdit* inputBox = new QLineEdit();
     285  inputLabel->setBuddy(inputBox);
     286  titleLabel->setBuddy(inputList);
     287  QPushButton* AddButton = new QPushButton("Add");
     288  AddButton->setEnabled(false);
     289  QPushButton* RemoveButton = new QPushButton("Remove");
     290  RemoveButton->setEnabled(false);
     291
     292  thisV1Layout->addWidget(titleLabel);
     293  thisV1Layout->addWidget(inputList);
     294  thisV2Layout->addWidget(inputLabel);
     295  thisV2Layout->addWidget(inputBox);
     296  thisV2Layout->addWidget(AddButton);
     297  thisV2Layout->addWidget(RemoveButton);
     298  parent->addLayout(thisHLayout);
     299  thisHLayout->addLayout(thisV1Layout);
     300  thisHLayout->addLayout(thisV2Layout);
     301
     302  pipe = new QTQueryListPipe<double>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
     303  connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
     304  connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
     305  connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
     306  connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
     307
     308QTDialog::DoublesQTQuery::~DoublesQTQuery()
     309{
     310  delete pipe;
     311}
     312
     313bool QTDialog::DoublesQTQuery::handle() {
     314  return true;
     315}
     316
     317
    194318QTDialog::StringQTQuery::StringQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
    195319    Dialog::StringQuery(_title),
     
    223347    parent(_parent)
    224348{
    225   thisLayout = new QHBoxLayout();
    226   titleLabel = new QLabel(QString(getTitle().c_str()));
    227   inputBox = new QLineEdit();
    228   parent->addLayout(thisLayout);
    229   thisLayout->addWidget(titleLabel);
    230   thisLayout->addWidget(inputBox);
    231 
    232   pipe = new StringQTQueryPipe(&temp,_dialog);
    233   pipe->update(inputBox->text());
    234   connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
    235 }
     349  QHBoxLayout * thisHLayout = new QHBoxLayout();
     350  QVBoxLayout * thisV1Layout = new QVBoxLayout();
     351  QVBoxLayout * thisV2Layout = new QVBoxLayout();
     352
     353  QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
     354  QLabel *inputLabel = new QLabel("Enter to add");
     355  QListWidget* inputList = new QListWidget();
     356  inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
     357  QLineEdit* inputBox = new QLineEdit();
     358  inputLabel->setBuddy(inputBox);
     359  titleLabel->setBuddy(inputList);
     360  QPushButton* AddButton = new QPushButton("Add");
     361  AddButton->setEnabled(false);
     362  QPushButton* RemoveButton = new QPushButton("Remove");
     363  RemoveButton->setEnabled(false);
     364
     365  thisV1Layout->addWidget(titleLabel);
     366  thisV1Layout->addWidget(inputList);
     367  thisV2Layout->addWidget(inputLabel);
     368  thisV2Layout->addWidget(inputBox);
     369  thisV2Layout->addWidget(AddButton);
     370  thisV2Layout->addWidget(RemoveButton);
     371  parent->addLayout(thisHLayout);
     372  thisHLayout->addLayout(thisV1Layout);
     373  thisHLayout->addLayout(thisV2Layout);
     374
     375  pipe = new QTQueryListPipe<std::string>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
     376  connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
     377  connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
     378  connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
     379  connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
    236380
    237381QTDialog::StringsQTQuery::~StringsQTQuery()
     
    293437}
    294438
     439QTDialog::MoleculesQTQuery::MoleculesQTQuery(string _title, QBoxLayout *_parent,QTDialog *_dialog) :
     440    Dialog::MoleculesQuery(_title),
     441    parent(_parent)
     442{
     443  thisLayout = new QHBoxLayout();
     444  titleLabel = new QLabel(QString(getTitle().c_str()));
     445  inputBox = new QComboBox();
     446  // add all molecules to the combo box
     447  vector<molecule*> molecules = World::getInstance().getAllMolecules();
     448  for(vector<molecule*>::iterator iter  = molecules.begin();
     449      iter != molecules.end();
     450      ++iter) {
     451    stringstream sstr;
     452    sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
     453    inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
     454  }
     455  parent->addLayout(thisLayout);
     456  thisLayout->addWidget(titleLabel);
     457  thisLayout->addWidget(inputBox);
     458
     459  pipe = new MoleculesQTQueryPipe(&tmp,_dialog,inputBox);
     460  pipe->update(inputBox->currentIndex());
     461  connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
     462}
     463
     464QTDialog::MoleculesQTQuery::~MoleculesQTQuery()
     465{
     466  delete pipe;
     467}
     468
     469// Handling is easy, since the GUI makes it impossible to select invalid values
     470bool QTDialog::MoleculesQTQuery::handle()
     471{
     472  return true;
     473}
     474
    295475QTDialog::VectorQTQuery::VectorQTQuery(std::string title, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
    296476    Dialog::VectorQuery(title,_check),
     
    304484  subLayout = new QVBoxLayout();
    305485  mainLayout->addLayout(subLayout);
    306   for(int i=0; i<3; i++) {
    307     coordLayout[i] = new QHBoxLayout();
    308     subLayout->addLayout(coordLayout[i]);
    309     coordLabel[i] = new QLabel(QString(coords[i]));
    310     coordLayout[i]->addWidget(coordLabel[i]);
    311     coordInput[i] = new QDoubleSpinBox();
    312     coordInput[i]->setRange(0,M.at(i,i));
    313     coordInput[i]->setDecimals(3);
    314     coordLayout[i]->addWidget(coordInput[i]);
    315     pipe[i] = new DoubleQTQueryPipe(&((*tmp)[i]),_dialog);
    316     pipe[i]->update(coordInput[i]->value());
    317     connect(coordInput[i],SIGNAL(valueChanged(double)),pipe[i],SLOT(update(double)));
    318 
    319   }
     486  QComboBox* inputBox = new QComboBox();
     487  coordLayout = new QHBoxLayout();
     488  subLayout->addLayout(coordLayout);
     489  coordLabel = new QLabel(QString("x,y,z"));
     490  coordLayout->addWidget(coordLabel);
     491  coordInput = new QDoubleSpinBox();
     492//  coordInput->setRange(0,M.at(i,i));
     493  coordInput->setDecimals(3);
     494  coordLayout->addWidget(coordInput);
     495  pipe = new VectorQTQueryPipe(&(tmp),_dialog,inputBox);
     496  //pipe->update(coordInput->value());
     497  connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
    320498  parent->addLayout(mainLayout);
    321499}
     
    325503
    326504bool QTDialog::VectorQTQuery::handle() {
     505  return true;
     506}
     507
     508
     509QTDialog::VectorsQTQuery::VectorsQTQuery(std::string title, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
     510    Dialog::VectorsQuery(title,_check),
     511    parent(_parent)
     512{
     513  const Matrix& M = World::getInstance().getDomain().getM();
     514  const char *coords[3] = {"x:","y:","z:"};
     515  mainLayout= new QHBoxLayout();
     516  titleLabel = new QLabel(QString(getTitle().c_str()));
     517  mainLayout->addWidget(titleLabel);
     518  subLayout = new QVBoxLayout();
     519  mainLayout->addLayout(subLayout);
     520  QComboBox* inputBox = new QComboBox();
     521  coordLayout = new QHBoxLayout();
     522  subLayout->addLayout(coordLayout);
     523  coordLabel = new QLabel(QString("x,y,z"));
     524  coordLayout->addWidget(coordLabel);
     525  coordInput = new QDoubleSpinBox();
     526//  coordInput->setRange(0,M.at(i,i));
     527  coordInput->setDecimals(3);
     528  coordLayout->addWidget(coordInput);
     529  pipe = new VectorsQTQueryPipe(&(tmp),_dialog,inputBox);
     530  //pipe->update(coordInput->value());
     531  connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
     532  parent->addLayout(mainLayout);
     533}
     534
     535QTDialog::VectorsQTQuery::~VectorsQTQuery()
     536{}
     537
     538bool QTDialog::VectorsQTQuery::handle() {
    327539  return true;
    328540}
     
    363575}
    364576
     577
     578QTDialog::ElementsQTQuery::ElementsQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
     579    Dialog::ElementsQuery(_title),
     580    parent(_parent)
     581{
     582  periodentafel *periode = World::getInstance().getPeriode();
     583  thisLayout = new QHBoxLayout();
     584  titleLabel = new QLabel(QString(getTitle().c_str()));
     585  inputBox = new QComboBox();
     586  for(periodentafel::const_iterator iter = periode->begin();
     587      iter!=periode->end();
     588      ++iter)
     589  {
     590    stringstream sstr;
     591    sstr << (*iter).first << "\t" << (*iter).second->name;
     592    inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
     593  }
     594  parent->addLayout(thisLayout);
     595  thisLayout->addWidget(titleLabel);
     596  thisLayout->addWidget(inputBox);
     597
     598  pipe = new ElementsQTQueryPipe(&tmp,_dialog,inputBox);
     599  pipe->update(inputBox->currentIndex());
     600  connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
     601}
     602
     603QTDialog::ElementsQTQuery::~ElementsQTQuery()
     604{
     605  delete pipe;
     606}
     607
     608bool QTDialog::ElementsQTQuery::handle(){
     609  return true;
     610}
     611
    365612/*************************** Plumbing *******************************/
     613
     614
     615template<typename T> QTQueryListPipe<T>::QTQueryListPipe(std::vector<T> *_content, QTDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) :
     616  content(_content),
     617  dialog(_dialog),
     618  inputBox(_inputBox),
     619  inputList(_inputList),
     620  AddButton(_AddButton),
     621  RemoveButton(_RemoveButton)
     622{}
     623
     624template<typename T> QTQueryListPipe<T>::~QTQueryListPipe()
     625{}
     626
     627template<typename T> void QTQueryListPipe<T>::IntegerEntered(const QString&)
     628{
     629  AddButton->setEnabled(true);
     630}
     631
     632template<typename T> void QTQueryListPipe<T>::IntegerSelected()
     633{
     634  if (inputList->selectedItems().empty())
     635    RemoveButton->setEnabled(false);
     636  else
     637    RemoveButton->setEnabled(true);
     638}
     639
     640template<typename T> void QTQueryListPipe<T>::AddInteger() {
     641  // type-check
     642  std::string text = inputBox->text().toStdString();
     643  int number = 0;
     644  try {
     645    number = boost::lexical_cast<int>(text);
     646  } catch (boost::bad_lexical_cast&) {
     647    return;
     648  };
     649  // add item to both
     650  inputList->addItem(QString(number));
     651  AddValue(number);
     652}
     653
     654template<typename T> void QTQueryListPipe<T>::AddValue(T item) {
     655  content->push_back(item);
     656
     657  dialog->update();
     658}
     659
     660template<typename T> void QTQueryListPipe<T>::RemoveInteger() {
     661  QList<QListWidgetItem *> items = inputList->selectedItems();
     662  for (QList<QListWidgetItem *>::iterator iter = items.begin(); !items.empty(); iter = items.begin()) {
     663    // obtain which position item has (by making it current item)
     664    inputList->setCurrentItem(*iter);
     665    // remove
     666    QTQueryListPipe<T>::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call
     667    inputList->removeItemWidget(*iter);
     668  }
     669}
     670
     671template<typename T> void QTQueryListPipe<T>::RemoveRow(int row) {
     672  int counter = 0;
     673  typename std::vector<T>::iterator iter = content->begin();
     674  for (; iter != content->end(); ++iter)
     675    if (counter++ == row)
     676      break;
     677  if (iter != content->end())
     678      content->erase(iter);
     679}
     680
    366681
    367682StringQTQueryPipe::StringQTQueryPipe(string *_content, QTDialog *_dialog) :
     
    403718  dialog->update();
    404719}
     720
     721VectorQTQueryPipe::VectorQTQueryPipe(Vector *_content, QTDialog *_dialog, QComboBox *_theBox) :
     722  content(_content),
     723  dialog(_dialog),
     724  theBox(_theBox)
     725{}
     726
     727VectorQTQueryPipe::~VectorQTQueryPipe()
     728{}
     729
     730void VectorQTQueryPipe::update() {
     731  dialog->update();
     732}
     733
     734VectorsQTQueryPipe::VectorsQTQueryPipe(std::vector<Vector> *_content, QTDialog *_dialog, QComboBox *_theBox) :
     735  content(_content),
     736  dialog(_dialog),
     737  theBox(_theBox)
     738{}
     739
     740VectorsQTQueryPipe::~VectorsQTQueryPipe()
     741{}
     742
     743void VectorsQTQueryPipe::update() {
     744  dialog->update();
     745}
     746
     747AtomQTQueryPipe::AtomQTQueryPipe(atom **_content, QTDialog *_dialog, QComboBox *_theBox) :
     748  content(_content),
     749  dialog(_dialog),
     750  theBox(_theBox)
     751{}
     752
     753AtomQTQueryPipe::~AtomQTQueryPipe()
     754{}
     755
     756void AtomQTQueryPipe::update(int newIndex) {
     757  QVariant data = theBox->itemData(newIndex);
     758  int idx = data.toInt();
     759  (*content) = World::getInstance().getAtom(AtomById(idx));
     760  dialog->update();
     761}
     762
     763
     764AtomsQTQueryPipe::AtomsQTQueryPipe(std::vector<atom *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
     765  content(_content),
     766  dialog(_dialog),
     767  theBox(_theBox)
     768{}
     769
     770AtomsQTQueryPipe::~AtomsQTQueryPipe()
     771{}
     772
     773void AtomsQTQueryPipe::update(int newIndex) {
     774  QVariant data = theBox->itemData(newIndex);
     775  int idx = data.toInt();
     776  atom *Walker = World::getInstance().getAtom(AtomById(idx));
     777  if (Walker)
     778    (*content).push_back(Walker) ;
     779  dialog->update();
     780}
     781
    405782
    406783MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox) :
     
    420797}
    421798
    422 ElementQTQueryPipe::ElementQTQueryPipe(std::vector<element *> *_content, QTDialog *_dialog, QComboBox *_theBox) :
     799
     800MoleculesQTQueryPipe::MoleculesQTQueryPipe(std::vector<molecule *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
    423801  content(_content),
    424802  dialog(_dialog),
    425803  theBox(_theBox)
    426 {
    427   content->resize(1);
    428 }
     804{}
     805
     806MoleculesQTQueryPipe::~MoleculesQTQueryPipe()
     807{}
     808
     809void MoleculesQTQueryPipe::update(int newIndex) {
     810  QVariant data = theBox->itemData(newIndex);
     811  int idx = data.toInt();
     812  molecule *mol = World::getInstance().getMolecule(MoleculeById(idx));
     813  if (mol)
     814    (*content).push_back(mol);
     815  dialog->update();
     816}
     817
     818ElementQTQueryPipe::ElementQTQueryPipe(element **_content, QTDialog *_dialog, QComboBox *_theBox) :
     819  content(_content),
     820  dialog(_dialog),
     821  theBox(_theBox)
     822{}
    429823
    430824ElementQTQueryPipe::~ElementQTQueryPipe()
     
    434828  QVariant data = theBox->itemData(newIndex);
    435829  int idx = data.toInt();
    436   (*content)[0] = World::getInstance().getPeriode()->FindElement(idx);
    437   dialog->update();
    438 }
    439 
     830  *content = World::getInstance().getPeriode()->FindElement(idx);
     831  dialog->update();
     832}
     833
     834ElementsQTQueryPipe::ElementsQTQueryPipe(std::vector<element *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
     835  content(_content),
     836  dialog(_dialog),
     837  theBox(_theBox)
     838{}
     839
     840ElementsQTQueryPipe::~ElementsQTQueryPipe()
     841{}
     842
     843void ElementsQTQueryPipe::update(int newIndex) {
     844  QVariant data = theBox->itemData(newIndex);
     845  int idx = data.toInt();
     846  element *elemental = World::getInstance().getPeriode()->FindElement(idx);
     847  if(elemental)
     848    (*content).push_back(elemental);
     849  dialog->update();
     850}
     851
     852
  • src/UIElements/QT4/QTDialog.hpp

    r0ff6b5 r7cd6e7  
    1717class QDoubleSpinBox;
    1818class QLineEdit;
     19class QListWidget;
    1920class QComboBox;
    2021class QDialogButtonBox;
     
    2223
    2324// Forward declarations for plumbing
     25template<typename T> class QTQueryListPipe;
    2426class StringQTQueryPipe;
     27class StringsQTQueryPipe;
    2528class IntQTQueryPipe;
    2629class DoubleQTQueryPipe;
     30class DoublesQTQueryPipe;
     31class AtomQTQueryPipe;
     32class AtomsQTQueryPipe;
    2733class MoleculeQTQueryPipe;
     34class MoleculesQTQueryPipe;
    2835class ElementQTQueryPipe;
     36class ElementsQTQueryPipe;
     37class VectorQTQueryPipe;
     38class VectorsQTQueryPipe;
    2939
    3040class QTDialog : public QDialog, public Dialog
     
    3848  virtual void queryBoolean(const char *, std::string = "");
    3949  virtual void queryInt(const char *,std::string = "");
     50  virtual void queryInts(const char *,std::string = "");
    4051  virtual void queryDouble(const char*,std::string = "");
     52  virtual void queryDoubles(const char*,std::string = "");
    4153  virtual void queryString(const char*,std::string = "");
    4254  virtual void queryStrings(const char*,std::string = "");
    4355  virtual void queryAtom(const char*,std::string = "");
     56  virtual void queryAtoms(const char*,std::string = "");
    4457  virtual void queryMolecule(const char*,std::string = "");
     58  virtual void queryMolecules(const char*,std::string = "");
    4559  virtual void queryVector(const char*,bool,std::string = "");
     60  virtual void queryVectors(const char*,bool,std::string = "");
    4661  virtual void queryBox(const char*, std::string = "");
    4762  virtual void queryElement(const char*,std::string = "");
     63  virtual void queryElements(const char*,std::string = "");
    4864
    4965  virtual bool display();
     
    6682    };
    6783
     84  class IntsQTQuery : public Dialog::IntsQuery {
     85    public:
     86      IntsQTQuery(std::string _title,QBoxLayout *_parent,QTDialog *_dialog);
     87      virtual ~IntsQTQuery();
     88      virtual bool handle();
     89      void IntegerEntered(const QString&);
     90      void IntegerSelected();
     91      void AddInteger();
     92      void RemoveInteger();
     93    private:
     94      QBoxLayout *parent;
     95      QBoxLayout *thisLayout;
     96      QLabel *titleLabel;
     97
     98      QTQueryListPipe<int> *pipe;
     99    };
     100
    68101    class DoubleQTQuery : public Dialog::DoubleQuery {
    69102    public:
     
    80113    };
    81114
     115    class DoublesQTQuery : public Dialog::DoublesQuery {
     116    public:
     117      DoublesQTQuery(std::string title,QBoxLayout *_parent,QTDialog *_dialog);
     118      virtual ~DoublesQTQuery();
     119      virtual bool handle();
     120    private:
     121      QBoxLayout *parent;
     122      QBoxLayout *thisLayout;
     123      QLabel *titleLabel;
     124      QDoubleSpinBox *inputBox;
     125
     126      QTQueryListPipe<double> *pipe;
     127    };
     128
    82129    class StringQTQuery : public Dialog::StringQuery {
    83130    public:
     
    105152      QLineEdit *inputBox;
    106153
    107       StringQTQueryPipe *pipe;
     154      QTQueryListPipe<std::string> *pipe;
     155    };
     156
     157    class AtomQTQuery : public Dialog::AtomQuery {
     158    public:
     159      AtomQTQuery(std::string _title, QBoxLayout *_parent,QTDialog *_dialog);
     160      virtual ~AtomQTQuery();
     161      virtual bool handle();
     162    private:
     163      QBoxLayout *parent;
     164      QBoxLayout *thisLayout;
     165      QLabel *titleLabel;
     166      QComboBox *inputBox;
     167
     168      AtomQTQueryPipe *pipe;
     169    };
     170
     171    class AtomsQTQuery : public Dialog::AtomsQuery {
     172    public:
     173      AtomsQTQuery(std::string _title, QBoxLayout *_parent,QTDialog *_dialog);
     174      virtual ~AtomsQTQuery();
     175      virtual bool handle();
     176    private:
     177      QBoxLayout *parent;
     178      QBoxLayout *thisLayout;
     179      QLabel *titleLabel;
     180      QComboBox *inputBox;
     181
     182      AtomsQTQueryPipe *pipe;
    108183    };
    109184
     
    122197    };
    123198
     199    class MoleculesQTQuery : public Dialog::MoleculesQuery {
     200    public:
     201      MoleculesQTQuery(std::string _title, QBoxLayout *_parent,QTDialog *_dialog);
     202      virtual ~MoleculesQTQuery();
     203      virtual bool handle();
     204    private:
     205      QBoxLayout *parent;
     206      QBoxLayout *thisLayout;
     207      QLabel *titleLabel;
     208      QComboBox *inputBox;
     209
     210      MoleculesQTQueryPipe *pipe;
     211    };
     212
    124213    class VectorQTQuery : public Dialog::VectorQuery {
    125214    public:
     
    132221      QLabel *titleLabel;
    133222      QBoxLayout *subLayout;
    134       QBoxLayout *coordLayout[3];
    135       QLabel *coordLabel[3];
    136       QDoubleSpinBox *coordInput[3];
    137 
    138       DoubleQTQueryPipe *pipe[3];
     223      QBoxLayout *coordLayout;
     224      QLabel *coordLabel;
     225      QDoubleSpinBox *coordInput;
     226
     227      VectorQTQueryPipe *pipe;
     228    };
     229
     230    class VectorsQTQuery : public Dialog::VectorsQuery {
     231    public:
     232      VectorsQTQuery(std::string title,bool _check,QBoxLayout *,QTDialog *);
     233      virtual ~VectorsQTQuery();
     234      virtual bool handle();
     235    private:
     236      QBoxLayout *parent;
     237      QBoxLayout *mainLayout;
     238      QLabel *titleLabel;
     239      QBoxLayout *subLayout;
     240      QBoxLayout *coordLayout;
     241      QLabel *coordLabel;
     242      QDoubleSpinBox *coordInput;
     243
     244      VectorsQTQueryPipe *pipe;
    139245    };
    140246
     
    151257
    152258      ElementQTQueryPipe *pipe;
     259    };
     260
     261    class ElementsQTQuery : public Dialog::ElementsQuery {
     262    public:
     263      ElementsQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog);
     264      virtual ~ElementsQTQuery();
     265      virtual bool handle();
     266    private:
     267      QBoxLayout *parent;
     268      QBoxLayout *thisLayout;
     269      QLabel *titleLabel;
     270      QComboBox *inputBox;
     271
     272      ElementsQTQueryPipe *pipe;
    153273    };
    154274
     
    164284// since MOC doesn't like nested classes
    165285
     286
     287template<typename T> class QTQueryListPipe : public QWidget {
     288  public:
     289    QTQueryListPipe(std::vector<T> *_content, QTDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton);
     290    virtual ~QTQueryListPipe();
     291    void AddInteger();
     292    void RemoveInteger();
     293    void IntegerSelected();
     294    void IntegerEntered(const QString&);
     295
     296  private:
     297    void AddValue(T item);
     298    void RemoveRow(int row);
     299
     300    std::vector<T> *content;
     301    QTDialog *dialog;
     302    QLineEdit *inputBox;
     303    QListWidget *inputList;
     304    QPushButton *AddButton;
     305    QPushButton *RemoveButton;
     306};
     307
     308
    166309class StringQTQueryPipe : public QWidget {
    167310  Q_OBJECT
     
    194337};
    195338
     339
    196340class DoubleQTQueryPipe : public QWidget {
    197341  Q_OBJECT
     
    209353};
    210354
     355class AtomQTQueryPipe : public QWidget {
     356  Q_OBJECT
     357public:
     358  AtomQTQueryPipe(atom **_content, QTDialog *_dialog, QComboBox *_theBox);
     359  virtual ~AtomQTQueryPipe();
     360
     361public slots:
     362  void update(int);
     363
     364private:
     365  atom **content;
     366  QTDialog *dialog;
     367  QComboBox *theBox;
     368
     369};
     370
     371
     372class AtomsQTQueryPipe : public QWidget {
     373  Q_OBJECT
     374public:
     375  AtomsQTQueryPipe(std::vector<atom *>*_content, QTDialog *_dialog, QComboBox *_theBox);
     376  virtual ~AtomsQTQueryPipe();
     377
     378public slots:
     379  void update(int);
     380
     381private:
     382  std::vector<atom *>*content;
     383  QTDialog *dialog;
     384  QComboBox *theBox;
     385
     386};
     387
    211388class MoleculeQTQueryPipe : public QWidget {
    212389  Q_OBJECT
     
    225402};
    226403
     404class MoleculesQTQueryPipe : public QWidget {
     405  Q_OBJECT
     406public:
     407  MoleculesQTQueryPipe(std::vector<molecule *>*_content, QTDialog *_dialog, QComboBox *_theBox);
     408  virtual ~MoleculesQTQueryPipe();
     409
     410public slots:
     411  void update(int);
     412
     413private:
     414  std::vector<molecule *>*content;
     415  QTDialog *dialog;
     416  QComboBox *theBox;
     417
     418};
     419
     420class VectorQTQueryPipe : public QWidget {
     421  Q_OBJECT
     422public:
     423  VectorQTQueryPipe(Vector *_content, QTDialog *_dialog, QComboBox *_theBox);
     424  virtual ~VectorQTQueryPipe();
     425
     426public slots:
     427  void update();
     428
     429private:
     430  Vector *content;
     431  QTDialog *dialog;
     432  QComboBox *theBox;
     433};
     434
     435class VectorsQTQueryPipe : public QWidget {
     436  Q_OBJECT
     437public:
     438  VectorsQTQueryPipe(std::vector<Vector>*_content, QTDialog *_dialog, QComboBox *_theBox);
     439  virtual ~VectorsQTQueryPipe();
     440
     441public slots:
     442  void update();
     443
     444private:
     445  std::vector<Vector> *content;
     446  QTDialog *dialog;
     447  QComboBox *theBox;
     448};
     449
    227450class ElementQTQueryPipe : public QWidget {
    228451  Q_OBJECT
    229452public:
    230   ElementQTQueryPipe(std::vector<element *> *_content, QTDialog *_dialog, QComboBox *_theBox);
     453  ElementQTQueryPipe(element **_content, QTDialog *_dialog, QComboBox *_theBox);
    231454  virtual ~ElementQTQueryPipe();
    232455
     
    235458
    236459private:
    237   std::vector<element *> *content;
     460  element **content;
     461  QTDialog *dialog;
     462  QComboBox *theBox;
     463};
     464
     465class ElementsQTQueryPipe : public QWidget {
     466  Q_OBJECT
     467public:
     468  ElementsQTQueryPipe(std::vector<element *>*_content, QTDialog *_dialog, QComboBox *_theBox);
     469  virtual ~ElementsQTQueryPipe();
     470
     471public slots:
     472  void update(int);
     473
     474private:
     475  std::vector<element *>*content;
    238476  QTDialog *dialog;
    239477  QComboBox *theBox;
  • src/UIElements/TextUI/TextDialog.cpp

    r0ff6b5 r7cd6e7  
    3030using namespace std;
    3131
     32using boost::lexical_cast;
     33using boost::bad_lexical_cast;
     34
    3235
    3336TextDialog::TextDialog()
     
    5255}
    5356
     57void TextDialog::queryInts(const char* title, string description){
     58  registerQuery(new IntsTextQuery(title,description));
     59}
     60
    5461void TextDialog::queryDouble(const char* title, string description){
    5562  registerQuery(new DoubleTextQuery(title,description));
    5663}
    5764
     65void TextDialog::queryDoubles(const char* title, string description){
     66  registerQuery(new DoublesTextQuery(title,description));
     67}
     68
    5869void TextDialog::queryString(const char* title, string description){
    5970  registerQuery(new StringTextQuery(title,description));
     
    6879}
    6980
     81void TextDialog::queryAtoms(const char* title, string description) {
     82  registerQuery(new AtomsTextQuery(title,description));
     83}
     84
    7085void TextDialog::queryMolecule(const char* title, string description) {
    7186  registerQuery(new MoleculeTextQuery(title,description));
    7287}
    7388
     89void TextDialog::queryMolecules(const char* title, string description) {
     90  registerQuery(new MoleculesTextQuery(title,description));
     91}
     92
    7493void TextDialog::queryVector(const char* title, bool check, string description) {
    7594  registerQuery(new VectorTextQuery(title,check,description));
    7695}
    7796
     97void TextDialog::queryVectors(const char* title, bool check, string description) {
     98  registerQuery(new VectorsTextQuery(title,check,description));
     99}
     100
    78101void TextDialog::queryBox(const char* title, string description) {
    79102  registerQuery(new BoxTextQuery(title,description));
     
    82105void TextDialog::queryElement(const char* title, string description){
    83106  registerQuery(new ElementTextQuery(title,description));
     107}
     108
     109void TextDialog::queryElements(const char* title, string description){
     110  registerQuery(new ElementsTextQuery(title,description));
    84111}
    85112
     
    118145  // clear the input buffer of anything still in the line
    119146  cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
     147  return true;
     148}
     149
     150TextDialog::IntsTextQuery::IntsTextQuery(string title, std::string _description) :
     151    Dialog::IntsQuery(title,_description)
     152{}
     153
     154TextDialog::IntsTextQuery::~IntsTextQuery() {}
     155
     156bool TextDialog::IntsTextQuery::handle() {
     157  Log() << Verbose(0) << getTitle();
     158  std::string line;
     159  getline(cin,line);
     160  // dissect by " "
     161  string::iterator olditer = line.begin();
     162  for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
     163    if (*iter == ' ') {
     164      std::istringstream stream(string(iter, olditer));
     165      stream >> temp;
     166      tmp.push_back(temp);
     167      olditer = iter;
     168    }
     169  }
     170  if (olditer != line.begin()) { // insert last part also
     171    std::istringstream stream(string(olditer, line.end()));
     172    stream >> temp;
     173    tmp.push_back(temp);
     174  }
     175
    120176  return true;
    121177}
     
    171227  Log() << Verbose(0) << getTitle();
    172228  getline(cin,temp);
    173   // dissect by ","
     229  // dissect by " "
    174230  string::iterator olditer = temp.begin();
    175231  for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
     
    208264}
    209265
     266
     267TextDialog::DoublesTextQuery::DoublesTextQuery(string title, std::string _description) :
     268    Dialog::DoublesQuery(title,_description)
     269{}
     270
     271TextDialog::DoublesTextQuery::~DoublesTextQuery() {}
     272
     273bool TextDialog::DoublesTextQuery::handle() {
     274  Log() << Verbose(0) << getTitle();
     275  std::string line;
     276  getline(cin,line);
     277  // dissect by " "
     278  string::iterator olditer = line.begin();
     279  for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
     280    if (*iter == ' ') {
     281      std::istringstream stream(string(iter, olditer));
     282      stream >> temp;
     283      tmp.push_back(temp);
     284      olditer = iter;
     285    }
     286  }
     287  if (olditer != line.begin()) { // insert last part also
     288    std::istringstream stream(string(olditer, line.end()));
     289    stream >> temp;
     290    tmp.push_back(temp);
     291  }
     292
     293  return true;
     294}
     295
    210296TextDialog::AtomTextQuery::AtomTextQuery(string title, std::string _description) :
    211297    Dialog::AtomQuery(title,_description)
     
    215301
    216302bool TextDialog::AtomTextQuery::handle() {
    217   int idxOfAtom=0;
     303  int idxOfAtom=-1;
    218304  bool badInput = false;
    219305  do{
     
    231317    tmp = World::getInstance().getAtom(AtomById(idxOfAtom));
    232318    if(!tmp && idxOfAtom!=-1){
    233       Log() << Verbose(0) << "Invalid Atom Index" << endl;
     319      Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
    234320      badInput = true;
    235321    }
     
    237323  } while(badInput);
    238324  cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
     325  return (idxOfAtom!=-1);
     326}
     327
     328
     329TextDialog::AtomsTextQuery::AtomsTextQuery(string title, std::string _description) :
     330    Dialog::AtomsQuery(title,_description)
     331{}
     332
     333TextDialog::AtomsTextQuery::~AtomsTextQuery() {}
     334
     335bool TextDialog::AtomsTextQuery::handle() {
     336  int idxOfAtom=-1;
     337  Log() << Verbose(0) << getTitle();
     338  std::string line;
     339  getline(cin,line);
     340  // dissect by " "
     341  string::iterator olditer = line.begin();
     342  for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
     343    if (*iter == ' ') {
     344      std::istringstream stream(string(iter, olditer));
     345      stream >> idxOfAtom;
     346      temp = World::getInstance().getAtom(AtomById(idxOfAtom));
     347      if(!temp && idxOfAtom!=-1){
     348        Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
     349        break;
     350      }
     351      tmp.push_back(temp);
     352      olditer = iter;
     353    }
     354  }
     355  if (olditer != line.begin()) { // insert last part also
     356    std::istringstream stream(string(olditer, line.end()));
     357    stream >> idxOfAtom;
     358    temp = World::getInstance().getAtom(AtomById(idxOfAtom));
     359    if(!temp && idxOfAtom!=-1) {
     360      Log() << Verbose(0) << "Invalid Atom Index" << idxOfAtom << endl;
     361      tmp.push_back(temp);
     362    }
     363  }
     364
    239365  return (idxOfAtom!=-1);
    240366}
     
    272398}
    273399
     400
     401TextDialog::MoleculesTextQuery::MoleculesTextQuery(string title, std::string _description) :
     402    Dialog::MoleculesQuery(title,_description)
     403{}
     404
     405TextDialog::MoleculesTextQuery::~MoleculesTextQuery() {}
     406
     407bool TextDialog::MoleculesTextQuery::handle() {
     408  int idxOfMol=-1;
     409  Log() << Verbose(0) << getTitle();
     410  std::string line;
     411  getline(cin,line);
     412  // dissect by " "
     413  string::iterator olditer = line.begin();
     414  for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
     415    if (*iter == ' ') {
     416      std::istringstream stream(string(iter, olditer));
     417      stream >> idxOfMol;
     418      temp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
     419      if(!temp && idxOfMol!=-1){
     420        Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl;
     421        break;
     422      }
     423      tmp.push_back(temp);
     424      olditer = iter;
     425    }
     426  }
     427  if (olditer != line.begin()) { // insert last part also
     428    std::istringstream stream(string(olditer, line.end()));
     429    stream >> idxOfMol;
     430    temp = World::getInstance().getMolecule(MoleculeById(idxOfMol));
     431    if(!temp && idxOfMol!=-1){
     432      Log() << Verbose(0) << "Invalid Molecule Index" << idxOfMol << endl;
     433      tmp.push_back(temp);
     434    }
     435  }
     436
     437  return (idxOfMol!=-1);
     438}
     439
    274440TextDialog::VectorTextQuery::VectorTextQuery(std::string title, bool _check, std::string _description) :
    275441    Dialog::VectorQuery(title,_check,_description)
     
    280446
    281447bool TextDialog::VectorTextQuery::handle() {
    282   Log() << Verbose(0) << getTitle();
    283 
     448  std::cout << getTitle();
    284449  const Matrix &M = World::getInstance().getDomain().getM();
    285   char coords[3] = {'x','y','z'};
    286   for (int i=0;i<3;i++) {
    287     do {
    288       Log() << Verbose(0) << coords[i] << "[0.." << M.at(i,i) << "]: ";
    289       cin >> (*tmp)[i];
    290     } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= M.at(i,i))) && (check));
    291   }
    292   return true;
     450  char coords[3] = {'x', 'y', 'z'};
     451  for (int i=0;i<3;i++)
     452    std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
     453
     454  std::string line;
     455  getline(cin,line);
     456
     457  // dissect by ","
     458  double coord = 0.;
     459  int counter = 0;
     460  string::iterator olditer = line.begin();
     461  for(string::iterator iter = line.begin(); (iter != line.end()) && (counter != 3); ++iter) {
     462    if (*iter == ',') {
     463      std::istringstream stream(string(iter, olditer));
     464      stream >> coord;
     465      tmp[counter++] = coord;
     466      olditer = iter;
     467    }
     468  }
     469  if ((olditer != line.begin()) && (counter != 3)) { // insert last part also
     470    std::istringstream stream(string(olditer, line.end()));
     471    stream >> coord;
     472    tmp[counter++] = coord;
     473  }
     474
     475  // check vector
     476  return World::getInstance().getDomain().isInside(tmp);
     477}
     478
     479TextDialog::VectorsTextQuery::VectorsTextQuery(std::string title, bool _check, std::string _description) :
     480    Dialog::VectorsQuery(title,_check,_description)
     481{}
     482
     483TextDialog::VectorsTextQuery::~VectorsTextQuery()
     484{}
     485
     486bool TextDialog::VectorsTextQuery::handle() {
     487  std::cout << getTitle();
     488  char coords[3] = {'x', 'y', 'z'};
     489  const Matrix &M = World::getInstance().getDomain().getM();
     490  for (int i=0;i<3;i++)
     491    std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
     492
     493  std::string line;
     494  getline(cin,line);
     495
     496  // dissect by ","
     497  double coord = 0.;
     498  string::iterator olditerspace = line.begin();
     499  string::iterator olditercomma = line.begin();
     500  int counter = 0;
     501  for(string::iterator vectoriter = line.begin(); vectoriter != line.end(); ++vectoriter) {
     502    if (*vectoriter == ',')
     503      counter++;
     504    if ((*vectoriter == ' ') && (counter == 2)) {
     505      counter = 0;
     506      for(string::iterator componentiter = olditerspace; (componentiter != vectoriter) && (counter !=3); ++componentiter) {
     507        if (*componentiter == ',') {
     508          std::istringstream stream(string(componentiter, olditercomma));
     509          stream >> coord;
     510          temp[counter++] = coord;
     511          olditercomma = componentiter;
     512        }
     513      }
     514      if ((olditercomma != line.begin()) && (counter != 3)) { // insert last part also
     515        std::istringstream stream(string(olditercomma, vectoriter));
     516        stream >> coord;
     517        temp[counter++] = coord;
     518      }
     519      if (World::getInstance().getDomain().isInside(temp))
     520        tmp.push_back(temp);
     521      olditerspace = vectoriter;
     522    }
     523  }
    293524}
    294525
     
    338569          Log() << Verbose(0) << "No element with this atomic number!" << endl;
    339570          badInput = true;
    340         } else {
    341           tmp.push_back(temp);
    342571        }
    343572      }
     
    362591          Log() << Verbose(0) << "No element with this shorthand!" << endl;
    363592          badInput = true;
    364         } else {
    365           tmp.push_back(temp);
    366593        }
    367594      }
     
    378605  return !aborted;
    379606}
     607
     608TextDialog::ElementsTextQuery::ElementsTextQuery(std::string title, std::string _description) :
     609    Dialog::ElementsQuery(title,_description)
     610{}
     611
     612TextDialog::ElementsTextQuery::~ElementsTextQuery()
     613{}
     614
     615bool TextDialog::ElementsTextQuery::handle() {
     616  std::string shorthand;
     617  int Z=-1;
     618  Log() << Verbose(0) << getTitle();
     619  std::string line;
     620  getline(cin,line);
     621  // dissect by " "
     622  string::iterator olditer = line.begin();
     623  for(string::iterator iter = line.begin(); iter != line.end(); ++iter) {
     624    if (*iter == ' ') {
     625      std::istringstream stream(string(iter, olditer));
     626      stream >> shorthand;
     627      try {
     628        Z = lexical_cast<int>(shorthand);
     629        temp = World::getInstance().getPeriode()->FindElement(Z);
     630      } catch (bad_lexical_cast) {
     631        temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
     632      };
     633      if(!temp && Z!=-1){
     634        Log() << Verbose(0) << "Invalid Element" << shorthand << endl;
     635        break;
     636      }
     637      tmp.push_back(temp);
     638      olditer = iter;
     639    }
     640  }
     641  if (olditer != line.begin()) { // insert last part also
     642    std::istringstream stream(string(olditer, line.end()));
     643    stream >> shorthand;
     644    try {
     645      Z = lexical_cast<int>(shorthand);
     646      temp = World::getInstance().getPeriode()->FindElement(Z);
     647    } catch (bad_lexical_cast) {
     648      temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
     649    };
     650    if(!temp && Z!=-1) {
     651      Log() << Verbose(0) << "Invalid Element" << shorthand << endl;
     652      tmp.push_back(temp);
     653    }
     654  }
     655
     656  return (Z!=-1);
     657}
  • src/UIElements/TextUI/TextDialog.hpp

    r0ff6b5 r7cd6e7  
    2727  virtual void queryBoolean(const char *, std::string = "");
    2828  virtual void queryInt(const char *, std::string = "");
     29  virtual void queryInts(const char *, std::string = "");
    2930  virtual void queryString(const char*, std::string = "");
    3031  virtual void queryStrings(const char*, std::string = "");
    3132  virtual void queryDouble(const char*, std::string = "");
     33  virtual void queryDoubles(const char*, std::string = "");
    3234  virtual void queryAtom(const char*,std::string = "");
     35  virtual void queryAtoms(const char*,std::string = "");
    3336  virtual void queryMolecule(const char*,std::string = "");
     37  virtual void queryMolecules(const char*,std::string = "");
    3438  virtual void queryVector(const char*,bool, std::string = "");
     39  virtual void queryVectors(const char*,bool, std::string = "");
    3540  virtual void queryBox(const char*, std::string = "");
    3641  virtual void queryElement(const char*, std::string = "");
     42  virtual void queryElements(const char*, std::string = "");
    3743
    3844protected:
     
    5965  };
    6066
     67  class IntsTextQuery : public Dialog::IntsQuery {
     68  public:
     69    IntsTextQuery(std::string title, std::string _description = NULL);
     70    virtual ~IntsTextQuery();
     71    virtual bool handle();
     72  };
     73
    6174  class DoubleTextQuery : public Dialog::DoubleQuery {
    6275  public:
    6376    DoubleTextQuery(std::string title, std::string _description = NULL);
    6477    virtual ~DoubleTextQuery();
     78    virtual bool handle();
     79  };
     80
     81  class DoublesTextQuery : public Dialog::DoublesQuery {
     82  public:
     83    DoublesTextQuery(std::string title, std::string _description = NULL);
     84    virtual ~DoublesTextQuery();
    6585    virtual bool handle();
    6686  };
     
    87107  };
    88108
     109  class AtomsTextQuery : public Dialog::AtomsQuery {
     110  public:
     111    AtomsTextQuery(std::string title, std::string _description = NULL);
     112    virtual ~AtomsTextQuery();
     113    virtual bool handle();
     114  };
     115
    89116  class MoleculeTextQuery : public Dialog::MoleculeQuery {
    90117  public:
     
    94121  };
    95122
     123  class MoleculesTextQuery : public Dialog::MoleculesQuery {
     124  public:
     125    MoleculesTextQuery(std::string title, std::string _description = NULL);
     126    virtual ~MoleculesTextQuery();
     127    virtual bool handle();
     128  };
     129
    96130  class VectorTextQuery : public Dialog::VectorQuery {
    97131  public:
    98132    VectorTextQuery(std::string title,bool _check, std::string _description = NULL);
    99133    virtual ~VectorTextQuery();
     134    virtual bool handle();
     135  };
     136
     137  class VectorsTextQuery : public Dialog::VectorsQuery {
     138  public:
     139    VectorsTextQuery(std::string title,bool _check, std::string _description = NULL);
     140    virtual ~VectorsTextQuery();
    100141    virtual bool handle();
    101142  };
     
    114155    virtual bool handle();
    115156  };
     157
     158  class ElementsTextQuery : public Dialog::ElementsQuery {
     159  public:
     160    ElementsTextQuery(std::string title, std::string _description = NULL);
     161    virtual ~ElementsTextQuery();
     162    virtual bool handle();
     163  };
    116164};
    117165
Note: See TracChangeset for help on using the changeset viewer.