Skip to content

Commit

Permalink
Merge branch 'master' into #1044-Text-Tool-Add-special-symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaOdnoshivkina committed Dec 3, 2021
2 parents cf0f8f5 + 3691de4 commit a48d769
Show file tree
Hide file tree
Showing 14 changed files with 854 additions and 725 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
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,17 @@ const formatProperties: FormatPropertiesMap = {
)
}

const imgFormatProperties = {
svg: { extension: '.svg', name: 'SVG Document' },
png: { extension: '.png', name: 'PNG Image' }
}

function getPropertiesByImgFormat(format) {
return imgFormatProperties[format]
}

function getPropertiesByFormat(format: SupportedFormat) {
return formatProperties[format]
}

export { formatProperties, getPropertiesByFormat }
export { formatProperties, getPropertiesByFormat, getPropertiesByImgFormat }
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
2 changes: 0 additions & 2 deletions packages/ketcher-react/src/Editor.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@
&[readonly],
fieldset[disabled] & {
cursor: not-allowed;
background: #efefef;
opacity: 0.6;
}
}

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 a48d769

Please sign in to comment.