当前位置: 首页>>代码示例>>C++>>正文


C++ Bond::index方法代码示例

本文整理汇总了C++中Bond::index方法的典型用法代码示例。如果您正苦于以下问题:C++ Bond::index方法的具体用法?C++ Bond::index怎么用?C++ Bond::index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bond的用法示例。


在下文中一共展示了Bond::index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: removeBond

void Molecule::removeBond(unsigned long id)
{
    if (id < m_bonds.size()) {
        Q_D(Molecule);
        if (m_bonds[id] == 0)
            return;

        d->invalidRings = true;
        m_invalidPartialCharges = true;
        m_invalidAromaticity = true;
        Bond *bond = m_bonds[id];
        m_bonds[id] = 0;
        // Delete the bond from the list and reorder the remaining bonds
        int index = bond->index();
        m_bondList.removeAt(index);
        for (int i = index; i < m_bondList.size(); ++i) {
            m_bondList[i]->setIndex(i);
        }

        // Also delete the bond from the attached atoms
        if (m_atoms.size() > bond->beginAtomId()) {
            if (m_atoms[bond->beginAtomId()])
                m_atoms[bond->beginAtomId()]->removeBond(id);
        }
        if (m_atoms.size() > bond->endAtomId()) {
            if (m_atoms[bond->endAtomId()])
                m_atoms[bond->endAtomId()]->removeBond(id);
        }

        disconnect(bond, SIGNAL(updated()), this, SLOT(updateBond()));
        emit bondRemoved(bond);
        bond->deleteLater();
    }
}
开发者ID:timvdm,项目名称:avogadro,代码行数:34,代码来源:molecule.cpp

示例2:

TEST_F(MoleculeTest, addBond)
{
  Molecule molecule;
  EXPECT_EQ(molecule.bondCount(), static_cast<Index>(0));

  Atom a = molecule.addAtom(1);
  Atom b = molecule.addAtom(1);
  Bond bondAB = molecule.addBond(a, b);
  EXPECT_TRUE(bondAB.isValid());
  EXPECT_EQ(bondAB.molecule(), &molecule);
  EXPECT_EQ(molecule.bondCount(), static_cast<Index>(1));
  EXPECT_EQ(bondAB.index(), static_cast<Index>(0));
  EXPECT_EQ(bondAB.atom1().index(), a.index());
  EXPECT_EQ(bondAB.atom2().index(), b.index());
  EXPECT_EQ(bondAB.order(), static_cast<unsigned char>(1));

  Atom c = molecule.addAtom(1);
  Bond bondBC = molecule.addBond(b, c, 2);
  EXPECT_TRUE(bondBC.isValid());
  EXPECT_EQ(molecule.bondCount(), static_cast<Index>(2));
  EXPECT_EQ(bondBC.index(), static_cast<Index>(1));
  EXPECT_EQ(bondBC.order(), static_cast<unsigned char>(2));

  // try to lookup nonexistant bond
  Bond bond = molecule.bond(a, c);
  EXPECT_FALSE(bond.isValid());

  // try to lookup bond between a and b
  bond = molecule.bond(a, b);
  EXPECT_TRUE(bond.isValid());
  EXPECT_EQ(bond.molecule(), &molecule);
  EXPECT_EQ(bond.atom1().index(), a.index());
  EXPECT_EQ(bond.atom2().index(), b.index());

  // try to lookup bond between b and c by index
  bond = molecule.bond(1);
  EXPECT_TRUE(bond.isValid());
  EXPECT_EQ(bond.molecule(), &molecule);
  EXPECT_EQ(bond.atom1().index(), b.index());
  EXPECT_EQ(bond.atom2().index(), c.index());
}
开发者ID:AlbertDeFusco,项目名称:avogadrolibs,代码行数:41,代码来源:moleculetest.cpp


注:本文中的Bond::index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。