Operations and selection

I have a use case (for aeva) where I would like an operation to modify the application’s selection. I see a few ways to do it:

  • good: add ReferenceItems to the operator’s Result attribute named append to selection and remove from selection. Then the application can decide what to do with them when processing the result. The reference items can have HoldReference="true" so that shared pointer things (like ephemeral selection objects).
  • bad: add a new SelectionOperation subclass of XMLOperation and have the application register its Selection with the operation manager, which will construct each SelectionOperation it creates with the application’s selection object.
  • ugly: have the operation link to the SMTK’s paraview/appcomponents library. When the application runs, it fetches the application’s selection from the pqSMTKBehavior instance and modifies it.

While I included the ugly option as a joke (albeit a prank I may pull in the short term), does anyone have a preference for the long-term solution?

I am not sure if your good solution is that much better than the other options you mentioned. I’m also not sure that the other options you mentioned are all that bad and ugly. I would be interested in knowing more about your use-case to determine whether or not this is broad pattern that we expect many modeling sessions to require.

Offline, @tj.corona came up with a third alternative that seems like the cleanest approach:

  • add a SelectionGroup (that inherits smtk::operation::Group) to indicate the operation would like to work with a selection provided by the operation.
  • have the application add an operation::MetadataObserver to its operation::Manager that passes the Selection to operations in that group as they are created by the operation manager.

I’m not sure how (without inheritance), the application’s metadata observer can pass the selection to the operation, but assuming that works out, it definitely is the most flexible alternative; the operation would be able to prepare the selection directly instead of via hints.

Privacy Notice