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-7466] Navigate-to-corresponding-node/group-by-clicking-it-in-the-TuneUp-list #61

Merged
Show file tree
Hide file tree
Changes from 6 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
88 changes: 56 additions & 32 deletions TuneUp/ProfiledNodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace TuneUp
public class ProfiledNodeViewModel : NotificationObject
{
#region Properties

/// <summary>
/// Checks if the Node has been Renamed after its creation
/// </summary>
Expand Down Expand Up @@ -46,9 +46,7 @@ public string OriginalName
{
get
{
//string originalName = NodeModel.GetOriginalName();
string originalName = GetOriginalName(NodeModel);
return originalName;
return GetOriginalName(NodeModel);
}
internal set
{
Expand All @@ -62,23 +60,51 @@ internal set
/// <summary>
/// Indicates whether this node represents the total execution time for its group
/// </summary>
public bool IsGroupExecutionTime
public bool IsGroupExecutionTime => NodeModel == null && GroupModel == null;

/// <summary>
/// Getting the original name before graph author renamed the node
/// </summary>
private static string GetOriginalName(NodeModel node)
reddyashish marked this conversation as resolved.
Show resolved Hide resolved
{
get => isGroupExecutionTime;
set
if (node == null) return string.Empty;
// For dummy node, return the current name so that does not appear to be renamed
if (node is DummyNode)
{
isGroupExecutionTime = value;
RaisePropertyChanged(nameof(IsGroupExecutionTime));
return node.Name;
}
if (node.IsCustomFunction)
{
// If the custom node is not loaded, return the current name so that does not appear to be renamed
if ((node as Function).State == ElementState.Error && (node as Function).Definition.IsProxy)
{
return node.Name;
}
// If the custom node is loaded, return original name as usual
var customNodeFunction = node as Function;
return customNodeFunction?.Definition.DisplayName;
}

var function = node as DSFunctionBase;
if (function != null)
return function.Controller.Definition.DisplayName;

var nodeType = node.GetType();
var elNameAttrib = nodeType.GetCustomAttributes<NodeNameAttribute>(false).FirstOrDefault();
if (elNameAttrib != null)
return elNameAttrib.Name;

return nodeType.FullName;
}
private bool isGroupExecutionTime = false;

/// <summary>
/// Prefix string of execution time.
/// </summary>
public static readonly string ExecutionTimelString = "Execution Time";
public static readonly string GroupNodePrefix = "Group: ";
public static readonly string GroupExecutionTimeString = "Group total";
internal const string ExecutionTimelString = "Execution Time";
internal const string GroupNodePrefix = "Group: ";
internal const string GroupExecutionTimeString = "Group total";
private const string DefaultGroupName = "Title <Double click here to edit group title>";
private const string DefaultDisplayGroupName = "Title";

private string name = String.Empty;
/// <summary>
Expand All @@ -90,11 +116,19 @@ public string Name
{
get
{
// For virtual row, do not attempt to grab node name
if (!name.Contains(ExecutionTimelString) &&
!name.StartsWith(GroupNodePrefix) &&
!name.Equals(GroupExecutionTimeString))
name = NodeModel?.Name;
// For virtual row, do not attempt to grab node or group name if it's already handled
if (!this.IsGroupExecutionTime)
{
if (NodeModel != null)
{
return NodeModel.Name;
}
else if (GroupModel != null)
{
return GroupModel.AnnotationText == DefaultGroupName ?
$"{GroupNodePrefix}{DefaultDisplayGroupName}" : GroupModel.AnnotationText;
}
}
return name;
}
internal set { name = value; }
Expand Down Expand Up @@ -233,16 +267,7 @@ public string GroupName
/// <summary>
/// Indicates if this node is a group
/// </summary>
public bool IsGroup
{
get => isGroup;
set
{
isGroup = value;
RaisePropertyChanged(nameof(IsGroup));
}
}
private bool isGroup;
public bool IsGroup => NodeModel == null && GroupModel != null;

public bool ShowGroupIndicator
{
Expand Down Expand Up @@ -297,6 +322,8 @@ public string StateDescription

internal NodeModel NodeModel { get; set; }

internal AnnotationModel GroupModel { get; set; }

#endregion

/// <summary>
Expand Down Expand Up @@ -371,7 +398,6 @@ public ProfiledNodeViewModel(NodeModel node)
/// <param name="state">state which determine grouping</param>
public ProfiledNodeViewModel(string name, TimeSpan exTimeSum, ProfiledNodeState state)
{
NodeModel = null;
this.Name = name;
this.ExecutionTime = exTimeSum;
State = state;
Expand All @@ -383,12 +409,10 @@ public ProfiledNodeViewModel(string name, TimeSpan exTimeSum, ProfiledNodeState
/// <param name="group">the annotation model</param>
public ProfiledNodeViewModel(AnnotationModel group)
{
NodeModel = null;
Name = $"{GroupNodePrefix}{group.AnnotationText}";
GroupModel = group;
GroupName = group.AnnotationText;
GroupGUID = group.GUID;
BackgroundBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(group.Background));
IsGroup = true;
State = ProfiledNodeState.NotExecuted;
ShowGroupIndicator = true;
}
Expand Down
43 changes: 26 additions & 17 deletions TuneUp/TuneUpWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
Expand All @@ -8,7 +7,7 @@
using System.Windows.Data;
using System.Windows.Media;
using Dynamo.Extensions;
using Dynamo.Graph.Nodes;
using Dynamo.Graph;
using Dynamo.Models;
using Dynamo.UI;
using Dynamo.Utilities;
Expand Down Expand Up @@ -53,29 +52,39 @@ public TuneUpWindow(ViewLoadedParams vlp, string id)
}

private void NodeAnalysisTable_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
{
if (!isUserInitiatedSelection) return;

// Get NodeModel(s) that correspond to selected row(s)
var selectedNodes = new List<NodeModel>();
foreach (var item in e.AddedItems)
var selectedItem = e.AddedItems.OfType<ProfiledNodeViewModel>().FirstOrDefault();

if (selectedItem == null) return;

// Extract the GUID and type (NodeModel or GroupModel)
var modelBase = selectedItem.NodeModel ?? (ModelBase)selectedItem.GroupModel;

if (modelBase != null)
{
// Check NodeModel valid before actual selection
var nodeModel = (item as ProfiledNodeViewModel).NodeModel;
if (nodeModel != null)
// Clear the selection in other DataGrids based on the sender
if (sender == LatestRunTable)
{
selectedNodes.Add(nodeModel);
NotExecutedTable.SelectedItem = null;
PreviousRunTable.SelectedItem = null;
}
else if (sender == NotExecutedTable)
{
LatestRunTable.SelectedItem = null;
PreviousRunTable.SelectedItem = null;
}
else if (sender == PreviousRunTable)
{
LatestRunTable.SelectedItem = null;
NotExecutedTable.SelectedItem = null;
}
}

if (selectedNodes.Count() > 0)
{
// Select
var command = new DynamoModel.SelectModelCommand(selectedNodes.Select(nm => nm.GUID), ModifierKeys.None);
var command = new DynamoModel.SelectModelCommand(new[] { modelBase.GUID }, ModifierKeys.None);
commandExecutive.ExecuteCommand(command, uniqueId, "TuneUp");

// Focus on selected
viewModelCommandExecutive.FindByIdCommand(selectedNodes.First().GUID.ToString());
viewModelCommandExecutive.FindByIdCommand(modelBase.GUID.ToString());
}
}

Expand Down
1 change: 0 additions & 1 deletion TuneUp/TuneUpWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,6 @@ private ProfiledNodeViewModel CreateGroupTotalTimeNode(ProfiledNodeViewModel pro
GroupGUID = profiledGroup.GroupGUID,
GroupName = profiledGroup.GroupName,
BackgroundBrush = profiledGroup.BackgroundBrush,
IsGroupExecutionTime = true,
ShowGroupIndicator = true
};

Expand Down
Loading