Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMazol committed Dec 2, 2021
2 parents d221fc1 + 0d87dd3 commit 3691de4
Show file tree
Hide file tree
Showing 8 changed files with 628 additions and 587 deletions.
3 changes: 2 additions & 1 deletion example/src/ErrorModal/ErrorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const ErrorModal = ({ message, close }: ErrorModalProps) => {
className={'ok'}
onClick={() => {
close()
}}>
}}
>
OK
</button>
</footer>
Expand Down
37 changes: 26 additions & 11 deletions packages/ketcher-core/src/application/editor/actions/rotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,37 @@ export function fromFlip(restruct, selection, dir, center) {

const action = new Action()

if (!selection) selection = structSelection(struct)
if (!selection) {
selection = structSelection(struct)
}

if (!selection.atoms) return action.perform(restruct)
if (!selection.atoms) {
return action.perform(restruct)
}

const fids = selection.atoms.reduce((acc, aid) => {
const atom = struct.atoms.get(aid)

if (!acc[atom.fragment]) acc[atom.fragment] = []
if (!acc[atom.fragment]) {
acc[atom.fragment] = []
}

acc[atom.fragment].push(aid)
return acc
}, {})

const isFragFound = Object.keys(fids)
.map(frag => parseInt(frag, 10))
.find(frag => {
return !struct.getFragmentIds(frag).equals(new Pile(fids[frag]))
})
const fidsNumberKeys = Object.keys(fids).map(frag => parseInt(frag, 10))

const isFragFound = fidsNumberKeys.find(frag => {
const allFragmentsOfStructure = struct.getFragmentIds(frag)
const selectedFragmentsOfStructure = new Pile(fids[frag])
const res = allFragmentsOfStructure.equals(selectedFragmentsOfStructure)
return !res
})

if (isFragFound) return action // empty action
if (typeof isFragFound === 'number') {
return action // empty action
}

Object.keys(fids).forEach(frag => {
const fragment = new Pile(fids[frag])
Expand All @@ -80,7 +91,9 @@ export function fromFlip(restruct, selection, dir, center) {
selection.bonds.forEach(bid => {
const bond = struct.bonds.get(bid)

if (bond.type !== Bond.PATTERN.TYPE.SINGLE) return
if (bond.type !== Bond.PATTERN.TYPE.SINGLE) {
return
}

if (bond.stereo === Bond.PATTERN.STEREO.UP) {
action.addOp(new BondAttr(bid, 'stereo', Bond.PATTERN.STEREO.DOWN))
Expand Down Expand Up @@ -120,7 +133,9 @@ export function fromRotate(restruct, selection, center, angle) {

const action = new Action()

if (!selection) selection = structSelection(struct)
if (!selection) {
selection = structSelection(struct)
}

if (selection.atoms) {
selection.atoms.forEach(aid => {
Expand Down
12 changes: 6 additions & 6 deletions packages/ketcher-core/src/application/render/restruct/reatom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class ReAtom extends ReObject {
}

if (this.a.attpnt) {
const lsb = bisectSmallestSector(this, restruct.molecule)
const lsb = bisectLargestSector(this, restruct.molecule)
showAttpnt(this, render, lsb, restruct.addReObjectPath.bind(restruct))
}

Expand Down Expand Up @@ -349,7 +349,7 @@ class ReAtom extends ReObject {
draw.recenterText(aamPath, aamBox)
const visel = this.visel
let t = 3
let dir = bisectSmallestSector(this, restruct.molecule)
let dir = bisectLargestSector(this, restruct.molecule)
// estimate the shift to clear the atom label
for (let i = 0; i < visel.exts.length; ++i)
t = Math.max(t, util.shiftRayBox(ps, dir, visel.exts[i].translate(ps)))
Expand Down Expand Up @@ -991,7 +991,7 @@ function pathAndRBoxTranslate(path, rbb, x, y) {
rbb.y += y
}

function bisectSmallestSector(atom: ReAtom, struct: Struct) {
function bisectLargestSector(atom: ReAtom, struct: Struct) {
let angles: Array<number> = []
atom.a.neighbors.forEach(hbid => {
const hb = struct.halfBonds.get(hbid)
Expand All @@ -1003,11 +1003,11 @@ function bisectSmallestSector(atom: ReAtom, struct: Struct) {
da.push(angles[(i + 1) % angles.length] - angles[i])
}
da.push(angles[0] - angles[angles.length - 1] + 2 * Math.PI)
let daMin = Number.MAX_VALUE
let daMax = 0
let ang = -Math.PI / 2
for (let i = 0; i < angles.length; ++i) {
if (da[i] < daMin) {
daMin = da[i]
if (da[i] > daMax) {
daMax = da[i]
ang = angles[i] + da[i] / 2
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/ketcher-react/src/script/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ class Editor implements KetcherEditor {
this._tool.cancel()
}

const tool = toolMap[name](this, opts)
// TODO: when all tools are refactored to classes, remove this check
// and use new keyword for every tool
let tool
if (name === 'select') {
tool = new toolMap[name](this, opts)
} else {
tool = toolMap[name](this, opts)
}
if (!tool) {
return null
}
Expand Down
Loading

0 comments on commit 3691de4

Please sign in to comment.