1 | /*
|
---|
2 | * ChangeElementAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/AtomAction/ChangeElementAction.hpp"
|
---|
11 | #include "atom.hpp"
|
---|
12 | #include "log.hpp"
|
---|
13 | #include "vector.hpp"
|
---|
14 | #include "verbose.hpp"
|
---|
15 | #include "World.hpp"
|
---|
16 |
|
---|
17 | #include <iostream>
|
---|
18 | #include <string>
|
---|
19 |
|
---|
20 | using namespace std;
|
---|
21 |
|
---|
22 | #include "UIElements/UIFactory.hpp"
|
---|
23 | #include "UIElements/Dialog.hpp"
|
---|
24 | #include "UIElements/ValueStorage.hpp"
|
---|
25 |
|
---|
26 | const char AtomChangeElementAction::NAME[] = "change-element";
|
---|
27 |
|
---|
28 | AtomChangeElementAction::AtomChangeElementAction() :
|
---|
29 | Action(NAME)
|
---|
30 | {}
|
---|
31 |
|
---|
32 | AtomChangeElementAction::~AtomChangeElementAction()
|
---|
33 | {}
|
---|
34 |
|
---|
35 | Dialog* AtomChangeElementAction::createDialog() {
|
---|
36 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
37 |
|
---|
38 | dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
39 |
|
---|
40 | return dialog;
|
---|
41 | }
|
---|
42 |
|
---|
43 | Action::state_ptr AtomChangeElementAction::performCall() {
|
---|
44 | atom *first = NULL;
|
---|
45 | std::vector<element *> elements;
|
---|
46 |
|
---|
47 | ValueStorage::getInstance().queryCurrentValue(NAME, elements);
|
---|
48 |
|
---|
49 | ASSERT(elements.size() == 1, "Unequal to one element specified when changing an atom's element");
|
---|
50 | if (elements.at(0) == NULL) {
|
---|
51 | return Action::failure;
|
---|
52 | }
|
---|
53 | for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) {
|
---|
54 | first = iter->second;
|
---|
55 | DoLog(1) && (Log() << Verbose(1) << "Changing atom " << *first << " to element " << elements.at(0) << "." << endl);
|
---|
56 | first->type = elements.at(0);
|
---|
57 | }
|
---|
58 | return Action::success;
|
---|
59 | }
|
---|
60 |
|
---|
61 | Action::state_ptr AtomChangeElementAction::performUndo(Action::state_ptr _state) {
|
---|
62 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
63 |
|
---|
64 | return Action::failure;
|
---|
65 | // string newName = state->mol->getName();
|
---|
66 | // state->mol->setName(state->lastName);
|
---|
67 | //
|
---|
68 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
69 | }
|
---|
70 |
|
---|
71 | Action::state_ptr AtomChangeElementAction::performRedo(Action::state_ptr _state){
|
---|
72 | return Action::failure;
|
---|
73 | }
|
---|
74 |
|
---|
75 | bool AtomChangeElementAction::canUndo() {
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | bool AtomChangeElementAction::shouldUndo() {
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 |
|
---|
83 | const string AtomChangeElementAction::getName() {
|
---|
84 | return NAME;
|
---|
85 | }
|
---|