1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * AllAtomsAction.cpp
|
---|
10 | *
|
---|
11 | * Created on: May 12, 2010
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "Helpers/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Actions/SelectionAction/AllAtomsAction.hpp"
|
---|
23 | #include "Actions/ActionRegistry.hpp"
|
---|
24 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
25 | #include "atom.hpp"
|
---|
26 | #include "Helpers/Log.hpp"
|
---|
27 | #include "Helpers/Verbose.hpp"
|
---|
28 | #include "World.hpp"
|
---|
29 |
|
---|
30 | #include <iostream>
|
---|
31 | #include <string>
|
---|
32 |
|
---|
33 | using namespace std;
|
---|
34 |
|
---|
35 | #include "UIElements/UIFactory.hpp"
|
---|
36 | #include "UIElements/Dialog.hpp"
|
---|
37 | #include "Actions/ValueStorage.hpp"
|
---|
38 |
|
---|
39 |
|
---|
40 | // memento to remember the state when undoing
|
---|
41 |
|
---|
42 | class SelectionAllAtomsState : public ActionState {
|
---|
43 | public:
|
---|
44 | SelectionAllAtomsState(std::vector<atom*> _selectedAtoms) :
|
---|
45 | selectedAtoms(_selectedAtoms)
|
---|
46 | {}
|
---|
47 | std::vector<atom*> selectedAtoms;
|
---|
48 | };
|
---|
49 |
|
---|
50 | const char SelectionAllAtomsAction::NAME[] = "select-all-atoms";
|
---|
51 |
|
---|
52 | SelectionAllAtomsAction::SelectionAllAtomsAction() :
|
---|
53 | Action(NAME)
|
---|
54 | {}
|
---|
55 |
|
---|
56 | SelectionAllAtomsAction::~SelectionAllAtomsAction()
|
---|
57 | {}
|
---|
58 |
|
---|
59 | void SelectionAllAtoms() {
|
---|
60 | ActionRegistry::getInstance().getActionByName(SelectionAllAtomsAction::NAME)->call(Action::NonInteractive);
|
---|
61 | };
|
---|
62 |
|
---|
63 | void SelectionAllAtomsAction::getParametersfromValueStorage()
|
---|
64 | {};
|
---|
65 |
|
---|
66 | Dialog* SelectionAllAtomsAction::fillDialog(Dialog *dialog) {
|
---|
67 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
68 |
|
---|
69 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
70 |
|
---|
71 | return dialog;
|
---|
72 | }
|
---|
73 |
|
---|
74 | Action::state_ptr SelectionAllAtomsAction::performCall() {
|
---|
75 | std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
|
---|
76 | DoLog(1) && (Log() << Verbose(1) << "Selecting all atoms." << endl);
|
---|
77 | World::getInstance().selectAllAtoms(AllAtoms());
|
---|
78 | return Action::state_ptr(new SelectionAllAtomsState(selectedAtoms));
|
---|
79 | }
|
---|
80 |
|
---|
81 | Action::state_ptr SelectionAllAtomsAction::performUndo(Action::state_ptr _state) {
|
---|
82 | SelectionAllAtomsState *state = assert_cast<SelectionAllAtomsState*>(_state.get());
|
---|
83 |
|
---|
84 | World::getInstance().clearAtomSelection();
|
---|
85 | for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
|
---|
86 | World::getInstance().selectAtom(*iter);
|
---|
87 |
|
---|
88 | return Action::state_ptr(new SelectionAllAtomsState(state->selectedAtoms));
|
---|
89 | }
|
---|
90 |
|
---|
91 | Action::state_ptr SelectionAllAtomsAction::performRedo(Action::state_ptr _state){
|
---|
92 | SelectionAllAtomsState *state = assert_cast<SelectionAllAtomsState*>(_state.get());
|
---|
93 |
|
---|
94 | World::getInstance().selectAllAtoms(AllAtoms());
|
---|
95 |
|
---|
96 | return Action::state_ptr(new SelectionAllAtomsState(state->selectedAtoms));
|
---|
97 | }
|
---|
98 |
|
---|
99 | bool SelectionAllAtomsAction::canUndo() {
|
---|
100 | return true;
|
---|
101 | }
|
---|
102 |
|
---|
103 | bool SelectionAllAtomsAction::shouldUndo() {
|
---|
104 | return true;
|
---|
105 | }
|
---|
106 |
|
---|
107 | const string SelectionAllAtomsAction::getName() {
|
---|
108 | return NAME;
|
---|
109 | }
|
---|