2022-03-03 16:52:01 -05:00
|
|
|
"""
|
|
|
|
Greenery catalog
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2022 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
|
|
"""
|
|
|
|
|
|
|
|
from pyecore.resources import ResourceSet, URI
|
|
|
|
from catalogs.greenery.ecore_greenery.greenerycatalog import GreeneryCatalog as gc
|
|
|
|
from catalogs.catalog import Catalog
|
|
|
|
from pathlib import Path
|
2022-03-08 20:25:50 -05:00
|
|
|
from catalogs.data_model.greenery.vegetation import Vegetation as libs_vegetation
|
|
|
|
from catalogs.data_model.greenery.plant import Plant as libs_plant
|
|
|
|
from catalogs.data_model.greenery.soil import Soil as libs_soil
|
|
|
|
from catalogs.data_model.greenery.plant_percentage import PlantPercentage as libs_pp
|
|
|
|
from catalogs.data_model.greenery.greenery_content import GreeneryContent
|
2022-03-03 16:52:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
class GreeneryCatalog(Catalog):
|
|
|
|
|
|
|
|
def __init__(self, path):
|
|
|
|
base_path = Path(Path(__file__).parent / 'ecore_greenery' / 'greenerycatalog_no_quantities.ecore')
|
|
|
|
resource_set = ResourceSet()
|
|
|
|
data_model = resource_set.get_resource(URI(str(base_path)))
|
|
|
|
data_model_root = data_model.contents[0]
|
|
|
|
resource_set.metamodel_registry[data_model_root.nsURI] = data_model_root
|
|
|
|
resource = resource_set.get_resource(URI(str(path)))
|
|
|
|
catalog_data: gc = resource.contents[0]
|
2022-03-08 20:25:50 -05:00
|
|
|
|
|
|
|
vegetations = []
|
2022-03-03 16:52:01 -05:00
|
|
|
for vegetation_category in catalog_data.vegetationCategories:
|
2022-03-08 20:25:50 -05:00
|
|
|
name = vegetation_category.name
|
|
|
|
for vegetation in vegetation_category.vegetationTemplates:
|
|
|
|
plant_percentages = []
|
|
|
|
|
|
|
|
for plant_percentage in vegetation.plants:
|
|
|
|
plant_percentages.append(libs_pp(plant_percentage.percentage, plant_percentage.plant))
|
|
|
|
vegetations.append(libs_vegetation(name, vegetation, plant_percentages))
|
|
|
|
plants = []
|
|
|
|
for plant_category in catalog_data.plantCategories:
|
|
|
|
name = plant_category.name
|
|
|
|
for plant in plant_category.plants:
|
|
|
|
plants.append(libs_plant(name, plant))
|
|
|
|
|
|
|
|
soils = []
|
|
|
|
for soil in catalog_data.soils:
|
|
|
|
soils.append(libs_soil(soil))
|
|
|
|
|
|
|
|
self._data = GreeneryContent(vegetations, plants, soils)
|
2022-03-03 16:52:01 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def names(self):
|
|
|
|
"""
|
|
|
|
:parm:
|
|
|
|
"""
|
|
|
|
_names = []
|
2022-03-08 20:25:50 -05:00
|
|
|
for vegetation in self._data.vegetations:
|
|
|
|
_names.append(vegetation.name)
|
|
|
|
for plant in self._data.plants:
|
|
|
|
_names.append(plant.name)
|
|
|
|
for soil in self._data.soils:
|
|
|
|
_names.append(soil.name)
|
2022-03-03 16:52:01 -05:00
|
|
|
return _names
|
|
|
|
|
2022-03-08 20:25:50 -05:00
|
|
|
def get_entry(self, name):
|
|
|
|
return 'value'
|
2022-03-03 16:52:01 -05:00
|
|
|
|
2022-03-08 20:25:50 -05:00
|
|
|
@property
|
|
|
|
def entries(self):
|
|
|
|
pass
|