Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/WorldAction/CenterOnEdgeAction.cpp

    rde7d1d rce7fdc  
    1818#endif
    1919
    20 // include headers that implement a archive in simple text format
    21 #include <boost/archive/text_oarchive.hpp>
    22 #include <boost/archive/text_iarchive.hpp>
    23 #include "boost/serialization/vector.hpp"
    24 
    2520#include "CodePatterns/MemDebug.hpp"
    2621
    2722#include "atom.hpp"
    2823#include "CodePatterns/Log.hpp"
    29 #include "LinearAlgebra/MatrixContent.hpp"
     24#include "LinearAlgebra/Vector.hpp"
     25#include "World.hpp"
    3026#include "LinearAlgebra/RealSpaceMatrix.hpp"
    31 #include "LinearAlgebra/Vector.hpp"
    32 #include "molecule.hpp"
    33 #include "World.hpp"
    3427
    3528#include <iostream>
    3629#include <string>
    37 #include <vector>
    3830
    3931#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
     
    5244  getParametersfromValueStorage();
    5345
    54   // create undo state
    55   std::stringstream undostream;
    56   boost::archive::text_oarchive oa(undostream);
    57   const RealSpaceMatrix &matrix = World::getInstance().getDomain().getM();
    58   oa << matrix;
    59   std::vector< boost::shared_ptr<Vector> > OldPositions;
    60   std::vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
    61   for (std::vector<atom *>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
    62     OldPositions.push_back(
    63         boost::shared_ptr<Vector>(new Vector(
    64             (*AtomRunner)->getPosition()
    65             ))
    66         );
    67 
    6846  // get maximum and minimum
     47  vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
    6948  ASSERT(AllAtoms.size() > 0, "For CenteronEdge atoms must be present.");
    70   std::vector<atom *>::iterator AtomRunner = AllAtoms.begin();
     49  vector<atom *>::iterator AtomRunner = AllAtoms.begin();
    7150  Min = (*AtomRunner)->getPosition();
    7251  Max = (*AtomRunner)->getPosition();
     
    8867  World::getInstance().setDomain(domain);
    8968  // translate all atoms, such that Min is aty (0,0,0)
    90   for (std::vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
     69  for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
    9170    *(*AtomRunner) -= Min;
    9271
     
    9473  LOG(0, "Box domain is now " << World::getInstance().getDomain().getM());
    9574
    96   // create undo state
    97   WorldCenterOnEdgeState *UndoState =
    98       new WorldCenterOnEdgeState(
    99           undostream.str(),
    100           Min,
    101           Max,
    102           params
    103           );
    104 
    105   return Action::state_ptr(UndoState);
     75  return Action::success;
    10676}
    10777
    10878Action::state_ptr WorldCenterOnEdgeAction::performUndo(Action::state_ptr _state) {
    109   WorldCenterOnEdgeState *state = assert_cast<WorldCenterOnEdgeState*>(_state.get());
     79//  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
    11080
    111   // restore domain
    112   RealSpaceMatrix matrix;
    113   std::stringstream undostream(state->undostring);
    114   boost::archive::text_iarchive ia(undostream);
    115   ia >> matrix;
    116   World::getInstance().setDomain(matrix);
    117 
    118   // translate all atoms back
    119   std::vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
    120   for (vector<atom*>::iterator AtomRunner = AllAtoms.begin();
    121       AtomRunner != AllAtoms.end();
    122       ++AtomRunner)
    123     *(*AtomRunner) += state->Min;
    124 
    125   // give final box size
    126   LOG(0, "Box domain restored to " << World::getInstance().getDomain().getM());
    127 
    128   return Action::state_ptr(_state);
     81  return Action::failure;
     82//  string newName = state->mol->getName();
     83//  state->mol->setName(state->lastName);
     84//
     85//  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
    12986}
    13087
    13188Action::state_ptr WorldCenterOnEdgeAction::performRedo(Action::state_ptr _state){
    132   WorldCenterOnEdgeState *state = assert_cast<WorldCenterOnEdgeState*>(_state.get());
    133 
    134   // set new box size
    135   RealSpaceMatrix rmatrix;
    136   for (int i=0;i<NDIM;i++) {
    137     double tmp = state->Max[i]-state->Min[i];
    138     tmp = fabs(tmp)>=1. ? tmp : 1.0;
    139     rmatrix.at(i,i) = tmp;
    140   }
    141   World::getInstance().setDomain(rmatrix);
    142   // translate all atoms, such that Min is aty (0,0,0)
    143   std::vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
    144   for (vector<atom*>::iterator AtomRunner = AllAtoms.begin();
    145       AtomRunner != AllAtoms.end();
    146       ++AtomRunner)
    147     *(*AtomRunner) -= state->Min;
    148 
    149   // give final box size
    150   LOG(0, "Box domain is again " << World::getInstance().getDomain().getM());
    151 
    152   return Action::state_ptr(_state);
     89  return Action::failure;
    15390}
    15491
    15592bool WorldCenterOnEdgeAction::canUndo() {
    156   return true;
     93  return false;
    15794}
    15895
    15996bool WorldCenterOnEdgeAction::shouldUndo() {
    160   return true;
     97  return false;
    16198}
    16299/** =========== end of function ====================== */
Note: See TracChangeset for help on using the changeset viewer.