Skip to content

Commit

Permalink
DYN-4964-WorkingRange-Popup (#13656)
Browse files Browse the repository at this point in the history
* DYN-4964-WorkingRange-Popup

I've added a new button in the Workspace that when is clicked will show a popup containing the working ranges and the one currently selected.
This new button will show a different image when the mouse is hover and when is clicked, also I've added a tooltip.
For implementing this functionality I've added a new Popup (GeometryScalingPopup.xaml) and it's corresponding ViewModel. Finally I've added a converter that will receive as a parameter the current Working Range and will return a Brush with a specific color so the checkmark will be visible or not.

* DYN-4964-WorkingRange-Popup CodeReview1

Added functionality for the new DefaultGeometryScaling property that will be serialized in the DynamoSettings.xml.
Also I've disconnected the functionality of selecting the Geometry Scale for the current Workspace in the Preferences panel, now will be selected from the Dynamo workspace and will be serialized in the dyn file (as currently is happening).

* DYN-4964-WorkingRange-Popup CodeReview1

Updated the string shown in Preferences panel (Geometry Scaling section) and the tooltip showed when the mouse is over the new Workspace button.

* Build Fix

When merging master to my branch there were some changed that I didn't noticed in the PR so I'm reverting back those changes.

* DYN-4964-WorkingRange-Popup CodeReview 2

Fixed several comments also several methods were removed (like RadioGeometryScaling_Checked method) or moved
The property GeoScalingViewModel was moved from DynamoViewModel to WorkspaceViewModel..
The property CurrentGeometryScaling was deleted due that was duplicating a functionality.

* DYN-4964-WorkingRange-Popup CodeReview 2

When changing the Workspace Geometry Scaling it was not running the graph so I did some changes so it will be running the graph every time is updated.

* DYN-4964-WorkingRange-Popup CodeReview 2

Add functionality for when a custom node is created the Workspace Scale Factor is set.
Updating and removing some comments and also I started to add the unit test.

* DYN-4964-WorkingRange-Popup CodeReview2

Updating Unit Test

* DYN-4964-WorkingRange-Popup Fixing Tests

I did the next fixes:
The test TestImportCopySettings() was failing due that was reading the DynamoSettings-NewSettings.xml and comparing against the properties in PreferencesSetting so the DefaultScaleFactor was missing in the DynamoSettings-NewSettings.xml file.

The test PreferencesGeoScaling_RunGraph_Automatic due that was opening the Preferences panel and changing the Geometry Scaling value for the workspace but now that this value was moved to the Workspace in a Popup then the code needed some changes so we can change the Geometry Scaling value using the Popup.
  • Loading branch information
RobertGlobant20 authored Jan 27, 2023
1 parent 7262a78 commit 58c4470
Show file tree
Hide file tree
Showing 22 changed files with 568 additions and 142 deletions.
7 changes: 6 additions & 1 deletion src/DynamoCore/Configuration/IPreferences.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Dynamo.Graph.Connectors;

Expand Down Expand Up @@ -40,6 +40,11 @@ public interface IPreferences
/// </summary>
bool IsBackgroundGridVisible { get; set; }

/// <summary>
/// Indicates the Default Geometry Scaling value from the Preferences panel
/// </summary>
double DefaultScaleFactor { get; set; }

/// <summary>
/// Indicates whether background preview is active or not.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class PreferenceSettings : NotificationObject, IPreferences, IRenderPreci
private string lastUpdateDownloadPath;
private int maxNumRecentFiles;
private bool isBackgroundGridVisible;
private double defaultScaleFactor;
private bool disableTrustWarnings = false;
private bool isNotificationCenterEnabled;
private bool isStaticSplashScreenEnabled;
Expand Down Expand Up @@ -230,6 +231,24 @@ public bool IsBackgroundGridVisible
}
}

/// <summary>
/// Default geometry scale factor for a new workspace
/// </summary>
public double DefaultScaleFactor
{
get
{
return defaultScaleFactor;
}
set
{
if (value == defaultScaleFactor) return;
defaultScaleFactor = value;

RaisePropertyChanged(nameof(DefaultScaleFactor));
}
}


