""" 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 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 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] vegetations = [] for vegetation_category in catalog_data.vegetationCategories: 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) @property def names(self): """ :parm: """ _names = [] 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) return _names def get_entry(self, name): return 'value' @property def entries(self): pass