Changeset b59da6 for src/UIElements/Menu/Menu.cpp
- Timestamp:
- Dec 4, 2010, 11:33:47 PM (14 years ago)
- Branches:
- 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
- Children:
- 0af7ef
- Parents:
- 5813ac
- git-author:
- Frederik Heber <heber@…> (11/08/10 09:36:45)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:33:47)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Menu/Menu.cpp
r5813ac rb59da6 20 20 #include "Helpers/MemDebug.hpp" 21 21 22 #include "Menu.hpp"22 #include <iostream> 23 23 24 Menu::Menu() 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 */ 32 Menu::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 */ 42 Menu::~Menu() 43 {} 44 45 /** Initialiser for class Menu. 46 * Fills menus with items. 47 */ 48 void Menu::init() 25 49 { 26 // TODO Auto-generated constructor stub27 50 populate(); 51 populateActions(); 28 52 } 29 53 30 Menu::~Menu() 54 /** Initializing function. 55 * Inserts Menus and Actions obtained from MenuDescription and 56 * ActionRegistry. 57 */ 58 void Menu::populate() 31 59 { 32 // TODO Auto-generated destructor stub 60 // go through all menus and create them 61 62 bool CompleteFlag = false; // indicates whether all menus have been added 63 bool PossibleMissingFlag = false; // indicates whether a separator is missing 64 while (!CompleteFlag) { 65 CompleteFlag = true; 66 PossibleMissingFlag = false; 67 for(MenuDescription::const_iterator iter = menudescriptions.getBeginIter(); 68 iter != menudescriptions.getEndIter(); 69 ++iter) { 70 // skip when already present 71 if (!isPresent(iter->first)) { 72 // have some short refs to infos 73 const std::string &MenuName = iter->first; 74 const std::string &TopName = iter->second.first; 75 const int &MenuPosition = iter->second.second; 76 std::cout << "MenuName is " << MenuName 77 << ", TopName is " << TopName 78 << " and Position is " << MenuPosition 79 << std::endl; 80 81 // does it belong to us? 82 if (TopName == name) { 83 if (MenuPosition-1 == TopPosition) { 84 Menu::addSubmenu(MenuName, MenuPosition); 85 CompleteFlag = false; 86 } 87 // is there a menuposition specified that we have not reached yet? 88 if (MenuPosition-1 > TopPosition) 89 PossibleMissingFlag = true; 90 } 91 } 92 } 93 if (PossibleMissingFlag && (CompleteFlag)) { 94 Menu::addSeparator(); 95 CompleteFlag = false; // pass once more as there should be a menu to come 96 } 97 } 33 98 } 99 100 /** Fills this menu with all Actions that belong to it. 101 */ 102 void Menu::populateActions() 103 { 104 // go through all actions and add those beloning to this menu 105 ActionRegistry &AR = ActionRegistry::getInstance(); 106 for (ActionRegistry::const_iterator iter = AR.getBeginIter(); 107 iter != AR.getEndIter(); 108 ++iter) { 109 const std::string &MenuName = iter->second->Traits.getMenuName(); 110 if (MenuName == name) { 111 const std::string &ActionName = iter->first; 112 Menu::addAction(ActionName); 113 } 114 } 115 } 116 117 void Menu::addAction(const std::string &ActionName) 118 { 119 LastItem = ActionItem; 120 addActionItem(ActionName, ActionName); 121 } 122 123 void Menu::addSeparator() 124 { 125 std::cout << "Creating separator at position " << TopPosition << std::endl; 126 ASSERT( LastItem != SeparatorItem, 127 "Menu::populate() - adding another separator after a separator!"); 128 LastItem = SeparatorItem; 129 addSeparatorItem(); 130 TopPosition++; 131 } 132 133 void Menu::addSubmenu(const std::string &MenuName, const int MenuPosition) 134 { 135 std::cout << "Creating top-level menu " << MenuName 136 << " at position " << TopPosition << std::endl; 137 ASSERT (!isPresent(MenuName), 138 "Menu::addSubmenu() - trying to add menu "+MenuName+" with already present token!"); 139 addSubmenuItem(MenuName, menudescriptions.getDescription(MenuName)); 140 DuplicatesList.insert(MenuName); 141 LastItem = MenuItem; 142 TopPosition = MenuPosition; 143 } 144 145 bool Menu::isPresent(const std::string &token) 146 { 147 return (DuplicatesList.find(token) != DuplicatesList.end()); 148 }
Note:
See TracChangeset
for help on using the changeset viewer.