#!/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

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


def DrawFigure(image, pen):

    w = image.GetWidth()
    h = image.GetHeight()
    image.Clear(oechem.OEWhite)

    a = oedepict.OE2DPoint(10.0, 10.0)
    b = oedepict.OE2DPoint(w - 10, h - 10.0)
    image.DrawRectangle(a, b, pen)

    a = oedepict.OE2DPoint(20.0, 20.0)
    b = oedepict.OE2DPoint(w - 20, h - 20.0)
    image.DrawLine(a, b, pen)

    a = oedepict.OE2DPoint(60.0, 20.0)
    b = oedepict.OE2DPoint(20.0, 60.0)
    image.DrawLine(a, b, pen)


def DrawFigures(pen, basefilename):

    image = oedepict.OEImage(80, 80)
    DrawFigure(image, pen)

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


pen = oedepict.OEPen()
DrawFigures(pen, "OEPen_Default")

# @ <SNIPPET-OEPEN-SET-FORECOLOR>
pen = oedepict.OEPen()
pen.SetForeColor(oechem.OERed)
# @ </SNIPPET-OEPEN-SET-FORECOLOR>
DrawFigures(pen, "OEPen_SetForeColor")

# @ <SNIPPET-OEPEN-SET-BACKCOLOR>
pen = oedepict.OEPen()
pen.SetFill(oedepict.OEFill_On)
pen.SetBackColor(oechem.OEBlueTint)
# @ </SNIPPET-OEPEN-SET-BACKCOLOR>
DrawFigures(pen, "OEPen_SetBackColor")


# @ <SNIPPET-OEPEN-SET-LINECAP>
pen = oedepict.OEPen()
pen.SetLineWidth(4)
pen.SetLineCap(oedepict.OELineCap_Square)
# @ </SNIPPET-OEPEN-SET-LINECAP>
DrawFigures(pen, "OEPen_SetLineCap")

# @ <SNIPPET-OEPEN-SET-LINEJOIN>
pen = oedepict.OEPen()
pen.SetLineWidth(4)
pen.SetLineJoin(oedepict.OELineJoin_Miter)
# @ </SNIPPET-OEPEN-SET-LINEJOIN>
DrawFigures(pen, "OEPen_SetLineJoin")

# @ <SNIPPET-OEPEN-SET-LINE-WIDTH>
pen = oedepict.OEPen()
pen.SetLineWidth(5.0)
# @ </SNIPPET-OEPEN-SET-LINE-WIDTH>
DrawFigures(pen, "OEPen_SetLineWidth")

# @ <SNIPPET-OEPEN-SET-LINE-STIPPLE>
pen = oedepict.OEPen()
pen.SetLineStipple(oedepict.OEStipple_ShortDash)
# @ </SNIPPET-OEPEN-SET-LINE-STIPPLE>
DrawFigures(pen, "OEPen_SetLineStipple")

# @ <SNIPPET-OEPEN-SET-STIPPLE-FACTOR>
pen = oedepict.OEPen()
pen.SetLineStipple(oedepict.OEStipple_ShortDash)
pen.SetStippleFactor(2)
# @ </SNIPPET-OEPEN-SET-STIPPLE-FACTOR>
DrawFigures(pen, "OEPen_SetStippleFactor")
