Ignore:
Timestamp:
Jul 25, 2010, 3:07:42 PM (14 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/TextUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.