Skip to content

Commit e2d3a2e

Browse files
authored
Merge pull request #937 from falias4/master
Drag&Drop to open files, added hotkeys to change JogStep
2 parents ba10b94 + fe91d98 commit e2d3a2e

File tree

11 files changed

+138
-43
lines changed

11 files changed

+138
-43
lines changed

LaserGRBL/AutoUpdate/GitHub.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// 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.
55
// 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;
66

7+
using System;
78
using System.Collections.Generic;
89
using System.Text.RegularExpressions;
910

LaserGRBL/GrblCore.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public object Clone()
258258

259259
public UsageStats.UsageCounters UsageCounters;
260260

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

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

293293
if (!Settings.ExistObject("Hotkey Setup")) Settings.SetObject("Hotkey Setup", new HotKeysManager());
294294
mHotKeyManager = (HotKeysManager)Settings.GetObject("Hotkey Setup", null);
295-
mHotKeyManager.Init(this, cbform);
295+
mHotKeyManager.Init(this, cbform, jogform);
296296

297297
UsageCounters = new UsageStats.UsageCounters();
298298

@@ -470,6 +470,7 @@ public void ReOpenFile(System.Windows.Forms.Form parent)
470470
}
471471

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

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

533534
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
534535
}
536+
else
537+
{
538+
System.Windows.Forms.MessageBox.Show(Strings.UnsupportedFiletype, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
539+
}
535540
}
536541
}
537542
catch (Exception ex)

LaserGRBL/HotKeysManager.cs

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public class HotKeysManager : List<HotKeysManager.HotKey>
1717
{
1818
[NonSerialized] private GrblCore mCore;
1919
[NonSerialized] private PreviewForm mPreviewForm;
20-
[NonSerialized] List<int> mCustomButtonPressed;
20+
[NonSerialized] private JogForm mJogForm;
21+
[NonSerialized] List<int> mCustomButtonPressed;
2122
[NonSerialized] private bool mJogKeyRequested = false;
2223

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

136-
AddNew(new HotKey(HotKey.Actions.OverridePowerDefault, Keys.None));
138+
AddNew(new HotKey(HotKey.Actions.JogStepIncrease, Keys.Multiply));
139+
AddNew(new HotKey(HotKey.Actions.JogStepDecrease, Keys.Divide));
140+
141+
AddNew(new HotKey(HotKey.Actions.OverridePowerDefault, Keys.None));
137142
AddNew(new HotKey(HotKey.Actions.OverridePowerUp, Keys.None));
138143
AddNew(new HotKey(HotKey.Actions.OverridePowerDown, Keys.None));
139144

@@ -166,10 +171,11 @@ private void AddNew(HotKey toadd)
166171
Add(toadd);
167172
}
168173

169-
public void Init(GrblCore core, PreviewForm cbform)
174+
public void Init(GrblCore core, PreviewForm cbform, JogForm jogform)
170175
{
171176
mCore = core;
172177
mPreviewForm = cbform;
178+
mJogForm = jogform;
173179
mCustomButtonPressed = new List<int>();
174180
AddAllFeatures();
175181
Sort(CompareKey);
@@ -259,13 +265,19 @@ private bool PerformAction(HotKey.Actions action)
259265
case HotKey.Actions.JogW:
260266
RequestJog(GrblCore.JogDirection.W); break;
261267
case HotKey.Actions.JogNW:
262-
RequestJog(GrblCore.JogDirection.NW); break;
263-
case HotKey.Actions.JogUp:
264-
RequestJog(GrblCore.JogDirection.Zup); break;
265-
case HotKey.Actions.JogDown:
266-
RequestJog(GrblCore.JogDirection.Zdown); break;
267-
case HotKey.Actions.OverridePowerDefault:
268-
case HotKey.Actions.OverridePowerUp:
268+
RequestJog(GrblCore.JogDirection.NW); break;
269+
case HotKey.Actions.JogUp:
270+
RequestJog(GrblCore.JogDirection.Zup); break;
271+
case HotKey.Actions.JogDown:
272+
RequestJog(GrblCore.JogDirection.Zdown); break;
273+
case HotKey.Actions.JogStepIncrease:
274+
ChangeJogStep(true);
275+
break;
276+
case HotKey.Actions.JogStepDecrease:
277+
ChangeJogStep(false);
278+
break;
279+
case HotKey.Actions.OverridePowerDefault:
280+
case HotKey.Actions.OverridePowerUp:
269281
case HotKey.Actions.OverridePowerDown:
270282
case HotKey.Actions.OverrideLinearDefault:
271283
case HotKey.Actions.OverrideLinearUp:
@@ -275,27 +287,27 @@ private bool PerformAction(HotKey.Actions action)
275287
case HotKey.Actions.OverrideRapidDown:
276288
mCore.HotKeyOverride(action); break;
277289
case HotKey.Actions.CustomButton1:
278-
EmulateCustomButtonDown(0); break;
290+
EmulateCustomButtonDown(0); break;
279291
case HotKey.Actions.CustomButton2:
280-
EmulateCustomButtonDown(1); break;
292+
EmulateCustomButtonDown(1); break;
281293
case HotKey.Actions.CustomButton3:
282-
EmulateCustomButtonDown(2); break;
294+
EmulateCustomButtonDown(2); break;
283295
case HotKey.Actions.CustomButton4:
284-
EmulateCustomButtonDown(3); break;
296+
EmulateCustomButtonDown(3); break;
285297
case HotKey.Actions.CustomButton5:
286-
EmulateCustomButtonDown(4); break;
298+
EmulateCustomButtonDown(4); break;
287299
case HotKey.Actions.CustomButton6:
288-
EmulateCustomButtonDown(5); break;
300+
EmulateCustomButtonDown(5); break;
289301
case HotKey.Actions.CustomButton7:
290-
EmulateCustomButtonDown(6); break;
302+
EmulateCustomButtonDown(6); break;
291303
case HotKey.Actions.CustomButton8:
292-
EmulateCustomButtonDown(7); break;
304+
EmulateCustomButtonDown(7); break;
293305
case HotKey.Actions.CustomButton9:
294-
EmulateCustomButtonDown(8); break;
306+
EmulateCustomButtonDown(8); break;
295307
case HotKey.Actions.CustomButton10:
296-
EmulateCustomButtonDown(9); break;
308+
EmulateCustomButtonDown(9); break;
297309
default:
298-
break;
310+
break;
299311
}
300312

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

