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-7698] Zoom to group, doesn't work #76

Merged
Merged
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
111 changes: 59 additions & 52 deletions TuneUp/TuneUpWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,68 +308,70 @@ internal void ResetProfiledNodes()
{
if (CurrentWorkspace == null) return;

// Clear existing collections
ProfiledNodesLatestRun?.Clear();
ProfiledNodesPreviousRun?.Clear();
ProfiledNodesNotExecuted?.Clear();
uiContext.Send(_ => {
// Clear existing collections
ProfiledNodesLatestRun?.Clear();
ProfiledNodesPreviousRun?.Clear();
ProfiledNodesNotExecuted?.Clear();

// Reset execution time stats
LatestGraphExecutionTime = PreviousGraphExecutionTime = TotalGraphExecutionTime = defaultExecutionTime;
// Reset execution time stats
LatestGraphExecutionTime = PreviousGraphExecutionTime = TotalGraphExecutionTime = defaultExecutionTime;

// Initialize observable collections and dictionaries
ProfiledNodesLatestRun = ProfiledNodesLatestRun ?? new ObservableCollection<ProfiledNodeViewModel>();
ProfiledNodesPreviousRun = ProfiledNodesPreviousRun ?? new ObservableCollection<ProfiledNodeViewModel>();
ProfiledNodesNotExecuted = ProfiledNodesNotExecuted ?? new ObservableCollection<ProfiledNodeViewModel>();
// Initialize observable collections and dictionaries
ProfiledNodesLatestRun = ProfiledNodesLatestRun ?? new ObservableCollection<ProfiledNodeViewModel>();
ProfiledNodesPreviousRun = ProfiledNodesPreviousRun ?? new ObservableCollection<ProfiledNodeViewModel>();
ProfiledNodesNotExecuted = ProfiledNodesNotExecuted ?? new ObservableCollection<ProfiledNodeViewModel>();

collectionMapping = new Dictionary<ObservableCollection<ProfiledNodeViewModel>, CollectionViewSource> {
collectionMapping = new Dictionary<ObservableCollection<ProfiledNodeViewModel>, CollectionViewSource> {
{ ProfiledNodesLatestRun, ProfiledNodesCollectionLatestRun },
{ProfiledNodesPreviousRun, ProfiledNodesCollectionPreviousRun },
{ProfiledNodesNotExecuted, ProfiledNodesCollectionNotExecuted }
{ProfiledNodesNotExecuted, ProfiledNodesCollectionNotExecuted }
};

nodeDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupModelDictionary = new Dictionary<Guid, List<ProfiledNodeViewModel>>();
nodeDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupModelDictionary = new Dictionary<Guid, List<ProfiledNodeViewModel>>();

// Create a profiled node for each NodeModel
foreach (var node in CurrentWorkspace.Nodes)
{
var profiledNode = new ProfiledNodeViewModel(node) { GroupName = node.Name };
ProfiledNodesNotExecuted.Add(profiledNode);
nodeDictionary[node.GUID] = profiledNode;
}
// Create a profiled node for each NodeModel
foreach (var node in CurrentWorkspace.Nodes)
{
var profiledNode = new ProfiledNodeViewModel(node) { GroupName = node.Name };
ProfiledNodesNotExecuted.Add(profiledNode);
nodeDictionary[node.GUID] = profiledNode;
}

// Create a profiled node for each AnnotationModel
foreach (var group in CurrentWorkspace.Annotations)
{
var pGroup = new ProfiledNodeViewModel(group);
ProfiledNodesNotExecuted.Add(pGroup);
groupDictionary[pGroup.NodeGUID] = (pGroup);
groupModelDictionary[group.GUID] = new List<ProfiledNodeViewModel> { pGroup };
// Create a profiled node for each AnnotationModel
foreach (var group in CurrentWorkspace.Annotations)
{
var pGroup = new ProfiledNodeViewModel(group);
ProfiledNodesNotExecuted.Add(pGroup);
groupDictionary[pGroup.NodeGUID] = (pGroup);
groupModelDictionary[group.GUID] = new List<ProfiledNodeViewModel> { pGroup };

var groupedNodeGUIDs = group.Nodes.OfType<NodeModel>().Select(n => n.GUID);
var groupedNodeGUIDs = group.Nodes.OfType<NodeModel>().Select(n => n.GUID);

foreach (var nodeGuid in groupedNodeGUIDs)
{
if (nodeDictionary.TryGetValue(nodeGuid, out var pNode))
foreach (var nodeGuid in groupedNodeGUIDs)
{
ApplyGroupPropertiesAndRegisterNode(pNode, pGroup);
if (nodeDictionary.TryGetValue(nodeGuid, out var pNode))
{
ApplyGroupPropertiesAndRegisterNode(pNode, pGroup);
}
}
}
}

ProfiledNodesCollectionLatestRun = new CollectionViewSource { Source = ProfiledNodesLatestRun };
ProfiledNodesCollectionPreviousRun = new CollectionViewSource { Source = ProfiledNodesPreviousRun };
ProfiledNodesCollectionNotExecuted = new CollectionViewSource { Source = ProfiledNodesNotExecuted };
ProfiledNodesCollectionLatestRun = new CollectionViewSource { Source = ProfiledNodesLatestRun };
ProfiledNodesCollectionPreviousRun = new CollectionViewSource { Source = ProfiledNodesPreviousRun };
ProfiledNodesCollectionNotExecuted = new CollectionViewSource { Source = ProfiledNodesNotExecuted };

// Refresh UI if any changes were made
RaisePropertyChanged(nameof(ProfiledNodesCollectionNotExecuted));
ApplyCustomSorting(ProfiledNodesCollectionNotExecuted, SortByName);
// Refresh UI if any changes were made
RaisePropertyChanged(nameof(ProfiledNodesCollectionNotExecuted));
ApplyCustomSorting(ProfiledNodesCollectionNotExecuted, SortByName);

ApplyGroupNodeFilter();
ApplyGroupNodeFilter();

// Ensure table visibility is updated in case TuneUp was closed and reopened with the same graph.
UpdateTableVisibility();
// Ensure table visibility is updated in case TuneUp was closed and reopened with the same graph.
UpdateTableVisibility();
}, null);
}

/// <summary>
Expand Down Expand Up @@ -578,6 +580,7 @@ private void CreateGroupNodesForCollection(ObservableCollection<ProfiledNodeView
{
int executionCounter = 1;
var processedNodes = new HashSet<ProfiledNodeViewModel>();
var nodesToAdd = new HashSet<ProfiledNodeViewModel>();

var sortedNodes = collection.OrderBy(n => n.ExecutionOrderNumber).ToList();

Expand Down Expand Up @@ -610,20 +613,16 @@ private void CreateGroupNodesForCollection(ObservableCollection<ProfiledNodeView
var pGroup = new ProfiledNodeViewModel(pNode)
{
GroupExecutionOrderNumber = executionCounter++,
GroupExecutionMilliseconds = groupExecTime
GroupExecutionMilliseconds = groupExecTime,
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 add some comments here to provide why we need nodesToAdd here?.
I thought this was fixed by DynamoDS/Dynamo#15547

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've written in the description that I couldn't build from master so I created this branch from DYN-7697-Crash-with-Periodic-Run as it was the latest I've published (the branch of #15547). Relevant changes to this ticket are only in CreateGroupNodesForCollection.

GroupModel = CurrentWorkspace.Annotations.First(n => n.GUID.Equals(pNode.GroupGUID))
};
nodesToAdd.Add(pGroup);

groupDictionary[pGroup.NodeGUID] = pGroup;
groupModelDictionary[pNode.GroupGUID].Add(pGroup);

// Create an register a new time node
var timeNode = CreateAndRegisterGroupTimeNode(pGroup);

GetCollectionViewSource(collection).Dispatcher.Invoke(() =>
{
collection.Add(timeNode);
collection.Add(pGroup);
});
nodesToAdd.Add(CreateAndRegisterGroupTimeNode(pGroup));

// Update group-related properties for all nodes in the group
foreach (var node in nodesInGroup)
Expand All @@ -633,6 +632,14 @@ private void CreateGroupNodesForCollection(ObservableCollection<ProfiledNodeView
}
}
}

GetCollectionViewSource(collection).Dispatcher.Invoke(() =>
{
foreach (var node in nodesToAdd)
{
collection.Add(node);
}
});
}

internal void OnNodeExecutionBegin(NodeModel nm)
Expand Down