Changeset 67c75b for src/UIElements


Ignore:
Timestamp:
Jun 2, 2010, 11:44:00 AM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
992fd7
Parents:
82b71a (diff), 190326 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'MenuRefactoring' into QT4Refactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/builder.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/vector.cpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/TextDialog.cpp

    r82b71a r67c75b  
    6262
    6363bool TextDialog::IntTextQuery::handle() {
    64   Log() << Verbose(0) << getTitle();
    65   cin >> tmp;
     64  bool badInput = false;
     65  do{
     66    badInput = false;
     67    Log() << Verbose(0) << getTitle();
     68    cin >> tmp;
     69    if(cin.fail()){
     70      badInput=true;
     71      cin.clear();
     72      cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
     73      Log() << Verbose(0) << "Input was not a number!" << endl;
     74    }
     75  } while(badInput);
     76  // clear the input buffer of anything still in the line
     77  cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    6678  return true;
    6779}
     
    7587bool TextDialog::StringTextQuery::handle() {
    7688  Log() << Verbose(0) << getTitle();
    77   cin >> tmp;
     89  getline(cin,tmp);
    7890  return true;
    7991}
     
    8698
    8799bool TextDialog::DoubleTextQuery::handle() {
    88   Log() << Verbose(0) << getTitle();
    89   cin >> tmp;
     100  bool badInput = false;
     101  do{
     102    badInput = false;
     103    Log() << Verbose(0) << getTitle();
     104    cin >> tmp;
     105    if(cin.fail()){
     106      badInput = true;
     107      cin.clear();
     108      cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
     109      Log() << Verbose(0) << "Input was not a number!" << endl;
     110    }
     111  }while(badInput);
     112  cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    90113  return true;
    91114}
     
    98121
    99122bool TextDialog::MoleculeTextQuery::handle() {
    100   int idxOfMol;
    101   Log() << Verbose(0) << getTitle();
    102   cin >> idxOfMol;
    103   tmp = molecules->ReturnIndex(idxOfMol);
    104   while(!tmp && (idxOfMol !=-1)) {
    105     Log() << Verbose(0) << "Invalid Molecule Index" << endl;
     123  int idxOfMol=0;
     124  bool badInput = false;
     125  do{
     126    badInput = false;
    106127    Log() << Verbose(0) << getTitle();
    107128    cin >> idxOfMol;
     129    if(cin.fail()){
     130      badInput = true;
     131      cin.clear();
     132      cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
     133      Log() << Verbose(0) << "Input was not a number!" << endl;
     134      continue;
     135    }
     136
    108137    tmp = molecules->ReturnIndex(idxOfMol);
    109   }
     138    if(!tmp && idxOfMol!=-1){
     139      Log() << Verbose(0) << "Invalid Molecule Index" << endl;
     140      badInput = true;
     141    }
     142
     143  } while(badInput);
     144  cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    110145  return (idxOfMol!=-1);
    111146}
     
    119154
    120155bool TextDialog::VectorTextQuery::handle() {
    121  Log() << Verbose(0) << getTitle();
    122  tmp->AskPosition(cellSize,check);
    123  return true;
     156  Log() << Verbose(0) << getTitle();
     157
     158  char coords[3] = {'x','y','z'};
     159  int j = -1;
     160  for (int i=0;i<3;i++) {
     161    j += i+1;
     162    do {
     163      Log() << Verbose(0) << coords[i] << "[0.." << cellSize[j] << "]: ";
     164      cin >> (*tmp)[i];
     165    } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= cellSize[j])) && (check));
     166  }
     167  return true;
    124168}
    125169
     
    133177
    134178bool TextDialog::ElementTextQuery::handle() {
    135   int Z;
    136   Log() << Verbose(0) << getTitle();
    137   cin >> Z;
    138   tmp = World::getInstance().getPeriode()->FindElement(Z);
    139   return tmp;
    140 }
     179  bool badInput=false;
     180  bool aborted = false;
     181  do{
     182    badInput = false;
     183    Log() << Verbose(0) << getTitle();
     184
     185    // try to read as Atomic number
     186    int Z;
     187    cin >> Z;
     188    if(!cin.fail()){
     189      if(Z==-1){
     190        aborted = true;
     191      }
     192      else{
     193        tmp = World::getInstance().getPeriode()->FindElement(Z);
     194        if(!tmp){
     195          Log() << Verbose(0) << "No element with this atomic number!" << endl;
     196          badInput = true;
     197        }
     198      }
     199      continue;
     200    }
     201    else{
     202      cin.clear();
     203    }
     204
     205    // Try to read as shorthand
     206    // the last buffer content was not removed, so we read the
     207    // same thing again, this time as a string
     208    string shorthand;
     209    cin >> shorthand;
     210    if(!cin.fail()){
     211      if(shorthand.empty()){
     212        aborted = true;
     213      }
     214      else{
     215        tmp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
     216        if(!tmp){
     217          Log() << Verbose(0) << "No element with this shorthand!" << endl;
     218          badInput = true;
     219        }
     220      }
     221    }
     222    else{
     223      Log() << Verbose(0) << "Could not read input. Try Again." << endl;
     224      cin.clear();
     225      cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
     226      badInput = true;
     227    }
     228
     229  }while(badInput);
     230  cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
     231  return !aborted;
     232}
Note: See TracChangeset for help on using the changeset viewer.