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

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

Added additional check in CodeCheck's project disclaimer for current year in copyright.

  • had to modify all .cpp files to update to 2011.
  • 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-2011 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 "CodePatterns/MemDebug.hpp"
21
22#include <iostream>
23
24#include "Actions/ActionRegistry.hpp"
25#include "Actions/Action.hpp"
26#include "Actions/ActionTrait.hpp"
27#include "Menu/Menu.hpp"
28
29using namespace MoleCuilder;
30
31/** Constructor of class Menu.
32 * \param &_name name of menu
33 */
34Menu::Menu(const std::string &_name) :
35 MenuInterface(_name),
36 name(_name),
37 TopPosition(0),
38 LastItem(NoItem)
39{}
40
41/** Destructor of class Menu.
42 *
43 */
44Menu::~Menu()
45{
46 DuplicatesList.clear();
47}
48
49/** Initialiser for class Menu.
50 * Fills menus with items.
51 */
52void Menu::init()
53{
54 populate();
55 populateActions();
56}
57
58/** Initializing function.
59 * Inserts Menus and Actions obtained from MenuDescription and
60 * ActionRegistry.
61 */
62void Menu::populate()
63{
64 // go through all menus and create them
65
66 bool CompleteFlag = false; // indicates whether all menus have been added
67 bool PossibleMissingFlag = false; // indicates whether a separator is missing
68 while (!CompleteFlag) {
69 CompleteFlag = true;
70 PossibleMissingFlag = false;
71 for(MenuDescription::const_iterator iter = MenuDescription::getInstance().getBeginIter();
72 iter != MenuDescription::getInstance().getEndIter();
73 ++iter) {
74 // skip when already present
75 if (!isPresent(iter->first)) {
76 // have some short refs to infos
77 const std::string &MenuName = iter->first;
78 const std::string &TopName = iter->second.first;
79 const int &MenuPosition = iter->second.second;
80// std::cout << "MenuName is " << MenuName
81// << ", TopName is " << TopName
82// << " and Position is " << MenuPosition
83// << std::endl;
84
85 // does it belong to us?
86 if (TopName == name) {
87 if (MenuPosition-1 == TopPosition) {
88 Menu::addSubmenu(MenuName, MenuPosition);
89 CompleteFlag = false;
90 }
91 // is there a menuposition specified that we have not reached yet?
92 if (MenuPosition-1 > TopPosition)
93 PossibleMissingFlag = true;
94 }
95 }
96 }
97 if (PossibleMissingFlag && (CompleteFlag)) {
98 Menu::addSeparator();
99 CompleteFlag = false; // pass once more as there should be a menu to come
100 }
101 }
102}
103
104/** Fills this menu with all Actions that belong to it.
105 */
106void Menu::populateActions()
107{
108 // go through all actions and add those beloning to this menu
109 ActionRegistry &AR = ActionRegistry::getInstance();
110 for (ActionRegistry::const_iterator iter = AR.getBeginIter();
111 iter != AR.getEndIter();
112 ++iter) {
113 const std::string &MenuName = iter->second->Traits.getMenuName();
114 if (MenuName == name) {
115 const std::string &ActionName = iter->first;
116 Menu::addAction(ActionName);
117 }
118 }
119}
120
121void Menu::addAction(const std::string &ActionName)
122{
123 LastItem = ActionItem;
124 addActionItem(ActionName, ActionName);
125}
126
127void Menu::addSeparator()
128{
129// std::cout << "Creating separator at position " << TopPosition << std::endl;
130 ASSERT( LastItem != SeparatorItem,
131 "Menu::populate() - adding another separator after a separator!");
132 LastItem = SeparatorItem;
133 addSeparatorItem();
134 TopPosition++;
135}
136
137void Menu::addSubmenu(const std::string &MenuName, const int MenuPosition)
138{
139// std::cout << "Creating top-level menu " << MenuName
140// << " at position " << TopPosition << std::endl;
141 ASSERT (!isPresent(MenuName),
142 "Menu::addSubmenu() - trying to add menu "+MenuName+" with already present token!");
143 addSubmenuItem(MenuName, MenuDescription::getInstance().getDescription(MenuName));
144 DuplicatesList.insert(MenuName);
145 LastItem = MenuItem;
146 TopPosition = MenuPosition;
147}
148
149bool Menu::isPresent(const std::string &token)
150{
151 return (DuplicatesList.find(token) != DuplicatesList.end());
152}
Note: See TracBrowser for help on using the repository browser.