Skip to content
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

Cherry Pick: Render precision save (#9108) #9562

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>