Skip to content

Commit

Permalink
AGD-2199 - custom dropdown node (#11958)
Browse files Browse the repository at this point in the history
* First successful build

* Added to Library View Extension

* Remove dependency on PresentationCore.dll

* Updated some attributes

* Added some resource strings

* AssemblySharedInfo

* Changed name to "Custom Dropdown"

* Added MD file

* Made changes to address two failed tests

* Fix broken tests (#12082)

Co-authored-by: Craig Long <[email protected]>

* Added test related files

* AGD 2199 Test Fix (#12161)

* Fix broken tests

* Remove temp test files

Co-authored-by: Craig Long <[email protected]>

* Modern styling applied to CustomDropdown node

* Update MarkdownGeneratorCommandTests.cs

* Resolved PR conflicts with master

* Midway commit

* Cleanup mostly done

* Addressed all issues related to first PR review round

* Removed .idea directory and added it to .gitignore

* Icon

* Merged from master

* Waypoint

* Error

* Commit just before fixing bug related to JSON deseiralization

* Fixed regression bug

* DYN file test completed

* Added tests and simplify some methods

* Addded the .dyn file required for tests to git tracking

* Corrected node name

* Addressed a couple of PR comments

* Deleted unused method

* Solved conflict with master

* A couple of changes

* AssemblySharedInfo

* Undid whitespace removal

* Undid blank line at the end of file

* Undid whitespace removal

* Undid whitespace removal

* Undid whitespace removal

* Undid blank line

* Revert XML indent size to 2 whitespaces

* Revert "Undid blank line"

This reverts commit 99bec28.

* Revert blank line

* Undid auto whitespace removal

* Undid auto whitespace removal

* Undid auto whitespace removal

* Undid auto whitespace removal

* Revert version number

* Undid auto whitespace removal

* Deleted two auto-generated resource cs files

* Fix build

* Don't hold separate source of truth, use Dynamo UI components.

Updates aren't yet working.

* Fix formatting.

* Remove INotifyPropertyChanged from DynamoDropDownItem.

Revert "Auxiliary commit to revert individual files from e849045"

This reverts commit eb01977c42b39ed216f700907810d1ccf3d70cd6.

* Fix some binding updates.

* Improve tab navigation.

* Fix more binding updates.

* Remove logging.

* Fix remove button styling.

* Rename to match current convention.

* Fix build by removing last line of AssemblySharedInfo.tt?

* Clean up tests.

* Clean up unnecessary changes.

* Clean up extra styling.

* Match +/- button color with existing nodes.

* Add serialization.

* Undo unnecessary changes.

* Fix image class names.

* Fix copy/paste deserialization.

* Actually fix icon images.

* Fix dropdown test.

* Remove lacing comment.

* Add custom selection documentation files.

* Update incorrect documentation on DoubleInput.

* Treat null AST as primitive for update graph execution cycle (#13221)

* Update CoreUtils.cs

* add test

* Fix some tests.

* Revert template change.

* Fix comment text.

* Localize output description.

* Add documentation.

* Reduce property visibility.

* Fix inline if format.

* Docs.

* Reduce whitespace.

* Docs fix.

* Naming fixes.

Co-authored-by: Craig Long <[email protected]>
Co-authored-by: Craig Long <[email protected]>
Co-authored-by: Trygve Wastvedt <[email protected]>
Co-authored-by: Trygve Wastvedt <[email protected]>
Co-authored-by: aparajit-pratap <[email protected]>
  • Loading branch information
6 people authored Aug 19, 2022
1 parent d49e7dd commit 4819d58
Show file tree
Hide file tree
Showing 28 changed files with 950 additions and 147 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ launchSettings.json
###############
*_ReSharper*

# IDE #
###############
.idea

#documentation files
doc/html/
Dynamo.sln.DotSettings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## In Depth
The Custom Dropdown node allows a user to create a dropdown selection input with custom labels and values. If all values are numbers, the output will be a double, and if all values are integers the output will be an integer. In the example below, "Two" is selected in the Custom Dropdown Menu node, making the output of that node the integer `2`.
___
## Example File

![Number](./CoreNodeModels.Input.CustomSelection_img.jpg)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## In Depth
Room numbers are returned as strings.
The Number node allows a user to enter a static number. This node is useful for things like constants that don't change values. Numbers can also be created by using a Code Block node. In the example below, the number is paired with a code block to create a list sequence with a variable step size.
___
## Example File

Expand Down
1 change: 0 additions & 1 deletion src/DynamoCoreWpf/Controls/DynamoNodeButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ private DynamoViewModel DynamoViewModel

public DynamoNodeButton()
{
Style = (Style)SharedDictionaryManager.DynamoModernDictionary["SNodeTextButton"];
}

public DynamoNodeButton(ModelBase model, string eventName)
Expand Down
168 changes: 130 additions & 38 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/Engine/ProtoCore/Utils/CoreUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,8 @@ public static bool IsPrimitiveASTNode(AssociativeNode node)
if (node is IntNode
|| node is DoubleNode
|| node is BooleanNode
|| node is StringNode)
|| node is StringNode
|| node is NullNode)
{
return true;
}
Expand Down Expand Up @@ -1001,4 +1002,4 @@ public static StackValue BuildStackValueForPrimitive(AssociativeNode node, Runti
return StackValue.BuildNull();
}
}
}
}
33 changes: 33 additions & 0 deletions src/Libraries/CoreNodeModels/CoreNodeModelsImages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,39 @@
PIw7vteQPuhLVMkA479rRIQ9hegBi3gVlTPYvr1bMcEHxT5Ginf+R2dm53gHaDPpF5En0WZeR3VH6qT1
trlz75fwK2w6VIVFBQ7AJvsESZk6BO/iW/E+9u9A57xW7BNsVoaQqfvVwBky/FPkch8Yc7bTvUnhewAA
AABJRU5ErkJggg==
</value>
</data>
<data name="CoreNodeModels.Input.CustomSelection.Large" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAh
NwAAITcBM1ifegAAA8ZJREFUeF7tmttV4zAQhlMCJWwJlJBn1s564+zz0gF0AB1AB9CBlyT77BIoIe/c
XEJ2xoy8g/BFcuRwjv1/58wBZF3/kUaSzQwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoCmK
4htZQnbx+vp6PUbjsZHNyU5k2F8Ld4Ts6u3tbUe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AAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAQDBms3/G6OUDtOjdugAAAABJRU5ErkJggg==
</value>
</data>
<data name="CoreNodeModels.Input.CustomSelection.Small" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
EgAACxIB0t1+/AAAAS1JREFUWEftkc1twzAMhTVCRvAIHsHn1g5Uu7lnhI6QEbxBuoEQpz13lB4N+HeF
8gmkISdpi6JC0QM/gLBIUI9PtFEURVH+LfM8Z+M4HmIF6VmW/hpqTKZpeqd4o4v1pdAvwkEX+jzqNmjC
BU6jMgzDHvqcXkMNFi/n1OOsTU7ldjHUVLk9PeR1UxZPXDIvVXEMewR67Ya/iZyh3/d9hvMVsi5OPTRo
f66KxdT5Mc9gSmp03qAW9gD5lfwobNUbvjVjAU0UNacLobgfWBUOJrhkXnc2pc08O3uXcsnTdV1Kw+dw
IPQxh9M1WA0uyLqE0AAGIW/Key8ihlALTQmXWtgG1VZGV7BDhxVyKQowQnFEcOlzsDI4jR14HIzwmO9p
2zaJFT8arCiKovwdxnwAzk7Zcq1S2RAAAAAASUVORK5CYII=
</value>
</data>
</root>
165 changes: 165 additions & 0 deletions src/Libraries/CoreNodeModels/Input/CustomSelection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml;

