Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FragmentationAction/DepthFirstSearchAction.cpp

    r623e89 r047878  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
     11#include "Actions/ActionRegistry.hpp"
    912#include "atom.hpp"
     13#include "bondgraph.hpp"
    1014#include "config.hpp"
    1115#include "log.hpp"
     
    2428#include "UIElements/UIFactory.hpp"
    2529#include "UIElements/Dialog.hpp"
    26 #include "Actions/MapOfActions.hpp"
     30#include "UIElements/ValueStorage.hpp"
    2731
    2832const char FragmentationDepthFirstSearchAction::NAME[] = "depth-first-search";
     
    3539{}
    3640
     41void FragmentationDepthFirstSearch(double distance) {
     42  ValueStorage::getInstance().setCurrentValue(FragmentationDepthFirstSearchAction::NAME, distance);
     43  ActionRegistry::getInstance().getActionByName(FragmentationDepthFirstSearchAction::NAME)->call(Action::NonInteractive);
     44};
     45
     46Dialog* 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
    3754Action::state_ptr FragmentationDepthFirstSearchAction::performCall() {
    38   Dialog *dialog = UIFactory::getInstance().makeDialog();
    3955  double distance;
    4056
    41   dialog->queryDouble(NAME, &distance, MapOfActions::getInstance().getDescription(NAME));
     57  ValueStorage::getInstance().queryCurrentValue(NAME, distance);
    4258
    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++;
    6981    }
    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);
    7783  }
     84  delete(BackEdgeStack);
     85  delete[](MinimumRingSize);
     86  return Action::success;
    7887}
    7988
    8089Action::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;
    8891}
    8992
    9093Action::state_ptr FragmentationDepthFirstSearchAction::performRedo(Action::state_ptr _state){
    91   return Action::failure;
     94  return Action::success;
    9295}
    9396
    9497bool FragmentationDepthFirstSearchAction::canUndo() {
    95   return false;
     98  return true;
    9699}
    97100
    98101bool FragmentationDepthFirstSearchAction::shouldUndo() {
    99   return false;
     102  return true;
    100103}
    101104
Note: See TracChangeset for help on using the changeset viewer.