| 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 |  * DepthFirstSearchAction.cpp
 | 
|---|
| 10 |  *
 | 
|---|
| 11 |  *  Created on: May 9, 2010
 | 
|---|
| 12 |  *      Author: heber
 | 
|---|
| 13 |  */
 | 
|---|
| 14 | 
 | 
|---|
| 15 | // include config.h
 | 
|---|
| 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 17 | #include <config.h>
 | 
|---|
| 18 | #endif
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "atom.hpp"
 | 
|---|
| 23 | #include "Graph/BondGraph.hpp"
 | 
|---|
| 24 | #include "config.hpp"
 | 
|---|
| 25 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 26 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| 27 | #include "Graph/CyclicStructureAnalysis.hpp"
 | 
|---|
| 28 | #include "Graph/DepthFirstSearchAnalysis.hpp"
 | 
|---|
| 29 | #include "molecule.hpp"
 | 
|---|
| 30 | #include "Descriptors/MoleculeDescriptor.hpp"
 | 
|---|
| 31 | #include "Descriptors/MoleculeIdDescriptor.hpp"
 | 
|---|
| 32 | #include "World.hpp"
 | 
|---|
| 33 | 
 | 
|---|
| 34 | #include <iostream>
 | 
|---|
| 35 | #include <string>
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #include "Actions/GraphAction/DepthFirstSearchAction.hpp"
 | 
|---|
| 38 | 
 | 
|---|
| 39 | using namespace MoleCuilder;
 | 
|---|
| 40 | 
 | 
|---|
| 41 | // and construct the stuff
 | 
|---|
| 42 | #include "DepthFirstSearchAction.def"
 | 
|---|
| 43 | #include "Action_impl_pre.hpp"
 | 
|---|
| 44 | /** =========== define the function ====================== */
 | 
|---|
| 45 | Action::state_ptr GraphDepthFirstSearchAction::performCall() {
 | 
|---|
| 46 |   // obtain information
 | 
|---|
| 47 |   getParametersfromValueStorage();
 | 
|---|
| 48 | 
 | 
|---|
| 49 |   DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl);
 | 
|---|
| 50 |   atom **ListOfAtoms = NULL;
 | 
|---|
| 51 |   std::deque<bond *> *LocalBackEdgeStack = NULL;
 | 
|---|
| 52 |   DepthFirstSearchAnalysis DFS;
 | 
|---|
| 53 |   DFS();
 | 
|---|
| 54 |   DFS.UpdateMoleculeStructure();
 | 
|---|
| 55 |   MoleculeLeafClass *Subgraphs = DFS.getMoleculeStructure();
 | 
|---|
| 56 |   if (Subgraphs != NULL) {
 | 
|---|
| 57 |     int FragmentCounter = 0;
 | 
|---|
| 58 |     while (Subgraphs->next != NULL) {
 | 
|---|
| 59 |       Subgraphs = Subgraphs->next;
 | 
|---|
| 60 |       ListOfAtoms = NULL;
 | 
|---|
| 61 |       Subgraphs->Leaf->FillListOfLocalAtoms(ListOfAtoms, Subgraphs->Leaf->getAtomCount());
 | 
|---|
| 62 |       LocalBackEdgeStack = new std::deque<bond *>; // no need to have it Subgraphs->Leaf->BondCount size
 | 
|---|
| 63 |       DFS.PickLocalBackEdges(ListOfAtoms, LocalBackEdgeStack);
 | 
|---|
| 64 |       CyclicStructureAnalysis CycleAnalysis;
 | 
|---|
| 65 |       CycleAnalysis(LocalBackEdgeStack);
 | 
|---|
| 66 |       delete(LocalBackEdgeStack);
 | 
|---|
| 67 |       Subgraphs->Leaf = NULL;
 | 
|---|
| 68 |       delete(Subgraphs->previous);
 | 
|---|
| 69 |       delete[](ListOfAtoms);  // allocated by FillListOfLocalAtoms
 | 
|---|
| 70 |       FragmentCounter++;
 | 
|---|
| 71 |     }
 | 
|---|
| 72 |     Subgraphs->Leaf = NULL;
 | 
|---|
| 73 |     delete(Subgraphs);
 | 
|---|
| 74 |   }
 | 
|---|
| 75 |   return Action::success;
 | 
|---|
| 76 | }
 | 
|---|
| 77 | 
 | 
|---|
| 78 | Action::state_ptr GraphDepthFirstSearchAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 79 |   return Action::success;
 | 
|---|
| 80 | }
 | 
|---|
| 81 | 
 | 
|---|
| 82 | Action::state_ptr GraphDepthFirstSearchAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 83 |   return Action::success;
 | 
|---|
| 84 | }
 | 
|---|
| 85 | 
 | 
|---|
| 86 | bool GraphDepthFirstSearchAction::canUndo() {
 | 
|---|
| 87 |   return true;
 | 
|---|
| 88 | }
 | 
|---|
| 89 | 
 | 
|---|
| 90 | bool GraphDepthFirstSearchAction::shouldUndo() {
 | 
|---|
| 91 |   return true;
 | 
|---|
| 92 | }
 | 
|---|
| 93 | /** =========== end of function ====================== */
 | 
|---|