source: src/UIElements/Dialog.cpp@ 4cac6c

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
Last change on this file since 4cac6c was 37a67f, checked in by Frederik Heber <heber@…>, 10 years ago

Replaced Query.. class and query..() function declarations in Dialog.. by boost preprocessor magic.

  • this removes a lot of copy&paste code.
  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[bcf653]21 */
22
[f5a86a]23/*
24 * Dialog.cpp
25 *
26 * Created on: Jan 5, 2010
27 * Author: crueger
28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
[ad011c]35#include "CodePatterns/MemDebug.hpp"
[112b09]36
[5079a0]37#include "Dialog.hpp"
[f5a86a]38
[ad011c]39#include "CodePatterns/Log.hpp"
40#include "CodePatterns/Verbose.hpp"
[8df74d]41
[e45c1d]42#include "Parameters/ParameterExceptions.hpp"
43
[8df74d]44class Atom;
45class element;
[cca9ef]46class RealSpaceMatrix;
[8df74d]47class molecule;
48class Vector;
[2ededc2]49
[f5a86a]50using namespace std;
51
[163110]52Dialog::Dialog(const std::string &_title)
[f5a86a]53{
54}
55
56Dialog::~Dialog()
57{
[45f5d6]58 list<Query*>::iterator iter;
59 for(iter=queries.begin();iter!=queries.end();iter++){
60 delete (*iter);
61 }
[f5a86a]62}
63
[45f5d6]64void Dialog::registerQuery(Query *query){
65 queries.push_back(query);
66}
[f5a86a]67
[45f5d6]68bool Dialog::display(){
[852ea3]69 handleAll();
[0d4168]70 setAll();
71 return true;
72// if(checkAll()){
73// setAll();
74// return true;
75// }
76// else{
77// return false;
78// }
[d3a5ea]79}
80
[852ea3]81void Dialog::handleAll(){
[45f5d6]82 list<Query*>::iterator iter;
83 for(iter=queries.begin(); iter!=queries.end(); iter++){
[852ea3]84 try{
85 (*iter)->handle();
86 }catch(...){
87 // if any query fails (is canceled), we can end the handling process
88 ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
[e45c1d]89 break;
90 }
[852ea3]91 }
92}
93
94bool Dialog::checkAll(){
95 list<Query*>::iterator iter;
96 bool retval = true;
97 for(iter=queries.begin(); iter!=queries.end(); iter++){
98 retval &= (*iter)->isValid();
[45f5d6]99 // if any query fails (is canceled), we can end the handling process
[94d131]100 if(!retval) {
[47d041]101 ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
[45f5d6]102 break;
[94d131]103 }
[45f5d6]104 }
105 return retval;
[f5a86a]106}
107
[d3a5ea]108void Dialog::setAll(){
109 list<Query*>::iterator iter;
110 for(iter=queries.begin(); iter!=queries.end(); iter++) {
[0d4168]111// try {
[e45c1d]112 (*iter)->setResult();
[0d4168]113// } catch (ParameterException &e) {
114// if( const std::string *name=boost::get_error_info<ParameterName>(e) )
115// ELOG(1, "The following parameter value is not valid: " << *name << ".");
116// break;
117// }
[d3a5ea]118 }
119}
120
[c508ef5]121bool Dialog::hasQueries(){
[0fe135]122 list<Query*>::iterator iter;
123 size_t nonemptyQueries = 0;
124 for(iter=queries.begin(); iter!=queries.end(); iter++) {
125 // count all queries that not EmptyQuery
126 if (dynamic_cast<Dialog::EmptyQuery *>(*iter) == NULL)
127 ++nonemptyQueries;
128 }
129 return nonemptyQueries != 0;
[c508ef5]130}
131
[f130d4]132/*template <> void Dialog::query<Dialog::EmptyType>(Parameter<Dialog::EmptyType> &param, const std::string title, const std::string description)
[9ee38b]133{
[f130d4]134 queryEmpty(param, title, description);
[1c55b8]135}*/
[9ee38b]136
[37a67f]137/** With the following boost::preprocessor code we generate template
138 * specializations for each desired query types in the abstract class Dialog.
139 */
140#include "UIElements/GlobalListOfParameterQueries.hpp"
141#include "UIElements/Dialog_impl_pre.hpp"
142
143 // print a template body
144 #define dialog_definition(z,n,TOKENLIST,TYPELIST) \
145 template <> void Dialog::query< \
146 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
147 >(Parameter< \
148 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
149 > &param, const std::string title, const std::string description) { \
150 BOOST_PP_CAT(query, BOOST_PP_SEQ_ELEM(n, TOKENLIST)) \
151 (param, title, description); }
152
153 // print template specialization for every query type
154 #if defined GLOBALLISTOFPARAMETERQUERIES_Token && defined GLOBALLISTOFPARAMETERQUERIES_Type
155 #define BOOST_PP_LOCAL_MACRO(n) dialog_definition(~, n, GLOBALLISTOFPARAMETERQUERIES_Token, GLOBALLISTOFPARAMETERQUERIES_Type)
156 #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMETERTOKENS-1)
157 #include BOOST_PP_LOCAL_ITERATE()
158 #endif
159
160 #undef dialog_definition
161
162#include "Dialog_impl_undef.hpp"
163/* End of preprocessor code piece */
164
165//template <> void Dialog::query< std::vector<KeyValuePair> >(Parameter< std::vector<KeyValuePair> > &param, const std::string title, const std::string description)
166//{
167// queryKeyValuePairs(param, title, description);
168//}
[33e801]169
[8df74d]170/************************** Query Infrastructure ************************/
171/* ---> shifted to folder Query */
172/************************************************************************/
Note: See TracBrowser for help on using the repository browser.