[1a7fd2] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[1a7fd2] | 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"
|
---|
[6f0841] | 25 | #include "Atom/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 | #include "Actions/MoleculeAction/CopyAction.hpp"
|
---|
| 35 |
|
---|
[ce7fdc] | 36 | using namespace MoleCuilder;
|
---|
| 37 |
|
---|
[1a7fd2] | 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 |
|
---|
[f10b0c] | 45 | copy = params.mol.get()->CopyMolecule();
|
---|
| 46 | Vector *Center = params.mol.get()->DetermineCenterOfAll();
|
---|
[1a7fd2] | 47 | *Center *= -1.;
|
---|
[f10b0c] | 48 | *Center += params.position.get();
|
---|
[1a7fd2] | 49 | copy->Translate(Center);
|
---|
| 50 | delete(Center);
|
---|
| 51 |
|
---|
| 52 | return Action::state_ptr(new MoleculeCopyState(copy,params));
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | Action::state_ptr MoleculeCopyAction::performUndo(Action::state_ptr _state) {
|
---|
| 56 | MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
|
---|
| 57 |
|
---|
[34fbb3] | 58 | state->copy->removeAtomsinMolecule();
|
---|
[1a7fd2] | 59 | World::getInstance().destroyMolecule(state->copy);
|
---|
| 60 |
|
---|
| 61 | return Action::state_ptr(_state);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | Action::state_ptr MoleculeCopyAction::performRedo(Action::state_ptr _state){
|
---|
| 65 | MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
|
---|
| 66 |
|
---|
[f10b0c] | 67 | molecule *copy = state->params.mol.get()->CopyMolecule();
|
---|
| 68 | Vector *Center = state->params.mol.get()->DetermineCenterOfAll();
|
---|
[1a7fd2] | 69 | *Center *= -1.;
|
---|
[f10b0c] | 70 | *Center += state->params.position.get();
|
---|
[1a7fd2] | 71 | copy->Translate(Center);
|
---|
| 72 | delete(Center);
|
---|
| 73 |
|
---|
| 74 | return Action::state_ptr(new MoleculeCopyState(copy,state->params));
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | bool MoleculeCopyAction::canUndo() {
|
---|
| 78 | return true;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | bool MoleculeCopyAction::shouldUndo() {
|
---|
| 82 | return true;
|
---|
| 83 | }
|
---|
| 84 | /** =========== end of function ====================== */
|
---|