[97ebf8] | 1 | /*
|
---|
| 2 | * ChangeElementAction.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/ChangeElementAction.hpp"
|
---|
[0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
|
---|
[97ebf8] | 17 | #include "atom.hpp"
|
---|
[023971] | 18 | #include "element.hpp"
|
---|
[952f38] | 19 | #include "Helpers/Log.hpp"
|
---|
[57f243] | 20 | #include "LinearAlgebra/Vector.hpp"
|
---|
[952f38] | 21 | #include "Helpers/Verbose.hpp"
|
---|
[dddbfe] | 22 | #include "molecule.hpp"
|
---|
[97ebf8] | 23 | #include "World.hpp"
|
---|
| 24 |
|
---|
| 25 | #include <iostream>
|
---|
| 26 | #include <string>
|
---|
| 27 |
|
---|
| 28 | using namespace std;
|
---|
| 29 |
|
---|
| 30 | #include "UIElements/UIFactory.hpp"
|
---|
| 31 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 32 | #include "Actions/ValueStorage.hpp"
|
---|
[97ebf8] | 33 |
|
---|
| 34 | const char AtomChangeElementAction::NAME[] = "change-element";
|
---|
| 35 |
|
---|
| 36 | AtomChangeElementAction::AtomChangeElementAction() :
|
---|
| 37 | Action(NAME)
|
---|
| 38 | {}
|
---|
| 39 |
|
---|
| 40 | AtomChangeElementAction::~AtomChangeElementAction()
|
---|
| 41 | {}
|
---|
| 42 |
|
---|
[1a8fbf6] | 43 | void AtomChangeElement(element *elemental) {
|
---|
| 44 | ValueStorage::getInstance().setCurrentValue(AtomChangeElementAction::NAME, elemental);
|
---|
| 45 | ActionRegistry::getInstance().getActionByName(AtomChangeElementAction::NAME)->call(Action::NonInteractive);
|
---|
| 46 | };
|
---|
| 47 |
|
---|
[047878] | 48 | Dialog* AtomChangeElementAction::fillDialog(Dialog *dialog) {
|
---|
| 49 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[454065] | 50 |
|
---|
| 51 | dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 52 |
|
---|
| 53 | return dialog;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | Action::state_ptr AtomChangeElementAction::performCall() {
|
---|
[97ebf8] | 57 | atom *first = NULL;
|
---|
[b5c53d] | 58 | const element *elemental;
|
---|
[dddbfe] | 59 | molecule *mol = NULL;
|
---|
[97ebf8] | 60 |
|
---|
[8d4100] | 61 | ValueStorage::getInstance().queryCurrentValue(NAME, elemental);
|
---|
[97ebf8] | 62 |
|
---|
[454065] | 63 | for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) {
|
---|
| 64 | first = iter->second;
|
---|
[2fe971] | 65 | DoLog(1) && (Log() << Verbose(1) << "Changing atom " << *first << " to element " << *elemental << "." << endl);
|
---|
[dddbfe] | 66 | mol = first->getMolecule();
|
---|
| 67 | first->removeFromMolecule(); // remove atom
|
---|
[d74077] | 68 | first->setType(elemental);
|
---|
[dddbfe] | 69 | mol->AddAtom(first); // add atom to ensure correctness of formula
|
---|
[454065] | 70 | }
|
---|
| 71 | return Action::success;
|
---|
[97ebf8] | 72 | }
|
---|
| 73 |
|
---|
| 74 | Action::state_ptr AtomChangeElementAction::performUndo(Action::state_ptr _state) {
|
---|
| 75 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 76 |
|
---|
| 77 | return Action::failure;
|
---|
| 78 | // string newName = state->mol->getName();
|
---|
| 79 | // state->mol->setName(state->lastName);
|
---|
| 80 | //
|
---|
| 81 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | Action::state_ptr AtomChangeElementAction::performRedo(Action::state_ptr _state){
|
---|
| 85 | return Action::failure;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | bool AtomChangeElementAction::canUndo() {
|
---|
| 89 | return false;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | bool AtomChangeElementAction::shouldUndo() {
|
---|
| 93 | return false;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | const string AtomChangeElementAction::getName() {
|
---|
| 97 | return NAME;
|
---|
| 98 | }
|
---|