[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 |
|
---|
[8ea3e7] | 22 | #include "Actions/UndoRedoHelpers.hpp"
|
---|
[ad011c] | 23 | #include "CodePatterns/Log.hpp"
|
---|
| 24 | #include "CodePatterns/Verbose.hpp"
|
---|
[1a7fd2] | 25 | #include "LinearAlgebra/Vector.hpp"
|
---|
[6f0841] | 26 | #include "Atom/atom.hpp"
|
---|
[129204] | 27 | #include "Bond/bond.hpp"
|
---|
[1a7fd2] | 28 | #include "molecule.hpp"
|
---|
| 29 | #include "World.hpp"
|
---|
| 30 |
|
---|
| 31 | #include <iostream>
|
---|
| 32 | #include <fstream>
|
---|
| 33 | #include <string>
|
---|
[8ea3e7] | 34 | #include <vector>
|
---|
[1a7fd2] | 35 |
|
---|
| 36 | #include "Actions/MoleculeAction/CopyAction.hpp"
|
---|
| 37 |
|
---|
[ce7fdc] | 38 | using namespace MoleCuilder;
|
---|
| 39 |
|
---|
[1a7fd2] | 40 | // and construct the stuff
|
---|
| 41 | #include "CopyAction.def"
|
---|
| 42 | #include "Action_impl_pre.hpp"
|
---|
| 43 | /** =========== define the function ====================== */
|
---|
[8ea3e7] | 44 | Action::state_ptr MoleculeCopyAction::performCall()
|
---|
| 45 | {
|
---|
| 46 | std::vector<moleculeId_t> molecules;
|
---|
| 47 | for (World::MoleculeSelectionConstIterator iter = World::getInstance().beginMoleculeSelection();
|
---|
| 48 | iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 49 | molecule * const copy = (iter->second)->CopyMolecule();
|
---|
| 50 | Vector *Center = (iter->second)->DetermineCenterOfAll();
|
---|
| 51 | *Center *= -1.;
|
---|
| 52 | *Center += params.position.get();
|
---|
| 53 | copy->Translate(Center);
|
---|
| 54 | delete(Center);
|
---|
| 55 | molecules.push_back(copy->getId());
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | return Action::state_ptr(new MoleculeCopyState(molecules,params));
|
---|
[1a7fd2] | 59 | }
|
---|
| 60 |
|
---|
| 61 | Action::state_ptr MoleculeCopyAction::performUndo(Action::state_ptr _state) {
|
---|
| 62 | MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
|
---|
| 63 |
|
---|
[8ea3e7] | 64 | RemoveMoleculesWithAtomsByIds(state->copies);
|
---|
[1a7fd2] | 65 |
|
---|
| 66 | return Action::state_ptr(_state);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | Action::state_ptr MoleculeCopyAction::performRedo(Action::state_ptr _state){
|
---|
[8ea3e7] | 70 | return performCall();
|
---|
[1a7fd2] | 71 | }
|
---|
| 72 |
|
---|
| 73 | bool MoleculeCopyAction::canUndo() {
|
---|
| 74 | return true;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | bool MoleculeCopyAction::shouldUndo() {
|
---|
| 78 | return true;
|
---|
| 79 | }
|
---|
| 80 | /** =========== end of function ====================== */
|
---|