source: src/UIElements/Dialog.hpp@ 0e5d14

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

Merge branch 'Candidate_v1.3.0' into stable

Conflicts:

src/Actions/unittests/stubs/DummyUI.hpp
src/UIElements/CommandLineUI/CommandLineDialog.cpp
src/UIElements/CommandLineUI/CommandLineDialog.hpp
src/UIElements/Dialog.cpp
src/UIElements/Dialog.hpp
src/UIElements/Makefile.am
src/UIElements/Qt4/QtDialog.cpp
src/UIElements/Qt4/QtDialog.hpp
src/UIElements/TextUI/TextDialog.cpp
src/UIElements/TextUI/TextDialog.hpp

  • Property mode set to 100644
File size: 19.1 KB
Line 
1/*
2 * Dialog.hpp
3 *
4 * Created on: Jan 5, 2010
5 * Author: crueger
6 */
7
8#ifndef DIALOG_HPP_
9#define DIALOG_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16
17#include<string>
18#include<list>
19#include<vector>
20
21#include <boost/filesystem.hpp>
22#include "LinearAlgebra/RealSpaceMatrix.hpp"
23#include "LinearAlgebra/Vector.hpp"
24#include "RandomNumbers/RandomNumberDistribution_Parameters.hpp"
25#include "Parameters/Parameter.hpp"
26
27class atom;
28class RealSpaceMatrix;
29class element;
30class molecule;
31
32
33/** Dialog is one of the two main classes of the UIFactory base class.
34 *
35 * The Dialog is meant for asking the user for information needed to perform
36 * actions he desires, such as asking for a position in space or a length.
37 *
38 * For this purpose there is the base class Query and numerous specializations
39 * for each of the types to be asked. There are primitives integer, doubles and
40 * string, but also advanced types such as element, molecule or Vector. There
41 * is also an empty query for displaying text.
42 *
43 * Note that the templatization of Dialog::query() allows for easy implementation
44 * of new types that correspond to/are derived from old ones.
45 *
46 * <H3>How do Dialogs operate?</H3>
47 *
48 * Dialogs are initiated by Action::FillDialog() function calls. Within Action::Call()
49 * a dialog is created and passed on to FillDialog(), which is specialized in each
50 * specific Action to ask for the specific parameter it needs.
51 *
52 * Dialogs are derived for each of the UI types
53 * -# CommandLineDialog
54 * -# QtDialog
55 * -# TextDialog
56 *
57 * This "asking" for parameters is done via the Query class. There are four types
58 * of Query types:
59 * -# Query, members in class Dialog
60 * -# CommandLineQuery, members in class CommandLineDialog
61 * -# QtQuery, members in class QtDialog
62 * -# TextQuery, members in class TextDialog
63 * Each embodies a certain way of asking the user for the specific type of parameter
64 * needed, e.g. a file via the TextMenu interface would be done in member functions of
65 * TextDialog::FileTextQuery.
66 *
67 *
68 * Generally, the sequence of events is as follows:
69 * -# Action::fillDialog() calls upon Dialog::query<T> for some type T, let's say T
70 * stands for double
71 * -# Dialog::query<double> call a function queryDouble()
72 * -# depending on the currently used UIFactory, the Dialog above is actually either
73 * of the three specialized types, let's say CommandLine. And we see that within
74 * CommandLineDialog we have the respective method ueryDouble() that registers
75 * a new instance of the class CommandLineDialog::DoubleCommandLineQuery.
76 * -# The Query's are first registered, as multiple parameters may be needed for
77 * a single Action and we don't want the popping up of a dialog window for each
78 * alone. Rather, we want to merge the Query's into a single Dialog. Therefore,
79 * they are first registered and then executed in sequence. This is done in
80 * Dialog::display(), i.e. when the dialog is finally shown to the user.
81 * -# Then each of the registered Query's, here our CommandLineDialog::
82 * DoubleCommandLineQuery, constructor is called.
83 * -# This will call the constructor of its base class, where the actual value
84 * is stored and later stored into the ValueStorage class by
85 * Dialog::Query::setResult().
86 * -# Also, e.g. for the Qt interface, the buttons, labels and so forth are
87 * created and added to the dialog.
88 * -# Now the users enters information for each UI something different happens:
89 * -# CommandLine: The actual value retrieval is done by the CommandLineParser and
90 * the boost::program_options library, the value is stored therein for the moment.
91 * (see here: http://www.boost.org/doc/libs/1_44_0/doc/html/program_options/)
92 * -# TextMenu: The value is requested via std::cin from the user.
93 * -# QtMenu: The users enters the value in a Dialog. Due to Qt necessities a
94 * Pipe class obtains the value from the Dialog with Qt's signal/slot mechanism
95 * and put it into Dialog::...Query value.
96 * -# in our case DoubleCommandLineQuery::handle() will be called. The value is
97 * retrieved and put into Dialog::DoubleQuery::tmp
98 * -# Finally, for each Query, also Dialog::DoubleQuery, setResult() is called which
99 * puts the value as a string into the ValueStorage under a given token that is
100 * associated with a type (and thereby we assure type-safety).
101 *
102 * <H3>Regarding derived types of types with already present queries</H3>
103 *
104 * Example: We have got a derived Vector class, called BoxVector, that is by any means
105 * a Vector but with one difference: it is always bound to lie within the current domain.
106 * With regards to type-casting it to and from a string however, nothing is different
107 * between Vector and BoxVector.
108 *
109 * So, do we need a new Query for this?
110 * No.
111 *
112 * We just have to do this:
113 * -# add a specialization of Dialog::query<BoxVector> where queryVector()is used.
114 * @code
115 * template <> void Dialog::query<BoxVector>(const char *token, std::string description) {
116 * queryVector(token, false, description);
117 * }
118 * @endcode
119 * -# make sure that
120 * -# ValueStorage::setCurrentValue() the specialization for class Vector has an
121 * if case also for BoxVector and does something appropriate.
122 * -# ValueStorage::queryCurrentValue() has another specialization doing the same
123 * as for Vector but for BoxVector in its signature.
124 *
125 * And that's all.
126 *
127 *
128 * <H3>Adding new queries</H3>
129 *
130 * Check first whether you really need a new query or whether we can derive it and re-use
131 * one of the present ones.
132 *
133 * Due to the three present UI interfaces we have to add a specific Query for each, here
134 * is a list:
135 * -# add ValueStorage::setCurrentValue() and ValueStorage::queryCurrentValue() for
136 * both types
137 * -# add Dialog::query...()
138 * -# add Dialog::query<>() specialization calling the above function
139 * -# add CommandLineDialog::query...(), TextDialog::query...(), and QtDialog::query...(),
140 * i.e. for each of the three interface
141 * -# add empty definition DummyDialog::query...() to the stub for Action unittests in DummUI.hpp.
142 * -# add Dialog::...Query class with tmp value of desired type
143 * -# add CommandLineDialog::...Query, TextDialog::...Query, QtDialog::...Query
144 * -# you probably also need a QtDialog::...QueryPipe() to handle the signal/slot stuff,
145 * Qt's moc does not like nested classes. Hence, this has to go extra.
146 * -# TypeEnumContainer add new type to query
147 * -# CommandLineParser::AddOptionToParser() add new type to query
148 * -# CommandLineParser_valdiates.[ch]pp: If given above as a new type
149 * program_options::value, define and implement a validate() function here.
150 *
151 */
152class Dialog
153{
154public:
155 Dialog();
156 virtual ~Dialog();
157
158 template <class T> void query(Parameter<T> &, const char *, std::string = "");
159
160 virtual void queryEmpty(const char *, std::string = "")=0;
161 virtual void queryBoolean(Parameter<bool> &, const char *, std::string = "")=0;
162 virtual void queryInt(Parameter<int> &, const char *, std::string = "")=0;
163 virtual void queryInts(Parameter<std::vector<int> > &, const char *, std::string = "")=0;
164 virtual void queryUnsignedInt(Parameter<unsigned int> &, const char *, std::string = "")=0;
165 virtual void queryUnsignedInts(Parameter<std::vector<unsigned int> > &, const char *, std::string = "")=0;
166 virtual void queryDouble(Parameter<double> &, const char*, std::string = "")=0;
167 virtual void queryDoubles(Parameter<std::vector<double> > &, const char*, std::string = "")=0;
168 virtual void queryString(Parameter<std::string> &, const char*, std::string = "")=0;
169 virtual void queryStrings(Parameter<std::vector<std::string> > &, const char*, std::string = "")=0;
170 virtual void queryAtom(Parameter<const atom *> &, const char*,std::string = "")=0;
171 virtual void queryAtoms(Parameter<std::vector<const atom *> > &, const char*,std::string = "")=0;
172 virtual void queryMolecule(Parameter<const molecule *> &, const char*, std::string = "")=0;
173 virtual void queryMolecules(Parameter<std::vector<const molecule *> > &, const char*, std::string = "")=0;
174 virtual void queryVector(Parameter<Vector> &, const char*,bool, std::string = "")=0;
175 virtual void queryVectors(Parameter<std::vector<Vector> > &, const char*,bool, std::string = "")=0;
176 virtual void queryRealSpaceMatrix(Parameter<RealSpaceMatrix> &, const char*, std::string = "")=0;
177 virtual void queryElement(Parameter<const element *> &, const char*, std::string = "")=0;
178 virtual void queryElements(Parameter<std::vector<const element *> > &, const char*, std::string = "")=0;
179 virtual void queryFile(Parameter<boost::filesystem::path> &, const char*, std::string = "")=0;
180 virtual void queryFiles(Parameter< std::vector<boost::filesystem::path> > &, const char*, std::string = "")=0;
181 virtual void queryRandomNumberDistribution_Parameters(Parameter<RandomNumberDistribution_Parameters> &, const char*, std::string = "")=0;
182
183 virtual bool display();
184
185 virtual bool checkAll();
186 virtual void setAll();
187
188 virtual bool hasQueries();
189
190protected:
191 // methodology for handling queries
192 // all queries are stored and then performed at appropriate times
193
194 //these queries can be handled by this dialog
195
196 //TODO: Find a way to reduce complexity...
197 //needs O(N*M) query classes, where N is the number of query types and M is the number of GUIs
198 //usual approach for reducing inheritance complexity (strategy pattern) does not work,
199 //due to lack of common code for query types as well as GUI-Types (all subtypes differ a lot)
200
201 /** Base class for all queries.
202 *
203 * A query is request to the user for a value of a specific type.
204 * E.g. All \ref Action's need parameters to perform a specific function.
205 * These are obtained from the user at run-time via a Query regardless
206 * of the interface that the user is using.
207 *
208 * A Query always contains a protected member variable of the specific type.
209 * For each type there is a derived class, e.g. for a boolean there is
210 * \ref BooleanQuery deriving from \ref Query. Each specific UI derives
211 * again from a specific Query, e.g. for the \link userinterfaces-textmenu
212 * textmenu \endlink we have \ref BooleanTextQuery that derives from
213 * \ref BooleanQuery. This derived class has to implement the Query::handle
214 * function that actually sets the protected member variable to something
215 * the user has entered. Also it implements Query::setResult that actually
216 * places the obtained value in the \ref ValueStorage.
217 *
218 * \section query-howto How to add another query?
219 *
220 * Let's say we want to query for a type called \a Value.
221 *
222 * Then, we do the following:
223 * -# Add a class ValueQuery inside class Dialog, the class contains
224 * -# constructor/destructor (latter virtual! because of derived class)
225 * -# virtual bool handle() and virtual void setResult()
226 * -# a protected member tmp of type Value (NOTE: herein the result is stored)
227 * -# if temporaries for conversion are needed put them in here
228 * -# add a function queryValue
229 * -# now, for each of the GUIs we basically have to repeat the above, i.e.
230 * add the class and the function that implement the virtual ones above.
231 * -# QT: an extra class called ValueQtQueryPipe that actually handles
232 * showing dialogs to obtain the value and placing it into the \a tmp
233 * variable (via a given pointer to it as reference). handle() will
234 * simply return true. This is needed because of a restriction of Qt4:
235 * its meta-object-compiler does not like nested classes.
236 * -# CommandLine: nothing special, handle() imports value from \a
237 * CommandLineParser and sets the tmp variable.
238 * -# Text: nothing special, handle() queries the user and sets the tmp
239 * variable
240 */
241 class Query {
242 friend class Dialog;
243 public:
244 Query(std::string _title, std::string _description = "");
245 virtual ~Query();
246 virtual bool handle()=0;
247 virtual void setResult()=0;
248 protected:
249 const std::string getTitle() const;
250 const std::string getDescription() const;
251 private:
252 std::string title; //!< short title of the query
253 std::string description; //!< longer description for tooltips or for help
254 };
255
256 // Empty Query is just meant for showing text, such as version, help, initial message or alike
257 class EmptyQuery : public Query {
258 public:
259 EmptyQuery(std::string title, std::string _description = "");
260 virtual ~EmptyQuery();
261 virtual bool handle()=0;
262 virtual void setResult();
263 };
264
265 //Specialized classes for certain types. GUI-Types are not specialized at this time
266 class BooleanQuery : public Query {
267 public:
268 BooleanQuery(Parameter<bool> &param, std::string title, std::string _description = "");
269 virtual ~BooleanQuery();
270 virtual bool handle()=0;
271 virtual void setResult();
272 protected:
273 Parameter<bool> &tmp;
274 };
275
276 class IntQuery : public Query {
277 public:
278 IntQuery(Parameter<int> &param, std::string title, std::string _description = "");
279 virtual ~IntQuery();
280 virtual bool handle()=0;
281 virtual void setResult();
282 protected:
283 Parameter<int> &tmp;
284 };
285
286 class IntsQuery : public Query {
287 public:
288 IntsQuery(Parameter<std::vector<int> > &, std::string title, std::string _description = "");
289 virtual ~IntsQuery();
290 virtual bool handle()=0;
291 virtual void setResult();
292 protected:
293 int temp;
294 Parameter<std::vector<int> > &tmp;
295 };
296
297 class UnsignedIntQuery : public Query {
298 public:
299 UnsignedIntQuery(Parameter<unsigned int> &, std::string title, std::string _description = "");
300 virtual ~UnsignedIntQuery();
301 virtual bool handle()=0;
302 virtual void setResult();
303 protected:
304 Parameter<unsigned int> &tmp;
305 };
306
307 class UnsignedIntsQuery : public Query {
308 public:
309 UnsignedIntsQuery(Parameter<std::vector<unsigned int> > &, std::string title, std::string _description = "");
310 virtual ~UnsignedIntsQuery();
311 virtual bool handle()=0;
312 virtual void setResult();
313 protected:
314 unsigned int temp;
315 Parameter<std::vector<unsigned int> > &tmp;
316 };
317
318 class DoubleQuery : public Query {
319 public:
320 DoubleQuery(Parameter<double> &, std::string title, std::string _description = "");
321 virtual ~DoubleQuery();
322 virtual bool handle()=0;
323 virtual void setResult();
324 protected:
325 Parameter<double> &tmp;
326 };
327
328 class DoublesQuery : public Query {
329 public:
330 DoublesQuery(Parameter<std::vector<double> > &, std::string title, std::string _description = "");
331 virtual ~DoublesQuery();
332 virtual bool handle()=0;
333 virtual void setResult();
334 protected:
335 double temp;
336 Parameter<std::vector<double> > &tmp;
337 };
338
339 class StringQuery : public Query {
340 public:
341 StringQuery(Parameter<std::string> &param, std::string title, std::string _description = "");
342 virtual ~StringQuery();
343 virtual bool handle()=0;
344 virtual void setResult();
345 protected:
346 Parameter<std::string> &tmp;
347 };
348
349 class StringsQuery : public Query {
350 public:
351 StringsQuery(Parameter<std::vector<std::string> > &param, std::string title, std::string _description = "");
352 virtual ~StringsQuery();
353 virtual bool handle()=0;
354 virtual void setResult();
355 protected:
356 std::string temp;
357 Parameter<std::vector<std::string> > &tmp;
358 };
359
360 class MoleculeQuery : public Query {
361 public:
362 MoleculeQuery(Parameter<const molecule *> &param, std::string title, std::string _description = "");
363 virtual ~MoleculeQuery();
364 virtual bool handle()=0;
365 virtual void setResult();
366 protected:
367 Parameter<const molecule *> &tmp;
368 };
369
370 class MoleculesQuery : public Query {
371 public:
372 MoleculesQuery(Parameter<std::vector<const molecule *> > &param, std::string title, std::string _description = "");
373 virtual ~MoleculesQuery();
374 virtual bool handle()=0;
375 virtual void setResult();
376 protected:
377 const molecule * temp;
378 Parameter<std::vector<const molecule *> > &tmp;
379 };
380
381 class AtomQuery : public Query {
382 public:
383 AtomQuery(Parameter<const atom *> &param, std::string title, std::string _description = "");
384 virtual ~AtomQuery();
385 virtual bool handle()=0;
386 virtual void setResult();
387 protected:
388 Parameter<const atom *> &tmp;
389 };
390
391 class AtomsQuery : public Query {
392 public:
393 AtomsQuery(Parameter<std::vector<const atom *> > &param, std::string title, std::string _description = "");
394 virtual ~AtomsQuery();
395 virtual bool handle()=0;
396 virtual void setResult();
397 protected:
398 const atom *temp;
399 Parameter<std::vector<const atom *> > &tmp;
400 };
401
402 class VectorQuery : public Query {
403 public:
404 VectorQuery(Parameter<Vector> &param, std::string title,bool _check, std::string _description = "");
405 virtual ~VectorQuery();
406 virtual bool handle()=0;
407 virtual void setResult();
408 protected:
409 Parameter<Vector> &tmp;
410 bool check;
411 };
412
413 class VectorsQuery : public Query {
414 public:
415 VectorsQuery(Parameter<std::vector<Vector> > &param, std::string title,bool _check, std::string _description = "");
416 virtual ~VectorsQuery();
417 virtual bool handle()=0;
418 virtual void setResult();
419 protected:
420 Vector temp;
421 Parameter<std::vector<Vector> > &tmp;
422 bool check;
423 };
424
425 class RealSpaceMatrixQuery : public Query {
426 public:
427 RealSpaceMatrixQuery(Parameter<RealSpaceMatrix> &param, std::string title, std::string _description = "");
428 virtual ~RealSpaceMatrixQuery();
429 virtual bool handle()=0;
430 virtual void setResult();
431 protected:
432 Parameter<RealSpaceMatrix> &tmp;
433 };
434
435 class ElementQuery : public Query {
436 public:
437 ElementQuery(Parameter<const element*> &param, std::string title, std::string _description = "");
438 virtual ~ElementQuery();
439 virtual bool handle()=0;
440 virtual void setResult();
441 protected:
442 Parameter<const element *> &tmp;
443 };
444
445 class ElementsQuery : public Query {
446 public:
447 ElementsQuery(Parameter<std::vector<const element *> > &param, std::string title, std::string _description = "");
448 virtual ~ElementsQuery();
449 virtual bool handle()=0;
450 virtual void setResult();
451 protected:
452 const element *temp;
453 Parameter<std::vector<const element *> > &tmp;
454 };
455
456 class FileQuery : public Query {
457 public:
458 FileQuery(Parameter<boost::filesystem::path> &param, std::string title, std::string _description = "");
459 virtual ~FileQuery();
460 virtual bool handle()=0;
461 virtual void setResult();
462 protected:
463 Parameter<boost::filesystem::path> &tmp;
464 };
465
466 class FilesQuery : public Query {
467 public:
468 FilesQuery(Parameter<std::vector<boost::filesystem::path> > &param, std::string title, std::string _description = "");
469 virtual ~FilesQuery();
470 virtual bool handle()=0;
471 virtual void setResult();
472 protected:
473 Parameter<std::vector<boost::filesystem::path> > &tmp;
474 };
475
476 class RandomNumberDistribution_ParametersQuery : public Query {
477 public:
478 RandomNumberDistribution_ParametersQuery(Parameter<RandomNumberDistribution_Parameters> &param, std::string title, std::string _description = "");
479 virtual ~RandomNumberDistribution_ParametersQuery();
480 virtual bool handle()=0;
481 virtual void setResult();
482 protected:
483 Parameter<RandomNumberDistribution_Parameters> &tmp;
484 };
485
486void registerQuery(Query* query);
487
488private:
489 std::list<Query*> queries;
490
491};
492
493
494#endif /* DIALOG_HPP_ */
Note: See TracBrowser for help on using the repository browser.