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-7334] Revised TuneUp controls layout #53

Merged
123 changes: 120 additions & 3 deletions TuneUp/ProfiledNodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,115 @@
using Dynamo.Core;
using Dynamo.Graph.Annotations;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Nodes.ZeroTouch;

namespace TuneUp
{
public class ProfiledNodeViewModel : NotificationObject
{
#region Properties

/// <summary>
/// Checks if the Node has been Renamed after its creation
/// </summary>
public bool IsRenamed
{
get
{
if (NodeModel == null)
{
return false;
}
isRenamed = GetOriginalName(NodeModel) != NodeModel.Name;
return isRenamed;
}
internal set
{
if (isRenamed == value) return;
isRenamed = value;
RaisePropertyChanged(nameof(IsRenamed));
}
}
private bool isRenamed = false;

/// <summary>
/// The original name of the node
/// </summary>
public string OriginalName
{
get
{
//string originalName = NodeModel.GetOriginalName();
string originalName = GetOriginalName(NodeModel);
return originalName;
}
internal set
{
if (originalName == value) return;
originalName = value;
RaisePropertyChanged(nameof(OriginalName));
}
}
private string originalName = string.Empty;

/// <summary>
/// Indicates whether this node represents the total execution time for its group
/// </summary>
public bool IsGroupExecutionTime
Copy link
Contributor

Choose a reason for hiding this comment

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

Add summary to this public property

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

{
get => isGroupExecutionTime;
set
{
isGroupExecutionTime = value;
RaisePropertyChanged(nameof(IsGroupExecutionTime));
}
}
private bool isGroupExecutionTime = false;

/// <summary>
/// Getting the original name before graph author renamed the node
/// </summary>
/// <param name="node">target NodeModel</param>
/// <returns>Original node name as string</returns>
private static string GetOriginalName(NodeModel node)
{
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)
{
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;
}

/// <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";

private string name = String.Empty;
/// <summary>
Expand All @@ -31,7 +128,9 @@ public string Name
get
{
// For virtual row, do not attempt to grab node name
if (!name.Contains(ExecutionTimelString) && !name.StartsWith(GroupNodePrefix))
if (!name.Contains(ExecutionTimelString) &&
!name.StartsWith(GroupNodePrefix) &&
!name.Equals(GroupExecutionTimeString))
name = NodeModel?.Name;
return name;
}
Expand Down Expand Up @@ -102,8 +201,14 @@ public TimeSpan GroupExecutionTime
/// </summary>
public int ExecutionMilliseconds
{
get => (int)Math.Round(ExecutionTime.TotalMilliseconds);
get => executionMilliseconds;
set
{
executionMilliseconds = value;
RaisePropertyChanged(nameof(ExecutionMilliseconds));
}
}
private int executionMilliseconds;

/// <summary>
/// Indicates whether this node was executed on the most recent graph run
Expand Down Expand Up @@ -176,6 +281,18 @@ public bool IsGroup
}
private bool isGroup;

public bool ShowGroupIndicator
{
get => showGroupIndicator;
set
{
showGroupIndicator = value;
RaisePropertyChanged(nameof(ShowGroupIndicator));
}
}
private bool showGroupIndicator;


/// <summary>
/// The background brush for this node
/// If this node represents a group, it inherits the background color from the associated AnnotationModel
Expand Down
7 changes: 4 additions & 3 deletions TuneUp/TuneUpViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class TuneUpViewExtension : ViewExtensionBase, IViewExtension

public override void Dispose()
{
TuneUpView.Dispose();
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to removing the dispose on the view when the extension is closed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAICT it was only unsubscribing from DynamoWindow_SizeChanged, which is not needed anymore.

}

public override void Startup(ViewStartupParams p)
Expand All @@ -34,7 +33,9 @@ public override void Loaded(ViewLoadedParams p)
TuneUpView = new TuneUpWindow(p, UniqueId)
{
// Set the data context for the main grid in the window.
NodeAnalysisTable = { DataContext = ViewModel },
LatestRunTable = { DataContext = ViewModel },
PreviousRunTable = { DataContext = ViewModel },
NotExecutedTable = { DataContext = ViewModel },
MainGrid = { DataContext = ViewModel },
Owner = p.DynamoWindow
};
Expand Down Expand Up @@ -114,7 +115,7 @@ public override void Closed()
this.TuneUpMenuItem.IsChecked = false;

// Reset DataGrid sorting order & direction
ViewModel.SortingOrder = "number";
ViewModel.SortingOrder = TuneUpWindowViewModel.SortByNumber;
ViewModel.SortDirection = System.ComponentModel.ListSortDirection.Ascending;
}
}
Expand Down
Loading