Skip to content

Commit

Permalink
Allow node deletion and fix IntegerUpDown some more
Browse files Browse the repository at this point in the history
  • Loading branch information
luca009 committed Jul 22, 2021
1 parent 88bca86 commit 13fe156
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Nodex/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using Nodex.Classes;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace Nodex
{
Expand All @@ -13,5 +15,6 @@ namespace Nodex
/// </summary>
public partial class App : Application
{

}
}
27 changes: 27 additions & 0 deletions Nodex/Classes/ActionCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Windows.Input;

namespace Nodex.Classes
{
class ActionCommand : ICommand
{
private readonly Action _action;

public ActionCommand(Action action)
{
_action = action;
}

public void Execute(object parameter)
{
_action();
}

public bool CanExecute(object parameter)
{
return true;
}

public event EventHandler CanExecuteChanged;
}
}
18 changes: 16 additions & 2 deletions Nodex/Classes/NodeProperty.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using Nodex.Resources.Controls;
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.Input;

namespace Nodex.Classes
Expand All @@ -20,14 +22,26 @@ public NodeProperty(UIElement propertyElement, string label)
this.propertyElement = propertyElement;
this.label = label;

propertyElement.MouseMove += ValueUpdated;
switch (propertyElement)
{
case IntegerUpDown integerUpDown:
integerUpDown.ValueChanged += ValueUpdated;
break;
default:
break;
}

propertyElement.MouseDown += ValueUpdated;
propertyElement.MouseUp += ValueUpdated;
propertyElement.MouseWheel += ValueUpdated;
propertyElement.KeyDown += ValueUpdated;
propertyElement.KeyUp += ValueUpdated;
}

private void ValueUpdated(object sender, EventArgs e)
{
NetworkSolver.SolveWithoutReindexing(((MainWindow)App.Current.MainWindow).lastNodes);
}
private void ValueUpdated(object sender, MouseEventArgs e)
{
NetworkSolver.SolveWithoutReindexing(((MainWindow)App.Current.MainWindow).lastNodes);
Expand Down
7 changes: 5 additions & 2 deletions Nodex/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="Nodex.MainWindow"
<Window x:Name="window" x:Class="Nodex.MainWindow"
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"
Expand All @@ -7,6 +7,9 @@
xmlns:local="clr-namespace:Nodex"
mc:Ignorable="d"
Title="Nodex" Height="500" Width="850">
<Window.InputBindings>
<KeyBinding Command="{Binding DeleteCommand, ElementName=window, Mode=OneWay}" Key="Delete"/>
</Window.InputBindings>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200*" MinWidth="100"/>
Expand All @@ -20,7 +23,7 @@
<RowDefinition Height="4" MaxHeight="4" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ScrollViewer x:Name="scrollviewerNodeSpace" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Drop="scrollviewerNodeSpace_Drop">
<ScrollViewer x:Name="scrollviewerNodeSpace" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Drop="scrollviewerNodeSpace_Drop" MouseRightButtonDown="scrollviewerNodeSpace_MouseRightButtonDown">
<Canvas x:Name="canvasNodeSpace" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"/>
</ScrollViewer>
<GridSplitter Grid.Row="1" Margin="0" ResizeDirection="Rows" ResizeBehavior="PreviousAndNext" HorizontalAlignment="Stretch"/>
Expand Down
88 changes: 86 additions & 2 deletions Nodex/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.IO;
using System.Xml;
using Nodex.Classes.Nodes;
using System.Windows.Media.Effects;

namespace Nodex
{
Expand All @@ -32,6 +33,21 @@ public partial class MainWindow : Window
public OutputNode outputNode { get; private set; }
public Node[] lastNodes { get; private set; }

#region Commands
private ICommand deleteCommand;
public ICommand DeleteCommand
{
get
{
return deleteCommand
?? (deleteCommand = new ActionCommand(() =>
{
DeleteNode(selectedNode);
}));
}
}
#endregion

public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -82,12 +98,47 @@ private void CreateNodeAndAdd(NodeControl nodeControl)
Panel.SetZIndex(nodeControl, 3);
}

private void DeleteNode(NodeControl nodeControl)
{
if (nodeControl == null || nodeControl.nodeType == typeof(OutputNode))
return;

foreach (NodeInputControl nodeInputControl in nodeControl.inputs)
{
nodeInputControl.connectedNodeOutput.connectedNodeInputs = null;
nodeInputControl.connectedNodeOutput.nodeIO.connectedNodeIOs.Remove(nodeInputControl.nodeIO);
canvasNodeSpace.Children.Remove(nodeInputControl.connectedLine);
nodeInputControl.connectedLine = null;
}
foreach (NodeOutputControl nodeOutputControl in nodeControl.outputs)
{
foreach (NodeInputControl nodeInputControl in nodeOutputControl.connectedNodeInputs)
{
nodeInputControl.connectedNodeOutput = null;
nodeInputControl.nodeIO.connectedNodeIOs.Remove(nodeOutputControl.nodeIO);
canvasNodeSpace.Children.Remove(nodeInputControl.connectedLine);
nodeInputControl.connectedLine = null;
}
}

//Cleanly empty the StackPanel for node properties
for (int i = stackpanelConfigureElements.Children.Count - 1; i >= 0; i--)
{
var temp = stackpanelConfigureElements.Children[i];
((Grid)temp).Children.Clear();
this.RemoveLogicalChild(temp);
}
stackpanelConfigureElements.Children.Clear();

canvasNodeSpace.Children.Remove(nodeControl);
}

private void nodeControl_NodeMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
//Change ZIndexes of each object depending on their type (make NodeControls on top)
Type lineType = typeof(Line);
Type nodeControlType = typeof(NodeControl);
foreach (FrameworkElement item in canvasNodeSpace.Children)
foreach (UIElement item in canvasNodeSpace.Children)
{
switch (item)
{
Expand All @@ -96,13 +147,17 @@ private void nodeControl_NodeMouseRightButtonDown(object sender, MouseButtonEven
break;
case NodeControl nodeControl:
Panel.SetZIndex(item, 2);
DropShadowEffect dropShadowEffectOfNodeControl = (DropShadowEffect)((UIElement)nodeControl.Content).Effect;
dropShadowEffectOfNodeControl.Color = Color.FromRgb(0, 0, 0);
dropShadowEffectOfNodeControl.BlurRadius = 5;
dropShadowEffectOfNodeControl.Opacity = 100;
break;
default:
Panel.SetZIndex(item, 0);
break;
}
}


//Cycle through the parents of the sender and find the related NodeControl
FrameworkElement currentElement = (FrameworkElement)sender;
Expand Down Expand Up @@ -140,6 +195,13 @@ private void SetNodeSelection(NodeControl nodeControl)
addGrid.Children.Add(tempControl);
stackpanelConfigureElements.Children.Add(addGrid);
}

selectedNode = nodeControl;

DropShadowEffect dropShadowEffectOfNodeControl = (DropShadowEffect)((UIElement)nodeControl.Content).Effect;
dropShadowEffectOfNodeControl.Color = Color.FromRgb(0, 200, 240);
dropShadowEffectOfNodeControl.BlurRadius = 2;
dropShadowEffectOfNodeControl.Opacity = 40;
}

