From 00c63600b070c055a9ad8a3ce53d8d8dcc6b4a28 Mon Sep 17 00:00:00 2001 From: DmytroMuravskyi Date: Mon, 11 Mar 2019 23:03:35 +0200 Subject: [PATCH] Render precision save (#9108) * ALS-5190 Dynamo: Render Precision setting is not remembered * Set correct path to ProtoGeometry lib * Return comment removed by accident * Add missing line * Add new interface * Copy Background Preview test * Creating RenderPrecision test * Updated RenderPrecision test * Removed inheritance I was testing * Added RenderPackageFactoryViewModel constructor * Updated constructor * Add TODO * Add test that loads settings file that does not contain RenderPrecision * Added const fro DefaultRenderPrecision * Added jira task --- src/DynamoCore/Configuration/IPreferences.cs | 12 +++ .../Configuration/PreferenceSettings.cs | 14 +++- src/DynamoCoreWpf/DynamoCoreWpf.csproj | 2 +- .../ViewModels/Core/DynamoViewModel.cs | 5 +- .../RenderPackageFactoryViewModel.cs | 20 ++++- test/DynamoCoreWpfTests/CoreUITests.cs | 31 ++++++++ .../DynamoSettings-WithoutRenderPrecision.xml | 76 +++++++++++++++++++ 7 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 test/settings/DynamoSettings-WithoutRenderPrecision.xml diff --git a/src/DynamoCore/Configuration/IPreferences.cs b/src/DynamoCore/Configuration/IPreferences.cs index 3e550144406..70ea88799d7 100644 --- a/src/DynamoCore/Configuration/IPreferences.cs +++ b/src/DynamoCore/Configuration/IPreferences.cs @@ -147,6 +147,18 @@ public interface IPreferences void SetIsBackgroundPreviewActive(string name, bool value); } + /// + /// Temporary interface to avoid breaking changes. + /// TODO: Merge with IPreferences for 3.0 (DYN-1699) + /// + public interface IRenderPrecisionPreference + { + /// + ///Indicate which render precision will be used + /// + int RenderPrecision { get; set; } + } + /// /// Represents data about active state of preview background /// diff --git a/src/DynamoCore/Configuration/PreferenceSettings.cs b/src/DynamoCore/Configuration/PreferenceSettings.cs index 47353def06e..b70c2bf5abe 100644 --- a/src/DynamoCore/Configuration/PreferenceSettings.cs +++ b/src/DynamoCore/Configuration/PreferenceSettings.cs @@ -15,7 +15,7 @@ namespace Dynamo.Configuration /// from a XML file from DYNAMO_SETTINGS_FILE. /// When GUI is closed, the settings are saved back into the XML file. /// - public class PreferenceSettings : NotificationObject, IPreferences + public class PreferenceSettings : NotificationObject, IPreferences, IRenderPrecisionPreference { private string numberFormat; private string lastUpdateDownloadPath; @@ -27,6 +27,11 @@ public class PreferenceSettings : NotificationObject, IPreferences /// internal const int DefaultMaxNumRecentFiles = 10; + /// + /// Indicates the default render precision, i.e. the maximum number of tessellation divisions + /// + internal const int DefaultRenderPrecision = 128; + /// /// Temp PreferenceSetting Location for testing /// @@ -154,7 +159,11 @@ public bool IsBackgroundPreviewActive } /// - /// Indicates whether surface and solid edges will + /// Indicate which render precision will be used + /// + public int RenderPrecision { get; set; } + + /// Indicates whether surface and solid edges will /// be rendered. /// public bool ShowEdges { get; set; } @@ -324,6 +333,7 @@ public PreferenceSettings() UseHardwareAcceleration = true; PackageDownloadTouAccepted = false; maxNumRecentFiles = DefaultMaxNumRecentFiles; + RenderPrecision = DefaultRenderPrecision; ShowEdges = false; OpenFileInManualExecutionMode = false; ShowDetailedLayout = true; diff --git a/src/DynamoCoreWpf/DynamoCoreWpf.csproj b/src/DynamoCoreWpf/DynamoCoreWpf.csproj index 8e160f82c5d..9c4e9e7fa22 100644 --- a/src/DynamoCoreWpf/DynamoCoreWpf.csproj +++ b/src/DynamoCoreWpf/DynamoCoreWpf.csproj @@ -80,7 +80,7 @@ False - Y:\Dynamo\extern\ProtoGeometry\ProtoGeometry.dll + ..\..\extern\ProtoGeometry\ProtoGeometry.dll False diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index 279cdf10370..3ba09d0cb59 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -601,10 +601,10 @@ protected void RegisterWatch3DViewModel(DefaultWatch3DViewModel watch3DViewModel private void RenderPackageFactoryViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { + var factoryVm = (RenderPackageFactoryViewModel)sender; switch (e.PropertyName) { case "ShowEdges": - var factoryVm = (RenderPackageFactoryViewModel)sender; model.PreferenceSettings.ShowEdges = factoryVm.Factory.TessellationParameters.ShowEdges; // A full regeneration is required to get the edge geometry. foreach (var vm in Watch3DViewModels) @@ -612,6 +612,9 @@ private void RenderPackageFactoryViewModel_PropertyChanged(object sender, Proper vm.RegenerateAllPackages(); } break; + case "MaxTessellationDivisions": + model.PreferenceSettings.RenderPrecision = factoryVm.Factory.TessellationParameters.MaxTessellationDivisions; + break; default: return; } diff --git a/src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs b/src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs index 317a10e22e4..2cb3070ac8f 100644 --- a/src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs @@ -1,6 +1,7 @@ using Dynamo.Interfaces; using Dynamo.ViewModels; using Dynamo.Visualization; +using Dynamo.Configuration; using Dynamo.Wpf.Rendering; namespace Dynamo.Wpf.ViewModels @@ -42,12 +43,25 @@ public int MaxTessellationDivisions } } + // TODO: Simplify this constructor once IPreferences and IRenderPrecisionPreference have been consolidated in 3.0 (DYN-1699) public RenderPackageFactoryViewModel(IPreferences preferenceSettings) { - this.factory = new HelixRenderPackageFactory() + var ps = preferenceSettings as PreferenceSettings; + if (ps != null) { - TessellationParameters = { ShowEdges = preferenceSettings.ShowEdges } - }; + this.factory = new HelixRenderPackageFactory() + { + TessellationParameters = { ShowEdges = ps.ShowEdges, MaxTessellationDivisions = ps.RenderPrecision } + }; + } + else + { + this.factory = new HelixRenderPackageFactory() + { + TessellationParameters = { ShowEdges = preferenceSettings.ShowEdges} + }; + } + } } } diff --git a/test/DynamoCoreWpfTests/CoreUITests.cs b/test/DynamoCoreWpfTests/CoreUITests.cs index dd19f30ad3f..28d2b5fbf88 100644 --- a/test/DynamoCoreWpfTests/CoreUITests.cs +++ b/test/DynamoCoreWpfTests/CoreUITests.cs @@ -468,6 +468,37 @@ public void PreferenceSetting_BackgroundPreview_1_0API() #endregion } + [Test, RequiresSTA] + [Category("DynamoUI")] + public void PreferenceSetting_RenderPrecision() + { + // Test that RenderPrecision setting works as expected + ViewModel.RenderPackageFactoryViewModel.MaxTessellationDivisions = 256; + Assert.AreEqual(256, ViewModel.Model.PreferenceSettings.RenderPrecision); + + ViewModel.RenderPackageFactoryViewModel.MaxTessellationDivisions = 128; + Assert.AreEqual(128, ViewModel.Model.PreferenceSettings.RenderPrecision); + + // Test serialization of RenderPrecision + string tempPath = System.IO.Path.GetTempPath(); + tempPath = Path.Combine(tempPath, "userPreference.xml"); + + PreferenceSettings initalSetting = new PreferenceSettings(); + PreferenceSettings resultSetting; + + initalSetting.RenderPrecision = 256; + + initalSetting.Save(tempPath); + resultSetting = PreferenceSettings.Load(tempPath); + + Assert.AreEqual(resultSetting.RenderPrecision, initalSetting.RenderPrecision); + + // Test loading old settings file without render precision attribute + var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-WithoutRenderPrecision.xml"); + PreferenceSettings WithoutRenderPrecision = PreferenceSettings.Load(filePath); + Assert.AreEqual(WithoutRenderPrecision.RenderPrecision, 128); + } + #region PreferenceSettings [Test, RequiresSTA] [Category("DynamoUI")] diff --git a/test/settings/DynamoSettings-WithoutRenderPrecision.xml b/test/settings/DynamoSettings-WithoutRenderPrecision.xml new file mode 100644 index 00000000000..28b9fe7d6d0 --- /dev/null +++ b/test/settings/DynamoSettings-WithoutRenderPrecision.xml @@ -0,0 +1,76 @@ + +- + + + true + + + false + + + false + + + 304 + + + 0 + + + true + + + true + + + BEZIER + + + + true + + + false + + + true + + + 0 + + + 0 + + + 1024 + + + 768 + + + true + + + f3 + + + 10 + + + + + + + + 60000 + + + 1 + + + false + + + false + +