- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomAction/AddAction.cpp
rbf3817 rea2830 6 6 */ 7 7 8 // include config.h9 #ifdef HAVE_CONFIG_H10 #include <config.h>11 #endif12 13 8 #include "Helpers/MemDebug.hpp" 14 9 15 10 #include "Actions/AtomAction/AddAction.hpp" 16 11 #include "Actions/ActionRegistry.hpp" 12 #include "Descriptors/AtomIdDescriptor.hpp" 17 13 #include "atom.hpp" 18 14 #include "element.hpp" … … 31 27 #include "UIElements/Dialog.hpp" 32 28 #include "Actions/ValueStorage.hpp" 29 30 // memento to remember the state when undoing 31 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 }; 33 43 34 44 const char AtomAddAction::NAME[] = "add-atom"; … … 75 85 (*iter)->AddAtom(first); 76 86 } 77 return Action::s uccess;87 return Action::state_ptr(new AtomAddState(position, elemental, first->getId())); 78 88 } 79 89 80 90 Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) { 81 // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());91 AtomAddState *state = assert_cast<AtomAddState*>(_state.get()); 82 92 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)); 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); 88 97 } 89 98 90 99 Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){ 91 return Action::failure; 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); 92 116 } 93 117 94 118 bool AtomAddAction::canUndo() { 95 return false;119 return true; 96 120 } 97 121 98 122 bool AtomAddAction::shouldUndo() { 99 return false;123 return true; 100 124 } 101 125
Note:
See TracChangeset
for help on using the changeset viewer.