- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomAction/AddAction.cpp
rea2830 rbf3817 6 6 */ 7 7 8 // include config.h 9 #ifdef HAVE_CONFIG_H 10 #include <config.h> 11 #endif 12 8 13 #include "Helpers/MemDebug.hpp" 9 14 10 15 #include "Actions/AtomAction/AddAction.hpp" 11 16 #include "Actions/ActionRegistry.hpp" 12 #include "Descriptors/AtomIdDescriptor.hpp"13 17 #include "atom.hpp" 14 18 #include "element.hpp" … … 27 31 #include "UIElements/Dialog.hpp" 28 32 #include "Actions/ValueStorage.hpp" 29 30 // memento to remember the state when undoing31 32 class AtomAddState : public ActionState {33 public:34 AtomAddState(const Vector &_position, const element *_elemental, const atomId_t _id) :35 position(_position),36 elemental(_elemental),37 id(_id)38 {}39 Vector position;40 const element *elemental;41 atomId_t id;42 };43 33 44 34 const char AtomAddAction::NAME[] = "add-atom"; … … 85 75 (*iter)->AddAtom(first); 86 76 } 87 return Action::s tate_ptr(new AtomAddState(position, elemental, first->getId()));77 return Action::success; 88 78 } 89 79 90 80 Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) { 91 AtomAddState *state = assert_cast<AtomAddState*>(_state.get());81 // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get()); 92 82 93 DoLog(1) && (Log() << Verbose(1) << "Removing atom with id " << state->id << "." << endl); 94 World::getInstance().destroyAtom(state->id); 95 96 return Action::state_ptr(_state); 83 return Action::failure; 84 // string newName = state->mol->getName(); 85 // state->mol->setName(state->lastName); 86 // 87 // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); 97 88 } 98 89 99 90 Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){ 100 AtomAddState *state = assert_cast<AtomAddState*>(_state.get()); 101 102 atom * first = World::getInstance().createAtom(); 103 first->setType(state->elemental); 104 first->setPosition(state->position); 105 DoLog(1) && (Log() << Verbose(1) << "Re-adding new atom with element " << state->elemental->getName() << " at " << state->position << "." << endl); 106 // TODO: remove when all of World's atoms are stored. 107 std::vector<molecule *> molecules = World::getInstance().getAllMolecules(); 108 if (!molecules.empty()) { 109 std::vector<molecule *>::iterator iter = molecules.begin(); 110 (*iter)->AddAtom(first); 111 } 112 if (first->getId() != state->id) 113 if (!first->changeId(state->id)) 114 return Action::failure; 115 return Action::state_ptr(_state); 91 return Action::failure; 116 92 } 117 93 118 94 bool AtomAddAction::canUndo() { 119 return true;95 return false; 120 96 } 121 97 122 98 bool AtomAddAction::shouldUndo() { 123 return true;99 return false; 124 100 } 125 101
Note:
See TracChangeset
for help on using the changeset viewer.