Skip to content

Commit

Permalink
#2517 Incorrect rendering of superatom with multiple connection points (
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaPlyako authored May 17, 2023
1 parent 191065b commit 189c5ab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
25 changes: 24 additions & 1 deletion packages/ketcher-core/src/application/editor/actions/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
SGroupDelete,
SGroupRemoveFromHierarchy
} from '../operations'
import { Pile, SGroup } from 'domain/entities'
import { FunctionalGroup, Pile, SGroup } from 'domain/entities'
import { atomGetAttr, atomGetDegree, atomGetSGroups } from './utils'

import { Action } from './action'
Expand Down Expand Up @@ -91,6 +91,29 @@ export function setExpandSGroup(restruct, sgid, attrs) {
return action.perform(restruct)
}

// todo delete after supporting expand - collapse for 2 attachment points
export function expandSGroupWithMultipleAttachmentPoint(restruct) {
const action = new Action()

const struct = restruct.molecule

struct.sgroups.forEach((sgroup) => {
const countAttachmentPoint = FunctionalGroup.getAttachmentPointCount(
sgroup,
struct
)
if (countAttachmentPoint > 1) {
action.mergeWith(
setExpandSGroup(restruct, sgroup.id, {
expanded: true
})
)
}
})

return action
}

export function sGroupAttributeAction(id, attrs) {
const action = new Action()

Expand Down
20 changes: 5 additions & 15 deletions packages/ketcher-react/src/script/editor/tool/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
***************************************************************************/

import {
expandSGroupWithMultipleAttachmentPoint,
fromItemsFuse,
fromPaste,
fromTemplateOnAtom,
FunctionalGroup,
getHoverToFuse,
getItemsToFuse,
setExpandSGroup,
SGroup,
Struct,
Vec2
Expand Down Expand Up @@ -62,20 +62,10 @@ class PasteTool {
this.action = action
this.editor.update(this.action, true)

// todo delete after supporting expand - collapse for 2 attachment points
struct.sgroups.forEach((sgroup) => {
const countAttachmentPoint = FunctionalGroup.getAttachmentPointCount(
sgroup,
this.editor.render.ctab.molecule
)
if (countAttachmentPoint > 1) {
action.mergeWith(
setExpandSGroup(this.editor.render.ctab, sgroup.id, {
expanded: true
})
)
}
})
action.mergeWith(
expandSGroupWithMultipleAttachmentPoint(this.editor.render.ctab)
)

this.editor.update(this.action, true)

this.findItems = ['functionalGroups']
Expand Down
5 changes: 4 additions & 1 deletion packages/ketcher-react/src/script/editor/tool/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
fromSgroupDeletion,
FunctionalGroup,
SGroup,
Pool
Pool,
expandSGroupWithMultipleAttachmentPoint
} from 'ketcher-core'

import LassoHelper from './helper/lasso'
Expand Down Expand Up @@ -512,6 +513,8 @@ class SGroupTool {
newSg.attrs
).mergeWith(fromSgroupDeletion(restruct, id))

action.mergeWith(expandSGroupWithMultipleAttachmentPoint(restruct))

editor.update(action)
editor.selection(selection)
return
Expand Down

0 comments on commit 189c5ab

Please sign in to comment.