Skip to content

Commit 84c0ba8

Browse files
committed
PoC
1 parent 1a57322 commit 84c0ba8

File tree

3 files changed

+73
-39
lines changed

3 files changed

+73
-39
lines changed

geos-mesh/src/geos/mesh/processing/FillPartialArrays.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from geos.mesh.utils.arrayModifiers import fillPartialAttributes
1010
from geos.mesh.utils.arrayHelpers import getAttributePieceInfo
1111

12+
from geos.utils.details import addLogSupport
1213
from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet
1314

1415
__doc__ = """
@@ -51,13 +52,13 @@
5152
loggerTitle: str = "Fill Partial Attribute"
5253

5354

55+
@addLogSupport(loggerTitle= loggerTitle)
5456
class FillPartialArrays:
5557

5658
def __init__(
5759
self: Self,
5860
multiBlockDataSet: vtkMultiBlockDataSet,
5961
dictAttributesValues: dict[ str, Union[ list[ Any ], None ] ],
60-
speHandler: bool = False,
6162
) -> None:
6263
"""Fill partial attributes with constant value per component.
6364
@@ -75,30 +76,8 @@ def __init__(
7576
self.multiBlockDataSet: vtkMultiBlockDataSet = multiBlockDataSet
7677
self.dictAttributesValues: dict[ str, Union[ list[ Any ], None ] ] = dictAttributesValues
7778

78-
# Logger.
79-
self.logger: Logger
80-
if not speHandler:
81-
self.logger = getLogger( loggerTitle, True )
82-
else:
83-
self.logger = logging.getLogger( loggerTitle )
84-
self.logger.setLevel( logging.INFO )
8579

86-
def setLoggerHandler( self: Self, handler: logging.Handler ) -> None:
87-
"""Set a specific handler for the filter logger.
88-
89-
In this filter 4 log levels are use, .info, .error, .warning and .critical, be sure to have at least the same 4 levels.
90-
91-
Args:
92-
handler (logging.Handler): The handler to add.
93-
"""
94-
if not self.logger.hasHandlers():
95-
self.logger.addHandler( handler )
96-
else:
97-
self.logger.warning(
98-
"The logger already has an handler, to use yours set the argument 'speHandler' to True during the filter initialization."
99-
)
100-
101-
def applyFilter( self: Self ) -> bool:
80+
def applyFilter( self : Self ) -> bool:
10281
"""Create a constant attribute per region in the mesh.
10382
10483
Returns:

geos-pv/src/geos/pv/plugins/PVFillPartialArrays.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
update_paths()
3131

3232
from geos.mesh.processing.FillPartialArrays import FillPartialArrays
33-
import geos.pv.utils.details
33+
# import geos.pv.utils.details
3434
__doc__ = """
3535
Fill partial arrays of input mesh.
3636
@@ -47,22 +47,22 @@
4747
"""
4848

4949

50-
# @smproxy.filter( name="PVFillPartialArrays", label="Fill Partial Arrays" )
51-
# @smhint.xml( '<ShowInMenu category="4- Geos Utils"/>' )
52-
# @smproperty.input( name="Input", port_index=0 )
53-
# @smdomain.datatype(
54-
# dataTypes=[ "vtkMultiBlockDataSet" ],
55-
# composite_data_supported=True,
56-
# )
57-
@geos.pv.utils.details.SISOFilter(decorated_name="PVFillPartialArrays", decorated_label="Fill Partial Arrays",decorated_type="vtkMultiBlockDataSet")
58-
class PVFillPartialArrays:
50+
@smproxy.filter( name="PVFillPartialArrays", label="Fill Partial Arrays" )
51+
@smhint.xml( '<ShowInMenu category="4- Geos Utils"/>' )
52+
@smproperty.input( name="Input", port_index=0 )
53+
@smdomain.datatype(
54+
dataTypes=[ "vtkMultiBlockDataSet" ],
55+
composite_data_supported=True,
56+
)
57+
# @geos.pv.utils.details.SISOFilter(decorated_name="PVFillPartialArrays", decorated_label="Fill Partial Arrays",decorated_type="vtkMultiBlockDataSet")
58+
class PVFillPartialArrays(VTKPythonAlgorithmBase):
5959

6060
def __init__( self: Self, ) -> None:
6161
"""Fill a partial attribute with constant value per component."""
62-
# super().__init__( nInputPorts=1,
63-
# nOutputPorts=1,
64-
# inputType="vtkMultiBlockDataSet",
65-
# outputType="vtkMultiBlockDataSet" )
62+
super().__init__( nInputPorts=1,
63+
nOutputPorts=1,
64+
inputType="vtkMultiBlockDataSet",
65+
outputType="vtkMultiBlockDataSet" )
6666

6767
self.clearDictAttributesValues: bool = True
6868
self.dictAttributesValues: dict[ str, Union[ list[ Any ], None ] ] = {}
@@ -158,7 +158,7 @@ def RequestData(
158158

159159
filter: FillPartialArrays = FillPartialArrays( outputMesh,
160160
self.dictAttributesValues,
161-
True,
161+
speHandler=True,
162162
)
163163

164164
if not filter.logger.hasHandlers():
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import logging
2+
from geos.utils.Logger import Logger, getLogger
3+
from functools import wraps
4+
from typing import Type, TypeVar
5+
6+
7+
__doc__ = """
8+
Decorators
9+
10+
"""
11+
12+
def addLogSupport(loggerTitle : str):
13+
T = TypeVar('T')
14+
def decorator(cls:Type[T]) -> Type[T]:
15+
original_init = cls.__init__
16+
17+
@wraps(cls)
18+
def new_init(self : T, *args, **kwargs):
19+
20+
self.logger : Logger
21+
22+
if kwargs.get('speHandler'):
23+
kwargs.pop('speHandler')
24+
self.logger = logging.getLogger( loggerTitle )
25+
self.logger.setLevel( logging.INFO )
26+
else:
27+
self.logger = getLogger( loggerTitle, True)
28+
29+
original_init(self,*args,*kwargs)
30+
31+
@property
32+
def logger(self : T)->Logger:
33+
return self.logger
34+
35+
def setLoggerHandler(self, handler : logging.Handler):
36+
"""Set a specific handler for the filter logger.
37+
38+
In this filter 4 log levels are use, .info, .error, .warning and .critical, be sure to have at least the same 4 levels.
39+
40+
Args:
41+
handler (logging.Handler): The handler to add.
42+
"""
43+
if not self.logger.hasHandlers():
44+
self.logger.addHandler( handler )
45+
else:
46+
self.logger.warning(
47+
"The logger already has an handler, to use yours set the argument 'speHandler' to True during the filter initialization."
48+
)
49+
50+
cls.__init__ = new_init
51+
cls.setLoggerHandler = setLoggerHandler
52+
53+
return cls
54+
55+
return decorator

0 commit comments

Comments
 (0)