Changeset d56640 for src


Ignore:
Timestamp:
Mar 25, 2010, 12:01:27 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:
975a11, b31bc4
Parents:
5b0b98
git-author:
Tillmann Crueger <crueger@…> (03/25/10 11:59:56)
git-committer:
Tillmann Crueger <crueger@…> (03/25/10 12:01:27)
Message:

Added full undo functioniality

Location:
src
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    r5b0b98 rd56640  
    1010#include "Actions/Action.hpp"
    1111#include "Actions/ActionRegistry.hpp"
     12#include "Actions/ActionHistory.hpp"
    1213
    1314using namespace std;
     
    3435void Action::call(){
    3536  // forward to private virtual
    36   performCall();
     37  state_ptr state = performCall();
     38  if(shouldUndo() && state != failure){
     39    if(canUndo()){
     40      ActionHistory::getInstance().addElement(this,state);
     41    }
     42    else{
     43      ActionHistory::getInstance().clear();
     44    }
     45  }
    3746}
    3847Action::state_ptr Action::undo(state_ptr _state) {
  • src/Actions/ActionRegistry.cpp

    r5b0b98 rd56640  
    1212
    1313#include <string>
    14 #include <cassert>
     14#include "Helpers/Assert.hpp"
    1515#include <iostream>
    1616
     
    3333  map<const string,Action*>::iterator iter;
    3434  iter = actionMap.find(name);
    35   assert(iter!=actionMap.end() && "Query for an action not stored in registry");
     35  ASSERT(iter!=actionMap.end(),"Query for an action not stored in registry");
    3636  return iter->second;
    3737}
     
    4040  pair<map<const string,Action*>::iterator,bool> ret;
    4141  ret = actionMap.insert(pair<const string,Action*>(action->getName(),action));
    42   assert(ret.second && "Two actions with the same name added to registry");
     42  ASSERT(ret.second,"Two actions with the same name added to registry");
    4343}
    4444
  • src/Actions/small_actions.cpp

    r5b0b98 rd56640  
    2626};
    2727
    28 char ChangeMoleculeNameAction::NAME[] = "Change filename of Molecule";
     28const char ChangeMoleculeNameAction::NAME[] = "Change filename of Molecule";
    2929
    3030ChangeMoleculeNameAction::ChangeMoleculeNameAction(MoleculeListClass *_molecules) :
  • src/Actions/small_actions.hpp

    r5b0b98 rd56640  
    2424
    2525  MoleculeListClass *molecules;
    26   static char NAME[];
     26  static const char NAME[];
    2727};
    2828
  • src/Makefile.am

    r5b0b98 rd56640  
    88ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
    99
    10 ACTIONSSOURCE = Actions/Action.cpp Actions/Process.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/small_actions.cpp Actions/ManipulateAtomsProcess.cpp Actions/ActionRegistry.cpp
    11 ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/Calculation.hpp Actions/Calculation_impl.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ManipulateAtomsProcess.hpp Actions/ActionRegistry.hpp
     10ACTIONSSOURCE = Actions/Action.cpp \
     11                                Actions/ActionHistory.cpp \
     12                                Actions/ActionRegistry.cpp \
     13                                Actions/ActionSequence.cpp \
     14                                Actions/ErrorAction.cpp \
     15                                Actions/MakroAction.cpp \
     16                                Actions/ManipulateAtomsProcess.cpp \
     17                                Actions/MethodAction.cpp \
     18                Actions/Process.cpp \
     19                Actions/small_actions.cpp
     20               
     21                 
     22ACTIONSHEADER = Actions/Action.hpp \
     23                                Actions/ActionHistory.hpp \
     24                                Actions/ActionRegistry.hpp \
     25                                Actions/ActionSequence.hpp \
     26                            Actions/Calculation.hpp \
     27                            Actions/Calculation_impl.hpp \
     28                            Actions/ErrorAction.hpp \
     29                            Actions/MakroAction.hpp \
     30                            Actions/ManipulateAtomsProcess.hpp \
     31                            Actions/MethodAction.hpp \
     32                            Actions/Process.hpp \
     33                            Actions/small_actions.hpp
     34                           
     35                           
    1236
    1337PATTERNSOURCE = Patterns/Observer.cpp
  • src/Menu/TextMenu.cpp

    r5b0b98 rd56640  
    1111#include "Menu/TextMenu.hpp"
    1212#include "Menu/MenuItem.hpp"
     13#include "Helpers/Assert.hpp"
    1314
    1415
     
    8889}
    8990
     91string TextMenu::getTitle(){
     92  return title;
     93}
     94
    9095void TextMenu::addDefault(MenuItem* _defaultItem) {
    9196  defaultItem = _defaultItem;
    9297}
     98
     99/****************************** Contained Actions ****************/
     100
     101const string TextMenu::LeaveAction::nameBase = "Leave menu: ";
     102
     103TextMenu::LeaveAction::LeaveAction(TextMenu* _menu) :
     104Action(nameBase+_menu->getTitle()),
     105menu(_menu)
     106{}
     107
     108TextMenu::LeaveAction::~LeaveAction(){}
     109
     110bool TextMenu::LeaveAction::canUndo(){
     111  return false;
     112}
     113
     114bool TextMenu::LeaveAction::shouldUndo(){
     115  return false;
     116}
     117
     118Action::state_ptr TextMenu::LeaveAction::performCall(){
     119  menu->doQuit();
     120  return Action::success;
     121}
     122
     123
     124Action::state_ptr TextMenu::LeaveAction::performUndo(Action::state_ptr){
     125  ASSERT(0,"Cannot undo leaving a menu");
     126  return Action::success;
     127}
     128
     129Action::state_ptr TextMenu::LeaveAction::performRedo(Action::state_ptr){
     130  ASSERT(0,"Cannot redo leaving a menu");
     131  return Action::success;
     132}
  • src/Menu/TextMenu.hpp

    r5b0b98 rd56640  
    1414
    1515#include "Menu/Menu.hpp"
     16#include "Actions/Action.hpp"
    1617#include "defs.hpp"
    1718
     
    2627{
    2728public:
     29  class LeaveAction : public Action {
     30  public:
     31    LeaveAction(TextMenu*);
     32    virtual ~LeaveAction();
     33
     34    bool canUndo();
     35    bool shouldUndo();
     36
     37  private:
     38    virtual Action::state_ptr performCall();
     39    virtual Action::state_ptr performUndo(Action::state_ptr);
     40    virtual Action::state_ptr performRedo(Action::state_ptr);
     41
     42    TextMenu* menu;
     43
     44    static const string nameBase;
     45  };
     46
    2847  TextMenu(ostream& _outputter, string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH);
    2948  virtual ~TextMenu();
     
    3251  virtual void removeItem(MenuItem*);
    3352  virtual void display();
     53  virtual string getTitle();
    3454
    3555  /**
  • src/UIElements/TextDialog.cpp

    r5b0b98 rd56640  
    6868
    6969bool TextDialog::StringTextQuery::handle() {
    70   //Log() << Verbose(0) << getTitle();
     70  Log() << Verbose(0) << getTitle();
    7171  cin >> tmp;
    7272  return true;
  • src/UIElements/TextWindow.cpp

    r5b0b98 rd56640  
    9494  populaters.MakeEditMoleculesMenu(editMoleculesMenu,molecules,configuration,periode);
    9595
    96   returnFromEditMoleculeAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,editMoleculesMenu),false);
     96  Action *returnFromEditMoleculeAction = new TextMenu::LeaveAction(editMoleculesMenu);
    9797  MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnFromEditMoleculeAction);
    9898
     
    108108  delete old_menu;
    109109  delete quitAction;
    110   delete returnFromEditMoleculeAction;
    111110  delete moleculeView;
    112111  delete statusIndicator;
  • src/UIElements/TextWindow.hpp

    r5b0b98 rd56640  
    2929  // some actions only needed in textMenus
    3030  Action *quitAction;
    31   Action *returnFromEditMoleculeAction;
    3231  // all views that are contained in the main Menu
    3332  StringView *moleculeView;
  • src/builder.cpp

    r5b0b98 rd56640  
    7474#include "Menu/ActionMenuItem.hpp"
    7575#include "Actions/ActionRegistry.hpp"
     76#include "Actions/ActionHistory.hpp"
    7677#include "Actions/MethodAction.hpp"
    7778#include "Actions/small_actions.hpp"
     
    21922193
    21932194    setVerbosity(0);
     2195    // need to init the history before any action is created
     2196    ActionHistory::init();
    21942197    /* structure of ParseCommandLineOptions will be refactored later */
    21952198    j = ParseCommandLineOptions(argc, argv,  World::getInstance().getMolecules(), World::getInstance().getPeriode(), *configuration, ConfigFileName);
Note: See TracChangeset for help on using the changeset viewer.