- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/FragmentationAction/DepthFirstSearchAction.cpp
r623e89 r047878 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 9 8 10 #include "Actions/FragmentationAction/DepthFirstSearchAction.hpp" 11 #include "Actions/ActionRegistry.hpp" 9 12 #include "atom.hpp" 13 #include "bondgraph.hpp" 10 14 #include "config.hpp" 11 15 #include "log.hpp" … … 24 28 #include "UIElements/UIFactory.hpp" 25 29 #include "UIElements/Dialog.hpp" 26 #include " Actions/MapOfActions.hpp"30 #include "UIElements/ValueStorage.hpp" 27 31 28 32 const char FragmentationDepthFirstSearchAction::NAME[] = "depth-first-search"; … … 35 39 {} 36 40 41 void FragmentationDepthFirstSearch(double distance) { 42 ValueStorage::getInstance().setCurrentValue(FragmentationDepthFirstSearchAction::NAME, distance); 43 ActionRegistry::getInstance().getActionByName(FragmentationDepthFirstSearchAction::NAME)->call(Action::NonInteractive); 44 }; 45 46 Dialog* FragmentationDepthFirstSearchAction::fillDialog(Dialog *dialog) { 47 ASSERT(dialog,"No Dialog given when filling action dialog"); 48 49 dialog->queryDouble(NAME, ValueStorage::getInstance().getDescription(NAME)); 50 51 return dialog; 52 } 53 37 54 Action::state_ptr FragmentationDepthFirstSearchAction::performCall() { 38 Dialog *dialog = UIFactory::getInstance().makeDialog();39 55 double distance; 40 56 41 dialog->queryDouble(NAME, &distance, MapOfActions::getInstance().getDescription(NAME));57 ValueStorage::getInstance().queryCurrentValue(NAME, distance); 42 58 43 if(dialog->display()) { 44 DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl); 45 molecule * const mol = World::getInstance().getMolecule(MoleculeById(0)); 46 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis 47 int *MinimumRingSize = new int[mol->getAtomCount()]; 48 atom ***ListOfLocalAtoms = NULL; 49 class StackClass<bond *> *BackEdgeStack = NULL; 50 class StackClass<bond *> *LocalBackEdgeStack = NULL; 51 mol->CreateAdjacencyList(distance, World::getInstance().getConfig()->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); 52 Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack); 53 if (Subgraphs != NULL) { 54 int FragmentCounter = 0; 55 while (Subgraphs->next != NULL) { 56 Subgraphs = Subgraphs->next; 57 Subgraphs->FillBondStructureFromReference(mol, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 58 LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount); 59 Subgraphs->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack); 60 Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize); 61 delete(LocalBackEdgeStack); 62 delete(Subgraphs->previous); 63 FragmentCounter++; 64 } 65 delete(Subgraphs); 66 for (int i=0;i<FragmentCounter;i++) 67 delete[](ListOfLocalAtoms[i]); 68 delete[](ListOfLocalAtoms); 59 DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl); 60 molecule * const mol = World::getInstance().getMolecule(MoleculeById(0)); 61 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis 62 int *MinimumRingSize = new int[mol->getAtomCount()]; 63 atom **ListOfAtoms = NULL; 64 class StackClass<bond *> *BackEdgeStack = NULL; 65 class StackClass<bond *> *LocalBackEdgeStack = NULL; 66 mol->CreateAdjacencyList(distance, World::getInstance().getConfig()->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); 67 Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack); 68 if (Subgraphs != NULL) { 69 int FragmentCounter = 0; 70 while (Subgraphs->next != NULL) { 71 Subgraphs = Subgraphs->next; 72 ListOfAtoms = NULL; 73 Subgraphs->FillBondStructureFromReference(mol, ListOfAtoms, false); // we want to keep the created ListOfLocalAtoms 74 LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount); 75 Subgraphs->Leaf->PickLocalBackEdges(ListOfAtoms, BackEdgeStack, LocalBackEdgeStack); 76 Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize); 77 delete(LocalBackEdgeStack); 78 delete(Subgraphs->previous); 79 delete[](ListOfAtoms); // and here we remove it 80 FragmentCounter++; 69 81 } 70 delete(BackEdgeStack); 71 delete[](MinimumRingSize); 72 delete dialog; 73 return Action::success; 74 } else { 75 delete dialog; 76 return Action::failure; 82 delete(Subgraphs); 77 83 } 84 delete(BackEdgeStack); 85 delete[](MinimumRingSize); 86 return Action::success; 78 87 } 79 88 80 89 Action::state_ptr FragmentationDepthFirstSearchAction::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)); 90 return Action::success; 88 91 } 89 92 90 93 Action::state_ptr FragmentationDepthFirstSearchAction::performRedo(Action::state_ptr _state){ 91 return Action:: failure;94 return Action::success; 92 95 } 93 96 94 97 bool FragmentationDepthFirstSearchAction::canUndo() { 95 return false;98 return true; 96 99 } 97 100 98 101 bool FragmentationDepthFirstSearchAction::shouldUndo() { 99 return false;102 return true; 100 103 } 101 104
Note:
See TracChangeset
for help on using the changeset viewer.