#!/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 CreateGrid(image):

    rows, cols = 3, 3
    grid = oedepict.OEImageGrid(image, rows, cols)
    grid.SetCellGap(5)
    grid.SetMargins(0)

    for cell in grid.GetCells():
        oedepict.OEDrawBorder(cell, oedepict.OERedPen)

    return grid


pen = oedepict.OEPen(oechem.OEColor(225, 200, 200), oechem.OERed, oedepict.OEFill_On, 1.0)

image = oedepict.OEImage(100, 100)
image.Clear(oechem.OELightGrey)
grid = CreateGrid(image)

i = 1
# @ <SNIPPET-OEIMAGEGRID-GETCELLS-ALL>
for cell in grid.GetCells():
    pass
# @ </SNIPPET-OEIMAGEGRID-GETCELLS-ALL>
    oedepict.OEDrawBorder(cell, pen)
    font = oedepict.OEFont()
    c = oedepict.OE2DPoint(cell.GetWidth(), cell.GetHeight() + font.GetSize())
    cell.DrawText(c / 2.0, "(%d)" % i, font)
    i += 1

oedepict.OEWriteImage("ImageGridIter-all.png", image)
oedepict.OEWriteImage("ImageGridIter-all.pdf", image)


image = oedepict.OEImage(100, 100)
image.Clear(oechem.OELightGrey)
grid = CreateGrid(image)

i = 1
# @ <SNIPPET-OEIMAGEGRID-GETCELLS-ROW>
row = 2
for cell in grid.GetCells(row, 0):
    pass
# @ </SNIPPET-OEIMAGEGRID-GETCELLS-ROW>
    oedepict.OEDrawBorder(cell, pen)
    font = oedepict.OEFont()
    c = oedepict.OE2DPoint(cell.GetWidth(), cell.GetHeight() + font.GetSize())
    cell.DrawText(c / 2.0, "(%d)" % i, font)
    i += 1

oedepict.OEWriteImage("ImageGridIter-row.png", image)
oedepict.OEWriteImage("ImageGridIter-row.pdf", image)

image = oedepict.OEImage(100, 100)
image.Clear(oechem.OELightGrey)
grid = CreateGrid(image)

i = 1
# @ <SNIPPET-OEIMAGEGRID-GETCELLS-COL>
col = 2
for cell in grid.GetCells(0, col):
    pass
# @ </SNIPPET-OEIMAGEGRID-GETCELLS-COL>
    oedepict.OEDrawBorder(cell, pen)
    font = oedepict.OEFont()
    c = oedepict.OE2DPoint(cell.GetWidth(), cell.GetHeight() + font.GetSize())
    cell.DrawText(c / 2.0, "(%d)" % i, font)
    i += 1

oedepict.OEWriteImage("ImageGridIter-col.png", image)
oedepict.OEWriteImage("ImageGridIter-col.pdf", image)
