- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/BondAction/BondAddAction.cpp
r26b4d62 r88afc9 57 57 ActionState::ptr BondAddAction::performCall() { 58 58 // check preconditions 59 if (World::getInstance().countSelectedAtoms() != 2) { 60 STATUS("Exactly two atoms must be selected for BondAction Add."); 59 World& world = World::getInstance(); 60 if (world.countSelectedAtoms() <= 1) { 61 STATUS("There must be at least two atoms selected for BondAction Add."); 61 62 return Action::failure; 62 63 } 63 const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms(); 64 if (selected_atoms[0]->IsBondedTo(WorldTime::getTime(), selected_atoms[1])) { 65 STATUS("There already is a bond in between the two selected atoms."); 64 65 bondPairIds_t bondPairIds; 66 for (World::AtomSelectionConstIterator firstiter = world.beginAtomSelection(); 67 firstiter != world.endAtomSelection(); ++firstiter) { 68 for (World::AtomSelectionConstIterator seconditer = firstiter; 69 seconditer != world.endAtomSelection(); ++seconditer) { 70 if (firstiter == seconditer) 71 continue; 72 if (!(firstiter->second)->IsBondedTo(WorldTime::getTime(), seconditer->second)) 73 bondPairIds.push_back( 74 std::make_pair((firstiter->second)->getId(), (seconditer->second)->getId())); 75 } 76 } 77 if (bondPairIds.empty()) { 78 STATUS("All bonds are already present."); 66 79 return Action::failure; 67 80 } 68 81 69 82 // create undo 70 BondAddState *UndoState = new BondAddState( selected_atoms[0]->getId(), selected_atoms[1]->getId(), params);83 BondAddState *UndoState = new BondAddState(bondPairIds, params); 71 84 72 85 // execute action 73 selected_atoms[0]->addBond(WorldTime::getTime(), selected_atoms[1]); 74 ASSERT( selected_atoms[0]->IsBondedTo(WorldTime::getTime(), selected_atoms[1]), 86 for (bondPairIds_t::const_iterator iter = bondPairIds.begin(); 87 iter != bondPairIds.end(); ++iter) { 88 atom *firstatom = world.getAtom(AtomById(iter->first)); 89 atom *secondatom = world.getAtom(AtomById(iter->second)); 90 ASSERT((firstatom != NULL) && (secondatom != NULL), 91 "BondAddAction::performCall() - at least one of the ids " 92 +toString(iter->first)+" or "+toString(iter->second)+" is not present."); 93 firstatom->addBond(WorldTime::getTime(), secondatom); 94 ASSERT( firstatom->IsBondedTo(WorldTime::getTime(), secondatom), 75 95 "BondAddAction::performCall() - adding bond in between " 76 +toString(*selected_atoms[0])+" and "+toString(*selected_atoms[1])+" failed."); 96 +toString(*firstatom)+" and "+toString(*secondatom)+" failed."); 97 } 77 98 78 99 return ActionState::ptr(UndoState); … … 83 104 84 105 // check whether bond already existed 85 atom * const first = World::getInstance().getAtom(AtomById(state->firstId)); 86 atom * const second = World::getInstance().getAtom(AtomById(state->secondId)); 87 ASSERT((first != NULL) && (second != NULL), 88 "BondAddAction::performUndo() - at least one of the ids " 89 +toString(state->firstId)+" or "+toString(state->secondId)+" is not present."); 90 if (first->IsBondedTo(WorldTime::getTime(), second)) { 91 first->removeBond(WorldTime::getTime(), second); 92 } else { 93 ELOG(2, "There is no bond in between "+toString(state->firstId) 94 +" and "+toString(state->secondId)+"."); 106 World& world = World::getInstance(); 107 for (bondPairIds_t::const_iterator iter = state->bondPairIds.begin(); 108 iter != state->bondPairIds.end(); ++iter) { 109 atom *firstatom = world.getAtom(AtomById(iter->first)); 110 atom *secondatom = world.getAtom(AtomById(iter->second)); 111 ASSERT((firstatom != NULL) && (secondatom != NULL), 112 "BondAddAction::performCall() - at least one of the ids " 113 +toString(iter->first)+" or "+toString(iter->second)+" is not present."); 114 if (firstatom->IsBondedTo(WorldTime::getTime(), secondatom)) { 115 firstatom->removeBond(WorldTime::getTime(), secondatom); 116 } else { 117 ELOG(2, "There is no bond in between "+toString(iter->first) 118 +" and "+toString(iter->second)+"."); 119 } 95 120 } 96 121 … … 102 127 103 128 // check whether bond already existed 104 atom * const first = World::getInstance().getAtom(AtomById(state->firstId)); 105 atom * const second = World::getInstance().getAtom(AtomById(state->secondId)); 106 ASSERT((first != NULL) && (second != NULL), 107 "BondAddAction::performRedo() - at least one of the ids " 108 +toString(state->firstId)+" or "+toString(state->secondId)+" is not present."); 109 if (!first->IsBondedTo(WorldTime::getTime(), second)) { 110 first->addBond(WorldTime::getTime(), second); 111 } else { 112 ELOG(2, "There is already a bond in between "+toString(state->firstId) 113 +" and "+toString(state->secondId)+"."); 129 World& world = World::getInstance(); 130 for (bondPairIds_t::const_iterator iter = state->bondPairIds.begin(); 131 iter != state->bondPairIds.end(); ++iter) { 132 atom * const firstatom = world.getAtom(AtomById(iter->first)); 133 atom * const secondatom = world.getAtom(AtomById(iter->second)); 134 ASSERT((firstatom != NULL) && (secondatom != NULL), 135 "BondAddAction::performCall() - at least one of the ids " 136 +toString(iter->first)+" or "+toString(iter->second)+" is not present."); 137 if (!firstatom->IsBondedTo(WorldTime::getTime(), secondatom)) { 138 firstatom->addBond(WorldTime::getTime(), secondatom); 139 } else { 140 ELOG(2, "There is already a bond in between "+toString(iter->first) 141 +" and "+toString(iter->second)+"."); 142 } 114 143 } 115 144
Note:
See TracChangeset
for help on using the changeset viewer.