| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010-2011 University of Bonn. All rights reserved. | 
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | /* | 
|---|
| 9 | * ChangeNameAction.cpp | 
|---|
| 10 | * | 
|---|
| 11 | *  Created on: Jan 15, 2010 | 
|---|
| 12 | *      Author: crueger | 
|---|
| 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 "Atom/atom.hpp" | 
|---|
| 23 | #include "molecule.hpp" | 
|---|
| 24 |  | 
|---|
| 25 | #include <iostream> | 
|---|
| 26 | #include <string> | 
|---|
| 27 |  | 
|---|
| 28 | #include "Actions/MoleculeAction/ChangeNameAction.hpp" | 
|---|
| 29 |  | 
|---|
| 30 | using namespace MoleCuilder; | 
|---|
| 31 |  | 
|---|
| 32 | // and construct the stuff | 
|---|
| 33 | #include "ChangeNameAction.def" | 
|---|
| 34 | #include "Action_impl_pre.hpp" | 
|---|
| 35 | /** =========== define the function ====================== */ | 
|---|
| 36 | Action::state_ptr MoleculeChangeNameAction::performCall() { | 
|---|
| 37 | molecule *mol = NULL; | 
|---|
| 38 |  | 
|---|
| 39 | // obtain information | 
|---|
| 40 | getParametersfromValueStorage(); | 
|---|
| 41 |  | 
|---|
| 42 | if (World::getInstance().countSelectedMolecules() == 1) { | 
|---|
| 43 | mol = World::getInstance().beginMoleculeSelection()->second; | 
|---|
| 44 | string oldName = mol->getName(); | 
|---|
| 45 | mol->setName(params.name); | 
|---|
| 46 | return Action::state_ptr(new MoleculeChangeNameState(mol,params)); | 
|---|
| 47 | } else | 
|---|
| 48 | return Action::failure; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | Action::state_ptr MoleculeChangeNameAction::performUndo(Action::state_ptr _state) { | 
|---|
| 52 | MoleculeChangeNameState *state = assert_cast<MoleculeChangeNameState*>(_state.get()); | 
|---|
| 53 |  | 
|---|
| 54 | string newName = state->mol->getName(); | 
|---|
| 55 | state->mol->setName(state->params.name); | 
|---|
| 56 | state->params.name = newName; | 
|---|
| 57 |  | 
|---|
| 58 | return Action::state_ptr(_state); | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | Action::state_ptr MoleculeChangeNameAction::performRedo(Action::state_ptr _state){ | 
|---|
| 62 | // Undo and redo have to do the same for this action | 
|---|
| 63 | return performUndo(_state); | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | bool MoleculeChangeNameAction::canUndo() { | 
|---|
| 67 | return true; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | bool MoleculeChangeNameAction::shouldUndo() { | 
|---|
| 71 | return true; | 
|---|
| 72 | } | 
|---|
| 73 | /** =========== end of function ====================== */ | 
|---|