Filter that takes a geometry and a selection as input

Once I learned that in the SM XML file for a filter that takes some data plus a selection input, this would describe the selection input:

      <InputProperty command="SetSelectionConnection"
                     name="Selection">
        <ProxyGroupDomain name="groups">
          <Group name="sources"/>
          <Group name="filters"/>
        </ProxyGroupDomain>
        <DataTypeDomain name="input_type">
          <DataType value="vtkSelection"/>
        </DataTypeDomain>
        <Documentation>
          The input that provides the selection object.
        </Documentation>
        <Hints>
          <SelectionInput/>
        </Hints>
      </InputProperty>

In the C++ code I can access this input then as a vtkSelection object and deal with it accordingly. I did all this, and in order to make sure I have nothing forgotten, I compared with the existing code of the Extract Selection filter.

However there is now one thing different: If I select some geometry in the pipeline, then select some cells in that geometry with any of the selection tools, then add the Extract Selection filter to my pipeline, I will see immediately my selection also in the “SelectionInput” widget of the properties panel.

If I do exactly the same thing with my own plugin, the “SelectionInput” widget is initially empty and I will see my previously defined selections only after pressing the “Copy Active Selection” button.

My question is: What is the trick to do this initial “Copy Active Selection” like the “Extract Selection” filter does it? Comparing as much code as I want, I do not find the difference!

After days and days of struggling with the debugger deep inside the ParaView code I finally found the solution: vtkSMExtractSelectionProxyInitializationHelper.

In other words: You need to implement a “helper class” (that can simply be a renamed copy of the above) that does the job explicitly.

(Several years ago I must have known it, but right now I had no such class left inside my code - and the “Extract Selection” filter is not a simple beast: All the required parts are spread out somehow in the source code tree…)