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-5161 The "Show Connectors" feature should register newly placed nodes #13170

Merged
merged 8 commits into from
Sep 16, 2024
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
4 changes: 4 additions & 0 deletions src/DynamoCore/Graph/Connectors/ConnectorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Xml;
using Dynamo.Configuration;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Workspaces;
using Dynamo.Utilities;
Expand Down Expand Up @@ -159,6 +160,9 @@ private ConnectorModel(
GUID = guid;
Start = start.OutPorts[startIndex];
PortModel endPort = end.InPorts[endIndex];
// Reading visibility settings from preferences and setting the visibility of the connector
// so that setting changes within the session can be relfected instantly
IsHidden = !PreferenceSettings.Instance.ShowConnector;

Debug.WriteLine("Creating a connector between ports {0}(owner:{1}) and {2}(owner:{3}).",
start.GUID, Start.Owner == null ? "null" : Start.Owner.Name, end.GUID, endPort.Owner == null ? "null" : endPort.Owner.Name);
Expand Down
21 changes: 13 additions & 8 deletions src/DynamoCore/Models/RecordableCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Runtime.Serialization;
using System.Xml;
using System.Globalization;
using Dynamo.Configuration;

namespace Dynamo.Models
{
Expand Down Expand Up @@ -1563,15 +1564,16 @@ public enum Mode
BeginCreateConnections
}

void setProperties(int portIndex, PortType portType, Mode mode)
void SetProperties(int portIndex, PortType portType, Mode mode)
{
PortIndex = portIndex;
Type = portType;
ConnectionMode = mode;
IsHidden = !PreferenceSettings.Instance.ShowConnector;
}

/// <summary>
///
/// Recordable command ConnectionCommand constructor
/// </summary>
/// <param name="nodeId"></param>
/// <param name="portIndex"></param>
Expand All @@ -1581,11 +1583,11 @@ void setProperties(int portIndex, PortType portType, Mode mode)
public MakeConnectionCommand(string nodeId, int portIndex, PortType portType, Mode mode)
: base(new[] { Guid.Parse(nodeId) })
{
setProperties(portIndex, portType, mode);
SetProperties(portIndex, portType, mode);
}

/// <summary>
///
/// Recordable command ConnectionCommand constructor
/// </summary>
/// <param name="nodeId"></param>
/// <param name="portIndex"></param>
Expand All @@ -1594,11 +1596,11 @@ public MakeConnectionCommand(string nodeId, int portIndex, PortType portType, Mo
public MakeConnectionCommand(Guid nodeId, int portIndex, PortType portType, Mode mode)
: base(new[] { nodeId })
{
setProperties(portIndex, portType, mode);
SetProperties(portIndex, portType, mode);
}

/// <summary>
///
/// Recordable command ConnectionCommand constructor
/// </summary>
/// <param name="nodeId"></param>
/// <param name="portIndex"></param>
Expand All @@ -1607,7 +1609,7 @@ public MakeConnectionCommand(Guid nodeId, int portIndex, PortType portType, Mode
public MakeConnectionCommand(IEnumerable<Guid> nodeId, int portIndex, PortType portType, Mode mode)
: base(nodeId)
{
setProperties(portIndex, portType, mode);
SetProperties(portIndex, portType, mode);
}

internal static MakeConnectionCommand DeserializeCore(XmlElement element)
Expand All @@ -1616,7 +1618,6 @@ internal static MakeConnectionCommand DeserializeCore(XmlElement element)
int portIndex = helper.ReadInteger("PortIndex");
var portType = ((PortType)helper.ReadInteger("Type"));
var mode = ((Mode)helper.ReadInteger("ConnectionMode"));

var modelGuids = DeserializeGuid(element, helper);

return new MakeConnectionCommand(modelGuids, portIndex, portType, mode);
Expand All @@ -1635,6 +1636,9 @@ internal static MakeConnectionCommand DeserializeCore(XmlElement element)
[DataMember]
public Mode ConnectionMode { get; private set; }

[DataMember]
internal bool IsHidden { get; private set; }

#endregion

#region Protected Overridable Methods
Expand All @@ -1651,6 +1655,7 @@ protected override void SerializeCore(XmlElement element)
helper.SetAttribute("PortIndex", PortIndex);
helper.SetAttribute("Type", ((int)Type));
helper.SetAttribute("ConnectionMode", ((int)ConnectionMode));
helper.SetAttribute("IsHidden", IsHidden);
}

#endregion
Expand Down
40 changes: 22 additions & 18 deletions src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,22 +1450,18 @@ public void Redraw(object parameter)
{
var p2 = new Point();

if (parameter is Point)
if (parameter is Point point)
{
p2 = (Point)parameter;
p2 = point;
}
else if (parameter is Point2D)
else if (parameter is Point2D d)
{
p2 = ((Point2D)parameter).AsWindowsType();
p2 = d.AsWindowsType();
}

CurvePoint3 = p2;

var offset = 0.0;
double distance = 0;

distance = Math.Sqrt(Math.Pow(CurvePoint3.X - CurvePoint0.X, 2) + Math.Pow(CurvePoint3.Y - CurvePoint0.Y, 2));
offset = .45 * distance;
double distance = Math.Sqrt(Math.Pow(CurvePoint3.X - CurvePoint0.X, 2) + Math.Pow(CurvePoint3.Y - CurvePoint0.Y, 2));
double offset = .45 * distance;

CurvePoint1 = new Point(CurvePoint0.X + offset, CurvePoint0.Y);
CurvePoint2 = new Point(p2.X - offset, p2.Y);
Expand All @@ -1485,20 +1481,28 @@ public void Redraw(object parameter)
//RaisePropertyChanged(string.Empty);


PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = CurvePoint0;
PathFigure pathFigure = new PathFigure
{
StartPoint = CurvePoint0
};

BezierSegment segment = new BezierSegment(CurvePoint1, CurvePoint2, CurvePoint3, true);
var segmentCollection = new PathSegmentCollection(1);
segmentCollection.Add(segment);
var segmentCollection = new PathSegmentCollection(1)
{
segment
};
pathFigure.Segments = segmentCollection;
PathFigureCollection pathFigureCollection = new PathFigureCollection();
pathFigureCollection.Add(pathFigure);

ComputedBezierPathGeometry = new PathGeometry();
ComputedBezierPathGeometry.Figures = pathFigureCollection;
ComputedBezierPath = new Path();
ComputedBezierPath.Data = ComputedBezierPathGeometry;
ComputedBezierPathGeometry = new PathGeometry
{
Figures = pathFigureCollection
};
ComputedBezierPath = new Path
{
Data = ComputedBezierPathGeometry
};
}

private PathFigure DrawSegmentBetweenPointPairs(Point startPt, Point endPt, ref List<Point[]> controlPointList)
Expand Down
Loading