source: src/Actions/SelectionAction/Atoms/AtomBondNeighborsAction.cpp@ 4de4f6

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

Added AtomBondNeighbors selection action.

  • DOCU: Added to userguide.
  • TEST: Added regression test case.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2020 Frederik Heber. 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 * AtomBondNeighborsAction.cpp
25 *
26 * Created on: Oct 04, 2020
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35//#include "CodePatterns/MemDebug.hpp"
36
37#include "CodePatterns/Log.hpp"
38#include "CodePatterns/Verbose.hpp"
39
40#include "Atom/atom.hpp"
41#include "Bond/bond.hpp"
42#include "Descriptors/AtomIdDescriptor.hpp"
43#include "World.hpp"
44
45#include "AtomBondNeighborsAction.hpp"
46
47using namespace MoleCuilder;
48
49// and construct the stuff
50#include "AtomBondNeighborsAction.def"
51#include "Action_impl_pre.hpp"
52/** =========== define the function ====================== */
53ActionState::ptr SelectionAtomBondNeighborsAction::performCall()
54{
55 const World &world = World::getConstInstance();
56 const std::vector<const atom *> atoms = world.getSelectedAtoms();
57
58 std::vector<atomId_t> undoatomids;
59 undoatomids.reserve(atoms.size()*6);
60 for(std::vector<const atom *>::const_iterator iter = atoms.begin();
61 iter != atoms.end(); ++iter) {
62 // look at all bond neighbors and select those
63 const atom &Walker = **iter;
64 const BondList& ListOfBonds = Walker.getListOfBonds();
65 for (BondList::const_iterator bonditer = ListOfBonds.begin();
66 bonditer != ListOfBonds.end(); ++bonditer) {
67 const atom &OtherWalker = *(*bonditer)->GetOtherAtom(&Walker);
68 if (!world.isSelected(&OtherWalker)) {
69 undoatomids.push_back(OtherWalker.getId());
70 World::getInstance().selectAtom(&OtherWalker);
71 }
72 }
73 }
74 LOG(0, World::getInstance().countSelectedAtoms()-atoms.size() << " atoms newly selected.");
75
76 return ActionState::ptr(new SelectionAtomBondNeighborsState(undoatomids, params));
77}
78
79ActionState::ptr SelectionAtomBondNeighborsAction::performUndo(ActionState::ptr _state) {
80 SelectionAtomBondNeighborsState *state = assert_cast<SelectionAtomBondNeighborsState*>(_state.get());
81
82 for (atomids_t::const_iterator iter = state->undoatomids.begin();
83 iter != state->undoatomids.end(); ++iter)
84 World::getInstance().unselectAllAtoms(AtomById(*iter));
85
86 return ActionState::ptr(_state);
87}
88
89ActionState::ptr SelectionAtomBondNeighborsAction::performRedo(ActionState::ptr _state){
90 SelectionAtomBondNeighborsState *state = assert_cast<SelectionAtomBondNeighborsState*>(_state.get());
91
92 for (atomids_t::const_iterator iter = state->undoatomids.begin();
93 iter != state->undoatomids.end(); ++iter)
94 World::getInstance().selectAllAtoms(AtomById(*iter));
95
96 return ActionState::ptr(_state);
97}
98
99bool SelectionAtomBondNeighborsAction::canUndo() {
100 return true;
101}
102
103bool SelectionAtomBondNeighborsAction::shouldUndo() {
104 return true;
105}
106/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.