1 | /*
|
---|
2 | * AddAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/AtomAction/AddAction.hpp"
|
---|
11 | #include "atom.hpp"
|
---|
12 | #include "element.hpp"
|
---|
13 | #include "log.hpp"
|
---|
14 | #include "molecule.hpp"
|
---|
15 | #include "vector.hpp"
|
---|
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"
|
---|
26 | #include "UIElements/ValueStorage.hpp"
|
---|
27 |
|
---|
28 | const char AtomAddAction::NAME[] = "add-atom";
|
---|
29 |
|
---|
30 | AtomAddAction::AtomAddAction() :
|
---|
31 | Action(NAME)
|
---|
32 | {}
|
---|
33 |
|
---|
34 | AtomAddAction::~AtomAddAction()
|
---|
35 | {}
|
---|
36 |
|
---|
37 | Dialog * AtomAddAction::createDialog() {
|
---|
38 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
39 |
|
---|
40 | dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
41 | dialog->queryVector("position", true, ValueStorage::getInstance().getDescription("position"));
|
---|
42 |
|
---|
43 | return dialog;
|
---|
44 | }
|
---|
45 |
|
---|
46 | Action::state_ptr AtomAddAction::performCall() {
|
---|
47 | element * elemental = NULL;
|
---|
48 | Vector position;
|
---|
49 |
|
---|
50 | // obtain information
|
---|
51 | ValueStorage::getInstance().queryCurrentValue(NAME, elemental);
|
---|
52 | ValueStorage::getInstance().queryCurrentValue("position", position);
|
---|
53 |
|
---|
54 | // execute action
|
---|
55 | atom * first = World::getInstance().createAtom();
|
---|
56 | first->type = elemental;
|
---|
57 | first->x = position;
|
---|
58 | DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << first->type->name << " at " << (first->x) << "." << endl);
|
---|
59 | // TODO: remove when all of World's atoms are stored.
|
---|
60 | std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
|
---|
61 | if (!molecules.empty()) {
|
---|
62 | std::vector<molecule *>::iterator iter = molecules.begin();
|
---|
63 | (*iter)->AddAtom(first);
|
---|
64 | }
|
---|
65 | return Action::success;
|
---|
66 | }
|
---|
67 |
|
---|
68 | Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) {
|
---|
69 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
70 |
|
---|
71 | return Action::failure;
|
---|
72 | // string newName = state->mol->getName();
|
---|
73 | // state->mol->setName(state->lastName);
|
---|
74 | //
|
---|
75 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
76 | }
|
---|
77 |
|
---|
78 | Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){
|
---|
79 | return Action::failure;
|
---|
80 | }
|
---|
81 |
|
---|
82 | bool AtomAddAction::canUndo() {
|
---|
83 | return false;
|
---|
84 | }
|
---|
85 |
|
---|
86 | bool AtomAddAction::shouldUndo() {
|
---|
87 | return false;
|
---|
88 | }
|
---|
89 |
|
---|
90 | const string AtomAddAction::getName() {
|
---|
91 | return NAME;
|
---|
92 | }
|
---|