Skip to content

Commit

Permalink
#1600 wrong sign for specific types while ket generation (#1606)
Browse files Browse the repository at this point in the history
* fix wrong sign for rxn, text, simple objects

* update indigo-ketcher version

Co-authored-by: Anastasiia Moskvina <anastasiia_moskvina@epam.com>
  • Loading branch information
AnaMoskvina and Anastasiia Moskvina authored May 16, 2022
1 parent 75abd1d commit 9c4aa6b
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
Text
} from 'domain/entities'

import { getNodeWithInvertedYCoord } from 'domain/serializers/ket/helpers'

const structs = {
prepareContent: {
atoms: [
Expand Down Expand Up @@ -1452,17 +1454,19 @@ const initStruct = (structName) => {
break
case 'rxnArrows':
structData.rxnArrows.forEach((props) =>
struct.rxnArrows.add(new RxnArrow(props))
struct.rxnArrows.add(new RxnArrow(getNodeWithInvertedYCoord(props)))
)
break
case 'rxnPluses':
structData.rxnPluses.forEach((props) =>
struct.rxnPluses.add(new RxnPlus(props))
struct.rxnPluses.add(new RxnPlus(getNodeWithInvertedYCoord(props)))
)
break
case 'simpleObjects':
structData.simpleObjects.forEach((props) =>
struct.simpleObjects.add(new SimpleObject(props))
struct.simpleObjects.add(
new SimpleObject(getNodeWithInvertedYCoord(props))
)
)
break
case 'sgroups':
Expand All @@ -1478,7 +1482,9 @@ const initStruct = (structName) => {
})
break
case 'texts':
structData.texts.forEach((props) => struct.texts.add(new Text(props)))
structData.texts.forEach((props) =>
struct.texts.add(new Text(getNodeWithInvertedYCoord(props)))
)
break
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
***************************************************************************/

import { RxnArrow, RxnPlus, Struct } from 'domain/entities'
import { getNodeWithInvertedYCoord } from '../helpers'

export function rxnToStruct(ketItem: any, struct: Struct): Struct {
if (ketItem.type === 'arrow') {
struct.rxnArrows.add(new RxnArrow(ketItem.data))
struct.rxnArrows.add(new RxnArrow(getNodeWithInvertedYCoord(ketItem.data)))
} else {
struct.rxnPluses.add(
new RxnPlus({
pp: {
x: ketItem.location[0],
y: ketItem.location[1],
y: -ketItem.location[1],
z: ketItem.location[2]
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
***************************************************************************/

import { SimpleObject, SimpleObjectMode, Struct, Vec2 } from 'domain/entities'
import { getNodeWithInvertedYCoord } from '../helpers'

export function simpleObjectToStruct(ketItem: any, struct: Struct): Struct {
const object =
ketItem.data.mode === 'circle' ? circleToEllipse(ketItem) : ketItem.data
struct.simpleObjects.add(new SimpleObject(object))
struct.simpleObjects.add(new SimpleObject(getNodeWithInvertedYCoord(object)))
return struct
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
***************************************************************************/

import { Struct, Text } from 'domain/entities'
import { getNodeWithInvertedYCoord } from '../helpers'

export function textToStruct(ketItem: any, struct: Struct) {
const object = ketItem.data
const object = getNodeWithInvertedYCoord(ketItem.data)
struct.texts.add(new Text(object))

return struct
Expand Down
28 changes: 28 additions & 0 deletions packages/ketcher-core/src/domain/serializers/ket/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/****************************************************************************
* Copyright 2022 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 { cloneDeepWith, cloneDeep } from 'lodash'

const customizer = (value: any) => {
if (typeof value === 'object' && value.y) {
const clonedValue = cloneDeep(value)
clonedValue.y = -clonedValue.y
return clonedValue
}
}

export const getNodeWithInvertedYCoord = (node: object) =>
cloneDeepWith(node, customizer)
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
* limitations under the License.
***************************************************************************/

import { getNodeWithInvertedYCoord } from '../helpers'

export function arrowToKet(arrowNode) {
return {
type: 'arrow',
data: arrowNode.data
data: getNodeWithInvertedYCoord(arrowNode.data)
}
}

export function plusToKet(plusNode) {
const coord = plusNode.center
return {
type: 'plus',
location: [coord.x, coord.y, coord.z],
location: [coord.x, -coord.y, coord.z],
prop: plusNode.data
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
* limitations under the License.
***************************************************************************/

import { getNodeWithInvertedYCoord } from '../helpers'

export function simpleObjectToKet(simpleObjectNode) {
return {
type: 'simpleObject',
data: simpleObjectNode.data
data: getNodeWithInvertedYCoord(simpleObjectNode.data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
import { getNodeWithInvertedYCoord } from '../helpers'

export function textToKet(textNode) {
return {
type: 'text',
data: textNode.data
data: getNodeWithInvertedYCoord(textNode.data)
}
}
2 changes: 1 addition & 1 deletion packages/ketcher-standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@babel/runtime": "^7.17.9",
"indigo-ketcher": "1.6.6-0",
"indigo-ketcher": "1.7.0-alpha-0",
"ketcher-core": "workspace:*"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9276,10 +9276,10 @@ __metadata:
languageName: node
linkType: hard

"indigo-ketcher@npm:1.6.6-0":
version: 1.6.6-0
resolution: "indigo-ketcher@npm:1.6.6-0"
checksum: 7d8008b4f6fe9d26d2a7ce8f854483a8510180118d822a769c8bf30a84abea2683a2a97686df7c271e41f1d6bb648d3947612fdf16a9c9417e76138c82db3e0b
"indigo-ketcher@npm:1.7.0-alpha-0":
version: 1.7.0-alpha-0
resolution: "indigo-ketcher@npm:1.7.0-alpha-0"
checksum: 9f4baee6cff7be91c247634d5c910fe5676d25d09a4cf78124cd74c86e687c7d7e619d9d62770d3df66ab8a7833206ab5fd5d4b806eb380cefeb7c36eafaa9c1
languageName: node
linkType: hard

Expand Down Expand Up @@ -11460,7 +11460,7 @@ __metadata:
cross-env: ^7.0.3
eslint: ^8.4.1
eslint-plugin-jest: ^25.3.0
indigo-ketcher: 1.6.6-0
indigo-ketcher: 1.7.0-alpha-0
jest: 26.6.0
ketcher-core: "workspace:*"
npm-run-all: ^4.1.5
Expand Down

0 comments on commit 9c4aa6b

Please sign in to comment.