- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/CommandAction/BondLengthTableAction.cpp
rb1ac7a rce7fdc 17 17 #include <config.h> 18 18 #endif 19 20 // include headers that implement a archive in simple text format21 #include <boost/archive/text_oarchive.hpp>22 #include <boost/archive/text_iarchive.hpp>23 19 24 20 #include "CodePatterns/MemDebug.hpp" … … 48 44 49 45 DoLog(0) && (Log() << Verbose(0) << "Using " << params.BondGraphFileName << " as bond length table." << endl); 50 BondGraph *&BG = World::getInstance().getBondGraph(); 46 config *configuration = World::getInstance().getConfig(); 47 BondGraph *OldBG = World::getInstance().getBondGraph(); 51 48 52 // create undo state 53 std::stringstream undostream; 54 boost::archive::text_oarchive oa(undostream); 55 oa << BG; 56 CommandBondLengthTableState *UndoState = 57 new CommandBondLengthTableState( 58 undostream.str(), 59 params 60 ); 61 62 BG->CleanupBondLengthTable(); 49 BondGraph *BG = new BondGraph(configuration->GetIsAngstroem()); 63 50 if ((!params.BondGraphFileName.empty()) 64 51 && boost::filesystem::exists(params.BondGraphFileName)) { … … 67 54 DoLog(0) && (Log() << Verbose(0) << "Bond length table parsed successfully." << endl); 68 55 input.close(); 69 return Action::state_ptr(UndoState); 56 CommandBondLengthTableState *state = new CommandBondLengthTableState(*OldBG, params); 57 World::getInstance().setBondGraph(BG); // Changes OldBG, hence have to copy beforehand 58 return Action::state_ptr(state); 70 59 } else { 71 60 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table parsing failed." << endl); 72 61 input.close(); 62 return Action::failure; 73 63 } 74 64 } else { 75 65 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl); 66 return Action::failure; 76 67 } 77 // recover bond graph78 boost::archive::text_iarchive ia(undostream);79 delete BG;80 ia >> BG;81 delete UndoState;82 return Action::failure;83 68 } 84 69 … … 86 71 CommandBondLengthTableState *state = assert_cast<CommandBondLengthTableState*>(_state.get()); 87 72 88 BondGraph *BG; 89 std::stringstream undostream(state->undostring); 90 boost::archive::text_iarchive ia(undostream); 91 ia >> BG; 92 World::getInstance().setBondGraph(BG); 73 BondGraph *OldBG = World::getInstance().getBondGraph(); 74 CommandBondLengthTableState *restate = new CommandBondLengthTableState(*OldBG, params); 75 World::getInstance().setBondGraph(new BondGraph(state->OldBG)); // Changes OldBG, hence have to copy beforehand 93 76 94 return Action::state_ptr( _state);77 return Action::state_ptr(restate); 95 78 } 96 79 … … 98 81 CommandBondLengthTableState *state = assert_cast<CommandBondLengthTableState*>(_state.get()); 99 82 100 BondGraph *&BG = World::getInstance().getBondGraph(); 101 BG->CleanupBondLengthTable(); 102 std::ifstream input(state->params.BondGraphFileName.string().c_str()); 103 if ((input.good()) && (BG->LoadBondLengthTable(input))) { 104 DoLog(0) && (Log() << Verbose(0) << "Bond length table parsed successfully." << endl); 105 input.close(); 106 } 83 BondGraph *OldBG = World::getInstance().getBondGraph(); 84 CommandBondLengthTableState *restate = new CommandBondLengthTableState(*OldBG, params); 85 World::getInstance().setBondGraph(new BondGraph(state->OldBG)); // Changes OldBG, hence have to copy beforehand 107 86 108 return Action::state_ptr( _state);87 return Action::state_ptr(restate); 109 88 } 110 89 111 90 bool CommandBondLengthTableAction::canUndo() { 112 return true;91 return false; 113 92 } 114 93 115 94 bool CommandBondLengthTableAction::shouldUndo() { 116 return true;95 return false; 117 96 } 118 97 /** =========== end of function ====================== */
Note:
See TracChangeset
for help on using the changeset viewer.