| [1a7fd2] | 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 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [1a7fd2] | 21 | 
 | 
|---|
| [ad011c] | 22 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 23 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [1a7fd2] | 24 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 25 | #include "atom.hpp"
 | 
|---|
| [129204] | 26 | #include "Bond/bond.hpp"
 | 
|---|
| [1a7fd2] | 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 | 
 | 
|---|
| [9d83b6] | 61 |   for (molecule::iterator AtomRunner = state->copy->begin();
 | 
|---|
 | 62 |       !state->copy->empty();
 | 
|---|
 | 63 |       AtomRunner = state->copy->begin()) {
 | 
|---|
| [5e2f80] | 64 |     (*AtomRunner)->removeAllBonds();
 | 
|---|
 | 65 | //    BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
 | 
|---|
 | 66 | //    for(BondList::iterator BondRunner = ListOfBonds.begin();
 | 
|---|
 | 67 | //        !ListOfBonds.empty();
 | 
|---|
 | 68 | //        BondRunner = ListOfBonds.begin()) {
 | 
|---|
 | 69 | //      delete(*BondRunner);
 | 
|---|
 | 70 | //    }
 | 
|---|
| [1a7fd2] | 71 |     atom *Walker = *AtomRunner;
 | 
|---|
 | 72 |     World::getInstance().destroyAtom(Walker);
 | 
|---|
 | 73 |   }
 | 
|---|
 | 74 |   World::getInstance().destroyMolecule(state->copy);
 | 
|---|
 | 75 | 
 | 
|---|
 | 76 |   return Action::state_ptr(_state);
 | 
|---|
 | 77 | }
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | Action::state_ptr MoleculeCopyAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 80 |   MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 |   molecule *copy = state->params.mol->CopyMolecule();
 | 
|---|
 | 83 |   Vector *Center = state->params.mol->DetermineCenterOfAll();
 | 
|---|
 | 84 |   *Center *= -1.;
 | 
|---|
 | 85 |   *Center += state->params.position;
 | 
|---|
 | 86 |   copy->Translate(Center);
 | 
|---|
 | 87 |   delete(Center);
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 |   return Action::state_ptr(new MoleculeCopyState(copy,state->params));
 | 
|---|
 | 90 | }
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 | bool MoleculeCopyAction::canUndo() {
 | 
|---|
 | 93 |   return true;
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | bool MoleculeCopyAction::shouldUndo() {
 | 
|---|
 | 97 |   return true;
 | 
|---|
 | 98 | }
 | 
|---|
 | 99 | /** =========== end of function ====================== */
 | 
|---|