Changeset 12b845


Ignore:
Timestamp:
Jan 9, 2010, 11:30:49 AM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
3c5606
Parents:
cc04b7
Message:

Seperated building of mainWindow and contained Menus

  • Moved code to build Menus to builder.cpp
  • Moved WindowGeneration code to constructor
Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/ActionRegistry.cpp

    rcc04b7 r12b845  
    1919ActionRegistry::ActionRegistry()
    2020{
    21   // TODO Auto-generated constructor stub
    22 
    2321}
    2422
    2523ActionRegistry::~ActionRegistry()
    2624{
    27   // TODO Auto-generated destructor stub
     25  map<const string,Action*>::iterator iter;
     26  for(iter=actionMap.begin();iter!=actionMap.end();iter++) {
     27    delete iter->second;
     28    actionMap.erase(iter);
     29  }
    2830}
    2931
  • src/UIElements/MainWindow.hpp

    rcc04b7 r12b845  
    1313class periodentafel;
    1414
     15class Menu;
     16
    1517class MainWindow
    1618{
     
    1921  virtual ~MainWindow();
    2022
    21   virtual void display(MoleculeListClass *, config *, periodentafel *, char *)=0;
     23  virtual void display()=0;
    2224
    2325};
    2426
     27typedef void (*MenuMaker)(Menu*,MoleculeListClass*, config*, periodentafel*);
     28
     29struct menuPopulaters{
     30  MenuMaker MakeEditMoleculesMenu;
     31};
     32
    2533#endif /* MAINWINDOW_HPP_ */
  • src/UIElements/TextUIFactory.cpp

    rcc04b7 r12b845  
    2727}
    2828
    29 MainWindow* TextUIFactory::makeMainWindow() {
    30   return new TextWindow();
     29MainWindow* TextUIFactory::makeMainWindow(menuPopulaters populaters,MoleculeListClass *molecules, config *configuration, periodentafel *periode, char *ConfigFileName) {
     30  return new TextWindow(populaters,molecules,configuration,periode,ConfigFileName);
    3131}
    3232
  • src/UIElements/TextUIFactory.hpp

    rcc04b7 r12b845  
    1919
    2020  virtual Dialog* makeDialog();
    21   virtual MainWindow* makeMainWindow();
     21  virtual MainWindow* makeMainWindow(menuPopulaters,MoleculeListClass *, config *, periodentafel *, char *);
    2222
    2323protected:
  • src/UIElements/TextWindow.cpp

    rcc04b7 r12b845  
    77
    88#include "UIElements/TextWindow.hpp"
     9
     10#include <boost/bind.hpp>
     11
     12
     13// TODO: When done with refactoring most of these wont be needed anymore
     14#include "analysis_correlation.hpp"
     15#include "atom.hpp"
     16#include "bond.hpp"
     17#include "bondgraph.hpp"
     18#include "boundary.hpp"
     19#include "config.hpp"
     20#include "element.hpp"
     21#include "ellipsoid.hpp"
     22#include "helpers.hpp"
     23#include "leastsquaremin.hpp"
     24#include "linkedcell.hpp"
     25#include "log.hpp"
     26#include "memoryusageobserverunittest.hpp"
     27#include "molecule.hpp"
     28#include "periodentafel.hpp"
     29
    930#include "../menu.hpp"
     31
     32#include "Menu/Menu.hpp"
     33#include "Menu/TextMenu.hpp"
     34#include "Menu/ActionMenuItem.hpp"
     35#include "Menu/SeperatorItem.hpp"
     36#include "Menu/DisplayMenuItem.hpp"
     37#include "Menu/SubMenuItem.hpp"
     38#include "Actions/MethodAction.hpp"
     39#include "Actions/ErrorAction.hpp"
     40#include "Views/StreamStringView.hpp"
     41#include "Views/MethodStringView.hpp"
    1042
    1143#include <iostream>
     
    1345using namespace std;
    1446
    15 TextWindow::TextWindow()
     47// TODO: see what code can be moved to a base class for Graphic and Text Windows
     48TextWindow::TextWindow(menuPopulaters populaters,MoleculeListClass *molecules, config *configuration, periodentafel *periode, char *ConfigFileName)
    1649{
    17   // TODO Auto-generated constructor stub
     50  old_menu = new oldmenu;
    1851
     52  // build the main menu
     53  main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
     54
     55  moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1));
     56  new DisplayMenuItem(main_menu,moleculeView,"Molecule List");
     57
     58  new SeperatorItem(main_menu);
     59
     60  Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,molecules));
     61  new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
     62
     63  TextMenu *editMoleculesMenu = new TextMenu(Log() << Verbose(0), "Edit Molecules");
     64  new SubMenuItem('e',"edit molecules (load, parse, save)",main_menu,editMoleculesMenu);
     65
     66  Action *manipulateMoleculeAction = new MethodAction("manipulateMoleculeAction",boost::bind(&oldmenu::ManipulateMolecules,old_menu,periode, molecules, configuration));
     67  new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction);
     68
     69  Action *mergeMoleculeAction = new MethodAction("mergeMoleculeAction",boost::bind(&oldmenu::MergeMolecules,old_menu,periode, molecules));
     70  new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction);
     71
     72  Action *manipulateAtomsAction = new MethodAction("manipulateAtomsAction",boost::bind(&oldmenu::ManipulateAtoms,old_menu,periode, molecules, configuration));
     73  new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction);
     74
     75  new SeperatorItem(main_menu);
     76
     77  Action *editConfigAction = new MethodAction("editConfigAction",boost::bind(&config::Edit,configuration));
     78  new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction);
     79
     80  new SeperatorItem(main_menu);
     81
     82  Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,configuration, ConfigFileName, periode, molecules));
     83  new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
     84
     85  Action *doTestAction = new MethodAction("doTestAction",boost::bind(&oldmenu::testroutine,old_menu,molecules));
     86  new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction);
     87
     88  quitAction = new MethodAction("quitAction",boost::bind(&TextMenu::doQuit,main_menu),false);
     89  new ActionMenuItem('q',"quit",main_menu,quitAction);
     90
     91  // call all functions used to build the submenus
     92
     93  populaters.MakeEditMoleculesMenu(editMoleculesMenu,molecules,configuration,periode);
     94
     95  returnFromEditMoleculeAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,editMoleculesMenu),false);
     96  MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnFromEditMoleculeAction);
     97
     98  editMoleculesMenu->addDefault(returnItem);
    1999}
    20100
    21101TextWindow::~TextWindow()
    22102{
    23   // TODO Auto-generated destructor stub
     103  delete old_menu;
     104  delete quitAction;
     105  delete returnFromEditMoleculeAction;
     106  delete moleculeView;
     107  delete main_menu;
    24108}
    25109
    26 void TextWindow::display(MoleculeListClass *molecules, config *configuration, periodentafel *periode, char *ConfigFileName) {
    27   cout << "creating main window" <<endl;
    28   oldmenu *main_menu;
    29   main_menu = new oldmenu;
    30   main_menu->perform(molecules, configuration, periode, ConfigFileName);
    31   delete main_menu;
     110void TextWindow::display() {
     111  main_menu->display();
    32112}
  • src/UIElements/TextWindow.hpp

    rcc04b7 r12b845  
    1111#include "UIElements/MainWindow.hpp"
    1212
     13class TextMenu;
     14class Action;
     15class oldmenu;
     16class StringView;
     17
    1318class TextWindow : public MainWindow
    1419{
    1520public:
    16   TextWindow();
     21  TextWindow(menuPopulaters,MoleculeListClass *, config *, periodentafel *, char *);
    1722  virtual ~TextWindow();
    1823
    19   virtual void display(MoleculeListClass *, config *, periodentafel *, char *);
     24  virtual void display();
     25private:
     26  TextMenu *main_menu;
     27
     28  // some actions only needed in textMenus
     29  Action *quitAction;
     30  Action *returnFromEditMoleculeAction;
     31  // all views that are contained in the main Menu
     32  StringView *moleculeView;
     33
     34  // This class still contains a lot of scattered functionality
     35  oldmenu *old_menu;
    2036};
    2137
  • src/UIElements/UIFactory.hpp

    rcc04b7 r12b845  
    1212class Dialog;
    1313
     14class MoleculeListClass;
     15class config;
     16class periodentafel;
     17
     18struct menuPopulaters;
     19
    1420class UIFactory
    1521{
     
    2026
    2127  // methods for creating UIElements
    22   virtual MainWindow* makeMainWindow()=0;
     28  virtual MainWindow* makeMainWindow(menuPopulaters,MoleculeListClass *, config *, periodentafel *, char *)=0;
    2329  virtual Dialog* makeDialog()=0;
    2430
  • src/builder.cpp

    rcc04b7 r12b845  
    4747 */
    4848
     49
     50#include <boost/bind.hpp>
    4951
    5052using namespace std;
     
    6769#include "UIElements/UIFactory.hpp"
    6870#include "UIElements/MainWindow.hpp"
     71#include "Menu/ActionMenuItem.hpp"
     72#include "Actions/ActionRegistry.hpp"
     73#include "Actions/MethodAction.hpp"
     74
    6975
    7076/** Parses the command line options.
     
    891897};
    892898
     899/***************************************** Functions used to build all menus **********************/
     900
     901void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){
     902  // build the EditMoleculesMenu
     903  Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
     904  new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
     905
     906  Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
     907  new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
     908
     909  Action *changeFilenameAction = new MethodAction("changeFilenameAction",boost::bind(&MoleculeListClass::changeName,molecules));
     910  new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
     911
     912  Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
     913  new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
     914
     915  Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
     916  new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
     917
     918  Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
     919  new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
     920}
     921
     922
    893923/********************************************** Main routine **************************************/
    894924
     
    938968    }
    939969
    940 
    941     UIFactory::makeUserInterface(UIFactory::Text);
    942     MainWindow *mainWindow = UIFactory::get()->makeMainWindow();
    943     mainWindow->display(molecules, configuration, periode, ConfigFileName);
     970    {
     971      menuPopulaters populaters;
     972      populaters.MakeEditMoleculesMenu = populateEditMoleculesMenu;
     973
     974      UIFactory::makeUserInterface(UIFactory::Text);
     975      MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,molecules, configuration, periode, ConfigFileName);
     976      mainWindow->display();
     977      delete mainWindow;
     978    }
    944979
    945980    if(periode->StorePeriodentafel(configuration->databasepath))
     
    953988  delete(configuration);
    954989
    955   delete mainWindow;
     990
    956991
    957992  Log() << Verbose(0) <<  "Maximum of allocated memory: "
     
    963998  errorLogger::purgeInstance();
    964999  UIFactory::purgeInstance();
     1000  ActionRegistry::purgeRegistry();
    9651001  return (0);
    9661002}
  • src/menu.cpp

    rcc04b7 r12b845  
    11171117{
    11181118
    1119   // build the main menu
    1120   TextMenu *main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
    1121 
    1122   StringView *moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1));
    1123   new DisplayMenuItem(main_menu,moleculeView,"Molecule List");
    1124 
    1125   new SeperatorItem(main_menu);
    1126 
    1127   Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,molecules));
    1128   new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
    1129 
    1130   TextMenu *editMoleculesMenu = new TextMenu(Log() << Verbose(0), "Edit Molecules");
    1131   new SubMenuItem('e',"edit molecules (load, parse, save)",main_menu,editMoleculesMenu);
    1132 
    1133   Action *manipulateMoleculeAction = new MethodAction("manipulateMoleculeAction",boost::bind(&oldmenu::ManipulateMolecules,this,periode, molecules, configuration));
    1134   new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction);
    1135 
    1136   Action *mergeMoleculeAction = new MethodAction("mergeMoleculeAction",boost::bind(&oldmenu::MergeMolecules,this,periode, molecules));
    1137   new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction);
    1138 
    1139   Action *manipulateAtomsAction = new MethodAction("manipulateAtomsAction",boost::bind(&oldmenu::ManipulateAtoms,this,periode, molecules, configuration));
    1140   new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction);
    1141 
    1142   new SeperatorItem(main_menu);
    1143 
    1144   Action *editConfigAction = new MethodAction("editConfigAction",boost::bind(&config::Edit,configuration));
    1145   new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction);
    1146 
    1147   new SeperatorItem(main_menu);
    1148 
    1149   Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,configuration, ConfigFileName, periode, molecules));
    1150   new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
    1151 
    1152   Action *doTestAction = new MethodAction("doTestAction",boost::bind(&oldmenu::testroutine,this,molecules));
    1153   new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction);
    1154 
    1155   Action *quitAction = new MethodAction("quitAction",boost::bind(&TextMenu::doQuit,main_menu),false);
    1156   new ActionMenuItem('q',"quit",main_menu,quitAction);
    1157 
    1158 
    1159 
    1160   // build the EditMoleculesMenu
    1161   Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
    1162   new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
    1163 
    1164   Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
    1165   new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
    1166 
    1167   Action *changeFilenameAction = new MethodAction("changeFilenameAction",boost::bind(&MoleculeListClass::changeName,molecules));
    1168   new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
    1169 
    1170   Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
    1171   new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
    1172 
    1173   Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
    1174   new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
    1175 
    1176   Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
    1177   new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
    1178 
    1179   Action *returnAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,editMoleculesMenu),false);
    1180   MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnAction);
    1181 
    1182   editMoleculesMenu->addDefault(returnItem);
    1183 
    1184   main_menu->display();
    1185 
    1186 
    1187   delete main_menu;
    1188 
    1189   // delete all actions and views contained in Menu
    1190   // TODO: find a better way to handle this
    1191 
    1192   delete moleculeView;
    1193 
    1194   delete setMoleculeAction;
    1195   delete manipulateMoleculeAction;
    1196   delete mergeMoleculeAction;
    1197   delete manipulateAtomsAction;
    1198   delete editConfigAction;
    1199   delete saveConfigAction;
    1200   delete doTestAction;
    1201   delete quitAction;
    1202 
    1203   delete createMoleculeAction;
    1204   delete loadMoleculeAction;
    1205   delete changeFilenameAction;
    1206   delete giveFilenameAction;
    1207   delete parseAtomsAction;
    1208   delete eraseMoleculeAction;
    1209   delete returnAction;
    1210 
    12111119};
  • src/menu.hpp

    rcc04b7 r12b845  
    3434  void simpleMergeMolecules(MoleculeListClass *molecules);
    3535
    36 protected:
    3736  void AddAtoms(periodentafel *, molecule *);
    3837  void AlignAtoms(periodentafel *, molecule *);
Note: See TracChangeset for help on using the changeset viewer.