From 3a93328a2f912759b236ef2335d01af58507eef7 Mon Sep 17 00:00:00 2001 From: KonstantinEpam23 <101649391+KonstantinEpam23@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:22:01 +0100 Subject: [PATCH] Revert "#2257 - Unable add a bond to a Function Group (#2261)" This reverts commit 282dd6646c7c80bb943aa9c887b7772a0134c886. --- .../src/application/editor/actions/bond.ts | 9 +++--- .../src/script/editor/tool/bond.ts | 14 ++------ .../src/script/editor/tool/chain.ts | 32 +++---------------- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/packages/ketcher-core/src/application/editor/actions/bond.ts b/packages/ketcher-core/src/application/editor/actions/bond.ts index c2bf427804..5e0baea972 100644 --- a/packages/ketcher-core/src/application/editor/actions/bond.ts +++ b/packages/ketcher-core/src/application/editor/actions/bond.ts @@ -36,7 +36,8 @@ import { atomForNewBond, atomGetAttr } from './utils' import { fromAtomMerge, fromStereoAtomAttrs, - mergeFragmentsIfNeeded + mergeFragmentsIfNeeded, + mergeSgroups } from './atom' import { Action } from './action' @@ -80,8 +81,7 @@ export function fromBondAddition( begin.fragment = frid begin = (action.addOp(new AtomAdd(begin, pos).perform(restruct)) as AtomAdd) .data.aid - if (typeof end === 'number') - mergeFragmentsIfNeeded(action, restruct, begin, end) + if (typeof end === 'number') mergeSgroups(action, restruct, [begin], end) pos = pos2 } else if (atomGetAttr(restruct, begin, 'label') === '*') { action.addOp(new AtomAttr(begin, 'label', 'C').perform(restruct)) @@ -92,8 +92,7 @@ export function fromBondAddition( // TODO: .data.aid here is a hack, need a better way to access the id of a created atom end = (action.addOp(new AtomAdd(end, pos).perform(restruct)) as AtomAdd) .data.aid - if (typeof begin === 'number') - mergeFragmentsIfNeeded(action, restruct, end, begin) + if (typeof begin === 'number') mergeSgroups(action, restruct, [end], begin) } else if (atomGetAttr(restruct, end, 'label') === '*') { action.addOp(new AtomAttr(end, 'label', 'C').perform(restruct)) } diff --git a/packages/ketcher-react/src/script/editor/tool/bond.ts b/packages/ketcher-react/src/script/editor/tool/bond.ts index efeaf75caa..042f52fe27 100644 --- a/packages/ketcher-react/src/script/editor/tool/bond.ts +++ b/packages/ketcher-react/src/script/editor/tool/bond.ts @@ -57,8 +57,7 @@ class BondTool { const struct = this.editor.render.ctab const molecule = struct.molecule const functionalGroups = molecule.functionalGroups - const itemsToFind = ['atoms', 'bonds', 'functionalGroups'] - const ci = this.editor.findItem(event, itemsToFind) + const ci = this.editor.findItem(event, ['atoms', 'bonds']) const atomResult: Array = [] const bondResult: Array = [] const result: Array = [] @@ -108,7 +107,7 @@ class BondTool { this.editor.selection(null) this.dragCtx = { xy0: rnd.page2obj(event), - item: ci + item: this.editor.findItem(event, ['atoms', 'bonds']) } if (!this.dragCtx.item) // ci.type == 'Canvas' @@ -317,15 +316,6 @@ class BondTool { this.editor.update( bondChangingAction(rnd.ctab, dragCtx.item.id, bond, bondProps) ) - } else if (dragCtx.item.map === 'functionalGroups') { - const groupId = dragCtx.item.id - const group = struct.sgroups.get(groupId) - const attAtomId = group?.getAttAtomId(struct) - - this.editor.update( - fromBondAddition(rnd.ctab, this.bondProps, attAtomId, undefined)[0] - ) - delete this.dragCtx.existedBond } delete this.dragCtx } diff --git a/packages/ketcher-react/src/script/editor/tool/chain.ts b/packages/ketcher-react/src/script/editor/tool/chain.ts index 17af6839c8..e9f4965615 100644 --- a/packages/ketcher-react/src/script/editor/tool/chain.ts +++ b/packages/ketcher-react/src/script/editor/tool/chain.ts @@ -22,8 +22,7 @@ import { fromItemsFuse, getHoverToFuse, getItemsToFuse, - FunctionalGroup, - Struct + FunctionalGroup } from 'ketcher-core' import { atomLongtapEvent } from './atom' @@ -45,9 +44,7 @@ class ChainTool { const molecule = struct.molecule const functionalGroups = molecule.functionalGroups const rnd = this.editor.render - - const itemsToFind = ['atoms', 'bonds', 'functionalGroups'] - const ci = this.editor.findItem(event, itemsToFind) + const ci = this.editor.findItem(event, ['atoms', 'bonds']) const atomResult: Array = [] const bondResult: Array = [] const result: Array = [] @@ -138,19 +135,14 @@ class ChainTool { editor.selection(null) - if ( - !dragCtx.item || - ['atoms', 'functionalGroups'].includes(dragCtx.item.map) - ) { + if (!dragCtx.item || dragCtx.item.map === 'atoms') { if (dragCtx.action) { dragCtx.action.perform(restruct) } - const atomId = getTargetAtomId(dragCtx.item, this.editor.struct()) - const atoms = restruct.molecule.atoms - const pos0 = atomId !== null ? atoms.get(atomId)?.pp : dragCtx.xy0 + const pos0 = dragCtx.item ? atoms.get(dragCtx.item.id)?.pp : dragCtx.xy0 const pos1 = editor.render.page2obj(event) const sectCount = Math.ceil(Vec2.diff(pos1, pos0).length()) @@ -164,7 +156,7 @@ class ChainTool { pos0, angle, sectCount, - atomId !== null ? atomId : null + dragCtx.item ? dragCtx.item.id : null ) editor.event.message.dispatch({ @@ -269,18 +261,4 @@ class ChainTool { } } -function getTargetAtomId( - closestItem: { id: number; map: string }, - struct: Struct -): number | null { - const { id, map } = closestItem - if (map === 'atoms') return id - if (map === 'functionalGroups') { - const sgroup = struct.sgroups.get(id) - const atomId = sgroup?.getAttAtomId(struct) - return atomId !== undefined ? atomId : null - } - return null -} - export default ChainTool