Skip to content

Commit

Permalink
#225 – fixed unselect for bonds and atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex committed Apr 12, 2023
1 parent 3876bd0 commit 376182d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
13 changes: 12 additions & 1 deletion packages/ketcher-core/src/application/render/restruct/reatom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class ReAtom extends ReObject {
color: string
component: number
label?: ElemAttr
cip?: {
// Raphael paths
path: any
text: any
rectangle: any
}

constructor(atom: Atom) {
super('atom')
Expand Down Expand Up @@ -404,7 +410,12 @@ class ReAtom extends ReObject {
}

if (atom.cip) {
util.drawCIPLabel(atom, atom.pp, render.ctab, this.visel)
this.cip = util.drawCIPLabel({
atomOrBond: atom,
position: atom.pp,
restruct: render.ctab,
visel: this.visel
})
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion packages/ketcher-core/src/application/render/restruct/rebond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class ReBond extends ReObject {
neihbid2 = -1
boldStereo?: boolean
rbb?: { x: number; y: number; width: number; height: number }
cip?: {
// Raphael paths
path: any
text: any
rectangle: any
}

constructor(bond: Bond) {
super('bond')
Expand Down Expand Up @@ -248,7 +254,12 @@ class ReBond extends ReObject {
}

if (bond.cip) {
util.drawCIPLabel(bond, bond.center, render.ctab, this.visel)
this.cip = util.drawCIPLabel({
atomOrBond: bond,
position: bond.center,
restruct: render.ctab,
visel: this.visel
})
}

this.path.toBack()
Expand Down
14 changes: 12 additions & 2 deletions packages/ketcher-core/src/application/render/restruct/restruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,19 @@ class ReStruct {
item.selectionPlate
)
}
if (item.selectionPlate) item.selectionPlate.show() // TODO [RB] review
if (item.selectionPlate) {
item.selectionPlate.show()
item.cip?.rectangle.attr({
fill: '#7f7',
stroke: '#7f7'
})
}
} else if (exists && item.selectionPlate) {
item.selectionPlate.hide() // TODO [RB] review
item.selectionPlate.hide()
item.cip?.rectangle.attr({
fill: '#fff',
stroke: '#fff'
})
}
}
}
Expand Down
34 changes: 22 additions & 12 deletions packages/ketcher-core/src/application/render/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,28 @@ function getCIPValuePath({
const path = paper.set()
const rect = paper
.rect(box.x - 1, box.y - 1, box.width + 2, box.height + 2, 3, 3)
.attr({ fill: '#fff', stroke: '#fff', opacity: 1 })
.attr({ fill: '#fff', stroke: '#fff' })
path.push(rect.toFront(), text.toFront())

return path
return {
path,
text,
rectangle: rect
}
}

function drawCIPLabel(
atomOrBond: Bond | Atom,
position: Vec2,
restruct: ReStruct,
function drawCIPLabel({
atomOrBond,
position,
restruct,
visel
}: {
atomOrBond: Bond | Atom
position: Vec2
restruct: ReStruct
visel: Visel
) {
const render = restruct.render
const { options, paper } = render
}) {
const { options, paper } = restruct.render
const path = paper.set()

const cipLabelPosition = position.scaled(options.scale)
Expand All @@ -173,12 +181,14 @@ function drawCIPLabel(
atomOrBond,
options
})
const box = relBox(cipValuePath.getBBox())
const box = relBox(cipValuePath.path.getBBox())

cipValuePath.translateAbs(0.5 * box.width, -0.5 * box.height)
path.push(cipValuePath.toFront())
cipValuePath.path.translateAbs(0.5 * box.width, -0.5 * box.height)
path.push(cipValuePath.path.toFront())

restruct.addReObjectPath(LayerMap.data, visel, path, null, true)

return cipValuePath
}

const util = {
Expand Down

0 comments on commit 376182d

Please sign in to comment.