using Autodesk.DesignScript.Runtime;

using Dynamo.Graph;
using Dynamo.Graph.Nodes;

using Newtonsoft.Json;

using ProtoCore.AST.AssociativeAST;

namespace CoreNodeModels.Input
{
/// <summary>
/// This node allows the user to create a dropdown selection list with an arbitrary number of custom items.
/// </summary>
[NodeName("Custom Selection")]
[NodeCategory(BuiltinNodeCategories.CORE_INPUT)]
[NodeDescription("CustomSelectionNodeDescription", typeof(Properties.Resources))]
[NodeSearchTags("CustomSelectionSearchTags", typeof(Properties.Resources))]
[OutPortNames("value")]
[OutPortTypes("var")]
[OutPortDescriptions(typeof(Properties.Resources), "CustomSelectionOutputDescription")]
[IsDesignScriptCompatible]
public class CustomSelection : DSDropDownBase
{
private List<DynamoDropDownItem> serializedItems;

/// <summary>
/// Copy of <see cref="DSDropDownBase.Items"/> to be serialized./>
/// </summary>
[JsonProperty]
protected List<DynamoDropDownItem> SerializedItems
{
get => serializedItems;
set
{
serializedItems = value;

Items.Clear();

foreach (DynamoDropDownItem item in serializedItems)
{
Items.Add(item);
}
}
}

/// <summary>
/// Construct a new Custom Dropdown Menu node
/// </summary>
public CustomSelection() : base("Value")
{
ArgumentLacing = LacingStrategy.Disabled;

Items.Add(new DynamoDropDownItem("One", "1"));
Items.Add(new DynamoDropDownItem("Two", "2"));
Items.Add(new DynamoDropDownItem("Three", "3"));

SelectedIndex = 0;
}

[JsonConstructor]
protected CustomSelection(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base("Value", inPorts, outPorts)
{
}

/// <summary>
/// Build the AST for this node
/// </summary>
/// <param name="inputAstNodes"></param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
AssociativeNode associativeNode = AstFactory.BuildPrimitiveNodeFromObject(GetSelectedValue());

return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), associativeNode) };
}

