33# SPDX-FileContributor: Martin Lemay, Romain Baville
44# ruff: noqa: E402 # disable Module level import not at top of file
55import sys
6+ import numpy as np
67from pathlib import Path
78
8- from typing import Union , Any
9+ from typing import Any
910from typing_extensions import Self
1011
1112from paraview .util .vtkAlgorithm import ( # type: ignore[import-not-found]
12- smdomain , smhint , smproperty , smproxy ,
13+ VTKPythonAlgorithmBase , smdomain , smproperty ,
1314) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/util/vtkAlgorithm.py
1415from paraview .detail .loghandler import ( # type: ignore[import-not-found]
1516 VTKHandler ,
1617) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py
1718
18- from vtkmodules .util .vtkAlgorithm import VTKPythonAlgorithmBase
19- from vtkmodules .vtkCommonCore import (
20- vtkInformation ,
21- vtkInformationVector ,
22- )
19+ import vtkmodules .util .numpy_support as vnp
20+
2321from vtkmodules .vtkCommonDataModel import (
24- vtkMultiBlockDataSet ,
25- vtkDataSet ,
26- )
22+ vtkDataSet , )
2723
2824# update sys.path to load all GEOS Python Package dependencies
2925geos_pv_path : Path = Path ( __file__ ).parent .parent .parent .parent .parent
3026sys .path .insert ( 0 , str ( geos_pv_path / "src" ) )
31- from geos .pv .utils .config import update_paths
3227
33- update_paths ( )
28+ from geos . mesh . processing . CreateConstantAttributePerRegion import ( CreateConstantAttributePerRegion )
3429
35- from geos .mesh . processing . CreateConstantAttributePerRegion import CreateConstantAttributePerRegion , vnp , np
30+ from geos .pv . utils . details import SISOFilter , FilterCategory
3631
3732__doc__ = """
3833PVCreateConstantAttributePerRegion is a Paraview plugin that allows to create an attribute
4237Input mesh is either vtkMultiBlockDataSet or vtkDataSet and the region attribute must have one component.
4338The relation index/values is given by a dictionary. Its keys are the indexes and its items are the list of values for each component.
4439
45- .. Warning::
40+ .. Warning::
4641 The input mesh should contain an attribute corresponding to the regions.
4742
4843To use it:
5651"""
5752
5853
59- @smproxy .filter (
60- name = "PVCreateConstantAttributePerRegion" ,
61- label = "Create Constant Attribute Per Region" ,
62- )
63- @smhint .xml ( """<ShowInMenu category="0- Geos Pre-processing"/>""" )
64- @smproperty .input ( name = "Input" , port_index = 0 )
65- @smdomain .datatype (
66- dataTypes = [ "vtkMultiBlockDataSet" , "vtkDataSet" ],
67- composite_data_supported = True ,
68- )
54+ @SISOFilter ( category = FilterCategory .GEOS_PROP ,
55+ decoratedLabel = "Create Constant Attribute Per Region" ,
56+ decoratedType = [ "vtkMultiBlockDataSet" , "vtkDataSet" ] )
6957class PVCreateConstantAttributePerRegion ( VTKPythonAlgorithmBase ):
7058
7159 def __init__ ( self : Self ) -> None :
7260 """Create an attribute with constant value per region."""
73- super ().__init__ ( nInputPorts = 1 , nOutputPorts = 1 , inputType = "vtkDataObject" , outputType = "vtkDataObject" )
74-
7561 self .clearDictRegionValues : bool = True
7662
7763 # Region attribute settings.
@@ -111,7 +97,7 @@ def __init__( self: Self ) -> None:
11197 <NoDefault />
11298 </Hints>
11399 """ )
114- def _setRegionAttributeName ( self : Self , regionName : str ) -> None :
100+ def setRegionAttributeName ( self : Self , regionName : str ) -> None :
115101 """Set region attribute name.
116102
117103 Args:
@@ -124,7 +110,7 @@ def _setRegionAttributeName( self: Self, regionName: str ) -> None:
124110 <StringVectorProperty
125111 name="SetDictRegionValues"
126112 number_of_elements="2"
127- command="_setDictRegionValues "
113+ command="setDictRegionValues "
128114 repeat_command="1"
129115 number_of_elements_per_command="2">
130116 <Documentation>
@@ -142,7 +128,7 @@ def _setRegionAttributeName( self: Self, regionName: str ) -> None:
142128 </Hints>
143129 </StringVectorProperty>
144130 """ )
145- def _setDictRegionValues ( self : Self , regionIndex : str , value : str ) -> None :
131+ def setDictRegionValues ( self : Self , regionIndex : str , value : str ) -> None :
146132 """Set the dictionary with the region indexes and its corresponding list of values for each components.
147133
148134 Args:
@@ -166,7 +152,7 @@ def _setDictRegionValues( self: Self, regionIndex: str, value: str ) -> None:
166152 <Property name="SetDictRegionValues"/>
167153 </PropertyGroup>
168154 """ )
169- def _groupRegionAttributeSettingsWidgets ( self : Self ) -> None :
155+ def groupRegionAttributeSettingsWidgets ( self : Self ) -> None :
170156 """Group the widgets to set the settings of the region attribute."""
171157 self .Modified ()
172158
@@ -183,7 +169,7 @@ def _groupRegionAttributeSettingsWidgets( self: Self ) -> None:
183169 </Documentation>
184170 </StringVectorProperty>
185171 """ )
186- def _setAttributeName ( self : Self , newAttributeName : str ) -> None :
172+ def setAttributeName ( self : Self , newAttributeName : str ) -> None :
187173 """Set attribute name.
188174
189175 Args:
@@ -216,7 +202,7 @@ def _setAttributeName( self: Self, newAttributeName: str ) -> None:
216202 The requested numpy scalar type for values of the new attribute.
217203 </Documentation>
218204 """ )
219- def _setValueType ( self : Self , valueType : int ) -> None :
205+ def setValueType ( self : Self , valueType : int ) -> None :
220206 """Set the type for the value used to create the new attribute.
221207
222208 Args:
@@ -238,7 +224,7 @@ def _setValueType( self: Self, valueType: int ) -> None:
238224 The number of components for the new attribute to create.
239225 </Documentation>
240226 """ )
241- def _setNbComponent ( self : Self , nbComponents : int ) -> None :
227+ def setNbComponent ( self : Self , nbComponents : int ) -> None :
242228 """Set the number of components of the attribute to create.
243229
244230 Args:
@@ -261,7 +247,7 @@ def _setNbComponent( self: Self, nbComponents: int ) -> None:
261247 Names of components: X, Y, Z
262248 </Documentation>
263249 """ )
264- def _setComponentNames ( self : Self , componentNames : str ) -> None :
250+ def setComponentNames ( self : Self , componentNames : str ) -> None :
265251 """Set the names of the components of the attribute to create.
266252
267253 Args:
@@ -283,57 +269,17 @@ def _setComponentNames( self: Self, componentNames: str ) -> None:
283269 <Property name="NumberOfComponents"/>
284270 <Property name="ComponentNames"/>
285271 </PropertyGroup>""" )
286- def _groupNewAttributeSettingsWidgets ( self : Self ) -> None :
272+ def groupNewAttributeSettingsWidgets ( self : Self ) -> None :
287273 """Group the widgets to set the settings of the new attribute."""
288274 self .Modified ()
289275
290- def RequestDataObject (
291- self : Self ,
292- request : vtkInformation ,
293- inInfoVec : list [ vtkInformationVector ],
294- outInfoVec : vtkInformationVector ,
295- ) -> int :
296- """Inherited from VTKPythonAlgorithmBase::RequestDataObject.
276+ def Filter ( self , inputMesh : vtkDataSet , outputMesh : vtkDataSet ) -> None :
277+ """Is applying CreateConstantAttributePerRegion filter.
297278
298279 Args:
299- request (vtkInformation): request
300- inInfoVec (list[vtkInformationVector]): input objects
301- outInfoVec (vtkInformationVector): output objects
302-
303- Returns:
304- int: 1 if calculation successfully ended, 0 otherwise.
280+ inputMesh : A mesh to transform
281+ outputMesh : A mesh transformed.
305282 """
306- inData = self .GetInputData ( inInfoVec , 0 , 0 )
307- outData = self .GetOutputData ( outInfoVec , 0 )
308- assert inData is not None
309- if outData is None or ( not outData .IsA ( inData .GetClassName () ) ):
310- outData = inData .NewInstance ()
311- outInfoVec .GetInformationObject ( 0 ).Set ( outData .DATA_OBJECT (), outData )
312- return super ().RequestDataObject ( request , inInfoVec , outInfoVec ) # type: ignore[no-any-return]
313-
314- def RequestData (
315- self : Self ,
316- request : vtkInformation , # noqa: F841
317- inInfoVec : list [ vtkInformationVector ], # noqa: F841
318- outInfoVec : vtkInformationVector , # noqa: F841
319- ) -> int :
320- """Inherited from VTKPythonAlgorithmBase::RequestData.
321-
322- Args:
323- request (vtkInformation): Request.
324- inInfoVec (list[vtkInformationVector]): Input objects.
325- outInfoVec (vtkInformationVector): Output objects.
326-
327- Returns:
328- int: 1 if calculation successfully ended, 0 otherwise.
329- """
330- inputMesh : Union [ vtkDataSet , vtkMultiBlockDataSet ] = self .GetInputData ( inInfoVec , 0 , 0 )
331- outputMesh : Union [ vtkDataSet , vtkMultiBlockDataSet ] = self .GetOutputData ( outInfoVec , 0 )
332-
333- assert inputMesh is not None , "Input mesh is null."
334- assert outputMesh is not None , "Output pipeline is null."
335-
336- outputMesh .ShallowCopy ( inputMesh )
337283 filter : CreateConstantAttributePerRegion = CreateConstantAttributePerRegion (
338284 outputMesh ,
339285 self .regionName ,
@@ -352,4 +298,4 @@ def RequestData(
352298
353299 self .clearDictRegion = True
354300
355- return 1
301+ return
0 commit comments