Skip to content

Commit

Permalink
Merge branch 'master' into update_libg231
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Jan 15, 2025
2 parents fb776aa + 18e1249 commit b591f88
Show file tree
Hide file tree
Showing 11 changed files with 810 additions and 6 deletions.
35 changes: 33 additions & 2 deletions src/DynamoCoreWpf/Interfaces/IWatchHandler.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System;

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Dynamo.Configuration;
using Newtonsoft.Json.Linq;

using Dynamo.Extensions;
using Dynamo.ViewModels;
using Dynamo.Wpf.Properties;
using ProtoCore.DSASM;
using ProtoCore.Mirror;
using ProtoCore.Utils;
using Newtonsoft.Json;

namespace Dynamo.Interfaces
{
Expand Down Expand Up @@ -83,7 +86,18 @@ private WatchViewModel ProcessThing(object value, ProtoCore.RuntimeCore runtimeC

return node;
}
if (value is JObject obj)
{
var dict = ConvertJObjectToDictionary(obj);
var node = new WatchViewModel(dict.Keys.Any() ? WatchViewModel.DICTIONARY : WatchViewModel.EMPTY_DICTIONARY, tag, RequestSelectGeometry, true);

foreach (var e in dict.Keys.Zip(dict.Values, (key, val) => new { key, val }))
{
node.Children.Add(ProcessThing(e.val, runtimeCore, tag + ":" + e.key, showRawData, callback));
}

return node;
}
if (!(value is string) && value is IEnumerable)
{
var list = (value as IEnumerable).Cast<dynamic>().ToList();
Expand Down Expand Up @@ -122,6 +136,23 @@ private WatchViewModel ProcessThing(object value, ProtoCore.RuntimeCore runtimeC
return new WatchViewModel(value, tag, RequestSelectGeometry);
}

private static Dictionary<string, object> ConvertJObjectToDictionary(JObject jObject)
{
var settings = new JsonSerializerSettings
{
// Add any specific settings you need here
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore,
TypeNameHandling = TypeNameHandling.None
};

var json = jObject.ToString();
var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(json, settings);

return dictionary;
}


private WatchViewModel ProcessThing(double value, ProtoCore.RuntimeCore runtimeCore, string tag, bool showRawData, WatchHandlerCallback callback)
{
return new WatchViewModel(value, tag, RequestSelectGeometry);
Expand Down
12 changes: 12 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ private static string GetStringFromObject(object obj)
return ((DateTime)obj).ToString(PreferenceSettings.DefaultDateFormat, CultureInfo.InvariantCulture);
case TypeCode.Object:
return ObjectToLabelString(obj);
case TypeCode.Byte:
return ((byte)obj).ToString(CultureInfo.InvariantCulture);
case TypeCode.UInt32:
return ((uint)obj).ToString(CultureInfo.InvariantCulture);
case TypeCode.UInt64:
return ((ulong)obj).ToString(CultureInfo.InvariantCulture);
default:
return (string)obj;
};
Expand Down Expand Up @@ -313,6 +319,12 @@ private string GetDisplayType(object obj)
return nameof(TypeCode.Object);
case TypeCode.String:
return nameof(TypeCode.String);
case TypeCode.Byte:
return nameof(TypeCode.Byte);
case TypeCode.UInt32:
return nameof(TypeCode.UInt32);
case TypeCode.UInt64:
return nameof(TypeCode.UInt64);
case TypeCode.Empty:
return String.Empty;
default:
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,8 @@ private void HandlePackageManagerWindowClosed(object sender, EventArgs e)

var cmd = Analytics.TrackCommandEvent("PackageManager");
cmd.Dispose();

this.Activate();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Views/Preview/WatchTree.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class WatchTree : UserControl
private readonly double widthPerCharacter = 7.5;
private static readonly int defaultHeightSize = 200;
private readonly int minWidthSize = 100;
private readonly int minHeightSize = 38;
private readonly int minHeightSize = 40;
private readonly int minHeightForList = 83;

public WatchTree(WatchViewModel vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void CustomizeView(Watch nodeModel, NodeView nodeView)

ResetWatch();

watchTree.Width = nodeModel.WatchWidth == 0 ? watchTree.Width : nodeModel.WatchWidth;
watchTree.Height = nodeModel.WatchHeight == 0 ? watchTree.Height : nodeModel.WatchHeight;
watchTree.Width = nodeModel.WatchWidth < watchTree.Width ? watchTree.Width : nodeModel.WatchWidth;
watchTree.Height = nodeModel.WatchHeight < watchTree.Height ? watchTree.Height : nodeModel.WatchHeight;

//Store width and height info of the node in the dictionary.
Watch.NodeSizes[watch.GUID] = new Tuple<double, double>(nodeModel.WatchWidth, nodeModel.WatchHeight);
Expand Down
91 changes: 91 additions & 0 deletions test/DynamoCoreWpfTests/WatchNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected override void GetLibrariesToPreload(List<string> libraries)
libraries.Add("VMDataBridge.dll");
libraries.Add("ProtoGeometry.dll");
libraries.Add("DesignScriptBuiltin.dll");
libraries.Add("DSCoreNodes.dll");
libraries.Add("FunctionObject.ds");
libraries.Add("FFITarget.dll");
base.GetLibrariesToPreload(libraries);
Expand Down Expand Up @@ -363,6 +364,83 @@ public void WatchMultiReturnNodeOrder()
Assert.AreEqual("1", children[3].NodeLabel);
}

[Test]
public void WatchDictionaryByteValuesDisplaysCorrectly()
{
string openPath = Path.Combine(TestDirectory, @"core\watch\WatchDictionaryByteValuesDisplaysCorrectly.dyn");
ViewModel.OpenCommand.Execute(openPath);
ViewModel.HomeSpace.Run();

var watchNode = ViewModel.Model.CurrentWorkspace.FirstNodeFromWorkspace<Watch>();
var watchVM = ViewModel.WatchHandler.GenerateWatchViewModelForData(
watchNode.CachedValue, watchNode.OutPorts.Select(p => p.Name),
ViewModel.Model.EngineController.LiveRunnerRuntimeCore,
watchNode.AstIdentifierForPreview.Name, true);

var list = watchVM.Children;
Assert.AreEqual(1, list.Count);
var children = list[0].Children;
Assert.AreEqual(12, children.Count);
Assert.AreEqual("Byte", children[0].ValueType);
Assert.AreEqual("72", children[0].NodeLabel);
}

[Test]
public void WatchDictionaryUintValuesDisplaysCorrectly()
{
string openPath = Path.Combine(TestDirectory, @"core\watch\WatchDictionaryUintValuesDisplaysCorrectly.dyn");
ViewModel.OpenCommand.Execute(openPath);
ViewModel.HomeSpace.Run();

var watchNode = ViewModel.Model.CurrentWorkspace.FirstNodeFromWorkspace<Watch>();
var watchVM = ViewModel.WatchHandler.GenerateWatchViewModelForData(
watchNode.CachedValue, watchNode.OutPorts.Select(p => p.Name),
ViewModel.Model.EngineController.LiveRunnerRuntimeCore,
watchNode.AstIdentifierForPreview.Name, true);

var list = watchVM.Children;
Assert.AreEqual(1, list.Count);
var children = list[0].Children;
Assert.AreEqual(5, children.Count);
Assert.AreEqual("UInt32", children[0].ValueType);
Assert.AreEqual("3", children[2].NodeLabel);

var uint64node = ViewModel.Model.CurrentWorkspace.GetDSFunctionNodeFromWorkspace("DummyZeroTouchClass.PreviewUint64Dictionary");
var vm = ViewModel.WatchHandler.GenerateWatchViewModelForData(
uint64node.CachedValue, watchNode.OutPorts.Select(p => p.Name),
ViewModel.Model.EngineController.LiveRunnerRuntimeCore,
watchNode.AstIdentifierForPreview.Name, true);

list = vm.Children;
Assert.AreEqual(1, list.Count);
children = list[0].Children;
Assert.AreEqual(5, children.Count);
Assert.AreEqual("UInt64", children[0].ValueType);
Assert.AreEqual("3", children[2].NodeLabel);
}

[Test]
public void WatchDictionaryJSONValuesDisplaysCorrectly()
{

string openPath = Path.Combine(TestDirectory, @"core\watch\WatchDictionaryJSONValuesDisplaysCorrectly.dyn");
ViewModel.OpenCommand.Execute(openPath);
ViewModel.HomeSpace.Run();

var watchNode = ViewModel.Model.CurrentWorkspace.FirstNodeFromWorkspace<Watch>();
var watchVM = ViewModel.WatchHandler.GenerateWatchViewModelForData(
watchNode.CachedValue, watchNode.OutPorts.Select(p => p.Name),
ViewModel.Model.EngineController.LiveRunnerRuntimeCore,
watchNode.AstIdentifierForPreview.Name, true);

var list = watchVM.Children;
Assert.AreEqual(1, list.Count);
var children = list[0].Children;
Assert.AreEqual(2, children.Count);
Assert.AreEqual("String", children[0].ValueType);
Assert.AreEqual("value1", children[0].NodeLabel);
}

[Test]
public void WatchNestedDictionaryPreviewFromMlutiReturnNode()
{
Expand Down Expand Up @@ -393,6 +471,19 @@ public void WatchNestedDictionaryPreviewFromMlutiReturnNode()
}

[Test]
public void WatchNodeWithBadSize()
{
string openPath = Path.Combine(TestDirectory, @"core\watch\WatchNodeBadSize.dyn");
ViewModel.OpenCommand.Execute(openPath);
ViewModel.HomeSpace.Run();

var watchNode = ViewModel.Model.CurrentWorkspace.NodeFromWorkspace("355685ad-754c-400f-ac75-53a56c7d5423") as Watch;

Assert.AreEqual(100, watchNode.Width);
Assert.AreEqual(100, watchNode.Height);
}

[Test]
public void GetNodeLabelTree()
{
// Arrange
Expand Down
47 changes: 46 additions & 1 deletion test/Engine/FFITarget/DummyZeroTouchClass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes;
using System.Text;
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace FFITarget
{
Expand All @@ -14,5 +18,46 @@ public int FunctionWithoutDescription(int a)
{
return 0;
}

public static Dictionary<string, object> PreviewByteDictionary()
{
// Example base64 encoded string
string encodedString = "SGVsbG8gV29ybGQh";

byte[] decodedBytes = Convert.FromBase64String(encodedString);
var result = new Dictionary<string, object>();
result.Add("decodedBytes", decodedBytes);

return result;
}

public static Dictionary<string, object> PreviewUint32Dictionary()
{
var uintArray = new uint[] { 1, 2, 3, 4, 5 };
var result = new Dictionary<string, object>();
result.Add("uint32List", uintArray);

return result;
}

public static Dictionary<string, object> PreviewUint64Dictionary()
{
var uintArray = new ulong[] { 1, 2, 3, 4, 5 };
var result = new Dictionary<string, object>();
result.Add("uint64List", uintArray);

return result;
}

public static Dictionary<string, object> PreviewJSONDictionary()
{
var json = new JObject();
json.Add("key1", "value1");
json.Add("key2", "value2");
var result = new Dictionary<string, object>();
result.Add("json", json);

return result;
}
}
}
Loading

0 comments on commit b591f88

Please sign in to comment.