Skip to content

Commit

Permalink
DYN-6633: Definedata UI update (#15234)
Browse files Browse the repository at this point in the history
Co-authored-by: Trygve Wastvedt <[email protected]>
Co-authored-by: Trygve Wastvedt <[email protected]>
  • Loading branch information
3 people authored May 22, 2024
1 parent 0099b02 commit e3ebfde
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 91 deletions.
25 changes: 14 additions & 11 deletions doc/distrib/NodeHelpFiles/CoreNodeModels.DefineData.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
## In Depth

The Define Data node validates the data type of incoming data. It can be used to ensure local data is of the desired type and is also designed to be used as an input or output node, declaring the type of data a graph expects or provides. The node supports a selection of commonly used Dynamo data types, for example 'String', 'Point', or 'Boolean'. The full list of supported data types is available in the drop-down menu of the node.
The Define Data node validates the data type of incoming data. It can be used to ensure local data is of the desired type, and it's also designed to be used as an input or output node that declares the type of data a graph expects or provides. The node supports a selection of commonly used Dynamo data types, for example "String", "Point", and "Boolean". The full list of supported data types is available in the node's drop-down menu. The node supports data in the form of a single value or a flat list. Nested lists, dictionaries, and replication are not supported.

### Behavior
The node validates the data coming in from the input port based on the setting of the drop-down menu and the **List** toggle (see below for details). If the validation is successful, the output of the node is the same as the input. If the validation is not successful, the node will enter a warning state with a null output.

The node has four inputs:
- The "**>**" input - Connect to an upstream node to validate the type of its data.
- The **drop-down** menu - Shows the expected data type. When the form is unlocked, set a data type for validation. When the form is locked, the data type is chosen automatically based on incoming data. Data is valid if its type matches the shown type exactly or if its type is a child of the shown type (e.g. If the drop-down is set to "Curve", objects of type "Rectangle", "Line", etc. are valid).
- The **List** toggle - When on, the node expects incoming data to be a single flat list containing items of a valid data type (see above). When off, the node expects a single item of a valid data type.
- The **Lock** toggle - When off/unlocked, the drop-down menu and the **List** toggle controls accept user input to set the type of data expected. When on/locked, the node will validate* the incoming data, disable the controls, and set their value based on the data connected to the node's input port.
The node validates the data coming in from the input port based on the setting of the Type drop-down menu and the List toggle (see below for details). If the validation is successful, the output of the node is the same as the input. If the validation is not successful, the node will enter a warning state with a null output.
The node has one input:

- The "**>**" input - Connect to an upstream node to validate the type of its data.
Additionally, the node offers three user controls:
- The **Auto-detect type** toggle - When toggled on, the node analyzes the incoming data, and if the data is of a supported type, the node sets the Type and List controls' values based on the type of the incoming data. The Type drop-down menu and the List toggle are disabled and will automatically update based on the input node.

When Auto-detect type is toggled off, you can specify a data type by using the Type menu and List toggle. If the incoming data does not match what you've specified, the node will enter a warning state with a null output.
- The **Type** drop-down menu - Sets the expected data type. When the control is enabled (**Auto-detect type** toggle is off), set a data type for validation. When the control is disabled (**Auto-detect type** toggle is on), the data type is set automatically based on incoming data. Data is valid if its type matches the shown type exactly or if its type is a child of the shown type (for example, if the Type drop-down is set to "Curve", objects of type "Rectangle", "Line", etc. are valid).
- The **List** toggle - When on, the node expects incoming data to be a single flat list containing items of a valid data type (see above). When off, the node expects a single item of a valid data type.

### Use as an input node
When set as an input ("Is Input" in the node's context menu) the node can optionally use upstream nodes to set the default value for the input. A run of the graph will cache the Define Data node's value for use when running the graph externally, for example with the Engine Node.

---
When set as an input ("Is Input" in the node's context menu), the node can optionally use upstream nodes to set the default value for the input. A run of the graph will cache the Define Data node's value for use when running the graph externally, for example with the Engine node.

## Example File
In the example below, the first group of "DefineData" nodes have an unlocked UI. The node correctly validates the Number input provided while rejecting the String input. The second group contains a node with locked UI. The node automatically adjusts the drop-down and the **List** toggle to match the input, in this case a list of integers.

In the example below, the first group of "DefineData" nodes have the **Auto-detect type** toggle off. The node correctly validates the Number input provided while rejecting the String input. The second group contains a node with **Auto-detect type** toggled on. The node automatically adjusts the Type drop-down and the List toggle to match the input, in this case a list of integers.

![Define_Data](./CoreNodeModels.DefineData_img.jpg)

Binary file modified doc/distrib/NodeHelpFiles/CoreNodeModels.DefineData_img.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3974,6 +3974,18 @@ To make this file into a new template, save it to a different folder, then move
<value>Toggle on if the input data contains a list.</value>
<comment>Tool-tip for info questionmark icon.</comment>
</data>
<data name="DataInputAutoDetectTypeTooltip" xml:space="preserve">
<value>Toggle on to allow Define Data to automatically detect the data type of the input node. Toggle off to set the desired data type yourself</value>
</data>
<data name="DataInputAutoDetectTypeLabel" xml:space="preserve">
<value>Auto-detect type</value>
</data>
<data name="DataInputTypeLabel" xml:space="preserve">
<value>Type</value>
</data>
<data name="DataInputListLabel" xml:space="preserve">
<value>List</value>
</data>
<data name="MessagePackageOlderDynamo" xml:space="preserve">
<value>This package or one of its dependencies were created for a previous version of Dynamo. It may not work in this version. Do you want to continue?</value>
</data>
Expand Down
12 changes: 12 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3961,6 +3961,18 @@ To make this file into a new template, save it to a different folder, then move
<value>Toggle on if the input data contains a list.</value>
<comment>Tool-tip for info questionmark icon next to the List toggle control.</comment>
</data>
<data name="DataInputAutoDetectTypeTooltip" xml:space="preserve">
<value>Toggle on to allow Define Data to automatically detect the data type of the input node. Toggle off to set the desired data type yourself</value>
</data>
<data name="DataInputAutoDetectTypeLabel" xml:space="preserve">
<value>Auto-detect type</value>
</data>
<data name="DataInputTypeLabel" xml:space="preserve">
<value>Type</value>
</data>
<data name="DataInputListLabel" xml:space="preserve">
<value>List</value>
</data>
<data name="MessagePackageOlderDynamo" xml:space="preserve">
<value>This package or one of its dependencies were created for a previous version of Dynamo. It may not work in this version. Do you want to continue?</value>
</data>
Expand Down
8 changes: 8 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Dynamo.Controls.BinaryRadioButtonCheckedConverter
Dynamo.Controls.BinaryRadioButtonCheckedConverter.BinaryRadioButtonCheckedConverter() -> void
Dynamo.Controls.BinaryRadioButtonCheckedConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.BinaryRadioButtonCheckedConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.BooleanNegationConverter
Dynamo.Controls.BooleanNegationConverter.BooleanNegationConverter() -> void
Dynamo.Controls.BooleanNegationConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.BooleanNegationConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.BooleanToBrushConverter
Dynamo.Controls.BooleanToBrushConverter.BooleanToBrushConverter() -> void
Dynamo.Controls.BooleanToBrushConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Expand Down Expand Up @@ -4462,8 +4466,12 @@ static Dynamo.Wpf.Properties.Resources.CustomNodePropertyWindowName.get -> strin
static Dynamo.Wpf.Properties.Resources.CustomNodePropertyWindowNameHint.get -> string
static Dynamo.Wpf.Properties.Resources.CustomNodePropertyWindowTitle.get -> string
static Dynamo.Wpf.Properties.Resources.CustomNodeTypeShortString.get -> string
static Dynamo.Wpf.Properties.Resources.DataInputAutoDetectTypeLabel.get -> string
static Dynamo.Wpf.Properties.Resources.DataInputAutoDetectTypeTooltip.get -> string
static Dynamo.Wpf.Properties.Resources.DataInputListLabel.get -> string
static Dynamo.Wpf.Properties.Resources.DataInputNodeInformationTooltip.get -> string
static Dynamo.Wpf.Properties.Resources.DataInputNodeModeLockTooltip.get -> string
static Dynamo.Wpf.Properties.Resources.DataInputTypeLabel.get -> string
static Dynamo.Wpf.Properties.Resources.DefaultPythonEngineNone.get -> string
static Dynamo.Wpf.Properties.Resources.DeleteFailureMessageBoxTitle.get -> string
static Dynamo.Wpf.Properties.Resources.DeprecatingPackageMessageBoxTitle.get -> string
Expand Down
22 changes: 21 additions & 1 deletion src/DynamoCoreWpf/UI/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Xml.Linq;
using Dynamo.Configuration;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Workspaces;
Expand Down Expand Up @@ -3939,4 +3938,25 @@ public object ConvertBack(object value, Type targetType, object parameter,
}
}

public class BooleanNegationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool booleanValue)
{
return !booleanValue;
}
return false;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool booleanValue)
{
return !booleanValue;
}
return false;
}
}

}
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoConverters.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,5 @@
<controls:ObjectTypeConverter x:Key="ObjectTypeConverter" />
<controls:TextForegroundSaturationColorConverter x:Key="TextForegroundSaturationColorConverter" />
<controls:PortTypeToStringConverter x:Key="PortTypeToStringConverter" />
<controls:BooleanNegationConverter x:Key="BooleanNegationConverter" />
</ResourceDictionary>
5 changes: 3 additions & 2 deletions src/Libraries/CoreNodeModels/DefineData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace CoreNodeModels
public class DefineData : DSDropDownBase
{
private List<DynamoDropDownItem> serializedItems;
private bool isAutoMode;
private bool isAutoMode = true; // default start with auto-detect 'on'
private bool isList;
private string playerValue = "";
private string displayValue = Properties.Resources.DefineDataDisplayValueMessage;
Expand Down Expand Up @@ -218,7 +218,8 @@ private void DataBridgeCallback(object data)
{
if(IsAutoMode)
{
DisplayValue = Properties.Resources.DefineDataDisplayValueMessage;
DisplayValue = string.Empty; // show blank if we are in locked mode (as we cannot interact with the node)
//DisplayValue = Properties.Resources.DefineDataDisplayValueMessage;
}
else
{
Expand Down
Loading

0 comments on commit e3ebfde

Please sign in to comment.