-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into #1954-draw-selected-structure-at-mouse-cur…
…sor-as-pasting-does
- Loading branch information
Showing
11 changed files
with
227 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Bond, ReBond, ReStruct } from 'ketcher-core' | ||
|
||
export function isFlipDisabled(editor): boolean { | ||
const selection: { atoms: number[]; bonds: number[] } = editor.selection() | ||
const restruct: ReStruct = editor.render.ctab | ||
|
||
if (!selection) { | ||
return false | ||
} | ||
|
||
const { bonds = [], atoms = [] } = selection | ||
const isAttachmentBond = ({ begin, end }: Bond): boolean => | ||
(selection.atoms.includes(begin) && !selection.atoms.includes(end)) || | ||
(selection.atoms.includes(end) && !selection.atoms.includes(begin)) | ||
const getBondIdsForAtom = (atomId: number) => { | ||
const result: number[] = [] | ||
for (const [bondId, bond] of restruct.bonds.entries()) { | ||
if (bond.b.begin === atomId || bond.b.end === atomId) { | ||
result.push(bondId) | ||
} | ||
} | ||
return result | ||
} | ||
const getBondIdsForAttachmentAtoms = () => { | ||
const result: number[] = [] | ||
for (const atomId of atoms) { | ||
const atomBondIds = getBondIdsForAtom(atomId) | ||
for (const atomBondId of atomBondIds) { | ||
const bond: ReBond | undefined = restruct.bonds.get(atomBondId) | ||
if (bond && isAttachmentBond(bond.b)) { | ||
result.push(atomBondId) | ||
} | ||
} | ||
} | ||
return result | ||
} | ||
const getAmountOfAttachmentBonds = (): number => { | ||
let amountOfAttachmentBonds = 0 | ||
const totalBondIds = new Set([...bonds, ...getBondIdsForAttachmentAtoms()]) | ||
for (const bondId of totalBondIds) { | ||
const bond: ReBond | undefined = restruct.bonds.get(bondId) | ||
if (bond && isAttachmentBond(bond.b)) { | ||
amountOfAttachmentBonds++ | ||
} | ||
} | ||
|
||
return amountOfAttachmentBonds | ||
} | ||
|
||
return getAmountOfAttachmentBonds() > 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.