def get_or_create_esi_qau(esh: EnergySystemHandler, active_es_id: str) -> esdl.QuantityAndUnits: es: esdl.EnergySystem = esh.get_energy_system(active_es_id) if not es.energySystemInformation: esi: esdl.EnergySystemInformation = esdl.EnergySystemInformation( id=str(uuid4())) es.energySystemInformation = esi esh.add_object_to_dict(active_es_id, esi) if not es.energySystemInformation.quantityAndUnits: qaus = esdl.QuantityAndUnits(id=str(uuid4())) es.energySystemInformation.quantityAndUnits = qaus esh.add_object_to_dict(active_es_id, qaus) return es.energySystemInformation.quantityAndUnits
def duplicate_energy_asset(esh: EnergySystemHandler, es_id, energy_asset_id: str): original_asset = esh.get_by_id(es_id, energy_asset_id) duplicate_asset = original_asset.deepcopy() # reset all id's for c in duplicate_asset.eContents: if c.eClass.findEStructuralFeature('id'): if c.eGet('id'): c.eSet('id', str(uuid4())) duplicate_asset.id = str(uuid4()) name = original_asset.name + '_ret' if original_asset.name.endswith('_ret'): name = original_asset.name[:-4] + '_sup' if original_asset.name.endswith('_sup'): name = original_asset.name[:-4] + '_ret' if not isinstance( duplicate_asset, Pipe): # do different naming for other conductors then pipes name = '{}_{}'.format(original_asset.name, 'copy') duplicate_asset.name = name geometry = duplicate_asset.geometry if isinstance(geometry, Line): line: Line = geometry # geometry.clone() rev_point = list(reversed(line.point)) # reverse coordinates line.point.clear() line.point.extend(rev_point) for p in line.point: _shift_point(p) if isinstance(geometry, Point): _shift_point(geometry) # disconnect the ports as also the connectedTo has been duplicated, we need to remove this reference for port in duplicate_asset.port: port.connectedTo.clear() esh.add_object_to_dict(es_id, duplicate_asset, recursive=True) # add to UUID registry return duplicate_asset
def duplicate_energy_asset(esh: EnergySystemHandler, es_id, energy_asset_id: str): original_asset = esh.get_by_id(es_id, energy_asset_id) duplicate_asset = original_asset.clone() duplicate_asset.id = str(uuid4()) name = original_asset.name + '_ret' if original_asset.name.endswith('_ret'): name = original_asset.name[:-4] + '_sup' if original_asset.name.endswith('_sup'): name = original_asset.name[:-4] + '_ret' if not isinstance(duplicate_asset, Pipe): # do different naming for other pipes name = '{}_{}'.format(original_asset.name, 'copy') duplicate_asset.name = name geometry = original_asset.geometry if isinstance(geometry, Line): line = geometry.clone() for p in geometry.point: point_clone = p.clone() _shift_point(point_clone) line.point.insert(0, point_clone) # reverse the list duplicate_asset.geometry = line if isinstance(geometry, Point): point_clone = geometry.clone() _shift_point(point_clone) duplicate_asset.geometry = point_clone for port in original_asset.port: newport = port.clone() newport.id = str(uuid4()) duplicate_asset.port.append(newport) esh.add_object_to_dict(es_id, newport) # add to UUID registry esh.add_object_to_dict(es_id, duplicate_asset) # add to UUID registry return duplicate_asset