-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DYN-6607 - Input/Output Node - part 1 (#14987)
* initialize definedata model - starting with the model and the test suite * added test structure, node customization - now types are contained inside an enum - added the basic primitives to the test structure, including lists checks - reworked the node to start getting the customization going (and make sense of the whole thing) * hierarchical container, geometry tests - created hierarchical container capable of tracking type inheritance - added all geometry tests * primitive tests done - finished all primitive date type tests * ggroup * Revert "ggroup" This reverts commit 1621855. * inheritance tests done - completed tests checking inf inheritance works on individual and on list level * comments - added a few additional comments - additional test checking if inheritance stops at the desired level (ie. `Cone` does not inherit from `Curve`) * finished refactoring for tests - removed the Enum, replaced directly with Type * refactor, comments - removed dictionary in favor of list of datatypes - renamed methods to better suit the specificity of the node functionality they were serving --------- Co-authored-by: Ashish Aggarwal <[email protected]>
- Loading branch information
Showing
9 changed files
with
952 additions
and
22 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
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,161 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using DSCore; | ||
using Dynamo.Graph.Nodes; | ||
using Newtonsoft.Json; | ||
using ProtoCore.AST.AssociativeAST; | ||
using VMDataBridge; | ||
|
||
|
||
namespace CoreNodeModels | ||
{ | ||
[NodeName("DefineData")] | ||
[NodeDescription(nameof(Properties.Resources.RememberDescription), typeof(Properties.Resources))] | ||
[NodeCategory("Core.Data")] | ||
[InPortNames(">")] | ||
[InPortTypes("var[]..[]")] | ||
[InPortDescriptions(typeof(Properties.Resources), | ||
nameof(Properties.Resources.RememberInputToolTip))] | ||
[OutPortNames(">")] | ||
[OutPortTypes("var[]..[]")] | ||
[OutPortDescriptions(typeof(Properties.Resources), nameof(Properties.Resources.RememberOuputToolTip))] | ||
[IsDesignScriptCompatible] | ||
public class DefineData : DSDropDownBase | ||
{ | ||
private bool context; | ||
private List<DynamoDropDownItem> serializedItems; | ||
|
||
[JsonProperty] | ||
public bool IsList { get; set; } | ||
|
||
/// <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 DefineData Dropdown Menu node | ||
/// </summary> | ||
public DefineData() : base(">") | ||
{ | ||
RegisterAllPorts(); | ||
PropertyChanged += OnPropertyChanged; | ||
|
||
foreach (var dataType in Data.GetDataNodeDynamoTypeList()) | ||
{ | ||
var displayName = dataType.Name; | ||
var value = dataType; | ||
|
||
Items.Add(new DynamoDropDownItem(displayName, value)); | ||
} | ||
|
||
SelectedIndex = 0; | ||
} | ||
|
||
[JsonConstructor] | ||
private DefineData(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(">", inPorts, outPorts) | ||
{ | ||
PropertyChanged += OnPropertyChanged; | ||
} | ||
|
||
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
|
||
} | ||
|
||
protected override void OnBuilt() | ||
{ | ||
base.OnBuilt(); | ||
DataBridge.Instance.RegisterCallback(GUID.ToString(), DataBridgeCallback); | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
PropertyChanged -= OnPropertyChanged; | ||
base.Dispose(); | ||
DataBridge.Instance.UnregisterCallback(GUID.ToString()); | ||
} | ||
|
||
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes) | ||
{ | ||
var resultAst = new List<AssociativeNode>(); | ||
|
||
// function call inputs - reference to the function, and the function arguments coming from the inputs | ||
// the object to be (type) evaluated | ||
// the expected datatype | ||
// if the input is an ArrayList or not | ||
var function = new Func<object, string, bool, bool>(DSCore.Data.IsSupportedDataNodeDynamoType); | ||
var funtionInputs = new List<AssociativeNode> { | ||
inputAstNodes[0], | ||
AstFactory.BuildStringNode((Items[SelectedIndex].Item as Data.DataNodeDynamoType).Type.ToString()), | ||
AstFactory.BuildBooleanNode(IsList) }; | ||
|
||
|
||
var functionCall = AstFactory.BuildFunctionCall(function, funtionInputs); | ||
var functionCallIdentifier = AstFactory.BuildIdentifier(GUID + "_func"); | ||
|
||
// build the function call | ||
resultAst.Add(AstFactory.BuildAssignment(functionCallIdentifier, functionCall)); | ||
|
||
// build the output call | ||
resultAst.Add(AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall)); | ||
|
||
// build the call for the DataBridge | ||
resultAst.Add(AstFactory.BuildAssignment(functionCallIdentifier, | ||
DataBridge.GenerateBridgeDataAst(GUID.ToString(), | ||
AstFactory.BuildExprList(inputAstNodes)))); | ||
|
||
|
||
return resultAst; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Not sure at the moment how relevant is the databridge for this node type | ||
/// </summary> | ||
/// <param name="data"></param> | ||
private void DataBridgeCallback(object data) | ||
{ | ||
var inputs = data as ArrayList; | ||
|
||
var inputObject = inputs[0]; | ||
|
||
if (!InPorts[0].IsConnected) | ||
{ | ||
return; | ||
} | ||
|
||
} | ||
|
||
|
||
protected override SelectionState PopulateItemsCore(string currentSelection) | ||
{ | ||
return SelectionState.Restore; | ||
} | ||
|
||
[OnSerializing] | ||
private void OnSerializing(StreamingContext context) | ||
{ | ||
serializedItems = Items.ToList(); | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/Libraries/CoreNodeModelsWpf/Controls/DefineDataControl.xaml
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,81 @@ | ||
<UserControl x:Class="CoreNodeModelsWpf.Controls.DefineDataControl" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:p="clr-namespace:Dynamo.Wpf.Properties" | ||
xmlns:core="clr-namespace:Dynamo.Nodes;assembly=DynamoCoreWpf" | ||
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf" | ||
mc:Ignorable="d" | ||
d:DesignHeight="200" d:DesignWidth="350"> | ||
<UserControl.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoModernDictionaryUri}" /> | ||
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoConvertersDictionaryUri}" /> | ||
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
<SolidColorBrush x:Key="StrokeBrush" Color="#999999 " /> | ||
|
||
<PathGeometry x:Key="QuestionIcon" Figures="M8 0C3.58172 0 0 3.58172 0 8C0 12.4183 3.58172 16 8 16C12.4183 16 16 12.4183 16 8C16 5.87827 15.1571 3.84344 13.6569 2.34315C12.1566 0.842855 10.1217 0 8 0ZM9 14H7V12H9V14ZM10 8.45C9.38 8.74 9 8.95 9 9.45V11H7V8.92C6.97651 8.37388 7.19188 7.84457 7.59 7.47C8.05 7.06 9.75 6.56 9.75 5.59C9.75 5 9.45 4.33 8.23 4.33C6.75 4.33 6.23 6.66 6.23 6.66L4.45 6.25C4.45 6.25 4.86 2.39 8.25 2.39C9.13189 2.33809 9.99827 2.63874 10.6584 3.22576C11.3186 3.81279 11.7185 4.63809 11.77 5.52C11.8034 6.75866 11.1119 7.90321 10 8.45Z"/> | ||
<PathGeometry x:Key="PadlockIcon" Figures="M 35 7 C 30.038 7 26 11.038 26 16 L 26 20 L 9 20 C 7.343 20 6 21.343 6 23 L 6 38 C 6 39.657 7.343 41 9 41 L 27 41 C 28.657 41 30 39.657 30 38 L 30 23 C 30 21.343 28.657 20 27 20 L 27 16 C 27 11.589 30.589 8 35 8 C 39.411 8 43 11.589 43 16 L 43 20.5 C 43 20.776 43.224 21 43.5 21 C 43.776 21 44 20.776 44 20.5 L 44 16 C 44 11.038 39.962 7 35 7 z M 9 21 L 27 21 C 28.105 21 29 21.895 29 23 L 29 38 C 29 39.105 28.105 40 27 40 L 9 40 C 7.895 40 7 39.105 7 38 L 7 23 C 7 21.895 7.895 21 9 21 z"/> | ||
</ResourceDictionary> | ||
</UserControl.Resources> | ||
<DockPanel VerticalAlignment="Bottom"> | ||
<ToggleButton VerticalAlignment="Center" | ||
Width="30" | ||
Height="15" | ||
Margin="2,0,0,0" | ||
IsEnabled="True" | ||
IsChecked="{Binding Path=StaticSplashScreenEnabled}" | ||
Style="{StaticResource EllipseToggleButton1}"/> | ||
<Label Content="List" | ||
Margin="4 0" | ||
Foreground="{StaticResource PreferencesWindowFontColor}"/> | ||
<Canvas VerticalAlignment="Center" Width="14" Height="14"> | ||
<Viewbox Width="14" Height="14"> | ||
<Path x:Name="ExpandPath" Data="{StaticResource QuestionIcon}" | ||
Fill="{StaticResource StrokeBrush}" | ||
Stroke="{StaticResource StrokeBrush}"> | ||
</Path> | ||
</Viewbox> | ||
<Canvas.ToolTip> | ||
<ToolTip Content="Fill in later" | ||
Style="{StaticResource GenericToolTipLight}"/> | ||
</Canvas.ToolTip> | ||
</Canvas> | ||
|
||
<Button Margin="0 0 10 3" | ||
x:Name="LockButton" | ||
BorderThickness="0" | ||
HorizontalAlignment="Right" | ||
VerticalAlignment="Center" | ||
Cursor="Hand"> | ||
<Button.ToolTip> | ||
<ToolTip Content="Lock tooltup" | ||
Style="{StaticResource GenericToolTipLight}" /> | ||
</Button.ToolTip> | ||
<Button.Template> | ||
<ControlTemplate TargetType="Button"> | ||
<Border Background="Transparent"> | ||
<Viewbox Width="16" | ||
Height="16" | ||
VerticalAlignment="Center"> | ||
<Path x:Name="Folder" | ||
Fill="#999999" | ||
Data="{StaticResource PadlockIcon}" | ||
StrokeThickness="1" | ||
Stroke="{StaticResource StrokeBrush}"> | ||
</Path> | ||
</Viewbox> | ||
</Border> | ||
<ControlTemplate.Triggers> | ||
<Trigger Property="IsMouseOver" Value="True"> | ||
<Setter TargetName="Folder" Property="Fill" Value="#6AC0E7" /> | ||
</Trigger> | ||
</ControlTemplate.Triggers> | ||
</ControlTemplate> | ||
</Button.Template> | ||
</Button> | ||
</DockPanel> | ||
</UserControl> |
Oops, something went wrong.