source: src/UIElements/TextUI/TextWindow.cpp@ 24c35a

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

Introduced a MenuBar and Menus to the QT interface.

  • new map MapOfActions::MenuDescriptionMap which contains short and long descriptions of the menus.
  • MapOfActions::populateActions() - rotate-to-pas and suspend-in-water actions were missing.
  • QTMainWindow
    • QTMainWindow() - creates a MenuBar and QTMenus and fills them with the actions from the maps in MapOfActions.
    • new function populateMenu() - same as in TextWindow.
    • new function getSuitableShortForm() - same as in TextWindow.
  • TextWindow::TextWindow() - also makes use of the new map MenuDescriptionMap.
  • MoleculeSuspendInWaterAction - changed argument to density and molecule is obtained by molecule-by-id
  • TESTFIX: Molecule/8 had wrong argument for rotate-to-pas
  • TESTFIX: Filling/2 had missing molecule-by-id
  • Property mode set to 100644
File size: 5.1 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#include "Helpers/MemDebug.hpp"
28
29#include "defs.hpp"
30#include "log.hpp"
31#include "verbose.hpp"
32
33// all needed due to config::SaveAll()
34#include "config.hpp"
35#include "periodentafel.hpp"
36
37// config::SaveAll() and enumerate()
38#include "molecule.hpp"
39
40#include <iostream>
41#include <map>
42
43using namespace std;
44
45// TODO: see what code can be moved to a base class for Graphic and Text Windows
46TextWindow::TextWindow()
47{
48 char ConfigFileName[MAXSTRINGSIZE];
49 map <std::string, TextMenu *> NametoTextMenuMap;
50
51 // populate all actions
52 MapOfActions::getInstance().populateActions();
53
54 // build the main menu
55 main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
56
57 moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,World::getInstance().getMolecules(),_1));
58 new DisplayMenuItem(main_menu,moleculeView,"Molecule List");
59
60 new SeperatorItem(main_menu);
61
62 Action* undoAction = ActionRegistry::getInstance().getActionByName("Undo");
63 new ActionMenuItem('u',"Undo last operation",main_menu,undoAction);
64
65 Action* redoAction = ActionRegistry::getInstance().getActionByName("Redo");
66 new ActionMenuItem('r',"Redo last operation",main_menu,redoAction);
67
68 new SeperatorItem(main_menu);
69
70 Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,World::getInstance().getMolecules()));
71 new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
72
73 TextMenu *Menu = NULL;
74 std::set <char> ShortcutList;
75 for(map<std::string, pair<std::string,std::string> >::iterator iter = MapOfActions::getInstance().MenuDescription.begin(); iter != MapOfActions::getInstance().MenuDescription.end(); ++iter) {
76 Menu = new TextMenu(Log() << Verbose(0), iter->second.second);
77 NametoTextMenuMap.insert( pair <std::string, TextMenu *> (iter->first, Menu) );
78 new SubMenuItem(getSuitableShortForm(ShortcutList,iter->first),iter->second.first.c_str(),main_menu,Menu);
79 }
80
81 new SeperatorItem(main_menu);
82
83 Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,World::getInstance().getConfig(), ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules()));
84 new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
85
86 quitAction = new MethodAction("quitAction",boost::bind(&TextMenu::doQuit,main_menu),false);
87 new ActionMenuItem('q',"quit",main_menu,quitAction);
88
89 // go through all menus and create them
90 for (map <std::string, TextMenu *>::iterator MenuRunner = NametoTextMenuMap.begin(); MenuRunner != NametoTextMenuMap.end(); ++MenuRunner) {
91 cout << "Creating Menu " << MenuRunner->first << "." << endl;
92 populateMenu(MenuRunner->second, MenuRunner->first);
93 }
94
95 // Add status indicators etc...
96
97 statusIndicator = new TextStatusIndicator();
98}
99
100TextWindow::~TextWindow()
101{
102 delete quitAction;
103 delete moleculeView;
104 delete statusIndicator;
105 delete main_menu;
106}
107
108void TextWindow::display() {
109 main_menu->display();
110}
111
112char TextWindow::getSuitableShortForm(set <char> &ShortcutList, const std::string name) const
113{
114 for (std::string::const_iterator CharRunner = name.begin(); CharRunner != name.end(); ++CharRunner) {
115 if (ShortcutList.find(*CharRunner) == ShortcutList.end())
116 return *CharRunner;
117 }
118 DoeLog(1) && (eLog() << Verbose(1) << "Could not find a suitable shortform for TextWindow::getSuitableShortForm()." << endl);
119 return ((char)(ShortcutList.size() % 10) + '0');
120}
121
122void TextWindow::populateMenu(TextMenu* Menu, const std::string &MenuName)
123{
124 Action *ActionItem = NULL;
125 set <char> ShortcutList;
126 // through all actions for this menu
127 pair < multimap <std::string, std::string>::iterator, multimap <std::string, std::string>::iterator > MenuActions = MapOfActions::getInstance().MenuContainsActionMap.equal_range(MenuName);
128 for (multimap <std::string, std::string>::const_iterator MenuRunner = MenuActions.first; MenuRunner != MenuActions.second; ++MenuRunner) {
129 cout << " Adding " << MenuRunner->second << " to submenu " << MenuName << endl;
130 ActionItem = ActionRegistry::getInstance().getActionByName(MenuRunner->second);
131 new ActionMenuItem(getSuitableShortForm(ShortcutList, MenuRunner->second),MapOfActions::getInstance().getDescription(MenuRunner->second).c_str(),Menu,ActionItem);
132 }
133 // finally add default quit item
134 Action *returnFromAction = new TextMenu::LeaveAction(Menu);
135 MenuItem *returnFromItem = new ActionMenuItem('q',"return to Main menu",Menu,returnFromAction);
136 Menu->addDefault(returnFromItem);
137}
Note: See TracBrowser for help on using the repository browser.