Skip to content

Commit

Permalink
Backmerge: #2458 The reaction with catalysts is displayed incorrect w…
Browse files Browse the repository at this point in the history
…ith ACS style setting and after layout

backmerge to master
  • Loading branch information
AliaksandrDziarkach committed Oct 17, 2024
1 parent 7d03fb4 commit 878ea21
Show file tree
Hide file tree
Showing 14 changed files with 1,490 additions and 183 deletions.
58 changes: 5 additions & 53 deletions api/c/indigo-renderer/src/indigo_render2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,54 +186,6 @@ void indigoRenderGetStereoStyle(Array<char>& value)
}
}

void indigoRenderSetLabelMode(const char* mode)
{
std::string mode_string(mode);
LABEL_MODE result;
if (mode_string == "none")
{
result = LABEL_MODE_NONE;
}
else if (mode_string == "hetero")
{
result = LABEL_MODE_HETERO;
}
else if (mode_string == "terminal-hetero")
{
result = LABEL_MODE_TERMINAL_HETERO;
}
else if (mode_string == "all")
{
result = LABEL_MODE_ALL;
}
else
{
throw IndigoError("Invalid label mode, should be 'none', 'hetero', 'terminal-hetero' or 'all'");
}
RenderParams& rp = indigoRendererGetInstance().renderParams;
rp.rOpt.labelMode = result;
}

void indigoRenderGetLabelMode(Array<char>& value)
{
RenderParams& rp = indigoRendererGetInstance().renderParams;
switch (rp.rOpt.labelMode)
{
case LABEL_MODE_NONE:
value.readString("none", true);
break;
case LABEL_MODE_HETERO:
value.readString("hetero", true);
break;
case LABEL_MODE_TERMINAL_HETERO:
value.readString("terminal-hetero", true);
break;
case LABEL_MODE_ALL:
value.readString("all", true);
break;
}
}

