Exemplo n.º 1
0
def generated_library(pygen_output_dir):
    rset = ResourceSet()
    resource = rset.get_resource(URI('input/library.ecore'))
    library_model = resource.contents[0]
    generator = EcoreGenerator()
    generator.generate(library_model, pygen_output_dir)
    return importlib.import_module('library')
def generated_metamodel(pygen_output_dir):
    rset = ResourceSet()
    resource = rset.get_resource(URI('input/A.ecore'))
    library_model = resource.contents[0]
    generator = EcoreGenerator(with_dependencies=True)
    generator.generate(library_model, pygen_output_dir)
    return importlib.import_module('a')
Exemplo n.º 3
0
def generate_meta_model(model,
                        output_dir,
                        *,
                        user_module=None,
                        auto_register_package=None):
    generator = EcoreGenerator(user_module=user_module,
                               auto_register_package=auto_register_package)
    generator.generate(model, output_dir)
    return importlib.import_module(model.name)
Exemplo n.º 4
0
def generate_code():
    def format_autopep8(raw: str) -> str:
        import autopep8
        return autopep8.fix_code(raw, options={'experimental': True})

    rset = setup_resourceset()
    uml_root = rset.get_resource('model/uml.ecore').contents[0]
    generator = EcoreGenerator(user_module='pyuml2.uml_mixins')
    for task in generator.tasks:
        task.formatter = format_autopep8
    generator.generate(uml_root, 'pyuml2')
Exemplo n.º 5
0
# This File reads the metamodel, reads the model and implements all
# the behavior of the Classes to introduce ROS code in every component
# Written in 14/2/2020
# Written by Rafael Brouzos

from pyecore.resources import ResourceSet, URI, global_registry
from pyecore.resources.json import JsonResource
from pyecore.ecore import EClass, EAttribute
import pyecore.ecore as Ecore
from pyecoregen.ecore import EcoreGenerator
import pyecore.behavior as behavior
from pyecore.utils import DynamicEPackage
import os

# We load the Ecore metamodel first
global_registry[Ecore.nsURI] = Ecore
rset = ResourceSet()
resource = rset.get_resource(URI('metageneros.ecore'))
# ~ rset.resource_factory['json'] = lambda uri: JsonResource(uri)
root = resource.contents[0]  # We get the root (an EPackage here)
# Register the metamodel (in case we open an XMI model later)
rset.metamodel_registry[root.nsURI] = root

# ~ model_root.hasPackages[0].package_init()
# ~ for x in model_root.hasPackages[0].allInstances():
# ~ print(x) # display 2 instances
# ~ os.chdir('/home/raf/Desktop/Thesis Project/ecoreWork')
generator = EcoreGenerator()
generator.generate(root, '')
Exemplo n.º 6
0
    kpi_costs = KPI(name="KPI Total costs",
                    value=None,
                    quantityAndUnit=costs_unit)

    # Add CO2-emissions and total costs KPIs to KPIs
    es.instance[0].area.KPIs.kpi.append(kpi_co2)
    es.instance[0].area.KPIs.kpi.append(kpi_costs)

    print("Energy system: {}".format(attr_to_dict(es)))
    print("OutPort connectedTo: {}".format(outPort.connectedTo))
    print("InPort connectedTo: {}".format(inPort.connectedTo))
    resource = rset.create_resource(URI('mpoc.esdl'))
    resource.append(es)
    resource.save()


if __name__ == '__main__':
    # Load the ESDL model from GitHub
    rset = ResourceSet()
    resource = rset.get_resource(
        HttpURI(
            'https://raw.githubusercontent.com/EnergyTransition/ESDL/master/esdl/model/esdl.ecore'
        ))
    esdl_model = resource.contents[0]

    # Generate the classes
    generator = EcoreGenerator()
    generator.generate(esdl_model, ".")

    main()