Skip to content

Commit

Permalink
DYN-5018 wires disappear when moving group (#12997)
Browse files Browse the repository at this point in the history
* Clear inports and outports.; report nodes position;

* Repositioning the collapsed groups of the wires based on the height of the ports

* Update the proxy ports if the Height or Width of the annotation is changed

* Remove from update proxy port on width and height property changed

* retrigger checks

* Removing modelBase property changed

* assigning comments
  • Loading branch information
filipeotero authored Jun 25, 2022
1 parent a28fdc8 commit 0174e38
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
67 changes: 43 additions & 24 deletions src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ public bool IsExpanded
set
{
annotationModel.IsExpanded = value;
InPorts.Clear();
OutPorts.Clear();
if (value)
{
this.ShowGroupContents();
this.ShowGroupContents();
}
else
{
Expand All @@ -260,6 +262,15 @@ public bool IsExpanded
AddGroupToGroupCommand.RaiseCanExecuteChanged();
RaisePropertyChanged(nameof(IsExpanded));
RedrawConnectors();
ReportNodesPosition();
}
}

private void ReportNodesPosition()
{
foreach (var node in Nodes.OfType<AnnotationModel>())
{
node.ReportPosition();
}
}

Expand Down Expand Up @@ -536,11 +547,13 @@ private bool CanChangeFontSize(object obj)
public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationModel model)
{
annotationModel = model;

this.WorkspaceViewModel = workspaceViewModel;
this.preferenceSettings = WorkspaceViewModel.DynamoViewModel.PreferenceSettings;
model.PropertyChanged += model_PropertyChanged;
model.RemovedFromGroup += OnModelRemovedFromGroup;
model.AddedToGroup += OnModelAddedToGroup;

DynamoSelection.Instance.Selection.CollectionChanged += SelectionOnCollectionChanged;

//https://jira.autodesk.com/browse/QNTM-3770
Expand Down Expand Up @@ -581,14 +594,15 @@ public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationMode
LoadGroupStylesFromPreferences(preferenceSettings.GroupStyleItemsList);
}


/// <summary>
/// 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
/// </summary>
internal void SetGroupInputPorts()
private void SetGroupInputPorts()
{
InPorts.Clear();
List<PortViewModel> newPortViewModels;

// we need to store the original ports here
Expand Down Expand Up @@ -622,10 +636,10 @@ internal void SetGroupInputPorts()
/// <summary>
/// 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
/// </summary>
internal void SetGroupOutPorts()
private void SetGroupOutPorts()
{
OutPorts.Clear();
List<PortViewModel> newPortViewModels;

// we need to store the original ports here
Expand Down Expand Up @@ -716,13 +730,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:
Expand All @@ -731,7 +742,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);
}
Expand All @@ -746,15 +757,19 @@ private List<PortViewModel> CreateProxyInPorts(IEnumerable<PortModel> groupPortM
.ToList();

var newPortViewModels = new List<PortViewModel>();
for (int i = 0; i < groupPortModels.Count(); i++)
double verticalPosition = 0;
foreach (var groupPort 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 == groupPort.GUID);
if (originalPort != null)
{
var portViewModel = originalPort.CreateProxyPortViewModel(groupPort);
newPortViewModels.Add(portViewModel);
// calculate new position for the proxy outports
groupPort.Center = CalculatePortPosition(groupPort, verticalPosition);
verticalPosition += originalPort.Height;
}
}

return newPortViewModels;
}

Expand All @@ -766,7 +781,7 @@ private List<PortViewModel> CreateProxyOutPorts(IEnumerable<PortModel> groupPort
.ToList();

var newPortViewModels = new List<PortViewModel>();
int index = 0;
double verticalPosition = 0;
foreach (var group in groupPortModels)
{
var originalPort = originalPortViewModels.FirstOrDefault(x => x.PortModel.GUID == group.GUID);
Expand All @@ -775,9 +790,9 @@ private List<PortViewModel> CreateProxyOutPorts(IEnumerable<PortModel> 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;
Expand All @@ -790,23 +805,28 @@ 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;
}
}
}
Expand Down Expand Up @@ -898,7 +918,6 @@ private void RedrawConnectors()

foreach (var connector in allNodes.SelectMany(x=>x.AllConnectors))
{

var connectorViewModel = WorkspaceViewModel
.Connectors
.Where(x => connector.GUID == x.ConnectorModel.GUID)
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ private void GroupTextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
SetTextMaxWidth();
SetTextHeight();
}

ViewModel.UpdateProxyPortsPosition();
}


Expand Down

0 comments on commit 0174e38

Please sign in to comment.