-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginForm.vb
237 lines (176 loc) · 6.31 KB
/
PluginForm.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
Imports System.Threading
Imports System.Windows.Forms
Friend Class PluginForm
Private UC As Plugininterface.Entry
Dim PluginMain As UCCNCplugin
Friend WithEvents Settings As Settings
Dim MustClose As Boolean = False
Dim WheelDelta As Integer = 120
Dim zpos As Double = 0
Dim stp As Double = 0.0001
Dim direction As Direction = Direction.X
Dim deftbcolor As Drawing.Color
Public Sub New(CallerPluginMain As UCCNCplugin)
Me.UC = CallerPluginMain.UC
Me.PluginMain = CallerPluginMain
InitializeComponent()
End Sub
Public Shared Sub Main()
End Sub
Private Sub PluginForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
WheelDelta = SystemInformation.MouseWheelScrollDelta
deftbcolor = BTN_Settings.BackColor
LoadSettings()
updateLabels()
End Sub
Public Sub LoadSettings() Handles Settings.SettingsChanged
Me.Settings = Me.PluginMain.Settings
If Me.Settings.imperial Then
BTN_00001.Visible = True
BTN_1.Visible = False
If stp >= 1 Then stp = 0.1
Else
BTN_00001.Visible = False
BTN_1.Visible = True
If stp = 0.0001 Then stp = 0.001
End If
updateLabels()
End Sub
Private Sub PluginForm_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
' Do not close the form when the red X button is pressed
' But start a Thread which will stop the Loop call from the UCCNC
' to prevent the form closing while there is a GUI update in the Loop event
If Not MustClose Then
e.Cancel = True
Dim thrClose As New Thread(Sub() Closeform())
thrClose.CurrentCulture = Thread.CurrentThread.CurrentCulture ' Preserve regional settings
thrClose.Start()
Else
' Form is closing here...
End If
End Sub
Delegate Sub CloseformDeletage()
Public Sub Closeform()
If Me.InvokeRequired Then
Me.Invoke(New CloseformDeletage(AddressOf Closeform))
Return
End If
' Stop the Loop event to update the GUI
PluginMain.LoopStop = True
' Wait until the loop exited
While (PluginMain.LoopWorking)
Thread.Sleep(10)
End While
' Set the mustclose variable to true and call the .Close() function to close the Form
MustClose = True
Me.Close()
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub PictureBox1_MouseWheel(sender As Object, e As MouseEventArgs)
End Sub
Private Sub PluginForm_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel
End Sub
Private Sub jog(steps As Integer)
Dim dist As Double = steps * stp
UC.AddLinearMoveRel(CInt(direction), stp, Math.Abs(steps), Settings.feedrate, steps < 0)
updateLabels()
End Sub
Delegate Sub DebugWriteLineDelegate(text As String)
Sub DebugWriteLine(text As String)
If (Me.InvokeRequired) Then
Me.Invoke(New DebugWriteLineDelegate(AddressOf DebugWriteLine), text)
Return
End If
txt_Debug.AppendText(text & vbNewLine)
End Sub
Private Sub updateLabels()
BTN_00001.BackColor = deftbcolor
BTN_0001.BackColor = deftbcolor
BTN_001.BackColor = deftbcolor
BTN_01.BackColor = deftbcolor
BTN_1.BackColor = deftbcolor
BTN_X.BackColor = deftbcolor
BTN_Y.BackColor = deftbcolor
BTN_Z.BackColor = deftbcolor
If stp = 0.0001 Then
BTN_00001.BackColor = Drawing.Color.Green
End If
If stp = 0.001 Then
BTN_0001.BackColor = Drawing.Color.Green
End If
If stp = 0.01 Then
BTN_001.BackColor = Drawing.Color.Green
End If
If stp = 0.1 Then
BTN_01.BackColor = Drawing.Color.Green
End If
If stp = 1 Then
BTN_1.BackColor = Drawing.Color.Green
End If
If direction = Direction.X Then
BTN_X.BackColor = Drawing.Color.Green
End If
If direction = Direction.Y Then
BTN_Y.BackColor = Drawing.Color.Green
End If
If direction = Direction.Z Then
BTN_Z.BackColor = Drawing.Color.Green
End If
End Sub
Private Sub BTN_X_Click(sender As Object, e As EventArgs) Handles BTN_X.Click
direction = Direction.X
updateLabels()
End Sub
Private Sub BTN_y_Click(sender As Object, e As EventArgs) Handles BTN_Y.Click
direction = Direction.Y
updateLabels()
End Sub
Private Sub BTN_z_Click(sender As Object, e As EventArgs) Handles BTN_Z.Click
direction = Direction.Z
updateLabels()
End Sub
Private Sub BTN_00001_Click(sender As Object, e As EventArgs) Handles BTN_00001.Click
stp = 0.0001
updateLabels()
End Sub
Private Sub BTN_0001_Click(sender As Object, e As EventArgs) Handles BTN_0001.Click
stp = 0.001
updateLabels()
End Sub
Private Sub BTN_001_Click(sender As Object, e As EventArgs) Handles BTN_001.Click
stp = 0.01
updateLabels()
End Sub
Private Sub BTN_01_Click(sender As Object, e As EventArgs) Handles BTN_01.Click
stp = 0.1
updateLabels()
End Sub
Private Sub BTN_1_Click(sender As Object, e As EventArgs) Handles BTN_1.Click
stp = 1
updateLabels()
End Sub
Private Sub MPG_BOX_Click(sender As Object, e As EventArgs) Handles MPG_BOX.Click
End Sub
Private Sub MPG_BOX_MouseWheel(sender As Object, e As MouseEventArgs) Handles MPG_BOX.MouseWheel
Dim steps As Integer = e.Delta / WheelDelta
jog(steps)
End Sub
Private Sub PluginForm_Activated(sender As Object, e As EventArgs) Handles Me.Activated
LoadSettings()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles BTN_Settings.Click
Dim f = New ConfigForm(Me.PluginMain)
f.ShowDialog()
LoadSettings()
End Sub
End Class
Public Enum Direction
X
Y
Z
End Enum
Public Class Move
Property direction As Direction
Property distance As Double
End Class