1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2013 University of Bonn. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * SubgraphDissectionAction.cpp
|
---|
25 | *
|
---|
26 | * Created on: Mar 1, 2013
|
---|
27 | * Author: heber
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "CodePatterns/MemDebug.hpp"
|
---|
36 |
|
---|
37 | #include "CodePatterns/Chronos.hpp"
|
---|
38 |
|
---|
39 | #include "Actions/GraphAction/CreateAdjacencyAction.hpp"
|
---|
40 | #include "Actions/GraphAction/DestroyAdjacencyAction.hpp"
|
---|
41 | #include "Actions/GraphAction/UpdateMoleculesAction.hpp"
|
---|
42 | #include "Actions/GraphAction/SubgraphDissectionAction.hpp"
|
---|
43 | #include "Actions/ActionRegistry.hpp"
|
---|
44 |
|
---|
45 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
46 |
|
---|
47 | #include "SubgraphDissectionAction.def"
|
---|
48 |
|
---|
49 | // some derived names: if CATEGORY is not given, we don't prefix with it
|
---|
50 | #ifdef CATEGORY
|
---|
51 | #define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
|
---|
52 | #define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
|
---|
53 | #define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
|
---|
54 | #else
|
---|
55 | #define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
|
---|
56 | #define COMMAND ACTIONNAME
|
---|
57 | #define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
|
---|
58 | #endif
|
---|
59 | // check if no lists given
|
---|
60 | #ifndef paramtypes
|
---|
61 | #define MAXPARAMTYPES 0
|
---|
62 | #else
|
---|
63 | #define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
|
---|
64 | #endif
|
---|
65 | #ifndef paramdefaults
|
---|
66 | #define MAXPARAMDEFAULTS 0
|
---|
67 | #else
|
---|
68 | #define MAXPARAMDEFAULTS BOOST_PP_SEQ_SIZE(paramdefaults)
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | namespace MoleCuilder {
|
---|
72 |
|
---|
73 | // static instances
|
---|
74 | ActionSequence GraphSubgraphDissectionAction::actions;
|
---|
75 | bool GraphSubgraphDissectionAction::isPrepared = false;
|
---|
76 |
|
---|
77 | GraphSubgraphDissectionAction::GraphSubgraphDissectionAction() :
|
---|
78 | MakroAction(ActionTraits< GraphSubgraphDissectionAction >(), actions, false)
|
---|
79 | {}
|
---|
80 |
|
---|
81 | GraphSubgraphDissectionAction::~GraphSubgraphDissectionAction()
|
---|
82 | {}
|
---|
83 |
|
---|
84 | void GraphSubgraphDissectionAction::prepare(ActionRegistry &AR)
|
---|
85 | {
|
---|
86 | actions.addAction(AR.getActionByName(std::string("destroy-adjacency")));
|
---|
87 | actions.addAction(AR.getActionByName(std::string("create-adjacency")));
|
---|
88 | actions.addAction(AR.getActionByName(std::string("update-molecules")));
|
---|
89 | isPrepared = true;
|
---|
90 | }
|
---|
91 |
|
---|
92 | void GraphSubgraphDissectionAction::unprepare(ActionRegistry &AR)
|
---|
93 | {
|
---|
94 | // empty sequence
|
---|
95 | while (actions.removeLastAction() != NULL);
|
---|
96 | isPrepared = false;
|
---|
97 | }
|
---|
98 |
|
---|
99 | void reselectAtoms(const std::vector<atom *> &selected_atoms)
|
---|
100 | {
|
---|
101 | World::getInstance().clearAtomSelection();
|
---|
102 | for (std::vector<atom *>::const_iterator iter = selected_atoms.begin();
|
---|
103 | iter != selected_atoms.end();
|
---|
104 | ++iter)
|
---|
105 | World::getInstance().selectAtom(*iter);
|
---|
106 | }
|
---|
107 |
|
---|
108 | Action::state_ptr GraphSubgraphDissectionAction::performCall(){
|
---|
109 | // we need to "emulate" that all atoms have been selected without destroying
|
---|
110 | // current selection
|
---|
111 | Chronos::getInstance().startTiming(TOKEN);
|
---|
112 | const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
|
---|
113 | World::getInstance().selectAllAtoms(AllAtoms());
|
---|
114 | Action::state_ptr state(MakroAction::performCall());
|
---|
115 | reselectAtoms(selected_atoms);
|
---|
116 | Chronos::getInstance().endTiming(TOKEN);
|
---|
117 |
|
---|
118 | return state;
|
---|
119 | }
|
---|
120 |
|
---|
121 | Action::state_ptr GraphSubgraphDissectionAction::performUndo(Action::state_ptr _state) {
|
---|
122 | // we need to "emulate" that all atoms have been selected without destroying
|
---|
123 | // current selection
|
---|
124 | const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
|
---|
125 | World::getInstance().selectAllAtoms(AllAtoms());
|
---|
126 | Action::state_ptr state(MakroAction::performUndo(_state));
|
---|
127 | reselectAtoms(selected_atoms);
|
---|
128 |
|
---|
129 | return state;
|
---|
130 | }
|
---|
131 |
|
---|
132 | Action::state_ptr GraphSubgraphDissectionAction::performRedo(Action::state_ptr _state){
|
---|
133 | // we need to "emulate" that all atoms have been selected without destroying
|
---|
134 | // current selection
|
---|
135 | const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
|
---|
136 | World::getInstance().selectAllAtoms(AllAtoms());
|
---|
137 | Action::state_ptr state(MakroAction::performRedo(_state));
|
---|
138 | reselectAtoms(selected_atoms);
|
---|
139 |
|
---|
140 | return state;
|
---|
141 | }
|
---|
142 |
|
---|
143 | // =========== command for calling action directly ===========
|
---|
144 | void COMMAND(
|
---|
145 | #if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
|
---|
146 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
|
---|
147 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
---|
148 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
149 | #endif
|
---|
150 | )
|
---|
151 | {
|
---|
152 | ACTION *ToCall = dynamic_cast<ACTION*>(ActionRegistry::getInstance().getActionByName( TOKEN )); //->clone(params);
|
---|
153 | //ACTION::PARAMS params;
|
---|
154 | #if defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
|
---|
155 | #define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, paramreferences, ToCall->params.)
|
---|
156 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
---|
157 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
158 | #endif
|
---|
159 | ToCall->call(Action::NonInteractive);
|
---|
160 | };
|
---|
161 |
|
---|
162 | void BOOST_PP_CAT( COMMAND, _stringargs)(
|
---|
163 | #if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
|
---|
164 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
|
---|
165 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
---|
166 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
167 | #endif
|
---|
168 | ) {
|
---|
169 | ACTION *ToCall = dynamic_cast<ACTION*>(ActionRegistry::getInstance().getActionByName( TOKEN )); //->clone(params);
|
---|
170 | //ACTION::PARAMS params;
|
---|
171 | #if defined paramtypes && defined paramtypes && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
|
---|
172 | #define BOOST_PP_LOCAL_MACRO(n) valuetype_print(~, n, paramreferences, paramtypes, ToCall->params. )
|
---|
173 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
---|
174 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
175 | #endif
|
---|
176 | ToCall->call(MoleCuilder::Action::NonInteractive);
|
---|
177 | };
|
---|
178 |
|
---|
179 | }
|
---|