-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AGD-2199 - custom dropdown node (#11958)
* 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
1 parent
d49e7dd
commit 4819d58
Showing
28 changed files
with
950 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
doc/distrib/NodeHelpFiles/CoreNodeModels.Input.CustomSelection.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Binary file added
BIN
+32.4 KB
doc/distrib/NodeHelpFiles/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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
src/Libraries/CoreNodeModels/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.