source: src/Actions/MoleculeAction/StretchBondAction.cpp@ 9f55b9

Candidate_v1.7.0 stable
Last change on this file since 9f55b9 was 9f55b9, checked in by Frederik Heber <frederik.heber@…>, 5 years ago

Extracted functor StretchBondUtil from StretchBondAction.

  • Property mode set to 100644
File size: 3.6 KB
RevLine 
[3a51bd]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * StretchBondAction.cpp
25 *
26 * Created on: Sep 26, 2012
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
[9eb71b3]35//#include "CodePatterns/MemDebug.hpp"
[3a51bd]36
37#include "Actions/MoleculeAction/StretchBondAction.hpp"
38
[d24ef58]39#include <boost/bind.hpp>
40
[3a51bd]41#include "CodePatterns/Log.hpp"
42#include "CodePatterns/Verbose.hpp"
43
44#include "LinearAlgebra/Plane.hpp"
45
46#include "Atom/atom.hpp"
47#include "Bond/bond.hpp"
[9f55b9]48#include "Bond/StretchBond.hpp"
[bccbe9]49#include "Graph/BoostGraphHelpers.hpp"
[3a51bd]50#include "World.hpp"
51
52using namespace MoleCuilder;
53
54// and construct the stuff
55#include "StretchBondAction.def"
56#include "Action_impl_pre.hpp"
[3b74fa]57
58
[3a51bd]59/** =========== define the function ====================== */
[b5b01e]60ActionState::ptr MoleculeStretchBondAction::performCall()
[3a51bd]61{
62 const std::vector< atom *> atoms = World::getInstance().getSelectedAtoms();
[9f55b9]63 StretchBondUtil stretcher(atoms);
64 bool status = stretcher(params.bonddistance.get());
65
66 if (status) {
67 MoleculeStretchBondState *UndoState =
68 new MoleculeStretchBondState(
69 stretcher.getShift(),
70 stretcher.getBondSides(),
71 &stretcher.getMolecule(),
72 params);
73 return ActionState::ptr(UndoState);
74 } else {
75 STATUS("Failed, exactly two atoms must be selected.");
[3a51bd]76 return Action::failure;
77 }
78}
79
[b5b01e]80ActionState::ptr MoleculeStretchBondAction::performUndo(ActionState::ptr _state) {
[3a51bd]81 MoleculeStretchBondState *state = assert_cast<MoleculeStretchBondState*>(_state.get());
82
83 // use given plane to undo
84 Box &domain = World::getInstance().getDomain();
[3b74fa]85 for (size_t i=0;i<2;++i) {
[bccbe9]86 for (BoostGraphHelpers::Nodeset_t::const_iterator iter = state->bondside_sets[i].begin();
[3b74fa]87 iter != state->bondside_sets[i].end(); ++iter) {
88 atom &walker = *World::getInstance().getAtom(AtomById(*iter));
89 const Vector &position = walker.getPosition();
90 walker.setPosition( domain.enforceBoundaryConditions(position-state->Shift[i]) );
[3a51bd]91 }
92 }
93
[b5b01e]94 return ActionState::ptr(_state);
[3a51bd]95}
96
[b5b01e]97ActionState::ptr MoleculeStretchBondAction::performRedo(ActionState::ptr _state){
[3a51bd]98 MoleculeStretchBondState *state = assert_cast<MoleculeStretchBondState*>(_state.get());
99
100 Box &domain = World::getInstance().getDomain();
[3b74fa]101 for (size_t i=0;i<2;++i) {
[bccbe9]102 for (BoostGraphHelpers::Nodeset_t::const_iterator iter = state->bondside_sets[i].begin();
[3b74fa]103 iter != state->bondside_sets[i].end(); ++iter) {
104 atom &walker = *World::getInstance().getAtom(AtomById(*iter));
105 const Vector &position = walker.getPosition();
106 walker.setPosition( domain.enforceBoundaryConditions(position+state->Shift[i]) );
[3a51bd]107 }
108 }
[3b74fa]109
[b5b01e]110 return ActionState::ptr(_state);
[3a51bd]111}
112
113bool MoleculeStretchBondAction::canUndo() {
114 return true;
115}
116
117bool MoleculeStretchBondAction::shouldUndo() {
118 return true;
119}
120/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.