| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010-2011 University of Bonn. All rights reserved. | 
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | /* | 
|---|
| 9 | * BondFileAction.cpp | 
|---|
| 10 | * | 
|---|
| 11 | *  Created on: May 10, 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 "Graph/BondGraph.hpp" | 
|---|
| 23 | #include "CodePatterns/Log.hpp" | 
|---|
| 24 | #include "molecule.hpp" | 
|---|
| 25 | #include "CodePatterns/Verbose.hpp" | 
|---|
| 26 | #include "World.hpp" | 
|---|
| 27 |  | 
|---|
| 28 | #include <iostream> | 
|---|
| 29 | #include <fstream> | 
|---|
| 30 | #include <string> | 
|---|
| 31 |  | 
|---|
| 32 | #include "Actions/MoleculeAction/BondFileAction.hpp" | 
|---|
| 33 |  | 
|---|
| 34 | using namespace MoleCuilder; | 
|---|
| 35 |  | 
|---|
| 36 | // and construct the stuff | 
|---|
| 37 | #include "BondFileAction.def" | 
|---|
| 38 | #include "Action_impl_pre.hpp" | 
|---|
| 39 | /** =========== define the function ====================== */ | 
|---|
| 40 | Action::state_ptr MoleculeBondFileAction::performCall() { | 
|---|
| 41 | molecule *mol = NULL; | 
|---|
| 42 |  | 
|---|
| 43 | // obtain information | 
|---|
| 44 | getParametersfromValueStorage(); | 
|---|
| 45 |  | 
|---|
| 46 | if(World::getInstance().countSelectedMolecules() == 1) { | 
|---|
| 47 | mol = World::getInstance().beginMoleculeSelection()->second; | 
|---|
| 48 | LOG(0, "STATUS: Parsing bonds from " << params.bondfile | 
|---|
| 49 | << ", skipping " << params.skiplines << "lines" | 
|---|
| 50 | << ", adding " << params.id_offset << " to each id."); | 
|---|
| 51 | ifstream input(params.bondfile.string().c_str()); | 
|---|
| 52 | World::AtomComposite Set = mol->getAtomSet(); | 
|---|
| 53 | World::getInstance().getBondGraph()->CreateAdjacencyListFromDbondFile(Set, &input, params.skiplines, params.id_offset); | 
|---|
| 54 | input.close(); | 
|---|
| 55 | mol->getBondCount(); | 
|---|
| 56 | return Action::success; | 
|---|
| 57 | } else | 
|---|
| 58 | return Action::failure; | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | Action::state_ptr MoleculeBondFileAction::performUndo(Action::state_ptr _state) { | 
|---|
| 62 | //  MoleculeBondFileState *state = assert_cast<MoleculeBondFileState*>(_state.get()); | 
|---|
| 63 |  | 
|---|
| 64 | //  string newName = state->mol->getName(); | 
|---|
| 65 | //  state->mol->setName(state->lastName); | 
|---|
| 66 |  | 
|---|
| 67 | return Action::failure; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | Action::state_ptr MoleculeBondFileAction::performRedo(Action::state_ptr _state){ | 
|---|
| 71 | return Action::failure; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | bool MoleculeBondFileAction::canUndo() { | 
|---|
| 75 | return true; | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | bool MoleculeBondFileAction::shouldUndo() { | 
|---|
| 79 | return true; | 
|---|
| 80 | } | 
|---|
| 81 | /** =========== end of function ====================== */ | 
|---|