Skip to content

Commit

Permalink
Release 2.0.45
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Dec 12, 2024
1 parent 614115d commit 40bccef
Show file tree
Hide file tree
Showing 99 changed files with 1,607 additions and 902 deletions.
26 changes: 13 additions & 13 deletions CNC Controls Dragknife/DragknifeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* DragKnifeViewModel.cs - part of CNC Controls DragKnife library for Grbl
*
* v0.40 / 2022-07-12 / Io Engineering (Terje Io)
* v0.45 / 2024-10-11 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2020-2021, Io Engineering (Terje Io)
Copyright (c) 2020-2024, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -159,8 +159,8 @@ private void Transform (List<segment> polyLine, List<GCodeToken> newToolPath)
if (i == 0)
{
end = prev.P1 + n1 * _knifeTipOffset;
newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(end), AxisFlags.XY));
newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(end + new Vector3(0d, 0d, _cutDepth)), AxisFlags.Z));
newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(end), AxisFlags.XY, false));
newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(end + new Vector3(0d, 0d, _cutDepth)), AxisFlags.Z, false));
}

if (Math.Abs(angle) > (i == 0 ? 1d : _swivelAngle) && cp2.Magnitude >= _dentLength)
Expand All @@ -171,19 +171,19 @@ private void Transform (List<segment> polyLine, List<GCodeToken> newToolPath)
StartDirection = dir;
end = end1;
var arcdir = n1.X * n2.Y - n1.Y * n2.X;
newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(end), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, 0, IJKMode.Incremental));
newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(end), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, 0, IJKMode.Incremental, false));
}
if (cp2.Magnitude > _knifeTipOffset)
end = polyLine[i].P2 + n2 * _knifeTipOffset;
else
end += cp2;

newToolPath.Add(new GCLinearMotion((i & 1) == 1 ? Commands.G1 : Commands.G1, lnr++, ToPos(end), AxisFlags.XY));
newToolPath.Add(new GCLinearMotion((i & 1) == 1 ? Commands.G1 : Commands.G1, lnr++, ToPos(end), AxisFlags.XY, false));
prev = polyLine[i];

if (i == polyLine.Count - 1)
{
newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(end + new Vector3(0d, 0d, -_cutDepth)), AxisFlags.Z));
newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(end + new Vector3(0d, 0d, -_cutDepth)), AxisFlags.Z, false));
}
}
}
Expand Down Expand Up @@ -219,26 +219,26 @@ private void Transformx(List<segment> polyLine, List<GCodeToken> newToolPath)
if (i == 0)
{
// start = StartDirection * _knifeTipOffset;
newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(start), AxisFlags.XY));
newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(start + new Vector3(0d, 0d, _cutDepth)), AxisFlags.Z));
newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(start), AxisFlags.XY, false));
newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(start + new Vector3(0d, 0d, _cutDepth)), AxisFlags.Z, false));
}
// else

newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(end), AxisFlags.XY));
newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(end), AxisFlags.XY, false));