private void nodeIOControl_Drop(object sender, DragEventArgs e)
Expand Down Expand Up @@ -277,5 +339,27 @@ private void scrollviewerNodeSpace_Drop(object sender, DragEventArgs e)

NetworkSolver.Solve(GetNodes());
}

private void scrollviewerNodeSpace_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
//if (selectedNode == null)
// return;

////Cleanly empty the StackPanel for node properties
//for (int i = stackpanelConfigureElements.Children.Count - 1; i >= 0; i--)
//{
// var temp = stackpanelConfigureElements.Children[i];
// ((Grid)temp).Children.Clear();
// this.RemoveLogicalChild(temp);
//}
//stackpanelConfigureElements.Children.Clear();

//DropShadowEffect dropShadowEffectOfNodeControl = (DropShadowEffect)((UIElement)selectedNode.Content).Effect;
//dropShadowEffectOfNodeControl.Color = Color.FromRgb(0, 200, 240);
//dropShadowEffectOfNodeControl.BlurRadius = 2;
//dropShadowEffectOfNodeControl.Opacity = 40;

//selectedNode = null;
}
}
}
4 changes: 4 additions & 0 deletions Nodex/Resources/Controls/IntegerUpDown.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private void bUp_Click(object sender, RoutedEventArgs e)
if (Value > MaxValue)
Value = MaxValue;
tboxInput.Text = Value.ToString();
if (ValueChanged != null)
ValueChanged(sender, e);
}

private void bDown_Click(object sender, RoutedEventArgs e)
Expand All @@ -59,6 +61,8 @@ private void bDown_Click(object sender, RoutedEventArgs e)
if (Value < MinValue)
Value = MinValue;
tboxInput.Text = Value.ToString();
if (ValueChanged != null)
ValueChanged(sender, e);
}

private void tboxInput_TextChanged(object sender, TextChangedEventArgs e)
Expand Down

0 comments on commit 13fe156

Please sign in to comment.