323+
private void ChangeJogStep(bool increase)
324+
{
325+
if (mCore.JogEnabled)
326+
{
327+
mJogForm.ChangeJogStepIndexBy(increase ? 1 : -1);
328+
}
329+
}
330+
311331
private void RequestJog(GrblCore.JogDirection dir)
312332
{
313333
mJogKeyRequested = true;

LaserGRBL/JogForm.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ private void TbStep_ValueChanged(object sender, EventArgs e)
8181
needsave = true;
8282
}
8383

84-
bool needsave = false;
84+
public void ChangeJogStepIndexBy(int value)
85+
{
86+
TbStep.ChangeIndexBy(value);
87+
}
88+
89+
bool needsave = false;
8590
private void OnSliderMouseUP(object sender, MouseEventArgs e)
8691
{
8792
if (needsave)
@@ -140,6 +145,10 @@ public StepBar()
140145
}
141146
}
142147

148+
public void ChangeIndexBy(int value)
149+
{
150+
CurIndex = Math.Max(Math.Min(CurIndex + value, Maximum), Minimum);
151+
}
143152
}
144153

145154

LaserGRBL/MainForm.Designer.cs

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LaserGRBL/MainForm.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Drawing;
99
using System.Windows.Forms;
10+
using System.Windows.Threading;
1011

1112
namespace LaserGRBL
1213
{
@@ -34,11 +35,11 @@ public MainForm()
3435
//build main communication object
3536
Firmware ftype = (Firmware)Settings.GetObject("Firmware Type", Firmware.Grbl);
3637
if (ftype == Firmware.Smoothie)
37-
Core = new SmoothieCore(this, PreviewForm);
38+
Core = new SmoothieCore(this, PreviewForm, JogForm);
3839
else if (ftype == Firmware.Marlin)
39-
Core = new MarlinCore(this, PreviewForm);
40+
Core = new MarlinCore(this, PreviewForm, JogForm);
4041
else
41-
Core = new GrblCore(this, PreviewForm);
42+
Core = new GrblCore(this, PreviewForm, JogForm);
4243

4344
ExceptionManager.Core = Core;
4445

@@ -607,10 +608,52 @@ private void activateExtendedLogToolStripMenuItem_Click(object sender, EventArgs
607608
ComWrapper.ComLogger.FileName = null;
608609
}
609610
}
610-
}
611611

612+
private DispatcherTimer dropDispatcherTimer;
613+
private string droppedFile;
612614

