Skip to content

Commit

Permalink
Merge branch 'release/2.9' of https://github.com/epam/ketcher into #2427
Browse files Browse the repository at this point in the history
-when-moving-a-structure-outside-of-the-canvas-structure-does-not-move-smoothly
  • Loading branch information
Nitvex committed Apr 10, 2023
2 parents 80fd5c0 + d5c02f8 commit 7d660b7
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Vec2 } from 'domain/entities'
import _ from 'lodash'

const edgeOffset = 150
const scrollMultiplier = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { Box2Abs, Struct, Vec2 } from 'domain/entities'

import Raphael from './raphael-ext'
import { shiftAndExtendCanvasByVector } from './canvasExtension'
import { ReStruct } from './restruct'
import { Scale } from 'domain/helpers'
import defaultOptions from './options'
Expand Down
4 changes: 4 additions & 0 deletions packages/ketcher-react/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
export const KETCHER_INIT_EVENT_NAME = 'ketcher-init'

export const KETCHER_SAVED_SETTINGS_KEY = 'ketcher_editor_saved_settings'

export const MODES = {
FG: 'fg'
}
4 changes: 2 additions & 2 deletions packages/ketcher-react/src/script/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Editor implements KetcherEditor {

const isAtomToolChosen = name === 'atom'
if (!isAtomToolChosen) {
this.hoverIcon.hide()
this.hoverIcon.hide(true)
}

if (!tool || tool.isNotActiveTool) {
Expand Down Expand Up @@ -285,7 +285,7 @@ class Editor implements KetcherEditor {
this.render.clientArea,
Object.assign({ scale: SCALE }, value)
)
this.render.setMolecule(struct) // TODO: reuse this.struct here?
this.struct(struct)
this.render.setZoom(zoom)
this.render.update()
return this.render.options
Expand Down
11 changes: 7 additions & 4 deletions packages/ketcher-react/src/script/editor/HoverIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class HoverIcon {
}

onMouseLeave(event: MouseEvent) {
if (!this.isOverLoader(event)) {
if (!this.isOverLoader(event) && this.isShown) {
this.shouldBeShownWhenMouseBack = true
this.hide()
}
Expand All @@ -86,9 +86,13 @@ export class HoverIcon {
this.shouldBeShownWhenMouseBack = false
}

hide() {
hide(restShouldBeShownWhenMouseBack?: boolean) {
this.element.hide()
this.isShown = false

if (restShouldBeShownWhenMouseBack) {
this.shouldBeShownWhenMouseBack = false
}
}

initialize(): {
Expand All @@ -115,8 +119,7 @@ export class HoverIcon {
this.element = icon.element
this._fill = icon.fill
this._label = icon.label
this.isShown = true
this.shouldBeShownWhenMouseBack = false
this.updatePosition()
this.hide()
}
}
74 changes: 54 additions & 20 deletions packages/ketcher-react/src/script/editor/tool/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import utils from '../shared/utils'
import Editor from '../Editor'
import { getGroupIdsFromItemArrays } from './helper/getGroupIdsFromItems'
import { MODES } from 'ketcher-react/src/constants'

type MergeItems = Record<string, Map<unknown, unknown>> | null

Expand Down Expand Up @@ -77,7 +78,7 @@ class TemplateTool {
}

const bond = frag.bonds.get(this.template.bid)
if (bond && this.mode !== 'fg') {
if (bond && !this.isModeFunctionalGroup) {
// template location sign against attachment bond
this.template.sign = getSign(frag, bond, this.template.xy0)
this.findItems.push('bonds')
Expand All @@ -94,7 +95,21 @@ class TemplateTool {
editor.hoverIcon.updatePosition()
}

mousedown(event) {
showRemoveAbbreviationPopup(): Promise<void> {
return this.editor.event.removeFG
.dispatch({ fgIds: this.targetGroupsIds })
.then(() => {
// case when we remove abbreviation group, click on benzene ring and try to add it
this.targetGroupsIds.length = 0
return Promise.resolve()
})
}

get isModeFunctionalGroup() {
return this.mode === MODES.FG
}

async mousedown(event) {
const closestItem = this.editor.findItem(event, [
'atoms',
'bonds',
Expand All @@ -111,6 +126,7 @@ class TemplateTool {
})

if (
// if point is functional group and it is not expanded
closestItem?.map === 'functionalGroups' &&
FunctionalGroup.isContractedFunctionalGroup(
closestItem.id,
Expand All @@ -121,6 +137,18 @@ class TemplateTool {
}
}

const isTargetExpanded = struct.functionalGroups.get(
this.targetGroupsIds[0]
)?.isExpanded
const isTargetAtomOrBond =
this.targetGroupsIds.length && !this.isModeFunctionalGroup

if (isTargetAtomOrBond || isTargetExpanded) {
await this.showRemoveAbbreviationPopup()

return
}

this.editor.hover(null)

this.dragCtx = {
Expand All @@ -137,7 +165,7 @@ class TemplateTool {
return
}

if (ci.map === 'bonds' && this.mode !== 'fg') {
if (ci.map === 'bonds' && !this.isModeFunctionalGroup) {
// calculate fragment center
const xy0 = new Vec2()
const bond = struct.bonds.get(ci.id)
Expand Down Expand Up @@ -205,7 +233,7 @@ class TemplateTool {
const struct = this.editor.render.ctab.molecule

/* moving when attached to bond */
if (ci && ci.map === 'bonds' && this.mode !== 'fg') {
if (ci && ci.map === 'bonds' && !this.isModeFunctionalGroup) {
const bond = struct.bonds.get(ci.id)
let sign = getSign(struct, bond, eventPos)

Expand Down Expand Up @@ -251,8 +279,9 @@ class TemplateTool {
targetPos = atom?.pp

if (targetPos) {
extraBond =
this.mode === 'fg' ? true : Vec2.dist(targetPos, eventPos) > 1
extraBond = this.isModeFunctionalGroup
? true
: Vec2.dist(targetPos, eventPos) > 1
}
}
}
Expand Down Expand Up @@ -320,7 +349,7 @@ class TemplateTool {

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

if (this.mode !== 'fg') {
if (!this.isModeFunctionalGroup) {
dragCtx.mergeItems = getItemsToFuse(this.editor, pasteItems)
this.editor.hover(getHoverToFuse(dragCtx.mergeItems))
}
Expand All @@ -334,11 +363,6 @@ class TemplateTool {
mouseup(event) {
const dragCtx = this.dragCtx

if (this.targetGroupsIds.length && this.mode !== 'fg') {
this.editor.event.removeFG.dispatch({ fgIds: this.targetGroupsIds })
return
}

if (!dragCtx) {
return true
}
Expand All @@ -351,7 +375,12 @@ class TemplateTool {
const functionalGroups = struct.functionalGroups

/* after moving around bond */
if (dragCtx.action && ci && ci.map === 'bonds' && this.mode !== 'fg') {
if (
dragCtx.action &&
ci &&
ci.map === 'bonds' &&
!this.isModeFunctionalGroup
) {
dragCtx.action.perform(restruct) // revert drag action

const promise = fromTemplateOnBondAction(
Expand Down Expand Up @@ -386,7 +415,7 @@ class TemplateTool {
} else if (
ci?.map === 'functionalGroups' &&
FunctionalGroup.isContractedFunctionalGroup(ci.id, functionalGroups) &&
this.mode === 'fg' &&
this.isModeFunctionalGroup &&
this.targetGroupsIds.length
) {
functionalGroupRemoveAction = new Action()
Expand Down Expand Up @@ -449,7 +478,7 @@ class TemplateTool {
action = functionalGroupRemoveAction.mergeWith(action)
}
dragCtx.action = action
} else if (ci.map === 'bonds' && this.mode !== 'fg') {
} else if (ci.map === 'bonds' && !this.isModeFunctionalGroup) {
const promise = fromTemplateOnBondAction(
restruct,
this.template,
Expand All @@ -460,7 +489,7 @@ class TemplateTool {
) as Promise<any>

promise.then(([action, pasteItems]) => {
if (this.mode !== 'fg') {
if (!this.isModeFunctionalGroup) {
const mergeItems = getItemsToFuse(this.editor, pasteItems)
action = fromItemsFuse(restruct, mergeItems).mergeWith(action)
this.editor.update(action)
Expand All @@ -473,7 +502,7 @@ class TemplateTool {

this.editor.selection(null)

if (!dragCtx.mergeItems && pasteItems && this.mode !== 'fg') {
if (!dragCtx.mergeItems && pasteItems && !this.isModeFunctionalGroup) {
dragCtx.mergeItems = getItemsToFuse(this.editor, pasteItems)
}
dragCtx.action = dragCtx.action
Expand Down Expand Up @@ -516,9 +545,14 @@ function addSaltsAndSolventsOnCanvasWithoutMerge(
}

function getTemplateMode(tmpl) {
if (tmpl.mode) return tmpl.mode
if (['Functional Groups', 'Salts and Solvents'].includes(tmpl.props?.group))
return 'fg'
if (tmpl.mode) {
return tmpl.mode
}

if (['Functional Groups', 'Salts and Solvents'].includes(tmpl.props?.group)) {
return MODES.FG
}

return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
***************************************************************************/

import isHidden from './isHidden'
import { MODES } from 'ketcher-react/src/constants'

const functionalGroupsLib = {
'functional-groups': {
shortcut: 'Shift+f',
// TODO Update HELP about current tools
title: 'Functional Groups',
action: { dialog: 'templates', prop: { tab: 1 } },
selected: (editor) => editor._tool.mode === 'fg',
selected: (editor) => editor._tool.mode === MODES.FG,
disabled: (_, __, options) => {
return !options.app.functionalGroups
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import templatesRawData from '../../../../templates/fg.sdf'
import { memoizedDebounce } from '../../utils'
import { TOOLTIP_DELAY } from '../../../editor/utils/functionalGroupsTooltip'
import { MODES } from 'ketcher-react/src/constants'

interface FGState {
lib: []
Expand All @@ -35,7 +36,7 @@ interface FGState {
const initialState: FGState = {
lib: [],
functionalGroupInfo: null,
mode: 'fg'
mode: MODES.FG
}

const functionalGroupsReducer = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from 'ketcher-core'
import { RenderStruct } from '../../utils'
import templatesRawData from '../../../../templates/salts-and-solvents.sdf'
import { MODES } from 'ketcher-react/src/constants'

interface SaltsAndSolventsState {
lib: []
Expand All @@ -33,7 +34,7 @@ interface SaltsAndSolventsState {

const initialState: SaltsAndSolventsState = {
lib: [],
mode: 'fg'
mode: MODES.FG
}

const saltsAndSolventsReducer = (
Expand Down

0 comments on commit 7d660b7

Please sign in to comment.