/// <summary>
/// Indicates whether background preview is active or not.
Expand Down
10 changes: 10 additions & 0 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<ItemGroup>
<None Remove="node_modules\%40dynamods\splash-screen\build\index.bundle.js" />
<None Remove="node_modules\%40dynamods\splash-screen\build\index.html" />
<None Remove="UI\Images\Canvas\canvas-button-geometry-scaling.png" />
<None Remove="Views\Core\GeometryScalingPopup.xaml" />
<None Remove="UI\Images\question-hover-blue-16px.png" />
<None Remove="Views\SplashScreen\WebApp\splashScreenBackground.png" />
</ItemGroup>
Expand Down Expand Up @@ -308,6 +310,7 @@
<Compile Include="ViewModels\Core\Converters\DynamoPythonScriptEditorTextOptions.cs" />
<Compile Include="ViewModels\Core\Converters\SerializationConverters.cs" />
<Compile Include="ViewModels\Core\DynamoViewModelBranding.cs" />
<Compile Include="ViewModels\Core\GeometryScalingViewModel.cs" />
<Compile Include="ViewModels\Core\HomeWorkspaceViewModel.cs" />
<Compile Include="ViewModels\Core\InPortViewModel.cs" />
<Compile Include="ViewModels\Core\OutPortViewModel.cs" />
Expand Down Expand Up @@ -358,6 +361,9 @@
<Compile Include="Views\Core\ConnectorPinView.xaml.cs">
<DependentUpon>ConnectorPinView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Core\GeometryScalingPopup.xaml.cs">
<DependentUpon>GeometryScalingPopup.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Debug\DebugModesWindow.xaml.cs">
<DependentUpon>DebugModesWindow.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -519,6 +525,9 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Core\GeometryScalingPopup.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\FileTrust\FileTrustWarning.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -684,6 +693,7 @@
<Resource Include="UI\Images\Alignment\align_x_distribute.png" />
<Resource Include="UI\Images\Alignment\align_y_average.png" />
<Resource Include="UI\Images\Alignment\align_y_distribute.png" />
<Resource Include="UI\Images\Canvas\canvas-button-geometry-scaling.png" />
<Resource Include="UI\Images\caret_up.png" />
<EmbeddedResource Include="Views\GuidedTour\HtmlPages\Resources\ArtifaktElement-Regular.woff" />
<Resource Include="UI\Images\cursors.psd" />
Expand Down
11 changes: 10 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ You can try disabling loading packages from built-in package paths, or unload th
Do you wish to uninstall {1}? Restart {2} to complete the uninstall and try downloading {0} again.</value>
</data>
<data name="PreferencesViewVisualSettingsGeoScaling" xml:space="preserve">
<value>Geometry Scaling</value>
<value>Default Geometry Scaling</value>
<comment>Expander Header Name</comment>
</data>
<data name="PreferencesViewVisualSettingsGroupStyles" xml:space="preserve">
Expand Down Expand Up @@ -3482,6 +3482,9 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="SplashScreenSigningIn" xml:space="preserve">
<value>Signing In</value>
</data>
<data name="InCanvasGeometryScalingToolTip" xml:space="preserve">
<value>Workspace Geometry Scaling</value>
</data>
<data name="GroupContextMenuPreview" xml:space="preserve">
<value>Preview Geometry</value>
</data>
Expand Down
5 changes: 4 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,7 @@ You can try disabling loading packages from built-in package paths, or unload th
Do you wish to uninstall {1}? Restart {2} to complete the uninstall and try downloading {0} again.</value>
</data>
<data name="PreferencesViewVisualSettingsGeoScaling" xml:space="preserve">
<value>Geometry Scaling</value>
<value>Default Geometry Scaling</value>
<comment>Expander Header Name</comment>
</data>
<data name="PreferencesViewVisualSettingsGroupStyles" xml:space="preserve">
Expand Down Expand Up @@ -3469,6 +3469,9 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="SplashScreenSigningIn" xml:space="preserve">
<value>Signing In</value>
</data>
<data name="InCanvasGeometryScalingToolTip" xml:space="preserve">
<value>Workspace Geometry Scaling</value>
</data>
<data name="GroupContextMenuPreview" xml:space="preserve">
<value>Preview Geometry</value>
</data>
Expand Down
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/UI/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3424,6 +3424,24 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}
}

/// <summary>
/// Receive a GeometryScaleSize value and if it matches the parameter passed will return a brush with a specific color
/// </summary>
public class ScaleSizeBackgroundConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value.Equals(parameter))
return new SolidColorBrush(Color.FromRgb(217, 217, 217));
return new SolidColorBrush(Color.FromRgb(71, 71, 71));

}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}

/// <summary>
/// This converter was designed for Expanders, so it will store/fetch the current Expander state
/// </summary>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 25 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using Dynamo.Wpf.ViewModels.FileTrust;
using Dynamo.Wpf.ViewModels.Watch3D;
using DynamoUtilities;
using ViewModels.Core;
using ISelectable = Dynamo.Selection.ISelectable;
using WpfResources = Dynamo.Wpf.Properties.Resources;

Expand Down Expand Up @@ -98,6 +99,8 @@ internal PreferencesViewModel PreferencesViewModel
}
}



/// <summary>
/// Guided Tour Manager
/// </summary>
Expand Down Expand Up @@ -743,6 +746,7 @@ protected DynamoViewModel(StartConfiguration startConfiguration)

preferencesViewModel = new PreferencesViewModel(this);


if (!DynamoModel.IsTestMode && !DynamoModel.IsHeadless)
{
model.State = DynamoModel.DynamoModelState.StartedUI;
Expand Down Expand Up @@ -2207,6 +2211,8 @@ private void ShowNewFunctionDialogAndMakeFunction(object parameter)
this.ExecuteCommand(new DynamoModel.CreateCustomNodeCommand(Guid.NewGuid(),
args.Name, args.Category, args.Description, true));
this.ShowStartPage = false;

SetDefaultScaleFactor();
}
}

