Example #1
0
 def get_object_info(self, esdl_object):
     esdl_object_descr = self.get_object_dict(esdl_object)
     container = esdl_object.eContainer()
     container_descr = self.get_container_dict(container)
     attributes = ESDLEcore.get_asset_attributes(esdl_object, self.esdl_doc)
     references = ESDLEcore.get_asset_references(esdl_object, self.esdl_doc,
                                                 ESDLBrowser.generate_repr)
     return {
         'object': esdl_object_descr,
         'attributes': attributes,
         'references': references,
         'container': container_descr
     }
 def get_browse_to_data(self, esdl_object):
     active_es_id = get_session('active_es_id')
     esdl_object_descr = self.get_object_dict(esdl_object)
     container = esdl_object.eContainer()
     container_descr = self.get_container_dict(container)
     attributes = ESDLEcore.get_asset_attributes(esdl_object, self.esdl_doc)
     references = ESDLEcore.get_asset_references(esdl_object, self.esdl_doc, ESDLBrowser.generate_repr)
     parent_asset_id = self.calculate_parent_energy_asset_id(esdl_object)
     return {'es_id': active_es_id,
             'object': esdl_object_descr,
             'attributes': attributes,
             'references': references,
             'container': container_descr,
             'parent_asset_id': parent_asset_id}
 def socket_io_list_references(message):
     reference_name = message['name']
     parent_object: EObject = self.get_object_from_identifier(message['parent'])
     root = parent_object.eRoot()
     reference = parent_object.eClass.findEStructuralFeature(reference_name)
     if reference is not None:
         types = ESDLEcore.find_types(reference)
         print("Creating list of references")
         reference_list = ESDLEcore.get_reachable_references(root, types, repr_function=ESDLBrowser.generate_repr)
         returnmsg = {'parent': message['parent'],
                      'ref': {'name': reference_name, 'type': reference.eType.eClass.name},
                      'xreferences': reference_list}
         print (returnmsg)
         emit('esdl_browse_select_cross_reference', returnmsg, namespace='/esdl')
 def socketio_create_object(message):
     # {'parent': {'id': parent_object.id, 'fragment': parent_object.fragment}, 'name': reference_data.name, 'type': types[0]}
     esh = get_handler()
     active_es_id = get_session('active_es_id')
     parent_object = self.get_object_from_identifier(message['parent'])
     reference_name = message['name']
     attribute = parent_object.eClass.findEStructuralFeature(reference_name)
     if attribute is not None:
         object_type = message['type']
         new_object = ESDLEcore.instantiate_type(object_type)
         if attribute.many:
             eOrderedSet = parent_object.eGet(reference_name)
             eOrderedSet.append(new_object)
         else:
             parent_object.eSet(reference_name, new_object)
     else:
         print("Error: Can't find reference {} of {}", reference_name, parent_object.name)
         return
     if hasattr(new_object, 'id'):
         new_object.id = esh.generate_uuid()
         esh.add_object_to_dict(active_es_id, new_object)
         print('adding to uuid dict ' + new_object.id)
     if hasattr(new_object, 'name'):
         new_object.name = 'New' + new_object.eClass.name
     browse_data = self.get_browse_to_data(new_object)
     emit('esdl_browse_to', browse_data, namespace='/esdl')
Example #5
0
 def delete_ref(self, message: DeleteRefMessage):
     parent_object = self.get_object_from_identifier(message.parent)
     esh = get_handler()
     active_es_id = get_session('active_es_id')
     reference: EReference = parent_object.eClass.findEStructuralFeature(
         message.ref_name)
     ref_object = parent_object.eGet(reference)
     print('deleting', message, ref_object)
     if reference.containment:
         try:
             esh.remove_object_from_dict(active_es_id, ref_object, True)
             resource = esh.get_resource(active_es_id)
             fragment = ref_object.eURIFragment()
             del resource._resolve_mem[
                 fragment]  # update fragment cache for pyecore<0.12.0
         except KeyError as e:
             print('ESDL Browser: can\'t delete id from uuid_dict', e)
         ref_object.delete(
             recursive=True
         )  # will automatically remove the reference from the list
     else:
         if reference.many:
             eOrderedSet = parent_object.eGet(reference)
             eOrderedSet.remove(ref_object)
         else:
             parent_object.eSet(reference, reference.get_default_value())
     # send updated reference description to frontend
     response = ESDLEcore.describe_reference_value(
         parent_object.eGet(reference), ESDLBrowser.generate_repr)
     print('delete ref response', response)
     return response
Example #6
0
        def essim_sensitivity_asset_info(id):
            with self.flask_app.app_context():
                esh = get_handler()
                active_es_id = get_session('active_es_id')
                asset = esh.get_by_id(active_es_id, id)

                asset_info = dict()
                asset_info['attrs_sorted'] = ESDLEcore.get_asset_attributes(asset)
                asset_info['port_profile_list'] = get_port_profile_info(asset)

                return asset_info
Example #7
0
    def get_filtered_type(self, esdl_object, reference):
        """
        :param EObject esdl_object: the esdl class instance (e.g. 'esdl.WindTurbine')
        :param EReference reference: the reference to find the possible types for (e.g. 'controlStrategy')

        :return: list of possible types
        """
        types = []
        reference_type = reference.eType
        if isinstance(reference_type, esdl.ControlStrategy):
            if isinstance(esdl_object, esdl.Producer):
                types.append(esdl.CurtailmentStrategy.eClass.name)
            if isinstance(esdl_object, esdl.Storage):
                types.append(esdl.StorageStrategy.eClass.name)
            if isinstance(esdl_object, esdl.Conversion):
                types.append(esdl.DrivenByDemand.eClass.name)
                types.append(esdl.DrivenBySupply.eClass.name)
                types.append(esdl.DrivenByProfile.eClass.name)
        else:
            types = ESDLEcore.find_types(reference)
        return types