Skip to content

Commit

Permalink
Merge pull request #672 from ghutchis/fix-select-delete-bug
Browse files Browse the repository at this point in the history
Fix #650 - deleting selected atoms
  • Loading branch information
ghutchis authored Jul 16, 2021
2 parents 17a0490 + 390c8c0 commit ec7f38f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
3 changes: 3 additions & 0 deletions avogadro/core/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ bool Molecule::removeAtom(Index index)
if (m_colors.size() == atomCount())
m_colors.swapAndPop(index);

if (m_selectedAtoms.size() == atomCount())
m_selectedAtoms.erase(m_selectedAtoms.begin() + index);

Index affectedIndex = static_cast<Index>(m_atomicNumbers.size() - 1);
m_atomicNumbers.swapAndPop(index);
removeBonds(index);
Expand Down
21 changes: 7 additions & 14 deletions avogadro/qtplugins/copypaste/copypaste.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
/******************************************************************************
This source file is part of the Avogadro project.
Copyright 2013 Kitware, Inc.
This source code is released under the New BSD License, (the "License").
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#include "copypaste.h"
Expand Down Expand Up @@ -156,7 +145,9 @@ void CopyPaste::cut()
if (m_molecule->isSelectionEmpty())
m_molecule->undoMolecule()->clearAtoms();
else {
for (Index i = 0; i < m_molecule->atomCount(); ++i)
// Remove atoms from the largest to the smallest index
// (that way, the index doesn't change)
for (Index i = m_molecule->atomCount(); i > 0; --i)
if (m_molecule->atomSelected(i))
m_molecule->undoMolecule()->removeAtom(i);
}
Expand All @@ -170,7 +161,9 @@ void CopyPaste::clear()
if (m_molecule->isSelectionEmpty())
m_molecule->undoMolecule()->clearAtoms();
else {
for (Index i = 0; i < m_molecule->atomCount(); ++i)
// Remove atoms from the largest to the smallest index
// (that way, the index doesn't change)
for (Index i = m_molecule->atomCount(); i > 0; --i)
if (m_molecule->atomSelected(i))
m_molecule->undoMolecule()->removeAtom(i);
}
Expand Down
13 changes: 1 addition & 12 deletions avogadro/qtplugins/copypaste/copypaste.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
/******************************************************************************
This source file is part of the Avogadro project.
Copyright 2013 Kitware, Inc.
This source code is released under the New BSD License, (the "License").
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#ifndef AVOGADRO_QTPLUGINS_COPYPASTE_H
Expand Down

0 comments on commit ec7f38f

Please sign in to comment.