| [8bcf3f] | 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 |  * MenuDescription.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Oct 26, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [d2b28f] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [d2b28f] | 21 | 
 | 
|---|
| [ffb9ad] | 22 | #include <iostream>
 | 
|---|
| [8bcf3f] | 23 | #include <map>
 | 
|---|
 | 24 | #include <string>
 | 
|---|
 | 25 | 
 | 
|---|
| [c82d0c] | 26 | //#include "Actions/ActionRegistry.hpp"
 | 
|---|
| [8bcf3f] | 27 | #include "Menu/MenuDescription.hpp"
 | 
|---|
 | 28 | 
 | 
|---|
| [ad011c] | 29 | #include "CodePatterns/Singleton_impl.hpp"
 | 
|---|
| [c82d0c] | 30 | 
 | 
|---|
 | 31 | MenuDescription::TextMap *MenuDescription::MenuDescriptionsMap = NULL;
 | 
|---|
 | 32 | MenuDescription::IterableMap *MenuDescription::MenuPositionMap = NULL;
 | 
|---|
 | 33 | MenuDescription::TextMap *MenuDescription::MenuNameMap = NULL;
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | 
 | 
|---|
| [8bcf3f] | 36 | /** Constructor of class MenuDescription.
 | 
|---|
 | 37 |  *
 | 
|---|
 | 38 |  */
 | 
|---|
 | 39 | MenuDescription::MenuDescription()
 | 
|---|
 | 40 | {
 | 
|---|
| [c82d0c] | 41 |   // allocate maps
 | 
|---|
 | 42 |   MenuDescriptionsMap = new TextMap();
 | 
|---|
 | 43 |   MenuPositionMap = new IterableMap();
 | 
|---|
 | 44 |   MenuNameMap = new TextMap();
 | 
|---|
 | 45 | 
 | 
|---|
| [ffb9ad] | 46 |   // put each menu into its place, "" means top level
 | 
|---|
| [c82d0c] | 47 |   MenuPositionMap->insert(std::make_pair("analysis",TopPosition("tools",1)));
 | 
|---|
 | 48 |   MenuPositionMap->insert(std::make_pair("atom",TopPosition("edit",1)));
 | 
|---|
 | 49 |   MenuPositionMap->insert(std::make_pair("command",TopPosition("",3)));
 | 
|---|
 | 50 |   MenuPositionMap->insert(std::make_pair("edit",TopPosition("",2)));
 | 
|---|
 | 51 |   MenuPositionMap->insert(std::make_pair("fragmentation",TopPosition("tools",3)));
 | 
|---|
| [d09093] | 52 |   MenuPositionMap->insert(std::make_pair("graph",TopPosition("tools",4)));
 | 
|---|
| [c82d0c] | 53 |   MenuPositionMap->insert(std::make_pair("molecule",TopPosition("edit",2)));
 | 
|---|
 | 54 |   MenuPositionMap->insert(std::make_pair("parser",TopPosition("edit",3)));
 | 
|---|
 | 55 |   MenuPositionMap->insert(std::make_pair("selection",TopPosition("edit",4)));
 | 
|---|
 | 56 |   MenuPositionMap->insert(std::make_pair("tesselation",TopPosition("tools",2)));
 | 
|---|
 | 57 |   MenuPositionMap->insert(std::make_pair("tools",TopPosition("",4)));
 | 
|---|
 | 58 |   MenuPositionMap->insert(std::make_pair("world",TopPosition("",1)));
 | 
|---|
| [8bcf3f] | 59 | 
 | 
|---|
 | 60 |   // put menu description into each menu category
 | 
|---|
| [c82d0c] | 61 |   MenuDescriptionsMap->insert(std::make_pair("analysis","Analysis (pair correlation, volume)"));
 | 
|---|
 | 62 |   MenuDescriptionsMap->insert(std::make_pair("atom","Edit atoms"));
 | 
|---|
 | 63 |   MenuDescriptionsMap->insert(std::make_pair("command","Configuration"));
 | 
|---|
 | 64 |   MenuDescriptionsMap->insert(std::make_pair("edit","Edit"));
 | 
|---|
 | 65 |   MenuDescriptionsMap->insert(std::make_pair("fragmentation","Fragmentation"));
 | 
|---|
| [d09093] | 66 |   MenuDescriptionsMap->insert(std::make_pair("graph","Graph"));
 | 
|---|
| [c82d0c] | 67 |   MenuDescriptionsMap->insert(std::make_pair("molecule","Parse files into system"));
 | 
|---|
 | 68 |   MenuDescriptionsMap->insert(std::make_pair("parser","Edit molecules (load, parse, save)"));
 | 
|---|
 | 69 |   MenuDescriptionsMap->insert(std::make_pair("selection","Select atoms/molecules"));
 | 
|---|
 | 70 |   MenuDescriptionsMap->insert(std::make_pair("tesselation","Tesselate molecules"));
 | 
|---|
 | 71 |   MenuDescriptionsMap->insert(std::make_pair("tools","Various tools"));
 | 
|---|
 | 72 |   MenuDescriptionsMap->insert(std::make_pair("world","Edit world"));
 | 
|---|
| [8bcf3f] | 73 | 
 | 
|---|
 | 74 |   // put menu name into each menu category
 | 
|---|
| [c82d0c] | 75 |   MenuNameMap->insert(std::make_pair("analysis","Analysis"));
 | 
|---|
 | 76 |   MenuNameMap->insert(std::make_pair("atom","Atoms"));
 | 
|---|
 | 77 |   MenuNameMap->insert(std::make_pair("command","Configuration"));
 | 
|---|
 | 78 |   MenuNameMap->insert(std::make_pair("edit","Edit"));
 | 
|---|
 | 79 |   MenuNameMap->insert(std::make_pair("fragmentation","Fragmentation"));
 | 
|---|
| [d09093] | 80 |   MenuNameMap->insert(std::make_pair("graph","Graph"));
 | 
|---|
| [c82d0c] | 81 |   MenuNameMap->insert(std::make_pair("molecule","Molecules"));
 | 
|---|
 | 82 |   MenuNameMap->insert(std::make_pair("parser","Input/Output"));
 | 
|---|
 | 83 |   MenuNameMap->insert(std::make_pair("selection","Selection"));
 | 
|---|
 | 84 |   MenuNameMap->insert(std::make_pair("tesselation","Tesselation"));
 | 
|---|
 | 85 |   MenuNameMap->insert(std::make_pair("tools","Tools"));
 | 
|---|
 | 86 |   MenuNameMap->insert(std::make_pair("world","Globals"));
 | 
|---|
| [8bcf3f] | 87 | }
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 | /** Destructor of class MenuDescription.
 | 
|---|
 | 90 |  *
 | 
|---|
 | 91 |  */
 | 
