1 | /*
|
---|
2 | * AddAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | // include config.h
|
---|
9 | #ifdef HAVE_CONFIG_H
|
---|
10 | #include <config.h>
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | #include "Helpers/MemDebug.hpp"
|
---|
14 |
|
---|
15 | #include "Actions/AtomAction/AddAction.hpp"
|
---|
16 | #include "Actions/ActionRegistry.hpp"
|
---|
17 | #include "atom.hpp"
|
---|
18 | #include "element.hpp"
|
---|
19 | #include "Helpers/Log.hpp"
|
---|
20 | #include "molecule.hpp"
|
---|
21 | #include "LinearAlgebra/Vector.hpp"
|
---|
22 | #include "Helpers/Verbose.hpp"
|
---|
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"
|
---|
32 | #include "Actions/ValueStorage.hpp"
|
---|
33 |
|
---|
34 | const char AtomAddAction::NAME[] = "add-atom";
|
---|
35 |
|
---|
36 | AtomAddAction::AtomAddAction() :
|
---|
37 | Action(NAME)
|
---|
38 | {}
|
---|
39 |
|
---|
40 | AtomAddAction::~AtomAddAction()
|
---|
41 | {}
|
---|
42 |
|
---|
43 | void AtomAdd(element *elemental, Vector &position) {
|
---|
44 | ValueStorage::getInstance().setCurrentValue(AtomAddAction::NAME, elemental);
|
---|
45 | ValueStorage::getInstance().setCurrentValue("position", elemental);
|
---|
46 | ActionRegistry::getInstance().getActionByName(AtomAddAction::NAME)->call(Action::NonInteractive);
|
---|
47 | };
|
---|
48 |
|
---|
49 | Dialog * AtomAddAction::fillDialog(Dialog *dialog) {
|
---|
50 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
51 |
|
---|
52 | dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
53 | dialog->queryVector("position", true, ValueStorage::getInstance().getDescription("position"));
|
---|
54 |
|
---|
55 | return dialog;
|
---|
56 | }
|
---|
57 |
|
---|
58 | Action::state_ptr AtomAddAction::performCall() {
|
---|
59 | const element * elemental = NULL;
|
---|
60 | Vector position;
|
---|
61 |
|
---|
62 | // obtain information
|
---|
63 | ValueStorage::getInstance().queryCurrentValue(NAME, elemental);
|
---|
64 | ValueStorage::getInstance().queryCurrentValue("position", position);
|
---|
65 |
|
---|
66 | // execute action
|
---|
67 | atom * first = World::getInstance().createAtom();
|
---|
68 | first->setType(elemental);
|
---|
69 | first->setPosition(position);
|
---|
70 | DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << first->getType()->getName() << " at " << (first->getPosition()) << "." << endl);
|
---|
71 | // TODO: remove when all of World's atoms are stored.
|
---|
72 | std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
|
---|
73 | if (!molecules.empty()) {
|
---|
74 | std::vector<molecule *>::iterator iter = molecules.begin();
|
---|
75 | (*iter)->AddAtom(first);
|
---|
76 | }
|
---|
77 | return Action::success;
|
---|
78 | }
|
---|
79 |
|
---|
80 | Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) {
|
---|
81 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
82 |
|
---|
83 | return Action::failure;
|
---|
84 | // string newName = state->mol->getName();
|
---|
85 | // state->mol->setName(state->lastName);
|
---|
86 | //
|
---|
87 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
88 | }
|
---|
89 |
|
---|
90 | Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){
|
---|
91 | return Action::failure;
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool AtomAddAction::canUndo() {
|
---|
95 | return false;
|
---|
96 | }
|
---|
97 |
|
---|
98 | bool AtomAddAction::shouldUndo() {
|
---|
99 | return false;
|
---|
100 | }
|
---|
101 |
|
---|
102 | const string AtomAddAction::getName() {
|
---|
103 | return NAME;
|
---|
104 | }
|
---|