Extended Selection Dialog

Selecting entities in the graphics window can sometimes be complicated. The Extended Selection Dialog leverages the combination of Python and the CubitInterface class to give users a very powerful mechanism for creating and managing custom selection filters.

Accessing the Dialog

The dialog is accessible any time a geometry entity is selected in the graphics window. Consider this workflow:

Launch the Dialog

  • Select a geometric entity
  • Get the context menu and select "Pick Extended...". The Extended Selection dialog will be shown with the selected entity (or entities) listed in the Source Selection window.

When the dialog is first shown, no filters are available.

Load Existing Filters

Load existing filters by:

  • Press the "Load Filters" button
  • The Locate and Load Filters dialog will be shown

The very first time this dialog is shown, the path to the filters folder will be blank and no filters will be shown in the filter list. Press the "Browse" button and select the folder that contains the custom filters. This folder can be anywhere on the file system. Cubit will remember the location and use it during subsequent sessions. The folder may be changed at any time.

A list of custom filters, written in Python, will be shown. Select any given filter to examine its contents. Check all filters to be included in the menu for Extended Filters. Then press "OK".

At this point, all of the filters selected in the Locate and Load Filters dialog will be available for use in the Extended Selection dialog.

Use a Filter

Use the pull down menu to select a filter. Click on an entity in the Source Selection list. Geometric entities that fit the filter criterion will be shown in the Target Entities list.

  • Make selections in the Target Entities list
  • If a pickwidget is active, selected IDs will be copied into the pickwidget
  • Access the context menu in the Target Entities list for other options, including copying entity names or IDs to the clipboard.

Dragging from Target Entities to Source Selection

Depending on the nature of the selection filter it may be useful to 're-seed' the Source Selection with an item from Target Entities. Simply drag an item or items from Target Entities into  the Source Selection list.

Creating Parameterized Filters

Parameterized filters will require a user interface which will be added into the extended selection filter dialog. The user interface can be made using Qt's Designer, which is a free tool that ships with the Qt toolkit. The Qt Designer tool produces an XML file that will be read by Cubit and automatically included in the Extended Selection Filter dialog.

For example, if we wanted to create a selection filter that would select all entities of a certain type within a certain radius of a source entity, we would require a user interface that captures the desired radius and the desired entity type to be selected. An image of that user interface is shown below. The image was copied directly from Qt Designer.

Notice two input fields: 1) a Line Edit to capture the desired selection radius and 2) a Combo Box that contains "Volumes", "Surfaces", "Curves", "Vertices" to specify the target entity selection type. The extended selection filter that contains this custom interface is shown below. The example shows a selection of all curves within 1 unit of the source selection.

Writing  Custom Python Filters

The class CubitInterface is used by the GUI to drive Cubit and access its database. You can read about the Python Interface used by Cubit for more details. Suffice to say, all of the functions and data included in CubitInterface are available to Python programmers.

Extended Selection custom filters are written in Python. Follow the instructions below, save the filters on the file system, then load the filters as explained above.

A Simple Example Filter

This first example shows a filter that will return a list of first generation children of the selected entities. No user input is required and no additional user interface is necessary.

  • The filter's File Name and Class Name must match. In this example, the file name is 'ChildFilter.py' and the class name is "ChildFilter".
  • LINE 2: import cubitgui -- this is the Python module that owns the base class (SelectionFilter) from which this filter class is derived.
  • LINE 3: import cubit -- this is the Python module that grants access to all of the CubitInterface functions.
  • LINE 6: When defining the class do the following:
    • Ensure the class name matches the file name
    • Derive the class from cubitgui.SelectionFilter
  • LINE 9: Implement the 'virtual' function "display_name". Return a string that represents the name of the filter. It is this name that will be shown in the Extended Selection dialog's filter menu.
  • LINE 13: Implement the 'virtual' function "run_filter. This is the actual filter.
  • LINE 15: The function get_source_types() returns a list of the types selected in the "Source Selection" list of the Extended Selection dialog.
  • LINE 16: The function get_source_ids() returns a list of the ids selected in the "Source Selection" list of the Extended Selection dialog.
  • LINE 17: The function clear_target_selections() clears the Target Entities list of the Extended Selection dialog.
  • LINE 18: The example filter begins manipulating data to suit its needs
  • LINE 35: The function get_relatives(...) is a member of CubitInterface. It returns a list of ids of a specified type
  • LINE 37: The function add_target_selection(<type> <id>) adds one instance of an entity-type/id to the Target Entities list.

The Selection Filter Class

As mentioned above, the custom Python filters must implement a class and that class must be derived from the SelectionFilter class. The SelectionFilter class is available in the Cubit SDK. The SDK is available to any user.

A Sample Filter that includes Additional User Interface

In order to include user input into an extended selection dialog, two additional things must happen:

  1. The developer must create the user interface definition file (.ui file) using Qt Designer.
  2. An additional function must be implemented in the class definition of the Python filter. The additional function is called get_ui_file().

Qt UI objects supported by the extended selection filter include:

  • QLineEdit - std::string get_line_edit_value ( object-name )
  • QComboBox - std::string get_combo_box_value ( object-name )
  • QRadioButton - bool get_radio_button_value ( object-name )
  • QCheckBox - bool get_check_box_value ( object-name )
  • QSpinBox - int get_spin_box_value ( object-name )
  • QSlider - int get_slider_value ( object-name )

As the example Python code shows, the Qt objects are referenced by name. These code snippets below are not complete. Complete examples and a video tutorial are available from www.csimsoft.com.