Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouterdek committed Nov 14, 2020
1 parent 91545bc commit 73d8e5a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
43 changes: 41 additions & 2 deletions NodeNetworkToolkit/ContextMenu/AddNodeContextMenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace NodeNetwork.Toolkit.ContextMenu
{
/// <summary>
/// A viewmodel for a context menu that allows users to add nodes to a network.
/// </summary>
public class AddNodeContextMenuViewModel : SearchableContextMenuViewModel
{
static AddNodeContextMenuViewModel()
Expand All @@ -18,6 +21,9 @@ static AddNodeContextMenuViewModel()
}

#region Network
/// <summary>
/// The network to which the nodes are to be added.
/// </summary>
public NetworkViewModel Network
{
get => _network;
Expand All @@ -26,16 +32,31 @@ public NetworkViewModel Network
private NetworkViewModel _network;
#endregion

/// <summary>
/// The format that is used to create labels for the menu entries based on the node name.
/// E.g. "Add {0}"
/// </summary>
public string LabelFormat { get; }

/// <summary>
/// When adding a node to the network,
/// this function is used to determine the position at which it is placed.
/// </summary>
public Func<NodeViewModel, Point> NodePositionFunc { get; set; } = (node) => new Point();

/// <summary>
/// A callback that is called after a node is added to the network through this menu.
/// </summary>
public Action<NodeViewModel> OnNodeAdded { get; set; } = node => { };

private ReactiveCommand<NodeTemplate, Unit> CreateNode { get; }

/// <summary>
/// An interaction that is used to open contextmenu views given a SearchableContextMenuViewModel.
/// Used in ShowAddNodeForPendingConnectionMenu to display this menu, and a menu for choosing an endpoint.
/// </summary>
public Interaction<SearchableContextMenuViewModel, Unit> OpenContextMenu { get; } = new Interaction<SearchableContextMenuViewModel, Unit>();

private ReactiveCommand<NodeTemplate, Unit> CreateNode { get; }

public AddNodeContextMenuViewModel(string labelFormat = "{0}")
{
LabelFormat = labelFormat;
Expand All @@ -50,6 +71,12 @@ public AddNodeContextMenuViewModel(string labelFormat = "{0}")
});
}

/// <summary>
/// Adds a new node type to the list.
/// Every time a node is added to a network from this list, the factory function in the template
/// will be called to create a new instance of the viewmodel type.
/// </summary>
/// <param name="template">The template with the node type to add.</param>
public void AddNodeType(NodeTemplate template)
{
Commands.Add(new LabeledCommand
Expand Down Expand Up @@ -165,6 +192,10 @@ public void ShowAddNodeForPendingConnectionMenu(PendingConnectionViewModel pendi
OpenContextMenu.Handle(this).Subscribe();
}

/// <summary>
/// Given a set of node templates, return those which have an endpoint
/// that could be connected to the specified pending connection.
/// </summary>
public static IEnumerable<NodeTemplate> GetConnectableNodes(IEnumerable<NodeTemplate> candidateNodeTemplates, PendingConnectionViewModel testCon)
{
foreach (var curNode in candidateNodeTemplates)
Expand All @@ -181,6 +212,10 @@ public static IEnumerable<NodeTemplate> GetConnectableNodes(IEnumerable<NodeTemp
}
}

/// <summary>
/// Given a node viewmodel, return the outputs which could be connected to the pending connection.
/// Assumes testCon.Input is set.
/// </summary>
public static IEnumerable<NodeOutputViewModel> GetConnectableOutputs(NodeViewModel node, PendingConnectionViewModel testCon)
{
var validator = testCon.Input.ConnectionValidator;
Expand All @@ -194,6 +229,10 @@ public static IEnumerable<NodeOutputViewModel> GetConnectableOutputs(NodeViewMod
}
}

/// <summary>
/// Given a node viewmodel, return the inputs which could be connected to the pending connection.
/// Assumes testCon.Output is set.
/// </summary>
public static IEnumerable<NodeInputViewModel> GetConnectableInputs(NodeViewModel node, PendingConnectionViewModel testCon)
{
foreach (var curInput in node.Inputs.Items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace NodeNetwork.Toolkit.ContextMenu
{
/// <summary>
/// A data type containing a command, parameter and display properties.
/// </summary>
public class LabeledCommand : ReactiveObject
{
#region Label
Expand Down Expand Up @@ -58,6 +61,9 @@ public object CommandParameter
#endregion
}

/// <summary>
/// A viewmodel for a context menu in which the entries can be filtered by the user based on a searchquery.
/// </summary>
public class SearchableContextMenuViewModel : ReactiveObject
{
static SearchableContextMenuViewModel()
Expand Down

0 comments on commit 73d8e5a

Please sign in to comment.