#!/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 DrawCubicBezier():
    # @ <SNIPPET-CUBIC-BEZIER>
    image = oedepict.OEImage(100, 100)

    b = oedepict.OE2DPoint(20, 70)
    e = oedepict.OE2DPoint(60, 70)
    c1 = b + oedepict.OE2DPoint(50, -60)
    c2 = e + oedepict.OE2DPoint(50, -60)

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack, oedepict.OEFill_On, 2.0)
    image.DrawCubicBezier(b, c1, c2, e, pen)

    # @ </SNIPPET-CUBIC-BEZIER>
    oedepict.OEWriteImage("DrawCubicBezier.png", image)
    oedepict.OEWriteImage("DrawCubicBezier.pdf", image)


def DrawPath():
    # @ <SNIPPET-DRAW-PATH>
    image = oedepict.OEImage(100, 100)

    path = oedepict.OE2DPath(oedepict.OE2DPoint(20, 80))
    path.AddLineSegment(oedepict.OE2DPoint(80, 80))
    path.AddLineSegment(oedepict.OE2DPoint(80, 40))
    path.AddCurveSegment(oedepict.OE2DPoint(80, 10), oedepict.OE2DPoint(20, 10),
                         oedepict.OE2DPoint(20, 40))

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack, oedepict.OEFill_On, 2.0)
    image.DrawPath(path, pen)

    # @ </SNIPPET-DRAW-PATH>
    oedepict.OEWriteImage("DrawPath.png", image)
    oedepict.OEWriteImage("DrawPath.pdf", image)

    # @ <SNIPPET-GET-PATH-POINTS>
    for p in path.GetPoints():
        pos = p.GetPoint()
        print(" %.1f %.1f %d" % (pos.GetX(), pos.GetY(), p.GetPointType()))
    # @ </SNIPPET-GET-PATH-POINTS>


def DrawPolygon():
    # @ <SNIPPET-DRAW-POLYGON>
    image = oedepict.OEImage(100, 100)

    polygon = []
    polygon.append(oedepict.OE2DPoint(20, 20))
    polygon.append(oedepict.OE2DPoint(40, 40))
    polygon.append(oedepict.OE2DPoint(60, 20))
    polygon.append(oedepict.OE2DPoint(80, 40))
    polygon.append(oedepict.OE2DPoint(80, 80))
    polygon.append(oedepict.OE2DPoint(20, 80))

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack, oedepict.OEFill_On, 2.0)
    image.DrawPolygon(polygon, pen)
    # @ </SNIPPET-DRAW-POLYGON>
    oedepict.OEWriteImage("DrawPolygon.png", image)
    oedepict.OEWriteImage("DrawPolygon.pdf", image)


def DrawQuadraticBezier():
    # @ <SNIPPET-DRAW-QUADRATIC-BEZIER>
    image = oedepict.OEImage(100, 100)

    b = oedepict.OE2DPoint(20, 70)
    e = oedepict.OE2DPoint(80, 70)
    c = b + oedepict.OE2DPoint(30, -80)

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack, oedepict.OEFill_On, 2.0)
    image.DrawQuadraticBezier(b, c, e, pen)
    # @ </SNIPPET-DRAW-QUADRATIC-BEZIER>
    oedepict.OEWriteImage("DrawQuadraticBezier.png", image)
    oedepict.OEWriteImage("DrawQuadraticBezier.pdf", image)


DrawCubicBezier()
DrawPath()
DrawPolygon()
DrawQuadraticBezier()
