From 992958bcc03802babb5d670ce84c1527c1822532 Mon Sep 17 00:00:00 2001 From: DimitarVen Date: Thu, 9 Jan 2025 23:19:13 +0200 Subject: [PATCH 01/12] disable animations, simplify images --- src/DynamoCoreWpf/UI/Converters.cs | 21 ++ .../UI/Themes/Modern/DynamoModern.xaml | 191 +++++++++++++----- src/DynamoCoreWpf/UI/Themes/Modern/Ports.xaml | 7 +- .../ViewModels/Core/WorkspaceViewModel.cs | 10 + src/DynamoCoreWpf/Views/Core/NodeView.xaml | 71 ++++--- 5 files changed, 208 insertions(+), 92 deletions(-) diff --git a/src/DynamoCoreWpf/UI/Converters.cs b/src/DynamoCoreWpf/UI/Converters.cs index b7572b2385b..e04da82ba33 100644 --- a/src/DynamoCoreWpf/UI/Converters.cs +++ b/src/DynamoCoreWpf/UI/Converters.cs @@ -34,6 +34,27 @@ namespace Dynamo.Controls { + public class BooleanStyleConverter : IValueConverter + { + public Style TrueStyle { get; set; } + public Style FalseStyle { get; set; } + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value is bool v && v) + { + return TrueStyle; + } + + return FalseStyle; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return false; + } + } + public class ToolTipFirstLineOnly : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml index ceee129adf0..5413b98afe9 100644 --- a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml +++ b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml @@ -7,7 +7,8 @@ xmlns:fa="clr-namespace:FontAwesome5;assembly=FontAwesome5.Net" xmlns:nodes="clr-namespace:Dynamo.Nodes;assembly=DynamoCoreWpf" xmlns:p="clr-namespace:Dynamo.Wpf.Properties;assembly=DynamoCoreWpf" - xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf"> + xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf" + xmlns:conv="clr-namespace:Dynamo.Controls;assembly=DynamoCoreWpf"> @@ -867,9 +868,13 @@ - - - + + - + + + + - - - + + + + + - - + + - + + + + - + + + + @@ -448,7 +445,7 @@ HorizontalAlignment="Right" VerticalAlignment="Bottom" Canvas.ZIndex="4" - Style="{StaticResource SZoomFadeOutFrameworkElement}" + Style="{Binding Path=DataContext.StopAnimations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:WorkspaceView}}, Converter={StaticResource SZoomFadeControl}}" FlowDirection="LeftToRight" Orientation="Horizontal"> @@ -512,7 +513,7 @@ FontFamily="{StaticResource ArtifaktElementRegular}" FontSize="10px" Foreground="Black" - Style="{StaticResource SZoomFadeLabel}" /> + Style="{Binding Path=DataContext.StopAnimations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:WorkspaceView}}, Converter={StaticResource SZoomFadeControl}}" /> + - + - - - + + + + + + - - + - Date: Tue, 21 Jan 2025 14:40:28 -0500 Subject: [PATCH 04/12] small changes --- src/DynamoCoreWpf/UI/Converters.cs | 12 +++++----- .../UI/Themes/Modern/DynamoModern.xaml | 12 +++++----- .../ViewModels/Core/WorkspaceViewModel.cs | 22 ++++++++++++++++--- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/DynamoCoreWpf/UI/Converters.cs b/src/DynamoCoreWpf/UI/Converters.cs index e04da82ba33..8867b74ee53 100644 --- a/src/DynamoCoreWpf/UI/Converters.cs +++ b/src/DynamoCoreWpf/UI/Converters.cs @@ -34,12 +34,12 @@ namespace Dynamo.Controls { - public class BooleanStyleConverter : IValueConverter + public class BooleanToStyleConverter : IValueConverter { public Style TrueStyle { get; set; } public Style FalseStyle { get; set; } - public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + public object Convert(object value, Type targetType, object parameter,CultureInfo culture) { if (value is bool v && v) { @@ -49,9 +49,9 @@ public object Convert(object value, Type targetType, object parameter, System.Gl return FalseStyle; } - public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - return false; + throw new NotSupportedException(); } } @@ -66,7 +66,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - throw new NotImplementedException(); + throw new NotSupportedException(); } } @@ -81,7 +81,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - throw new NotImplementedException(); + throw new NotSupportedException(); } } diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml index 5413b98afe9..e2596de5084 100644 --- a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml +++ b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml @@ -914,12 +914,12 @@ - - + - @@ -1018,7 +1018,7 @@ - @@ -1070,7 +1070,7 @@ - @@ -1122,7 +1122,7 @@ - diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index 9e714417078..6889a254a71 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -480,8 +480,22 @@ public double Zoom } [JsonIgnore] - public bool StopAnimations { get => stopAnimations; set { stopAnimations = value; RaisePropertyChanged(nameof(StopAnimations)); } } - private bool stopAnimations = false; + public bool StopAnimations + { + get => stopAnimations; + set + { + if (stopAnimations != value) + { + stopAnimations = value; + RaisePropertyChanged(nameof(StopAnimations)); + } + } + } + private bool stopAnimations = false; + + + [JsonIgnore] public bool CanZoomIn @@ -890,7 +904,7 @@ private void unsubscribeNodeEvents(NodeViewModel nodeViewModel) nodeViewModel.NodeLogic.Modified -= OnNodeModified; } - private const int MaxNodesBeforeAnimationStops = 150; + private const int MaxNodesBeforeAnimationStops = 10; void Model_NodeRemoved(NodeModel node) { @@ -908,6 +922,8 @@ void Model_NodeRemoved(NodeModel node) PostNodeChangeActions(); + //TODO might also need to set this when switching current workspace if we make it static. + //profile and decide if it's worth it to get rid of the wpf ancestor look up. StopAnimations = Nodes.Count > MaxNodesBeforeAnimationStops; } From f86f1f27d82538d8e75443f90380efa5053aa561 Mon Sep 17 00:00:00 2001 From: "mjk.kirschner" <508936+mjkkirschner@users.noreply.github.com> Date: Mon, 27 Jan 2025 13:24:17 -0500 Subject: [PATCH 05/12] feature flag to control zoom animation behavior --- src/DynamoCoreWpf/UI/Converters.cs | 3 + .../ViewModels/Core/WorkspaceViewModel.cs | 59 +++++++++++++++---- src/DynamoUtilities/CLIWrapper.cs | 5 +- .../DynamoFeatureFlagsManager.cs | 6 +- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/DynamoCoreWpf/UI/Converters.cs b/src/DynamoCoreWpf/UI/Converters.cs index 8867b74ee53..79633d70a86 100644 --- a/src/DynamoCoreWpf/UI/Converters.cs +++ b/src/DynamoCoreWpf/UI/Converters.cs @@ -34,6 +34,9 @@ namespace Dynamo.Controls { + /// + /// selects from one of two styles based on a boolean value. + /// public class BooleanToStyleConverter : IValueConverter { public Style TrueStyle { get; set; } diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index 6889a254a71..1896679139c 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -479,20 +479,26 @@ public double Zoom } } + /// + /// When enabled, some child wpf framework elements will not animate opacity changes. + /// Useful for improving performance during zoom. + /// [JsonIgnore] - public bool StopAnimations + public bool StopNodeViewOpacityAnimations { - get => stopAnimations; + get => stopNodeViewOpacityAnimations; set { - if (stopAnimations != value) + if (stopNodeViewOpacityAnimations != value) { - stopAnimations = value; - RaisePropertyChanged(nameof(StopAnimations)); + stopNodeViewOpacityAnimations = value; + RaisePropertyChanged(nameof(StopNodeViewOpacityAnimations)); } } } - private bool stopAnimations = false; + private bool stopNodeViewOpacityAnimations = false; + + private int zoomAnimationThresholdFeatureFlagVal = 0; @@ -632,7 +638,38 @@ public WorkspaceViewModel(WorkspaceModel model, DynamoViewModel dynamoViewModel) geoScalingViewModel = new GeometryScalingViewModel(this.DynamoViewModel); geoScalingViewModel.ScaleValue = Convert.ToInt32(Math.Log10(Model.ScaleFactor)); + + DynamoFeatureFlagsManager.FlagsRetrieved += OnFlagsRetrieved; + //if we've already retrieved flags, grab the value, + SetStopNodeZoomAnimationBehavior((int)(DynamoModel.FeatureFlags?.CheckFeatureFlag("zoom_opacity_animation_nodenum_threshold", 0) ?? 0)); + } + + private void OnFlagsRetrieved() + { + zoomAnimationThresholdFeatureFlagVal = (int)(DynamoModel.FeatureFlags?.CheckFeatureFlag("zoom_opacity_animation_nodenum_threshold", 0) ?? 0); + SetStopNodeZoomAnimationBehavior(zoomAnimationThresholdFeatureFlagVal); + DynamoFeatureFlagsManager.FlagsRetrieved -= OnFlagsRetrieved; } + + private void SetStopNodeZoomAnimationBehavior(int featureFlagValue) + { + //threshold mode so we can tune the cutoff. + if (featureFlagValue>0) + { + StopNodeViewOpacityAnimations = Nodes.Count > zoomAnimationThresholdFeatureFlagVal; + } + //always enable animations (ie, disable the feature flag) + else if (featureFlagValue == 0) + { + StopNodeViewOpacityAnimations = false; + } + //always disable animations + else if (featureFlagValue<0) + { + StopNodeViewOpacityAnimations = true; + } + } + /// /// This event is triggered from Workspace Model. Used in instrumentation /// @@ -904,7 +941,6 @@ private void unsubscribeNodeEvents(NodeViewModel nodeViewModel) nodeViewModel.NodeLogic.Modified -= OnNodeModified; } - private const int MaxNodesBeforeAnimationStops = 10; void Model_NodeRemoved(NodeModel node) { @@ -922,9 +958,7 @@ void Model_NodeRemoved(NodeModel node) PostNodeChangeActions(); - //TODO might also need to set this when switching current workspace if we make it static. - //profile and decide if it's worth it to get rid of the wpf ancestor look up. - StopAnimations = Nodes.Count > MaxNodesBeforeAnimationStops; + SetStopNodeZoomAnimationBehavior(zoomAnimationThresholdFeatureFlagVal); } void Model_NodeAdded(NodeModel node) @@ -941,7 +975,7 @@ void Model_NodeAdded(NodeModel node) PostNodeChangeActions(); - StopAnimations = Nodes.Count > MaxNodesBeforeAnimationStops; + SetStopNodeZoomAnimationBehavior(zoomAnimationThresholdFeatureFlagVal); } void PostNodeChangeActions() @@ -1899,4 +1933,5 @@ public ViewModelEventArgs(NodeViewModel vm) ViewModel = vm; } } -} + + } diff --git a/src/DynamoUtilities/CLIWrapper.cs b/src/DynamoUtilities/CLIWrapper.cs index 0f0da2e7222..59e23f8fbda 100644 --- a/src/DynamoUtilities/CLIWrapper.cs +++ b/src/DynamoUtilities/CLIWrapper.cs @@ -67,7 +67,10 @@ private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) //do nothing, we just want to empty the error stream. } - + protected void OnLogMessage(string message) + { + MessageLogged?.Invoke(message); + } /// /// Kill the CLI tool - if running diff --git a/src/DynamoUtilities/DynamoFeatureFlagsManager.cs b/src/DynamoUtilities/DynamoFeatureFlagsManager.cs index 32be9566ca6..44536d6896c 100644 --- a/src/DynamoUtilities/DynamoFeatureFlagsManager.cs +++ b/src/DynamoUtilities/DynamoFeatureFlagsManager.cs @@ -75,6 +75,8 @@ internal void CacheAllFlags() FlagsRetrieved?.Invoke(); }, null); + var formattedFlags = JsonConvert.SerializeObject(AllFlagsCache, Formatting.Indented); + OnLogMessage($"retrieved feature flags with value: {formattedFlags}"); } catch (Exception e) @@ -88,11 +90,11 @@ internal void CacheAllFlags() /// /// Must be a bool or string, only bool or string flags should be created unless this implementation is improved. /// feature flag name - /// Currently the flag and default val MUST be a bool or string. + /// Currently the flag and default val MUST be a bool, or long(int64). /// internal T CheckFeatureFlag(string featureFlagKey, T defaultval) { - if(!(defaultval is bool || defaultval is string)){ + if(!(defaultval is bool || defaultval is string || defaultval is long)){ throw new ArgumentException("unsupported flag type", defaultval.GetType().ToString()); } // if we have not retrieved flags from the cli return empty From 1286f603e3f7c5c45f69935e8981472ae0bca99c Mon Sep 17 00:00:00 2001 From: "mjk.kirschner" <508936+mjkkirschner@users.noreply.github.com> Date: Mon, 27 Jan 2025 14:05:05 -0500 Subject: [PATCH 06/12] cleanup rename symbol does not work on xaml. --- .../UI/Themes/Modern/DynamoModern.xaml | 4 ++-- src/DynamoCoreWpf/UI/Themes/Modern/Ports.xaml | 4 ++-- .../ViewModels/Core/WorkspaceViewModel.cs | 5 +++-- src/DynamoCoreWpf/Views/Core/NodeView.xaml | 14 +++++++------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml index e2596de5084..7ec9d616ff0 100644 --- a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml +++ b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml @@ -1879,7 +1879,7 @@ FontSize="{TemplateBinding FontSize}" FontWeight="Bold" Foreground="{TemplateBinding Foreground}" - Style="{Binding Path=DataContext.StopAnimations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:WorkspaceView}}, Converter={StaticResource SZoomFadeControl}}" + Style="{Binding Path=DataContext.StopNodeViewOpacityAnimations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:WorkspaceView}}, Converter={StaticResource SZoomFadeControl}}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" /> @@ -1924,7 +1924,7 @@ FontSize="28px" FontWeight="Bold" Foreground="#999999" - Style="{Binding Path=DataContext.StopAnimations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:WorkspaceView}}, Converter={StaticResource SZoomFadeControl}}" + Style="{Binding Path=DataContext.StopNodeViewOpacityAnimations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:WorkspaceView}}, Converter={StaticResource SZoomFadeControl}}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" /> diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/Ports.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/Ports.xaml index 6399f3a2acc..495c2112267 100644 --- a/src/DynamoCoreWpf/UI/Themes/Modern/Ports.xaml +++ b/src/DynamoCoreWpf/UI/Themes/Modern/Ports.xaml @@ -126,7 +126,7 @@ FontWeight="Medium" Foreground="{StaticResource PrimaryCharcoal200Brush}" IsHitTestVisible="False" - Style="{Binding Path=DataContext.StopAnimations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controlsWpf:WorkspaceView}}, Converter={StaticResource SZoomFadeControl}}" /> + Style="{Binding Path=DataContext.StopNodeViewOpacityAnimations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controlsWpf:WorkspaceView}}, Converter={StaticResource SZoomFadeControl}}" /> - - - - -