|---|
 | 92 | MenuDescription::~MenuDescription()
 | 
|---|
| [c82d0c] | 93 | {
 | 
|---|
| [ad7270] | 94 |   //std::cout << "MenuDescription: clearing maps ... " << std::endl;
 | 
|---|
| [c82d0c] | 95 |   for (IterableMap::iterator iter = MenuPositionMap->begin(); !MenuPositionMap->empty(); iter = MenuPositionMap->begin())
 | 
|---|
 | 96 |     MenuPositionMap->erase(iter);
 | 
|---|
 | 97 |   delete MenuNameMap;
 | 
|---|
 | 98 |   delete MenuDescriptionsMap;
 | 
|---|
 | 99 |   delete MenuPositionMap;
 | 
|---|
 | 100 | }
 | 
|---|
| [8bcf3f] | 101 | 
 | 
|---|
 | 102 | /** Getter for MenuDescriptionsMap.
 | 
|---|
 | 103 |  * \param token name of menu
 | 
|---|
 | 104 |  * \return description string of the menu or empty
 | 
|---|
 | 105 |  */
 | 
|---|
| [b59da6] | 106 | const std::string MenuDescription::getDescription(const std::string &token) const
 | 
|---|
| [8bcf3f] | 107 | {
 | 
|---|
| [c82d0c] | 108 |   if (MenuDescriptionsMap->find(token) != MenuDescriptionsMap->end())
 | 
|---|
 | 109 |     return MenuDescriptionsMap->find(token)->second;
 | 
|---|
| [8bcf3f] | 110 |   else
 | 
|---|
 | 111 |     return std::string();
 | 
|---|
 | 112 | }
 | 
|---|
 | 113 | 
 | 