Expand Down Expand Up @@ -2514,11 +2520,13 @@ internal bool CanSelectAll(object parameter)
public void MakeNewHomeWorkspace(object parameter)
{
if (ClearHomeWorkspaceInternal())
{
{
var t = new DelegateBasedAsyncTask(model.Scheduler, () => model.ResetEngine());
model.Scheduler.ScheduleForExecution(t);

ShowStartPage = false; // Hide start page if there's one.

SetDefaultScaleFactor();
}
}

Expand Down Expand Up @@ -2563,6 +2571,11 @@ internal bool ClearHomeWorkspaceInternal()

model.ClearCurrentWorkspace();

var defaultWorkspace = Workspaces.FirstOrDefault();
//Every time that a new workspace is created we have to assign the Default Geometry Scaling value defined in Preferences
if (defaultWorkspace !=null && defaultWorkspace.GeoScalingViewModel != null && preferencesViewModel != null)
defaultWorkspace.GeoScalingViewModel.ScaleSize = preferencesViewModel.DefaultGeometryScaling;

return true;
}

Expand Down Expand Up @@ -3163,6 +3176,17 @@ private bool CanSetNumberFormat(object parameter)
return true;
}

private void SetDefaultScaleFactor()
{
var defaultWorkspace = Workspaces.FirstOrDefault();

if (defaultWorkspace != null)
{
defaultWorkspace.GeoScalingViewModel.ScaleValue = PreferenceSettings.DefaultScaleFactor;
defaultWorkspace.GeoScalingViewModel.UpdateGeometryScale(PreferenceSettings.DefaultScaleFactor);
}
}

#region Shutdown related methods

/// <summary>
Expand Down
80 changes: 80 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/GeometryScalingViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using Dynamo.Core;
using Dynamo.ViewModels;

namespace ViewModels.Core
{
/// <summary>
/// This class will be contain information about the current Geometry Scale selected in the Dynamo Workspace
/// </summary>
public class GeometryScalingViewModel : NotificationObject
{
private DynamoViewModel dynViewModel;
private GeometryScaleSize scaleSize;
private double scaleValue = 0;
internal double ScaleValue
{
get
{
return scaleValue;
}
set
{
scaleValue = value;
UpdateGeometryScale(scaleValue);
}
}

internal GeometryScalingViewModel(DynamoViewModel dynViewModel)
{
this.dynViewModel = dynViewModel;
}

internal Tuple<string, string, string> ScaleRange
{
get
{
return scaleRanges[ScaleSize];
}
}


internal static Dictionary<GeometryScaleSize, Tuple<string, string, string>> scaleRanges = new Dictionary<GeometryScaleSize, Tuple<string, string, string>>
{
{GeometryScaleSize.Medium, new Tuple<string, string, string>("medium", "0.0001", "10,000")},
{GeometryScaleSize.Small, new Tuple<string, string, string>("small", "0.000,001", "100")},
{GeometryScaleSize.Large, new Tuple<string, string, string>("large", "0.01", "1,000,000")},
{GeometryScaleSize.ExtraLarge, new Tuple<string, string, string>("extra large", "1", "100,000,000")}
};

/// <summary>
/// Current Geometry Scale selected in dynamo workspace.
/// </summary>
public GeometryScaleSize ScaleSize
{
get
{
return scaleSize;
}
set
{
if(scaleSize != value)
{
scaleSize = value;
RaisePropertyChanged(nameof(ScaleSize));
}
}
}

internal void UpdateGeometryScale(double scaleFactor)
{
int UIScaleFactor = GeometryScalingOptions.ConvertScaleFactorToUI((int)scaleFactor);

if (Enum.IsDefined(typeof(GeometryScaleSize), UIScaleFactor))
{
ScaleSize = (GeometryScaleSize)UIScaleFactor;
}
}
}
}
14 changes: 13 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using DynamoUtilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ViewModels.Core;
using Function = Dynamo.Graph.Nodes.CustomNodes.Function;

namespace Dynamo.ViewModels
Expand Down Expand Up @@ -431,7 +432,15 @@ public bool CanRunNodeToCode
[JsonIgnore]
public RunSettingsViewModel RunSettingsViewModel { get; protected set; }



private GeometryScalingViewModel geoScalingViewModel;
internal GeometryScalingViewModel GeoScalingViewModel
{
get
{
return geoScalingViewModel;
}
}

#endregion

Expand Down Expand Up @@ -504,6 +513,9 @@ public WorkspaceViewModel(WorkspaceModel model, DynamoViewModel dynamoViewModel)
{
Visible = true
};

geoScalingViewModel = new GeometryScalingViewModel(this.DynamoViewModel);
geoScalingViewModel.ScaleValue = this.DynamoViewModel.ScaleFactorLog;
}
/// <summary>
/// This event is triggered from Workspace Model. Used in instrumentation
Expand Down
Loading

0 comments on commit 58c4470

Please sign in to comment.