OEDrawSVGToggleText

bool OEDrawSVGToggleText(OE2DMolDisplay &disp, OE2DAtomDisplay *adisp,
                        const std::string &text, const OEFont &font)

bool OEDrawSVGToggleText(OE2DMolDisplay &disp, OE2DBondDisplay *bdisp,
                        const std::string &text, const OEFont &font)

Creates and interactive effect in .svg images. The given text will appear / disappear when clicking at the position defined by the given atom / bond display.

Note

This functionality is only available for .svg image format. In other image formats it has no effects.

The generated svg image should be included into and HTML page with the SVG MIME type.

<object data="<imagename>.svg" type="image/svg+xml"></object>
disp

The OE2DMolDisplay object that holds the data necessary to depict the molecule with which it is initialized.

adisp

The OE2DAtomDisplay object that defines where the text will appear.

bdisp

The OE2DBondDisplay object that defines where the text will appear.

text

The text that appears/disappears on mouse clicks.

font

The graphical properties of the font used to draw the text.

uint width  = 400;
uint height = 200;

OEImage image = new OEImage(width, height);

OEGraphMol mol = new OEGraphMol();
OEChem.OESmilesToMol(mol, "Cc1cccnc1/C=C/[C@H](C(=O)O)O");
OEDepict.OEPrepareDepiction(mol);

OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
opts.SetMargins(10);
OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);

OEFont font = new OEFont(OEFontFamily.Default, OEFontStyle.Default, 12,
                         OEAlignment.Center, OEChem.OEDarkRed);

foreach (OE2DAtomDisplay adisp in disp.GetAtomDisplays())
{
    OEAtomBase atom = adisp.GetAtom();
    String toggletext = "atom idx=" + atom.GetIdx().ToString();
    OEDepict.OEDrawSVGToggleText(disp, adisp, toggletext, font);
}
OEDepict.OERenderMolecule("ToggleAtomText.svg", disp);

Download code

ToggleAtomText.cs

click on any atoms

Example of using the OEDrawSVGToggleText function for atom positions

../../_images/ToggleAtomText.svg

uint width  = 400;
uint height = 200;

OEImage image = new OEImage(width, height);

OEGraphMol mol = new OEGraphMol();
OEChem.OESmilesToMol(mol, "Cc1cccnc1/C=C/[C@H](C(=O)O)O");
OEDepict.OEPrepareDepiction(mol);

OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
opts.SetMargins(10);
OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);

OEFont font = new OEFont(OEFontFamily.Default, OEFontStyle.Default, 12,
                         OEAlignment.Center, OEChem.OEDarkRed);

foreach (OE2DBondDisplay bdisp in disp.GetBondDisplays())
{
    OEBondBase bond = bdisp.GetBond();
    String toggletext = "bond idx=" + bond.GetIdx().ToString();
    OEDepict.OEDrawSVGToggleText(disp, bdisp, toggletext, font);
}
OEDepict.OERenderMolecule("ToggleBondText.svg", disp);

Download code

ToggleBondText.cs

click on the middle of any bonds

Example of using the OEDrawSVGToggleText function for bond positions

../../_images/ToggleBondText.svg

See also