From 49f5b8ad6d82bc7085b8f7d78d76d1e6c52283a4 Mon Sep 17 00:00:00 2001 From: Roman Rodionov Date: Fri, 11 Oct 2024 19:28:08 +0200 Subject: [PATCH] #5634 - ketcher.getMolfile() stopped working for macro canvas with peptides --- .../src/application/editor/editor.types.ts | 1 + packages/ketcher-core/src/application/indigo.ts | 13 ++++++++----- .../ketcher-core/src/application/ketcher.ts | 17 ++++++++++------- packages/ketcher-core/src/application/utils.ts | 4 +++- .../ketcher-react/src/script/editor/Editor.ts | 9 ++++++++- .../src/script/ui/views/Editor.jsx | 12 +++++++----- .../components/StructEditor/StructEditor.jsx | 16 ++++++++++++---- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/packages/ketcher-core/src/application/editor/editor.types.ts b/packages/ketcher-core/src/application/editor/editor.types.ts index 0cd4df8194..b3563a854d 100644 --- a/packages/ketcher-core/src/application/editor/editor.types.ts +++ b/packages/ketcher-core/src/application/editor/editor.types.ts @@ -82,4 +82,5 @@ export interface Editor { macromoleculeConvertionError: string | null | undefined; setMacromoleculeConvertionError: (errorMessage: string) => void; clearMacromoleculeConvertionError: () => void; + serverSettings: object; } diff --git a/packages/ketcher-core/src/application/indigo.ts b/packages/ketcher-core/src/application/indigo.ts index ac1d5865bb..ee0e5ae9ad 100644 --- a/packages/ketcher-core/src/application/indigo.ts +++ b/packages/ketcher-core/src/application/indigo.ts @@ -113,12 +113,15 @@ export class Indigo { }); } - layout(struct: StructOrString): Promise { + layout(struct: StructOrString, options): Promise { return this.#structService - .layout({ - struct: convertStructToString(struct, this.#ketSerializer), - output_format: ChemicalMimeType.KET, - }) + .layout( + { + struct: convertStructToString(struct, this.#ketSerializer), + output_format: ChemicalMimeType.KET, + }, + options, + ) .then((data) => this.#ketSerializer.deserialize(data.struct)); } diff --git a/packages/ketcher-core/src/application/ketcher.ts b/packages/ketcher-core/src/application/ketcher.ts index 5b6597f776..945eb13782 100644 --- a/packages/ketcher-core/src/application/ketcher.ts +++ b/packages/ketcher-core/src/application/ketcher.ts @@ -18,7 +18,7 @@ import { saveAs } from 'file-saver'; import { FormatterFactory, SupportedFormat } from './formatters'; import { GenerateImageOptions, StructService } from 'domain/services'; -import { CoreEditor, Editor, defaultBondThickness } from './editor'; +import { CoreEditor, Editor } from './editor'; import { Indigo } from 'application/indigo'; import { KetSerializer, MolfileFormat } from 'domain/serializers'; import { SGroup, Struct } from 'domain/entities'; @@ -413,7 +413,10 @@ export class Ketcher { } runAsyncAction(async () => { - const struct = await this._indigo.layout(this.#editor.struct()); + const struct = await this._indigo.layout( + this.#editor.struct(), + this.editor.serverSettings, + ); const ketSerializer = new KetSerializer(); this.setMolecule(ketSerializer.serialize(struct)); }, this.eventBus); @@ -465,7 +468,6 @@ export class Ketcher { data: string, options: GenerateImageOptions = { outputFormat: 'png', - bondThickness: defaultBondThickness, }, ): Promise { let meta = ''; @@ -480,11 +482,12 @@ export class Ketcher { meta = 'image/png'; options.outputFormat = 'png'; } + const serverSettings = this.editor.serverSettings; - const base64 = await this.structService.generateImageAsBase64( - data, - options, - ); + const base64 = await this.structService.generateImageAsBase64(data, { + ...serverSettings, + ...options, + }); const byteCharacters = atob(base64); const byteNumbers = new Array(byteCharacters.length); for (let i = 0; i < byteCharacters.length; i++) { diff --git a/packages/ketcher-core/src/application/utils.ts b/packages/ketcher-core/src/application/utils.ts index 52f329589b..7133be462c 100644 --- a/packages/ketcher-core/src/application/utils.ts +++ b/packages/ketcher-core/src/application/utils.ts @@ -36,7 +36,9 @@ export function getStructure( drawingEntitiesManager?: DrawingEntitiesManager, selection?: EditorSelection, ): Promise { - const formatter = formatterFactory.create(structureFormat); + const serverSettings = ketcherProvider.getKetcher().editor.serverSettings; + const formatter = formatterFactory.create(structureFormat, serverSettings); + return formatter.getStructureFromStructAsync( struct, drawingEntitiesManager, diff --git a/packages/ketcher-react/src/script/editor/Editor.ts b/packages/ketcher-react/src/script/editor/Editor.ts index 5b80d93988..dd66583557 100644 --- a/packages/ketcher-react/src/script/editor/Editor.ts +++ b/packages/ketcher-react/src/script/editor/Editor.ts @@ -162,10 +162,12 @@ class Editor implements KetcherEditor { updateFloatingTools: Subscription; }; + public serverSettings = {}; + lastEvent: any; macromoleculeConvertionError: string | null | undefined; - constructor(clientArea, options) { + constructor(clientArea, options, serverSettings) { this.render = new Render( clientArea, Object.assign( @@ -186,6 +188,7 @@ class Editor implements KetcherEditor { this.renderAndRecoordinateStruct = this.renderAndRecoordinateStruct.bind(this); this.setOptions = this.setOptions.bind(this); + this.setServerSettings(serverSettings); this.lastCursorPosition = { x: 0, @@ -339,6 +342,10 @@ class Editor implements KetcherEditor { return this.render.options; } + public setServerSettings(serverSettings) { + this.serverSettings = serverSettings; + } + private updateToolAfterOptionsChange(wasViewOnlyEnabled: boolean) { const isViewOnlyEnabled = this.render.options.viewOnlyMode; if ( diff --git a/packages/ketcher-react/src/script/ui/views/Editor.jsx b/packages/ketcher-react/src/script/ui/views/Editor.jsx index 4918c88eb0..a1ce75fe40 100644 --- a/packages/ketcher-react/src/script/ui/views/Editor.jsx +++ b/packages/ketcher-react/src/script/ui/views/Editor.jsx @@ -35,12 +35,14 @@ const mapDispatchToProps = (dispatch) => { }; }; -const Editor = connect( - (state) => ({ +const Editor = connect((state) => { + const serverSettings = state.options.getServerSettings(); + + return { options: state.options.settings, + serverSettings, indigoVerification: state.requestsStatuses.indigoVerification, - }), - mapDispatchToProps, -)(StructEditor); + }; +}, mapDispatchToProps)(StructEditor); export default Editor; diff --git a/packages/ketcher-react/src/script/ui/views/components/StructEditor/StructEditor.jsx b/packages/ketcher-react/src/script/ui/views/components/StructEditor/StructEditor.jsx index b66985e997..af24060c7b 100644 --- a/packages/ketcher-react/src/script/ui/views/components/StructEditor/StructEditor.jsx +++ b/packages/ketcher-react/src/script/ui/views/components/StructEditor/StructEditor.jsx @@ -41,7 +41,10 @@ function setupEditor(editor, props, oldProps = {}) { } } - if (oldProps.options && options !== oldProps.options) editor.options(options); + if (oldProps.options && options !== oldProps.options) { + editor.options(options); + editor.setServerSettings(props.serverSettings); + } Object.keys(editor.event).forEach((name) => { const eventName = `on${upperFirst(name)}`; @@ -147,9 +150,13 @@ class StructEditor extends Component { } componentDidMount() { - this.editor = new Editor(this.editorRef.current, { - ...this.props.options, - }); + this.editor = new Editor( + this.editorRef.current, + { + ...this.props.options, + }, + { ...this.props.serverSettings }, + ); const ketcher = ketcherProvider.getKetcher(); if (ketcher?.editor.macromoleculeConvertionError) { this.props.onShowMacromoleculesErrorMessage( @@ -287,6 +294,7 @@ class StructEditor extends Component { showAttachmentPoints = true, onUpdateFloatingTools, onShowMacromoleculesErrorMessage, + serverSettings, /* eslint-enable @typescript-eslint/no-unused-vars */ ...props } = this.props;