From 3785210f128f578cef771fa81ea888ccf4beed99 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Mon, 5 Feb 2024 15:36:26 +0000 Subject: [PATCH 01/15] initialize definedata model - starting with the model and the test suite --- src/Libraries/CoreNodeModels/DefineData.cs | 118 +++++++++++++++++++++ src/Libraries/CoreNodes/Data.cs | 48 +++++++-- test/DynamoCoreTests/DSCoreDataTests.cs | 23 +++- 3 files changed, 178 insertions(+), 11 deletions(-) create mode 100644 src/Libraries/CoreNodeModels/DefineData.cs diff --git a/src/Libraries/CoreNodeModels/DefineData.cs b/src/Libraries/CoreNodeModels/DefineData.cs new file mode 100644 index 00000000000..479fa67defb --- /dev/null +++ b/src/Libraries/CoreNodeModels/DefineData.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +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("InputValue", "TypeID", "Context")] + [InPortTypes("var[]..[]", "string", "boolean")] + [InPortDescriptions(typeof(Properties.Resources), + nameof(Properties.Resources.RememberInputToolTip), + nameof(Properties.Resources.RememberInputToolTip), + nameof(Properties.Resources.RememberInputToolTip))] + [OutPortNames("OutputValue")] + [OutPortTypes("var[]..[]")] + [OutPortDescriptions(typeof(Properties.Resources), nameof(Properties.Resources.RememberOuputToolTip))] + [IsDesignScriptCompatible] + internal class DefineData : NodeModel + { + private string cache = ""; + + public string Cache + { + get { return cache; } + set + { + var valueToSet = value == null ? "" : value; + if (valueToSet != cache) + { + cache = valueToSet; + MarkNodeAsModified(); + } + } + } + + [JsonConstructor] + private DefineData(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts) + { + PropertyChanged += OnPropertyChanged; + } + + public DefineData() + { + RegisterAllPorts(); + 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 BuildOutputAst(List inputAstNodes) + { + var resultAst = new List(); + + // Function call inputs - reference to the function, and the function arguments coming from the inputs + var function = new Func(DSCore.Data.IsSupportedDataType); + var funtionInputs = new List { inputAstNodes[0], inputAstNodes[1], inputAstNodes[2] }; + + //First build the function call + var functionCall = AstFactory.BuildFunctionCall(function, funtionInputs); + + resultAst.Add(AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall)); + + // Now build the cal for the DataBridge ?? + var functionCallIndentifier = AstFactory.BuildIdentifier(GUID + "_func"); + + resultAst.Add(AstFactory.BuildAssignment( + functionCallIndentifier, + DataBridge.GenerateBridgeDataAst(GUID.ToString(), AstFactory.BuildExprList(inputAstNodes)))); + + + return resultAst; + } + + + /// + /// Not sure at the moment how relevant is the databridge for this node type + /// + /// + private void DataBridgeCallback(object data) + { + var inputs = data as ArrayList; + + var inputObject = inputs[0]; + var dataType = inputs[1] as string; + var context = (bool)inputs[2]; + + if (!InPorts[0].IsConnected && !InPorts[1].IsConnected && !InPorts[2].IsConnected) + { + return; + } + + } + } +} diff --git a/src/Libraries/CoreNodes/Data.cs b/src/Libraries/CoreNodes/Data.cs index 011d581df5e..1bf80c0274f 100644 --- a/src/Libraries/CoreNodes/Data.cs +++ b/src/Libraries/CoreNodes/Data.cs @@ -1,20 +1,20 @@ -using Autodesk.DesignScript.Geometry; using System; +using System.Collections; using System.Collections.Generic; -using System.Linq; -using Autodesk.DesignScript.Runtime; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System.Drawing; -using System.IO; using System.Drawing.Imaging; -using System.Collections; +using System.Globalization; +using System.IO; +using System.Linq; using System.Runtime.Versioning; +using System.Text; +using Autodesk.DesignScript.Geometry; +using Autodesk.DesignScript.Runtime; using Dynamo.Events; using Dynamo.Logging; using Dynamo.Session; -using System.Globalization; -using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace DSCore { @@ -529,6 +529,36 @@ public static Dictionary Remember([ArbitraryDimensionArrayImport internal static DynamoLogger dynamoLogger = ExecutionEvents.ActiveSession?.GetParameterValue(ParameterKeys.Logger) as DynamoLogger; + /// + /// Function to validate input type against supported Dynamo input types + /// + /// The incoming data to validate + /// The input type provided by the user. It has to match the inputValue type + /// The value of this boolean decides if the input is a single object or a list + /// + [IsVisibleInDynamoLibrary(false)] + public static bool IsSupportedDataType([ArbitraryDimensionArrayImport] object inputValue, string typeID, bool context) + { + // Make sure the initial inputs are not nulls + if (inputValue == null || string.IsNullOrEmpty(typeID)) + { + return false; + } + + string newCachedJson; + try + { + newCachedJson = StringifyJSON(inputValue); + } + catch (Exception ex) + { + dynamoLogger?.Log("Remember failed to serialize with this exception: " + ex.Message); + throw new NotSupportedException(string.Format(Properties.Resources.Exception_Serialize_Unsupported_Type, inputValue.GetType().FullName)); + } + + return true; + } + #endregion } } diff --git a/test/DynamoCoreTests/DSCoreDataTests.cs b/test/DynamoCoreTests/DSCoreDataTests.cs index 4ee3955e9df..7a9323be153 100644 --- a/test/DynamoCoreTests/DSCoreDataTests.cs +++ b/test/DynamoCoreTests/DSCoreDataTests.cs @@ -4,10 +4,8 @@ using System.Drawing; using System.IO; using System.Linq; -using System.Text; using Dynamo.Graph.Nodes; using Dynamo.Graph.Nodes.ZeroTouch; -using DynamoUnits; using Newtonsoft.Json.Linq; using NUnit.Framework; @@ -573,5 +571,26 @@ public void ThrowsWhenPassedAnObjectThatCanNotSerialize() Assert.That(() => DSCore.Data.Remember(unsupportedInput, validCachedJson), Throws.Exception); } + + [Test] + [Category("UnitTests")] + public void IsSupportedDataTypeFalseOnInitialNullInputs() + { + object unsupportedInput = null; + object supportedInput = "inputValue"; + var validString = "type"; + var validate = DSCore.Data.IsSupportedDataType(unsupportedInput, validString, false); + + Assert.AreEqual(false, validate); + + validate = DSCore.Data.IsSupportedDataType(supportedInput, null, false); + Assert.AreEqual(false, validate); + + validate = DSCore.Data.IsSupportedDataType(supportedInput, string.Empty, false); + Assert.AreEqual(false, validate); + + validate = DSCore.Data.IsSupportedDataType(supportedInput, validString, false); + Assert.AreEqual(true, validate); + } } } From 93c4741eeeb19864d6ccb62e60512c13acd33485 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Tue, 20 Feb 2024 22:06:26 +0000 Subject: [PATCH 02/15] 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) --- .../UI/Themes/Modern/DynamoModern.xaml | 130 ++++++++++++++++++ src/Libraries/CoreNodeModels/DefineData.cs | 104 ++++++++++---- .../Controls/DefineDataControl.xaml | 81 +++++++++++ .../Controls/DefineDataControl.xaml.cs | 23 ++++ .../CoreNodeModelsWpf.csproj | 1 + .../CoreNodeModelsWpf/DefineDataViewModel.cs | 21 +++ .../NodeViewCustomizations/DefineData.cs | 47 +++++++ src/Libraries/CoreNodes/Data.cs | 68 +++++++-- test/DynamoCoreTests/DSCoreDataTests.cs | 56 ++++++-- 9 files changed, 480 insertions(+), 51 deletions(-) create mode 100644 src/Libraries/CoreNodeModelsWpf/Controls/DefineDataControl.xaml create mode 100644 src/Libraries/CoreNodeModelsWpf/Controls/DefineDataControl.xaml.cs create mode 100644 src/Libraries/CoreNodeModelsWpf/DefineDataViewModel.cs create mode 100644 src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/DefineData.cs diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml index c3cc6e2c43e..a4b33d7d357 100644 --- a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml +++ b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml @@ -489,6 +489,136 @@ + + + + + + + + + + + + + + + + + + + + +