| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [bcf653] | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [97ebf8] | 8 | /*
 | 
|---|
 | 9 |  * BondFileAction.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: May 10, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 21 | 
 | 
|---|
| [632508] | 22 | #include "Graph/BondGraph.hpp"
 | 
|---|
| [ad011c] | 23 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [1a3c26] | 24 | #include "molecule.hpp"
 | 
|---|
| [ad011c] | 25 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [1a3c26] | 26 | #include "World.hpp"
 | 
|---|
| [97ebf8] | 27 | 
 | 
|---|
 | 28 | #include <iostream>
 | 
|---|
 | 29 | #include <fstream>
 | 
|---|
 | 30 | #include <string>
 | 
|---|
 | 31 | 
 | 
|---|
| [1fd675] | 32 | #include "Actions/MoleculeAction/BondFileAction.hpp"
 | 
|---|
| [eacc3b] | 33 | 
 | 
|---|
| [ce7fdc] | 34 | using namespace MoleCuilder;
 | 
|---|
 | 35 | 
 | 
|---|
| [1fd675] | 36 | // and construct the stuff
 | 
|---|
 | 37 | #include "BondFileAction.def"
 | 
|---|
 | 38 | #include "Action_impl_pre.hpp"
 | 
|---|
 | 39 | /** =========== define the function ====================== */
 | 
|---|
| [97ebf8] | 40 | Action::state_ptr MoleculeBondFileAction::performCall() {
 | 
|---|
 | 41 |   molecule *mol = NULL;
 | 
|---|
 | 42 | 
 | 
|---|
| [eacc3b] | 43 |   if(World::getInstance().countSelectedMolecules() == 1) {
 | 
|---|
 | 44 |     mol = World::getInstance().beginMoleculeSelection()->second;
 | 
|---|
| [0cbad2] | 45 |     LOG(0, "STATUS: Parsing bonds from " << params.bondfile
 | 
|---|
 | 46 |         << ", skipping " << params.skiplines << "lines"
 | 
|---|
 | 47 |         << ", adding " << params.id_offset << " to each id.");
 | 
|---|
| [e4afb4] | 48 |     ifstream input(params.bondfile.string().c_str());
 | 
|---|
| [9317be] | 49 |     World::AtomComposite Set = mol->getAtomSet();
 | 
|---|
| [0cbad2] | 50 |     World::getInstance().getBondGraph()->CreateAdjacencyListFromDbondFile(Set, &input, params.skiplines, params.id_offset);
 | 
|---|
| [97ebf8] | 51 |     input.close();
 | 
|---|
| [0cbad2] | 52 |     mol->getBondCount();
 | 
|---|
| [97ebf8] | 53 |     return Action::success;
 | 
|---|
| [eacc3b] | 54 |   } else
 | 
|---|
 | 55 |     return Action::failure;
 | 
|---|
| [97ebf8] | 56 | }
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | Action::state_ptr MoleculeBondFileAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 59 | //  MoleculeBondFileState *state = assert_cast<MoleculeBondFileState*>(_state.get());
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | //  string newName = state->mol->getName();
 | 
|---|
 | 62 | //  state->mol->setName(state->lastName);
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 |   return Action::failure;
 | 
|---|
 | 65 | }
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 | Action::state_ptr MoleculeBondFileAction::performRedo(Action::state_ptr _state){
 | 
|---|
| [e69c87] | 68 |   return Action::failure;
 | 
|---|
| [97ebf8] | 69 | }
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | bool MoleculeBondFileAction::canUndo() {
 | 
|---|
| [e69c87] | 72 |   return true;
 | 
|---|
| [97ebf8] | 73 | }
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | bool MoleculeBondFileAction::shouldUndo() {
 | 
|---|
| [e69c87] | 76 |   return true;
 | 
|---|
| [97ebf8] | 77 | }
 | 
|---|
| [1fd675] | 78 | /** =========== end of function ====================== */
 | 
|---|