|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies. |
| 3 | +# SPDX-FileContributor: Martin Lemay, Romain Baville |
| 4 | +# ruff: noqa: E402 # disable Module level import not at top of file |
| 5 | +import sys |
| 6 | +from pathlib import Path |
| 7 | +from typing import Union, Any |
| 8 | +from typing_extensions import Self |
| 9 | + |
| 10 | +# from functools import wraps |
| 11 | +# from dataclasses import dataclass |
| 12 | + |
| 13 | +from paraview.util.vtkAlgorithm import ( # type: ignore[import-not-found] |
| 14 | + VTKPythonAlgorithmBase, smdomain, smhint, smproperty, smproxy, |
| 15 | +) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/util/vtkAlgorithm.py |
| 16 | +from paraview.detail.loghandler import ( # type: ignore[import-not-found] |
| 17 | + VTKHandler, |
| 18 | +) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py |
| 19 | + |
| 20 | +from vtkmodules.vtkCommonDataModel import ( |
| 21 | + vtkMultiBlockDataSet, ) |
| 22 | + |
| 23 | +from vtkmodules.vtkCommonCore import ( |
| 24 | + vtkInformation, |
| 25 | + vtkInformationVector, |
| 26 | +) |
| 27 | + |
| 28 | +# update sys.path to load all GEOS Python Package dependencies |
| 29 | +geos_pv_path: Path = Path( __file__ ).parent.parent.parent.parent.parent |
| 30 | +sys.path.insert( 0, str( geos_pv_path / "src" ) ) |
| 31 | +from geos.pv.utils.config import update_paths |
| 32 | + |
| 33 | +update_paths() |
| 34 | + |
| 35 | +__doc__ = """ |
| 36 | +Set of decorators that allow: |
| 37 | + - quicker generation of MultiBlockDataSet to MultiBlockDataSet filters |
| 38 | + - more stable logger strategy |
| 39 | +
|
| 40 | +Usage is: |
| 41 | +
|
| 42 | + @SISO(name='MyFilter',label='This is my filter',dtype='vtkMultiBlockDataSet') |
| 43 | + class PVMyFilter: |
| 44 | + ... |
| 45 | + def __hidden_layer(self): |
| 46 | + |
| 47 | +
|
| 48 | +""" |
| 49 | + |
| 50 | +def SISOFilter(decorated_name, decorated_label, decorated_type): |
| 51 | + """ |
| 52 | + Decorate single input single output filter |
| 53 | + """ |
| 54 | + def decorated_class(cls): |
| 55 | + @smproxy.filter( name=decorated_name, label=decorated_label ) |
| 56 | + @smhint.xml( '<ShowInMenu category="4- Geos Utils"/>' ) |
| 57 | + @smproperty.input( name="Input", port_index=0 ) |
| 58 | + @smdomain.datatype( |
| 59 | + dataTypes=[ decorated_type ], |
| 60 | + composite_data_supported=True, |
| 61 | + ) |
| 62 | + # @dataclass |
| 63 | + # class WrappingClass(cls): |
| 64 | + class WrappingClass(cls,VTKPythonAlgorithmBase): |
| 65 | + |
| 66 | + def __init__(self,*ar,**kw): |
| 67 | + VTKPythonAlgorithmBase.__init__(self, nInputPorts=1, |
| 68 | + nOutputPorts=1, |
| 69 | + inputType=decorated_type, |
| 70 | + outputType=decorated_type ) |
| 71 | + cls.___init__(self,*ar,**kw) |
| 72 | + WrappingClass.__name__ = cls.__name__ |
| 73 | + WrappingClass.__module__ = cls.__module__ |
| 74 | + |
| 75 | + return WrappingClass |
| 76 | + return decorated_class |
| 77 | + |
| 78 | + |
| 79 | + |
0 commit comments