if (Math.Abs(ad) > _swivelAngle && cp2.Magnitude >= _dentLength)
{
var arcdir = n1.X * n2.Y - n1.Y * n2.X;
// newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(polyLine[i + 1].P1 + offset2), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, IJKMode.Incremental));
//newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(polyLine[i].P1 + offset2), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, IJKMode.Incremental));
newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(polyLine[i + 1].P1 + offset2), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, 0, IJKMode.Incremental));
newToolPath.Add(new GCArc(arcdir < 0d ? Commands.G2 : Commands.G3, lnr++, ToPos(polyLine[i + 1].P1 + offset2), AxisFlags.XY, ToPos(dir), IJKFlags.I | IJKFlags.J, 0d, 0, IJKMode.Incremental, false));
}

}
if (i == polyLine.Count - 1)
{
newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(polyLine[i].P2 + offset2), AxisFlags.XY));
newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(polyLine[i].P2 + offset2 + new Vector3(0d, 0d, -_cutDepth)), AxisFlags.Z));
newToolPath.Add(new GCLinearMotion(Commands.G1, lnr++, ToPos(polyLine[i].P2 + offset2), AxisFlags.XY, false));
newToolPath.Add(new GCLinearMotion(Commands.G0, lnr++, ToPos(polyLine[i].P2 + offset2 + new Vector3(0d, 0d, -_cutDepth)), AxisFlags.Z, false));
// StartDirection = dir;
}
// newToolPath.Add(new GCLinearMotion(Commands.G1, (uint)i, new double[] { polyLine[i].P2.X, polyLine[i].P2.Y, polyLine[i].P2.Z }, AxisFlags.XY));
Expand Down
6 changes: 3 additions & 3 deletions CNC Controls Dragknife/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Io Engineering")]
[assembly: AssemblyProduct("ioSender")]
[assembly: AssemblyCopyright("Copyright © 2021 Io Engineering")]
[assembly: AssemblyCopyright("Copyright © 2024 Io Engineering")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
Expand Down 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.45.0")]
[assembly: AssemblyFileVersion("2.0.45.0")]
85 changes: 73 additions & 12 deletions CNC Controls Lathe/CNC Controls Lathe/TaperControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*
* TaperControl.xaml.cs - part of CNC Controls library
*
* v0.45 / 2024-04-21 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2019-2024, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
· Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
· Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
· Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
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.Navigation;
using System.Windows.Shapes;

namespace CNC.Controls.Lathe
{
Expand All @@ -20,17 +48,50 @@ namespace CNC.Controls.Lathe
/// </summary>
public partial class TaperControl : UserControl
{
public Action<double> OnValueChanged;
public Action<bool> OnTaperEnabledChanged;

public TaperControl()
{
InitializeComponent();

data.TextChanged += Data_TextChanged;
chkTaper.Checked += ChkTaper_Checked;
chkTaper.Unchecked += ChkTaper_Checked;
}

private void ChkTaper_Checked(object sender, RoutedEventArgs e)
{
OnTaperEnabledChanged?.Invoke(chkTaper.IsChecked == true);
}

private void Data_TextChanged(object sender, TextChangedEventArgs e)
{
OnValueChanged?.Invoke(double.IsNaN(Value) ? 0d : Value);
}

// public string Format { get { return data.Format; } }


public static readonly DependencyProperty IsTaperEnabledProperty = DependencyProperty.Register(nameof(IsTaperEnabled), typeof(bool), typeof(TaperControl), new PropertyMetadata(/*"Label:" , new PropertyChangedCallback(OnLabelChanged)*/));
public bool IsTaperEnabled
{
get { return (bool)GetValue(IsTaperEnabledProperty); }
set { SetValue(IsTaperEnabledProperty, value); }
}

public static readonly DependencyProperty FormatProperty = DependencyProperty.Register(nameof(Format), typeof(string), typeof(TaperControl), new PropertyMetadata("##0", new PropertyChangedCallback(OnFormatChanged)));
public string Format
{
get { return (string)GetValue(FormatProperty); }
set { SetValue(FormatProperty, value); }
}

private static void OnFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((TaperControl)d).data.Format = (string)e.NewValue;
}

public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(double), typeof(TaperControl), new PropertyMetadata(/*"Label:" , new PropertyChangedCallback(OnLabelChanged)*/));
public double Value
{
Expand Down
23 changes: 18 additions & 5 deletions CNC Controls Lathe/CNC Controls Lathe/TurningLogic.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* TurningLogic.cs - part of CNC Controls Lathe library
*
* v0.43 / 2023-06-03 / Io Engineering (Terje Io)
* v0.45 / 2024-04-21 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2019-2023, Io Engineering (Terje Io)
Copyright (c) 2019-2024, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -133,8 +133,15 @@ public void Calculate()
PassCalc cut = new PassCalc(xdistance, passdepth, passdepth_last, model.Precision);

if (model.IsTaperEnabled)
{
if (model.Taper >= 90d)
{
model.SetError(nameof(model.Taper), "Error: taper cannot be >= 90 deg.");
return;
}
angle = Math.Tan(Math.PI * model.Taper / 180.0d);

model.ZLength = (xtarget - diameter) / angle * model.config.ZDirection;
}
// error.Clear();

if (cut.Passes < 1)
Expand Down Expand Up @@ -170,15 +177,19 @@ public void Calculate()
// TODO: G0 to prev target to keep spindle speed constant?
// if (css)
// code[i++] = string.Format("G0 X{0}", model.FormatValue(doc_prev));
model.gCode.Add(string.Format("G1 X{0} F{1}", model.FormatValue(xtarget), model.FormatValue(feedrate)));
if (angle != 0.0d)
{
ztarget = cut.Distance / angle * model.config.ZDirection;
model.gCode.Add(string.Format("G1 X{0} F{1}", model.FormatValue(xtarget -= model.config.ZClearance / model.UnitFactor * angle), model.FormatValue(feedrate)));
model.gCode.Add(string.Format("G1 X{0} Z{1}", model.FormatValue(diameter), model.FormatValue(zstart + ztarget)));
model.gCode.Add(string.Format("G0 X{0}", model.FormatValue(diameter + xclearance)));
}
else
{
model.gCode.Add(string.Format("G1 X{0} F{1}", model.FormatValue(xtarget), model.FormatValue(feedrate)));
model.gCode.Add(string.Format("G1 Z{0} F{1}", model.FormatValue(ztarget), model.FormatValue(feedrate)));
model.gCode.Add(string.Format("G0 X{0}", model.FormatValue(xtarget + xclearance)));
model.gCode.Add(string.Format("G0 X{0}", model.FormatValue(xtarget + xclearance)));
}
model.gCode.Add(string.Format("G0 Z{0}", model.FormatValue(zstart + model.config.ZClearance / model.UnitFactor)));

} while (++pass <= cut.Passes);
Expand All @@ -190,6 +201,8 @@ public void Calculate()
GCode.File.AddBlock(string.Format("(Passdepth: {0}, Feedrate: {1}, {2}: {3})",
model.FormatValue(passdepth), model.FormatValue(model.FeedRate),
(model.IsCssEnabled ? "CSS" : "RPM"), model.FormatValue((double)model.CssSpeed)), Core.Action.Add);
if (angle != 0.0d)
GCode.File.AddBlock(string.Format("(Taper length: {0})", model.FormatValue(model.ZLength)));

foreach (string s in model.gCode)
GCode.File.AddBlock(s, Core.Action.Add);
Expand Down
7 changes: 4 additions & 3 deletions CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
xmlns:local="clr-namespace:CNC.Controls.Lathe"
xmlns:Controls="clr-namespace:CNC.Controls;assembly=CNC.Controls.WPF" x:Class="CNC.Controls.Lathe.TurningWizard"
xmlns:Converters="clr-namespace:CNC.Controls.Lathe"
mc:Ignorable="d"
d:DesignHeight="515" d:DesignWidth="875">
mc:Ignorable="d"
d:DesignHeight="515" d:DesignWidth="875"
Loaded="TurningWizard_Load">
<UserControl.Resources>
<Controls:StringCollectionToTextConverter x:Key="GCodeConverter"/>
<Controls:MultiLineConverter x:Key="ErrorMessageConverter" />
Expand Down Expand Up @@ -55,7 +56,7 @@
<Controls:NumericField x:Name="cvTargetX" Label="Target" Value="{Binding Path=XTarget, Mode=TwoWay}" Style="{StaticResource CNCValue}"/>
<Controls:NumericField x:Name="cvClearanceX" Label="Clearance" Value="{Binding Path=XClearance, Mode=TwoWay}" Style="{StaticResource CNCValue}"/>
</StackPanel>
<local:TaperControl x:Name="taper" Value="{Binding Taper, Mode=TwoWay}" IsTaperEnabled="{Binding IsTaperEnabled, Mode=TwoWay}" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" ToolTip="Degrees from centerline."/>
<local:TaperControl x:Name="taper" Value="{Binding Taper, Mode=TwoWay}" Format="#0.##" IsTaperEnabled="{Binding IsTaperEnabled, Mode=TwoWay}" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" ToolTip="Degrees from centerline."/>
</StackPanel>
</GroupBox>
<GroupBox x:Name="groupBox2" Header="Cut depths and feed rates" HorizontalAlignment="Left" Margin="10,185,0,0" VerticalAlignment="Top" Height="95" Width="585">
Expand Down
38 changes: 35 additions & 3 deletions CNC Controls Lathe/CNC Controls Lathe/TurningWizard.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* TurningWizard.xaml.cs - part of CNC Controls library
*
* v0.31 / 2021-04-27 / Io Engineering (Terje Io)
* v0.45 / 2024-04-21 / Io Engineering (Terje Io)
*
*/

/*
Copyright (c) 2019-2021, Io Engineering (Terje Io)
Copyright (c) 2019-2024, Io Engineering (Terje Io)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -41,6 +41,7 @@ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
using System.Collections.ObjectModel;
using System.Windows.Controls;
using CNC.Core;
using CNC.GCode;

namespace CNC.Controls.Lathe
{
Expand All @@ -50,7 +51,7 @@ namespace CNC.Controls.Lathe
public partial class TurningWizard : UserControl, ICNCView
{
private bool initOk = false, resetProfileBindings = true;
private double last_rpm = 0d, last_css = 0d;
private double last_rpm = 0d, last_css = 0d, length = 0d;
private BaseViewModel model;
private TurningLogic logic = new TurningLogic();

Expand All @@ -74,6 +75,8 @@ void TurningWizard_Load(object sender, EventArgs e)

//UIUtils.GroupBoxCaptionBold(groupBox1);
//UIUtils.GroupBoxCaptionBold(groupBox2);
taper.OnValueChanged += taperChanged;
taper.OnTaperEnabledChanged += taperEnabled;
}

public ObservableCollection<string> gCode { get; private set; }
Expand Down Expand Up @@ -120,10 +123,39 @@ public void Setup(UIViewModel model, AppConfig profile)
#endregion
public void InitUI()
{

}

public WizardConfig config { get; private set; }

private void taperEnabled (bool enabled)
{
if (enabled)
length = cvLength.Value;
else
cvLength.Value = length;

cvLength.IsEnabled = !enabled;
}

private void taperChanged (double angle)
{
if(taper.IsTaperEnabled && angle != 0d && Math.Abs(model.XStart - model.XTarget) != 0.0d)
{
double xtarget = model.XTarget;
double diameter = model.XStart;

if (model.config.xmode == LatheMode.Radius)
{
xtarget /= 2.0d;
diameter /= 2.0d;
}

//bool boring = (xtarget - diameter) > 0.0d; ??
cvLength.Value = (xtarget - diameter) / Math.Tan(Math.PI * angle / 180.0d) * model.config.ZDirection;
}
}

private void btnCalculate_Click(object sender, System.Windows.RoutedEventArgs e)
{
logic.Calculate();
Expand Down
Loading

0 comments on commit 40bccef

Please sign in to comment.