[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 | #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 |
|
---|
| 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 |
|
---|
[34fbb3] | 61 | state->copy->removeAtomsinMolecule();
|
---|
[1a7fd2] | 62 | World::getInstance().destroyMolecule(state->copy);
|
---|
| 63 |
|
---|
| 64 | return Action::state_ptr(_state);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | Action::state_ptr MoleculeCopyAction::performRedo(Action::state_ptr _state){
|
---|
| 68 | MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
|
---|
| 69 |
|
---|
| 70 | molecule *copy = state->params.mol->CopyMolecule();
|
---|
| 71 | Vector *Center = state->params.mol->DetermineCenterOfAll();
|
---|
| 72 | *Center *= -1.;
|
---|
| 73 | *Center += state->params.position;
|
---|
| 74 | copy->Translate(Center);
|
---|
| 75 | delete(Center);
|
---|
| 76 |
|
---|
| 77 | return Action::state_ptr(new MoleculeCopyState(copy,state->params));
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool MoleculeCopyAction::canUndo() {
|
---|
| 81 | return true;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | bool MoleculeCopyAction::shouldUndo() {
|
---|
| 85 | return true;
|
---|
| 86 | }
|
---|
| 87 | /** =========== end of function ====================== */
|
---|