Changeset d90762 for src/UIElements


Ignore:
Timestamp:
May 8, 2010, 10:57:04 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:
bcd072
Parents:
4380af
git-author:
Frederik Heber <heber@…> (05/08/10 22:52:19)
git-committer:
Frederik Heber <heber@…> (05/08/10 22:57:04)
Message:

Rewrote all CommandLineDialog's Query... to use the prorgam_options::vm.

  • we scan for the given title of the Query in program_options::vm and return the value.
  • in case of molecule we use MoleculeIdDescriptor.
  • in case of vector, new vector is created and components initialized from vector<double>
  • in case of element we use Periodetafel::FindElement()

Signed-off-by: Frederik Heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/CommandLineDialog.cpp

    r4380af rd90762  
    77
    88
     9#include <cassert>
    910#include <iostream>
    1011
     12#include <Descriptors/MoleculeDescriptor.hpp>
     13#include <Descriptors/MoleculeIdDescriptor.hpp>
    1114#include "UIElements/CommandLineDialog.hpp"
    1215
    13 #include "World.hpp"
    1416#include "periodentafel.hpp"
    1517#include "atom.hpp"
     18#include "CommandLineParser.hpp"
     19#include "defs.hpp"
    1620#include "molecule.hpp"
    1721#include "log.hpp"
    1822#include "verbose.hpp"
     23#include "World.hpp"
    1924
    2025using namespace std;
     
    6368
    6469bool CommandLineDialog::IntTextQuery::handle() {
    65   bool badInput = false;
    66   do{
    67     badInput = false;
    68     Log() << Verbose(0) << getTitle();
    69     cin >> tmp;
    70     if(cin.fail()){
    71       badInput=true;
    72       cin.clear();
    73       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    74       Log() << Verbose(0) << "Input was not a number!" << endl;
    75     }
    76   } while(badInput);
    77   // clear the input buffer of anything still in the line
    78   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    79   return true;
     70  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     71    tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
     72    return true;
     73  } else
     74    return false;
    8075}
    8176
     
    8782
    8883bool CommandLineDialog::StringTextQuery::handle() {
    89   Log() << Verbose(0) << getTitle();
    90   getline(cin,tmp);
    91   return true;
     84  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     85    tmp = CommandLineParser::getInstance().vm[getTitle()].as<std::string>();
     86    return true;
     87  } else
     88    return false;
    9289}
    9390
     
    9996
    10097bool CommandLineDialog::DoubleTextQuery::handle() {
    101   bool badInput = false;
    102   do{
    103     badInput = false;
    104     Log() << Verbose(0) << getTitle();
    105     cin >> tmp;
    106     if(cin.fail()){
    107       badInput = true;
    108       cin.clear();
    109       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    110       Log() << Verbose(0) << "Input was not a number!" << endl;
    111     }
    112   }while(badInput);
    113   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    114   return true;
     98  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     99    tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
     100    return true;
     101  } else
     102    return false;
    115103}
    116104
     
    122110
    123111bool CommandLineDialog::MoleculeTextQuery::handle() {
    124   int idxOfMol=0;
    125   bool badInput = false;
    126   do{
    127     badInput = false;
    128     Log() << Verbose(0) << getTitle();
    129     cin >> idxOfMol;
    130     if(cin.fail()){
    131       badInput = true;
    132       cin.clear();
    133       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    134       Log() << Verbose(0) << "Input was not a number!" << endl;
    135       continue;
    136     }
    137 
    138     tmp = molecules->ReturnIndex(idxOfMol);
    139     if(!tmp && idxOfMol!=-1){
    140       Log() << Verbose(0) << "Invalid Molecule Index" << endl;
    141       badInput = true;
    142     }
    143 
    144   } while(badInput);
    145   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    146   return (idxOfMol!=-1);
     112  int IdxOfMol = -1;
     113  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     114    IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
     115    tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
     116    return true;
     117  } else
     118    return false;
    147119}
    148120
     
    155127
    156128bool CommandLineDialog::VectorTextQuery::handle() {
    157   Log() << Verbose(0) << getTitle();
    158 
    159   char coords[3] = {'x','y','z'};
    160   int j = -1;
    161   for (int i=0;i<3;i++) {
    162     j += i+1;
    163     do {
    164       Log() << Verbose(0) << coords[i] << "[0.." << cellSize[j] << "]: ";
    165       cin >> (*tmp)[i];
    166     } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= cellSize[j])) && (check));
    167   }
    168   return true;
     129  vector<double> temp;
     130  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     131    temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >();
     132    assert((temp.size() == 3) && "Vector from command line does not have three components.");
     133    tmp = new Vector;
     134    for (int i=0;i<NDIM;i++)
     135      tmp->at(i) = temp[i];
     136    return true;
     137  } else
     138    return false;
    169139}
    170140
     
    178148
    179149bool CommandLineDialog::ElementTextQuery::handle() {
    180   bool badInput=false;
    181   bool aborted = false;
    182   do{
    183     badInput = false;
    184     Log() << Verbose(0) << getTitle();
    185 
    186     // try to read as Atomic number
    187     int Z;
    188     cin >> Z;
    189     if(!cin.fail()){
    190       if(Z==-1){
    191         aborted = true;
    192       }
    193       else{
    194         tmp = World::getInstance().getPeriode()->FindElement(Z);
    195         if(!tmp){
    196           Log() << Verbose(0) << "No element with this atomic number!" << endl;
    197           badInput = true;
    198         }
    199       }
    200       continue;
    201     }
    202     else{
    203       cin.clear();
    204     }
    205 
    206     // Try to read as shorthand
    207     // the last buffer content was not removed, so we read the
    208     // same thing again, this time as a string
    209     string shorthand;
    210     cin >> shorthand;
    211     if(!cin.fail()){
    212       if(shorthand.empty()){
    213         aborted = true;
    214       }
    215       else{
    216         tmp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
    217         if(!tmp){
    218           Log() << Verbose(0) << "No element with this shorthand!" << endl;
    219           badInput = true;
    220         }
    221       }
    222     }
    223     else{
    224       Log() << Verbose(0) << "Could not read input. Try Again." << endl;
    225       cin.clear();
    226       cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    227       badInput = true;
    228     }
    229 
    230   }while(badInput);
    231   cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
    232   return !aborted;
     150  int Z = -1;
     151  if (CommandLineParser::getInstance().vm.count(getTitle())) {
     152    Z = CommandLineParser::getInstance().vm[getTitle()].as<int>();
     153    tmp = World::getInstance().getPeriode()->FindElement(Z);
     154    return true;
     155  } else
     156    return false;
    233157}
Note: See TracChangeset for help on using the changeset viewer.