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