| [8bcf3f] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [8bcf3f] | 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)));
 | 
|---|
| [a88452] | 51 |   MenuPositionMap->insert(std::make_pair("fill",TopPosition("tools",5)));
 | 
|---|
| [c82d0c] | 52 |   MenuPositionMap->insert(std::make_pair("fragmentation",TopPosition("tools",3)));
 | 
|---|
| [d09093] | 53 |   MenuPositionMap->insert(std::make_pair("graph",TopPosition("tools",4)));
 | 
|---|
| [c82d0c] | 54 |   MenuPositionMap->insert(std::make_pair("molecule",TopPosition("edit",2)));
 | 
|---|
 | 55 |   MenuPositionMap->insert(std::make_pair("parser",TopPosition("edit",3)));
 | 
|---|
 | 56 |   MenuPositionMap->insert(std::make_pair("selection",TopPosition("edit",4)));
 | 
|---|
 | 57 |   MenuPositionMap->insert(std::make_pair("tesselation",TopPosition("tools",2)));
 | 
|---|
 | 58 |   MenuPositionMap->insert(std::make_pair("tools",TopPosition("",4)));
 | 
|---|
 | 59 |   MenuPositionMap->insert(std::make_pair("world",TopPosition("",1)));
 | 
|---|
| [8bcf3f] | 60 | 
 | 
|---|
 | 61 |   // put menu description into each menu category
 | 
|---|
| [c82d0c] | 62 |   MenuDescriptionsMap->insert(std::make_pair("analysis","Analysis (pair correlation, volume)"));
 | 
|---|
 | 63 |   MenuDescriptionsMap->insert(std::make_pair("atom","Edit atoms"));
 | 
|---|
 | 64 |   MenuDescriptionsMap->insert(std::make_pair("command","Configuration"));
 | 
|---|
 | 65 |   MenuDescriptionsMap->insert(std::make_pair("edit","Edit"));
 | 
|---|
| [a88452] | 66 |   MenuDescriptionsMap->insert(std::make_pair("fill","Fill"));
 | 
|---|
| [c82d0c] | 67 |   MenuDescriptionsMap->insert(std::make_pair("fragmentation","Fragmentation"));
 | 
|---|
| [d09093] | 68 |   MenuDescriptionsMap->insert(std::make_pair("graph","Graph"));
 | 
|---|
| [c82d0c] | 69 |   MenuDescriptionsMap->insert(std::make_pair("molecule","Parse files into system"));
 | 
|---|
 | 70 |   MenuDescriptionsMap->insert(std::make_pair("parser","Edit molecules (load, parse, save)"));
 | 
|---|
 | 71 |   MenuDescriptionsMap->insert(std::make_pair("selection","Select atoms/molecules"));
 | 
|---|
 | 72 |   MenuDescriptionsMap->insert(std::make_pair("tesselation","Tesselate molecules"));
 | 
|---|
 | 73 |   MenuDescriptionsMap->insert(std::make_pair("tools","Various tools"));
 | 
|---|
 | 74 |   MenuDescriptionsMap->insert(std::make_pair("world","Edit world"));
 | 
|---|
| [8bcf3f] | 75 | 
 | 
|---|
 | 76 |   // put menu name into each menu category
 | 
|---|
| [c82d0c] | 77 |   MenuNameMap->insert(std::make_pair("analysis","Analysis"));
 | 
|---|
 | 78 |   MenuNameMap->insert(std::make_pair("atom","Atoms"));
 | 
|---|
 | 79 |   MenuNameMap->insert(std::make_pair("command","Configuration"));
 | 
|---|
 | 80 |   MenuNameMap->insert(std::make_pair("edit","Edit"));
 | 
|---|
| [a88452] | 81 |   MenuNameMap->insert(std::make_pair("fill","Fill"));
 | 
|---|
| [c82d0c] | 82 |   MenuNameMap->insert(std::make_pair("fragmentation","Fragmentation"));
 | 
|---|
| [d09093] | 83 |   MenuNameMap->insert(std::make_pair("graph","Graph"));
 | 
|---|
| [c82d0c] | 84 |   MenuNameMap->insert(std::make_pair("molecule","Molecules"));
 | 
|---|
 | 85 |   MenuNameMap->insert(std::make_pair("parser","Input/Output"));
 | 
|---|
 | 86 |   MenuNameMap->insert(std::make_pair("selection","Selection"));
 | 
|---|
 | 87 |   MenuNameMap->insert(std::make_pair("tesselation","Tesselation"));
 | 
|---|
 | 88 |   MenuNameMap->insert(std::make_pair("tools","Tools"));
 | 
|---|
 | 89 |   MenuNameMap->insert(std::make_pair("world","Globals"));
 | 
|---|
| [8bcf3f] | 90 | }
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 | /** Destructor of class MenuDescription.
 | 
|---|
 | 93 |  *
 | 
|---|
 | 94 |  */
 | 
|---|
 | 95 | MenuDescription::~MenuDescription()
 | 
|---|
| [c82d0c] | 96 | {
 | 
|---|
| [ad7270] | 97 |   //std::cout << "MenuDescription: clearing maps ... " << std::endl;
 | 
|---|
| [c82d0c] | 98 |   for (IterableMap::iterator iter = MenuPositionMap->begin(); !MenuPositionMap->empty(); iter = MenuPositionMap->begin())
 | 
|---|
 | 99 |     MenuPositionMap->erase(iter);
 | 
|---|
 | 100 |   delete MenuNameMap;
 | 
|---|
 | 101 |   delete MenuDescriptionsMap;
 | 
|---|
 | 102 |   delete MenuPositionMap;
 | 
|---|
 | 103 | }
 | 
