Ignore:
Timestamp:
Jun 25, 2010, 1:04:13 PM (15 years ago)
Author:
Frederik Heber <heber@…>
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:
0c5eeb, b0acc3
Parents:
a356f2
Message:

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)
Location:
src/UIElements/TextUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/TextUI/TextWindow.cpp

    ra356f2 r326bbe  
    1212#include <boost/bind.hpp>
    1313
    14 
    15 // TODO: When done with refactoring most of these wont be needed anymore
    16 #include "analysis_correlation.hpp"
    17 #include "atom.hpp"
    18 #include "bond.hpp"
    19 #include "bondgraph.hpp"
    20 #include "boundary.hpp"
    21 #include "config.hpp"
    22 #include "element.hpp"
    23 #include "ellipsoid.hpp"
    24 #include "helpers.hpp"
    25 #include "leastsquaremin.hpp"
    26 #include "linkedcell.hpp"
    27 #include "log.hpp"
    28 #include "memoryusageobserver.hpp"
    29 #include "molecule.hpp"
    30 #include "periodentafel.hpp"
    31 #include "World.hpp"
    32 
    33 #include "Legacy/oldmenu.hpp"
    34 
    3514#include "Menu/Menu.hpp"
    3615#include "Menu/TextMenu.hpp"
     
    4019#include "Menu/SubMenuItem.hpp"
    4120#include "TextUI/TextStatusIndicator.hpp"
     21#include "Actions/MapOfActions.hpp"
    4222#include "Actions/MethodAction.hpp"
    43 #include "Actions/MoleculeAction/ChangeNameAction.hpp"
    4423#include "Actions/ErrorAction.hpp"
    4524#include "Actions/ActionRegistry.hpp"
     
    4726#include "Views/MethodStringView.hpp"
    4827
     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
    4939#include <iostream>
     40#include <map>
    5041
    5142using namespace std;
     
    5445TextWindow::TextWindow()
    5546{
    56   MoleculeListClass *molecules = World::getInstance().getMolecules();
    57   config *configuration = World::getInstance().getConfig();
    58   periodentafel *periode = World::getInstance().getPeriode();
    59   char *ConfigFileName = NULL;
    60   old_menu = new oldmenu;
     47  char ConfigFileName[MAXSTRINGSIZE];
     48  map <std::string, TextMenu *> NametoTextMenuMap;
     49
     50  // populate all actions
     51  MapOfActions::getInstance().populateActions();
    6152
    6253  // build the main menu
    6354  main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
    6455
    65   moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1));
     56  moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,World::getInstance().getMolecules(),_1));
    6657  new DisplayMenuItem(main_menu,moleculeView,"Molecule List");
    6758
     
    7667  new SeperatorItem(main_menu);
    7768
    78   Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,molecules));
     69  Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,World::getInstance().getMolecules()));
    7970  new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
    8071
    81   TextMenu *editMoleculesMenu = new TextMenu(Log() << Verbose(0), "Edit Molecules");
    82   new SubMenuItem('e',"edit molecules (load, parse, save)",main_menu,editMoleculesMenu);
     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);
    8375
    84   Action *manipulateMoleculeAction = new MethodAction("manipulateMoleculeAction",boost::bind(&oldmenu::ManipulateMolecules,old_menu,periode, molecules, configuration));
    85   new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction);
     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);
    8679
    87   Action *mergeMoleculeAction = new MethodAction("mergeMoleculeAction",boost::bind(&oldmenu::MergeMolecules,old_menu,periode, molecules));
    88   new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction);
     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);
    8983
    90   Action *manipulateAtomsAction = new MethodAction("manipulateAtomsAction",boost::bind(&oldmenu::ManipulateAtoms,old_menu,periode, molecules, configuration));
    91   new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction);
     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);
    92103
    93104  new SeperatorItem(main_menu);
    94105
    95   Action *editConfigAction = new MethodAction("editConfigAction",boost::bind(&config::Edit,configuration));
    96   new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction);
    97 
    98   new SeperatorItem(main_menu);
    99 
    100   Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,configuration, ConfigFileName, periode, molecules));
     106  Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,World::getInstance().getConfig(), ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules()));
    101107  new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
    102 
    103   Action *doTestAction = new MethodAction("doTestAction",boost::bind(&oldmenu::testroutine,old_menu,molecules));
    104   new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction);
    105108
    106109  quitAction = new MethodAction("quitAction",boost::bind(&TextMenu::doQuit,main_menu),false);
    107110  new ActionMenuItem('q',"quit",main_menu,quitAction);
    108111
    109   // call all functions used to build the submenus
    110 
    111   populateEditMoleculesMenu(editMoleculesMenu);
    112 
    113   Action *returnFromEditMoleculeAction = new TextMenu::LeaveAction(editMoleculesMenu);
    114   MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnFromEditMoleculeAction);
    115 
    116   editMoleculesMenu->addDefault(returnItem);
     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  }
    117117
    118118  // Add status indicators etc...
     
    123123TextWindow::~TextWindow()
    124124{
    125   delete old_menu;
    126125  delete quitAction;
    127126  delete moleculeView;
     
    134133}
    135134
    136 void TextWindow::populateEditMoleculesMenu(Menu* editMoleculesMenu)
     135char TextWindow::getSuitableShortForm(set <char> &ShortcutList, const std::string name) const
    137136{
    138   MoleculeListClass *molecules = World::getInstance().getMolecules();
    139   periodentafel *periode = World::getInstance().getPeriode();
     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}
    140144
    141   // build the EditMoleculesMenu
    142   Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
    143   new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
    144 
    145   Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
    146   new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
    147 
    148   Action *changeFilenameAction = new MoleculeChangeNameAction();
    149   new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
    150 
    151   Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
    152   new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
    153 
    154   Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
    155   new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
    156 
    157   Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
    158   new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
    159 
     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);
    160160}
  • src/UIElements/TextUI/TextWindow.hpp

    ra356f2 r326bbe  
    1111#include "MainWindow.hpp"
    1212
     13#include <set>
     14
    1315class TextMenu;
    1416class Action;
    15 class oldmenu;
    1617class StringView;
    1718class TextStatusIndicator;
     
    2728private:
    2829  // populaters
    29   void populateEditMoleculesMenu(Menu* editMoleculesMenu);
     30  char getSuitableShortForm(std::set <char> &ShortcutList, const std::string name) const;
     31  void populateMenu(TextMenu* Menu, const std::string &name);
    3032
    3133  TextMenu *main_menu;
     
    3638  StringView *moleculeView;
    3739  TextStatusIndicator *statusIndicator;
    38 
    39   // This class still contains a lot of scattered functionality
    40   oldmenu *old_menu;
    4140};
    4241
Note: See TracChangeset for help on using the changeset viewer.