from ..properties.descriptor import restricted_set_function_property
from ..properties.predefined import RESTRICT_NUMBER, RESTRICT_POSITIVE
from ..properties.initializer import strong_property_initializer
__all__ = []
class unit_grid_container(strong_property_initializer):

    def set_grid(self, value):
        self.__grid__ = value
        if hasattr(self, '__unit__') and not self.__unit__ == None:
            self.__grids_per_unit = self.__unit__/ value
            self.__units_per_grid = value / self.__unit__


    def set_unit (self,value ):
        self.__unit__ = value
        if hasattr(self, '__grid__') and not self.__grid__ == None:
            self.__grids_per_unit = value / self.__grid__
            self.__units_per_grid = self.__grid__ / value

    
    unit = restricted_set_function_property("__unit__", set_unit, restriction = RESTRICT_NUMBER & RESTRICT_POSITIVE, default = 1E-6)
    grid = restricted_set_function_property("__grid__", set_grid, restriction = RESTRICT_NUMBER & RESTRICT_POSITIVE, default = 1E-9)

    def get_grids_per_unit(self):
        return self.__grids_per_unit

    def get_units_per_grid(self):
        return self.__units_per_grid

    grids_per_unit = property(get_grids_per_unit)
    units_per_grid = property(get_units_per_grid)