Skip to content

Commit

Permalink
Release 2.0.37
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Mar 11, 2022
1 parent fe01ffa commit 696f941
Show file tree
Hide file tree
Showing 72 changed files with 1,133 additions and 391 deletions.
2 changes: 1 addition & 1 deletion CNC Controls Camera/CNC Controls Camera/Camera.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CNC.Controls.Camera"
mc:Ignorable="d"
Title="Sender" Height="390" Width="504"
Title="Sender" Height="414" Width="504"
Topmost="True"
Closing="Window_Closing" Icon="App.ico" ShowInTaskbar="False" ResizeMode="NoResize">
<Window.TaskbarItemInfo>
Expand Down
7 changes: 5 additions & 2 deletions CNC Controls Camera/CNC Controls Camera/Camera.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Camera.xaml.cs - part of CNC Controls Camera library
*
* v0.33 / 2021-05-04 / Io Engineering (Terje Io)
* v0.37 / 2022-03-02 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2018-2021, Io Engineering (Terje Io) - parts derived from AForge example code
Copyright (c) 2018-2022, Io Engineering (Terje Io) - parts derived from AForge example code
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -66,6 +66,7 @@ private void CNCCamera_MoveOffset(Core.CameraMoveMode Mode, double XOffset, doub
public bool HasCamera { get { return CNCCamera.HasCamera; } }
public CameraControl CameraControl { get { return CNCCamera; } }
public new bool IsVisible { get { return CNCCamera.IsVisible; } }
public bool IsMoveEnabled { get { return CNCCamera.IsMoveEnabled; } set { CNCCamera.IsMoveEnabled = value && (CNCCamera.XOffset != 0d || CNCCamera.YOffset != 0d); } }

public void Setup(UIViewModel model)
{
Expand All @@ -89,6 +90,8 @@ public void Open()

Show();

CameraControl.MoveCameraToSpindlePosition = AppConfig.Settings.Camera.InitialMoveToSpindle;

if (CNCCamera.OpenVideoSource())
IsVisibilityChanged?.Invoke();
}
Expand Down
26 changes: 18 additions & 8 deletions CNC Controls Camera/CNC Controls Camera/CameraControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:CNC.Controls.Camera"
mc:Ignorable="d"
d:DesignHeight="360" d:DesignWidth="500"
d:DesignHeight="370" d:DesignWidth="500"
Background="#FFF0F0F0" Loaded="CameraControl_Loaded">
<UserControl.Resources>
<system:String x:Uid="str_moveSpindleTo" x:Key="MoveSpindleTo">Move spindle to camera position?</system:String>
<system:String x:Uid="str_moveCameraTo" x:Key="MoveCameraTo">Move camera to spindle position?</system:String>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="320"/>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
<RowDefinition Height="307"/>
<RowDefinition Height="33"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="420"/>
<ColumnDefinition Width="407"/>
<ColumnDefinition Width="80"/>
</Grid.ColumnDefinitions>
<Image Width="400" Height="300" HorizontalAlignment="Left" Name="frameHolder" VerticalAlignment="Top" Margin="10,10,0,0"/>
<Slider x:Name="sldcircle" Orientation="Vertical" HorizontalAlignment="Left" Value="{Binding Path=GuideScale, Mode=TwoWay}" Margin="28,30,0,0" VerticalAlignment="Top" Height="118" Width="30" Grid.Column="1" ValueChanged="sldcircle_ValueChanged" Maximum="100" Minimum="5" LargeChange="10" SmallChange="1"/>
<Button x:Uid="btn_moveOffset" x:Name="btnMove" Content="Move offset" IsEnabled="{Binding Path=IsMoveEnabled}" HorizontalAlignment="Left" Margin="10,4,0,0" Grid.Row="1" VerticalAlignment="Top" Width="75" Click="btnMove_Click" Height="22"/>
<ComboBox x:Name="cbxCamera" ItemsSource="{Binding Path=Cameras}" DisplayMemberPath="Name" SelectedValuePath="Camera" HorizontalAlignment="Left" Margin="100,4,0,0" Grid.Row="1" VerticalAlignment="Top" Width="300" SelectionChanged="cbxCamera_SelectionChanged" Height="22"/>
<ComboBox x:Name="cbxCamera" ItemsSource="{Binding Cameras}" DisplayMemberPath="Name" SelectedValuePath="Camera" Width="400" SelectionChanged="cbxCamera_SelectionChanged" Height="22" Margin="5,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
<Image Width="400" Height="300" HorizontalAlignment="Left" Name="frameHolder" VerticalAlignment="Top" Margin="5,5,0,0" Grid.Row="1"/>
<Slider x:Name="sldcircle" Orientation="Vertical" HorizontalAlignment="Left" Value="{Binding Path=GuideScale, Mode=TwoWay}" Margin="28,1,0,0" VerticalAlignment="Top" Height="118" Width="30" Grid.Column="1" ValueChanged="sldcircle_ValueChanged" Maximum="100" Minimum="5" LargeChange="10" SmallChange="1" Grid.Row="1"/>
<StackPanel Orientation="Horizontal" Grid.Row="2" Margin="5,4,0,0" Grid.ColumnSpan="2" Height="22" VerticalAlignment="Top">
<Button x:Uid="btn_moveOffset" x:Name="btnMove" Content="Move offset" IsEnabled="{Binding Path=IsMoveEnabled}" Width="75" Click="btnMove_Click" Height="22"/>
<CheckBox x:Uid="lbl_cameraToSpindlePosition" x:Name="chkCameraToSpindlePosition" Content="camera to spindle" Focusable="False" IsChecked="{Binding Path=MoveCameraToSpindlePosition, Mode=TwoWay}" IsEnabled="{Binding Path=IsMoveEnabled}" Margin="4,0,0,0" VerticalAlignment="Center"/>
<Button x:Uid="btn_useAsProbe" x:Name="btnUseAsProbe" Content="Use as probe position" IsEnabled="{Binding Path=grbl.IsProbing}" Focusable="False" Padding="4,0" Margin="46,0,0,0" Click="btnPublish_Click" Height="22"/>
</StackPanel>
</Grid>
</UserControl>
67 changes: 55 additions & 12 deletions CNC Controls Camera/CNC Controls Camera/CameraControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* CameraControl.xaml.cs - part of CNC Controls Camera library
*
* v0.30 / 2021-04-08 / Io Engineering (Terje Io)
* v0.37 / 2022-03-02 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2018-2021, Io Engineering (Terje Io) - parts derived from AForge example code
Copyright (c) 2018-2022, Io Engineering (Terje Io) - parts derived from AForge example code
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -68,9 +68,9 @@ public partial class CameraControl : UserControl

public CameraControl()
{
DataContext = this;

InitializeComponent();

DataContext = this;
}

private void CameraControl_Loaded(object sender, RoutedEventArgs e)
Expand All @@ -83,6 +83,12 @@ private void CameraControl_Loaded(object sender, RoutedEventArgs e)
if (Cameras.Count > 0)
{
Camera = Cameras[0];
if (AppConfig.Settings.Camera.SelectedCamera != string.Empty)
{
foreach (FilterInfo camera in Cameras)
if (camera.MonikerString == AppConfig.Settings.Camera.SelectedCamera)
Camera = camera;
}
cbxCamera.SelectedItem = Camera;
}
}
Expand Down Expand Up @@ -123,6 +129,15 @@ private static void OnGuideScaleChanged(DependencyObject d, DependencyPropertyCh
AppConfig.Settings.Camera.GuideScale = (int)e.NewValue;
}

