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 "CommandLineParser.hpp"
|
---|
12 | #include "atom.hpp"
|
---|
13 | #include "element.hpp"
|
---|
14 | #include "log.hpp"
|
---|
15 | #include "periodentafel.hpp"
|
---|
16 | #include "vector.hpp"
|
---|
17 | #include "verbose.hpp"
|
---|
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"
|
---|
27 | #include "Actions/MapOfActions.hpp"
|
---|
28 |
|
---|
29 | const char AtomAddAction::NAME[] = "add-atom";
|
---|
30 |
|
---|
31 | AtomAddAction::AtomAddAction() :
|
---|
32 | Action(NAME)
|
---|
33 | {}
|
---|
34 |
|
---|
35 | AtomAddAction::~AtomAddAction()
|
---|
36 | {}
|
---|
37 |
|
---|
38 | Action::state_ptr AtomAddAction::performCall() {
|
---|
39 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
40 | int Z = -1;
|
---|
41 | Vector position;
|
---|
42 |
|
---|
43 | dialog->queryInt(NAME, &Z, MapOfActions::getInstance().getDescription(NAME));
|
---|
44 | dialog->queryVector("position", &position, World::getInstance().getDomain(), true, MapOfActions::getInstance().getDescription("position"));
|
---|
45 |
|
---|
46 | if(dialog->display()) {
|
---|
47 | delete dialog;
|
---|
48 | atom * first = World::getInstance().createAtom();
|
---|
49 | first->type = World::getInstance().getPeriode()->FindElement(Z);
|
---|
50 | first->x = position;
|
---|
51 | if (first->type != NULL) {
|
---|
52 | DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << first->type->name << " at " << (first->x) << "." << endl);
|
---|
53 | return Action::success;
|
---|
54 | } else {
|
---|
55 | DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the specified element." << endl);
|
---|
56 | World::getInstance().destroyAtom(first);
|
---|
57 | return Action::failure;
|
---|
58 | }
|
---|
59 | } else {
|
---|
60 | delete dialog;
|
---|
61 | return Action::failure;
|
---|
62 | }
|
---|
63 |
|
---|
64 | }
|
---|
65 |
|
---|
66 | Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) {
|
---|
67 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
68 |
|
---|
69 | return Action::failure;
|
---|
70 | // string newName = state->mol->getName();
|
---|
71 | // state->mol->setName(state->lastName);
|
---|
72 | //
|
---|
73 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
74 | }
|
---|
75 |
|
---|
76 | Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){
|
---|
77 | return Action::failure;
|
---|
78 | }
|
---|
79 |
|
---|
80 | bool AtomAddAction::canUndo() {
|
---|
81 | return false;
|
---|
82 | }
|
---|
83 |
|
---|
84 | bool AtomAddAction::shouldUndo() {
|
---|
85 | return false;
|
---|
86 | }
|
---|
87 |
|
---|
88 | const string AtomAddAction::getName() {
|
---|
89 | return NAME;
|
---|
90 | }
|
---|