# -*- coding: utf-8 -*-
"""
Created on Wed Aug  1 09:26:57 2018

@author: Lonnie
"""

import numpy as np
from scipy.spatial import Delaunay
import Analytica_Python
import AnalyticaPythonConnector

class DelaunayCOM:
    _reg_clsid_ = "{B524651C-71B2-4521-9E9D-8CC470E51B24}"
    _reg_desc_ = "COM component that computes a Delaunay tesselation"   
    _reg_progid_ = "Lumina.DelaunayCOM"    
    _reg_class_spec_ = "DelaunayCOM.DelaunayCOM"
    _public_methods_ = ['Tessellation','Pause']
    _public_attrs_ = ['softspace', 'noCalls']
    _readonly_attrs_ = ['noCalls']

    def __init__(self):
        print("New " + self.__class__.__name__)
        self.softspace = 1
        self.noCalls = 0

    def Pause(self):
        Analytica_Python.gBreakPump = True
        
    def Tessellation(self,pts):
        print("Computing Tessellation of %d points" % (len(pts)))
        tri = Delaunay(np.array(pts))
        return tri.simplices.tolist()

Analytica_Python.AddCOMClass(DelaunayCOM)

print("Loading %s with __name__=%s" % (__file__, __name__))

if __name__ == "__main__":
    Analytica_Python.TopLevelServer(__file__)