/*
* 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 .
*/
/*
* SetShapeAction.cpp
*
* Created on: Sep 6, 2012
* Author: ankele
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include "CodePatterns/MemDebug.hpp"
#include "Shapes/ShapeFactory.hpp"
#include "CodePatterns/Log.hpp"
#include "CodePatterns/Verbose.hpp"
#include
#include
#include "SetShapeAction.hpp"
using namespace MoleCuilder;
// and construct the stuff
#include "SetShapeAction.def"
#include "Action_impl_pre.hpp"
/** =========== define the function ====================== */
Action::state_ptr ShapeSetShapeAction::performCall() {
ShapeFactory &factory = ShapeFactory::getInstance();
LOG(1, "Setting shape factory to: '" << params.shape_type.get() << "'");
const std::string old_type = factory.getShapeName(factory.getType());
Vector old_translation = factory.getTranslation();
Vector old_stretch = factory.getStretch();
double old_angle_x = factory.getAngle()[0];
double old_angle_y = factory.getAngle()[1];
double old_angle_z = factory.getAngle()[2];
factory.setType(factory.getShapeByName(params.shape_type.get()));
factory.setTranslation(params.translation.get());
factory.setStretch(params.stretch.get());
factory.setAngle(params.angle_x.get(), params.angle_y.get(), params.angle_z.get());
return Action::state_ptr(new ShapeSetShapeState(old_type, old_translation, old_stretch, old_angle_x, old_angle_y, old_angle_z, params));
}
Action::state_ptr ShapeSetShapeAction::performUndo(Action::state_ptr _state) {
ShapeFactory &factory = ShapeFactory::getInstance();
ShapeSetShapeState *state = assert_cast(_state.get());
LOG(1, "INFO: Reverting shape factory to '" << state->old_type << "'.");
factory.setType(factory.getShapeByName(state->old_type));
factory.setTranslation(state->old_translation);
factory.setStretch(state->old_stretch);
factory.setAngle(state->old_angle_x, state->old_angle_y, state->old_angle_z);
return Action::state_ptr(_state);
}
Action::state_ptr ShapeSetShapeAction::performRedo(Action::state_ptr _state){
ShapeFactory &factory = ShapeFactory::getInstance();
factory.setType(factory.getShapeByName(params.shape_type.get()));
factory.setTranslation(params.translation.get());
factory.setStretch(params.stretch.get());
factory.setAngle(params.angle_x.get(), params.angle_y.get(), params.angle_z.get());
return Action::state_ptr(_state);
}
bool ShapeSetShapeAction::canUndo() {
return true;
}
bool ShapeSetShapeAction::shouldUndo() {
return true;
}
/** =========== end of function ====================== */