Paraview plugin restored after opening a state file *.pvsm

Is there a way for a reader plugin to discriminate the creation reason, i.e., from scratch or upon opening a state or session file? For a plugin with private options, Paraview restores those after calling the “RequestData” slot. Thus, the plugin does not have a chance to process the restored option values (i.e., all options are set to True (defaults), for instance). It seems that there is a z-order issue while opening such state file. Paraview must initialize the private options before calling the slots for the plugin. For instance, consider the Pyhon example at (https://gitlab.kitware.com/paraview/paraview/-/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py), where the array returned from " `PythonCSVReader::GetDataArraySelection" comes from opening a session file.

Thanks in advance.

I’m very confused by your question, this sound like there is a bug somewhere. Could you give proper steps to reproduce the problem ?

Sure, let me try to better explain. Our in-house plugin incorporates filtering options via vtkDataArraySelection. For instance, we decorate our plugin with code like:

@smproperty.dataarrayselection(name = "Static properties")
def GetDataArraySelectionProps(self):
    return self.data.static_props_selection

where static_props_selection is an instance of vtkDataArraySelection. If you open the plugin associated file from scratch, the user will have a chance to change those options, to filter a property for loading for instance. Let assume you filter some properties like that. You then save the state and close Paraview. Once you reopen and load the state, Paraview restores the options correctly, they look good on the screen, but what the plugin receives on the slots are the default values, not the saved options. I am asking if the plugin can know when opening a state so we should try to read the latest options from a separate private file. I agree with you that there is bug in the way you are restarting the plugins. I may try to prep a trivial example to share the code with you if that helps.

Sounds like a bug to me, plugin or not, the options should be restored the same.

Can you reproduce the issue using the PythonAlgorithmExamples.py ?

I could reproduce with the code below:

from paraview.util.vtkAlgorithm import *
from vtk import vtkDataArraySelection

@smproxy.reader(name="PythonDummyReader", label="Python-based Dummy Reader",
                extensions="dummy", file_description="Dummy files")
class DummyReader(VTKPythonAlgorithmBase):

    reading_option_names = ['Parse initial perforations only', 
                            'Shutdown persistency support', 
                            'Allow only one plugin instance']

    def __init__(self):
        VTKPythonAlgorithmBase.__init__(self, nInputPorts = 0, nOutputPorts = 1, outputType = 'vtkTable')
        self._filename = None
        self.options = None

    @smproperty.stringvector(name = "FileName")
    @smdomain.filelist()
    @smhint.filechooser(extensions = "dummy", file_description = "Dummy files")
    def SetFileName(self, name):
        """Specify filename for the file to read."""
        if self._filename != name:
            self._filename = name
            self.Modified()

    @smproperty.dataarrayselection(name = "Plugin options")
    def GetPluginOptions(self):
        return self.options if self.options != None else vtkDataArraySelection()

    def RequestInformation(self, request, inInfoVec, outInfoVec):
        executive = self.GetExecutive()
        outInfo = outInfoVec.GetInformationObject(0)
        outInfo.Remove(executive.TIME_STEPS())
        outInfo.Remove(executive.TIME_RANGE())
        # Populate options
        self.options = vtkDataArraySelection()
        self.options.RemoveAllArrays()
        for property_name in self.reading_option_names:
            self.options.AddArray(property_name)
        return 1

    # It returns the selected or checked array entries.
    @staticmethod
    def GetArraySelection(array_selection):
        selection_list = []
        for i in range(array_selection.GetNumberOfArrays()):
            variable_name = array_selection.GetArrayName(i)
            if array_selection.ArrayIsEnabled(variable_name):
                selection_list.append(variable_name)
        # Return resulting list 
        return selection_list

    def RequestData(self, request, inInfoVec, outInfoVec):
        print('\nOptions = ', DummyReader.GetArraySelection(self.options))
        return 1

Repro steps:

  1. Create and load the plugin above.
  2. Create a dummy empty file, with the extension “*.dummy”.
  3. Load the file from Paraview, change two options to false, and then apply changes.
  4. Save the session file.
  5. Reopen the previouly saved state or session.

My console prints for steps 1-3:
Options = [‘Parse initial perforations only’]

Upon restarting the session prints:

Options =  ['Parse initial perforations only', 'Shutdown persistency support', 'Allow only one plugin instance']

Now, It seems that if the options are modified within “RequestInformation” then it breaks, but if the options are initialized in the plugin constructor then you should be fine. I will try defining the options in the SetFileName slot. What happens is that we first poke the input files in “RequestInformation” to get the metadata and prepare timesteps and properties and variables for the user to choose before applying, but there is no applying when reading a state. Let me know.

You need an observer on the modified event of the DataArraySelection, see here for an example:
https://gitlab.kitware.com/paraview/paraview/-/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py?ref_type=heads#L160

Ok, thanks! I will try.