# Expanding GroupItem Functionality

**URL:** <https://discourse.kitware.com/t/expanding-groupitem-functionality/622>\
**Category:** Simulation Modeling Toolkit (SMTK)\
**Created:** [March 24, 2021, 7:56pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622 "2021-03-24T19:56:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_Obara](https://discourse.kitware.com/user_avatar/discourse.kitware.com/bob_obara/32/37_2.png) [@Bob\_Obara](https://discourse.kitware.com/u/Bob_Obara)\
**Post date:** [March 24, 2021, 7:56pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/1 "2021-03-24T19:56:32Z")

</div>

# Add the ability to model a group of conditions

Consider a Group Item consisting of a set of optional items. The designer want to stipulate that at least n options should be enabled for the Group Item to be considered valid.

## Possible Group Item Definition Changes

- Add a property to indicate that the group is a set of conditions
  - This would automatically add isOptional to all of the group’s item definitions so the designer would not have to do so.
  - This would allow the use of Item Blocks w/o forcing the designer of adding the isOptional property in the Item Block itself.

- Add a property to indicate the number of “relevant” optional children items should be enabled in order for the group to be considered valid

There may be the need for the Group Item to have a different number of conditions items to be enabled.

## Possible Group Item Changes

- Add a property to override the number of “relevant” optional children items should be enabled in order for the group to be considered valid

## Possible Qt Changes

How to indicate to the user that he/she hasn’t selected enough options

- Could put the alert icon next to the group name with a tooltip
- Could put text in red saying “Please choose n” in read next to the group’s label
  - When satisfied , the text could go black or go away.

## Suggested API

- GroupItemDefinition::setIsConditional(bool)
- GroupItemDefintion::setConditionalRange(unsigned int minNumber, unsigned int maxNumber) - if maxNumber is 0 then there is no maximum;
- GroupItem::setConditionalRange(unsigned int minNumber, unsigned int maxNumber) - overrides the values specified in the GroupItemDefinition

## Suggested XML Format

```xml
<Group Name="options" Label="OptionsTest" Optional="true" 
       IsEnabledByDefault="false"
       OptionalChoices="true" "MinNumberRequiredChoices="1" "MaxNumberRequiredChoices="0">
  <ItemDefinitions>
    <String Name="opt1"/>
    <Int Name="opt2"/>
    <Double Name="opt3"/>
  </ItemDefinitions>
</Group>

```

---

<div class="post-metadata">

**Author:** ![Bob\_Obara](https://discourse.kitware.com/user_avatar/discourse.kitware.com/bob_obara/32/37_2.png) [@Bob\_Obara](https://discourse.kitware.com/u/Bob_Obara)\
**Post date:** [March 24, 2021, 8:01pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/2 "2021-03-24T20:01:42Z")

</div>

@chart3388 @amuhsin @johnt Comments?

---

<div class="post-metadata">

**Author:** ![johnt](https://discourse.kitware.com/user_avatar/discourse.kitware.com/johnt/32/147_2.png) [@johnt](https://discourse.kitware.com/u/johnt)\
**Post date:** [March 25, 2021, 12:22am UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/3 "2021-03-25T00:22:24Z")

</div>

This seems very specialized to incorporate into smtk core. Do we envision multiple use cases? Could it be addressed in the UI, presumably as an ItemView, or is the need in the smtk GroupItem?

---

<div class="post-metadata">

**Author:** ![Bob\_Obara](https://discourse.kitware.com/user_avatar/discourse.kitware.com/bob_obara/32/37_2.png) [@Bob\_Obara](https://discourse.kitware.com/u/Bob_Obara)\
**Post date:** [March 25, 2021, 1:28pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/4 "2021-03-25T13:28:19Z")

</div>

Since this conceptually affects item validity it seems that it needs to be in GroupItem (especially if we also need to support an Item overriding its # of enabled options requirement.

---

<div class="post-metadata">

**Author:** ![Bob\_Obara](https://discourse.kitware.com/user_avatar/discourse.kitware.com/bob_obara/32/37_2.png) [@Bob\_Obara](https://discourse.kitware.com/u/Bob_Obara)\
**Post date:** [March 26, 2021, 4:05pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/5 "2021-03-26T16:05:13Z")

</div>

@Aaron @chart3388 @amuhsin @johnt - Added possible syntax - also what do you think we should do for error feedback? Caution symbol or text?

---

<div class="post-metadata">

**Author:** ![johnt](https://discourse.kitware.com/user_avatar/discourse.kitware.com/johnt/32/147_2.png) [@johnt](https://discourse.kitware.com/u/johnt)\
**Post date:** [March 26, 2021, 5:04pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/6 "2021-03-26T17:04:22Z")

</div>

And I presume adding a subclass like `SelectionGroupItem` would be significantly more effort than adding a mode to `GroupItem`.

Should also note that the new mode is only supported for `NumberOfRequiredGroups` == 1 and `Extensible` == false.

---

<div class="post-metadata">

**Author:** ![Bob\_Obara](https://discourse.kitware.com/user_avatar/discourse.kitware.com/bob_obara/32/37_2.png) [@Bob\_Obara](https://discourse.kitware.com/u/Bob_Obara)\
**Post date:** [March 26, 2021, 5:21pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/7 "2021-03-26T17:21:29Z")

</div>

Yes to both questions - though technically it could apply to extensible groups I don’t see a valid use case for it.

In terms of creating a new Type of Item - this would involve creating the new definition, new item, new I/O, and new qtItem classes for it so yes a lot more work.

---

<div class="post-metadata">

**Author:** ![amuhsin](https://discourse.kitware.com/user_avatar/discourse.kitware.com/amuhsin/32/335_2.png) [@amuhsin](https://discourse.kitware.com/u/amuhsin)\
**Post date:** [March 26, 2021, 6:42pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/8 "2021-03-26T18:42:31Z")

</div>

I think we should go with Caution symbol and put the text in a hint that pops up when you hover over the symbol. That way we follow the pattern we’ve established in the rest of the UI. Also it takes up less real-estate.

---

<div class="post-metadata">

**Author:** ![Bob\_Obara](https://discourse.kitware.com/user_avatar/discourse.kitware.com/bob_obara/32/37_2.png) [@Bob\_Obara](https://discourse.kitware.com/u/Bob_Obara)\
**Post date:** [March 30, 2021, 8:28pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/9 "2021-03-30T20:28:51Z")

</div>

Some API/XML Changes

So I thinking to change: setConditionalRange(unsigned int minNumber, unsigned int maxNumber) to a pair of functions:

- setMaxNumberOfChoices
- setMinNumberOfChoices

The reason of splitting them is to provide more flexibility on the GroupItem side of things so you can easily override only min or max values.  
And for the XML format:

```xml
<Group Name="options" Label="OptionsTest" Optional="true" 
       IsEnabledByDefault="false"
       IsConditional="true" "MinNumberOfChoices="1" "MaxNumberOfChoices="0">

```

This better matches the programming API  
Comments?

---

<div class="post-metadata">

**Author:** ![Bob\_Obara](https://discourse.kitware.com/user_avatar/discourse.kitware.com/bob_obara/32/37_2.png) [@Bob\_Obara](https://discourse.kitware.com/u/Bob_Obara)\
**Post date:** [March 31, 2021, 10:36pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/10 "2021-03-31T22:36:09Z")

</div>

## Results of Current Implementation

Here is the sample test XML:

```xml
<SMTK_AttributeResource Version="3">
  <Definitions>
    <AttDef Type="Test">
      <ItemDefinitions>
        <Group Name="opt1" Label="Pick At Least 2"
          IsConditional="true" MinNumberOfChoices="2" MaxNumberOfChoices="0">
          <ItemDefinitions>
            <String Name="opt1"/>
            <Int Name="opt2"/>
            <Double Name="opt3"/>
          </ItemDefinitions>
        </Group>
        <Group Name="opt2" Label="Pick No more than 2"
          IsConditional="true" MinNumberOfChoices="0" MaxNumberOfChoices="2">
          <ItemDefinitions>
            <String Name="opt1"/>
            <Int Name="opt2"/>
            <Double Name="opt3"/>
          </ItemDefinitions>
        </Group>
        <Group Name="opt3" Label="Pick exactly 2"
          IsConditional="true" MinNumberOfChoices="2" MaxNumberOfChoices="2">
          <ItemDefinitions>
            <String Name="opt1"/>
            <Int Name="opt2"/>
            <Double Name="opt3"/>
          </ItemDefinitions>
        </Group>
        <Group Name="opt4" Label="Pick At Least 1 but no more than 2"
          IsConditional="true" MinNumberOfChoices="1" MaxNumberOfChoices="2">
          <ItemDefinitions>
            <String Name="opt1"/>
            <Int Name="opt2"/>
            <Double Name="opt3"/>
          </ItemDefinitions>
        </Group>
      </ItemDefinitions>
    </AttDef>
  </Definitions>
  <Views>
    <View Type="Instanced" Title="TopLevel" TopLevel="true" TabPosition="North">
      <InstancedAttributes>
        <Att Type="Test" Name="Test1"/>
      </InstancedAttributes>
    </View>
  </Views>
</SMTK_AttributeResource>

```

Here is the resulting UI:

 ![Screen Shot 2021-03-31 at 6.32.30 PM](https://discourse.kitware.com/uploads/default/original/1X/b3081da191a17b4c2776dbaede3d82c8d649b78f.png)

---

<div class="post-metadata">

**Author:** ![chart3388](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@chart3388](https://discourse.kitware.com/u/chart3388)\
**Post date:** [April 14, 2021, 3:43pm UTC](https://discourse.kitware.com/t/expanding-groupitem-functionality/622/11 "2021-04-14T15:43:20Z")

</div>

@Bob_Obara - Would it make sense with gray out or put an X or make the other extra boxes not selectable until I have deselected the number of items that put me back into a valid state state of selection when I’ve reached the maximum number of items? Here is an example with graying out the box and graying out the box with an additional icon.

 ![GroupItemAlerts](https://discourse.kitware.com/uploads/default/original/1X/bba9b3dec93670bc7988ac93d11cc886cd85b349.png)
