1 | /*
|
---|
2 | * FragmentationAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/FragmentationAction/FragmentationAction.hpp"
|
---|
11 | #include "atom.hpp"
|
---|
12 | #include "config.hpp"
|
---|
13 | #include "log.hpp"
|
---|
14 | #include "molecule.hpp"
|
---|
15 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
16 | #include "stackclass.hpp"
|
---|
17 | #include "World.hpp"
|
---|
18 |
|
---|
19 | #include <iostream>
|
---|
20 | #include <string>
|
---|
21 |
|
---|
22 | using namespace std;
|
---|
23 |
|
---|
24 | #include "UIElements/UIFactory.hpp"
|
---|
25 | #include "UIElements/Dialog.hpp"
|
---|
26 | #include "Actions/MapOfActions.hpp"
|
---|
27 |
|
---|
28 | const char FragmentationFragmentationAction::NAME[] = "fragment-mol";
|
---|
29 |
|
---|
30 | FragmentationFragmentationAction::FragmentationFragmentationAction() :
|
---|
31 | Action(NAME)
|
---|
32 | {}
|
---|
33 |
|
---|
34 | FragmentationFragmentationAction::~FragmentationFragmentationAction()
|
---|
35 | {}
|
---|
36 |
|
---|
37 | Action::state_ptr FragmentationFragmentationAction::performCall() {
|
---|
38 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
39 | clock_t start,end;
|
---|
40 | molecule *mol = NULL;
|
---|
41 | double distance = -1.;
|
---|
42 | int order = 0;
|
---|
43 | config *configuration = World::getInstance().getConfig();
|
---|
44 | int ExitFlag = 0;
|
---|
45 |
|
---|
46 | cout << "pre-dialog"<< endl;
|
---|
47 | dialog->queryMolecule(NAME, &mol, MapOfActions::getInstance().getDescription(NAME));
|
---|
48 | dialog->queryDouble("distance", &distance, MapOfActions::getInstance().getDescription("distance"));
|
---|
49 | dialog->queryInt("order", &order, MapOfActions::getInstance().getDescription("order"));
|
---|
50 |
|
---|
51 | if(dialog->display()) {
|
---|
52 | cout << "POST-dialog"<< endl;
|
---|
53 | ASSERT(mol != NULL, "No molecule has been picked for fragmentation.");
|
---|
54 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with bond distance " << distance << " angstroem, order of " << order << "." << endl);
|
---|
55 | DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl);
|
---|
56 | start = clock();
|
---|
57 | mol->CreateAdjacencyList(distance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
58 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
|
---|
59 | if (mol->hasBondStructure()) {
|
---|
60 | ExitFlag = mol->FragmentMolecule(order, configuration);
|
---|
61 | }
|
---|
62 | World::getInstance().setExitFlag(ExitFlag);
|
---|
63 | end = clock();
|
---|
64 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
|
---|
65 | delete dialog;
|
---|
66 | return Action::success;
|
---|
67 | } else {
|
---|
68 | delete dialog;
|
---|
69 | return Action::failure;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | Action::state_ptr FragmentationFragmentationAction::performUndo(Action::state_ptr _state) {
|
---|
74 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
75 |
|
---|
76 | return Action::failure;
|
---|
77 | // string newName = state->mol->getName();
|
---|
78 | // state->mol->setName(state->lastName);
|
---|
79 | //
|
---|
80 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
81 | }
|
---|
82 |
|
---|
83 | Action::state_ptr FragmentationFragmentationAction::performRedo(Action::state_ptr _state){
|
---|
84 | return Action::failure;
|
---|
85 | }
|
---|
86 |
|
---|
87 | bool FragmentationFragmentationAction::canUndo() {
|
---|
88 | return false;
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool FragmentationFragmentationAction::shouldUndo() {
|
---|
92 | return false;
|
---|
93 | }
|
---|
94 |
|
---|
95 | const string FragmentationFragmentationAction::getName() {
|
---|
96 | return NAME;
|
---|
97 | }
|
---|