/// <summary>
/// Return the selected item as an int, or a double, or a string
/// </summary>
/// <returns></returns>
private object GetSelectedValue()
{
if (SelectedIndex == -1)
{
return null;
}

DynamoDropDownItem selectedItem = Items[SelectedIndex];

if (selectedItem?.Item is string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return value;
}

if (Items.All(item => item is null || ( item.Item is string v && ( string.IsNullOrEmpty(v) || int.TryParse(v, out _) ) )))
{
int.TryParse(value, out int intValue);
return intValue;
}

if (Items.All(item => item is null || ( item.Item is string v && ( string.IsNullOrEmpty(v) || double.TryParse(v, out _) ) )))
{
double.TryParse(value, out double doubleValue);
return doubleValue;
}

return value;
}

return selectedItem?.Item;
}

protected override SelectionState PopulateItemsCore(string currentSelection)
{
return SelectionState.Restore;
}

[OnSerializing]
private void OnSerializing(StreamingContext context)
{
serializedItems = Items.ToList();
}

[Obsolete]
protected override void SerializeCore(XmlElement nodeElement, SaveContext context)
{
nodeElement.SetAttribute("serializedItems", JsonConvert.SerializeObject(Items));

base.SerializeCore(nodeElement, context);
}

[Obsolete]
protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
{
XmlAttribute itemsAttribute = nodeElement.Attributes["serializedItems"];

if (itemsAttribute == null)
{
return;
}

List<DynamoDropDownItem> items = JsonConvert.DeserializeObject<List<DynamoDropDownItem>>(itemsAttribute.Value);

Items.Clear();

foreach (DynamoDropDownItem item in items)
{
Items.Add(item);
}

base.DeserializeCore(nodeElement, context);
}

}
}
29 changes: 28 additions & 1 deletion src/Libraries/CoreNodeModels/Properties/Resources.Designer.cs

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

9 changes: 9 additions & 0 deletions src/Libraries/CoreNodeModels/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,19 @@ Default value: {0}</value>
<data name="IFNodeWarningMessage" xml:space="preserve">
<value>This node has been updated and will be removed in a future version of Dynamo. Existing behavior is retained, but a new version now supports Empty Lists, Null values and inputs of varying length. Please replace this node if you wish to use this improved behavior.</value>
</data>
<data name="CustomSelectionSearchTags" xml:space="preserve">
<value>dropdown;custom;custom dropdown;enum;custom enum</value>
</data>
<data name="CustomSelectionNodeDescription" xml:space="preserve">
<value>A dropdown menu with customizable values.</value>
</data>
<data name="ConversionNodeObsoleteMessage" xml:space="preserve">
<value>is obsolete, please use the new Convert Units node.</value>
</data>
<data name="IntegerSliderInfoMessage" xml:space="preserve">
<value>The value entered is not in the int64 range.</value>
</data>
<data name="CustomSelectionOutputDescription" xml:space="preserve">
<value>Selected value</value>
</data>
</root>
9 changes: 9 additions & 0 deletions src/Libraries/CoreNodeModels/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,16 @@ Default value: {0}</value>
<data name="ConversionNodeObsoleteMessage" xml:space="preserve">
<value>is obsolete, please use the new Convert Units node.</value>
</data>
<data name="CustomSelectionNodeDescription" xml:space="preserve">
<value>A dropdown menu with customizable values.</value>
</data>
<data name="CustomSelectionSearchTags" xml:space="preserve">
<value>dropdown;custom;custom dropdown;enum;custom enum</value>
</data>
<data name="IntegerSliderInfoMessage" xml:space="preserve">
<value>The value entered is not in the int64 range.</value>
</data>
<data name="CustomSelectionOutputDescription" xml:space="preserve">
<value>Selected value</value>
</data>
</root>
Loading

0 comments on commit 4819d58

Please sign in to comment.