/* * 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 . */ /* * StretchShapeAction.cpp * * Created on: Nov 19, 2012 * Author: ankele */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Shapes/ShapeRegistry.hpp" #include "Shapes/ShapeOps.hpp" #include "CodePatterns/Log.hpp" #include "CodePatterns/Verbose.hpp" #include #include #include "StretchShapeAction.hpp" using namespace MoleCuilder; // and construct the stuff #include "StretchShapeAction.def" #include "Action_impl_pre.hpp" /** =========== define the function ====================== */ Action::state_ptr ShapeStretchShapeAction::performCall() { LOG(1, "Translating shapes in ShapeRegistry."); std::vector selectedShapes = ShapeRegistry::getInstance().getSelectedShapes(); std::vector old_shapes; Vector helper = params.center.get(); helper.ScaleAll(params.stretch.get()); Vector translation = params.center.get() - helper; for (unsigned int i=0;igetName(); s.setName(name); ShapeRegistry::getInstance().removeShape(name); ShapeRegistry::getInstance().addShape(s); ShapeRegistry::getInstance().selectShape(name); } return Action::state_ptr(new ShapeStretchShapeState(old_shapes, params)); } Action::state_ptr ShapeStretchShapeAction::performUndo(Action::state_ptr _state) { ShapeStretchShapeState *state = assert_cast(_state.get()); for (unsigned int i=0;iold_shapes.size();i++){ std::string name = state->old_shapes[i].getName(); ShapeRegistry::getInstance().removeShape(name); ShapeRegistry::getInstance().addShape(state->old_shapes[i]); ShapeRegistry::getInstance().selectShape(name); } return Action::state_ptr(_state); } Action::state_ptr ShapeStretchShapeAction::performRedo(Action::state_ptr _state){ ShapeStretchShapeState *state = assert_cast(_state.get()); std::vector selectedShapes = ShapeRegistry::getInstance().getSelectedShapes(); Vector helper = params.center.get(); helper.ScaleAll(params.stretch.get()); Vector translation = params.center.get() - helper; for (unsigned int i=0;igetName(); s.setName(name); ShapeRegistry::getInstance().removeShape(name); ShapeRegistry::getInstance().addShape(s); ShapeRegistry::getInstance().selectShape(name); } return Action::state_ptr(_state); } bool ShapeStretchShapeAction::canUndo() { return true; } bool ShapeStretchShapeAction::shouldUndo() { return true; } /** =========== end of function ====================== */