Changeset f79d65 for src/UIElements
- Timestamp:
- Jun 19, 2017, 8:24:16 AM (8 years ago)
- 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)
- Location:
- src/UIElements
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/CommandLineUI/CommandLineParser_validate.cpp
r2eded3e rf79d65 66 66 std::string("value"), 67 67 std::string("VectorValue") 68 ); 69 #endif 70 } 71 VV.vectorstring = values.at(0); 72 v = boost::any(VectorValue(VV)); 73 } 74 75 void 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") 68 90 ); 69 91 #endif … … 83 105 components.push_back(std::string(Biter,argument.end())); 84 106 85 if (components.size() != 3) {86 std::cerr << "Specified vector does not have three components but " << components.size() << std::endl;87 #if BOOST_VERSION < 10420088 throw boost::program_options::validation_error("Specified vector does not have three components");89 #else90 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 #endif96 }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 values108 if (values.size() != 1) {109 std::cerr << "Not one vector but " << values.size() << " given " << std::endl;110 #if BOOST_VERSION < 104200111 throw boost::program_options::validation_error("Unequal to one vector given");112 #else113 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 #endif119 }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 134 107 if (components.size() != 6) { 135 108 std::cerr << "Specified vector does not have three components but " << components.size() << std::endl; -
src/UIElements/CommandLineUI/Query/VectorCommandLineQuery.cpp
r2eded3e rf79d65 53 53 54 54 bool CommandLineDialog::VectorCommandLineQuery::handle() { 55 VectorValue _temp;55 VectorValue temporary; 56 56 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; 65 59 return true; 66 60 } -
src/UIElements/CommandLineUI/Query/VectorsCommandLineQuery.cpp
r2eded3e rf79d65 46 46 47 47 CommandLineDialog::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) 49 49 {} 50 50 … … 53 53 54 54 bool CommandLineDialog::VectorsCommandLineQuery::handle() { 55 std::vector<VectorValue> temporary; 55 std::vector<std::string> temporary; 56 std::stringstream output; 56 57 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> >(); 67 59 return true; 68 60 } -
src/UIElements/Dialog.cpp
r2eded3e rf79d65 145 145 } 146 146 147 static 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 156 bool Dialog::TQuery< std::vector<Vector> >::isValid() 157 { 158 return param.isValidAsString(concatenateStrings(temp)); 159 } 160 void Dialog::TQuery< std::vector<Vector> >::setResult() 161 { 162 param.setAsString(concatenateStrings(temp)); 163 } 164 147 165 /** With the following boost::preprocessor code we generate template 148 166 * specializations for each desired query types in the abstract class Dialog. -
src/UIElements/Dialog.hpp
r2eded3e rf79d65 304 304 virtual ~TQuery(){} 305 305 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); } 308 308 protected: 309 Vectortemp;309 std::string temp; 310 310 Parameter<Vector> ¶m; 311 311 }; … … 318 318 virtual ~TQuery(){} 319 319 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(); 322 322 protected: 323 std::vector< Vector> temp;323 std::vector<std::string> temp; 324 324 Parameter< std::vector<Vector> > ¶m; 325 325 }; -
src/UIElements/Qt4/Query/QtQuery.hpp
r2eded3e rf79d65 414 414 415 415 public slots: 416 void pageChanged(int); 417 void onUpdateName(int); 416 418 void onUpdateX(double); 417 419 void onUpdateY(double); … … 424 426 QBoxLayout *subLayout; 425 427 QBoxLayout *coordLayout; 426 QLabel *coordLabel;427 428 QDoubleSpinBox *coordInputX; 428 429 QDoubleSpinBox *coordInputY; 429 430 QDoubleSpinBox *coordInputZ; 430 431 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 436 class QtDialog::VectorsQtQuery : 437 public QWidget, 438 public QtQuery<std::vector<Vector> >, 439 public QtQueryList<Vector> { 434 440 Q_OBJECT 435 441 public: -
src/UIElements/Qt4/Query/QtQueryList.hpp
r2eded3e rf79d65 105 105 class QtQueryList<Vector> : public QtQueryListUntyped { 106 106 public: 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) 108 108 { 109 109 // do we have an STLVectorValidator? … … 137 137 // add item to both 138 138 addElementToListWidget(subParam->getAsString()); 139 tempRef.push_back(subParam->get ());139 tempRef.push_back(subParam->getAsString()); 140 140 onUpdate(); 141 141 } … … 151 151 } 152 152 protected: 153 std::vector< Vector> &tempRef;153 std::vector<std::string> &tempRef; 154 154 Parameter<Vector> *subParam; 155 155 }; -
src/UIElements/Qt4/Query/VectorQtQuery.cpp
r2eded3e rf79d65 37 37 #include <Qt/qcombobox.h> 38 38 #include <Qt/qlabel.h> 39 #include <Qt/qstackedwidget.h> 39 40 40 41 //#include "CodePatterns/MemDebug.hpp" … … 42 43 #include "UIElements/Qt4/Query/QtQuery.hpp" 43 44 45 #include "CodePatterns/toString.hpp" 46 47 #include "Geometry/GeometryRegistry.hpp" 48 #include "Parameters/Specifics/Value_vector.hpp" 44 49 45 50 QtDialog::VectorQtQuery::VectorQtQuery(Parameter<Vector> &_param, const std::string &_title, const std::string &_description, QBoxLayout *_parent,Dialog *_dialog) : … … 48 53 dialog(_dialog) 49 54 { 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 } 53 61 mainLayout= new QHBoxLayout(); 54 62 titleLabel = new QLabel(QString(getTitle().c_str())); 55 63 titleLabel->setToolTip(QString(getDescription().c_str())); 56 64 mainLayout->addWidget(titleLabel); 57 subLayout = new Q VBoxLayout();65 subLayout = new QHBoxLayout(); 58 66 mainLayout->addLayout(subLayout); 59 67 // 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 60 87 coordLayout = new QHBoxLayout(); 61 subLayout->addLayout(coordLayout);62 coordLabel = new QLabel(QString("x,y,z"));63 coordLayout->addWidget(coordLabel);64 88 coordInputX = new QDoubleSpinBox(); 65 89 coordInputX->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max()); 66 coordInputX->setValue(temp [0]);90 coordInputX->setValue(temporary[0]); 67 91 // coordInputX->setRange(0,M.at(i,i)); 68 92 coordInputX->setDecimals(3); … … 70 94 coordInputY = new QDoubleSpinBox(); 71 95 coordInputY->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max()); 72 coordInputY->setValue(temp [1]);96 coordInputY->setValue(temporary[1]); 73 97 // coordInputY->setRange(0,M.at(i,i)); 74 98 coordInputY->setDecimals(3); … … 76 100 coordInputZ = new QDoubleSpinBox(); 77 101 coordInputZ->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max()); 78 coordInputZ->setValue(temp [2]);102 coordInputZ->setValue(temporary[2]); 79 103 // coordInputZ->setRange(0,M.at(i,i)); 80 104 coordInputZ->setDecimals(3); … … 83 107 connect(coordInputY,SIGNAL(valueChanged(double)),this,SLOT(onUpdateY(double))); 84 108 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 ® = 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 85 127 parent->addLayout(mainLayout); 86 128 } … … 89 131 {} 90 132 133 static 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 141 void 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 164 void QtDialog::VectorQtQuery::onUpdateName(int index) { 165 const QString itemtext = nameComboBox->itemText(index); 166 temp = itemtext.toStdString(); 167 dialog->update(); 168 } 169 91 170 void QtDialog::VectorQtQuery::onUpdateX(double newDouble) { 92 temp[0] = newDouble;171 updateVectorString(temp, newDouble, 0); 93 172 dialog->update(); 94 173 } 95 174 96 175 void QtDialog::VectorQtQuery::onUpdateY(double newDouble) { 97 temp[1] = newDouble;176 updateVectorString(temp, newDouble, 1); 98 177 dialog->update(); 99 178 } 100 179 101 180 void QtDialog::VectorQtQuery::onUpdateZ(double newDouble) { 102 temp[2] = newDouble;181 updateVectorString(temp, newDouble, 2); 103 182 dialog->update(); 104 183 } -
src/UIElements/TextUI/Query/VectorsTextQuery.cpp
r2eded3e rf79d65 41 41 #include "CodePatterns/Log.hpp" 42 42 #include "CodePatterns/Verbose.hpp" 43 #include "Geometry/GeometryRegistry.hpp" 43 44 #include "LinearAlgebra/Vector.hpp" 44 45 #include "LinearAlgebra/RealSpaceMatrix.hpp" … … 54 55 55 56 bool TextDialog::VectorsTextQuery::handle() { 57 std::stringstream output; 56 58 std::cout << getDescription() << std::endl; 57 59 char coords[3] = {'x', 'y', 'z'}; 58 60 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) ? "], " : "]: "); 61 65 62 std::string line;63 getline(std::cin,line);66 std::string line; 67 getline(std::cin,line); 64 68 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 ® = 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; 83 76 } 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); 91 82 } 92 83 }
Note:
See TracChangeset
for help on using the changeset viewer.