Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag&Drop to open files, added hotkeys to change JogStep #937

Merged
merged 4 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LaserGRBL/AutoUpdate/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GPLv3 General Public License for more details.
// You should have received a copy of the GPLv3 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. using System;

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

Expand Down
11 changes: 8 additions & 3 deletions LaserGRBL/GrblCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public object Clone()

public UsageStats.UsageCounters UsageCounters;

public GrblCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform)
public GrblCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform, JogForm jogform)
{
if (Type != Firmware.Grbl) Logger.LogMessage("Program", "Load {0} core", Type);

Expand Down Expand Up @@ -292,7 +292,7 @@ public GrblCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform)

if (!Settings.ExistObject("Hotkey Setup")) Settings.SetObject("Hotkey Setup", new HotKeysManager());
mHotKeyManager = (HotKeysManager)Settings.GetObject("Hotkey Setup", null);
mHotKeyManager.Init(this, cbform);
mHotKeyManager.Init(this, cbform, jogform);

UsageCounters = new UsageStats.UsageCounters();

Expand Down Expand Up @@ -470,6 +470,7 @@ public void ReOpenFile(System.Windows.Forms.Form parent)
}

public static readonly System.Collections.Generic.List<string> ImageExtensions = new System.Collections.Generic.List<string>(new string[] { ".jpg", ".bmp", ".png", ".gif" });
public static readonly System.Collections.Generic.List<string> GCodeExtensions = new System.Collections.Generic.List<string>(new string[] { ".nc", ".cnc", ".tap", ".gcode", ".ngc" });
public void OpenFile(System.Windows.Forms.Form parent, string filename = null, bool append = false)
{
if (!CanLoadNewFile) return;
Expand Down Expand Up @@ -518,7 +519,7 @@ public void OpenFile(System.Windows.Forms.Form parent, string filename = null, b
catch (Exception ex)
{ Logger.LogException("SvgImport", ex); }
}
else //load GCODE file
else if (GCodeExtensions.Contains(System.IO.Path.GetExtension(filename).ToLowerInvariant())) //load GCODE file
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

Expand All @@ -532,6 +533,10 @@ public void OpenFile(System.Windows.Forms.Form parent, string filename = null, b

System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
else
{
System.Windows.Forms.MessageBox.Show(Strings.UnsupportedFiletype, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
Expand Down
62 changes: 41 additions & 21 deletions LaserGRBL/HotKeysManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class HotKeysManager : List<HotKeysManager.HotKey>
{
[NonSerialized] private GrblCore mCore;
[NonSerialized] private PreviewForm mPreviewForm;
[NonSerialized] List<int> mCustomButtonPressed;
[NonSerialized] private JogForm mJogForm;
[NonSerialized] List<int> mCustomButtonPressed;
[NonSerialized] private bool mJogKeyRequested = false;

[Serializable]
Expand All @@ -30,6 +31,7 @@ public enum Actions
HelpOnline = 30,
Reset = 100, Homing = 101, Unlock = 102, PauseJob = 103, ResumeJob = 104, SetNewZero = 105,
JogHome = 1000, JogN = 1001, JogNE = 1002, JogE = 1003, JogSE = 1004, JogS = 1005, JogSW = 1006, JogW = 1007, JogNW = 1008, JogUp = 1009, JogDown = 1010,
JogStepIncrease = 1020, JogStepDecrease = 1021,
OverridePowerDefault = 1100, OverridePowerUp = 1101, OverridePowerDown = 1102,
OverrideLinearDefault = 1110, OverrideLinearUp = 1111, OverrideLinearDown = 1112,
OverrideRapidDefault = 1120, OverrideRapidUp = 1121, OverrideRapidDown = 1122,
Expand Down Expand Up @@ -133,7 +135,10 @@ private void AddAllFeatures()
AddNew(new HotKey(HotKey.Actions.JogUp, (Keys)107));
AddNew(new HotKey(HotKey.Actions.JogDown, (Keys)109));

AddNew(new HotKey(HotKey.Actions.OverridePowerDefault, Keys.None));
AddNew(new HotKey(HotKey.Actions.JogStepIncrease, Keys.Multiply));
AddNew(new HotKey(HotKey.Actions.JogStepDecrease, Keys.Divide));

AddNew(new HotKey(HotKey.Actions.OverridePowerDefault, Keys.None));
AddNew(new HotKey(HotKey.Actions.OverridePowerUp, Keys.None));
AddNew(new HotKey(HotKey.Actions.OverridePowerDown, Keys.None));

Expand Down Expand Up @@ -166,10 +171,11 @@ private void AddNew(HotKey toadd)
Add(toadd);
}

public void Init(GrblCore core, PreviewForm cbform)
public void Init(GrblCore core, PreviewForm cbform, JogForm jogform)
{
mCore = core;
mPreviewForm = cbform;
mJogForm = jogform;
mCustomButtonPressed = new List<int>();
AddAllFeatures();
Sort(CompareKey);
Expand Down Expand Up @@ -259,13 +265,19 @@ private bool PerformAction(HotKey.Actions action)
case HotKey.Actions.JogW:
RequestJog(GrblCore.JogDirection.W); break;
case HotKey.Actions.JogNW:
RequestJog(GrblCore.JogDirection.NW); break;
case HotKey.Actions.JogUp:
RequestJog(GrblCore.JogDirection.Zup); break;
case HotKey.Actions.JogDown:
RequestJog(GrblCore.JogDirection.Zdown); break;
case HotKey.Actions.OverridePowerDefault:
case HotKey.Actions.OverridePowerUp:
RequestJog(GrblCore.JogDirection.NW); break;
case HotKey.Actions.JogUp:
RequestJog(GrblCore.JogDirection.Zup); break;
case HotKey.Actions.JogDown:
RequestJog(GrblCore.JogDirection.Zdown); break;
case HotKey.Actions.JogStepIncrease:
ChangeJogStep(true);
break;
case HotKey.Actions.JogStepDecrease:
ChangeJogStep(false);
break;
case HotKey.Actions.OverridePowerDefault:
case HotKey.Actions.OverridePowerUp:
case HotKey.Actions.OverridePowerDown:
case HotKey.Actions.OverrideLinearDefault:
case HotKey.Actions.OverrideLinearUp:
Expand All @@ -275,27 +287,27 @@ private bool PerformAction(HotKey.Actions action)
case HotKey.Actions.OverrideRapidDown:
mCore.HotKeyOverride(action); break;
case HotKey.Actions.CustomButton1:
EmulateCustomButtonDown(0); break;
EmulateCustomButtonDown(0); break;
case HotKey.Actions.CustomButton2:
EmulateCustomButtonDown(1); break;
EmulateCustomButtonDown(1); break;
case HotKey.Actions.CustomButton3:
EmulateCustomButtonDown(2); break;
EmulateCustomButtonDown(2); break;
case HotKey.Actions.CustomButton4:
EmulateCustomButtonDown(3); break;
EmulateCustomButtonDown(3); break;
case HotKey.Actions.CustomButton5:
EmulateCustomButtonDown(4); break;
EmulateCustomButtonDown(4); break;
case HotKey.Actions.CustomButton6:
EmulateCustomButtonDown(5); break;
EmulateCustomButtonDown(5); break;
case HotKey.Actions.CustomButton7:
EmulateCustomButtonDown(6); break;
EmulateCustomButtonDown(6); break;
case HotKey.Actions.CustomButton8:
EmulateCustomButtonDown(7); break;
EmulateCustomButtonDown(7); break;
case HotKey.Actions.CustomButton9:
EmulateCustomButtonDown(8); break;
EmulateCustomButtonDown(8); break;
case HotKey.Actions.CustomButton10:
EmulateCustomButtonDown(9); break;
EmulateCustomButtonDown(9); break;
default:
break;
break;
}

//ConnectDisconnect = 10, Connect = 11, Disconnect = 12,
Expand All @@ -308,6 +320,14 @@ private bool PerformAction(HotKey.Actions action)
return true;
}

private void ChangeJogStep(bool increase)
{
if (mCore.JogEnabled)
{
mJogForm.ChangeJogStepIndexBy(increase ? 1 : -1);
}
}

private void RequestJog(GrblCore.JogDirection dir)
{
mJogKeyRequested = true;
Expand Down
11 changes: 10 additions & 1 deletion LaserGRBL/JogForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ private void TbStep_ValueChanged(object sender, EventArgs e)
needsave = true;
}

bool needsave = false;
public void ChangeJogStepIndexBy(int value)
{
TbStep.ChangeIndexBy(value);
}

bool needsave = false;
private void OnSliderMouseUP(object sender, MouseEventArgs e)
{
if (needsave)
Expand Down Expand Up @@ -140,6 +145,10 @@ public StepBar()
}
}

public void ChangeIndexBy(int value)
{
CurIndex = Math.Max(Math.Min(CurIndex + value, Maximum), Minimum);
}
}


Expand Down
3 changes: 3 additions & 0 deletions LaserGRBL/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 48 additions & 5 deletions LaserGRBL/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Threading;

namespace LaserGRBL
{
Expand Down Expand Up @@ -34,11 +35,11 @@ public MainForm()
//build main communication object
Firmware ftype = (Firmware)Settings.GetObject("Firmware Type", Firmware.Grbl);
if (ftype == Firmware.Smoothie)
Core = new SmoothieCore(this, PreviewForm);
Core = new SmoothieCore(this, PreviewForm, JogForm);
else if (ftype == Firmware.Marlin)
Core = new MarlinCore(this, PreviewForm);
Core = new MarlinCore(this, PreviewForm, JogForm);
else
Core = new GrblCore(this, PreviewForm);
Core = new GrblCore(this, PreviewForm, JogForm);

ExceptionManager.Core = Core;

Expand Down Expand Up @@ -607,10 +608,52 @@ private void activateExtendedLogToolStripMenuItem_Click(object sender, EventArgs
ComWrapper.ComLogger.FileName = null;
}
}
}

