Skip to content

Commit e1649a0

Browse files
authored
Improvement Number Format (#13744)
* Improvement Number Format * updating scope * minor refactoring * Number Format to Double and String values based on the preference * comment changes and refactoring
1 parent 707277b commit e1649a0

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

src/DynamoCore/Models/DynamoModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ private IPreferences CreateOrLoadPreferences(IPreferences preferences)
16631663

16641664
private static void InitializePreferences(IPreferences preferences)
16651665
{
1666-
DynamoUnits.Display.PrecisionFormat = preferences.NumberFormat;
1666+
ProtoCore.Mirror.MirrorData.PrecisionFormat = DynamoUnits.Display.PrecisionFormat = preferences.NumberFormat;
16671667

16681668
var settings = preferences as PreferenceSettings;
16691669
if (settings != null)
@@ -1683,8 +1683,8 @@ private void PreferenceSettings_PropertyChanged(object sender, PropertyChangedEv
16831683
{
16841684
switch (e.PropertyName)
16851685
{
1686-
case "NumberFormat":
1687-
DynamoUnits.Display.PrecisionFormat = PreferenceSettings.NumberFormat;
1686+
case nameof(PreferenceSettings.NumberFormat):
1687+
ProtoCore.Mirror.MirrorData.PrecisionFormat = DynamoUnits.Display.PrecisionFormat = PreferenceSettings.NumberFormat;
16881688
break;
16891689
}
16901690
}

src/DynamoCoreWpf/Utilities/PreferencesPanelUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Linq;
1+
using System.Linq;
22
using System.Windows;
33
using System.Windows.Controls;
44
using Dynamo.Controls;

src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ private static string GetStringFromObject(object obj)
250250
return ObjectToLabelString(obj);
251251
case TypeCode.Double:
252252
return ((double)obj).ToString(numberFormat, CultureInfo.InvariantCulture);
253+
//TODO: uncomment this once https://jira.autodesk.com/browse/DYN-5101 is complete
254+
//return ((double)obj).ToString(ProtoCore.Mirror.MirrorData.PrecisionFormat, CultureInfo.InvariantCulture);
253255
case TypeCode.Int32:
254256
return ((int)obj).ToString(CultureInfo.InvariantCulture);
255257
case TypeCode.Int64:
@@ -259,6 +261,10 @@ private static string GetStringFromObject(object obj)
259261
case TypeCode.Object:
260262
return ObjectToLabelString(obj);
261263
default:
264+
if (double.TryParse(obj.ToString(), out double d))
265+
{
266+
return Convert.ToDouble(obj).ToString(ProtoCore.Mirror.MirrorData.PrecisionFormat, CultureInfo.InvariantCulture);
267+
}
262268
return (string)obj;
263269
};
264270
}

src/DynamoCoreWpf/Views/Preview/PreviewControl.xaml.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
@@ -383,8 +383,7 @@ private void RefreshExpandedDisplay(Action refreshDisplay)
383383

384384
newViewModel = nodeViewModel.DynamoViewModel.WatchHandler.GenerateWatchViewModelForData(
385385
nodeViewModel.NodeModel.CachedValue, preferredDictionaryOrdering,
386-
null, nodeViewModel.NodeModel.AstIdentifierForPreview.Name, false);
387-
386+
null, nodeViewModel.NodeModel.AstIdentifierForPreview.Name, false);
388387
},
389388
(m) =>
390389
{
@@ -434,7 +433,7 @@ private void RefreshExpandedDisplay(Action refreshDisplay)
434433
}
435434
);
436435
}
437-
436+
438437
/// <summary>
439438
/// It's used to apply Collapsed and Expanded events for TreeViewItems.
440439
/// </summary>

src/Engine/ProtoCore/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.CompilerServices;
33

44
// General Information about an assembly is controlled through the following
@@ -12,6 +12,7 @@
1212
[assembly: InternalsVisibleTo("ProtoTest")]
1313
[assembly: InternalsVisibleTo("ProtoTestFx")]
1414
[assembly:InternalsVisibleTo("DynamoCore")]
15+
[assembly: InternalsVisibleTo("DynamoCoreWpf")]
1516
[assembly: InternalsVisibleTo("DynamoCoreTests")]
1617
[assembly: InternalsVisibleTo("DynamoCoreWpfTests")]
1718
[assembly: InternalsVisibleTo("ProtoImperative")]

src/Engine/ProtoCore/Reflection/MirrorData.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Linq;
@@ -208,6 +208,8 @@ internal static object GetData(StackValue sv, RuntimeCore runtimeCore)
208208
return null;
209209
}
210210

211+
internal static string PrecisionFormat { get; set; } = "f3";
212+
211213
/// <summary>
212214
/// Returns string representation of data
213215
/// </summary>
@@ -230,10 +232,23 @@ public string StringData
230232
// https://msdn.microsoft.com/en-us/library/3hfd35ad(v=vs.110).aspx
231233
// We should always use invariant culture format for formattable
232234
// object.
235+
236+
//TODO: uncomment this once https://jira.autodesk.com/browse/DYN-5101 is complete
237+
//if (Data is double)
238+
//{
239+
// return (Data as IFormattable).ToString(PrecisionFormat, CultureInfo.InvariantCulture);
240+
//}
241+
//else
242+
//{
233243
return (Data as IFormattable).ToString(null, CultureInfo.InvariantCulture);
244+
//}
234245
}
235246
else
236247
{
248+
if (double.TryParse(Data.ToString(), out double d))
249+
{
250+
return Convert.ToDouble(Data).ToString(PrecisionFormat, CultureInfo.InvariantCulture);
251+
}
237252
return Data.ToString();
238253
}
239254
}

0 commit comments

Comments
 (0)