Skip to content

Commit

Permalink
Render precision save (#9108) (#9562)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
scottmitchell authored Mar 11, 2019
1 parent 655b116 commit 9a77032
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/DynamoCore/Configuration/IPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ public interface IPreferences
void SetIsBackgroundPreviewActive(string name, bool value);
}

/// <summary>
/// Temporary interface to avoid breaking changes.
/// TODO: Merge with IPreferences for 3.0 (DYN-1699)
/// </summary>
public interface IRenderPrecisionPreference
{
///<summary>
///Indicate which render precision will be used
///</summary>
int RenderPrecision { get; set; }
}

/// <summary>
/// Represents data about active state of preview background
/// </summary>
Expand Down
14 changes: 12 additions & 2 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public class PreferenceSettings : NotificationObject, IPreferences
public class PreferenceSettings : NotificationObject, IPreferences, IRenderPrecisionPreference
{
private string numberFormat;
private string lastUpdateDownloadPath;
Expand All @@ -27,6 +27,11 @@ public class PreferenceSettings : NotificationObject, IPreferences
/// </summary>
internal const int DefaultMaxNumRecentFiles = 10;

/// <summary>
/// Indicates the default render precision, i.e. the maximum number of tessellation divisions
/// </summary>
internal const int DefaultRenderPrecision = 128;

/// <summary>
/// Temp PreferenceSetting Location for testing
/// </summary>
Expand Down Expand Up @@ -154,7 +159,11 @@ public bool IsBackgroundPreviewActive
}

/// <summary>
/// Indicates whether surface and solid edges will
/// Indicate which render precision will be used
/// </summary>
public int RenderPrecision { get; set; }

/// Indicates whether surface and solid edges will
/// be rendered.
/// </summary>
public bool ShowEdges { get; set; }
Expand Down Expand Up @@ -324,6 +333,7 @@ public PreferenceSettings()
UseHardwareAcceleration = true;
PackageDownloadTouAccepted = false;
maxNumRecentFiles = DefaultMaxNumRecentFiles;
RenderPrecision = DefaultRenderPrecision;
ShowEdges = false;
OpenFileInManualExecutionMode = false;
ShowDetailedLayout = true;
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<Reference Include="PresentationFramework" />
<Reference Include="ProtoGeometry, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Y:\Dynamo\extern\ProtoGeometry\ProtoGeometry.dll</HintPath>
<HintPath>..\..\extern\ProtoGeometry\ProtoGeometry.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
5 changes: 4 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,17 +601,20 @@ 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)
{
vm.RegenerateAllPackages();
}
break;
case "MaxTessellationDivisions":
model.PreferenceSettings.RenderPrecision = factoryVm.Factory.TessellationParameters.MaxTessellationDivisions;
break;
default:
return;
}
Expand Down
20 changes: 17 additions & 3 deletions src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dynamo.Interfaces;
using Dynamo.ViewModels;
using Dynamo.Visualization;
using Dynamo.Configuration;
using Dynamo.Wpf.Rendering;

namespace Dynamo.Wpf.ViewModels
Expand Down Expand Up @@ -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}
};
}

}
}
}
31 changes: 31 additions & 0 deletions test/DynamoCoreWpfTests/CoreUITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
76 changes: 76 additions & 0 deletions test/settings/DynamoSettings-WithoutRenderPrecision.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0"?>
-
<PreferenceSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<IsFirstRun>
true
</IsFirstRun>
<IsUsageReportingApproved>
false
</IsUsageReportingApproved>
<IsAnalyticsReportingApproved>
false
</IsAnalyticsReportingApproved>
<LibraryWidth>
304
</LibraryWidth>
<ConsoleHeight>
0
</ConsoleHeight>
<ShowPreviewBubbles>
true
</ShowPreviewBubbles>
<ShowConnector>
true
</ShowConnector>
<ConnectorType>
BEZIER
</ConnectorType>
<BackgroundPreviews />
<IsBackgroundGridVisible>
true
</IsBackgroundGridVisible>
<ShowEdges>
false
</ShowEdges>
<ShowDetailedLayout>
true
</ShowDetailedLayout>
<WindowX>
0
</WindowX>
<WindowY>
0
</WindowY>
<WindowW>
1024
</WindowW>
<WindowH>
768
</WindowH>
<UseHardwareAcceleration>
true
</UseHardwareAcceleration>
<NumberFormat>
f3
</NumberFormat>
<MaxNumRecentFiles>
10
</MaxNumRecentFiles>
<RecentFiles />
<BackupFiles />
<CustomPackageFolders />
<PackageDirectoriesToUninstall />
<PythonTemplateFilePath />
<BackupInterval>
60000
</BackupInterval>
<BackupFilesCount>
1
</BackupFilesCount>
<PackageDownloadTouAccepted>
false
</PackageDownloadTouAccepted>
<OpenFileInManualExecutionMode>
false
</OpenFileInManualExecutionMode>
</PreferenceSettings>

0 comments on commit 9a77032

Please sign in to comment.