From 5016dee78a2b8d7f830d877bc7f313e26d340a33 Mon Sep 17 00:00:00 2001 From: Tim Alyakin <31693137+TimSPb89@users.noreply.github.com> Date: Fri, 3 Feb 2023 12:58:13 +0300 Subject: [PATCH] #2033: Abbreviations: Atoms protrude beyond the expanded view (#2125) * #2033 - Abbreviations: Atoms protrude beyond the expanded view for Functional Groups and Salts and Solvents * #2033 - review fixes * #2033 - review fix (replaced in with instanceof check) * Revert "#2033 - review fix (replaced in with instanceof check)" to fix the build failure This reverts commit 3b983e8a878d82312aa49915c19caa9acc5b1c51. --- .../application/render/restruct/resgroup.js | 2 +- .../src/domain/entities/sgroup.ts | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/ketcher-core/src/application/render/restruct/resgroup.js b/packages/ketcher-core/src/application/render/restruct/resgroup.js index 90468749d6..9483ee13cf 100644 --- a/packages/ketcher-core/src/application/render/restruct/resgroup.js +++ b/packages/ketcher-core/src/application/render/restruct/resgroup.js @@ -40,7 +40,7 @@ class ReSGroup extends ReObject { let set = this.render.paper.set() const atomSet = new Pile(sgroup.atoms) const crossBonds = SGroup.getCrossBonds(remol.molecule, atomSet) - SGroup.bracketPos(sgroup, remol.molecule, crossBonds) + SGroup.bracketPos(sgroup, remol.molecule, crossBonds, remol, this.render) const bracketBox = sgroup.bracketBox const d = sgroup.bracketDir sgroup.areas = [bracketBox] diff --git a/packages/ketcher-core/src/domain/entities/sgroup.ts b/packages/ketcher-core/src/domain/entities/sgroup.ts index cfd39b0a0a..7d3d90ecee 100644 --- a/packages/ketcher-core/src/domain/entities/sgroup.ts +++ b/packages/ketcher-core/src/domain/entities/sgroup.ts @@ -21,6 +21,7 @@ import { Pile } from './pile' import { Struct } from './struct' import { SaltsAndSolventsProvider } from '../helpers' import { Vec2 } from './vec2' +import { ReStruct } from '../../application/render' export class SGroupBracketParams { readonly c: Vec2 @@ -335,7 +336,9 @@ export class SGroup { static bracketPos( sGroup, mol, - crossBondsPerAtom: { [key: number]: Array } + crossBondsPerAtom: { [key: number]: Array }, + remol?: ReStruct, + render? ): void { const atoms = sGroup.atoms const crossBonds = crossBondsPerAtom @@ -352,12 +355,24 @@ export class SGroup { let braketBox: Box2Abs | null = null const contentBoxes: Array = [] + const getAtom = (aid) => { + if (remol && render) { + return remol.atoms.get(aid) + } + return mol.atoms.get(aid) + } atoms.forEach((aid) => { - const atom = mol.atoms.get(aid) - const pos = new Vec2(atom.pp) + const atom = getAtom(aid) const ext = new Vec2(0.05 * 3, 0.05 * 3) - const bba = new Box2Abs(pos, pos).extend(ext, ext) - contentBoxes.push(bba) + let position + let structBoundingBox + if ('getVBoxObj' in atom && render) { + structBoundingBox = atom.getVBoxObj(render) + } else { + position = new Vec2(atom.pp) + structBoundingBox = new Box2Abs(position, position) + } + contentBoxes.push(structBoundingBox.extend(ext, ext)) }) contentBoxes.forEach((bba) => { let bbb: Box2Abs | null = null