source: src/UIElements/TextUI/TextWindow.cpp@ 326bbe

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

Legacy/oldmenu is no more.

  • TextWindow::TextWindow() now properly uses the actions that have been created during the Refactoring of CommandLineUI.
  • removed TextWindow::populateEditMolecules() as there is a more general function now
  • new Textwindow::populateMenu() - populates the menu by looking at MapOfActions::MenuContainsActionMap.
  • new TextWindow::getSuitableShortForm() - educatedly guesses good key for action in menu.
  • Hence, Legacy/oldmenu.* is dropped from molecuilder/src/Makefile.am
  • new map MapOfActions::MenuContainsActionMap with menu names and all desired actions therein
  • new MapOfActions::populateActions() which instantiate all possible actions (moved over from CommandLineWindow)
  • DOCU: MapOfActions has full documentation explaining how to add new actions
  • main(): CommandLineUI is taken if at least argument it present, otherwise text menu.

Still missing:

  • testsuite cases should work for both command line AND text menu (just add by calling with "< input", where input has all the user input needed)
  • Property mode set to 100644
File size: 6.4 KB
Line 
1/*
2 * TextWindow.cpp
3 *
4 * Created on: Jan 7, 2010
5 * Author: crueger
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include "TextUI/TextWindow.hpp"
11
12#include <boost/bind.hpp>
13
14#include "Menu/Menu.hpp"
15#include "Menu/TextMenu.hpp"
16#include "Menu/ActionMenuItem.hpp"
17#include "Menu/SeperatorItem.hpp"
18#include "Menu/DisplayMenuItem.hpp"
19#include "Menu/SubMenuItem.hpp"
20#include "TextUI/TextStatusIndicator.hpp"
21#include "Actions/MapOfActions.hpp"
22#include "Actions/MethodAction.hpp"
23#include "Actions/ErrorAction.hpp"
24#include "Actions/ActionRegistry.hpp"
25#include "Views/StreamStringView.hpp"
26#include "Views/MethodStringView.hpp"
27
28#include "defs.hpp"
29#include "log.hpp"
30#include "verbose.hpp"
31
32// all needed due to config::SaveAll()
33#include "config.hpp"
34#include "periodentafel.hpp"
35
36// config::SaveAll() and enumerate()
37#include "molecule.hpp"
38
39#include <iostream>
40#include <map>
41
42using namespace std;
43
44// TODO: see what code can be moved to a base class for Graphic and Text Windows
45TextWindow::TextWindow()
46{
47 char ConfigFileName[MAXSTRINGSIZE];
48 map <std::string, TextMenu *> NametoTextMenuMap;
49
50 // populate all actions
51 MapOfActions::getInstance().populateActions();
52
53 // build the main menu
54 main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
55
56 moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,World::getInstance().getMolecules(),_1));
57 new DisplayMenuItem(main_menu,moleculeView,"Molecule List");
58
59 new SeperatorItem(main_menu);
60
61 Action* undoAction = ActionRegistry::getInstance().getActionByName("Undo");
62 new ActionMenuItem('u',"Undo last operation",main_menu,undoAction);
63
64 Action* redoAction = ActionRegistry::getInstance().getActionByName("Redo");
65 new ActionMenuItem('r',"Redo last operation",main_menu,redoAction);
66
67 new SeperatorItem(main_menu);
68
69 Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,World::getInstance().getMolecules()));
70 new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
71
72 TextMenu *AnalysisMenu = new TextMenu(Log() << Verbose(0), "Analysis");
73 NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("analysis", AnalysisMenu) );
74 new SubMenuItem('A',"Analysis (pair correlation, volume)",main_menu,AnalysisMenu);
75
76 TextMenu *CommandMenu = new TextMenu(Log() << Verbose(0), "Configuration");
77 NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("command", CommandMenu) );
78 new SubMenuItem('c',"configuration",main_menu,CommandMenu);
79
80 TextMenu *AtomMenu = new TextMenu(Log() << Verbose(0), "Atoms");
81 NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("atom", AtomMenu) );
82 new SubMenuItem('e',"edit atoms",main_menu,AtomMenu);
83
84 TextMenu *FragmentationMenu = new TextMenu(Log() << Verbose(0), "Fragmentation");
85 NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("fragmentation", FragmentationMenu) );
86 new SubMenuItem('f',"fragmentation",main_menu,FragmentationMenu);
87
88 TextMenu *ParserMenu = new TextMenu(Log() << Verbose(0), "Parse files");
89 NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("parser", ParserMenu) );
90 new SubMenuItem('p',"parse files into system",main_menu,ParserMenu);
91
92 TextMenu *MoleculesMenu = new TextMenu(Log() << Verbose(0), "Edit Molecules");
93 NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("analysis", AnalysisMenu) );
94 new SubMenuItem('m',"edit molecules (load, parse, save)",main_menu,MoleculesMenu);
95
96 TextMenu *TesselationMenu = new TextMenu(Log() << Verbose(0), "Tesselate Molecules");
97 NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("tesselation", TesselationMenu) );
98 new SubMenuItem('t',"tesselate molecules",main_menu,TesselationMenu);
99
100 TextMenu *WorldMenu = new TextMenu(Log() << Verbose(0), "World");
101 NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("world", WorldMenu) );
102 new SubMenuItem('w',"edit world",main_menu,WorldMenu);
103
104 new SeperatorItem(main_menu);
105
106 Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,World::getInstance().getConfig(), ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules()));
107 new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
108
109 quitAction = new MethodAction("quitAction",boost::bind(&TextMenu::doQuit,main_menu),false);
110 new ActionMenuItem('q',"quit",main_menu,quitAction);
111
112 // go through all menus and create them
113 for (map <std::string, TextMenu *>::iterator MenuRunner = NametoTextMenuMap.begin(); MenuRunner != NametoTextMenuMap.end(); ++MenuRunner) {
114 cout << "Creating Menu " << MenuRunner->first << "." << endl;
115 populateMenu(MenuRunner->second, MenuRunner->first);
116 }
117
118 // Add status indicators etc...
119
120 statusIndicator = new TextStatusIndicator();
121}
122
123TextWindow::~TextWindow()
124{
125 delete quitAction;
126 delete moleculeView;
127 delete statusIndicator;
128 delete main_menu;
129}
130
131void TextWindow::display() {
132 main_menu->display();
133}
134
135char TextWindow::getSuitableShortForm(set <char> &ShortcutList, const std::string name) const
136{
137 for (std::string::const_iterator CharRunner = name.begin(); CharRunner != name.end(); ++CharRunner) {
138 if (ShortcutList.find(*CharRunner) == ShortcutList.end())
139 return *CharRunner;
140 }
141 DoeLog(1) && (eLog() << Verbose(1) << "Could not find a suitable shortform for TextWindow::getSuitableShortForm()." << endl);
142 return ((char)(ShortcutList.size() % 10) + '0');
143}
144
145void TextWindow::populateMenu(TextMenu* Menu, const std::string &MenuName)
146{
147 Action *ActionItem = NULL;
148 set <char> ShortcutList;
149 // through all actions for this menu
150 pair < multimap <std::string, std::string>::iterator, multimap <std::string, std::string>::iterator > MenuActions = MapOfActions::getInstance().MenuContainsActionMap.equal_range(MenuName);
151 for (multimap <std::string, std::string>::const_iterator MenuRunner = MenuActions.first; MenuRunner != MenuActions.second; ++MenuRunner) {
152 cout << " Adding " << MenuRunner->second << " to submenu " << MenuName << endl;
153 ActionItem = ActionRegistry::getInstance().getActionByName(MenuRunner->second);
154 new ActionMenuItem(getSuitableShortForm(ShortcutList, MenuRunner->second),MapOfActions::getInstance().getDescription(MenuRunner->second).c_str(),Menu,ActionItem);
155 }
156 // finally add default quit item
157 Action *returnFromAction = new TextMenu::LeaveAction(Menu);
158 MenuItem *returnFromItem = new ActionMenuItem('q',"return to Main menu",Menu,returnFromAction);
159 Menu->addDefault(returnFromItem);
160}
Note: See TracBrowser for help on using the repository browser.