/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2010-2012 University of Bonn. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* ScaleBoxAction.cpp
*
* Created on: May 8, 2010
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include "CodePatterns/MemDebug.hpp"
#include "Atom/atom.hpp"
#include "CodePatterns/Log.hpp"
#include "LinearAlgebra/RealSpaceMatrix.hpp"
#include "LinearAlgebra/Vector.hpp"
#include "World.hpp"
#include "Box.hpp"
#include
#include
#include
#include "Actions/WorldAction/ScaleBoxAction.hpp"
using namespace MoleCuilder;
// and construct the stuff
#include "ScaleBoxAction.def"
#include "Action_impl_pre.hpp"
/** =========== define the function ====================== */
Action::state_ptr WorldScaleBoxAction::performCall() {
double x[NDIM];
// scale atoms
for (int i=0;i AllAtoms = World::getInstance().getAllAtoms();
for(std::vector::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) {
(*AtomRunner)->ScaleAll(x);
}
// scale box
RealSpaceMatrix M = World::getInstance().getDomain().getM();
RealSpaceMatrix scale;
for (int i=0;i(_state.get());
// scale back atoms
double x[NDIM];
for (int i=0;iparams.Scaler.get()[i];
vector AllAtoms = World::getInstance().getAllAtoms();
for(vector::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) {
(*AtomRunner)->ScaleAll(x);
}
// scale back box
RealSpaceMatrix M = World::getInstance().getDomain().getM();
RealSpaceMatrix scale;
for (int i=0;iparams.Scaler.get()[i];
}
M *= scale;
World::getInstance().setDomain(M);
// give final box size
LOG(0, "Box domain restored to " << World::getInstance().getDomain().getM());
return Action::state_ptr(_state);
}
Action::state_ptr WorldScaleBoxAction::performRedo(Action::state_ptr _state){
WorldScaleBoxState *state = assert_cast(_state.get());
// scale atoms
double x[NDIM];
for (int i=0;iparams.Scaler.get()[i];
vector AllAtoms = World::getInstance().getAllAtoms();
for(vector::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) {
(*AtomRunner)->ScaleAll(x);
}
// scale box
RealSpaceMatrix M = World::getInstance().getDomain().getM();
RealSpaceMatrix scale;
for (int i=0;iparams.Scaler.get()[i];
}
M *= scale;
World::getInstance().setDomain(M);
// give final box size
LOG(0, "Box domain is again " << World::getInstance().getDomain().getM());
return Action::state_ptr(_state);
}
bool WorldScaleBoxAction::canUndo() {
return true;
}
bool WorldScaleBoxAction::shouldUndo() {
return true;
}
/** =========== end of function ====================== */