|---|
| [c82d0c] | 114 | /** Getter for MenuNameMap->
 | 
|---|
| [8bcf3f] | 115 |  * \param token name of menu
 | 
|---|
 | 116 |  * \return description string of the menu or empty
 | 
|---|
 | 117 |  */
 | 
|---|
| [b59da6] | 118 | const std::string MenuDescription::getName(const std::string &token) const
 | 
|---|
| [8bcf3f] | 119 | {
 | 
|---|
| [c82d0c] | 120 |   if (MenuNameMap->find(token) != MenuNameMap->end())
 | 
|---|
 | 121 |     return MenuNameMap->find(token)->second;
 | 
|---|
| [8bcf3f] | 122 |   else
 | 
|---|
 | 123 |     return std::string();
 | 
|---|
 | 124 | }
 | 
|---|
 | 125 | 
 | 
|---|
| [c82d0c] | 126 | ///** Constructs a multimap of all menus running over all actions belonging to it.
 | 
|---|
 | 127 | // * \return multimap with which actions belongs to which menu.
 | 
|---|
 | 128 | // */
 | 
|---|
 | 129 | //std::multimap <std::string, std::string> MenuDescription::getMenuItemsMap() const
 | 
|---|
 | 130 | //{
 | 
|---|
 | 131 | //  std::multimap <std::string, std::string> result;
 | 
|---|
 | 132 | //
 | 
|---|
 | 133 | //  ActionRegistry &AR = ActionRegistry::getInstance();
 | 
|---|
 | 134 | //  for (ActionRegistry::const_iterator iter = AR.getBeginIter();iter != AR.getEndIter();++iter) {
 | 
|---|
 | 135 | //    std::cout << "Inserting " << (iter->second)->getName() << " into menu " << (iter->second)->Traits.getMenuName() << std::endl;
 | 
|---|
 | 136 | //    result.insert( std::pair<std::string, std::string> ((iter->second)->Traits.getMenuName(), (iter->second)->getName()));
 | 
|---|
 | 137 | //  }
 | 
|---|
 | 138 | //  // TODO: MenuPosition is not yet realized.
 | 
|---|
 | 139 | //  return result;
 | 
|---|
 | 140 | //}
 | 
|---|
| [e4afb4] | 141 | 
 | 
|---|
| [8bcf3f] | 142 | /** Forward iterator from beginning of list of descriptions.
 | 
|---|
 | 143 |  * \return iterator
 | 
|---|
 | 144 |  */
 | 
|---|
 | 145 | MenuDescription::iterator MenuDescription::getBeginIter()
 | 
|---|
 | 146 | {
 | 
|---|
| [c82d0c] | 147 |   return MenuPositionMap->begin();
 | 
|---|
| [8bcf3f] | 148 | }
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | /** Forward iterator at end of list of descriptions.
 | 
|---|
 | 151 |  * \return iterator
 | 
|---|
 | 152 |  */
 | 
|---|
 | 153 | MenuDescription::iterator MenuDescription::getEndIter()
 | 
|---|
 | 154 | {
 | 
|---|
| [c82d0c] | 155 |   return MenuPositionMap->end();
 | 
|---|
| [8bcf3f] | 156 | }
 | 
|---|
 | 157 | 
 | 
|---|
 | 158 | /** Constant forward iterator from beginning of list of descriptions.
 | 
|---|
 | 159 |  * \return constant iterator
 | 
|---|
 | 160 |  */
 | 
|---|
 | 161 | MenuDescription::const_iterator MenuDescription::getBeginIter() const
 | 
|---|
 | 162 | {
 | 
|---|
| [c82d0c] | 163 |   return MenuPositionMap->begin();
 | 
|---|
| [8bcf3f] | 164 | }
 | 
|---|
 | 165 | 
 | 
|---|
 | 166 | /** Constant forward iterator at end of list of descriptions.
 | 
|---|
 | 167 |  * \return constant iterator
 | 
|---|
 | 168 |  */
 | 
|---|
 | 169 | MenuDescription::const_iterator MenuDescription::getEndIter() const
 | 
|---|
 | 170 | {
 | 
|---|
| [c82d0c] | 171 |   return MenuPositionMap->end();
 | 
|---|
| [8bcf3f] | 172 | }
 | 
|---|
 | 173 | 
 | 
|---|
| [c82d0c] | 174 | CONSTRUCT_SINGLETON(MenuDescription)
 | 
|---|