Skip to content

Commit

Permalink
#1990 - #2195 merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Permiakov committed Feb 16, 2023
1 parent 69a2568 commit 5d7b2a3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 45 deletions.
41 changes: 39 additions & 2 deletions packages/ketcher-core/src/application/editor/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import { Atom, Vec2 } from 'domain/entities'
import { AtomAdd, BondAdd, CalcImplicitH } from '../operations'
import { atomForNewBond, atomGetAttr, extraBondAction } from './utils'
import { atomForNewBond, atomGetAttr } from './utils'
import { fromAtomsAttrs, mergeSgroups } from './atom'
import { fromBondStereoUpdate, fromBondsAttrs } from './bond'
import { fromBondStereoUpdate, fromBondsAttrs, fromBondAddition } from './bond'

import { Action } from './action'
import closest from '../shared/closest'
Expand All @@ -40,6 +40,43 @@ export function fromTemplateOnCanvas(restruct, template, pos, angle) {
return [action, pasteItems]
}

function extraBondAction(restruct, aid, angle) {
let action = new Action()
const frid = atomGetAttr(restruct, aid, 'fragment')
let additionalAtom: any = null

if (angle === null) {
const middleAtom = atomForNewBond(restruct, aid)
const actionRes = fromBondAddition(
restruct,
{ type: 1 },
aid,
middleAtom.atom,
middleAtom.pos.get_xy0()
)
action = actionRes[0]
action.operations.reverse()
additionalAtom = actionRes[2]
} else {
const operation = new AtomAdd(
{ label: 'C', fragment: frid },
new Vec2(1, 0)
.rotate(angle)
.add(restruct.molecule.atoms.get(aid).pp)
.get_xy0()
).perform(restruct) as AtomAdd

action.addOp(operation)
action.addOp(
new BondAdd(aid, operation.data.aid, { type: 1 }).perform(restruct)
)

additionalAtom = operation.data.aid
}

return { action, aid1: additionalAtom }
}

export function fromTemplateOnAtom(restruct, template, aid, angle, extraBond) {
let action = new Action()

Expand Down
38 changes: 0 additions & 38 deletions packages/ketcher-core/src/application/editor/actions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { Bond, Vec2 } from 'domain/entities'

import closest from '../shared/closest'
import { difference } from 'lodash'
import { Action, AtomAdd, BondAdd, fromBondAddition } from 'application/editor'

export function atomGetAttr(restruct, aid, name) {
return restruct.molecule.atoms.get(aid)[name]
Expand Down Expand Up @@ -199,40 +198,3 @@ export function isAttachmentBond({ begin, end }: Bond, selection): boolean {
isBondEndsInSelectionAndStartsOutside
)
}

export function extraBondAction(restruct, aid, angle) {
let action = new Action()
const frid = atomGetAttr(restruct, aid, 'fragment')
let additionalAtom: any = null

if (angle === null) {
const middleAtom = atomForNewBond(restruct, aid)
const actionRes = fromBondAddition(
restruct,
{ type: 1 },
aid,
middleAtom.atom,
middleAtom.pos.get_xy0()
)
action = actionRes[0]
action.operations.reverse()
additionalAtom = actionRes[2]
} else {
const operation = new AtomAdd(
{ label: 'C', fragment: frid },
new Vec2(1, 0)
.rotate(angle)
.add(restruct.molecule.atoms.get(aid).pp)
.get_xy0()
).perform(restruct) as AtomAdd

action.addOp(operation)
action.addOp(
new BondAdd(aid, operation.data.aid, { type: 1 }).perform(restruct)
)

additionalAtom = operation.data.aid
}

return { action, aid1: additionalAtom }
}
Empty file.
12 changes: 7 additions & 5 deletions packages/ketcher-react/src/script/editor/tool/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ class TemplateTool {
findItems: Array<string>
dragCtx: any
targetGroupsIds: Array<number> = []
isSaltOrSolvant: boolean

constructor(editor, tmpl) {
this.editor = editor
this.mode = getTemplateMode(tmpl)
this.editor.selection(null)
this.isSaltOrSolvant = SGroup.isSaltOrSolvent(tmpl.struct.name)

this.template = {
aid: parseInt(tmpl.aid) || 0,
Expand All @@ -62,7 +64,6 @@ class TemplateTool {
this.template.molecule = frag // preloaded struct
this.findItems = []
this.template.xy0 = xy0.scaled(1 / (frag.atoms.size || 1)) // template center
this.findItems.push('functionalGroups')

const atom = frag.atoms.get(this.template.aid)
if (atom) {
Expand Down Expand Up @@ -120,7 +121,7 @@ class TemplateTool {
const dragCtx = this.dragCtx
const ci = dragCtx.item

if (!ci) {
if (!ci || this.isSaltOrSolvant) {
// ci.type == 'Canvas'
delete dragCtx.item
return
Expand Down Expand Up @@ -311,7 +312,7 @@ class TemplateTool {
mouseup(event) {
const dragCtx = this.dragCtx

if (this.targetGroupsIds.length) {
if (this.targetGroupsIds.length && this.mode !== 'fg') {
this.editor.event.removeFG.dispatch({ fgIds: this.targetGroupsIds })
return
}
Expand Down Expand Up @@ -354,7 +355,7 @@ class TemplateTool {
let pasteItems = null
let isFunctionalGroupReplace = false

if (SGroup.isSaltOrSolvent(this.template.molecule.name)) {
if (this.isSaltOrSolvant) {
addSaltsAndSolventsOnCanvasWithoutMerge(
restruct,
this.template,
Expand All @@ -365,7 +366,8 @@ class TemplateTool {
} else if (
ci?.map === 'functionalGroups' &&
FunctionalGroup.isContractedFunctionalGroup(ci.id, functionalGroups) &&
this.mode === 'fg'
this.mode === 'fg' &&
this.targetGroupsIds.length
) {
const sGroup = sgroups.get(ci.id)
this.editor.update(
Expand Down

0 comments on commit 5d7b2a3

Please sign in to comment.