[97ebf8] | 1 | /*
|
---|
| 2 | * RemoveAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/AtomAction/RemoveAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[97ebf8] | 12 | #include "atom.hpp"
|
---|
| 13 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
| 14 | #include "log.hpp"
|
---|
[d55743e] | 15 | #include "molecule.hpp"
|
---|
[97ebf8] | 16 | #include "verbose.hpp"
|
---|
| 17 | #include "World.hpp"
|
---|
| 18 |
|
---|
| 19 | #include <iostream>
|
---|
| 20 | #include <string>
|
---|
| 21 |
|
---|
| 22 | using namespace std;
|
---|
| 23 |
|
---|
| 24 | #include "UIElements/UIFactory.hpp"
|
---|
| 25 | #include "UIElements/Dialog.hpp"
|
---|
[5cb3cb] | 26 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 27 |
|
---|
| 28 | const char AtomRemoveAction::NAME[] = "remove-atom";
|
---|
| 29 |
|
---|
| 30 | AtomRemoveAction::AtomRemoveAction() :
|
---|
| 31 | Action(NAME)
|
---|
| 32 | {}
|
---|
| 33 |
|
---|
| 34 | AtomRemoveAction::~AtomRemoveAction()
|
---|
| 35 | {}
|
---|
| 36 |
|
---|
[1a8fbf6] | 37 | void AtomRemove() {
|
---|
| 38 | ActionRegistry::getInstance().getActionByName(AtomRemoveAction::NAME)->call(Action::NonInteractive);
|
---|
| 39 | };
|
---|
| 40 |
|
---|
[5cb3cb] | 41 | Dialog* AtomRemoveAction::createDialog() {
|
---|
[97ebf8] | 42 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 43 |
|
---|
[5cb3cb] | 44 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 45 |
|
---|
| 46 | return dialog;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | Action::state_ptr AtomRemoveAction::performCall() {
|
---|
| 50 | atom *first = NULL;
|
---|
[97ebf8] | 51 |
|
---|
[5cb3cb] | 52 | std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
|
---|
| 53 | for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) {
|
---|
| 54 | first = iter->second;
|
---|
[97ebf8] | 55 | DoLog(1) && (Log() << Verbose(1) << "Removing atom " << first->getId() << "." << endl);
|
---|
[d55743e] | 56 | // TODO: this is not necessary when atoms and their storing to file are handled by the World
|
---|
| 57 | // simply try to erase in every molecule found
|
---|
| 58 | for (std::vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end(); ++iter) {
|
---|
| 59 | (*iter)->erase(first);
|
---|
| 60 | }
|
---|
[97ebf8] | 61 | World::getInstance().destroyAtom(first);
|
---|
| 62 | }
|
---|
[5cb3cb] | 63 | return Action::success;
|
---|
[97ebf8] | 64 | }
|
---|
| 65 |
|
---|
| 66 | Action::state_ptr AtomRemoveAction::performUndo(Action::state_ptr _state) {
|
---|
| 67 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 68 |
|
---|
| 69 | return Action::failure;
|
---|
| 70 | // string newName = state->mol->getName();
|
---|
| 71 | // state->mol->setName(state->lastName);
|
---|
| 72 | //
|
---|
| 73 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr AtomRemoveAction::performRedo(Action::state_ptr _state){
|
---|
| 77 | return Action::failure;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool AtomRemoveAction::canUndo() {
|
---|
| 81 | return false;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | bool AtomRemoveAction::shouldUndo() {
|
---|
| 85 | return false;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | const string AtomRemoveAction::getName() {
|
---|
| 89 | return NAME;
|
---|
| 90 | }
|
---|