private DispatcherTimer dropDispatcherTimer;
private string droppedFile;

public class MMnRenderer : ToolStripProfessionalRenderer
private void MainForm_DragEnter(object sender, DragEventArgs e)
{
if (droppedFile == null)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
}

private void MainForm_DragDrop(object sender, DragEventArgs e)
{
if (droppedFile == null)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length == 1)
{
droppedFile = files[0];

// call via DispatcherTimer to unblock the source of the drag-event (e.g. Explorer-Window)
if (dropDispatcherTimer == null)
{
this.dropDispatcherTimer = new DispatcherTimer();
this.dropDispatcherTimer.Interval = TimeSpan.FromSeconds(0.5);
this.dropDispatcherTimer.Tick += new EventHandler(dropDispatcherTimer_Tick);
}
this.dropDispatcherTimer.Start();
}
}
}

void dropDispatcherTimer_Tick(object sender, EventArgs e)
{
if (this.droppedFile != null)
{
Core.OpenFile(this, this.droppedFile);
this.droppedFile = null;
dropDispatcherTimer.Stop();
}
}
}


public class MMnRenderer : ToolStripProfessionalRenderer
{
public MMnRenderer() : base(new CustomMenuColor()) { }

Expand Down
22 changes: 11 additions & 11 deletions LaserGRBL/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
<value>70, 18</value>
</data>
<data name="TTLEstimated.Size" type="System.Drawing.Size, System.Drawing">
<value>96, 19</value>
<value>95, 19</value>
</data>
<data name="TTLEstimated.Text" xml:space="preserve">
<value>Estimated Time:</value>
Expand All @@ -295,7 +295,7 @@
<value>unknown</value>
</data>
<data name="spring1.Size" type="System.Drawing.Size, System.Drawing">
<value>421, 19</value>
<value>422, 19</value>
</data>
<data name="TTOvS.AutoSize" type="System.Boolean, mscorlib">
<value>False</value>
Expand Down Expand Up @@ -1188,7 +1188,7 @@
<value>False</value>
</data>
<data name="toolsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>47, 20</value>
<value>46, 20</value>
</data>
<data name="toolsToolStripMenuItem.Text" xml:space="preserve">
<value>&amp;Tools</value>
Expand Down Expand Up @@ -1216,19 +1216,19 @@
</value>
</data>
<data name="helpOnLineToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 22</value>
<value>189, 22</value>
</data>
<data name="helpOnLineToolStripMenuItem.Text" xml:space="preserve">
<value>Help on line</value>
</data>
<data name="autoUpdateToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 22</value>
<value>189, 22</value>
</data>
<data name="autoUpdateToolStripMenuItem.Text" xml:space="preserve">
<value>Auto update</value>
</data>
<data name="toolStripMenuItem5.Size" type="System.Drawing.Size, System.Drawing">
<value>185, 6</value>
<value>186, 6</value>
</data>
<data name="openSessionLogToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand All @@ -1248,19 +1248,19 @@
</value>
</data>
<data name="openSessionLogToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 22</value>
<value>189, 22</value>
</data>
<data name="openSessionLogToolStripMenuItem.Text" xml:space="preserve">
<value>Open session log</value>
</data>
<data name="activateExtendedLogToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 22</value>
<value>189, 22</value>
</data>
<data name="activateExtendedLogToolStripMenuItem.Text" xml:space="preserve">
<value>Activate extended log</value>
</data>
<data name="toolStripMenuItem7.Size" type="System.Drawing.Size, System.Drawing">
<value>185, 6</value>
<value>186, 6</value>
</data>
<data name="donateToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand All @@ -1276,7 +1276,7 @@
</value>
</data>
<data name="donateToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 22</value>
<value>189, 22</value>
</data>
<data name="donateToolStripMenuItem.Text" xml:space="preserve">
<value>Donate!</value>
Expand All @@ -1303,7 +1303,7 @@
</value>
</data>
<data name="aboutToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 22</value>
<value>189, 22</value>
</data>
<data name="aboutToolStripMenuItem.Text" xml:space="preserve">
<value>Web Site</value>
Expand Down
2 changes: 1 addition & 1 deletion LaserGRBL/MarlinCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace LaserGRBL
{
public class MarlinCore : GrblCore
{
public MarlinCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform) : base(syncroObject, cbform)
public MarlinCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform, JogForm jogform) : base(syncroObject, cbform, jogform)
{
}

Expand Down
Loading