CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 660
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
Improvement Number Format #13744
Changes from 1 commit
01f5a8b
9a48930
e0a46a8
584cbcb
29881fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,6 +241,8 @@ public WatchViewModel(string label, string path, Action<string> tagGeometry, boo | |
IsCollection = label == WatchViewModel.LIST || label == WatchViewModel.DICTIONARY; | ||
} | ||
|
||
internal static string PrecisionFormat { get; set; } = "f3"; | ||
|
||
private static string GetStringFromObject(object obj) | ||
{ | ||
TypeCode type = Type.GetTypeCode(obj.GetType()); | ||
|
@@ -249,7 +251,7 @@ private static string GetStringFromObject(object obj) | |
case TypeCode.Boolean: | ||
return ObjectToLabelString(obj); | ||
case TypeCode.Double: | ||
return ((double)obj).ToString(numberFormat, CultureInfo.InvariantCulture); | ||
return ((double)obj).ToString(ProtoCore.Mirror.MirrorData.PrecisionFormat, CultureInfo.InvariantCulture); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again I would comment out this change for the time being until https://jira.autodesk.com/browse/DYN-5101 is done. Add a TODO. |
||
case TypeCode.Int32: | ||
return ((int)obj).ToString(CultureInfo.InvariantCulture); | ||
case TypeCode.Int64: | ||
|
@@ -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(PrecisionFormat, CultureInfo.InvariantCulture); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also be |
||
} | ||
return (string)obj; | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,7 +329,6 @@ private void RefreshCondensedDisplay(Action refreshDisplay) | |
{ | ||
var mirrorData = nodeViewModel.NodeModel.CachedValue; | ||
newContent = CompactBubbleHandler.Process(mirrorData); | ||
newContent.NodeLabel = checkNumberFormat(newContent.NodeLabel); | ||
}, | ||
(m) => | ||
{ | ||
|
@@ -382,10 +381,11 @@ private void RefreshExpandedDisplay(Action refreshDisplay) | |
nodeViewModel.NodeModel.OutPorts.Select(p => p.Name).Where(n => !string.IsNullOrEmpty(n)); | ||
} | ||
|
||
WatchViewModel.PrecisionFormat = nodeViewModel.DynamoViewModel.PreferenceSettings.NumberFormat; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes to this file can be reverted entirely. |
||
|
||
newViewModel = nodeViewModel.DynamoViewModel.WatchHandler.GenerateWatchViewModelForData( | ||
nodeViewModel.NodeModel.CachedValue, preferredDictionaryOrdering, | ||
null, nodeViewModel.NodeModel.AstIdentifierForPreview.Name, false); | ||
newViewModel.NodeLabel = checkNumberFormat(newViewModel.NodeLabel); | ||
null, nodeViewModel.NodeModel.AstIdentifierForPreview.Name, false); | ||
}, | ||
(m) => | ||
{ | ||
|
@@ -435,19 +435,7 @@ private void RefreshExpandedDisplay(Action refreshDisplay) | |
} | ||
); | ||
} | ||
|
||
private string checkNumberFormat(string numberValue) | ||
{ | ||
if (PreferencesPanelUtilities.IsValidDoubleNumber(numberValue)) | ||
{ | ||
return Convert.ToDouble(numberValue).ToString(nodeViewModel.DynamoViewModel.PreferenceSettings.NumberFormat); | ||
} | ||
else | ||
{ | ||
return numberValue; | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// It's used to apply Collapsed and Expanded events for TreeViewItems. | ||
/// </summary> | ||
|
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; | ||
|
@@ -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> | ||
|
@@ -230,10 +232,21 @@ 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. | ||
return (Data as IFormattable).ToString(null, CultureInfo.InvariantCulture); | ||
if (Data is double) | ||
{ | ||
return (Data as IFormattable).ToString(PrecisionFormat, CultureInfo.InvariantCulture); | ||
} | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would comment out this code for the time being and leave a TODO comment here saying "uncomment this once https://jira.autodesk.com/browse/DYN-5101 is complete". |
||
{ | ||
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(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to add this property.