Changeset f79d65 for src/UIElements


Ignore:
Timestamp:
Jun 19, 2017, 8:24:16 AM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, ChangeBugEmailaddress, ChemicalSpaceEvaluator, EmpiricalPotential_contain_HomologyGraph_documentation, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, Fix_Verbose_Codepatterns, ForceAnnealing_oldresults, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids_IntegrationTest, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, StoppableMakroAction, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps
Children:
1ba51c
Parents:
2eded3e
git-author:
Frederik Heber <heber@…> (03/30/17 21:59:00)
git-committer:
Frederik Heber <frederik.heber@…> (06/19/17 08:24:16)
Message:

Vector(s) are now stored as strings in Querys intermediately.

  • they get evaluated first after being stored in a Parameter/Value on request via get().
  • Needed to change all Vector(s)..Query's of all UIs and also the general base classes inside Dialog.
  • QtQueryList need to be specialized in order to allow a QtQueryList<Vector> to actually store a vector of strings.
  • we may use setAsString() in order to set the Parameter thankfully.
  • TESTS: All regression tests on Geometry Actions are now working. Removed XFAIL from Options/Session test that use Python, i.e. the ones we marked four commits ago.
Location:
src/UIElements
Files:
9 edited

Legend:

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

    r2eded3e rf79d65  
    6666        std::string("value"),
    6767        std::string("VectorValue")
     68    );
     69#endif
     70  }
     71  VV.vectorstring = values.at(0);
     72  v = boost::any(VectorValue(VV));
     73}
     74
     75void validate(boost::any& v, const std::vector<std::string>& values, RealSpaceMatrixValue *, int)
     76{
     77  RealSpaceMatrixValue RSMV;
     78  std::vector<std::string> components;
     79
     80  // split comma-separated values
     81  if (values.size() != 1) {
     82    std::cerr <<  "Not one vector but " << values.size() << " given " << std::endl;
     83#if BOOST_VERSION < 104200
     84    throw boost::program_options::validation_error("Unequal to one vector given");
     85#else
     86    throw boost::program_options::validation_error(
     87        boost::program_options::validation_error::invalid_option_value,
     88        std::string("value"),
     89        std::string("BoxValue")
    6890    );
    6991#endif
     
    83105  components.push_back(std::string(Biter,argument.end()));
    84106
    85   if (components.size() != 3) {
    86     std::cerr <<  "Specified vector does not have three components but " << components.size() << std::endl;
    87 #if BOOST_VERSION < 104200
    88     throw boost::program_options::validation_error("Specified vector does not have three components");
    89 #else
    90     throw boost::program_options::validation_error(
    91         boost::program_options::validation_error::invalid_option_value,
    92         std::string("value"),
    93         std::string("VectorValue")
    94     );
    95 #endif
    96   }
    97   for (size_t i=0;i<NDIM;++i)
    98     VV.vector[i] = boost::lexical_cast<double>(components.at(i));
    99   v = boost::any(VectorValue(VV));
    100 }
    101 
    102 void validate(boost::any& v, const std::vector<std::string>& values, RealSpaceMatrixValue *, int)
    103 {
    104   RealSpaceMatrixValue RSMV;
    105   std::vector<std::string> components;
    106 
    107   // split comma-separated values
    108   if (values.size() != 1) {
    109     std::cerr <<  "Not one vector but " << values.size() << " given " << std::endl;
    110 #if BOOST_VERSION < 104200
    111     throw boost::program_options::validation_error("Unequal to one vector given");
    112 #else
    113     throw boost::program_options::validation_error(
    114         boost::program_options::validation_error::invalid_option_value,
    115         std::string("value"),
    116         std::string("BoxValue")
    117     );
    118 #endif
    119   }
    120   std::string argument(values.at(0));
    121   std::string::iterator Aiter = argument.begin();
    122   std::string::iterator Biter = argument.begin();
    123   for (; Aiter != argument.end(); ++Aiter) {
    124     if (*Aiter == ',') {
    125       components.push_back(std::string(Biter,Aiter));
    126       do {
    127         Aiter++;
    128       } while (*Aiter == ' ' || *Aiter == '\t');
    129       Biter = Aiter;
    130     }
    131   }
    132   components.push_back(std::string(Biter,argument.end()));
    133 
    134107  if (components.size() != 6) {
    135108    std::cerr <<  "Specified vector does not have three components but " << components.size() << std::endl;
  • src/UIElements/CommandLineUI/Query/VectorCommandLineQuery.cpp

    r2eded3e rf79d65  
    5353
    5454bool CommandLineDialog::VectorCommandLineQuery::handle() {
    55   VectorValue _temp;
     55  VectorValue temporary;
    5656  if (CommandLineParser::getInstance().vm.count(getTitle())) {
    57     try {
    58       _temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
    59     } catch(boost::bad_any_cast &e) {
    60       for (size_t i=0;i<NDIM;++i)
    61         _temp.vector[i] = 0.;
    62       return false;
    63     }
    64     temp = _temp.toVector();
     57    temporary = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
     58    temp = temporary.vectorstring;
    6559    return true;
    6660  }
  • src/UIElements/CommandLineUI/Query/VectorsCommandLineQuery.cpp

    r2eded3e rf79d65  
    4646
    4747CommandLineDialog::VectorsCommandLineQuery::VectorsCommandLineQuery(Parameter<std::vector<Vector> > &_param, const std::string &_title, const std::string &_description) :
    48     Dialog::TQuery<std::vector<Vector> >(_param, _title, _description)
     48    Dialog::TQuery< std::vector<Vector> >(_param, _title, _description)
    4949{}
    5050
     
    5353
    5454bool CommandLineDialog::VectorsCommandLineQuery::handle() {
    55   std::vector<VectorValue> temporary;
     55  std::vector<std::string> temporary;
     56  std::stringstream output;
    5657  if (CommandLineParser::getInstance().vm.count(getTitle())) {
    57     try {
    58       temporary = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<VectorValue> >();
    59     } catch(boost::bad_any_cast &e) {
    60       temporary.clear();
    61       return false;
    62     }
    63     for(std::vector<VectorValue>::iterator iter = temporary.begin(); iter != temporary.end(); ++iter) {
    64       Vector temp_element = (*iter).toVector();
    65       temp.push_back(temp_element);
    66     }
     58    temp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<std::string> >();
    6759    return true;
    6860  }
  • src/UIElements/Dialog.cpp

    r2eded3e rf79d65  
    145145}
    146146
     147static const std::string concatenateStrings(const std::vector<std::string> &_strings)
     148{
     149  std::stringstream output;
     150  for (std::vector<std::string>::const_iterator iter = _strings.begin();
     151      iter != _strings.end(); ++iter)
     152    output << *iter << " ";
     153  return output.str();
     154}
     155
     156bool Dialog::TQuery< std::vector<Vector> >::isValid()
     157{
     158  return param.isValidAsString(concatenateStrings(temp));
     159}
     160void Dialog::TQuery< std::vector<Vector> >::setResult()
     161{
     162  param.setAsString(concatenateStrings(temp));
     163}
     164
    147165/** With the following boost::preprocessor code we generate template
    148166 * specializations for each desired query types in the abstract class Dialog.
  • src/UIElements/Dialog.hpp

    r2eded3e rf79d65  
    304304  virtual ~TQuery(){}
    305305  virtual bool handle()=0;
    306   virtual bool isValid(){ return param.isValid(temp);  }
    307   virtual void setResult(){ param.set(temp);  }
     306  virtual bool isValid(){ return param.isValidAsString(temp);  }
     307  virtual void setResult(){ param.setAsString(temp);  }
    308308protected:
    309   Vector temp;
     309  std::string temp;
    310310  Parameter<Vector> &param;
    311311};
     
    318318  virtual ~TQuery(){}
    319319  virtual bool handle()=0;
    320   virtual bool isValid(){ return param.isValid(temp);  }
    321   virtual void setResult(){ param.set(temp);  }
     320  virtual bool isValid();
     321  virtual void setResult();
    322322protected:
    323   std::vector<Vector> temp;
     323  std::vector<std::string> temp;
    324324  Parameter< std::vector<Vector> > &param;
    325325};
  • src/UIElements/Qt4/Query/QtQuery.hpp

    r2eded3e rf79d65  
    414414
    415415public slots:
     416  void pageChanged(int);
     417  void onUpdateName(int);
    416418  void onUpdateX(double);
    417419  void onUpdateY(double);
     
    424426  QBoxLayout *subLayout;
    425427  QBoxLayout *coordLayout;
    426   QLabel *coordLabel;
    427428  QDoubleSpinBox *coordInputX;
    428429  QDoubleSpinBox *coordInputY;
    429430  QDoubleSpinBox *coordInputZ;
    430431  Dialog *dialog;
    431 };
    432 
    433 class QtDialog::VectorsQtQuery : public QWidget, public QtQuery<std::vector<Vector> >, public QtQueryList<Vector> {
     432  QBoxLayout *nameLayout;
     433  QComboBox *nameComboBox;
     434};
     435
     436class QtDialog::VectorsQtQuery :
     437    public QWidget,
     438    public QtQuery<std::vector<Vector> >,
     439    public QtQueryList<Vector> {
    434440  Q_OBJECT
    435441public:
  • src/UIElements/Qt4/Query/QtQueryList.hpp

    r2eded3e rf79d65  
    105105class QtQueryList<Vector> : public QtQueryListUntyped {
    106106public:
    107   QtQueryList(Parameter<std::vector<Vector> > &parentParam, QBoxLayout *parent, Dialog *_dialog, std::vector<Vector> &_temp) : QtQueryListUntyped(parent, _dialog), tempRef(_temp)
     107  QtQueryList(Parameter<std::vector<Vector> > &parentParam, QBoxLayout *parent, Dialog *_dialog, std::vector<std::string> &_temp) : QtQueryListUntyped(parent, _dialog), tempRef(_temp)
    108108  {
    109109    // do we have an STLVectorValidator?
     
    137137    // add item to both
    138138    addElementToListWidget(subParam->getAsString());
    139     tempRef.push_back(subParam->get());
     139    tempRef.push_back(subParam->getAsString());
    140140    onUpdate();
    141141  }
     
    151151  }
    152152protected:
    153   std::vector<Vector> &tempRef;
     153  std::vector<std::string> &tempRef;
    154154  Parameter<Vector> *subParam;
    155155};
  • src/UIElements/Qt4/Query/VectorQtQuery.cpp

    r2eded3e rf79d65  
    3737#include <Qt/qcombobox.h>
    3838#include <Qt/qlabel.h>
     39#include <Qt/qstackedwidget.h>
    3940
    4041//#include "CodePatterns/MemDebug.hpp"
     
    4243#include "UIElements/Qt4/Query/QtQuery.hpp"
    4344
     45#include "CodePatterns/toString.hpp"
     46
     47#include "Geometry/GeometryRegistry.hpp"
     48#include "Parameters/Specifics/Value_vector.hpp"
    4449
    4550QtDialog::VectorQtQuery::VectorQtQuery(Parameter<Vector> &_param, const std::string &_title, const std::string &_description, QBoxLayout *_parent,Dialog *_dialog) :
     
    4853    dialog(_dialog)
    4954{
    50   temp = Vector(0, 0, 0);
    51   if (param.isSet())
    52     temp = param.get();
     55  Vector temporary(0, 0, 0);
     56  temp = "0, 0, 0";
     57  if (param.isSet()) {
     58    temporary = param.get();
     59    temp = param.getAsString();
     60  }
    5361  mainLayout= new QHBoxLayout();
    5462  titleLabel = new QLabel(QString(getTitle().c_str()));
    5563  titleLabel->setToolTip(QString(getDescription().c_str()));
    5664  mainLayout->addWidget(titleLabel);
    57   subLayout = new QVBoxLayout();
     65  subLayout = new QHBoxLayout();
    5866  mainLayout->addLayout(subLayout);
    5967//  QComboBox* inputBox = new QComboBox();
     68
     69  QWidget *firstPageWidget = new QWidget;
     70  QWidget *secondPageWidget = new QWidget;
     71
     72  QStackedWidget *stackedWidget = new QStackedWidget;
     73  stackedWidget->addWidget(firstPageWidget);
     74  stackedWidget->addWidget(secondPageWidget);
     75
     76  QComboBox *pageComboBox = new QComboBox;
     77  pageComboBox->addItem(tr("x,y,z"));
     78  pageComboBox->addItem(tr("vector name"));
     79  connect(pageComboBox, SIGNAL(activated(int)),
     80      stackedWidget, SLOT(setCurrentIndex(int)));
     81  connect(pageComboBox, SIGNAL(activated(int)),
     82      this, SLOT(pageChanged(int)));
     83  subLayout->addWidget(pageComboBox);
     84  subLayout->addWidget(stackedWidget);
     85
     86   // first widget with coordinates
    6087  coordLayout = new QHBoxLayout();
    61   subLayout->addLayout(coordLayout);
    62   coordLabel = new QLabel(QString("x,y,z"));
    63   coordLayout->addWidget(coordLabel);
    6488  coordInputX = new QDoubleSpinBox();
    6589  coordInputX->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
    66   coordInputX->setValue(temp[0]);
     90  coordInputX->setValue(temporary[0]);
    6791//  coordInputX->setRange(0,M.at(i,i));
    6892  coordInputX->setDecimals(3);
     
    7094  coordInputY = new QDoubleSpinBox();
    7195  coordInputY->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
    72   coordInputY->setValue(temp[1]);
     96  coordInputY->setValue(temporary[1]);
    7397//  coordInputY->setRange(0,M.at(i,i));
    7498  coordInputY->setDecimals(3);
     
    76100  coordInputZ = new QDoubleSpinBox();
    77101  coordInputZ->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
    78   coordInputZ->setValue(temp[2]);
     102  coordInputZ->setValue(temporary[2]);
    79103//  coordInputZ->setRange(0,M.at(i,i));
    80104  coordInputZ->setDecimals(3);
     
    83107  connect(coordInputY,SIGNAL(valueChanged(double)),this,SLOT(onUpdateY(double)));
    84108  connect(coordInputZ,SIGNAL(valueChanged(double)),this,SLOT(onUpdateZ(double)));
     109  firstPageWidget->setLayout(coordLayout);
     110
     111  // second widget with string field
     112  nameLayout = new QHBoxLayout();
     113  nameComboBox = new QComboBox;
     114  GeometryRegistry &reg = GeometryRegistry::getInstance();
     115//  nameComboBox->setEditable(true);
     116  GeometryRegistry::const_iterator iter;
     117  for (iter = reg.getBeginIter(); iter != reg.getEndIter(); iter ++){
     118    GeometryObject *v = iter->second;
     119    nameComboBox->addItem(tr(v->getName().c_str()));
     120    nameComboBox->setItemData(nameComboBox->count()-1, tr(toString<Vector>(v->getVector()).c_str()), Qt::ToolTipRole);
     121  }
     122  connect(nameComboBox, SIGNAL(activated(int)),
     123      this, SLOT(onUpdateName(int)));
     124  nameLayout->addWidget(nameComboBox);
     125  secondPageWidget->setLayout(nameLayout);
     126
    85127  parent->addLayout(mainLayout);
    86128}
     
    89131{}
    90132
     133static void updateVectorString(std::string &_temp, const double newDouble, int component)
     134{
     135  //!> Internal converter from string to internal type
     136  Vector vec = Value<Vector>::parseAsVector(_temp);
     137  vec[component] = newDouble;
     138  _temp = Value<Vector>::setFromVector(vec);
     139}
     140
     141void QtDialog::VectorQtQuery::pageChanged(int pagenr) {
     142  if (pagenr == 1) {
     143    // change from x,y,z input
     144    onUpdateName(nameComboBox->currentIndex());
     145    dialog->update();
     146  } else if (pagenr == 0) {
     147    // change from name input
     148    if (GeometryRegistry::getInstance().isPresentByName(temp)) {
     149      const GeometryObject * const v = GeometryRegistry::getInstance().getByName(temp);
     150      coordInputX->setValue(v->getVector()[0]);
     151      coordInputY->setValue(v->getVector()[1]);
     152      coordInputZ->setValue(v->getVector()[2]);
     153    } else {
     154      coordInputX->setValue(0.);
     155      coordInputY->setValue(0.);
     156      coordInputZ->setValue(0.);
     157    }
     158    dialog->update();
     159  } else {
     160    ASSERT(0, "VectorQtQuery::pageChanged() - unknown page for pageComboBox.");
     161  }
     162}
     163
     164void QtDialog::VectorQtQuery::onUpdateName(int index) {
     165  const QString itemtext = nameComboBox->itemText(index);
     166  temp = itemtext.toStdString();
     167  dialog->update();
     168}
     169
    91170void QtDialog::VectorQtQuery::onUpdateX(double newDouble) {
    92   temp[0] = newDouble;
     171  updateVectorString(temp, newDouble, 0);
    93172  dialog->update();
    94173}
    95174
    96175void QtDialog::VectorQtQuery::onUpdateY(double newDouble) {
    97   temp[1] = newDouble;
     176  updateVectorString(temp, newDouble, 1);
    98177  dialog->update();
    99178}
    100179
    101180void QtDialog::VectorQtQuery::onUpdateZ(double newDouble) {
    102   temp[2] = newDouble;
     181  updateVectorString(temp, newDouble, 2);
    103182  dialog->update();
    104183}
  • src/UIElements/TextUI/Query/VectorsTextQuery.cpp

    r2eded3e rf79d65  
    4141#include "CodePatterns/Log.hpp"
    4242#include "CodePatterns/Verbose.hpp"
     43#include "Geometry/GeometryRegistry.hpp"
    4344#include "LinearAlgebra/Vector.hpp"
    4445#include "LinearAlgebra/RealSpaceMatrix.hpp"
     
    5455
    5556bool TextDialog::VectorsTextQuery::handle() {
     57  std::stringstream output;
    5658  std::cout << getDescription() << std::endl;
    5759  char coords[3] = {'x', 'y', 'z'};
    5860  const RealSpaceMatrix &M = World::getInstance().getDomain().getM();
    59   for (int i=0;i<3;i++)
    60     std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
     61  std::cout << "Enter three comma-separated coordinates, vector name, ? for list or empty for end." << std::endl;
     62  while (true) {
     63    for (int i=0;i<3;i++)
     64      std::cout << coords[i] << "[0.." << M.at(i,i) << ( (i!=2) ? "], " : "]: ");
    6165
    62   std::string line;
    63   getline(std::cin,line);
     66    std::string line;
     67    getline(std::cin,line);
    6468
    65   // dissect by ","
    66   double coord = 0.;
    67   std::string::iterator olditerspace = line.begin();
    68   std::string::iterator olditercomma = line.begin();
    69   int counter = 0;
    70   Vector temp_element;
    71   for(std::string::iterator vectoriter = line.begin(); vectoriter != line.end(); ++vectoriter) {
    72     if (*vectoriter == ',')
    73       counter++;
    74     if ((*vectoriter == ' ') && (counter == 2)) {
    75       counter = 0;
    76       for(std::string::iterator componentiter = olditerspace; (componentiter != vectoriter) && (counter !=3); ++componentiter) {
    77         if (*componentiter == ',') {
    78           std::istringstream stream(std::string(componentiter, olditercomma));
    79           stream >> coord;
    80           temp_element[counter++] = coord;
    81           olditercomma = componentiter;
    82         }
     69    if (line == "?") {
     70      GeometryRegistry &reg = GeometryRegistry::getInstance();
     71
     72      GeometryRegistry::const_iterator iter;
     73      for (iter = reg.getBeginIter(); iter != reg.getEndIter(); iter ++){
     74        GeometryObject *v = iter->second;
     75        std::cout << "\t" << *v << std::endl;
    8376      }
    84       if ((olditercomma != line.begin()) && (counter != 3)) { // insert last part also
    85         std::istringstream stream(std::string(olditercomma, vectoriter));
    86         stream >> coord;
    87         temp_element[counter++] = coord;
    88       }
    89       temp.push_back(temp_element);
    90       olditerspace = vectoriter;
     77    } else if (line.empty()) {
     78      break;
     79    } else {
     80      // simply append with white-space delimiter
     81      temp.push_back(line);
    9182    }
    9283  }
Note: See TracChangeset for help on using the changeset viewer.