##Modul z klasami SubareaData i pomocniczymi wykorzystywanymi przez SubareaData
from Mapa_PU.swdl.model.converter import Converter
"""Klasa obiektow SubareaData
"""
class SubareaData(Converter):
     
    def __init__(self,id,address_forest,damage_degree,cause_cd,area_type_cd,position_cd,relief_cd,site_type_cd,degradation_cd,veg_cover_cd,
                 forest_func_cd,stand_struct_cd,slope_cd,exposure_cd,moisture_cd,soil_pec_cd,soil_sub_type_cd,plant_comm_cd,rotation_age,subarea,
                 subarea_info,altitude_min,altitude_max,accord_cd,silviculture_cd,reconstr_period,seed_base_nr,control_unit_cd,reconstr_cd,phase_cd):
        self.id=id
        self.address_forest=address_forest
        self.degradation_cd=self.to_upper(degradation_cd)
        self.damage_degree=damage_degree
        self.cause_cd=self.to_upper(cause_cd)
        self.area_type_cd=self.to_upper(area_type_cd)
        self.position_cd=self.to_upper(position_cd)
        self.relief_cd=self.to_upper(relief_cd)
        self.site_type_cd=self.to_upper(site_type_cd)
        self.veg_cover_cd=self.to_upper(veg_cover_cd)
        self.forest_func_cd=self.to_upper(forest_func_cd)
        self.stand_struct_cd=self.to_upper(stand_struct_cd)
        self.slope_cd=self.to_upper(slope_cd)
        self.exposure_cd=self.to_upper(exposure_cd)
        self.moisture_cd=self.to_upper(moisture_cd)
        self.soil_pec_cd=self.to_upper(soil_pec_cd)
        self.soil_sub_type_cd=self.to_upper(soil_sub_type_cd)
        self.plant_comm_cd=plant_comm_cd
        self.rotation_age=rotation_age
        self.subarea= round(subarea,4)      
        self.subarea_info=subarea_info
        self.altitude_max=altitude_max
        self.altitude_min=altitude_min
        self.__protect_areas=[]
        #TODO tych pól brakuje w pobieraniu
        self.accord_cd=self.to_upper(accord_cd)
        self.silviculture_cd=self.to_upper(silviculture_cd)
        self.reconstr_period=reconstr_period
        self.seed_base_nr=seed_base_nr
        self.control_unit_cd=control_unit_cd
        self.reconstr_cd=self.to_upper(reconstr_cd)
        self.phase_cd=self.to_upper(phase_cd)
        self.geometry=None
        
        
    #Kolekcje obiektów
    @property
    def arod_stand_pecs(self):
        return self.__arod_stand_pecs
    @arod_stand_pecs.setter
    def arod_stand_pecs(self,arod_stand_pecs):
        self.__arod_stand_pecs=arod_stand_pecs
        
    @property
    def arod_categories(self):
        return self.__arod_categories
    @arod_categories.setter
    def arod_categories(self,value):
        self.__arod_categories=value
        
    @property
    def arod_cues(self):
        return self.__arod_cues
    @arod_cues.setter
    def arod_cues(self,value):
        self.__arod_cues=value
        
    @property
    def arod_goals(self):
        return self.__arod_goals
    @arod_goals.setter
    def arod_goals(self,value):
        self.__arod_goals=value
        
    @property
    def arod_phenomenas(self):
        return self.__arod_phenomenas
    @arod_phenomenas.setter
    def arod_phenomenas(self,value):
        self.__arod_phenomenas=value
        
    @property
    def arod_soil_specs(self):
        return self.__arod_soil_specs
    @arod_soil_specs.setter
    def arod_soil_specs(self,value):
        self.__arod_soil_specs=value
        
    @property
    def arod_spec_areas(self):
        return self.__arod_spec_areas
    @arod_spec_areas.setter
    def arod_spec_areas(self,value):
        self.__arod_spec_areas=value
        
    @property
    def tree_layers(self):
        return self.__tree_layers
    @tree_layers.setter
    def tree_layers(self,value):
        self.__tree_layers=value
        
    @property
    def subarea_parcels(self):
        return self.__subarea_parcels
    @subarea_parcels.setter
    def subarea_parcels(self,value):
        self.__subarea_parcels=value
        
    @property
    def geometry(self):
        return self.__geometry
    @geometry.setter
    def geometry(self,value):
        self.__geometry=value
        
    @property
    def arod_spec_areas(self):
        return self.__arod_spec_areas
    @arod_spec_areas.setter
    def arod_spec_areas(self,value):
        self.__arod_spec_areas=value
    
    @property
    def subarea_ownership_structure(self):
        return self.__subarea_ownership_structure
    @subarea_ownership_structure.setter
    def subarea_ownership_structure(self,value):
        self.__subarea_ownership_structure=value
        
    @property
    def protect_areas(self)->[]:
        """Obszary chronione"""
        return self.__protect_areas
    @protect_areas.setter
    def protect_areas(self,value):
        self.__protect_areas=value    
    
    @property
    def done_measures(self):
        return []
    @done_measures.setter
    def done_measures(self,value):
        pass
    
    @property
    def damages_list(self):
        return []
    @damages_list.setter
    def damages_list(self,value):
        pass
    
    @property
    def random_samples(self):
        return []
    @random_samples.setter
    def random_samples(self,value):
        pass
    
    @property
    def arod_prot_sites(self):
        return []
    @arod_prot_sites.setter
    def arod_prot_sites(self,value):
        pass
    
    
        #TODO Do wyjasnienia
