Skip to content

Commit

Permalink
#1026 SVG/PNG: Contracted 'Functional Groups' and 'Salts and Solvents…
Browse files Browse the repository at this point in the history
…' are rendered expanded when saved (#1154)
  • Loading branch information
Wadym authored Jun 23, 2023
1 parent 1fd76de commit 17585b2
Show file tree
Hide file tree
Showing 46 changed files with 1,505 additions and 130 deletions.
30 changes: 0 additions & 30 deletions api/c/indigo-renderer/src/indigo_render2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,35 +271,6 @@ void indigoRenderGetCatalystsPlacement(Array<char>& value)
value.readString("above", true);
}

void indigoRenderSetSuperatomMode(const char* mode)
{
std::string mode_string(mode);
int result;
if (mode_string == "expand")
{
result = 0;
}
else if (mode_string == "collapse")
{
result = 1;
}
else
{
throw IndigoError("Invalid label mode, should be 'expand' or 'collapse'");
}
RenderParams& rp = indigoRendererGetInstance().renderParams;
rp.rOpt.collapseSuperatoms = result != 0;
}

void indigoRenderGetSuperatomMode(Array<char>& value)
{
RenderParams& rp = indigoRendererGetInstance().renderParams;
if (rp.rOpt.collapseSuperatoms)
value.readString("collapse", true);
else
value.readString("expand", true);
}

static MultilineTextLayout _parseTextLayout(const char* text)
{
// Try to read as float for compatibility with previous versions
Expand Down Expand Up @@ -735,7 +706,6 @@ void IndigoRenderer::setOptionsHandlers()
mgr->setOptionHandlerString("render-comment-position", indigoRenderSetCommentPosition, indigoRenderGetCommentPosition);
mgr->setOptionHandlerString("render-stereo-style", indigoRenderSetStereoStyle, indigoRenderGetStereoStyle);
mgr->setOptionHandlerString("render-catalysts-placement", indigoRenderSetCatalystsPlacement, indigoRenderGetCatalystsPlacement);
mgr->setOptionHandlerString("render-superatom-mode", indigoRenderSetSuperatomMode, indigoRenderGetSuperatomMode);
mgr->setOptionHandlerString("render-atom-color-property", SETTER_GETTER_STR_OPTION(rp.rOpt.atomColorProp));

mgr->setOptionHandlerBool("render-coloring", SETTER_GETTER_BOOL_OPTION(rp.rOpt.atomColoring));
Expand Down
6 changes: 3 additions & 3 deletions api/c/indigo/src/indigo_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3216,8 +3216,8 @@ CEXPORT int indigoGetSGroupDisplayOption(int sgroup)
INDIGO_BEGIN
{
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
if (sup.contracted > -1)
return sup.contracted;
if (sup.contracted > DisplayOption::Undefined)
return (int)sup.contracted;

return 0;
}
Expand All @@ -3229,7 +3229,7 @@ CEXPORT int indigoSetSGroupDisplayOption(int sgroup, int option)
INDIGO_BEGIN
{
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
sup.contracted = option;
sup.contracted = (DisplayOption)option;

return 1;
}
Expand Down
3 changes: 0 additions & 3 deletions api/c/tests/unit/tests/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class IndigoApiRendererTest : public IndigoApiTest
indigoSetOption("render-stereo-style", "none");
indigoSetOptionXY("render-image-size", 400, 400);
indigoSetOption("render-output-format", "png");
indigoSetOption("render-superatom-mode", "collapse");

try
{
Expand Down Expand Up @@ -89,7 +88,6 @@ TEST_F(IndigoApiRendererTest, layout_rings)
indigoSetOption("render-stereo-style", "none");
indigoSetOptionXY("render-image-size", 400, 400);
indigoSetOption("render-output-format", "png");
indigoSetOption("render-superatom-mode", "collapse");
indigoRenderToFile(m, "ring.png");
}
catch (Exception& e)
Expand All @@ -112,7 +110,6 @@ TEST_F(IndigoApiRendererTest, layout_crown)
indigoSetOption("render-stereo-style", "none");
indigoSetOptionXY("render-image-size", 400, 400);
indigoSetOption("render-output-format", "png");
indigoSetOption("render-superatom-mode", "collapse");
indigoRenderToFile(m, "crown.png");
}
catch (Exception& e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*** test png output ***
*** test ket input ***
contracted_fg_ss_ket.png rendering status: OK
contracted_expanded_fg_ss_ket.png rendering status: OK
expanded_fg_ss_ket.png rendering status: OK
*** test mol input ***
*** contracted_fg_ss_mol.png done ***
contracted_fg_ss_mol.png rendering status: OK
contracted_expanded_fg_ss_mol.png rendering status: OK
expanded_fg_ss_mol.png rendering status: OK
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import errno
import os
import sys

sys.path.append(
os.path.normpath(
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
)
)
from env_indigo import * # noqa
from rendering import *

if not os.path.exists(joinPathPy("out", __file__)):
try:
os.makedirs(joinPathPy("out", __file__))
except OSError as e:
if e.errno != errno.EEXIST:
raise

indigo = Indigo()
renderer = IndigoRenderer(indigo)

print("*** test png output ***")

print("*** test ket input ***")

mol11 = indigo.loadMoleculeFromFile(
joinPathPy("molecules/contracted_fg_ss.ket", __file__)
)
indigo.setOption("render-output-format", "png")
renderer.renderToFile(
mol11, joinPathPy("out/contracted_fg_ss_ket.png", __file__)
)
print(checkImageSimilarity("contracted_fg_ss_ket.png"))

mol12 = indigo.loadMoleculeFromFile(
joinPathPy("molecules/contracted_expanded_fg_ss.ket", __file__)
)
indigo.setOption("render-output-format", "png")
renderer.renderToFile(
mol12, joinPathPy("out/contracted_expanded_fg_ss_ket.png", __file__)
)
print(checkImageSimilarity("contracted_expanded_fg_ss_ket.png"))

mol13 = indigo.loadMoleculeFromFile(
joinPathPy("molecules/expanded_fg_ss.ket", __file__)
)
indigo.setOption("render-output-format", "png")
renderer.renderToFile(
mol13, joinPathPy("out/expanded_fg_ss_ket.png", __file__)
)
print(checkImageSimilarity("expanded_fg_ss_ket.png"))

print("*** test mol input ***")

mol14 = indigo.loadMoleculeFromFile(
joinPathPy("molecules/contracted_fg_ss.mol", __file__)
)
indigo.setOption("render-output-format", "png")
renderer.renderToFile(
mol14, joinPathPy("out/contracted_fg_ss_mol.png", __file__)
)
print("*** contracted_fg_ss_mol.png done ***")
print(checkImageSimilarity("contracted_fg_ss_mol.png"))

mol15 = indigo.loadMoleculeFromFile(
joinPathPy("molecules/contracted_expanded_fg_ss.mol", __file__)
)
indigo.setOption("render-output-format", "png")
renderer.renderToFile(
mol15, joinPathPy("out/contracted_expanded_fg_ss_mol.png", __file__)
)
print(checkImageSimilarity("contracted_expanded_fg_ss_mol.png"))

mol16 = indigo.loadMoleculeFromFile(
joinPathPy("molecules/expanded_fg_ss.mol", __file__)
)
indigo.setOption("render-output-format", "png")
renderer.renderToFile(
mol16, joinPathPy("out/expanded_fg_ss_mol.png", __file__)
)
print(checkImageSimilarity("expanded_fg_ss_mol.png"))

if isIronPython():
renderer.Dispose()
indigo.Dispose()
Loading

0 comments on commit 17585b2

Please sign in to comment.