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

[DYN-7839] Wires & Pins: improve snapping tolerance #15683

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions src/DynamoCore/Configuration/Configurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public class Configurations
/// </summary>
public static readonly double ZoomToFitPaddingFactor = 3.5;

/// <summary>
/// Const defining the base stroke thickness for connectors.
/// </summary>
public static readonly double ConnectorBaseThickness = 3;

/// <summary>
/// Const defining the scaling factor for adjusting connector stroke thickness based on zoom level.
/// </summary>
public const double ConnectorZoomScalingFactor = 2.0;

#endregion

#region Usage Reporting Error Message
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,8 @@ static readonly Dynamo.Configuration.Configurations.ZoomDirectEditThreshold -> d
static readonly Dynamo.Configuration.Configurations.ZoomIncrement -> double
static readonly Dynamo.Configuration.Configurations.ZoomThreshold -> double
static readonly Dynamo.Configuration.Configurations.ZoomToFitPaddingFactor -> double
static readonly Dynamo.Configuration.Configurations.ConnectorBaseThickness -> double
static readonly Dynamo.Configuration.Configurations.ConnectorZoomScalingFactor -> double
static readonly Dynamo.Configuration.PreferenceSettings.DynamoDefaultTime -> System.DateTime
virtual Dynamo.Core.CustomNodeManager.OnCustomNodeRemoved(System.Guid functionId) -> void
virtual Dynamo.Core.CustomNodeManager.OnDefinitionUpdated(Dynamo.CustomNodeDefinition obj) -> void
Expand Down
12 changes: 9 additions & 3 deletions src/DynamoCoreWpf/UI/Themes/Modern/Connectors.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
xmlns:i="clr-namespace:Dynamo.Microsoft.Xaml.Behaviors;assembly=Dynamo.Microsoft.Xaml.Behaviors"
xmlns:views="clr-namespace:Dynamo.Controls;assembly=DynamoCoreWpf"
xmlns:nodes="clr-namespace:Dynamo.Nodes;assembly=DynamoCoreWpf"
xmlns:mouse="clr-namespace:Dynamo.Wpf.UI;assembly=DynamoCoreWpf">
xmlns:mouse="clr-namespace:Dynamo.Wpf.UI;assembly=DynamoCoreWpf"
xmlns:configuration="clr-namespace:Dynamo.Configuration;assembly=DynamoCore">

<ResourceDictionary.MergedDictionaries>
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoConvertersDictionaryUri}" />
Expand Down Expand Up @@ -126,10 +127,15 @@
</Canvas>

<!--Bezier Path-->
<Path Stroke="{DynamicResource BConnectorSelection}" StrokeThickness="3"
<Path Stroke="{DynamicResource BConnectorSelection}" StrokeThickness="{Binding Source={x:Static configuration:Configurations.ConnectorBaseThickness}}"
Name="connector"
Visibility="{Binding IsCollapsed, Converter={StaticResource InverseBoolToVisibilityCollapsedConverter}, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource SConnector}" Canvas.ZIndex="-1"
Style="{StaticResource SConnector}" Canvas.ZIndex="-2"
Data="{Binding ComputedBezierPathGeometry, UpdateSourceTrigger=PropertyChanged}">
</Path>
<Path Stroke="Transparent" StrokeThickness="{Binding DynamicStrokeThickness}"
Visibility="{Binding IsCollapsed, Converter={StaticResource InverseBoolToVisibilityCollapsedConverter}, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource SConnector}" Canvas.ZIndex="-1"
Data="{Binding ComputedBezierPathGeometry, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Behaviors>
<mouse:MouseBehaviour MouseX="{Binding PanelX, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" MouseY="{Binding PanelY, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" />
Expand Down
36 changes: 36 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;
using Dynamo.Configuration;
using Dynamo.Graph;
using Dynamo.Graph.Connectors;
using Dynamo.Graph.Nodes;
Expand Down Expand Up @@ -48,6 +49,7 @@ public partial class ConnectorViewModel : ViewModelBase
private double dotLeft;
private double endDotSize = 6;
private double zIndex = 3;
private double dynamicStrokeThickness;

private Point curvePoint1;
private Point curvePoint2;
Expand Down Expand Up @@ -568,6 +570,16 @@ public PathGeometry ComputedBezierPathGeometry
}
}

public double DynamicStrokeThickness
{
get => dynamicStrokeThickness;
set
{
dynamicStrokeThickness = value;
RaisePropertyChanged(nameof(DynamicStrokeThickness));
}
}

#endregion

/// <summary>
Expand Down Expand Up @@ -959,13 +971,15 @@ public ConnectorViewModel(WorkspaceViewModel workspace, PortModel port)
this.workspaceViewModel = workspace;
ConnectorPinViewCollection = new ObservableCollection<ConnectorPinViewModel>();
ConnectorPinViewCollection.CollectionChanged += HandleCollectionChanged;
workspaceViewModel.PropertyChanged += WorkspaceViewModel_PropertyChanged;

IsHidden = !workspaceViewModel.DynamoViewModel.IsShowingConnectors;
IsConnecting = true;
MouseHoverOn = false;
activeStartPort = port;
ZIndex = SetZIndex();

UpdateDynamicStrokeThickness();
Redraw(port.Center);

InitializeCommands();
Expand Down Expand Up @@ -1001,6 +1015,7 @@ public ConnectorViewModel(WorkspaceViewModel workspace, ConnectorModel connector

ConnectorPinViewCollection = new ObservableCollection<ConnectorPinViewModel>();
ConnectorPinViewCollection.CollectionChanged += HandleCollectionChanged;
workspaceViewModel.PropertyChanged += WorkspaceViewModel_PropertyChanged;


if (connectorModel.ConnectorPinModels != null)
Expand Down Expand Up @@ -1028,6 +1043,7 @@ public ConnectorViewModel(WorkspaceViewModel workspace, ConnectorModel connector
NodeEnd.PropertyChanged += nodeEndViewModel_PropertyChanged;
}

UpdateDynamicStrokeThickness();
Redraw();
InitializeCommands();

Expand Down Expand Up @@ -1164,6 +1180,24 @@ private void HandleCollectionChanged(object sender, NotifyCollectionChangedEvent
Redraw();
}

private void WorkspaceViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(workspaceViewModel.Zoom))
{
UpdateDynamicStrokeThickness();
}
}

private void UpdateDynamicStrokeThickness()
{
DynamicStrokeThickness = Math.Max(
Configurations.ConnectorBaseThickness,
Configurations.ConnectorBaseThickness *
(1 / workspaceViewModel.Zoom) *
Configurations.ConnectorZoomScalingFactor
);
}

/// <summary>
/// Dispose function
/// </summary>
Expand All @@ -1190,6 +1224,8 @@ public override void Dispose()
}
ConnectorPinViewCollection.CollectionChanged -= HandleCollectionChanged;

workspaceViewModel.PropertyChanged -= WorkspaceViewModel_PropertyChanged;

foreach (var pin in ConnectorPinViewCollection.ToList())
{
pin.RequestRedraw -= HandlerRedrawRequest;
Expand Down
Loading