Ignore:
File:
1 edited

Legend:

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

    rea2830 rbf3817  
    66 */
    77
     8// include config.h
     9#ifdef HAVE_CONFIG_H
     10#include <config.h>
     11#endif
     12
    813#include "Helpers/MemDebug.hpp"
    914
    1015#include "Actions/AtomAction/AddAction.hpp"
    1116#include "Actions/ActionRegistry.hpp"
    12 #include "Descriptors/AtomIdDescriptor.hpp"
    1317#include "atom.hpp"
    1418#include "element.hpp"
     
    2731#include "UIElements/Dialog.hpp"
    2832#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 };
    4333
    4434const char AtomAddAction::NAME[] = "add-atom";
     
    8575    (*iter)->AddAtom(first);
    8676  }
    87   return Action::state_ptr(new AtomAddState(position, elemental, first->getId()));
     77  return Action::success;
    8878}
    8979
    9080Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) {
    91   AtomAddState *state = assert_cast<AtomAddState*>(_state.get());
     81//  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
    9282
    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));
    9788}
    9889
    9990Action::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;
    11692}
    11793
    11894bool AtomAddAction::canUndo() {
    119   return true;
     95  return false;
    12096}
    12197
    12298bool AtomAddAction::shouldUndo() {
    123   return true;
     99  return false;
    124100}
    125101
Note: See TracChangeset for help on using the changeset viewer.