Skip to content
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
30 changes: 29 additions & 1 deletion src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,16 @@ public IEnumerable<ModelBase> Nodes
get { return nodes; }
set
{
nodes = value.ToHashSet<ModelBase>();
// First remove all pins from the input
var valuesWithoutPins = value
.Where(x => !(x is ConnectorPinModel));

// then recalculate which pins belongs to the
// group and add them to the nodes collection
var pinModels = GetPinsFromNodes(value.OfType<NodeModel>());
nodes = valuesWithoutPins.Concat(pinModels)
.ToHashSet<ModelBase>();

if (nodes != null && nodes.Any())
{
foreach (var model in nodes)
Expand Down Expand Up @@ -353,6 +362,7 @@ public AnnotationModel(IEnumerable<NodeModel> nodes, IEnumerable<NoteModel> note
var nodeModels = nodes as NodeModel[] ?? nodes.ToArray();
var noteModels = notes as NoteModel[] ?? notes.ToArray();
var groupModels = groups as AnnotationModel[] ?? groups.ToArray();

DeletedModelBases = new List<ModelBase>();
this.Nodes = nodeModels
.Concat(noteModels.Cast<ModelBase>())
Expand All @@ -362,6 +372,24 @@ public AnnotationModel(IEnumerable<NodeModel> nodes, IEnumerable<NoteModel> note
UpdateBoundaryFromSelection();
}

private ConnectorPinModel[] GetPinsFromNodes(IEnumerable<NodeModel> nodeModels)
{
if (nodeModels is null ||
!nodeModels.Any())
{
return new List<ConnectorPinModel>().ToArray();
}

var connectorPinsToAdd = nodeModels
.SelectMany(x => x.AllConnectors)
.Where(x => nodeModels.Contains(x.Start.Owner) && nodeModels.Contains(x.End.Owner))
.SelectMany(x => x.ConnectorPinModels)
.Distinct()
.ToArray();

return connectorPinsToAdd;
}

private void model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
Expand Down
5 changes: 4 additions & 1 deletion src/DynamoCoreWpf/Views/Core/ConnectorPinView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Dynamo.Wpf.Views.Preview"
xmlns:props="clr-namespace:Dynamo.Wpf.Properties;assembly=DynamoCoreWpf"
xmlns:viewModels="clr-namespace:Dynamo.ViewModels"
mc:Ignorable="d"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ui="clr-namespace:Dynamo.UI"
MouseLeftButtonDown="OnPinMouseDown"
PreviewMouseLeftButtonDown="OnPreviewMouseLeftButtonDown"
MouseLeave="OnPinViewMouseLeave">
MouseLeave="OnPinViewMouseLeave"
Visibility="{Binding IsCollapsed, Converter={StaticResource InverseBoolToVisibilityCollapsedConverter}}"
d:DataContext="{d:DesignInstance Type=viewModels:ConnectorViewModel}">

<UserControl.Resources>
<ResourceDictionary>
Expand Down
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Views/Core/ConnectorPinView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public partial class ConnectorPinView : IViewModelView<ConnectorPinViewModel>

public ConnectorPinView()
{
// Add DynamoConverters - currently using the InverseBoolToVisibilityCollapsedConverter
// to be able to collapse pins
Resources.MergedDictionaries.Add(SharedDictionaryManager.DynamoConvertersDictionary);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SHKnudsen Can you remind me what is this for? I thought at some point we conclude this does not work? Or maybe I misunderstood

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this as a comment? Once that is done, this is good to go, thanks for doing it


InitializeComponent();
ViewModel = null;

Expand Down
22 changes: 22 additions & 0 deletions test/DynamoCoreWpfTests/AnnotationViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Dynamo.Graph;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.ZeroTouch;
using Dynamo.Models;
Expand Down Expand Up @@ -973,6 +974,27 @@ public void ChangingIsExpandedMarksGraphAsModified()
Assert.IsTrue(ViewModel.CurrentSpaceViewModel.HasUnsavedChanges);
}

[Test]
public void ConnectorPinsGetsAddedToTheGroup()
{
// Arrange
OpenModel(@"core\annotationViewModelTests\groupsTestFile.dyn");
var pinNode1Name = "PinNode1";
var pinNode2Name = "PinNode2";

var nodesToGroup = ViewModel.CurrentSpace.Nodes.Where(x => x.Name == pinNode1Name || x.Name == pinNode2Name);

// Act
DynamoSelection.Instance.ClearSelection();
DynamoSelection.Instance.Selection.AddRange(nodesToGroup);

Guid groupid = Guid.NewGuid();
var annotation = ViewModel.Model.CurrentWorkspace.AddAnnotation("This is a test group", "Group that contains connector pins", groupid);

// Assert
Assert.That(annotation.Nodes.OfType<ConnectorPinModel>().Any());
}

#endregion
}
}
141 changes: 137 additions & 4 deletions test/core/annotationViewModelTests/groupsTestFile.dyn
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,66 @@
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "a;",
"Id": "0fa88a0f76bf484c8f24d0c98f2001cb",
"Inputs": [
{
"Id": "a7e5d857c1c0497080e1089d78da7029",
"Name": "a",
"Description": "a",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "7872b35b1e01440bbf5b2bfa5092988d",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "b;",
"Id": "db79855ec8da41f59d5bd442d2c0bdc6",
"Inputs": [
{
"Id": "48d52e734c9049878d217514b5eaf12e",
"Name": "b",
"Description": "b",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "3e23b62e7ff34131bef9744a2817daf2",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
}
],
"Connectors": [
Expand Down Expand Up @@ -540,6 +600,12 @@
"End": "6704d22af2ff424ab10a009a6875b28b",
"Id": "4b7cb708a19148feaa7cc63be6711bf4",
"IsCollapsed": "False"
},
{
"Start": "7872b35b1e01440bbf5b2bfa5092988d",
"End": "48d52e734c9049878d217514b5eaf12e",
"Id": "17318da5dd194962a7b751344001f14b",
"IsCollapsed": "False"
}
],
"Dependencies": [],
Expand Down Expand Up @@ -583,7 +649,13 @@
"UpY": 1.0,
"UpZ": 0.0
},
"ConnectorPins": [],
"ConnectorPins": [
{
"Left": 368.21708173297861,
"Top": 2232.6963790506429,
"ConnectorGuid": "17318da5-dd19-4962-a7b7-51344001f14b"
}
],
"NodeViews": [
{
"Name": "Code Block",
Expand Down Expand Up @@ -744,6 +816,26 @@
"Excluded": false,
"X": 565.42700418512209,
"Y": 1742.6828879588616
},
{
"Name": "PinNode1",
"ShowGeometry": true,
"Id": "0fa88a0f76bf484c8f24d0c98f2001cb",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 141.0,
"Y": 2028.0
},
{
"Name": "PinNode2",
"ShowGeometry": true,
"Id": "db79855ec8da41f59d5bd442d2c0bdc6",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 483.49280771890994,
"Y": 2027.8375359168431
}
],
"Annotations": [
Expand Down Expand Up @@ -838,6 +930,28 @@
"TextblockHeight": 63.333333333333336,
"Background": "#FFC1D676"
},
{
"Id": "a87c3469dc5d4475849e85ccd5fbae78",
"Title": "CollapsedGroup",
"DescriptionText": "<Double click here to edit group description>",
"IsExpanded": false,
"WidthAdjustment": 0.0,
"HeightAdjustment": 0.0,
"Nodes": [
"b66aa988e2c14953ba8b161b0f748e1d",
"bb8e7e6e3daf42f19b24b34fd2b6429a"
],
"HasNestedGroups": false,
"Left": 185.06467884730887,
"Top": 1672.634327243012,
"Width": 465.02899200447985,
"Height": 150.0,
"FontSize": 36.0,
"InitialTop": 1735.9676605763452,
"InitialHeight": 151.71522738251633,
"TextblockHeight": 53.333333333333336,
"Background": "#FFC1D676"
},
{
"Id": "7fbc02d54b664e38b37a639e6c9d9663",
"Title": "GroupWithGroupedGroup",
Expand Down Expand Up @@ -882,10 +996,29 @@
"InitialHeight": 173.04856071584959,
"TextblockHeight": 53.333333333333336,
"Background": "#FFC1D676"
},
{
"Id": "84f2246557994f83b6263c3f5790d7cc",
"Title": "PinnedNodes to be grouped in test",
"DescriptionText": null,
"IsExpanded": true,
"WidthAdjustment": 0.0,
"HeightAdjustment": 0.0,
"Nodes": [],
"HasNestedGroups": false,
"Left": 150.44194031057322,
"Top": 1967.3947826699173,
"Width": 0.0,
"Height": 0.0,
"FontSize": 36.0,
"InitialTop": 0.0,
"InitialHeight": 0.0,
"TextblockHeight": 0.0,
"Background": "#FFC1D676"
}
],
"X": 231.11707316395939,
"Y": -739.73367060986516,
"Zoom": 0.69594667359159645
"X": 284.7662528512343,
"Y": -2058.3224230670721,
"Zoom": 1.1994243414922043
}
}