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