Skip to content

Commit

Permalink
Tweak atom and bond removal
Browse files Browse the repository at this point in the history
Fix #1478
- remove a hydrogen if right-clicked (always)
- adjust hydrogens if you right-click to break a bond

Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis committed Dec 28, 2024
1 parent b6365a9 commit 2ffcad3
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions avogadro/qtplugins/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Editor::Editor(QObject* parent_)
m_activateAction->setToolTip(
tr("Draw Tool \t(%1)\n\n"
"Left Mouse: \tClick and Drag to create Atoms and Bond\n"
"Right Mouse: \tDelete Atom").arg(shortcut));
"Right Mouse: \tDelete Atom")
.arg(shortcut));
setIcon();
reset();
}
Expand Down Expand Up @@ -421,9 +422,9 @@ void Editor::atomRightClick(QMouseEvent* e)
Core::Array<Index> bondedAtoms;
if (m_toolWidget->adjustHydrogens()) {
// before we remove the atom, we need to delete any H atoms
// that are bonded to it
// that are bonded to it -- unless it's a hydrogen atom itself
RWAtom atom = m_molecule->atom(m_clickedObject.index);
if (atom.isValid()) {
if (atom.isValid() && atom.atomicNumber() != Core::Hydrogen) {
// get the list of bonded atoms
Core::Array<RWBond> atomBonds = m_molecule->bonds(atom);
for (const RWBond& bond : atomBonds) {
Expand Down Expand Up @@ -453,8 +454,17 @@ void Editor::atomRightClick(QMouseEvent* e)
void Editor::bondRightClick(QMouseEvent* e)
{
e->accept();
m_molecule->removeBond(m_clickedObject.index);
m_molecule->emitChanged(Molecule::Bonds | Molecule::Removed);
// see if we need to adjust hydrogens
if (m_toolWidget->adjustHydrogens()) {
RWBond bond = m_molecule->bond(m_clickedObject.index);
RWAtom atom1 = bond.atom1();
RWAtom atom2 = bond.atom2();
m_molecule->removeBond(m_clickedObject.index);
QtGui::HydrogenTools::adjustHydrogens(atom1);
QtGui::HydrogenTools::adjustHydrogens(atom2);
}
m_molecule->emitChanged(Molecule::Atoms | Molecule::Bonds |
Molecule::Removed);
}

int expectedBondOrder(RWAtom atom1, RWAtom atom2)
Expand Down

0 comments on commit 2ffcad3

Please sign in to comment.