#         self.reconstr_period=''
#         self.silviculture_cd=''
#         self.degradation_cd=''
#         self.accord_cd='' nie ma pobrania z bazy
#         self.seed_base_nr=''
#         self.control_unit_cd=''
#         self.reconstr_cd=''#RECONSTR_CD
#         self.phase_cd='' #T PHASE_CD
#         self.damages_list=List()#F_AROD_DAMAGE, F_AROD_PEST?
#         self.random_samples=List()


#         self.arod_prot_sites=List()
#         
#         self.arod_spec_areas=List()

#         self.subarea_ownership_structure=List()
    
    
        
"""Obiekty subarea parcel
"""
class SubareaParcel():
    
    def __init__(self,id,parcel_nr,county_cd,district_cd,municipality_cd,community_cd,ownership_cd,parcel_area,regSheetNr2):
        self.id=id
        self.parcel_nr = parcel_nr
        self.county_cd = county_cd
        self.district_cd = district_cd
        self.municipality_cd = municipality_cd
        self.community_cd = community_cd
        self.ownership_cd = ownership_cd
        self.parcel_area = parcel_area
        self.regSheetNr2=regSheetNr2
        self.__geometry=None
        self.__executions=[]
        
    def set_parcel_land_use(self,ParcelLandUse):
        self.parcels_land_use=ParcelLandUse
    
    @property
    def executions(self)->[]:
        """Lista zabiegów wykonane na działce"""
        return self.__executions
    @executions.setter
    def executions(self,value:[]):
        self.__executions=value
        
    @property
    def geometry(self):
        """Geometria"""
        return self.__geometry
    @geometry.setter
    def geometry(self,value):
        self.__geometry=value
        
"""Obiekty Subarea Land Use
"""
class ParcelLandUse():
    def __init__(self,area_use_dic, soil_quality_dic,land_use_area,arod_land_use_area,for_afforestation,shape_nr):
        self.area_use_dic = area_use_dic
        self.soil_quality_dic = soil_quality_dic
        self.land_use_area = land_use_area
        self.arod_land_use_area = arod_land_use_area
        self.for_afforestation=for_afforestation
        self.shape_nr=shape_nr
        self.__geometry=None
        self.__land_use_measures=[]
        
    @property
    def geometry(self):
        """Geometria"""
        return self.__geometry
    @geometry.setter
    def geometry(self,value):
        self.__geometry=value
        
    @property
    def land_use_measures(self)->[]:
        """Zabiegi przypisane do użytku"""
        return self.__land_use_measures
    @land_use_measures.setter
    def land_use_measures(self,value:[]):
        self.__land_use_measures=value
    
"""Obiekty TreeLayer
"""
class TreeLayer(Converter):
    
        def __init__(self,id,storey_cd,stand_density_index,mixture_cd,density_cd, storey_rank_order,location_cd,tree_stock_cd,silv_quality_cd):
            self.id=id
            self.storey_cd = storey_cd
            self.stand_density_index= round(float(stand_density_index),2) if stand_density_index!=None else stand_density_index
            self.mixture_cd=self.to_upper(mixture_cd)
            self.density_cd=self.to_upper(density_cd)
            self.storey_rank_order = storey_rank_order
            #TODO brak danych
            self.location_cd=self.to_upper(location_cd)
            self.tree_stock_cd=self.to_upper(tree_stock_cd)
            self.silv_quality_cd=silv_quality_cd
        
        def set_layer_species(self,LayerSpecies):
            self.layer_species=LayerSpecies
            
"""Obiekty TreeSpecies
"""
class  TreeSpecies(Converter):
    
        def __init__(self,species_cd,volume_ha,part_cd,dbh,height,site_class_cd,species_age, species_rank_order,increment_ha,volume,increment,tech_quality_cd):
            self.species_cd = self.to_upper(species_cd)
            self.volume_ha=volume_ha
            self.part_cd=self.to_upper(part_cd)
            self.dbh=dbh
            self.height=height
            self.site_class_cd=self.to_upper(site_class_cd)
            self.species_age=species_age
            self.species_rank_order = species_rank_order
            self.increment_ha=increment_ha
            self.volume=volume
            self.increment=increment
            #TODO Brak pobrania danej
            self.tech_quality_cd=tech_quality_cd
  
       
"""Obiekt Goal
"""
class Goal(Converter):
    
    def __init__(self,id,goal_type_fl, species_cd, goal_rank_order,goal_species_perc):
        self.id=id
        self.goal_type_fl=goal_type_fl
        self.species_cd=self.to_upper(species_cd)
        self.goal_rank_order=goal_rank_order
        self.goal_species_perc=goal_species_perc
        
