Skip to content

Commit

Permalink
Block several tools for FGs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Kapytov authored and Kirill Kapytov committed Oct 18, 2021
1 parent 2d1dcd4 commit 3eca8a4
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/apoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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'])
Expand Down
5 changes: 5 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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'])
Expand Down
7 changes: 7 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/bond.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
***************************************************************************/

import { Bond, Vec2 } from 'ketcher-core'
import { offFunctionsToFG } from './offFunctionsToFG'
import {
fromItemsFuse,
getHoverToFuse,
Expand All @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@

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)

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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/eraser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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',
Expand All @@ -52,19 +55,25 @@ 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'
this.lassoHelper.begin(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

Expand All @@ -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)

Expand Down
52 changes: 52 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/offFunctionsToFG.ts
Original file line number Diff line number Diff line change
@@ -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 }
5 changes: 5 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/rgroupatom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -26,13 +27,17 @@ function RGroupAtomTool(editor) {
}

this.editor = editor
this.sgroups = editor.render.ctab.sgroups
this.functionalGroups = editor.render.ctab.molecule.functionalGroups
}

RGroupAtomTool.prototype.mousemove = function (event) {
this.editor.hover(this.editor.findItem(event, ['atoms']))
}

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'])

Expand Down
7 changes: 7 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -44,13 +45,17 @@ 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
this.editor.selection(null)
}

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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3eca8a4

Please sign in to comment.