1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 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 "Actions/UndoRedoHelpers.hpp"
|
---|
23 | #include "CodePatterns/Log.hpp"
|
---|
24 | #include "CodePatterns/Verbose.hpp"
|
---|
25 | #include "LinearAlgebra/Vector.hpp"
|
---|
26 | #include "Atom/atom.hpp"
|
---|
27 | #include "Bond/bond.hpp"
|
---|
28 | #include "molecule.hpp"
|
---|
29 | #include "World.hpp"
|
---|
30 |
|
---|
31 | #include <iostream>
|
---|
32 | #include <fstream>
|
---|
33 | #include <string>
|
---|
34 | #include <vector>
|
---|
35 |
|
---|
36 | #include "Actions/MoleculeAction/CopyAction.hpp"
|
---|
37 |
|
---|
38 | using namespace MoleCuilder;
|
---|
39 |
|
---|
40 | // and construct the stuff
|
---|
41 | #include "CopyAction.def"
|
---|
42 | #include "Action_impl_pre.hpp"
|
---|
43 | /** =========== define the function ====================== */
|
---|
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));
|
---|
59 | }
|
---|
60 |
|
---|
61 | Action::state_ptr MoleculeCopyAction::performUndo(Action::state_ptr _state) {
|
---|
62 | MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
|
---|
63 |
|
---|
64 | RemoveMoleculesWithAtomsByIds(state->copies);
|
---|
65 |
|
---|
66 | return Action::state_ptr(_state);
|
---|
67 | }
|
---|
68 |
|
---|
69 | Action::state_ptr MoleculeCopyAction::performRedo(Action::state_ptr _state){
|
---|
70 | return performCall();
|
---|
71 | }
|
---|
72 |
|
---|
73 | bool MoleculeCopyAction::canUndo() {
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | bool MoleculeCopyAction::shouldUndo() {
|
---|
78 | return true;
|
---|
79 | }
|
---|
80 | /** =========== end of function ====================== */
|
---|