| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | /*
 | 
|---|
| 9 |  * CopyAction.cpp
 | 
|---|
| 10 |  *
 | 
|---|
| 11 |  *  Created on: May 10, 2010
 | 
|---|
| 12 |  *      Author: heber
 | 
|---|
| 13 |  */
 | 
|---|
| 14 | 
 | 
|---|
| 15 | // include config.h
 | 
|---|
| 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 17 | #include <config.h>
 | 
|---|
| 18 | #endif
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 23 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| 24 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| 25 | #include "atom.hpp"
 | 
|---|
| 26 | #include "bond.hpp"
 | 
|---|
| 27 | #include "molecule.hpp"
 | 
|---|
| 28 | #include "World.hpp"
 | 
|---|
| 29 | 
 | 
|---|
| 30 | #include <iostream>
 | 
|---|
| 31 | #include <fstream>
 | 
|---|
| 32 | #include <string>
 | 
|---|
| 33 | 
 | 
|---|
| 34 | using namespace std;
 | 
|---|
| 35 | 
 | 
|---|
| 36 | #include "Actions/MoleculeAction/CopyAction.hpp"
 | 
|---|
| 37 | 
 | 
|---|
| 38 | // and construct the stuff
 | 
|---|
| 39 | #include "CopyAction.def"
 | 
|---|
| 40 | #include "Action_impl_pre.hpp"
 | 
|---|
| 41 | /** =========== define the function ====================== */
 | 
|---|
| 42 | Action::state_ptr MoleculeCopyAction::performCall() {
 | 
|---|
| 43 |   molecule *copy = NULL;
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   // obtain information
 | 
|---|
| 46 |   getParametersfromValueStorage();
 | 
|---|
| 47 | 
 | 
|---|
| 48 |   copy = params.mol->CopyMolecule();
 | 
|---|
| 49 |   Vector *Center = params.mol->DetermineCenterOfAll();
 | 
|---|
| 50 |   *Center *= -1.;
 | 
|---|
| 51 |   *Center += params.position;
 | 
|---|
| 52 |   copy->Translate(Center);
 | 
|---|
| 53 |   delete(Center);
 | 
|---|
| 54 | 
 | 
|---|
| 55 |   return Action::state_ptr(new MoleculeCopyState(copy,params));
 | 
|---|
| 56 | }
 | 
|---|
| 57 | 
 | 
|---|
| 58 | Action::state_ptr MoleculeCopyAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 59 |   MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
 | 
|---|
| 60 | 
 | 
|---|
| 61 |   for (molecule::iterator AtomRunner = state->copy->begin(); !state->copy->empty(); AtomRunner = state->copy->begin()) {
 | 
|---|
| 62 |     for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
 | 
|---|
| 63 |       delete(*BondRunner);
 | 
|---|
| 64 |     atom *Walker = *AtomRunner;
 | 
|---|
| 65 |     state->copy->erase(AtomRunner);
 | 
|---|
| 66 |     World::getInstance().destroyAtom(Walker);
 | 
|---|
| 67 |   }
 | 
|---|
| 68 |   World::getInstance().destroyMolecule(state->copy);
 | 
|---|
| 69 | 
 | 
|---|
| 70 |   return Action::state_ptr(_state);
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | Action::state_ptr MoleculeCopyAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 74 |   MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
 | 
|---|
| 75 | 
 | 
|---|
| 76 |   molecule *copy = state->params.mol->CopyMolecule();
 | 
|---|
| 77 |   Vector *Center = state->params.mol->DetermineCenterOfAll();
 | 
|---|
| 78 |   *Center *= -1.;
 | 
|---|
| 79 |   *Center += state->params.position;
 | 
|---|
| 80 |   copy->Translate(Center);
 | 
|---|
| 81 |   delete(Center);
 | 
|---|
| 82 | 
 | 
|---|
| 83 |   return Action::state_ptr(new MoleculeCopyState(copy,state->params));
 | 
|---|
| 84 | }
 | 
|---|
| 85 | 
 | 
|---|
| 86 | bool MoleculeCopyAction::canUndo() {
 | 
|---|
| 87 |   return true;
 | 
|---|
| 88 | }
 | 
|---|
| 89 | 
 | 
|---|
| 90 | bool MoleculeCopyAction::shouldUndo() {
 | 
|---|
| 91 |   return true;
 | 
|---|
| 92 | }
 | 
|---|
| 93 | /** =========== end of function ====================== */
 | 
|---|