"""Obiekt Cue
"""
class Cue():
    def __init__(self,id,site_nr,measure_cd,urgency,cutting_nr,cutting_area,large_timber_perc,large_timber,large_timber_netto,cue_rank_order):
        self.id=id
        self.site_nr=site_nr
        self.measure_cd=measure_cd
        self.urgency=urgency
        self.cutting_nr=cutting_nr
        self.cutting_area=cutting_area
        self.large_timber_perc=large_timber_perc
        self.large_timber=large_timber
        self.large_timber_netto=large_timber_netto
        self.cue_rank_order=cue_rank_order
        
        
        
"""Obiekt Phenomena
"""  
class Phenomena(Converter):

    def __init__(self,id,phenomena_cd,location_cd,species_cd,plant_cd,phen_num,phen_area,nature_mon_fl):
        self.id=id
        self.phenomena_cd=self.to_upper(phenomena_cd)
        self.location_cd=self.to_upper(location_cd)
        self.species_cd=self.to_upper(species_cd)
        self.plant_cd=self.to_upper(plant_cd)
        self.phen_num=phen_num
        self.phen_area=phen_area
        self.nature_mon_fl=nature_mon_fl
        self.geometry=None
        
    def set_geometry(self,geometry):
        """Wstawia geometrie gml
        """
        self.geometry=geometry
  
"""Obiekt SoilSpec
"""      
class SoilSpec(Converter):
    
    def __init__(self,id,soil_species_cd, soil_level_dic_cd,soil_rank_order):
        self.id=id
        self.soil_species_cd=self.to_lower(soil_species_cd)
        self.soil_level_dic_cd=soil_level_dic_cd
        self.soil_rank_order=soil_rank_order

"""Obiekty SpecArea
"""
class SpecArea(Converter):
    def __init__(self,id,special_area_cd,location_cd,special_area,special_area_num,special_area_year,sparea_order,address_forest):
        self.id=id
        self.special_area_cd=special_area_cd
        self.location_cd=self.to_upper(location_cd)
        self.special_area=special_area
        self.special_area_num=special_area_num
        self.special_area_year=special_area_year
        self.county_cd=address_forest[0:1]
        self.district_cd=address_forest[1:3]
        self.municipality_cd=address_forest[3:6]
        self.community_cd=address_forest[6:10]
        self.__parcel_nr=None
        self.sparea_order=sparea_order
        self.geometry=None
        
    @property
    def parcel_nr(self):
        """Numer dzialki"""
        return self.__parcel_nr
    @parcel_nr.setter
    def parcel_nr(self,value):
        self.__parcel_nr=value 
    
    def set_species_spec_areas(self,species_spec_areas):
        ##Lista species spec area
        self.species_spec_areas=species_spec_areas
        
    def set_geometry(self,geometry):
        ##Geometria obiektu
        self.geometry=geometry
 
"""Obiekty Species Spec Area
"""        
class SpeciesSpecArea(Converter):
    def __init__(self,id,species_cd,species_age):
        self.id=id
        self.species_cd=self.to_upper(species_cd)
        self.species_age=species_age

"""Obiekty ArodCategory
"""
class ArodCategory(Converter):
    def __init__(self,id,category_cd,category_rank_order):
        self.id=id
        self.category_cd=self.to_upper(category_cd)
        self.category_rank_order=category_rank_order
        
"""Obiekty ArodStandPec
"""
class ArodStandPec(Converter):
    def __init__(self,id,forest_pec_cd):
        self.id=id
        self.forest_pec_cd=self.to_upper(forest_pec_cd)

class OwnershipShare():
    def __init__(self,id,ownership_category_gus,share,share_area):
        self.id=id
        self.ownership_category_gus=ownership_category_gus
        self.share=share
        self.share_area=share_area
        
class ParcelExecution():
    """Zabieg wykonany na działce"""
    def __init__(self,measure_cd,hintRankOrder,executionArea,outOfPlan,executionYear,certyficate):
        self.measure_cd=measure_cd
        self.hintRankOrder=hintRankOrder
        self.executionArea=executionArea
        self.outOfPlan=outOfPlan
        self.executionYear=executionYear
        self.certyficate=certyficate
    
class LandUseMeasure():
    """Zabiegi przypisdane do użytku"""
    def __init__(self,measure_cd,large_timber,large_timber_netto,cue_area_div,cue_rank_order):
        self.measure_cd=measure_cd
        self.large_timber=large_timber
        self.large_timber_netto=large_timber_netto
        self.cue_area_div=cue_area_div
        self.cue_rank_order=cue_rank_order
    
class ProtectArea(Converter):
    """Obszary chronione"""
    def __init__(self,protect_area_cd,protect_area_name):
        self.protect_area_cd=self.to_upper(protect_area_cd)
        self.protect_area_name=protect_area_name
        

        