public static readonly DependencyProperty MoveCameraToSpindlePositionProperty = DependencyProperty.Register(nameof(MoveCameraToSpindlePosition), typeof(bool), typeof(CameraControl), new PropertyMetadata(false));
public bool MoveCameraToSpindlePosition
{
get { return (bool)GetValue(MoveCameraToSpindlePositionProperty); }
set { SetValue(MoveCameraToSpindlePositionProperty, value); }
}

public GrblViewModel grbl { get { return Grbl.GrblViewModel; } }

public double XOffset
{
get { return _xOffset; }
Expand All @@ -139,27 +154,34 @@ public double YOffset
public FilterInfoCollection Cameras { get; private set; } = new FilterInfoCollection(FilterCategory.VideoInputDevice);
public FilterInfo Camera { get; private set; }

public bool OpenVideoSource()
public bool OpenVideoSource(FilterInfo camera)
{
if (Camera != null)
CloseCurrentVideoSource();

if (camera != null)
{
videoSource = new VideoCaptureDevice(Camera.MonikerString);
videoSource = new VideoCaptureDevice(camera.MonikerString);
videoSource.Start();
videoSource.NewFrame += videoSource_NewFrame;
}

return videoSource != null && videoSource.IsRunning;
}

public bool OpenVideoSource()
{
return IsCameraOpen || OpenVideoSource(Camera);
}

public void CloseCurrentVideoSource()
{
if (videoSource != null)
{
videoSource.NewFrame -= videoSource_NewFrame;
videoSource.SignalToStop();

// wait ~ 3 seconds
for (int i = 0; i < 30; i++)
// wait ~5 seconds
for (int i = 0; i < 50; i++)
{
if (!videoSource.IsRunning)
break;
Expand Down Expand Up @@ -225,15 +247,36 @@ private void sldcircle_ValueChanged(object sender, RoutedPropertyChangedEventArg

private void btnMove_Click(object sender, RoutedEventArgs e)
{
MoveOffset?.Invoke(Mode, XOffset, YOffset);
if (!AppConfig.Settings.Camera.ConfirmMove || MessageBox.Show(UIUtils.TryFindParent<Window>(this), (string)FindResource(MoveCameraToSpindlePosition ? "MoveCameraTo" : "MoveSpindleTo"), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
if (MoveCameraToSpindlePosition)
{
MoveCameraToSpindlePosition = false;
MoveOffset?.Invoke(Mode, -XOffset, -YOffset);
}
else
MoveOffset?.Invoke(Mode, XOffset, YOffset);
}
}

private void btnPublish_Click(object sender, RoutedEventArgs e)
{
Position pos = new Position(Grbl.GrblViewModel.MachinePosition);

pos.X += XOffset;
pos.Y += YOffset;

Grbl.GrblViewModel.CameraProbed(pos);
}

private void cbxCamera_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(((ComboBox)sender).IsDropDownOpen)
if(((ComboBox)sender).IsDropDownOpen && e.AddedItems.Count == 1)
{
CloseCurrentVideoSource();
OpenVideoSource();
OpenVideoSource(e.AddedItems[0] as FilterInfo);
AppConfig.Settings.Camera.SelectedCamera = (e.AddedItems[0] as FilterInfo).MonikerString;
AppConfig.Settings.Save();
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions CNC Controls Camera/CNC Controls Camera/ConfigControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
xmlns:local="clr-namespace:CNC.Controls.Camera"
xmlns:Controls="clr-namespace:CNC.Controls;assembly=CNC.Controls.WPF" x:Class="CNC.Controls.Camera.ConfigControl"
mc:Ignorable="d"
d:DesignHeight="140" d:DesignWidth="250">
d:DesignHeight="160" d:DesignWidth="250">
<GroupBox x:Uid="grp_camera" x:Name="grpCamera" Header="Camera" HorizontalAlignment="Left" VerticalAlignment="Top" Height="Auto" Width="250">
<StackPanel HorizontalAlignment="Left" Height="115" Margin="0,3,0,0" VerticalAlignment="Top" Width="235">
<StackPanel HorizontalAlignment="Left" Height="Auto" Margin="0,3,0,0" VerticalAlignment="Top" Width="235">
<CheckBox x:Uid="chk_moveToSpindle" Content="Inital move to spindle" IsChecked="{Binding Path=Camera.InitialMoveToSpindle, Mode=TwoWay}" Margin="90,0,0,0"/>
<CheckBox x:Uid="chk_confirmMove" Content="Confirm move" IsChecked="{Binding Path=Camera.ConfirmMove, Mode=TwoWay}" Margin="90,0,0,0"/>
<Controls:NumericField x:Uid="fld_xOffset" x:Name="xOffset" Label="X offset:" ColonAt="90" Value="{Binding Path=Camera.XOffset, Mode=TwoWay}"/>
<Controls:NumericField x:Uid="fld_yOffset" x:Name="yOffset" Label="Y offset:" ColonAt="90" Value="{Binding Path=Camera.YOffset, Mode=TwoWay}"/>
<Grid Height="29">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
// 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("2.0.35.0")]
[assembly: AssemblyFileVersion("2.0.35.0")]
[assembly: AssemblyVersion("2.0.37.0")]
[assembly: AssemblyFileVersion("2.0.37.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<system:String x:Uid="str_centerFinderClearance" x:Key="Clearance">Probing XY clearance too large for workpiece {0} size.</system:String>
<system:String x:Uid="str_centerFinderFailed" x:Key="ProbingFailed">Probing failed</system:String>
<system:String x:Uid="str_centerFinderCompleted" x:Key="ProbingCompleted">Probing completed: X distance {0}, Y distance {1}.</system:String>
<system:String x:Uid="str_positionsRequired" x:Key="PositionsRequired">{0} probe positions are required.</system:String>
<Controls:MultiLineConverter x:Key="ErrorMessageConverter" />
<Controls:LogicalNotConverter x:Key="IsNotRunningConverter" />
<Controls:BoolToVisibleConverter x:Key="ToVisibleConverter" />
Expand Down Expand Up @@ -88,6 +89,7 @@
<StackPanel Margin="5,0,0,5" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="Auto" Width="Auto">
<Button x:Uid="btn_start" Content="Start" IsEnabled="{Binding Path=Grbl.IsJobRunning, Converter={StaticResource IsNotRunningConverter}}" Margin="2,0" Width="75" Click="start_Click"/>
<Button x:Uid="btn_stop" Content="Stop" IsEnabled="{Binding Path=Grbl.IsJobRunning}" Margin="2,0" Width="75" Click="stop_Click"/>
<Button x:Uid="btn_useCamera" Content="Use camera positions" IsEnabled="{Binding Path=CanApplyTransform}" Margin="2,0" Padding="4,0" Click="camera_Click"/>
</StackPanel>
<CheckBox x:Uid="lbl_preview" Content="Preview" Margin="365,10,0,0" IsChecked="{Binding Path=PreviewEnable}"/>
<GroupBox x:Uid="grp_preview" Header="Preview" Margin="365,30,0,0" Visibility="{Binding Path=PreviewEnable, Converter={StaticResource ToVisibleConverter}}" VerticalAlignment="Top">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* CenterFinderControl.xaml.cs - part of CNC Probing library
*
* v0.36 / 2021-12-01 / Io Engineering (Terje Io)
* v0.37 / 2022-02-21 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020-2021, Io Engineering (Terje Io)
Copyright (c) 2020-2022, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -74,9 +74,53 @@ public CenterFinderControl()

public ProbingType ProbingType { get { return ProbingType.CenterFinder; } }

public void Activate()
public void Activate(bool activate)
{
(DataContext as ProbingViewModel).Instructions = ((string)FindResource("Instructions")).Replace("\\n", "\n");
var probing = DataContext as ProbingViewModel;

if (activate)
{
probing.Instructions = ((string)FindResource("Instructions")).Replace("\\n", "\n");
probing.PropertyChanged += Probing_PropertyChanged;
} else
probing.PropertyChanged -= Probing_PropertyChanged;
}

private void Probing_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ProbingViewModel.CameraPositions))
{
var probing = DataContext as ProbingViewModel;
bool ok = probing.CameraPositions <= 1 || !probing.Positions[probing.CameraPositions - 1].Equals(probing.Positions[probing.CameraPositions - 2]);

if(ok) switch (probing.CameraPositions)
{
case 2:
if(mode == FindMode.Y)
ok = probing.Positions[1].X == probing.Positions[0].X && probing.Positions[1].Y > probing.Positions[0].Y;
else
ok = probing.Positions[1].X > probing.Positions[0].X && probing.Positions[1].Y == probing.Positions[0].Y;
break;

case 3:
ok = !probing.Positions[2].Equals(probing.Positions[0]) && probing.Positions[2].X != probing.Positions[1].X;
break;

case 4:
ok = !probing.Positions[3].Equals(probing.Positions[0]) &&
!probing.Positions[3].Equals(probing.Positions[1]) &&
probing.Positions[3].X == probing.Positions[2].X &&
probing.Positions[3].Y > probing.Positions[2].Y;
break;
}

if (!ok)
{
MessageBox.Show(LibStrings.FindResource("IllegalPosition"), "ioSender", MessageBoxButton.OK, MessageBoxImage.Exclamation);
probing.RemoveLastPosition();
} else
probing.CanApplyTransform = probing.CameraPositions == (mode == FindMode.XY ? 4 : 2);
}
}

private bool CreateProgram(bool preview)
Expand Down Expand Up @@ -378,6 +422,25 @@ private void start_Click(object sender, RoutedEventArgs e)
Start((DataContext as ProbingViewModel).PreviewEnable);
}

private void camera_Click(object sender, RoutedEventArgs e)
{
var probing = DataContext as ProbingViewModel;

if (probing.ProbeCenter == Center.None)
{
MessageBox.Show((string)FindResource("SelectType"), "Center finder", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}

if (probing.Positions.Count == (mode == FindMode.XY ? 4 : 2))
{
probing.IsSuccess = true;
OnCompleted();
probing.Positions.Clear();
probing.CanApplyTransform = probing.PreviewEnable = false;
}
}

private void stop_Click(object sender, RoutedEventArgs e)
{
Stop();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* EdgeFinderControl.xaml.cs - part of CNC Probing library
*
* v0.36 / 2021-12-01 / Io Engineering (Terje Io)
* v0.37 / 2022-02-21 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020-2021, Io Engineering (Terje Io)
Copyright (c) 2020-2022, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -78,9 +78,10 @@ public EdgeFinderControl()

public ProbingType ProbingType { get { return ProbingType.EdgeFinderExternal; } }

public void Activate()
public void Activate(bool activate)
{
(DataContext as ProbingViewModel).Instructions = ((string)FindResource("Instructions")).Replace("\\n", "\n");
if(activate)
(DataContext as ProbingViewModel).Instructions = ((string)FindResource("Instructions")).Replace("\\n", "\n");
}

public void Start(bool preview = false)
Expand Down
Loading

0 comments on commit 696f941

Please sign in to comment.