source: src/UIElements/Menu/Menu.cpp@ c82d0c

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

MenuDescription is now a singleton.

  • also all Maps are static objects, allocated and filled dynamically in the constructor, removed in the destructor.
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * Menu.cpp
10 *
11 * Created on: Dec 10, 2009
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "Helpers/MemDebug.hpp"
21
22#include <iostream>
23
24#include "Actions/ActionRegistry.hpp"
25#include "Actions/Action.hpp"
26#include "Actions/ActionTraits.hpp"
27#include "Menu/Menu.hpp"
28
29/** Constructor of class Menu.
30 * \param &_name name of menu
31 */
32Menu::Menu(const std::string &_name) :
33 MenuInterface(_name),
34 name(_name),
35 TopPosition(0),
36 LastItem(NoItem)
37{}
38
39/** Destructor of class Menu.
40 *
41 */
42Menu::~Menu()
43{
44 DuplicatesList.clear();
45}
46
47/** Initialiser for class Menu.
48 * Fills menus with items.
49 */
50void Menu::init()
51{
52 populate();
53 populateActions();
54}
55
56/** Initializing function.
57 * Inserts Menus and Actions obtained from MenuDescription and
58 * ActionRegistry.
59 */
60void Menu::populate()
61{
62 // go through all menus and create them
63
64 bool CompleteFlag = false; // indicates whether all menus have been added
65 bool PossibleMissingFlag = false; // indicates whether a separator is missing
66 while (!CompleteFlag) {
67 CompleteFlag = true;
68 PossibleMissingFlag = false;
69 for(MenuDescription::const_iterator iter = MenuDescription::getInstance().getBeginIter();
70 iter != MenuDescription::getInstance().getEndIter();
71 ++iter) {
72 // skip when already present
73 if (!isPresent(iter->first)) {
74 // have some short refs to infos
75 const std::string &MenuName = iter->first;
76 const std::string &TopName = iter->second.first;
77 const int &MenuPosition = iter->second.second;
78 std::cout << "MenuName is " << MenuName
79 << ", TopName is " << TopName
80 << " and Position is " << MenuPosition
81 << std::endl;
82
83 // does it belong to us?
84 if (TopName == name) {
85 if (MenuPosition-1 == TopPosition) {
86 Menu::addSubmenu(MenuName, MenuPosition);
87 CompleteFlag = false;
88 }
89 // is there a menuposition specified that we have not reached yet?
90 if (MenuPosition-1 > TopPosition)
91 PossibleMissingFlag = true;
92 }
93 }
94 }
95 if (PossibleMissingFlag && (CompleteFlag)) {
96 Menu::addSeparator();
97 CompleteFlag = false; // pass once more as there should be a menu to come
98 }
99 }
100}
101
102/** Fills this menu with all Actions that belong to it.
103 */
104void Menu::populateActions()
105{
106 // go through all actions and add those beloning to this menu
107 ActionRegistry &AR = ActionRegistry::getInstance();
108 for (ActionRegistry::const_iterator iter = AR.getBeginIter();
109 iter != AR.getEndIter();
110 ++iter) {
111 const std::string &MenuName = iter->second->Traits.getMenuName();
112 if (MenuName == name) {
113 const std::string &ActionName = iter->first;
114 Menu::addAction(ActionName);
115 }
116 }
117}
118
119void Menu::addAction(const std::string &ActionName)
120{
121 LastItem = ActionItem;
122 addActionItem(ActionName, ActionName);
123}
124
125void Menu::addSeparator()
126{
127 std::cout << "Creating separator at position " << TopPosition << std::endl;
128 ASSERT( LastItem != SeparatorItem,
129 "Menu::populate() - adding another separator after a separator!");
130 LastItem = SeparatorItem;
131 addSeparatorItem();
132 TopPosition++;
133}
134
135void Menu::addSubmenu(const std::string &MenuName, const int MenuPosition)
136{
137 std::cout << "Creating top-level menu " << MenuName
138 << " at position " << TopPosition << std::endl;
139 ASSERT (!isPresent(MenuName),
140 "Menu::addSubmenu() - trying to add menu "+MenuName+" with already present token!");
141 addSubmenuItem(MenuName, MenuDescription::getInstance().getDescription(MenuName));
142 DuplicatesList.insert(MenuName);
143 LastItem = MenuItem;
144 TopPosition = MenuPosition;
145}
146
147bool Menu::isPresent(const std::string &token)
148{
149 return (DuplicatesList.find(token) != DuplicatesList.end());
150}
Note: See TracBrowser for help on using the repository browser.