/*
 * 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 .
 */
/*
 * TranslateShapeAction.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 "TranslateShapeAction.hpp"
using namespace MoleCuilder;
// and construct the stuff
#include "TranslateShapeAction.def"
#include "Action_impl_pre.hpp"
/** =========== define the function ====================== */
Action::state_ptr ShapeTranslateShapeAction::performCall() {
  LOG(1, "Translating shapes in ShapeRegistry.");
  std::vector old_shapes;
  std::vector selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
  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 ShapeTranslateShapeState(old_shapes, params));
}
Action::state_ptr ShapeTranslateShapeAction::performUndo(Action::state_ptr _state) {
  ShapeTranslateShapeState *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 ShapeTranslateShapeAction::performRedo(Action::state_ptr _state){
  ShapeTranslateShapeState *state = assert_cast(_state.get());
  std::vector selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
  for (unsigned int i=0;iparams.translation.get());
    std::string name = selectedShapes[i]->getName();
    s.setName(name);
    ShapeRegistry::getInstance().removeShape(name);
    ShapeRegistry::getInstance().addShape(s);
    ShapeRegistry::getInstance().selectShape(name);
  }
  return Action::state_ptr(_state);
}
bool ShapeTranslateShapeAction::canUndo() {
  return true;
}
bool ShapeTranslateShapeAction::shouldUndo() {
  return true;
}
/** =========== end of function ====================== */