Skip to content

Commit

Permalink
#367 change selection of simple objects (#381)
Browse files Browse the repository at this point in the history
* make selection of simple objects based on reference points

* run prettier

* move ReObject to ts

* clean up code

* clean up code

* update copyright year
  • Loading branch information
ensemenova authored Mar 15, 2021
1 parent 6404370 commit 92c1da6
Show file tree
Hide file tree
Showing 16 changed files with 532 additions and 536 deletions.
18 changes: 10 additions & 8 deletions packages/ketcher-react/src/script/editor/tool/helper/locate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2020 EPAM Systems
* 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.
Expand Down Expand Up @@ -71,13 +71,11 @@ function getElementsInRectangle(restruct, p0, p1) {
})

restruct.simpleObjects.forEach((item, id) => {
if (
item.item.pos[0].x > x0 &&
item.item.pos[0].x < x1 &&
item.item.pos[0].y > y0 &&
item.item.pos[0].y < y1
const referencePoints = item.getReferencePoints(true)
const referencePointInRectangle = referencePoints.find(
point => point.x > x0 && point.x < x1 && point.y > y0 && point.y < y1
)
simpleObjectsList.push(id)
if (referencePointInRectangle) simpleObjectsList.push(id)
})

const enhancedFlagList = []
Expand Down Expand Up @@ -144,7 +142,11 @@ function getElementsInPolygon(restruct, rr) {
})

restruct.simpleObjects.forEach((item, id) => {
if (isPointInPolygon(r, item.item.pos[0])) simpleObjectsList.push(id)
const referencePoints = item.getReferencePoints(true)
const referencePointInPolygon = referencePoints.find(point =>
isPointInPolygon(r, point)
)
if (referencePointInPolygon) simpleObjectsList.push(id)
})

const enhancedFlagList = []
Expand Down
76 changes: 76 additions & 0 deletions packages/ketcher-react/src/script/render/restruct/ReObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/****************************************************************************
* 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.
***************************************************************************/

import Visel from './visel'
import { scale } from 'ketcher-core'

class ReObject {
protected visel: Visel
protected highlight: boolean = false
protected highlighting: any
protected selected: boolean = false
protected selectionPlate: any

constructor(viselType: string) {
this.visel = new Visel(viselType)
}

getVBoxObj(render: any): any {
var vbox = this.visel.boundingBox
if (vbox === null) return null
if (render.options.offset)
vbox = vbox.translate(render.options.offset.negated())
return vbox.transform(scale.scaled2obj, render.options)
}

setHighlight(highLight: boolean, render: any): void {
// TODO render should be field
if (highLight) {
let noredraw = 'highlighting' in this && this.highlighting !== null // && !this.highlighting.removed;
if (noredraw) {
if (this.highlighting.type === 'set') {
if (!this.highlighting[0]) return
noredraw = !this.highlighting[0].removed
} else {
noredraw = !this.highlighting.removed
}
}
if (noredraw) {
this.highlighting.show()
} else {
render.paper.setStart()
this.drawHighlight(render)
this.highlighting = render.paper.setFinish()
}
} else if (this.highlighting) {
this.highlighting.hide()
}

this.highlight = highLight
}

// @ts-ignore
drawHighlight(render: any): any {
console.assert(null, 'ReObject.drawHighlight is not overridden') // eslint-disable-line no-console
}

// @ts-ignore
makeSelectionPlate(restruct: any, paper: any, styles: any): any {
console.assert(null, 'ReObject.makeSelectionPlate is not overridden') // eslint-disable-line no-console
}
}

export default ReObject
Loading

0 comments on commit 92c1da6

Please sign in to comment.