|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies. |
| 3 | +# SPDX-FileContributor: Lionel Untereiner |
| 4 | +from typing_extensions import Self |
| 5 | + |
| 6 | +from paraview.util.vtkAlgorithm import smdomain, smhint, smproperty, smproxy |
| 7 | +from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase |
| 8 | +from vtkmodules.vtkCommonCore import vtkInformation, vtkInformationVector |
| 9 | +from vtkmodules.vtkCommonDataModel import vtkPartitionedDataSetCollection |
| 10 | + |
| 11 | +paraview_plugin_version = "0.1.0" |
| 12 | + |
| 13 | + |
| 14 | +@smproxy.reader( |
| 15 | + name="PythonGeosDeckReader", |
| 16 | + label="Python-based Deck Reader for GEOS", |
| 17 | + extensions="xml", |
| 18 | + file_description="XML files", |
| 19 | +) |
| 20 | +class PVGeosDeckReader( VTKPythonAlgorithmBase ): |
| 21 | + |
| 22 | + def __init__( self: Self ) -> Self: |
| 23 | + """Constructor of the reader.""" |
| 24 | + VTKPythonAlgorithmBase.__init__( |
| 25 | + self, |
| 26 | + nInputPorts=0, |
| 27 | + nOutputPorts=1, |
| 28 | + outputType="vtkPartitionedDataSetCollection", |
| 29 | + ) # type: ignore |
| 30 | + self.__filename: str |
| 31 | + from geos_xml_viewer.filters.geosDeckReader import GeosDeckReader |
| 32 | + |
| 33 | + self.__realAlgorithm = GeosDeckReader() |
| 34 | + |
| 35 | + @smproperty.stringvector( name="FileName" ) # type: ignore |
| 36 | + @smdomain.filelist() # type: ignore |
| 37 | + @smhint.filechooser( extensions="xml", file_description="GEOS XML files" ) # type: ignore |
| 38 | + def SetFileName( self: Self, name: str ) -> None: |
| 39 | + """Specify filename for the file to read. |
| 40 | +
|
| 41 | + Args: |
| 42 | + name (str): filename |
| 43 | + """ |
| 44 | + if self.__filename != name: |
| 45 | + self.__filename = name |
| 46 | + self.__realAlgorithm.SetFileName( self.__filename ) |
| 47 | + self.__realAlgorithm.Update() |
| 48 | + self.Modified() |
| 49 | + |
| 50 | + def RequestData( |
| 51 | + self: Self, |
| 52 | + request: vtkInformation, |
| 53 | + inInfoVec: list[ vtkInformationVector ], |
| 54 | + outInfoVec: vtkInformationVector, |
| 55 | + ) -> int: |
| 56 | + """RequestData function of the vtk pipeline. |
| 57 | +
|
| 58 | + Args: |
| 59 | + request (vtkInformation): information about the request |
| 60 | + inInfoVec (list[vtkInformationVector]): input information vector |
| 61 | + outInfoVec (vtkInformationVector): output information vector |
| 62 | +
|
| 63 | + Raises: |
| 64 | + RuntimeError: Raises an error if no filename is specified |
| 65 | +
|
| 66 | + Returns: |
| 67 | + int: Returns 1 if the pipeline is successful |
| 68 | + """ |
| 69 | + if self.__filename is None: |
| 70 | + raise RuntimeError( "No filename specified" ) |
| 71 | + |
| 72 | + output = vtkPartitionedDataSetCollection.GetData( inInfoVec, 0 ) |
| 73 | + output.ShallowCopy( self.__realAlgorithm.GetOutputDataObject( 0 ) ) |
| 74 | + return 1 |
0 commit comments