Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WaynePatrickDalton committed Apr 5, 2019
0 parents commit f1d95fe
Show file tree
Hide file tree
Showing 45 changed files with 990 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Dynamo.Extensions;
using Dynamo.Graph.Nodes;
using System.Windows;

namespace HelloDynamo
{
public static class Events
{
private static ReadyParams DynamoReadyParams;

/// <summary>
/// Registers custom events to be triggered when something happens in Dynamo.
/// </summary>
/// <param name="dynamoReadyParams">Reference to the Dynamo extension ready parameters.</param>
public static void RegisterEventHandlers(ReadyParams dynamoReadyParams)
{
dynamoReadyParams.CurrentWorkspaceChanged += OnCurrentWorkspaceChanged;
dynamoReadyParams.CurrentWorkspaceModel.NodeAdded += OnNodeAdded;
dynamoReadyParams.CurrentWorkspaceModel.NodeRemoved += OnNodeRemoved;

// keep a reference to the parameters supplied at startup
// so we can unregister our event handlers later
DynamoReadyParams = dynamoReadyParams;
}

/// <summary>
/// Removes our custom events from Dynamo.
/// </summary>
public static void UnregisterEventHandlers()
{
DynamoReadyParams.CurrentWorkspaceChanged -= OnCurrentWorkspaceChanged;
DynamoReadyParams.CurrentWorkspaceModel.NodeAdded -= OnNodeAdded;
DynamoReadyParams.CurrentWorkspaceModel.NodeRemoved -= OnNodeRemoved;
}

/// <summary>
/// Event triggered whenever a Dynamo Workspace (file) is changed.
/// </summary>
/// <param name="obj">The current Dynamo workspace</param>
private static void OnCurrentWorkspaceChanged(Dynamo.Graph.Workspaces.IWorkspaceModel obj)
{
MessageBox.Show($"Congratulations on opening the {obj.Name} workspace!");
}

/// <summary>
/// Event triggered whenever a new node is added to the Dynamo canvas.
/// </summary>
/// <param name="node">The node that was added.</param>
private static void OnNodeAdded(NodeModel node)
{
MessageBox.Show($"You just added the {node.Name} node with Id {node.GUID} to the canvas.");
}

/// <summary>
/// Event triggered whenever a node is removed from the Dynamo canvas.
/// </summary>
/// <param name="node">The node that was removed.</param>
private static void OnNodeRemoved(NodeModel node)
{
MessageBox.Show($"You just removed the {node.Name} node with Id {node.GUID} from the canvas.");
}
}
}
4 changes: 4 additions & 0 deletions HelloDynamo_ExtensionDefinition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ExtensionDefinition>
<AssemblyPath>..\bin\HelloDynamo.dll</AssemblyPath>
<TypeName>HelloDynamo.ExtensionExample</TypeName>
</ExtensionDefinition>
4 changes: 4 additions & 0 deletions HelloDynamo_ViewExtensionDefinition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ViewExtensionDefinition>
<AssemblyPath>..\bin\HelloDynamo.dll</AssemblyPath>
<TypeName>HelloDynamo.ViewExtensionExample</TypeName>
</ViewExtensionDefinition>
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HelloDynamo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HelloDynamo")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("528a5658-2861-4727-bdc8-c3cdb60c3601")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
79 changes: 79 additions & 0 deletions StatsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Dynamo.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dynamo.Extensions;
using Dynamo.Graph.Nodes;
using Dynamo.ViewModels;
using System.Windows;
using Dynamo.Graph;
using Dynamo.Wpf.Extensions;
using Dynamo.Graph.Annotations;
using Dynamo.Graph.Workspaces;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace HelloDynamo.Stats
{
public class StatsViewModel : NotificationObject
{
private ViewLoadedParams readyParams;
private string activeNodeCount;
private string activeWireCount;

//Displays the count of the nodes in the workspace
public string ActiveNodeCount => readyParams.CurrentWorkspaceModel.Nodes.Count().ToString();

//Displays the count of the wires in the workspace
public string ActiveWireCount => readyParams.CurrentWorkspaceModel.Connectors.Count().ToString();

public StatsViewModel(ReadyParams p)
{
readyParams = p as ViewLoadedParams;
readyParams.CurrentWorkspaceModel.NodeAdded += OnNodeCountChange;
readyParams.CurrentWorkspaceModel.NodeRemoved += OnNodeCountChange;
readyParams.CurrentWorkspaceModel.ConnectorAdded += OnWireCountChange;
readyParams.CurrentWorkspaceModel.ConnectorDeleted += OnWireCountChange;
readyParams.CurrentWorkspaceModel.NodeAdded += OnNodesUpdate;
readyParams.CurrentWorkspaceModel.NodeRemoved += OnNodesUpdate;
readyParams.CurrentWorkspaceChanged += OnWorkspaceChange;
}

#region ChangeProperty events

private void OnNodeCountChange(NodeModel obj)
{
RaisePropertyChanged("ActiveNodeCount");
}

private void OnWireCountChange(Dynamo.Graph.Connectors.ConnectorModel obj)
{
RaisePropertyChanged("ActiveWireCount");
}

private void OnNodesUpdate(NodeModel obj)
{
RaisePropertyChanged("ActiveNodeCount");
}

private void OnWorkspaceChange(Dynamo.Graph.Workspaces.IWorkspaceModel obj)
{
RaisePropertyChanged("ActiveNodeCount", "ActiveWireCount");
}

#endregion

public void Dispose()
{
readyParams.CurrentWorkspaceModel.NodeAdded -= OnNodeCountChange;
readyParams.CurrentWorkspaceModel.NodeRemoved -= OnNodeCountChange;
readyParams.CurrentWorkspaceModel.ConnectorAdded -= OnWireCountChange;
readyParams.CurrentWorkspaceModel.ConnectorDeleted -= OnWireCountChange;
readyParams.CurrentWorkspaceModel.NodeAdded -= OnNodesUpdate;
readyParams.CurrentWorkspaceModel.NodeRemoved -= OnNodesUpdate;
readyParams.CurrentWorkspaceChanged -= OnWorkspaceChange;
}
}
}
32 changes: 32 additions & 0 deletions StatsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Window x:Class="HelloDynamo.StatsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HelloDynamo"
mc:Ignorable="d" d:DesignWidth="300"
Width="180" Title="Graph Totals" SizeToContent="Height" BorderThickness="0" Background="White">

