From 19e93d1035db7f2213f514d43d009abb5822eb3e Mon Sep 17 00:00:00 2001 From: arkypita Date: Tue, 21 Nov 2017 22:42:38 +0100 Subject: [PATCH] Min-Max from config + negative offset --- LaserGRBL/GrblCore.cs | 4 +- .../ConvertSizeAndOptionForm.Designer.cs | 2 + .../ConvertSizeAndOptionForm.cs | 63 ++++++++++++------- .../ConvertSizeAndOptionForm.resx | 22 +++---- .../RasterConverter/RasterToLaserForm.cs | 9 +-- .../RasterConverter/ResolutionHelperForm.cs | 4 +- .../IntegerInput/IntegerInputBase.cs | 54 ++++++---------- .../IntegerInput/IntegerInputRanged.cs | 2 +- 8 files changed, 84 insertions(+), 76 deletions(-) diff --git a/LaserGRBL/GrblCore.cs b/LaserGRBL/GrblCore.cs index f38401303..5b217098b 100644 --- a/LaserGRBL/GrblCore.cs +++ b/LaserGRBL/GrblCore.cs @@ -1935,10 +1935,10 @@ public decimal ResolutionY { get { return ReadWithDefault(Version9 ? 101 : 1, 250); } } public decimal TableWidth - { get { return ReadWithDefault(Version9 ? 130 : -1, 200); } } + { get { return ReadWithDefault(Version9 ? 130 : -1, 3000); } } public decimal TableHeight - { get { return ReadWithDefault(Version9 ? 131 : -1, 300); } } + { get { return ReadWithDefault(Version9 ? 131 : -1, 2000); } } private decimal ReadWithDefault(int number, decimal defval) diff --git a/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.Designer.cs b/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.Designer.cs index ef1972b9e..6c97abc8c 100644 --- a/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.Designer.cs +++ b/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.Designer.cs @@ -195,6 +195,7 @@ private void InitializeComponent() this.IISizeH.MinValue = 10; this.IISizeH.Name = "IISizeH"; this.IISizeH.NormalBorderColor = System.Drawing.SystemColors.ActiveBorder; + this.IISizeH.OnTheFlyValueChanged += new LaserGRBL.UserControls.IntegerInput.IntegerInputBase.CurrentValueChangedEventHandler(this.IISizeH_OnTheFlyValueChanged); this.IISizeH.CurrentValueChanged += new LaserGRBL.UserControls.IntegerInput.IntegerInputBase.CurrentValueChangedEventHandler(this.IISizeH_CurrentValueChanged); // // IISizeW @@ -206,6 +207,7 @@ private void InitializeComponent() this.IISizeW.MinValue = 10; this.IISizeW.Name = "IISizeW"; this.IISizeW.NormalBorderColor = System.Drawing.SystemColors.ActiveBorder; + this.IISizeW.OnTheFlyValueChanged += new LaserGRBL.UserControls.IntegerInput.IntegerInputBase.CurrentValueChangedEventHandler(this.IISizeW_OnTheFlyValueChanged); this.IISizeW.CurrentValueChanged += new LaserGRBL.UserControls.IntegerInput.IntegerInputBase.CurrentValueChangedEventHandler(this.IISizeW_CurrentValueChanged); // // label6 diff --git a/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.cs b/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.cs index 1a1465e7e..0333811f7 100644 --- a/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.cs +++ b/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.cs @@ -17,20 +17,34 @@ namespace LaserGRBL.RasterConverter /// public partial class ConvertSizeAndOptionForm : Form { + GrblCore mCore; bool supportPWM = (bool)Settings.GetObject("Support Hardware PWM", true); - public ConvertSizeAndOptionForm() + public ConvertSizeAndOptionForm(GrblCore core) { - // - // The InitializeComponent() call is required for Windows Forms designer support. - // InitializeComponent(); + mCore = core; BackColor = ColorScheme.FormBackColor; GbLaser.ForeColor = GbSize.ForeColor = GbSpeed.ForeColor = ForeColor = ColorScheme.FormForeColor; BtnCancel.BackColor = BtnCreate.BackColor = ColorScheme.FormButtonsColor; LblSmin.Visible = LblSmax.Visible = IIMaxPower.Visible = IIMinPower.Visible = BtnModulationInfo.Visible = supportPWM; + AssignMinMaxLimit(); + } + + private void AssignMinMaxLimit() + { + IISizeW.MaxValue = (int)mCore.Configuration.TableWidth; + IISizeH.MaxValue = (int)mCore.Configuration.TableHeight; + + IIOffsetX.MaxValue = (int)mCore.Configuration.TableWidth; + IIOffsetY.MaxValue = (int)mCore.Configuration.TableHeight; + IIOffsetX.MinValue = -(int)mCore.Configuration.TableWidth; + IIOffsetY.MinValue = -(int)mCore.Configuration.TableHeight; + + IIBorderTracing.MaxValue = IILinearFilling.MaxValue = IITravelSpeed.MaxValue = (int)mCore.Configuration.MaxRateX; + IIMaxPower.MaxValue = (int)mCore.Configuration.MaxPWM; } ImageProcessor IP; @@ -82,50 +96,44 @@ public void ShowDialog(ImageProcessor processor) ShowDialog(); } - - - private void IISizeW_CurrentValueChanged(object sender, int NewValue, bool ByUser) + + + private void IISizeW_CurrentValueChanged(object sender, int OldValue, int NewValue, bool ByUser) { - if (ByUser) - IISizeH.CurrentValue = IP.WidthToHeight(NewValue); - IP.TargetSize = new Size(IISizeW.CurrentValue, IISizeH.CurrentValue); } - private void IISizeH_CurrentValueChanged(object sender, int NewValue, bool ByUser) + private void IISizeH_CurrentValueChanged(object sender, int OldValue, int NewValue, bool ByUser) { - if (ByUser) - IISizeW.CurrentValue = IP.HeightToWidht(NewValue); - IP.TargetSize = new Size(IISizeW.CurrentValue, IISizeH.CurrentValue); } - void IIOffsetXYCurrentValueChanged(object sender, int NewValue, bool ByUser) + void IIOffsetXYCurrentValueChanged(object sender, int OldValue, int NewValue, bool ByUser) { IP.TargetOffset = new Point(IIOffsetX.CurrentValue, IIOffsetY.CurrentValue); } - - void IIBorderTracingCurrentValueChanged(object sender, int NewValue, bool ByUser) + + void IIBorderTracingCurrentValueChanged(object sender, int OldValue, int NewValue, bool ByUser) { IP.BorderSpeed = NewValue; } - - void IIMarkSpeedCurrentValueChanged(object sender, int NewValue, bool ByUser) + + void IIMarkSpeedCurrentValueChanged(object sender, int OldValue, int NewValue, bool ByUser) { IP.MarkSpeed = NewValue; } - void IITravelSpeedCurrentValueChanged(object sender, int NewValue, bool ByUser) + void IITravelSpeedCurrentValueChanged(object sender, int OldValue, int NewValue, bool ByUser) { IP.TravelSpeed = NewValue; } - void IIMinPowerCurrentValueChanged(object sender, int NewValue, bool ByUser) + void IIMinPowerCurrentValueChanged(object sender, int OldValue, int NewValue, bool ByUser) { if (ByUser && IIMaxPower.CurrentValue <= NewValue) IIMaxPower.CurrentValue = NewValue + 1; IP.MinPower = NewValue; } - void IIMaxPowerCurrentValueChanged(object sender, int NewValue, bool ByUser) + void IIMaxPowerCurrentValueChanged(object sender, int OldValue, int NewValue, bool ByUser) { if (ByUser && IIMinPower.CurrentValue >= NewValue) IIMinPower.CurrentValue = NewValue - 1; @@ -152,6 +160,17 @@ private void CBLaserOFF_SelectedIndexChanged(object sender, EventArgs e) { IP.LaserOff = (string)CBLaserOFF.SelectedItem; } + + private void IISizeW_OnTheFlyValueChanged(object sender, int OldValue, int NewValue, bool ByUser) + { + if (ByUser) + IISizeH.CurrentValue = IP.WidthToHeight(NewValue); + } + + private void IISizeH_OnTheFlyValueChanged(object sender, int OldValue, int NewValue, bool ByUser) + { + if (ByUser) IISizeW.CurrentValue = IP.HeightToWidht(NewValue); + } } } diff --git a/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.resx b/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.resx index 2b49b64b0..d80f0d8c8 100644 --- a/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.resx +++ b/LaserGRBL/RasterConverter/ConvertSizeAndOptionForm.resx @@ -229,7 +229,7 @@ IIOffsetX - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel3 @@ -253,7 +253,7 @@ IIOffsetY - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel3 @@ -277,7 +277,7 @@ IISizeH - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel3 @@ -301,7 +301,7 @@ IISizeW - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel3 @@ -622,7 +622,7 @@ IIBorderTracing - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel6 @@ -715,7 +715,7 @@ IILinearFilling - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel6 @@ -742,7 +742,7 @@ IITravelSpeed - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel6 @@ -928,7 +928,7 @@ Click for more information... BtnModulationInfo - LaserGRBL.UserControls.ImageButton, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.ImageButton, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel7 @@ -1018,7 +1018,7 @@ Click for more information... IIMinPower - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel7 @@ -1075,7 +1075,7 @@ Click for more information... IIMaxPower - LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.IntegerInput.IntegerInputRanged, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel7 @@ -1154,7 +1154,7 @@ Click for more information... BtnOnOffInfo - LaserGRBL.UserControls.ImageButton, LaserGRBL, Version=2.7.6.0, Culture=neutral, PublicKeyToken=null + LaserGRBL.UserControls.ImageButton, LaserGRBL, Version=2.8.19.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel7 diff --git a/LaserGRBL/RasterConverter/RasterToLaserForm.cs b/LaserGRBL/RasterConverter/RasterToLaserForm.cs index fbe7d7831..a41e7e22e 100644 --- a/LaserGRBL/RasterConverter/RasterToLaserForm.cs +++ b/LaserGRBL/RasterConverter/RasterToLaserForm.cs @@ -9,14 +9,15 @@ namespace LaserGRBL.RasterConverter { public partial class RasterToLaserForm : Form { + GrblCore mCore; ImageProcessor IP; bool preventClose; - bool supportPWM = (bool)Settings.GetObject("Support Hardware PWM", true); private RasterToLaserForm(GrblCore core, string filename) { InitializeComponent(); + mCore = core; BackColor = ColorScheme.FormBackColor; GbConversionTool.ForeColor = GbLineToLineOptions.ForeColor = GbParameters.ForeColor = GbVectorizeOptions.ForeColor = ForeColor = ColorScheme.FormForeColor; @@ -141,7 +142,7 @@ void GoodInput(object sender, KeyPressEventArgs e) void BtnCreateClick(object sender, EventArgs e) { - using (ConvertSizeAndOptionForm f = new ConvertSizeAndOptionForm()) + using (ConvertSizeAndOptionForm f = new ConvertSizeAndOptionForm(mCore)) { f.ShowDialog(IP); if (f.DialogResult == DialogResult.OK) @@ -596,13 +597,13 @@ private void CbDither_SelectedIndexChanged(object sender, EventArgs e) private void BtnQualityInfo_Click(object sender, EventArgs e) { - UDQuality.Value = (decimal)ResolutionHelperForm.CreateAndShowDialog((double)UDQuality.Value); + UDQuality.Value = (decimal)ResolutionHelperForm.CreateAndShowDialog(mCore, (double)UDQuality.Value); //System.Diagnostics.Process.Start(@"http://lasergrbl.com/usage/raster-image-import/setting-reliable-resolution/"); } private void BtnFillingQualityInfo_Click(object sender, EventArgs e) { - UDFillingQuality.Value = (decimal)ResolutionHelperForm.CreateAndShowDialog((double)UDFillingQuality.Value); + UDFillingQuality.Value = (decimal)ResolutionHelperForm.CreateAndShowDialog(mCore, (double)UDFillingQuality.Value); //System.Diagnostics.Process.Start(@"http://lasergrbl.com/usage/raster-image-import/setting-reliable-resolution/"); } diff --git a/LaserGRBL/RasterConverter/ResolutionHelperForm.cs b/LaserGRBL/RasterConverter/ResolutionHelperForm.cs index 937c17ae7..48eef5f65 100644 --- a/LaserGRBL/RasterConverter/ResolutionHelperForm.cs +++ b/LaserGRBL/RasterConverter/ResolutionHelperForm.cs @@ -22,14 +22,14 @@ public ResolutionHelperForm() BtnCancel.BackColor = BtnCreate.BackColor = ColorScheme.FormButtonsColor; } - public static double CreateAndShowDialog(double oldval) + public static double CreateAndShowDialog(GrblCore Core, double oldval) { double rv = oldval; using (ResolutionHelperForm f = new ResolutionHelperForm()) { f.UDDesired.Value = (decimal)oldval; - f.UDHardware.Value = (decimal)Settings.GetObject("Hardware Resolution", 100.0m); + f.UDHardware.Value = Core.Configuration.ResolutionX; f.Compute(null, null); if (f.ShowDialog() == DialogResult.OK) diff --git a/LaserGRBL/UserControls/IntegerInput/IntegerInputBase.cs b/LaserGRBL/UserControls/IntegerInput/IntegerInputBase.cs index 946136624..9d90bd703 100644 --- a/LaserGRBL/UserControls/IntegerInput/IntegerInputBase.cs +++ b/LaserGRBL/UserControls/IntegerInput/IntegerInputBase.cs @@ -44,10 +44,11 @@ private void InitializeComponent() this.TB.Name = "TB"; this.TB.Size = new System.Drawing.Size(77, 13); this.TB.TabIndex = 0; - this.TB.KeyDown += TB_KeyDown; + this.TB.KeyDown += TBKeyDown; this.TB.KeyPress += TBKeyPress; this.TB.GotFocus += FocusEvent; this.TB.LostFocus += FocusEvent; + this.TB.TextChanged += TBTextChanged; // //LB // @@ -69,36 +70,14 @@ private void InitializeComponent() this.PerformLayout(); } - - //protected System.Windows.Forms.TextBox TB { - // get { return withEventsField_TB; } - // set { - // if (withEventsField_TB != null) { - // withEventsField_TB.KeyDown -= TB_KeyDown; - // withEventsField_TB.KeyPress -= TBKeyPress; - // withEventsField_TB.MouseWheel -= TBWheel; - // withEventsField_TB.GotFocus -= FocusEvent; - // withEventsField_TB.LostFocus -= FocusEvent; - // } - // withEventsField_TB = value; - // if (withEventsField_TB != null) { - // withEventsField_TB.KeyDown += TB_KeyDown; - // withEventsField_TB.KeyPress += TBKeyPress; - // withEventsField_TB.MouseWheel += TBWheel; - // withEventsField_TB.GotFocus += FocusEvent; - // withEventsField_TB.LostFocus += FocusEvent; - // } - // } - //} internal System.Windows.Forms.TextBox TB; internal System.Windows.Forms.Label LB; - public event CurrentValueChangedEventHandler CurrentValueChanged; - public delegate void CurrentValueChangedEventHandler(object sender, int NewValue, bool ByUser); //ok - public event CurrentValueChanged1EventHandler CurrentValueChanged1; - public delegate void CurrentValueChanged1EventHandler(object sender, int OldValue, int NewValue, bool ByUser); + public event CurrentValueChangedEventHandler OnTheFlyValueChanged; + public event CurrentValueChangedEventHandler CurrentValueChanged; + public delegate void CurrentValueChangedEventHandler(object sender, int OldValue, int NewValue, bool ByUser); //ok public event BeginEditEventHandler BeginEdit; @@ -199,12 +178,8 @@ private void SetCurrentValue(int value, bool byuser) _CurrentValue = value; _ForcedText = null; UpdateStatus(); - if (CurrentValueChanged != null) { - CurrentValueChanged(this, value, byuser); - } - if (CurrentValueChanged1 != null) { - CurrentValueChanged1(this, O, value, byuser); - } + if (CurrentValueChanged != null) + CurrentValueChanged(this, O, value, byuser); } } } @@ -224,7 +199,7 @@ public bool InEdit { get { return TB.ContainsFocus; } } - private void TB_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) + private void TBKeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == System.Windows.Forms.Keys.Enter) { @@ -242,11 +217,22 @@ protected virtual void TBKeyPress(object sender, System.Windows.Forms.KeyPressEv e.Handled = !AcceptKeys(e.KeyChar); } + void TBTextChanged(object sender, EventArgs e) + { + try + { + int newValue = ParseEditValue(); + if (OnTheFlyValueChanged != null) + OnTheFlyValueChanged(this, OldEditValue, newValue, InEdit); + } + catch { } + } + protected virtual bool AcceptKeys(char key) { System.Globalization.CultureInfo CI = System.Globalization.CultureInfo.CurrentCulture; - return char.IsDigit(key) | char.IsControl(key) | key.ToString() == CI.NumberFormat.NegativeSign; + return char.IsDigit(key) || char.IsControl(key) || key.ToString() == CI.NumberFormat.NegativeSign; } private void FocusEvent(object sender, System.EventArgs e) diff --git a/LaserGRBL/UserControls/IntegerInput/IntegerInputRanged.cs b/LaserGRBL/UserControls/IntegerInput/IntegerInputRanged.cs index e56bdea10..0750e3c09 100644 --- a/LaserGRBL/UserControls/IntegerInput/IntegerInputRanged.cs +++ b/LaserGRBL/UserControls/IntegerInput/IntegerInputRanged.cs @@ -174,7 +174,7 @@ protected override void UpdateStatus() protected override bool AcceptKeys(char key) { System.Globalization.CultureInfo CI = System.Globalization.CultureInfo.CurrentCulture; - return char.IsDigit(key) | char.IsControl(key) | key.ToString() == CI.NumberFormat.NumberDecimalSeparator | (key.ToString() == CI.NumberFormat.NegativeSign & MinValue < 0); + return char.IsDigit(key) || char.IsControl(key) || key.ToString() == CI.NumberFormat.NumberDecimalSeparator || (key.ToString() == CI.NumberFormat.NegativeSign & MinValue < 0); }