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.

  const unsigned int width  = 400u;
  const unsigned int height = 200u;

  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, 12u, OEAlignment::Center, OEDarkRed);

  for (OEIter<OE2DAtomDisplay> ai = disp.GetAtomDisplays(); ai; ++ai)
  {
    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);

Download code

ToggleAtomText.cpp

click on any atoms

Example of using the OEDrawSVGToggleText function for atom positions

../../_images/ToggleAtomText.svg

  const unsigned int width  = 400u;
  const unsigned int height = 200u;

  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)
  {
    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);

Download code

ToggleBondText.cpp

click on the middle of any bonds

Example of using the OEDrawSVGToggleText function for bond positions

../../_images/ToggleBondText.svg

See also