From 2e803c721797a80147ec64f57875948d213babac Mon Sep 17 00:00:00 2001 From: filipeotero <89042471+filipeotero@users.noreply.github.com> Date: Fri, 10 Jun 2022 17:44:09 -0300 Subject: [PATCH 1/7] Clear inports and outports.; report nodes position; --- .../ViewModels/Core/AnnotationViewModel.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs index 6da22dcc704..c657f23fbb3 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs @@ -245,6 +245,8 @@ public bool IsExpanded set { annotationModel.IsExpanded = value; + InPorts.Clear(); + OutPorts.Clear(); if (value) { this.ShowGroupContents(); @@ -259,6 +261,15 @@ public bool IsExpanded WorkspaceViewModel.HasUnsavedChanges = true; AddGroupToGroupCommand.RaiseCanExecuteChanged(); RaisePropertyChanged(nameof(IsExpanded)); + ReportNodesPosition(); + } + } + + private void ReportNodesPosition() + { + foreach (var node in Nodes) + { + node.ReportPosition(); } } @@ -587,7 +598,6 @@ public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationMode /// internal void SetGroupInputPorts() { - InPorts.Clear(); List newPortViewModels; // we need to store the original ports here @@ -624,7 +634,6 @@ internal void SetGroupInputPorts() /// internal void SetGroupOutPorts() { - OutPorts.Clear(); List newPortViewModels; // we need to store the original ports here From 90af9e062b72e5b87992fb42b53a622af6194cf4 Mon Sep 17 00:00:00 2001 From: filipeotero <89042471+filipeotero@users.noreply.github.com> Date: Tue, 14 Jun 2022 10:52:59 -0300 Subject: [PATCH 2/7] Repositioning the collapsed groups of the wires based on the height of the ports --- .../ViewModels/Core/AnnotationViewModel.cs | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs index 410973f521c..c4ca960186c 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs @@ -249,7 +249,7 @@ public bool IsExpanded OutPorts.Clear(); if (value) { - this.ShowGroupContents(); + this.ShowGroupContents(); } else { @@ -725,13 +725,10 @@ private double GetPortVerticalOffset(PortModel portModel, int proxyPortIndex) return verticalOffset + (proxyPortIndex * portHeight) + portVerticalMidPoint; } - private Point2D CalculatePortPosition(PortModel portModel, int proxyPortIndex) + private Point2D CalculatePortPosition(PortModel portModel, double verticalPosition) { double groupHeaderHeight = Height - ModelAreaRect.Height; - - double offset = GetPortVerticalOffset(portModel, proxyPortIndex); - double y = Top + groupHeaderHeight + offset; - + double y = Top + groupHeaderHeight + verticalPosition + verticalOffset + portVerticalMidPoint; switch (portModel.PortType) { case PortType.Input: @@ -740,7 +737,7 @@ private Point2D CalculatePortPosition(PortModel portModel, int proxyPortIndex) if (portModel.Owner is CodeBlockNodeModel) { // Special case because code block outputs are smaller than regular outputs. - return new Point2D(Left + Width, y + 6); + return new Point2D(Left + Width, y - 8); } return new Point2D(Left + Width, y); } @@ -755,15 +752,19 @@ private List CreateProxyInPorts(IEnumerable groupPortM .ToList(); var newPortViewModels = new List(); - for (int i = 0; i < groupPortModels.Count(); i++) + double verticalPosition = 0; + foreach (var group in groupPortModels) { - var model = groupPortModels.ElementAt(i); - newPortViewModels.Add(originalPortViewModels[i].CreateProxyPortViewModel(model)); - - // calculate new position for the proxy inports. - model.Center = CalculatePortPosition(model, i); + var originalPort = originalPortViewModels.FirstOrDefault(x => x.PortModel.GUID == group.GUID); + if (originalPort != null) + { + var portViewModel = originalPort.CreateProxyPortViewModel(group); + newPortViewModels.Add(portViewModel); + // calculate new position for the proxy outports + group.Center = CalculatePortPosition(group, verticalPosition); + verticalPosition += originalPort.Height; + } } - return newPortViewModels; } @@ -775,7 +776,7 @@ private List CreateProxyOutPorts(IEnumerable groupPort .ToList(); var newPortViewModels = new List(); - int index = 0; + double verticalPosition = 0; foreach (var group in groupPortModels) { var originalPort = originalPortViewModels.FirstOrDefault(x => x.PortModel.GUID == group.GUID); @@ -784,9 +785,9 @@ private List CreateProxyOutPorts(IEnumerable groupPort var portViewModel = originalPort.CreateProxyPortViewModel(group); newPortViewModels.Add(portViewModel); // calculate new position for the proxy outports - group.Center = CalculatePortPosition(group, index); + group.Center = CalculatePortPosition(group, verticalPosition); + verticalPosition += originalPort.Height; } - index++; } return newPortViewModels; @@ -799,23 +800,30 @@ internal void UpdateProxyPortsPosition() if (parent != null && !parent.IsExpanded) return; + double verticalPosition = 0; + for (int i = 0; i < inPorts.Count(); i++) { var model = inPorts[i]?.PortModel; if (model != null && model.IsProxyPort) { // calculate new position for the proxy inports. - model.Center = CalculatePortPosition(model, i); + model.Center = CalculatePortPosition(model, verticalPosition); + verticalPosition += model.Height; + } } + verticalPosition = 0; for (int i = 0; i < outPorts.Count(); i++) { var model = outPorts[i]?.PortModel; if (model != null && model.IsProxyPort) { // calculate new position for the proxy outports. - model.Center = CalculatePortPosition(model, i); + model.Center = CalculatePortPosition(model, verticalPosition); + verticalPosition += model.Height; + } } } From 57dc338cd483f35b01d3fc57ea1aabfedb7230ec Mon Sep 17 00:00:00 2001 From: filipeotero <89042471+filipeotero@users.noreply.github.com> Date: Tue, 14 Jun 2022 14:33:24 -0300 Subject: [PATCH 3/7] Update the proxy ports if the Height or Width of the annotation is changed --- src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs index c4ca960186c..b86cea3e9cc 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs @@ -915,7 +915,6 @@ private void RedrawConnectors() foreach (var connector in allNodes.SelectMany(x=>x.AllConnectors)) { - var connectorViewModel = WorkspaceViewModel .Connectors .Where(x => connector.GUID == x.ConnectorModel.GUID) @@ -1098,10 +1097,12 @@ private void model_PropertyChanged(object sender, System.ComponentModel.Property RaisePropertyChanged("Width"); RaisePropertyChanged(nameof(ModelAreaRect)); UpdateAllGroupedGroups(); + UpdateProxyPortsPosition(); break; case "Height": RaisePropertyChanged("Height"); UpdateAllGroupedGroups(); + UpdateProxyPortsPosition(); break; case nameof(AnnotationDescriptionText): RaisePropertyChanged(nameof(AnnotationDescriptionText)); From 334302162ac0f0bdbc181a1d4dbca95bc949786a Mon Sep 17 00:00:00 2001 From: filipeotero <89042471+filipeotero@users.noreply.github.com> Date: Wed, 15 Jun 2022 17:58:38 -0300 Subject: [PATCH 4/7] Remove from update proxy port on width and height property changed --- .../ViewModels/Core/AnnotationViewModel.cs | 36 ++++++++++++------- .../Views/Core/AnnotationView.xaml.cs | 2 ++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs index b86cea3e9cc..d76e44d4918 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs @@ -268,7 +268,7 @@ public bool IsExpanded private void ReportNodesPosition() { - foreach (var node in Nodes) + foreach (var node in Nodes.OfType()) { node.ReportPosition(); } @@ -547,11 +547,15 @@ private bool CanChangeFontSize(object obj) public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationModel model) { annotationModel = model; + var modelBase = (ModelBase)model; + this.WorkspaceViewModel = workspaceViewModel; this.preferenceSettings = WorkspaceViewModel.DynamoViewModel.PreferenceSettings; model.PropertyChanged += model_PropertyChanged; model.RemovedFromGroup += OnModelRemovedFromGroup; model.AddedToGroup += OnModelAddedToGroup; + modelBase.PropertyChanged += ModelBase_PropertyChanged; + DynamoSelection.Instance.Selection.CollectionChanged += SelectionOnCollectionChanged; //https://jira.autodesk.com/browse/QNTM-3770 @@ -592,11 +596,21 @@ public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationMode LoadGroupStylesFromPreferences(preferenceSettings.GroupStyleItemsList); } + private void ModelBase_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(annotationModel.Position): + UpdateProxyPortsPosition(); + break; + } + } + /// - /// Creates input ports for the group based on its Nodes. - /// Input ports that either is connected to a Node outside of the - /// group, or has a port that is not connected will be used for the group. - /// + /// Creates input ports for the group based on its Nodes. + /// Input ports that either is connected to a Node outside of the + /// group, or has a port that is not connected will be used for the group. + /// internal void SetGroupInputPorts() { List newPortViewModels; @@ -753,15 +767,15 @@ private List CreateProxyInPorts(IEnumerable groupPortM var newPortViewModels = new List(); double verticalPosition = 0; - foreach (var group in groupPortModels) + foreach (var groupPort in groupPortModels) { - var originalPort = originalPortViewModels.FirstOrDefault(x => x.PortModel.GUID == group.GUID); + var originalPort = originalPortViewModels.FirstOrDefault(x => x.PortModel.GUID == groupPort.GUID); if (originalPort != null) { - var portViewModel = originalPort.CreateProxyPortViewModel(group); + var portViewModel = originalPort.CreateProxyPortViewModel(groupPort); newPortViewModels.Add(portViewModel); // calculate new position for the proxy outports - group.Center = CalculatePortPosition(group, verticalPosition); + groupPort.Center = CalculatePortPosition(groupPort, verticalPosition); verticalPosition += originalPort.Height; } } @@ -810,7 +824,6 @@ internal void UpdateProxyPortsPosition() // calculate new position for the proxy inports. model.Center = CalculatePortPosition(model, verticalPosition); verticalPosition += model.Height; - } } @@ -823,7 +836,6 @@ internal void UpdateProxyPortsPosition() // calculate new position for the proxy outports. model.Center = CalculatePortPosition(model, verticalPosition); verticalPosition += model.Height; - } } } @@ -1097,12 +1109,10 @@ private void model_PropertyChanged(object sender, System.ComponentModel.Property RaisePropertyChanged("Width"); RaisePropertyChanged(nameof(ModelAreaRect)); UpdateAllGroupedGroups(); - UpdateProxyPortsPosition(); break; case "Height": RaisePropertyChanged("Height"); UpdateAllGroupedGroups(); - UpdateProxyPortsPosition(); break; case nameof(AnnotationDescriptionText): RaisePropertyChanged(nameof(AnnotationDescriptionText)); diff --git a/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs b/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs index d75cd72c3cc..e11e93d31fb 100644 --- a/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs @@ -254,6 +254,8 @@ private void GroupTextBlock_SizeChanged(object sender, SizeChangedEventArgs e) SetTextMaxWidth(); SetTextHeight(); } + + ViewModel.UpdateProxyPortsPosition(); } From d70576dd75ae5243d93de58bd1e0f3f13a208071 Mon Sep 17 00:00:00 2001 From: filipeotero <89042471+filipeotero@users.noreply.github.com> Date: Fri, 17 Jun 2022 09:04:30 -0300 Subject: [PATCH 5/7] retrigger checks From 9cc120cfe3ca6682e4be1178c7d97cc99fd09270 Mon Sep 17 00:00:00 2001 From: filipeotero <89042471+filipeotero@users.noreply.github.com> Date: Thu, 23 Jun 2022 11:16:14 -0300 Subject: [PATCH 6/7] Removing modelBase property changed --- .../ViewModels/Core/AnnotationViewModel.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs index d76e44d4918..41c4cb0dcac 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs @@ -547,14 +547,12 @@ private bool CanChangeFontSize(object obj) public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationModel model) { annotationModel = model; - var modelBase = (ModelBase)model; this.WorkspaceViewModel = workspaceViewModel; this.preferenceSettings = WorkspaceViewModel.DynamoViewModel.PreferenceSettings; model.PropertyChanged += model_PropertyChanged; model.RemovedFromGroup += OnModelRemovedFromGroup; model.AddedToGroup += OnModelAddedToGroup; - modelBase.PropertyChanged += ModelBase_PropertyChanged; DynamoSelection.Instance.Selection.CollectionChanged += SelectionOnCollectionChanged; @@ -596,15 +594,6 @@ public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationMode LoadGroupStylesFromPreferences(preferenceSettings.GroupStyleItemsList); } - private void ModelBase_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(annotationModel.Position): - UpdateProxyPortsPosition(); - break; - } - } /// /// Creates input ports for the group based on its Nodes. From eedca247b3eb6c84612600fb464102edc9439f3a Mon Sep 17 00:00:00 2001 From: filipeotero <89042471+filipeotero@users.noreply.github.com> Date: Thu, 23 Jun 2022 15:24:52 -0300 Subject: [PATCH 7/7] assigning comments --- .../ViewModels/Core/AnnotationViewModel.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs index 41c4cb0dcac..f856c2a4875 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs @@ -594,13 +594,14 @@ public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationMode LoadGroupStylesFromPreferences(preferenceSettings.GroupStyleItemsList); } - + /// - /// Creates input ports for the group based on its Nodes. - /// Input ports that either is connected to a Node outside of the - /// group, or has a port that is not connected will be used for the group. - /// - internal void SetGroupInputPorts() + /// Creates input ports for the group based on its Nodes. + /// Input ports that either is connected to a Node outside of the + /// group, or has a port that is not connected will be used for the group. + /// This function appends to the inputs + /// + private void SetGroupInputPorts() { List newPortViewModels; @@ -635,8 +636,9 @@ internal void SetGroupInputPorts() /// /// Creates output ports for the group based on its Nodes. /// Output ports that are not connected will be used for the group. + /// This function appends to the outports /// - internal void SetGroupOutPorts() + private void SetGroupOutPorts() { List newPortViewModels;