void SetBondOrderCommand::redo() { Bond *bond = editor()->bond(m_atomId1, m_atomId2); Q_ASSERT(bond != 0); bond->setOrder(m_finalOrder); }
bool KCFFile::readEDGE_(KCFFile::IndexAtomMap& index_to_atom) { if (!getLine().hasPrefix(EDGE_TAG)) { throw Exception::ParseError(__FILE__, __LINE__, String("'") + getLine() + "' (line " + String(getLineNumber()) + " of " + getName() + "'", String("Expected EDGE tag: ")); } Size number_of_edges = getLine().getField(1).toInt(); bool ok = true; for (Position i = 0; ok && (i < number_of_edges); i++) { // Get the next line readLine(); // Make sure the line starts with a blank ok &= getLine().hasPrefix(CONTINUED_LINE); // ??? Comments still mising Position first = getLine().getField(1).toInt(); Position second = getLine().getField(2).toInt(); Position order = getLine().getField(3).toInt(); // Make sure the indices refered to do exist ok &= index_to_atom.has(first) && index_to_atom.has(second); if (ok) { Bond* bond = index_to_atom[first]->createBond(*index_to_atom[second]); bond->setOrder(order); } } return (ok && readLine()); }
void SetBondOrderCommand::undo() { Bond *bond = editor()->bond(m_atomId1, m_atomId2); assert(bond != 0); bond->setOrder(m_initialOrder); }
FOR_BONDS_OF_MOL(obBond, obMol) { Bond *bond = new Bond; bond->setOrder(obBond->GetBondOrder()); bond->setFromAtom(atomMap.value(obBond->GetBeginAtomIdx())); bond->setToAtom(atomMap.value(obBond->GetEndAtomIdx())); m_molecule->addBond(bond); }
void RGroupAssembler::appendMoiety_(AtomContainer* molecule, AtomContainer* moiety, String pm_atom) { AtomContainer* moiety_copy = new AtomContainer; *moiety_copy = *moiety; molecule->insert(*moiety_copy); vector<Atom*> conn_atoms; for (AtomIterator atom_it = molecule->beginAtom(); +atom_it; atom_it++) { if (atom_it->getName() == pm_atom) { // find placemark atom .. conn_atoms.push_back(atom_it->beginBond()->getPartner(*atom_it)); // ... and select placemark atom's partner atom_it->select(); } else atom_it->deselect(); } // remove placemark atoms molecule->removeSelected(); // create bond between both R-atoms Bond* bnd = conn_atoms[0]->createBond(*conn_atoms[1]); bnd->setOrder(1); }
void EditMode::createBond_() { // this functionality shall be independent from the edit mode // check if two atoms are selected HashSet<Composite*> selection = scene_->getMainControl()->getSelection(); // by switching into the edit mode recursive selection // has already cleaned up Atom* first_atom = 0; Atom* second_atom = 0; // case 1: one system with exactly two atoms if (selection.size() == 1) { if (RTTI::isKindOf<AtomContainer>(**selection.begin())) { AtomContainer* ac = reinterpret_cast<AtomContainer*>(*selection.begin()); if (ac->countAtoms() == 2) { AtomIterator atom_it = ac->beginAtom(); for(; +atom_it; ++atom_it) { if (!first_atom) { first_atom = &*atom_it; } else if (!second_atom) { second_atom = &*atom_it; } else { Log.error() << (String)tr("Internal error! Too many atoms selected.") << std::endl; } } } else { scene_->setStatusbarText(tr("Please select exactly two atoms."), true); } } else { scene_->setStatusbarText(tr("Please select exactly two atoms."), true); } } // case 2: two selected atoms with unselected in // either distinct atom containers // or with unselected in the same container else if (selection.size() == 2) { HashSet<Composite*>::Iterator it = selection.begin(); for (; +it; ++it) { if (RTTI::isKindOf<Atom>(**it)) { if (!first_atom) { first_atom = reinterpret_cast<Atom*>(*it); } else if (!second_atom) { second_atom = reinterpret_cast<Atom*>(*it); } } // case 3: a single atom in selected atomcontainer else if (RTTI::isKindOf<AtomContainer>(**it)) { AtomContainer* ac = reinterpret_cast<AtomContainer*>(*it); if (ac->countAtoms() == 1) { if (!first_atom) { first_atom = &*ac->beginAtom(); } else if (!second_atom) { second_atom = &*ac->beginAtom(); } } else { Log.error() << (String)tr("Scene: Internal error! ") << __LINE__ << std::endl; } } } } // we found two atoms if (first_atom && second_atom) { // create a bond Bond* bond = first_atom->createBond(*second_atom); bond->setOrder(Bond::ORDER__SINGLE); //TODO single bond or current edit mode default bond order? // TODO:for undo -operation // EditOperation eo(0, bond, "Added bond of type single" , EditOperation::ADDED__BOND); // undo_.push_back(eo); // // // tell about the new undo operation // emit newEditOperation(eo); // if the bond is between two molecules, merge them scene_->merge(first_atom, second_atom); // update representation scene_->getMainControl()->update(*first_atom, true); scene_->getMainControl()->update(*second_atom, true); scene_->setStatusbarText(tr("Added a bond")); // deselect and delete recursively from the selection set HashSet<Composite*>::Iterator it = selection.begin(); for (; +it; ++it) { if (!(**it).containsSelection()) continue; scene_->getMainControl()->deselectCompositeRecursive(*it, true); scene_->getMainControl()->update(**it, false); } first_atom->deselect(); second_atom->deselect(); // update representation scene_->getMainControl()->update(*first_atom, true); scene_->getMainControl()->update(*second_atom, true); } else { scene_->setStatusbarText(tr("Please select exactly two atoms."), true); } }