Skip to content

Improvement Number Format #13744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ private IPreferences CreateOrLoadPreferences(IPreferences preferences)

private static void InitializePreferences(IPreferences preferences)
{
DynamoUnits.Display.PrecisionFormat = preferences.NumberFormat;
ProtoCore.Mirror.MirrorData.PrecisionFormat = DynamoUnits.Display.PrecisionFormat = preferences.NumberFormat;

var settings = preferences as PreferenceSettings;
if (settings != null)
Expand All @@ -1656,8 +1656,8 @@ private void PreferenceSettings_PropertyChanged(object sender, PropertyChangedEv
{
switch (e.PropertyName)
{
case "NumberFormat":
DynamoUnits.Display.PrecisionFormat = PreferenceSettings.NumberFormat;
case nameof(PreferenceSettings.NumberFormat):
ProtoCore.Mirror.MirrorData.PrecisionFormat = DynamoUnits.Display.PrecisionFormat = PreferenceSettings.NumberFormat;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Utilities/PreferencesPanelUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can be reverted entirely.

using System.Windows;
using System.Windows.Controls;
using Dynamo.Controls;
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ private static string GetStringFromObject(object obj)
return ObjectToLabelString(obj);
case TypeCode.Double:
return ((double)obj).ToString(numberFormat, CultureInfo.InvariantCulture);
//TODO: uncomment this once https://jira.autodesk.com/browse/DYN-5101 is complete
//return ((double)obj).ToString(ProtoCore.Mirror.MirrorData.PrecisionFormat, CultureInfo.InvariantCulture);
case TypeCode.Int32:
return ((int)obj).ToString(CultureInfo.InvariantCulture);
case TypeCode.Int64:
Expand All @@ -259,6 +261,10 @@ private static string GetStringFromObject(object obj)
case TypeCode.Object:
return ObjectToLabelString(obj);
default:
if (double.TryParse(obj.ToString(), out double d))
{
return Convert.ToDouble(obj).ToString(ProtoCore.Mirror.MirrorData.PrecisionFormat, CultureInfo.InvariantCulture);
}
return (string)obj;
};
}
Expand Down
7 changes: 3 additions & 4 deletions src/DynamoCoreWpf/Views/Preview/PreviewControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -383,8 +383,7 @@ private void RefreshExpandedDisplay(Action refreshDisplay)

newViewModel = nodeViewModel.DynamoViewModel.WatchHandler.GenerateWatchViewModelForData(
nodeViewModel.NodeModel.CachedValue, preferredDictionaryOrdering,
null, nodeViewModel.NodeModel.AstIdentifierForPreview.Name, false);

null, nodeViewModel.NodeModel.AstIdentifierForPreview.Name, false);
},
(m) =>
{
Expand Down Expand Up @@ -434,7 +433,7 @@ private void RefreshExpandedDisplay(Action refreshDisplay)
}
);
}

/// <summary>
/// It's used to apply Collapsed and Expanded events for TreeViewItems.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Engine/ProtoCore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;

// General Information about an assembly is controlled through the following
Expand All @@ -12,6 +12,7 @@
[assembly: InternalsVisibleTo("ProtoTest")]
[assembly: InternalsVisibleTo("ProtoTestFx")]
[assembly:InternalsVisibleTo("DynamoCore")]
[assembly: InternalsVisibleTo("DynamoCoreWpf")]
[assembly: InternalsVisibleTo("DynamoCoreTests")]
[assembly: InternalsVisibleTo("DynamoCoreWpfTests")]
[assembly: InternalsVisibleTo("ProtoImperative")]
Expand Down
17 changes: 16 additions & 1 deletion src/Engine/ProtoCore/Reflection/MirrorData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -208,6 +208,8 @@ internal static object GetData(StackValue sv, RuntimeCore runtimeCore)
return null;
}

internal static string PrecisionFormat { get; set; } = "f3";

/// <summary>
/// Returns string representation of data
/// </summary>
Expand All @@ -230,10 +232,23 @@ public string StringData
// https://msdn.microsoft.com/en-us/library/3hfd35ad(v=vs.110).aspx
// We should always use invariant culture format for formattable
// object.

//TODO: uncomment this once https://jira.autodesk.com/browse/DYN-5101 is complete
//if (Data is double)
//{
// return (Data as IFormattable).ToString(PrecisionFormat, CultureInfo.InvariantCulture);
//}
//else
//{
return (Data as IFormattable).ToString(null, CultureInfo.InvariantCulture);
//}
}
else
{
if (double.TryParse(Data.ToString(), out double d))
{
return Convert.ToDouble(Data).ToString(PrecisionFormat, CultureInfo.InvariantCulture);
}
return Data.ToString();
}
}
Expand Down