Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backmerge: #4192 - Export to SVG/PNG ignores "Show hydrogen labels" option #4317

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/ketcher-core/src/infrastructure/services/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ShowHydrogenLabels } from 'application/render';
import { ketcherProvider } from 'application/utils';

enum IndigoShowHydrogenLabelsMode {
OFF = 'none',
HETERO = 'hetero',
TERMINAL_HETERO = 'terminal-hetero',
ALL = 'all',
}

export function getLabelRenderModeForIndigo() {
// Terminal does not supported by indigo so TERMINAL_HETERO used
// Off removing all labels in indigo so HETERO used
const renderModeMapping = {
[ShowHydrogenLabels.Off]: IndigoShowHydrogenLabelsMode.HETERO,
[ShowHydrogenLabels.Hetero]: IndigoShowHydrogenLabelsMode.HETERO,
[ShowHydrogenLabels.Terminal]: IndigoShowHydrogenLabelsMode.TERMINAL_HETERO,
[ShowHydrogenLabels.TerminalAndHetero]:
IndigoShowHydrogenLabelsMode.TERMINAL_HETERO,
[ShowHydrogenLabels.On]: IndigoShowHydrogenLabelsMode.ALL,
};

return (
renderModeMapping[
ketcherProvider.getKetcher().editor.options().showHydrogenLabels
] || IndigoShowHydrogenLabelsMode.OFF
);
}
1 change: 1 addition & 0 deletions packages/ketcher-core/src/infrastructure/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
***************************************************************************/

export * from './struct';
export * from './helpers';
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
StructServiceOptions,
} from 'domain/services';
import { KetcherLogger } from 'utilities';
import { getLabelRenderModeForIndigo } from 'infrastructure/services/helpers';

function pollDeferred(process, complete, timeGap, startTimeGap) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -348,6 +349,7 @@ export class RemoteStructService implements StructService {
{
'render-output-format': outputFormat,
'render-bond-line-width': bondThickness,
'render-label-mode': getLabelRenderModeForIndigo(),
},
(response) => response.then((resp) => resp.text()),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
RecognizeResult,
StructService,
StructServiceOptions,
getLabelRenderModeForIndigo,
} from 'ketcher-core';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -702,6 +703,7 @@ class IndigoService implements StructService {
): Promise<string> {
const { outputFormat, backgroundColor, bondThickness, ...restOptions } =
options;

return new Promise((resolve, reject) => {
const action = ({ data }: OutputMessageWrapper) => {
const msg: OutputMessage<string> = data;
Expand All @@ -717,8 +719,8 @@ class IndigoService implements StructService {
const commandOptions: CommandOptions = {
...this.defaultOptions,
...restOptions,
'render-label-mode': getLabelRenderModeForIndigo(),
};

const commandData: GenerateImageCommandData = {
struct: inputData,
outputFormat: outputFormat || 'png',
Expand Down
Loading