613-
public class MMnRenderer : ToolStripProfessionalRenderer
615+
private void MainForm_DragEnter(object sender, DragEventArgs e)
616+
{
617+
if (droppedFile == null)
618+
{
619+
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
620+
}
621+
}
622+
623+
private void MainForm_DragDrop(object sender, DragEventArgs e)
624+
{
625+
if (droppedFile == null)
626+
{
627+
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
628+
if (files.Length == 1)
629+
{
630+
droppedFile = files[0];
631+
632+
// call via DispatcherTimer to unblock the source of the drag-event (e.g. Explorer-Window)
633+
if (dropDispatcherTimer == null)
634+
{
635+
this.dropDispatcherTimer = new DispatcherTimer();
636+
this.dropDispatcherTimer.Interval = TimeSpan.FromSeconds(0.5);
637+
this.dropDispatcherTimer.Tick += new EventHandler(dropDispatcherTimer_Tick);
638+
}
639+
this.dropDispatcherTimer.Start();
640+
}
641+
}
642+
}
643+
644+
void dropDispatcherTimer_Tick(object sender, EventArgs e)
645+
{
646+
if (this.droppedFile != null)
647+
{
648+
Core.OpenFile(this, this.droppedFile);
649+
this.droppedFile = null;
650+
dropDispatcherTimer.Stop();
651+
}
652+
}
653+
}
654+
655+
656+
public class MMnRenderer : ToolStripProfessionalRenderer
614657
{
615658
public MMnRenderer() : base(new CustomMenuColor()) { }
616659

LaserGRBL/MainForm.resx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
<value>70, 18</value>
284284
</data>
285285
<data name="TTLEstimated.Size" type="System.Drawing.Size, System.Drawing">
286-
<value>96, 19</value>
286+
<value>95, 19</value>
287287
</data>
288288
<data name="TTLEstimated.Text" xml:space="preserve">
289289
<value>Estimated Time:</value>
@@ -295,7 +295,7 @@
295295
<value>unknown</value>
296296
</data>
297297
<data name="spring1.Size" type="System.Drawing.Size, System.Drawing">
298-
<value>421, 19</value>
298+
<value>422, 19</value>
299299
</data>
300300
<data name="TTOvS.AutoSize" type="System.Boolean, mscorlib">
301301
<value>False</value>
@@ -1188,7 +1188,7 @@
11881188
<value>False</value>
11891189
</data>
11901190
<data name="toolsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
1191-
<value>47, 20</value>
1191+
<value>46, 20</value>
11921192
</data>
11931193
<data name="toolsToolStripMenuItem.Text" xml:space="preserve">
11941194
<value>&amp;Tools</value>
@@ -1216,19 +1216,19 @@
12161216
</value>
12171217
</data>
12181218
<data name="helpOnLineToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
1219-
<value>188, 22</value>
1219+
<value>189, 22</value>
12201220
</data>
12211221
<data name="helpOnLineToolStripMenuItem.Text" xml:space="preserve">
12221222
<value>Help on line</value>
12231223
</data>
12241224
<data name="autoUpdateToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
1225-
<value>188, 22</value>
1225+
<value>189, 22</value>
12261226
</data>
12271227
<data name="autoUpdateToolStripMenuItem.Text" xml:space="preserve">
12281228
<value>Auto update</value>
12291229
</data>
12301230
<data name="toolStripMenuItem5.Size" type="System.Drawing.Size, System.Drawing">
1231-
<value>185, 6</value>
1231+
<value>186, 6</value>
12321232
</data>
12331233
<data name="openSessionLogToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
12341234
<value>
@@ -1248,19 +1248,19 @@
12481248
</value>
12491249
</data>
12501250
<data name="openSessionLogToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
1251-
<value>188, 22</value>
1251+
<value>189, 22</value>
12521252
</data>
12531253
<data name="openSessionLogToolStripMenuItem.Text" xml:space="preserve">
12541254
<value>Open session log</value>
12551255
</data>
12561256
<data name="activateExtendedLogToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
1257-
<value>188, 22</value>
1257+
<value>189, 22</value>
12581258
</data>
12591259
<data name="activateExtendedLogToolStripMenuItem.Text" xml:space="preserve">
12601260
<value>Activate extended log</value>
12611261
</data>
12621262
<data name="toolStripMenuItem7.Size" type="System.Drawing.Size, System.Drawing">
1263-
<value>185, 6</value>
1263+
<value>186, 6</value>
12641264
</data>
12651265
<data name="donateToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
12661266
<value>
@@ -1276,7 +1276,7 @@
12761276
</value>
12771277
</data>
12781278
<data name="donateToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
1279-
<value>188, 22</value>
1279+
<value>189, 22</value>
12801280
</data>
12811281
<data name="donateToolStripMenuItem.Text" xml:space="preserve">
12821282
<value>Donate!</value>
@@ -1303,7 +1303,7 @@
13031303
</value>
13041304
</data>
13051305
<data name="aboutToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
1306-
<value>188, 22</value>
1306+
<value>189, 22</value>
13071307
</data>
13081308
<data name="aboutToolStripMenuItem.Text" xml:space="preserve">
13091309
<value>Web Site</value>

LaserGRBL/MarlinCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace LaserGRBL
1313
{
1414
public class MarlinCore : GrblCore
1515
{
16-
public MarlinCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform) : base(syncroObject, cbform)
16+
public MarlinCore(System.Windows.Forms.Control syncroObject, PreviewForm cbform, JogForm jogform) : base(syncroObject, cbform, jogform)
1717
{
1818
}
1919

0 commit comments

Comments
 (0)