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