From 3eca8a44a0de7c2bb943f39141c8edc1d15c923f Mon Sep 17 00:00:00 2001 From: Kirill Kapytov Date: Mon, 18 Oct 2021 11:22:24 +0300 Subject: [PATCH] Block several tools for FGs --- .../src/script/editor/tool/apoint.js | 5 ++ .../src/script/editor/tool/atom.js | 5 ++ .../src/script/editor/tool/bond.js | 7 +++ .../src/script/editor/tool/chain.js | 7 +++ .../src/script/editor/tool/charge.js | 7 +++ .../src/script/editor/tool/eraser.js | 11 ++++ .../script/editor/tool/offFunctionsToFG.ts | 52 +++++++++++++++++++ .../src/script/editor/tool/rgroupatom.js | 5 ++ .../src/script/editor/tool/rotate.js | 7 +++ .../src/script/editor/tool/select.js | 5 ++ .../src/script/editor/tool/template.js | 6 +++ 11 files changed, 117 insertions(+) create mode 100644 packages/ketcher-react/src/script/editor/tool/offFunctionsToFG.ts diff --git a/packages/ketcher-react/src/script/editor/tool/apoint.js b/packages/ketcher-react/src/script/editor/tool/apoint.js index c3363eb8de..85048aec28 100644 --- a/packages/ketcher-react/src/script/editor/tool/apoint.js +++ b/packages/ketcher-react/src/script/editor/tool/apoint.js @@ -15,11 +15,14 @@ ***************************************************************************/ import { fromAtomsAttrs } from '../actions/atom' +import { offFunctionsToFG } from './offFunctionsToFG' function APointTool(editor) { if (!(this instanceof APointTool)) return new APointTool(editor) this.editor = editor + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups this.editor.selection(null) } @@ -28,6 +31,8 @@ APointTool.prototype.mousemove = function (event) { } APointTool.prototype.click = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return var editor = this.editor var struct = editor.render.ctab.molecule var ci = editor.findItem(event, ['atoms']) diff --git a/packages/ketcher-react/src/script/editor/tool/atom.js b/packages/ketcher-react/src/script/editor/tool/atom.js index d925c52939..e00874dd83 100644 --- a/packages/ketcher-react/src/script/editor/tool/atom.js +++ b/packages/ketcher-react/src/script/editor/tool/atom.js @@ -19,6 +19,7 @@ import { fromAtomAddition, fromAtomsAttrs } from '../actions/atom' import { fromBondAddition } from '../actions/bond' import utils from '../shared/utils' +import { offFunctionsToFG } from './offFunctionsToFG' function AtomTool(editor, atomProps) { if (!(this instanceof AtomTool)) { @@ -39,9 +40,13 @@ function AtomTool(editor, atomProps) { this.editor = editor this.atomProps = atomProps this.bondProps = { type: 1, stereo: Bond.PATTERN.STEREO.NONE } + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups } AtomTool.prototype.mousedown = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return this.editor.hover(null) this.editor.selection(null) const ci = this.editor.findItem(event, ['atoms']) diff --git a/packages/ketcher-react/src/script/editor/tool/bond.js b/packages/ketcher-react/src/script/editor/tool/bond.js index 998dd2db2d..594701a1e6 100644 --- a/packages/ketcher-react/src/script/editor/tool/bond.js +++ b/packages/ketcher-react/src/script/editor/tool/bond.js @@ -22,6 +22,7 @@ import { } from '../actions/bond' import utils from '../shared/utils' +import { offFunctionsToFG } from './offFunctionsToFG' function BondTool(editor, bondProps) { if (!(this instanceof BondTool)) { @@ -41,9 +42,13 @@ function BondTool(editor, bondProps) { this.editor = editor this.atomProps = { label: 'C' } this.bondProps = bondProps + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups } BondTool.prototype.mousedown = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return const rnd = this.editor.render this.editor.hover(null) this.editor.selection(null) @@ -125,6 +130,8 @@ BondTool.prototype.mousemove = function (event) { } BondTool.prototype.mouseup = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return // eslint-disable-line max-statements if ('dragCtx' in this) { var dragCtx = this.dragCtx diff --git a/packages/ketcher-react/src/script/editor/tool/chain.js b/packages/ketcher-react/src/script/editor/tool/chain.js index bdfb7acabc..92077e7727 100644 --- a/packages/ketcher-react/src/script/editor/tool/chain.js +++ b/packages/ketcher-react/src/script/editor/tool/chain.js @@ -15,6 +15,7 @@ ***************************************************************************/ import { Bond, Vec2 } from 'ketcher-core' +import { offFunctionsToFG } from './offFunctionsToFG' import { fromItemsFuse, getHoverToFuse, @@ -31,11 +32,17 @@ function ChainTool(editor) { this.editor = editor this.editor.selection(null) + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups } ChainTool.prototype.mousedown = function (event) { const rnd = this.editor.render const ci = this.editor.findItem(event, ['atoms', 'bonds']) + + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return + this.editor.hover(null) this.dragCtx = { xy0: rnd.page2obj(event), diff --git a/packages/ketcher-react/src/script/editor/tool/charge.js b/packages/ketcher-react/src/script/editor/tool/charge.js index bd97267c39..08b8386773 100644 --- a/packages/ketcher-react/src/script/editor/tool/charge.js +++ b/packages/ketcher-react/src/script/editor/tool/charge.js @@ -16,6 +16,7 @@ import { Elements } from 'ketcher-core' import { fromAtomsAttrs } from '../actions/atom' +import { offFunctionsToFG } from './offFunctionsToFG' function ChargeTool(editor, charge) { if (!(this instanceof ChargeTool)) return new ChargeTool(editor, charge) @@ -23,9 +24,13 @@ function ChargeTool(editor, charge) { this.editor = editor this.editor.selection(null) this.charge = charge + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups } ChargeTool.prototype.mousemove = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return var rnd = this.editor.render var ci = this.editor.findItem(event, ['atoms']) var struct = rnd.ctab.molecule @@ -36,6 +41,8 @@ ChargeTool.prototype.mousemove = function (event) { } ChargeTool.prototype.click = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return var editor = this.editor var rnd = editor.render var struct = rnd.ctab.molecule diff --git a/packages/ketcher-react/src/script/editor/tool/eraser.js b/packages/ketcher-react/src/script/editor/tool/eraser.js index e6d6b6d67c..bf2adb90be 100644 --- a/packages/ketcher-react/src/script/editor/tool/eraser.js +++ b/packages/ketcher-react/src/script/editor/tool/eraser.js @@ -25,6 +25,7 @@ import LassoHelper from './helper/lasso' import { fromSgroupDeletion } from '../actions/sgroup' import { fromSimpleObjectDeletion } from '../actions/simpleobject' import { fromTextDeletion } from '../actions/text' +import { offFunctionsToFG } from './offFunctionsToFG' function EraserTool(editor, mode) { if (!(this instanceof EraserTool)) { @@ -37,6 +38,8 @@ function EraserTool(editor, mode) { } this.editor = editor + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups this.maps = [ 'atoms', @@ -52,6 +55,8 @@ function EraserTool(editor, mode) { } EraserTool.prototype.mousedown = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return const ci = this.editor.findItem(event, this.maps) if (!ci) // ci.type == 'Canvas' @@ -59,12 +64,16 @@ EraserTool.prototype.mousedown = function (event) { } EraserTool.prototype.mousemove = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return if (this.lassoHelper.running()) this.editor.selection(this.lassoHelper.addPoint(event)) else this.editor.hover(this.editor.findItem(event, this.maps)) } EraserTool.prototype.mouseup = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return // eslint-disable-line max-statements const rnd = this.editor.render @@ -78,6 +87,8 @@ EraserTool.prototype.mouseup = function (event) { } EraserTool.prototype.click = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return const restruct = this.editor.render.ctab const ci = this.editor.findItem(event, this.maps) diff --git a/packages/ketcher-react/src/script/editor/tool/offFunctionsToFG.ts b/packages/ketcher-react/src/script/editor/tool/offFunctionsToFG.ts new file mode 100644 index 0000000000..c8439e8051 --- /dev/null +++ b/packages/ketcher-react/src/script/editor/tool/offFunctionsToFG.ts @@ -0,0 +1,52 @@ +/**************************************************************************** + * Copyright 2021 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +function offFunctionsToFG(editor, functionalGroups, sgroups, event) { + const ci = editor.findItem(event, ['atoms', 'bonds']) + if (functionalGroups.size > 0 && ci && ci.map) { + switch (ci.map) { + case 'atoms': + for (let sg of sgroups.values()) { + if (sg.item.atoms.includes(ci.id)) { + for (let fg of functionalGroups.values()) { + if (sg.item.id === fg.relatedSGroupId + 1) { + return true + } + } + } + } + break + case 'bonds': + const bond = editor.render.ctab.bonds.get(ci.id) + for (let sgs of sgroups.values()) { + if ( + sgs.item.atoms.includes(bond.b.begin) && + sgs.item.atoms.includes(bond.b.end) + ) { + for (let fg of functionalGroups.values()) { + if (sgs.item.id === fg.relatedSGroupId + 1) { + return true + } + } + } + } + break + } + } + return false +} + +export { offFunctionsToFG } diff --git a/packages/ketcher-react/src/script/editor/tool/rgroupatom.js b/packages/ketcher-react/src/script/editor/tool/rgroupatom.js index 7a2dcf2280..0448a05678 100644 --- a/packages/ketcher-react/src/script/editor/tool/rgroupatom.js +++ b/packages/ketcher-react/src/script/editor/tool/rgroupatom.js @@ -17,6 +17,7 @@ import { fromAtomAddition, fromAtomsAttrs } from '../actions/atom' import { Atom } from 'ketcher-core' +import { offFunctionsToFG } from './offFunctionsToFG' function RGroupAtomTool(editor) { if (!(this instanceof RGroupAtomTool)) { @@ -26,6 +27,8 @@ function RGroupAtomTool(editor) { } this.editor = editor + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups } RGroupAtomTool.prototype.mousemove = function (event) { @@ -33,6 +36,8 @@ RGroupAtomTool.prototype.mousemove = function (event) { } RGroupAtomTool.prototype.click = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return const rnd = this.editor.render const ci = this.editor.findItem(event, ['atoms']) diff --git a/packages/ketcher-react/src/script/editor/tool/rotate.js b/packages/ketcher-react/src/script/editor/tool/rotate.js index c4ae1afa74..1fb1c333cb 100644 --- a/packages/ketcher-react/src/script/editor/tool/rotate.js +++ b/packages/ketcher-react/src/script/editor/tool/rotate.js @@ -23,6 +23,7 @@ import { import { Vec2 } from 'ketcher-core' import utils from '../shared/utils' +import { offFunctionsToFG } from './offFunctionsToFG' function RotateTool(editor, dir) { if (!(this instanceof RotateTool)) { @@ -44,6 +45,8 @@ function RotateTool(editor, dir) { } this.editor = editor + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups if (!editor.selection() || !editor.selection().atoms) // otherwise, clear selection @@ -51,6 +54,8 @@ function RotateTool(editor, dir) { } RotateTool.prototype.mousedown = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return var xy0 = new Vec2() var selection = this.editor.selection() var rnd = this.editor.render @@ -117,6 +122,8 @@ RotateTool.prototype.mousedown = function (event) { } RotateTool.prototype.mousemove = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return // eslint-disable-line max-statements if (!this.dragCtx) return true diff --git a/packages/ketcher-react/src/script/editor/tool/select.js b/packages/ketcher-react/src/script/editor/tool/select.js index 58cb49f929..23eb927daf 100644 --- a/packages/ketcher-react/src/script/editor/tool/select.js +++ b/packages/ketcher-react/src/script/editor/tool/select.js @@ -31,11 +31,14 @@ import { fromMultipleMove } from '../actions/fragment' import { sgroupDialog } from './sgroup' import utils from '../shared/utils' import { xor } from 'lodash/fp' +import { offFunctionsToFG } from './offFunctionsToFG' function SelectTool(editor, mode) { if (!(this instanceof SelectTool)) return new SelectTool(editor, mode) this.editor = editor + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups this.lassoHelper = new LassoHelper( mode === 'lasso' ? 0 : 1, editor, @@ -44,6 +47,8 @@ function SelectTool(editor, mode) { } SelectTool.prototype.mousedown = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return // eslint-disable-line max-statements const rnd = this.editor.render const ctab = rnd.ctab diff --git a/packages/ketcher-react/src/script/editor/tool/template.js b/packages/ketcher-react/src/script/editor/tool/template.js index 4a4673a076..7bdbc71b63 100644 --- a/packages/ketcher-react/src/script/editor/tool/template.js +++ b/packages/ketcher-react/src/script/editor/tool/template.js @@ -27,12 +27,16 @@ import { import { Vec2 } from 'ketcher-core' import utils from '../shared/utils' +import { offFunctionsToFG } from './offFunctionsToFG' function TemplateTool(editor, tmpl) { // eslint-disable-line max-statements if (!(this instanceof TemplateTool)) return new TemplateTool(editor, tmpl) this.editor = editor + this.mode = tmpl.mode + this.sgroups = editor.render.ctab.sgroups + this.functionalGroups = editor.render.ctab.molecule.functionalGroups this.editor.selection(null) this.template = { @@ -67,6 +71,8 @@ function TemplateTool(editor, tmpl) { } TemplateTool.prototype.mousedown = function (event) { + if (offFunctionsToFG(this.editor, this.functionalGroups, this.sgroups, event)) + return // eslint-disable-line max-statements const editor = this.editor const restruct = editor.render.ctab