#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable OpenEye offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################


def DepictColorGradient(colorg, opts, basefilename):

    width, height = 400, 100
    image = oedepict.OEImage(width, height)
    oegrapheme.OEDrawColorGradient(image, colorg, opts)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)

########################################################################
#
########################################################################


width, height = 400, 100
image = oedepict.OEImage(width, height)

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-DEFAULT>
colorg = oechem.OELinearColorGradient(oechem.OEColorStop(0.0, oechem.OEYellow))
colorg.AddStop(oechem.OEColorStop(+1.0, oechem.OEOrange))
colorg.AddStop(oechem.OEColorStop(-1.0, oechem.OEGreen))
opts = oegrapheme.OEColorGradientDisplayOptions()
oegrapheme.OEDrawColorGradient(image, colorg)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-DEFAULT>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_Default")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-COLORSTOPLABELFONT>
opts = oegrapheme.OEColorGradientDisplayOptions()
font = oedepict.OEFont()
font.SetColor(oechem.OEDarkGreen)
font.SetStyle(oedepict.OEFontStyle_Bold)
opts.SetColorStopLabelFont(font)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-COLORSTOPLABELFONT>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetColorStopLabelFont")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-COLORSTOPLABELFONTSCALE>
opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetColorStopLabelFontScale(0.5)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-COLORSTOPLABELFONTSCALE>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetColorStopLabelFontScale")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-COLORSTOPPRECISION>
opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetColorStopPrecision(4)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-COLORSTOPPRECISION>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetColorStopPrecision")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-COLORSTOPVISIBILITY>
opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetColorStopVisibility(False)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-COLORSTOPVISIBILITY>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetColorStopVisibility")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-BOXRANGE>
opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetBoxRange(-0.5, 0.5)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-BOXRANGE>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetBoxRange")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-BOXRANGEPEN>
opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetBoxRange(-0.5, 0.5)
pen = oedepict.OEPen(oechem.OEBlack, oechem.OEBlack, oedepict.OEFill_On,
                     2.0, oedepict.OEStipple_ShortDash)
opts.SetBoxRangePen(pen)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-BOXRANGEPEN>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetBoxRangePen")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-ADDMARKEDVALUE>
opts = oegrapheme.OEColorGradientDisplayOptions()
opts.AddMarkedValue(0.20)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-ADDMARKEDVALUE>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_AddMarkedValue")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-ADDMARKEDVALUES>
opts = oegrapheme.OEColorGradientDisplayOptions()
markedvalues = oechem.OEDoubleVector([0.20, 0.70, 0.72])
opts.AddMarkedValues(markedvalues)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-ADDMARKEDVALUES>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_AddMarkedValues")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-SETMARKEDVALUES>
opts = oegrapheme.OEColorGradientDisplayOptions()
opts.AddMarkedValue(0.0)
markedvalues = oechem.OEDoubleVector([0.5, 0.75])
opts.SetMarkedValues(markedvalues)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-SETMARKEDVALUES>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetMarkedValues")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-MARKEDVALUEPRECISION>
opts = oegrapheme.OEColorGradientDisplayOptions()
markedvalues = oechem.OEDoubleVector([0.20, 0.70, 0.72])
opts.AddMarkedValues(markedvalues)
opts.SetMarkedValuePrecision(1)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-MARKEDVALUEPRECISION>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetMarkedValuePrecision")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-MARKEDVALUEPEN>
opts = oegrapheme.OEColorGradientDisplayOptions()
markedvalues = oechem.OEDoubleVector([0.20, 0.70, 0.72])
opts.AddMarkedValues(markedvalues)
pen = oedepict.OEPen(oechem.OEBlack, oechem.OEDarkGreen, oedepict.OEFill_On,
                     2.0, oedepict.OEStipple_ShortDash)
opts.SetMarkedValuePen(pen)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-MARKEDVALUEPEN>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetMarkedValuePen")

# @ <SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-ADDLABEL>
opts = oegrapheme.OEColorGradientDisplayOptions()
opts.AddLabel(oegrapheme.OEColorGradientLabel(-1.0, "dissimilar"))
opts.AddLabel(oegrapheme.OEColorGradientLabel(+1.0, "similar"))
oegrapheme.OEDrawColorGradient(image, colorg, opts)
# @ </SNIPPET-OECOLORGRADIENTDISPLAYOPTIONS-ADDLABEL>
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_AddLabel")
