[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 |
|
---|
[51769f] | 23 | /*
|
---|
| 24 | * NotMoleculeByFormulaAction.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: May 12, 2010
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
[ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
|
---|
[51769f] | 36 |
|
---|
| 37 | #include "Descriptors/MoleculeFormulaDescriptor.hpp"
|
---|
[ff237c] | 38 | #include "Descriptors/MoleculeSelectionDescriptor.hpp"
|
---|
[51769f] | 39 | #include "molecule.hpp"
|
---|
[ad011c] | 40 | #include "CodePatterns/Log.hpp"
|
---|
| 41 | #include "CodePatterns/Verbose.hpp"
|
---|
[51769f] | 42 | #include "World.hpp"
|
---|
| 43 |
|
---|
[92d756] | 44 | #include <boost/foreach.hpp>
|
---|
[51769f] | 45 | #include <iostream>
|
---|
| 46 | #include <string>
|
---|
| 47 |
|
---|
[125002] | 48 | #include "NotMoleculeByFormulaAction.hpp"
|
---|
[51769f] | 49 |
|
---|
[ce7fdc] | 50 | using namespace MoleCuilder;
|
---|
| 51 |
|
---|
[1fd675] | 52 | // and construct the stuff
|
---|
| 53 | #include "NotMoleculeByFormulaAction.def"
|
---|
| 54 | #include "Action_impl_pre.hpp"
|
---|
| 55 | /** =========== define the function ====================== */
|
---|
[b5b01e] | 56 | ActionState::ptr SelectionNotMoleculeByFormulaAction::performCall() {
|
---|
[f10b0c] | 57 | LOG(1, "Unselecting molecules with chemical formula " << params.formula.get() << ":");
|
---|
[1259df] | 58 | std::vector<const molecule *> matchingMolecules =
|
---|
| 59 | const_cast<const World &>(World::getInstance()).
|
---|
| 60 | getAllMolecules(MoleculeByFormula(params.formula.get()));
|
---|
| 61 | std::vector<const molecule *> unselectedMolecules =
|
---|
| 62 | const_cast<const World &>(World::getInstance()).
|
---|
| 63 | getAllMolecules(!MoleculesBySelection());
|
---|
[f10b0c] | 64 | World::getInstance().unselectAllMolecules(MoleculeByFormula(params.formula.get()));
|
---|
[47d041] | 65 | LOG(0, World::getInstance().countSelectedMolecules() << " molecules remain selected.");
|
---|
[b5b01e] | 66 | return ActionState::ptr(new SelectionNotMoleculeByFormulaState(unselectedMolecules,params));
|
---|
[51769f] | 67 | }
|
---|
| 68 |
|
---|
[b5b01e] | 69 | ActionState::ptr SelectionNotMoleculeByFormulaAction::performUndo(ActionState::ptr _state) {
|
---|
[51769f] | 70 | SelectionNotMoleculeByFormulaState *state = assert_cast<SelectionNotMoleculeByFormulaState*>(_state.get());
|
---|
| 71 |
|
---|
[f10b0c] | 72 | World::getInstance().selectAllMolecules(MoleculeByFormula(state->params.formula.get()));
|
---|
[1259df] | 73 | BOOST_FOREACH( const molecule *mol, state->unselectedMolecules)
|
---|
[92d756] | 74 | World::getInstance().unselectMolecule(mol);
|
---|
[51769f] | 75 |
|
---|
[b5b01e] | 76 | return ActionState::ptr(_state);
|
---|
[51769f] | 77 | }
|
---|
| 78 |
|
---|
[b5b01e] | 79 | ActionState::ptr SelectionNotMoleculeByFormulaAction::performRedo(ActionState::ptr _state){
|
---|
[51769f] | 80 | SelectionNotMoleculeByFormulaState *state = assert_cast<SelectionNotMoleculeByFormulaState*>(_state.get());
|
---|
| 81 |
|
---|
[f10b0c] | 82 | World::getInstance().unselectAllMolecules(MoleculeByFormula(state->params.formula.get()));
|
---|
[51769f] | 83 |
|
---|
[b5b01e] | 84 | return ActionState::ptr(_state);
|
---|
[51769f] | 85 | }
|
---|
| 86 |
|
---|
| 87 | bool SelectionNotMoleculeByFormulaAction::canUndo() {
|
---|
| 88 | return true;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | bool SelectionNotMoleculeByFormulaAction::shouldUndo() {
|
---|
| 92 | return true;
|
---|
| 93 | }
|
---|
[1fd675] | 94 | /** =========== end of function ====================== */
|
---|