import pickle
import bpy
import math
from bpy.types import Node
# from . import Node


class GridSurface():
	def __init__(self):
		_data = {}
		self.totalX = 10
		self.totalY = 10
		self.cellSizeMeters = 1

	def get(self, x, y):
		'''Retourne None si en dehors des limites ou si rien de spécifié encore sur la grille à cet endroit'''
		try:
			return self._data[(x, y)]
		except KeyError:
			return None


# class GridSurfaceNode(Node, Node):
# 	bl_label = 'Grid surface'
# 	length_x = bpy.props.IntProperty(
# 		name='Length X (meters)',
# 		description='Length of the grid along x',
# 		default=1000, min=0)
# 	length_y = bpy.props.IntProperty(
# 		name='Length Y (meters)',
# 		description='Length of the grid along y',
# 		default=1000, min=0)
# 	resolution = bpy.props.FloatProperty(
# 		name='Resolution (meters)',
# 		description='Side length of grid cells',
# 		default=1, min=0.01, max=100)
#
# 	pickled_grid_surface = bpy.props.StringProperty()
#
# 	def draw_buttons(self, context, layout):
# 		layout.prop(self, 'length_x')
# 		layout.prop(self, 'length_y')
# 		layout.prop(self, 'resolution')
# 		total_x = math.ceil(self.length_x / self.resolution)
# 		total_y = math.ceil(self.length_y / self.resolution)
# 		total = total_x * total_y
# 		layout.label(text='Resulting grid: {:,} x {:,} = {:,}'.format(total_x, total_y, total))
#
# 	def init(self, context):
# 		self.width = 300
# 		self.outputs.new('GridSurfaceSocket', 'Grid surface')
#
# 	def update(self):
# 		grid_surface = GridSurface()
# 		grid_surface.totalX = math.ceil(self.length_x / self.resolution)
# 		grid_surface.totalY = math.ceil(self.length_y / self.resolution)
# 		grid_surface.cellSizeMeters = self.resolution
# 		self.pickled_grid_surface = str(pickle.dumps(grid_surface))