<Grid>
<StackPanel Name="MainGrid"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="2*" />
<RowDefinition Height="2*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,0,0" Padding="5" TextWrapping="Wrap" TextAlignment="Center" Text="Node Count" FontFamily="Arial" FontWeight="Bold" FontSize="14" Background="#8d9ca9" Foreground="#f2f3f4" VerticalAlignment="Center"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0,0,0,0" Padding="5" TextWrapping="Wrap" TextAlignment="Center" Text="Connector Count" FontFamily="Arial" FontWeight="Bold" FontSize="14" Background="#8d9ca9" Foreground="#f2f3f4" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,0,0" Text="{Binding ActiveNodeCount}" Padding="10" TextAlignment="Center" FontFamily="Arial" FontWeight="Bold" FontSize="20" Background="White" Foreground="#13344e"/>
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0,0,0,0" Text="{Binding ActiveWireCount}" Padding="10" TextAlignment="Center" FontFamily="Arial" FontWeight="Bold" FontSize="20" Background="White" Foreground="#13344e"/>
</Grid>
</StackPanel>
</Grid>
</Window>
27 changes: 27 additions & 0 deletions StatsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HelloDynamo
{
/// <summary>
/// Interaction logic for StatsWindow.xaml
/// </summary>
public partial class StatsWindow : Window
{
public StatsWindow()
{
InitializeComponent();
}
}
}

0 comments on commit f1d95fe

Please sign in to comment.