|---|
| [8bcf3f] | 104 | 
 | 
|---|
 | 105 | /** Getter for MenuDescriptionsMap.
 | 
|---|
 | 106 |  * \param token name of menu
 | 
|---|
 | 107 |  * \return description string of the menu or empty
 | 
|---|
 | 108 |  */
 | 
|---|
| [b59da6] | 109 | const std::string MenuDescription::getDescription(const std::string &token) const
 | 
|---|
| [8bcf3f] | 110 | {
 | 
|---|
| [c82d0c] | 111 |   if (MenuDescriptionsMap->find(token) != MenuDescriptionsMap->end())
 | 
|---|
 | 112 |     return MenuDescriptionsMap->find(token)->second;
 | 
|---|
| [8bcf3f] | 113 |   else
 | 
|---|
 | 114 |     return std::string();
 | 
|---|
 | 115 | }
 | 
|---|
 | 116 | 
 | 
|---|
| [c82d0c] | 117 | /** Getter for MenuNameMap->
 | 
|---|
| [8bcf3f] | 118 |  * \param token name of menu
 | 
|---|
 | 119 |  * \return description string of the menu or empty
 | 
|---|
 | 120 |  */
 | 
|---|
| [b59da6] | 121 | const std::string MenuDescription::getName(const std::string &token) const
 | 
|---|
| [8bcf3f] | 122 | {
 | 
|---|
| [c82d0c] | 123 |   if (MenuNameMap->find(token) != MenuNameMap->end())
 | 
|---|
 | 124 |     return MenuNameMap->find(token)->second;
 | 
|---|
| [8bcf3f] | 125 |   else
 | 
|---|
 | 126 |     return std::string();
 | 
|---|
 | 127 | }
 | 
|---|
 | 128 | 
 | 
|---|
| [c82d0c] | 129 | ///** Constructs a multimap of all menus running over all actions belonging to it.
 | 
|---|
 | 130 | // * \return multimap with which actions belongs to which menu.
 | 
|---|
 | 131 | // */
 | 
|---|
 | 132 | //std::multimap <std::string, std::string> MenuDescription::getMenuItemsMap() const
 | 
|---|
 | 133 | //{
 | 
|---|
 | 134 | //  std::multimap <std::string, std::string> result;
 | 
|---|
 | 135 | //
 | 
|---|
 | 136 | //  ActionRegistry &AR = ActionRegistry::getInstance();
 | 
|---|
 | 137 | //  for (ActionRegistry::const_iterator iter = AR.getBeginIter();iter != AR.getEndIter();++iter) {
 | 
|---|
 | 138 | //    std::cout << "Inserting " << (iter->second)->getName() << " into menu " << (iter->second)->Traits.getMenuName() << std::endl;
 | 
|---|
 | 139 | //    result.insert( std::pair<std::string, std::string> ((iter->second)->Traits.getMenuName(), (iter->second)->getName()));
 | 
|---|
 | 140 | //  }
 | 
|---|
 | 141 | //  // TODO: MenuPosition is not yet realized.
 | 
|---|
 | 142 | //  return result;
 | 
|---|
 | 143 | //}
 | 
|---|
| [e4afb4] | 144 | 
 | 
|---|
| [8bcf3f] | 145 | /** Forward iterator from beginning of list of descriptions.
 | 
|---|
 | 146 |  * \return iterator
 | 
|---|
 | 147 |  */
 | 
|---|
 | 148 | MenuDescription::iterator MenuDescription::getBeginIter()
 | 
|---|
 | 149 | {
 | 
|---|
| [c82d0c] | 150 |   return MenuPositionMap->begin();
 | 
|---|
| [8bcf3f] | 151 | }
 | 
|---|
 | 152 | 
 | 
|---|
 | 153 | /** Forward iterator at end of list of descriptions.
 | 
|---|
 | 154 |  * \return iterator
 | 
|---|
 | 155 |  */
 | 
|---|
 | 156 | MenuDescription::iterator MenuDescription::getEndIter()
 | 
|---|
 | 157 | {
 | 
|---|
| [c82d0c] | 158 |   return MenuPositionMap->end();
 | 
|---|
| [8bcf3f] | 159 | }
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 | /** Constant forward iterator from beginning of list of descriptions.
 | 
|---|
 | 162 |  * \return constant iterator
 | 
|---|
 | 163 |  */
 | 
|---|
 | 164 | MenuDescription::const_iterator MenuDescription::getBeginIter() const
 | 
|---|
 | 165 | {
 | 
|---|
| [c82d0c] | 166 |   return MenuPositionMap->begin();
 | 
|---|
| [8bcf3f] | 167 | }
 | 
|---|
 | 168 | 
 | 
|---|
 | 169 | /** Constant forward iterator at end of list of descriptions.
 | 
|---|
 | 170 |  * \return constant iterator
 | 
|---|
 | 171 |  */
 | 
|---|
 | 172 | MenuDescription::const_iterator MenuDescription::getEndIter() const
 | 
|---|
 | 173 | {
 | 
|---|
| [c82d0c] | 174 |   return MenuPositionMap->end();
 | 
|---|
| [8bcf3f] | 175 | }
 | 
|---|
 | 176 | 
 | 
|---|
| [c82d0c] | 177 | CONSTRUCT_SINGLETON(MenuDescription)
 | 
|---|