source: src/UIElements/Dialog.hpp@ aec098

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

DOCU: Extended documentation on how values from the user are eventually used by Actions.

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