source: src/UIElements/Dialog.hpp@ 9f9b5a

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 9f9b5a was e4afb4, checked in by Frederik Heber <heber@…>, 14 years ago

Huge refactoring: Introduction of Traits to Actions.

This change is really big but the introduction of the Trait concept (at least
in its current light form) is so fundamental that lots of pieces had to be
changed in order to get everything working.

The main point why it was necessary to add these traits in the first place was
to comfortably allow for adding extension of Actions information-wise, i.e.
with stuff that is only important for the QtUI, such as icons, or tooltips, ...
This extra information should not be stored with Action itself, as it has
nothing to do with the workings of the Action. And neither should it get
stored with some blown-out-of-proportions MapOfActions class ...

The gist of the change is as follows:

  • OptionTrait contains the token, description, shortform and type of an option, such as ("position", "position in space, none, typeid(Vector)).
  • ActionTrait is the derived form for actions where additionally MenuPosition and MenuName are stored (and probably more to come for the GUI), also we have a set of OptionTrait instances, one for each option of the Action.
  • Action then contains this ActionTrait, specialized for each Action.
  • the preprocessor macros have been enhanced to gather all this information from the .def files.
  • MapOfActions is gone. Completely. Most of its use was to store this extra information and the ValueStorage part now is just in class ValueStorage.
  • ValueStorage is no more an interface to MapOfActions but as the name says a (type-safe) ValueStorage.

Listing the (remaining) changes in alphabetical order of the class:

  • Action
    • member value ::name dropped, ::getName() uses ActionTraits::getName()
    • new define NODEFAULT which is used in paramdefaults in .def files
    • all derived actions classes such as Process, Calculations, MakroAction,... have been adapated to use the ActionTrait concept as well.
  • ActionHistory
    • extraced RedoAction and UndoAction, shifted implementation into their own object files and they use .def files as well (i.e. streamlined with method used for other actions)
  • MenuDescription
    • contain information on Menus such as name, ...
    • new unit test checks for consistency
  • molecule
    • const member functions: Copy(), Output() and OutputBonds()
  • OptionRegistry
    • new registry class for options only
    • we want the same type throughout the code for each token, e.g. "position"
    • the registry containts checks for consistency
  • OptionTrait
    • default values are specified in paramdefaults, none are given by NODEFAULT
    • introduced default for translate-atoms, point-correlation, pair-correlation
  • Registry pattern
    • new unit test, but only sceleton code so far
  • ...Query, also ...Pipe
    • atoms, molecule and elements are now all const
    • also ValueStorage's signatures all have const therein
  • ValueStorage
    • set/queryCurrentValue from MapOfActions
    • at times VectorValue has been in .def files where Vector was in the signature. This is cleared. Such stuff is only present for e.g. BoxVector being queried as a Vector. But this is a feature and intended.
  • World
    • most of the (un)selection functions now work on const atoms and molecules
    • in one case we need a const_cast to remove this, but this is intentional, as the vector of selected atoms stores non-const pointers and this is ok.

There is only one test which had to be changed slightly because a specific
option token as "position" must now have the same type everywhere, e.g. always
Vector.

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