source: src/Actions/SelectionAction/Atoms/NotAllAtomsInsideVolumeAction.cpp@ 97dff0

Last change on this file since 97dff0 was 26b4d62, checked in by Frederik Heber <heber@…>, 11 years ago

All Actions now give correct failure status via STATUS() macro.

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]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/>.
[bcf653]21 */
22
[1cc87e]23/*
[eff536]24 * NotAllAtomsInsideVolumeAction.cpp
[1cc87e]25 *
26 * Created on: Aug 9, 2010
27 * Author: heber
28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
[ad011c]35#include "CodePatterns/MemDebug.hpp"
[1cc87e]36
[92d756]37#include "Descriptors/AtomSelectionDescriptor.hpp"
[1cc87e]38#include "Descriptors/AtomShapeDescriptor.hpp"
[6f0841]39#include "Atom/atom.hpp"
[ad011c]40#include "CodePatterns/Log.hpp"
41#include "CodePatterns/Verbose.hpp"
[1cc87e]42#include "LinearAlgebra/Vector.hpp"
[060c7d]43#include "Shapes/ShapeRegistry.hpp"
[1cc87e]44#include "World.hpp"
45
[92d756]46#include <boost/foreach.hpp>
[1cc87e]47#include <iostream>
48#include <string>
49
[eff536]50#include "NotAllAtomsInsideVolumeAction.hpp"
[1cc87e]51
[ce7fdc]52using namespace MoleCuilder;
53
[1fd675]54// and construct the stuff
[eff536]55#include "NotAllAtomsInsideVolumeAction.def"
[1fd675]56#include "Action_impl_pre.hpp"
57/** =========== define the function ====================== */
[b5b01e]58ActionState::ptr SelectionNotAllAtomsInsideVolumeAction::performCall() {
[eff536]59 LOG(1, "Unselecting all atoms inside a volume.");
[060c7d]60 std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
61 if (selectedShapes.size() != 1){
[26b4d62]62 STATUS("There has to be exactly 1 selected shape.");
[060c7d]63 return Action::failure;
64 }
65 std::vector<atom *> unselectedAtoms = World::getInstance().getAllAtoms((!AtomsBySelection()) && AtomsByShape(*selectedShapes[0]));
66 World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0]));
[47d041]67 LOG(0, World::getInstance().countSelectedAtoms() << " atoms remain selected.");
[b5b01e]68 return ActionState::ptr(new SelectionNotAllAtomsInsideVolumeState(unselectedAtoms, params));
[1cc87e]69}
70
[b5b01e]71ActionState::ptr SelectionNotAllAtomsInsideVolumeAction::performUndo(ActionState::ptr _state) {
[eff536]72 SelectionNotAllAtomsInsideVolumeState *state = assert_cast<SelectionNotAllAtomsInsideVolumeState*>(_state.get());
[1cc87e]73
[060c7d]74 std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
75 World::getInstance().selectAllAtoms(AtomsByShape(*selectedShapes[0]));
[92d756]76 BOOST_FOREACH(atom *_atom, state->unselectedAtoms)
77 World::getInstance().unselectAtom(_atom);
[1cc87e]78
[b5b01e]79 return ActionState::ptr(_state);
[1cc87e]80}
81
[b5b01e]82ActionState::ptr SelectionNotAllAtomsInsideVolumeAction::performRedo(ActionState::ptr _state){
[eff536]83 //SelectionNotAllAtomsInsideVolumeState *state = assert_cast<SelectionNotAllAtomsInsideVolumeState*>(_state.get());
[1cc87e]84
[060c7d]85 std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
86 World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0]));
[1cc87e]87
[b5b01e]88 return ActionState::ptr(_state);
[1cc87e]89}
90
[eff536]91bool SelectionNotAllAtomsInsideVolumeAction::canUndo() {
[1cc87e]92 return true;
93}
94
[eff536]95bool SelectionNotAllAtomsInsideVolumeAction::shouldUndo() {
[1cc87e]96 return true;
97}
[1fd675]98/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.