OEDrawSVGToggleTextΒΆ

Attention

PRELIMINARY-IMAGE This is a preliminary API until 2018.Feb and may be improved based on user feedback. It is currently available in C++ and Python.

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

bool OEDrawSVGToggleText(OE2DMolDisplay &disp, const 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 the given text will be rendered to the given position permanently.

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.
#include <openeye.h>

#include <oesystem.h>
#include <oechem.h>
#include <oedepict.h>

using namespace std;
using namespace OESystem;
using namespace OEChem;
using namespace OEDepict;

int main()
{
  const unsigned int width  = 400;
  const unsigned int height = 200;

  OEImage image(width, height);

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

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

  OEFont font(OEFontFamily::Default, OEFontStyle::Default, 12, OEAlignment::Center, OEDarkRed);

  for (OEIter<OE2DAtomDisplay> ai = disp.GetAtomDisplays(); ai; ++ai)
  {
    const OE2DAtomDisplay* adisp = ai;
    const OEAtomBase* atom = adisp->GetAtom();
    const string toggletext = "atom idx=" + OENumberToString(atom->GetIdx());
    OEDrawSVGToggleText(disp, adisp, toggletext, font);
  }
  OERenderMolecule("ToggleAtomText.svg", disp);

  return 0;
}

Download code

ToggleAtomText.cpp

click on any atoms

Example of using the OEDrawSVGToggleText function for atom positions

#include <openeye.h>

#include <oesystem.h>
#include <oechem.h>
#include <oedepict.h>

using namespace std;
using namespace OESystem;
using namespace OEChem;
using namespace OEDepict;

int main()
{
  const unsigned int width  = 400;
  const unsigned int height = 200;

  OEImage image(width, height);

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

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

  OEFont font(OEFontFamily::Default, OEFontStyle::Default, 12, OEAlignment::Center, OEDarkRed);

  for (OEIter<OE2DBondDisplay> bi = disp.GetBondDisplays(); bi; ++bi)
  {
    const OE2DBondDisplay* bdisp = bi;
    const OEBondBase* bond = bdisp->GetBond();
    const string toggletext = "bond idx=" + OENumberToString(bond->GetIdx());
    OEDrawSVGToggleText(disp, bdisp, toggletext, font);
  }
  OERenderMolecule("ToggleBondText.svg", disp);

  return 0;
}

Download code

ToggleBondText.cpp

click on the middle of any bonds

Example of using the OEDrawSVGToggleText function for bond positions

See also