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