Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/AtomAction/AddAction.cpp

    rea2830 re5c0a1  
    1010#include "Actions/AtomAction/AddAction.hpp"
    1111#include "Actions/ActionRegistry.hpp"
    12 #include "Descriptors/AtomIdDescriptor.hpp"
    1312#include "atom.hpp"
    1413#include "element.hpp"
    15 #include "Helpers/Log.hpp"
     14#include "log.hpp"
    1615#include "molecule.hpp"
    17 #include "LinearAlgebra/Vector.hpp"
    18 #include "Helpers/Verbose.hpp"
     16#include "vector.hpp"
     17#include "verbose.hpp"
    1918#include "World.hpp"
    2019
     
    2625#include "UIElements/UIFactory.hpp"
    2726#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"
    4328
    4429const char AtomAddAction::NAME[] = "add-atom";
     
    7661  // execute action
    7762  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);
    8166  // TODO: remove when all of World's atoms are stored.
    8267  std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
     
    8570    (*iter)->AddAtom(first);
    8671  }
    87   return Action::state_ptr(new AtomAddState(position, elemental, first->getId()));
     72  return Action::success;
    8873}
    8974
    9075Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) {
    91   AtomAddState *state = assert_cast<AtomAddState*>(_state.get());
     76//  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
    9277
    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));
    9783}
    9884
    9985Action::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;
    11687}
    11788
    11889bool AtomAddAction::canUndo() {
    119   return true;
     90  return false;
    12091}
    12192
    12293bool AtomAddAction::shouldUndo() {
    123   return true;
     94  return false;
    12495}
    12596
Note: See TracChangeset for help on using the changeset viewer.