- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomAction/AddAction.cpp
re5c0a1 rea2830 10 10 #include "Actions/AtomAction/AddAction.hpp" 11 11 #include "Actions/ActionRegistry.hpp" 12 #include "Descriptors/AtomIdDescriptor.hpp" 12 13 #include "atom.hpp" 13 14 #include "element.hpp" 14 #include " log.hpp"15 #include "Helpers/Log.hpp" 15 16 #include "molecule.hpp" 16 #include " vector.hpp"17 #include " verbose.hpp"17 #include "LinearAlgebra/Vector.hpp" 18 #include "Helpers/Verbose.hpp" 18 19 #include "World.hpp" 19 20 … … 25 26 #include "UIElements/UIFactory.hpp" 26 27 #include "UIElements/Dialog.hpp" 27 #include "UIElements/ValueStorage.hpp" 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 }; 28 43 29 44 const char AtomAddAction::NAME[] = "add-atom"; … … 61 76 // execute action 62 77 atom * first = World::getInstance().createAtom(); 63 first-> type = elemental;64 first-> x = position;65 DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << *first->type << " at " << (first->x) << "." << endl);78 first->setType(elemental); 79 first->setPosition(position); 80 DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << first->getType()->getName() << " at " << (first->getPosition()) << "." << endl); 66 81 // TODO: remove when all of World's atoms are stored. 67 82 std::vector<molecule *> molecules = World::getInstance().getAllMolecules(); … … 70 85 (*iter)->AddAtom(first); 71 86 } 72 return Action::s uccess;87 return Action::state_ptr(new AtomAddState(position, elemental, first->getId())); 73 88 } 74 89 75 90 Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) { 76 // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());91 AtomAddState *state = assert_cast<AtomAddState*>(_state.get()); 77 92 78 return Action::failure; 79 // string newName = state->mol->getName(); 80 // state->mol->setName(state->lastName); 81 // 82 // 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); 83 97 } 84 98 85 99 Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){ 86 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); 87 116 } 88 117 89 118 bool AtomAddAction::canUndo() { 90 return false;119 return true; 91 120 } 92 121 93 122 bool AtomAddAction::shouldUndo() { 94 return false;123 return true; 95 124 } 96 125
Note:
See TracChangeset
for help on using the changeset viewer.