void indigoRenderSetCatalystsPlacement(const char* mode)
{
int result;
Expand Down Expand Up @@ -454,6 +406,11 @@ static void setParams(RenderParams& rp, LayoutOptions& layout_options)
rp.cnvOpt.bondLength = layout_options.bondLength;
rp.cnvOpt.bondLengthUnit = layout_options.bondLengthUnit;
rp.rOpt.ppi = layout_options.ppi;
rp.rOpt.fontSize = layout_options.fontSize;
rp.rOpt.fontSizeUnit = layout_options.fontSizeUnit;
rp.rOpt.fontSizeSub = layout_options.fontSizeSub;
rp.rOpt.fontSizeSubUnit = layout_options.fontSizeSubUnit;
rp.rOpt.labelMode = layout_options.labelMode;
rp.rOpt.bond_length_px = layout_options.bondLength > EPSILON ? layout_options.getBondLengthPx() : LayoutOptions::DEFAULT_BOND_LENGTH_PX;
if (rp.cnvOpt.outputSheetWidth > 0)
{
Expand Down Expand Up @@ -732,7 +689,6 @@ void IndigoRenderer::setOptionsHandlers()

mgr->setOptionHandlerString("render-output-format", indigoRenderSetOutputFormat, indigoRenderGetOutputFormat);

mgr->setOptionHandlerString("render-label-mode", indigoRenderSetLabelMode, indigoRenderGetLabelMode);
mgr->setOptionHandlerString("render-comment", SETTER_GETTER_STR_OPTION(rp.cnvOpt.comment));
mgr->setOptionHandlerString("render-comment-position", indigoRenderSetCommentPosition, indigoRenderGetCommentPosition);
mgr->setOptionHandlerString("render-stereo-style", indigoRenderSetStereoStyle, indigoRenderGetStereoStyle);
Expand Down Expand Up @@ -790,10 +746,6 @@ void IndigoRenderer::setOptionsHandlers()
mgr->setOptionHandlerVoid("reset-render-options", indigoRenderResetOptions);

// ACS style options
mgr->setOptionHandlerFloat("render-font-size", SETTER_GETTER_FLOAT_OPTION(rp.rOpt.fontSize));
mgr->setOptionHandlerString("render-font-size-unit", SETTER_GETTER_UNIT_OPTION(rp.rOpt.fontSizeUnit));
mgr->setOptionHandlerFloat("render-font-size-sub", SETTER_GETTER_FLOAT_OPTION(rp.rOpt.fontSizeSub));
mgr->setOptionHandlerString("render-font-size-sub-unit", SETTER_GETTER_UNIT_OPTION(rp.rOpt.fontSizeSubUnit));
mgr->setOptionHandlerFloat("render-bond-thickness", SETTER_GETTER_FLOAT_OPTION(rp.rOpt.bondThickness));
mgr->setOptionHandlerString("render-bond-thickness-unit", SETTER_GETTER_UNIT_OPTION(rp.rOpt.bondThicknessUnit));
mgr->setOptionHandlerFloat("render-bond-spacing", SETTER_GETTER_FLOAT_OPTION(rp.rOpt.bondSpacing));
Expand Down
53 changes: 53 additions & 0 deletions api/c/indigo/src/indigo_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,54 @@ void indigoProductEnumeratorGetOneTubeMode(Array<char>& value)
value.readString("grid", true);
}

void indigoRenderSetLabelMode(const char* mode)
{
std::string mode_string(mode);
LABEL_MODE result;
if (mode_string == "none")
{
result = LABEL_MODE_NONE;
}
else if (mode_string == "hetero")
{
result = LABEL_MODE_HETERO;
}
else if (mode_string == "terminal-hetero")
{
result = LABEL_MODE_TERMINAL_HETERO;
}
else if (mode_string == "all")
{
result = LABEL_MODE_ALL;
}
else
{
throw IndigoError("Invalid label mode, should be 'none', 'hetero', 'terminal-hetero' or 'all'");
}
LayoutOptions& layout_options = indigoGetInstance().layout_options;
layout_options.labelMode = result;
}

void indigoRenderGetLabelMode(Array<char>& value)
{
LayoutOptions& layout_options = indigoGetInstance().layout_options;
switch (layout_options.labelMode)
{
case LABEL_MODE_NONE:
value.readString("none", true);
break;
case LABEL_MODE_HETERO:
value.readString("hetero", true);
break;
case LABEL_MODE_TERMINAL_HETERO:
value.readString("terminal-hetero", true);
break;
case LABEL_MODE_ALL:
value.readString("all", true);
break;
}
}

void IndigoOptionHandlerSetter::setBasicOptionHandlers(const qword id)
{
auto mgr = sf::xlock_safe_ptr(indigoGetOptionManager(id));
Expand Down Expand Up @@ -391,4 +439,9 @@ void IndigoOptionHandlerSetter::setBasicOptionHandlers(const qword id)
mgr->setOptionHandlerFloat("reaction-component-margin-size", SETTER_GETTER_FLOAT_OPTION(indigo.layout_options.reactionComponentMarginSize));
mgr->setOptionHandlerString("reaction-component-margin-size-unit", SETTER_GETTER_UNIT_OPTION(indigo.layout_options.reactionComponentMarginSizeUnit));
mgr->setOptionHandlerInt("image-resolution", SET_POSITIVE_INT_OPTION(indigo.layout_options.ppi, "image resolution ppi must be positive"));
mgr->setOptionHandlerFloat("render-font-size", SETTER_GETTER_FLOAT_OPTION(indigo.layout_options.fontSize));
mgr->setOptionHandlerString("render-font-size-unit", SETTER_GETTER_UNIT_OPTION(indigo.layout_options.fontSizeUnit));
mgr->setOptionHandlerFloat("render-font-size-sub", SETTER_GETTER_FLOAT_OPTION(indigo.layout_options.fontSizeSub));
mgr->setOptionHandlerString("render-font-size-sub-unit", SETTER_GETTER_UNIT_OPTION(indigo.layout_options.fontSizeSubUnit));
mgr->setOptionHandlerString("render-label-mode", indigoRenderSetLabelMode, indigoRenderGetLabelMode);
}
3 changes: 3 additions & 0 deletions api/tests/integration/ref/layout/acs_style_reaction.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@

*** 2389 wrong margin ***
acs_issue_2389.ket:SUCCEED

*** 2458 catalist margins margin ***
acs_issue_2458.ket:SUCCEED
29 changes: 29 additions & 0 deletions api/tests/integration/tests/layout/acs_style_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,32 @@ def find_diff(a, b):
else:
print(filename + ":FAILED")
print(diff)


print("\n*** 2458 catalist margins margin ***")
filename = "acs_issue_2458.ket"
rxn = indigo.loadReactionFromFile(os.path.join(root, filename))
indigo.resetOptions()
indigo.setOption("molfile-saving-skip-date", "1")
indigo.setOption("json-saving-pretty", "1")
indigo.setOption("json-use-native-precision", "1")
indigo.setOption("smart-layout", "true")
indigo.setOption("dearomatize-on-load", "false")
indigo.setOption("render-font-size", "10")
indigo.setOption("render-font-size-unit", "pt")
indigo.setOption("image-resolution", "600")
indigo.setOption("bond-length-unit", "pt")
indigo.setOption("bond-length", "14.4")
indigo.setOption("render-label-mode", "terminal-hetero")
rxn.layout()
# with open(os.path.join(ref, filename), "w") as file:
# file.write(rxn.json())
with open(os.path.join(ref, filename), "r") as file:
ket_ref = file.read()
ket = rxn.json()
diff = find_diff(ket_ref, ket)
if not diff:
print(filename + ":SUCCEED")
else:
print(filename + ":FAILED")
print(diff)
Loading

0 comments on commit 878ea21

Please sign in to comment.