source: src/UIElements/Dialog.cpp@ 0d4168

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 0d4168 was 0d4168, checked in by Frederik Heber <heber@…>, 11 years ago

Allow setting of invalid values in Value class, Action::performCall() catches ParameterExceptions.

Value changes:

  • Values are now checked with get().
  • having the Actions fill their parameters on instantiation may lead to invalid values because actions that, e.g. add an atom and thereby make a so far invalid atomic id now valid, still have to get executed.
  • hence, we allow setting of invalid values. Validity is check/enforced on get(), i.e. when the Action is actually performed and not before. This is also the very moment where the parameters are first required to be valid.
  • Parameter::clone() and copy cstor must not use get() as invalid values are there still allowed.
  • TESTFIX: Value behavior changed.
  • TESTFIX: regression test add atom outside boundary is working again.
  • TESTFIX: regression tests load/store-session would be skipped as loading non-present file fails now. We use --help --actionname instead.

Action changes:

  • are turned into Action::failure.
  • ActionQueue calling an Action wrapped in try/catch-block for ActionFailure.
  • removed try/catch in doUI().
  • as exception (will) occur in ActionQueue's queue_thread, we need to catch it there. As the only thing we do is set the exit flag of the World. We can do this in ActionQueue as well.
  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
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/>.
21 */
22
23/*
24 * Dialog.cpp
25 *
26 * Created on: Jan 5, 2010
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "Dialog.hpp"
38
39#include "CodePatterns/Log.hpp"
40#include "CodePatterns/Verbose.hpp"
41
42#include "Parameters/ParameterExceptions.hpp"
43
44class Atom;
45class element;
46class RealSpaceMatrix;
47class molecule;
48class Vector;
49
50using namespace std;
51
52Dialog::Dialog()
53{
54}
55
56Dialog::~Dialog()
57{
58 list<Query*>::iterator iter;
59 for(iter=queries.begin();iter!=queries.end();iter++){
60 delete (*iter);
61 }
62}
63
64void Dialog::registerQuery(Query *query){
65 queries.push_back(query);
66}
67
68bool Dialog::display(){
69 handleAll();
70 setAll();
71 return true;
72// if(checkAll()){
73// setAll();
74// return true;
75// }
76// else{
77// return false;
78// }
79}
80
81void Dialog::handleAll(){
82 list<Query*>::iterator iter;
83 for(iter=queries.begin(); iter!=queries.end(); iter++){
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() << ".");
89 break;
90 }
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();
99 // if any query fails (is canceled), we can end the handling process
100 if(!retval) {
101 ELOG(1, "The following query failed: " << (**iter).getTitle() << ".");
102 break;
103 }
104 }
105 return retval;
106}
107
108void Dialog::setAll(){
109 list<Query*>::iterator iter;
110 for(iter=queries.begin(); iter!=queries.end(); iter++) {
111// try {
112 (*iter)->setResult();
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// }
118 }
119}
120
121bool Dialog::hasQueries(){
122 return queries.size();
123}
124
125/*template <> void Dialog::query<Dialog::EmptyType>(Parameter<Dialog::EmptyType> &param, const std::string title, const std::string description)
126{
127 queryEmpty(param, title, description);
128}*/
129
130template <> void Dialog::query<bool>(Parameter<bool> &param, const std::string title, const std::string description)
131{
132 queryBoolean(param, title, description);
133}
134
135template <> void Dialog::query<int>(Parameter<int> &param, const std::string title, const std::string description)
136{
137 queryInt(param, title, description);
138}
139
140template <> void Dialog::query< std::vector<int> >(Parameter<std::vector<int> > &param, const std::string title, const std::string description)
141{
142 queryInts(param, title, description);
143}
144
145template <> void Dialog::query<unsigned int>(Parameter<unsigned int> &param, const std::string title, const std::string description)
146{
147 queryUnsignedInt(param, title, description);
148}
149
150template <> void Dialog::query< std::vector<unsigned int> >(Parameter<std::vector<unsigned int> > &param, const std::string title, const std::string description)
151{
152 queryUnsignedInts(param, title, description);
153}
154
155template <> void Dialog::query<double>(Parameter<double> &param, const std::string title, const std::string description)
156{
157 queryDouble(param, title, description);
158}
159
160template <> void Dialog::query< std::vector<double> >(Parameter<std::vector<double> > &param, const std::string title, const std::string description)
161{
162 queryDoubles(param, title, description);
163}
164
165template <> void Dialog::query<std::string>(Parameter<std::string> &param, const std::string title, const std::string description)
166{
167 queryString(param, title, description);
168}
169
170template <> void Dialog::query< std::vector<std::string> >(Parameter<std::vector<std::string> > &param, const std::string title, const std::string description)
171{
172 queryStrings(param, title, description);
173}
174
175template <> void Dialog::query<const atom *>(Parameter<const atom *> &param, const std::string title, const std::string description)
176{
177 queryAtom(param, title, description);
178}
179
180template <> void Dialog::query< std::vector<const atom *> >(Parameter<std::vector<const atom *> > &param, const std::string title, const std::string description)
181{
182 queryAtoms(param, title, description);
183}
184
185template <> void Dialog::query<const molecule *>(Parameter<const molecule *> &param, const std::string title, const std::string description)
186{
187 queryMolecule(param, title, description);
188}
189
190template <> void Dialog::query< std::vector<const molecule *> >(Parameter<std::vector<const molecule *> > &param, const std::string title, const std::string description)
191{
192 queryMolecules(param, title, description);
193}
194
195template <> void Dialog::query<Vector>(Parameter<Vector> &param, const std::string title, const std::string description)
196{
197 queryVector(param, title, description);
198}
199
200template <> void Dialog::query< std::vector<Vector> >(Parameter<std::vector<Vector> > &param, const std::string title, const std::string description)
201{
202 queryVectors(param, title, description);
203}
204
205template <> void Dialog::query<RealSpaceMatrix>(Parameter<RealSpaceMatrix> &param, const std::string title, const std::string description)
206{
207 queryRealSpaceMatrix(param, title, description);
208}
209
210template <> void Dialog::query<const element *>(Parameter<const element *> &param, const std::string title, const std::string description)
211{
212 queryElement(param, title, description);
213}
214
215template <> void Dialog::query< std::vector<const element *> >(Parameter<std::vector<const element *> > &param, const std::string title, const std::string description)
216{
217 queryElements(param, title, description);
218}
219
220template <> void Dialog::query< boost::filesystem::path >(Parameter<boost::filesystem::path> &param, const std::string title, const std::string description)
221{
222 queryFile(param, title, description);
223}
224
225template <> void Dialog::query< std::vector<boost::filesystem::path> >(Parameter<std::vector< boost::filesystem::path> > &param, const std::string title, const std::string description)
226{
227 queryFiles(param, title, description);
228}
229
230template <> void Dialog::query< RandomNumberDistribution_Parameters >(Parameter<RandomNumberDistribution_Parameters> &param, const std::string title, const std::string description)
231{
232 queryRandomNumberDistribution_Parameters(param, title, description);
233}
234
235/************************** Query Infrastructure ************************/
236/* ---> shifted to folder Query */
237/************************************************************************/
Note: See TracBrowser for help on using the repository browser.