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 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
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 used to define the interaction or hit area thickness for connectors in the workspace.
/// </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 @@ -36,6 +36,7 @@ abstract Dynamo.Search.SearchElements.SearchElementBase.Type.get -> string
abstract Dynamo.Search.SearchElements.SearchElementBase.Weight.get -> double
abstract Dynamo.Search.SearchElements.SearchElementBase.Weight.set -> void
const Dynamo.Configuration.Configurations.NotificationsDefaultTimeOut = 10000 -> int
const Dynamo.Configuration.Configurations.ConnectorZoomScalingFactor = 2 -> double
const Dynamo.Configuration.Context.NONE = "None" -> string
const Dynamo.Configuration.Context.REVIT_2014 = "Revit 2014" -> string
const Dynamo.Configuration.Context.REVIT_2015 = "Revit 2015" -> string
Expand Down Expand Up @@ -3001,6 +3002,7 @@ static readonly Dynamo.Configuration.Configurations.AutodeskAsString -> string
static readonly Dynamo.Configuration.Configurations.BackupFolderName -> string
static readonly Dynamo.Configuration.Configurations.CBNMaxPortNameLength -> int
static readonly Dynamo.Configuration.Configurations.CodeBlockOutputPortHeightInPixels -> double
static readonly Dynamo.Configuration.Configurations.ConnectorBaseThickness -> double
static readonly Dynamo.Configuration.Configurations.DoubleSliderTextBoxWidth -> double
static readonly Dynamo.Configuration.Configurations.DynamoAsString -> string
static readonly Dynamo.Configuration.Configurations.DynamoNodeHelpDocs -> string
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,8 @@ Dynamo.ViewModels.ConnectorViewModel.DotLeft.get -> double
Dynamo.ViewModels.ConnectorViewModel.DotLeft.set -> void
Dynamo.ViewModels.ConnectorViewModel.DotTop.get -> double
Dynamo.ViewModels.ConnectorViewModel.DotTop.set -> void
Dynamo.ViewModels.ConnectorViewModel.DynamicStrokeThickness.get -> double
Dynamo.ViewModels.ConnectorViewModel.DynamicStrokeThickness.set -> void
Dynamo.ViewModels.ConnectorViewModel.EndDotSize.get -> double
Dynamo.ViewModels.ConnectorViewModel.EndDotSize.set -> void
Dynamo.ViewModels.ConnectorViewModel.GoToEndNodeCommand.get -> Dynamo.UI.Commands.DelegateCommand
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