Changeset 536b13 for src/Actions


Ignore:
Timestamp:
Jun 20, 2017, 8:01:31 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, ChangeBugEmailaddress, ChemicalSpaceEvaluator, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph_documentation, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_oldresults, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, IndependentFragmentGrids_IntegrationTest, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, StoppableMakroAction, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps
Children:
da7ef9
Parents:
5e17bf
git-author:
Frederik Heber <heber@…> (03/23/17 03:37:36)
git-committer:
Frederik Heber <frederik.heber@…> (06/20/17 20:01:31)
Message:

RotateToPrincipalAxisSystemAction now has Undo/Redo working.

  • TESTS: Removed XFAIL from these tests.
Location:
src/Actions/MoleculeAction
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.cpp

    r5e17bf r536b13  
    3535//#include "CodePatterns/MemDebug.hpp"
    3636
     37#include "CodePatterns/Assert.hpp"
    3738#include "CodePatterns/Log.hpp"
    38 #include "CodePatterns/Verbose.hpp"
     39
     40#include "Actions/UndoRedoHelpers.hpp"
     41#include "Atom/AtomicInfo.hpp"
    3942#include "LinearAlgebra/Line.hpp"
    4043#include "LinearAlgebra/RealSpaceMatrix.hpp"
     
    5861  molecule *mol = NULL;
    5962
     63  std::vector<AtomicInfo> UndoInfo;
    6064  for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
    6165    mol = iter->second;
    6266    LOG(0, "Converting to prinicipal axis system.");
    6367
    64     RealSpaceMatrix InertiaTensor = mol->getInertiaTensor();
     68    // gather undo information: store position of all atoms of molecule
     69    UndoInfo.reserve(UndoInfo.size()+mol->size());
     70    {
     71      for (molecule::const_iterator iter = const_cast<molecule const *>(mol)->begin();
     72          iter != const_cast<molecule const *>(mol)->end();
     73          ++iter) {
     74        const atom * const Walker = *iter;
     75        UndoInfo.push_back(AtomicInfo(*Walker));
     76      }
     77    }
    6578
     79    // rotate
     80//    RealSpaceMatrix InertiaTensor = mol->getInertiaTensor();
    6681    mol->RotateToPrincipalAxisSystem(params.Axis.get());
    6782
    6883    // summing anew for debugging (resulting matrix has to be diagonal!)
    69     InertiaTensor = mol->getInertiaTensor();
     84    RealSpaceMatrix InertiaTensor = mol->getInertiaTensor();
    7085  }
    71   return Action::success;
     86
     87  MoleculeRotateToPrincipalAxisSystemState *UndoState =
     88      new MoleculeRotateToPrincipalAxisSystemState(UndoInfo, params);
     89  return ActionState::ptr(UndoState);
    7290}
    7391
    7492ActionState::ptr MoleculeRotateToPrincipalAxisSystemAction::performUndo(ActionState::ptr _state) {
    75 //  MoleculeRotateToPrincipalAxisSystemState *state = assert_cast<MoleculeRotateToPrincipalAxisSystemState*>(_state.get());
     93  MoleculeRotateToPrincipalAxisSystemState *state =
     94      assert_cast<MoleculeRotateToPrincipalAxisSystemState*>(_state.get());
    7695
    77 //  string newName = state->mol->getName();
    78 //  state->mol->setName(state->lastName);
     96  // set stored old state
     97  SetAtomsFromAtomicInfo(state->undoinfo);
    7998
    80   STATUS("Undo of MoleculeRotateToPrincipalAxisSystemAction not implemented.");
    81   return Action::failure;
     99  return ActionState::ptr(_state);
    82100}
    83101
    84102ActionState::ptr MoleculeRotateToPrincipalAxisSystemAction::performRedo(ActionState::ptr _state){
    85   STATUS("Redo of MoleculeRotateToPrincipalAxisSystemAction not implemented.");
    86   return Action::failure;
     103  MoleculeRotateToPrincipalAxisSystemState *state =
     104      assert_cast<MoleculeRotateToPrincipalAxisSystemState*>(_state.get());
     105
     106  for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection();
     107      iter != World::getInstance().endMoleculeSelection(); ++iter) {
     108    molecule * const mol = iter->second;
     109    mol->RotateToPrincipalAxisSystem(state->params.Axis.get());
     110  }
     111
     112  return ActionState::ptr(_state);
    87113}
    88114
  • src/Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.def

    r5e17bf r536b13  
    77
    88// all includes and forward declarations necessary for non-integral types below
     9#include <vector>
     10
    911#include "Actions/Values.hpp"
     12#include "Atom/AtomicInfo.hpp"
    1013#include "LinearAlgebra/Vector.hpp"
    1114
     
    2326(VectorNotZeroValidator())
    2427
    25 #undef statetypes
    26 #undef statereferences
     28#define statetypes (std::vector<AtomicInfo>)
     29#define statereferences (undoinfo)
    2730
    2831// some defines for all the names, you may use ACTION, STATE and PARAMS
Note: See TracChangeset for help on using the changeset viewer.