Changeset cc04b7


Ignore:
Timestamp:
Jan 7, 2010, 2:46:34 PM (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:
12b845
Parents:
a56275
Message:

Added a central registry that allows access to actions by name.

Location:
src
Files:
2 added
17 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    ra56275 rcc04b7  
    66 */
    77
    8 #include "Action.hpp"
     8#include <string>
    99
    10 Action::Action()
    11 {}
     10#include "Actions/Action.hpp"
     11#include "Actions/ActionRegistry.hpp"
     12
     13using namespace std;
     14
     15Action::Action(std::string _name,bool _doRegister) :
     16name(_name)
     17{
     18  if(_doRegister){
     19    ActionRegistry::getRegistry()->registerAction(this);
     20  }
     21}
    1222
    1323Action::~Action()
    1424{}
     25
     26const string Action::getName(){
     27  return name;
     28}
  • src/Actions/Action.hpp

    ra56275 rcc04b7  
    88#ifndef ACTION_H_
    99#define ACTION_H_
     10
     11#include <string>
    1012
    1113/**
     
    2123protected:
    2224public:
    23   Action();
     25  Action(std::string _name,bool _doRegister=true);
    2426  virtual ~Action();
    2527
     
    2830  virtual bool canUndo()=0;
    2931
     32  virtual const std::string getName();
     33
     34private:
     35  std::string name;
    3036};
    3137
  • src/Actions/ErrorAction.cpp

    ra56275 rcc04b7  
    1414using namespace std;
    1515
    16 ErrorAction::ErrorAction(const char * _errorMsg) :
     16ErrorAction::ErrorAction(string _name,const char * _errorMsg,bool _doRegister) :
     17Action(_name,_doRegister),
    1718errorMsg(_errorMsg)
    1819{
  • src/Actions/ErrorAction.hpp

    ra56275 rcc04b7  
    1515{
    1616public:
    17   ErrorAction(const char *);
     17  ErrorAction(std::string _name,const char * _errorMsg,bool _doRegister=true);
    1818  virtual ~ErrorAction();
    1919
  • src/Actions/MakroAction.cpp

    ra56275 rcc04b7  
    66 */
    77
     8#include <string>
     9
    810#include "Actions/MakroAction.hpp"
    911#include "Actions/Action.hpp"
    1012#include "Actions/ActionSequence.hpp"
    1113
    12 MakroAction::MakroAction(ActionSequence* _actions) :
     14using namespace std;
     15
     16MakroAction::MakroAction(string _name,ActionSequence* _actions,bool _doRegister) :
     17Action(_name,_doRegister),
    1318actions(_actions)
    1419{
  • src/Actions/MakroAction.hpp

    ra56275 rcc04b7  
    88#ifndef MAKROACTION_HPP_
    99#define MAKROACTION_HPP_
     10
     11#include <string>
    1012
    1113#include "Actions/Action.hpp"
     
    2123{
    2224public:
    23   MakroAction(ActionSequence*);
     25  MakroAction(std::string _name,ActionSequence* _actions,bool _doRegister=true);
    2426  virtual ~MakroAction();
    2527
  • src/Actions/MethodAction.cpp

    ra56275 rcc04b7  
    88#include <iostream>
    99#include <boost/function.hpp>
     10#include <string>
    1011
    1112#include "MethodAction.hpp"
     
    1314using namespace std;
    1415
    15 MethodAction::MethodAction(boost::function<void()> _executeMethod) :
     16MethodAction::MethodAction(string _name,boost::function<void()> _executeMethod,bool _doRegister) :
     17   Action(_name,_doRegister),
    1618executeMethod(_executeMethod)
    1719{
  • src/Actions/MethodAction.hpp

    ra56275 rcc04b7  
    1010
    1111#include <boost/function.hpp>
     12#include <string>
    1213
    1314#include "Actions/Action.hpp"
     
    1920{
    2021public:
    21   MethodAction(boost::function<void()>);
     22  MethodAction(std::string _name,boost::function<void()> _executeMethod,bool _doRegister=true);
    2223  virtual ~MethodAction();
    2324
  • src/Makefile.am

    ra56275 rcc04b7  
    55ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
    66
    7 ACTIONSSOURCE = Actions/Action.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp
    8 ACTIONSHEADER = Actions/Action.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp
     7ACTIONSSOURCE = Actions/Action.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/ActionRegistry.cpp
     8ACTIONSHEADER = Actions/Action.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/ActionRegistry.hpp
    99
    1010VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp
     
    1414MENUHEADER = Menu/Menu.hpp Menu/TextMenu.hpp Menu/MenuItem.hpp Menu/SubMenuItem.hpp Menu/ActionMenuItem.hpp Menu/SeperatorItem.hpp Menu/DisplayMenuItem.hpp
    1515
    16 UISOURCE = ${ACTIONSSOURCE} ${VIEWSOURCE} ${MENUSOURCE} UIElements/UIFactory.cpp UIElements/TextUIFactory.cpp UIElements/Dialog.cpp UIElements/TextDialog.cpp
    17 UIHEADER = ${ACTIONSHEADER} ${VIEWHEADER} ${MENUHEADER} UIElements/UIFactory.hpp UIElements/TextUIFactory.hpp UIElements/Dialog.hpp UIElements/TextDialog.hpp
     16UISOURCE = ${ACTIONSSOURCE} ${VIEWSOURCE} ${MENUSOURCE} UIElements/UIFactory.cpp UIElements/TextUIFactory.cpp UIElements/MainWindow.cpp UIElements/TextWindow.cpp UIElements/Dialog.cpp UIElements/TextDialog.cpp
     17UIHEADER = ${ACTIONSHEADER} ${VIEWHEADER} ${MENUHEADER} UIElements/UIFactory.hpp UIElements/TextUIFactory.hpp UIElements/MainWindow.hpp UIElements/TextWindow.hpp UIElements/Dialog.hpp UIElements/TextDialog.hpp
    1818
    1919SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${UISOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp menu.cpp
  • src/UIElements/TextUIFactory.cpp

    ra56275 rcc04b7  
    77
    88#include "UIElements/TextUIFactory.hpp"
     9#include "UIElements/TextWindow.hpp"
    910#include "UIElements/TextDialog.hpp"
     11
    1012
    1113TextUIFactory::TextUIFactory()
     
    2527}
    2628
     29MainWindow* TextUIFactory::makeMainWindow() {
     30  return new TextWindow();
     31}
    2732
  • src/UIElements/TextUIFactory.hpp

    ra56275 rcc04b7  
    1919
    2020  virtual Dialog* makeDialog();
     21  virtual MainWindow* makeMainWindow();
    2122
    2223protected:
  • src/UIElements/TextWindow.cpp

    ra56275 rcc04b7  
    88#include "UIElements/TextWindow.hpp"
    99#include "../menu.hpp"
     10
     11#include <iostream>
     12
     13using namespace std;
    1014
    1115TextWindow::TextWindow()
     
    2125
    2226void TextWindow::display(MoleculeListClass *molecules, config *configuration, periodentafel *periode, char *ConfigFileName) {
     27  cout << "creating main window" <<endl;
    2328  oldmenu *main_menu;
    2429  main_menu = new oldmenu;
  • src/UIElements/UIFactory.cpp

    ra56275 rcc04b7  
    1212// all factories that can be used:
    1313#include "UIElements/TextUIFactory.hpp"
     14
     15UIFactory *UIFactory::theFactory = 0;
    1416
    1517UIFactory::UIFactory()
     
    4143  return theFactory;
    4244}
     45
     46
     47void UIFactory::purgeInstance(){
     48  if(theFactory) {
     49    delete theFactory;
     50    theFactory = 0;
     51  }
     52}
  • src/UIElements/UIFactory.hpp

    ra56275 rcc04b7  
    99#define UIFACTORY_HPP_
    1010
     11class MainWindow;
    1112class Dialog;
    1213
     
    1415{
    1516
     17public:
    1618  enum InterfaceTypes {Text};
    17 public:
    1819  virtual ~UIFactory();
    1920
    2021  // methods for creating UIElements
     22  virtual MainWindow* makeMainWindow()=0;
    2123  virtual Dialog* makeDialog()=0;
    2224
     
    2527
    2628// singleton stuff
     29private:
     30  static UIFactory *theFactory;
     31
    2732public:
    2833  static void makeUserInterface(InterfaceTypes type);
    2934  static UIFactory* get();
    30 
    31 private:
    32   static UIFactory *theFactory;
     35  static void purgeInstance();
    3336};
    3437
  • src/builder.cpp

    ra56275 rcc04b7  
    6565#include "molecule.hpp"
    6666#include "periodentafel.hpp"
    67 #include "menu.hpp"
     67#include "UIElements/UIFactory.hpp"
     68#include "UIElements/MainWindow.hpp"
    6869
    6970/** Parses the command line options.
     
    904905    char *ConfigFileName = NULL;
    905906    int j;
    906     oldmenu *main_menu;
    907     main_menu = new oldmenu;
    908907    setVerbosity(0);
    909908    /* structure of ParseCommandLineOptions will be refactored later */
     
    940939
    941940
    942 
    943     main_menu->perform(molecules, configuration, periode, ConfigFileName);
     941    UIFactory::makeUserInterface(UIFactory::Text);
     942    MainWindow *mainWindow = UIFactory::get()->makeMainWindow();
     943    mainWindow->display(molecules, configuration, periode, ConfigFileName);
    944944
    945945    if(periode->StorePeriodentafel(configuration->databasepath))
     
    952952    delete(periode);
    953953  delete(configuration);
     954
     955  delete mainWindow;
    954956
    955957  Log() << Verbose(0) <<  "Maximum of allocated memory: "
     
    960962  logger::purgeInstance();
    961963  errorLogger::purgeInstance();
    962 
     964  UIFactory::purgeInstance();
    963965  return (0);
    964966}
  • src/menu.cpp

    ra56275 rcc04b7  
    993993  TextMenu *MergeMoleculesMenu = new TextMenu(Log() << Verbose(0), "Merge Molecules");
    994994
    995   Action *simpleAddAction = new MethodAction(boost::bind(&oldmenu::SimpleAddMolecules,this,molecules));
     995  Action *simpleAddAction = new MethodAction("simpleAddAction",boost::bind(&oldmenu::SimpleAddMolecules,this,molecules),false);
    996996  new ActionMenuItem('a',"simple add of one molecule to another",MergeMoleculesMenu,simpleAddAction);
    997997
    998   Action *embeddAction = new MethodAction(boost::bind(&oldmenu::embeddMolecules,this,molecules));
     998  Action *embeddAction = new MethodAction("embeddAction",boost::bind(&oldmenu::embeddMolecules,this,molecules),false);
    999999  new ActionMenuItem('e',"embedding merge of two molecules",MergeMoleculesMenu,embeddAction);
    10001000
    1001   Action *multiMergeAction = new MethodAction(boost::bind(&oldmenu::multiMergeMolecules,this,molecules));
     1001  Action *multiMergeAction = new MethodAction("multiMergeAction",boost::bind(&oldmenu::multiMergeMolecules,this,molecules),false);
    10021002  new ActionMenuItem('m',"multi-merge of all molecules",MergeMoleculesMenu,multiMergeAction);
    10031003
    1004   Action *scatterMergeAction = new ErrorAction("Not Implemented yet");
     1004  Action *scatterMergeAction = new ErrorAction("scatterMergeAction","Not Implemented yet",false);
    10051005  new ActionMenuItem('s',"scatter merge of two molecules",MergeMoleculesMenu,scatterMergeAction);
    10061006
    1007   Action *simpleMergeAction = new MethodAction(boost::bind(&oldmenu::simpleMergeMolecules,this,molecules));
     1007  Action *simpleMergeAction = new MethodAction("simpleMergeAction",boost::bind(&oldmenu::simpleMergeMolecules,this,molecules),false);
    10081008  new ActionMenuItem('t',"simple merge of two molecules",MergeMoleculesMenu,simpleMergeAction);
    10091009
    1010   Action *returnAction = new MethodAction(boost::bind(&TextMenu::doQuit,MergeMoleculesMenu));
     1010  Action *returnAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,MergeMoleculesMenu),false);
    10111011  MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",MergeMoleculesMenu,returnAction);
    10121012
     
    11251125  new SeperatorItem(main_menu);
    11261126
    1127   Action *setMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::flipChosen,molecules));
     1127  Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,molecules));
    11281128  new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
    11291129
     
    11311131  new SubMenuItem('e',"edit molecules (load, parse, save)",main_menu,editMoleculesMenu);
    11321132
    1133   Action *manipulateMoleculeAction = new MethodAction(boost::bind(&oldmenu::ManipulateMolecules,this,periode, molecules, configuration));
     1133  Action *manipulateMoleculeAction = new MethodAction("manipulateMoleculeAction",boost::bind(&oldmenu::ManipulateMolecules,this,periode, molecules, configuration));
    11341134  new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction);
    11351135
    1136   Action *mergeMoleculeAction = new MethodAction(boost::bind(&oldmenu::MergeMolecules,this,periode, molecules));
     1136  Action *mergeMoleculeAction = new MethodAction("mergeMoleculeAction",boost::bind(&oldmenu::MergeMolecules,this,periode, molecules));
    11371137  new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction);
    11381138
    1139   Action *manipulateAtomsAction = new MethodAction(boost::bind(&oldmenu::ManipulateAtoms,this,periode, molecules, configuration));
     1139  Action *manipulateAtomsAction = new MethodAction("manipulateAtomsAction",boost::bind(&oldmenu::ManipulateAtoms,this,periode, molecules, configuration));
    11401140  new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction);
    11411141
    11421142  new SeperatorItem(main_menu);
    11431143
    1144   Action *editConfigAction = new MethodAction(boost::bind(&config::Edit,configuration));
     1144  Action *editConfigAction = new MethodAction("editConfigAction",boost::bind(&config::Edit,configuration));
    11451145  new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction);
    11461146
    11471147  new SeperatorItem(main_menu);
    11481148
    1149   Action *saveConfigAction = new MethodAction(boost::bind(&config::SaveAll,configuration, ConfigFileName, periode, molecules));
     1149  Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,configuration, ConfigFileName, periode, molecules));
    11501150  new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
    11511151
    1152   Action *doTestAction = new MethodAction(boost::bind(&oldmenu::testroutine,this,molecules));
     1152  Action *doTestAction = new MethodAction("doTestAction",boost::bind(&oldmenu::testroutine,this,molecules));
    11531153  new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction);
    11541154
    1155   Action *quitAction = new MethodAction(boost::bind(&TextMenu::doQuit,main_menu));
     1155  Action *quitAction = new MethodAction("quitAction",boost::bind(&TextMenu::doQuit,main_menu),false);
    11561156  new ActionMenuItem('q',"quit",main_menu,quitAction);
    11571157
     
    11591159
    11601160  // build the EditMoleculesMenu
    1161   Action *createMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
     1161  Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
    11621162  new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
    11631163
    1164   Action *loadMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
     1164  Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
    11651165  new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
    11661166
    1167   Action *changeFilenameAction = new MethodAction(boost::bind(&MoleculeListClass::changeName,molecules));
     1167  Action *changeFilenameAction = new MethodAction("changeFilenameAction",boost::bind(&MoleculeListClass::changeName,molecules));
    11681168  new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
    11691169
    1170   Action *giveFilenameAction = new MethodAction(boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
     1170  Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
    11711171  new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
    11721172
    1173   Action *parseAtomsAction = new MethodAction(boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
     1173  Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
    11741174  new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
    11751175
    1176   Action *eraseMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::eraseMolecule,molecules));
     1176  Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
    11771177  new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
    11781178
    1179   Action *returnAction = new MethodAction(boost::bind(&TextMenu::doQuit,editMoleculesMenu));
     1179  Action *returnAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,editMoleculesMenu),false);
    11801180  MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnAction);
    11811181
     
    12081208  delete eraseMoleculeAction;
    12091209  delete returnAction;
     1210
    12101211};
  • src/unittests/ActionSequenceTest.cpp

    ra56275 rcc04b7  
    2626{
    2727public:
    28   canUndoActionStub(){}
     28  canUndoActionStub(): Action("canUndoActionStub",false){}
    2929  virtual ~canUndoActionStub(){}
    3030
     
    3939{
    4040public:
    41   cannotUndoActionStub(){}
     41  cannotUndoActionStub() : Action("cannotUndoActionStub",false){}
    4242  virtual ~cannotUndoActionStub(){}
    4343
     
    5353public:
    5454  wasCalledActionStub() :
     55      Action("wasCalledActionStub",false),
    5556      called(false)
    5657  {}
Note: See TracChangeset for help on using the changeset viewer.