Changeset e41c48 for src


Ignore:
Timestamp:
Aug 10, 2010, 11:31:36 AM (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:
f8456c
Parents:
353e82
git-author:
Frederik Heber <heber@…> (08/10/10 11:29:23)
git-committer:
Frederik Heber <heber@…> (08/10/10 11:31:36)
Message:

RemoveAction has Undo/Redo capability.

  • FIX: atom::getMolecule() is now const member function
  • new class AtomicInfo that stores essential info contained in atom.
  • TESTFIX: had to pre/replace test.conf due to wrong MaxMinStopSteps, PsiNumbers in original file ... (this never occured because we compared against this in post/)
  • added test for undo/redo to Simple_configuration/5
Location:
src
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/AtomAction/RemoveAction.cpp

    r353e82 re41c48  
    1111#include "Actions/ActionRegistry.hpp"
    1212#include "atom.hpp"
     13#include "AtomicInfo.hpp"
    1314#include "Descriptors/AtomDescriptor.hpp"
    1415#include "Helpers/Log.hpp"
     
    2526#include "UIElements/Dialog.hpp"
    2627#include "Actions/ValueStorage.hpp"
     28
     29// memento to remember the state when undoing
     30
     31class AtomRemoveState : public ActionState {
     32public:
     33  AtomRemoveState(std::vector<AtomicInfo> _Walkers) :
     34    Walkers(_Walkers)
     35  {}
     36  std::vector<AtomicInfo> Walkers;
     37};
    2738
    2839const char AtomRemoveAction::NAME[] = "remove-atom";
     
    5061  atom *first = NULL;
    5162
    52   std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
     63  // create undo state
     64  std::vector<AtomicInfo> Walkers;
     65  for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) {
     66    Walkers.push_back(AtomicInfo(*(iter->second)));
     67  }
     68  AtomRemoveState *UndoState = new AtomRemoveState(Walkers);
     69
     70  // remove all selected atoms
     71//  std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
    5372  for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) {
    5473    first = iter->second;
    5574    DoLog(1) && (Log() << Verbose(1) << "Removing atom " << first->getId() << "." << endl);
    56     // TODO: this is not necessary when atoms and their storing to file are handled by the World
    57     // simply try to erase in every molecule found
    58     for (std::vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end(); ++iter) {
    59       (*iter)->erase(first);
    60     }
     75//    // TODO: this is not necessary when atoms and their storing to file are handled by the World
     76//    // simply try to erase in every molecule found
     77//    for (std::vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end(); ++iter) {
     78//      (*iter)->erase(first);
     79//    }
    6180    World::getInstance().destroyAtom(first);
    6281  }
    63   return Action::success;
     82  return Action::state_ptr(UndoState);
    6483}
    6584
    6685Action::state_ptr AtomRemoveAction::performUndo(Action::state_ptr _state) {
    67 //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
     86  AtomRemoveState *state = assert_cast<AtomRemoveState*>(_state.get());
    6887
    69   return Action::failure;
    70 //  string newName = state->mol->getName();
    71 //  state->mol->setName(state->lastName);
    72 //
    73 //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
     88  size_t i=0;
     89  for (; i<state->Walkers.size(); ++i) {
     90    // re-create the atom
     91    DoLog(1) && (Log() << Verbose(1) << "Re-adding atom " << state->Walkers[i].getId() << "." << endl);
     92    atom *Walker = World::getInstance().createAtom();
     93    if (!state->Walkers[i].setAtom(*Walker)) {
     94      DoeLog(1) && (eLog() << Verbose(1) << "Failed to set id." << endl);
     95      World::getInstance().destroyAtom(Walker);
     96      break;
     97    }
     98  }
     99  if (i<state->Walkers.size()) {
     100    // remove all previous ones, too
     101    for (size_t j=0;j<i;++j)
     102      World::getInstance().destroyAtom(state->Walkers[j].getId());
     103    // and announce the failure of the undo
     104    return Action::failure;
     105  }
     106  return Action::state_ptr(_state);
    74107}
    75108
    76109Action::state_ptr AtomRemoveAction::performRedo(Action::state_ptr _state){
    77   return Action::failure;
     110  AtomRemoveState *state = assert_cast<AtomRemoveState*>(_state.get());
     111
     112  // simple remove again all previously added atoms
     113  for (size_t i=0; i<state->Walkers.size(); ++i) {
     114    DoLog(1) && (Log() << Verbose(1) << "Re-removing atom " << state->Walkers[i].getId() << "." << endl);
     115    World::getInstance().destroyAtom(state->Walkers[i].getId());
     116  }
     117
     118  return Action::state_ptr(_state);
    78119}
    79120
    80121bool AtomRemoveAction::canUndo() {
    81   return false;
     122  return true;
    82123}
    83124
    84125bool AtomRemoveAction::shouldUndo() {
    85   return false;
     126  return true;
    86127}
    87128
  • src/Makefile.am

    r353e82 re41c48  
    66ATOMSOURCE = \
    77  atom.cpp \
     8  AtomicInfo.cpp \
    89  atom_atominfo.cpp \
    910  atom_bondedparticle.cpp \
     
    1617ATOMHEADER = \
    1718  atom.hpp \
     19  AtomicInfo.hpp \
    1820  atom_atominfo.hpp \
    1921  atom_bondedparticle.hpp \
  • src/atom.cpp

    r353e82 re41c48  
    353353}
    354354
    355 molecule* atom::getMolecule(){
     355molecule* atom::getMolecule() const {
    356356  return mol;
    357357}
  • src/atom.hpp

    r353e82 re41c48  
    9292
    9393   void setMolecule(molecule*);
    94    molecule* getMolecule();
     94   molecule* getMolecule() const;
    9595   void removeFromMolecule();
    9696
Note: See TracChangeset for help on using the changeset viewer.