Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/BondAction/BondRemoveAction.cpp

    r88afc9 r26b4d62  
    5757ActionState::ptr BondRemoveAction::performCall() {
    5858  // check preconditions
    59   World& world = World::getInstance();
    60   if (world.countSelectedAtoms() <= 1) {
    61     STATUS("At least two atoms must be selected for BondAction Remove.");
     59  if (World::getInstance().countSelectedAtoms() != 2) {
     60    STATUS("Exactly two atoms must be selected for BondAction Remove.");
    6261    return Action::failure;
    6362  }
    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("No bonds are present.");
     63  const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
     64  if (!selected_atoms[0]->IsBondedTo(WorldTime::getTime(), selected_atoms[1])) {
     65    STATUS("There is no bond in between the two selected atoms.");
    7966    return Action::failure;
    8067  }
    8168
    8269  // create undo
    83   BondRemoveState *UndoState = new BondRemoveState(bondPairIds, params);
     70  BondRemoveState *UndoState = new BondRemoveState(selected_atoms[0]->getId(), selected_atoms[1]->getId(), params);
    8471
    8572  // execute action
    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->removeBond(WorldTime::getTime(), secondatom);
    94     ASSERT( !firstatom->IsBondedTo(WorldTime::getTime(), secondatom),
    95       "BondAddAction::performCall() - adding bond in between "
    96       +toString(*firstatom)+" and "+toString(*secondatom)+" failed.");
    97   }
     73  selected_atoms[0]->removeBond(WorldTime::getTime(), selected_atoms[1]);
     74  ASSERT( !selected_atoms[0]->IsBondedTo(WorldTime::getTime(), selected_atoms[1]),
     75      "BondRemoveAction::performCall() - removing bond in between "
     76      +toString(*selected_atoms[0])+" and "+toString(*selected_atoms[1])+" failed.");
    9877
    9978  return ActionState::ptr(UndoState);
     
    10382  BondRemoveState *state = assert_cast<BondRemoveState*>(_state.get());
    10483
    105   World& world = World::getInstance();
    106   for (bondPairIds_t::const_iterator iter = state->bondPairIds.begin();
    107       iter != state->bondPairIds.end(); ++iter) {
    108     atom * const firstatom = world.getAtom(AtomById(iter->first));
    109     atom * const secondatom = world.getAtom(AtomById(iter->second));
    110     ASSERT((firstatom != NULL) && (secondatom != NULL),
    111         "BondAddAction::performCall() - at least one of the ids "
    112         +toString(iter->first)+" or "+toString(iter->second)+" is not present.");
    113     if (!firstatom->IsBondedTo(WorldTime::getTime(), secondatom)) {
    114       firstatom->addBond(WorldTime::getTime(), secondatom);
    115     } else {
    116       ELOG(2, "There is already a bond in between "+toString(iter->first)
    117           +" and "+toString(iter->second)+".");
    118     }
     84  // 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      "BondRemoveAction::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->addBond(WorldTime::getTime(), second);
     92  } else {
     93    ELOG(2, "There is already a bond in between "+toString(state->firstId)
     94        +" and "+toString(state->secondId)+".");
    11995  }
    12096
     
    125101  BondRemoveState *state = assert_cast<BondRemoveState*>(_state.get());
    126102
    127   World& world = World::getInstance();
    128   for (bondPairIds_t::const_iterator iter = state->bondPairIds.begin();
    129       iter != state->bondPairIds.end(); ++iter) {
    130     atom *firstatom = world.getAtom(AtomById(iter->first));
    131     atom *secondatom = world.getAtom(AtomById(iter->second));
    132     ASSERT((firstatom != NULL) && (secondatom != NULL),
    133         "BondAddAction::performCall() - at least one of the ids "
    134         +toString(iter->first)+" or "+toString(iter->second)+" is not present.");
    135     if (firstatom->IsBondedTo(WorldTime::getTime(), secondatom)) {
    136       firstatom->removeBond(WorldTime::getTime(), secondatom);
    137     } else {
    138       ELOG(2, "There is no bond in between "+toString(iter->first)
    139           +" and "+toString(iter->second)+".");
    140     }
     103  // 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      "BondRemoveAction::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->removeBond(WorldTime::getTime(), second);
     111  } else {
     112    ELOG(2, "There is no bond in between "+toString(state->firstId)
     113        +" and "+toString(state->secondId)+".");
    141114  }
    142115
Note: See TracChangeset for help on using the changeset viewer.