-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathg-code_ripper-016.py
More file actions
6282 lines (5405 loc) · 278 KB
/
g-code_ripper-016.py
File metadata and controls
6282 lines (5405 loc) · 278 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
"""
g-code_ripper G-Code-Ripper
Copyright (C) <2018> <Scorch>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Version 0.01 Initial code
Version 0.02 - Added feed rate scaling
- Eliminated read abort on N codes (the N code line numbers are simply ignored now)
Version 0.03 - Added ability to map X or Y axis moves to A or B rotary axis for cutting on a cylindrical surface.
- Added more plot view orientation options
Version 0.04 - Fixed bug relating to arcs without explicit g-codes (G2,G3) on each line
- Added ability to have zero decimal places on feed rates
Version 0.05 - Added "Export" to the g-code operations. Now g-code tool path data can be exported as DXF
or CSV (Comma Separated Values) formatted files. With or without rapid motions.
Version 0.06 - Fixed code to again automatically convert arcs to lines when raping code (auto conversion was broken in V0.5)
- Fixed evaluation of equations using exponents "**"
- Added Auto Probe to g-code operations
Version 0.07 - Fixed bug in "Auto Probe" that caused an error when the Z offset is set to zero.
- Modified code to make it compatible with Python 2.5
Version 0.08 - Fixed bug in g-code wrapping resulting in mapping failure resulting from to zero length tool path.
- Added logic for dealing with ambiguous start positions (when the tool position is not set by G0 commands before a G1, G2 or G3 command)
- Added a warning pop-up message when assumptions are made about the tool starting position.
- Fixed automatic conversion from arcs to lines when required by conversion type selected.
Version 0.09 - Increased default decimal places to 1 for the feed rate. The adjusted feed rates for
g-code mapped to a cylinder were being rounded to the nearest integer resulting in
unpredictable cutting speeds.
- Added the ability to save and read probe data files for auto-probing.
Version 0.10 - Updated to be compatible with Python 3.x
Version 0.11 - Fixed a minor bug that cause a failed file read in rare cases (tries to calculate square root of negative number)
Version 0.12 - Updated the probe data file reading routine to be less sensitive to file formating
- Fixed error in probe Z offsets when using an external probe data file
Version 0.13 - Changed "Probe & Cut" to add the "Probe Z Safe" value to the height of the rapid moves ensuring the tool does not crash
- Fixed a bug in the conversion of arcs to lines when the arc spanned more than one Z value.
Version 0.14 - Added dialog that allows users to skip over errors when reading g-code files
- Fixed bug that prevented the feed rate to return to the input value after a rapid move in a split file until a G1 command was issued
- Fixed bug that resulted in the feed rate being scaled at the z axis scale value
- Fixed variable handling for some cases
Version 0.16 - Added support for MACH4 auto-probing
- Added pass through for G43 values
- Fixed bug in splitting code
"""
version = '0.16'
import sys
VERSION = sys.version_info[0]
if VERSION == 3:
from tkinter import *
from tkinter.filedialog import *
import tkinter.messagebox
else:
from Tkinter import *
from tkFileDialog import *
import tkMessageBox
if VERSION < 3 and sys.version_info[1] < 6:
def next(item):
return item.next()
try:
import psyco
psyco.full()
sys.stdout.write("(Psyco loaded)\n")
except:
pass
from math import *
import os
import re
import binascii
import getopt
import webbrowser
#import gcode_ripper_lib
Zero = 0.0000001
STOP_CALC = 0
#Setting QUIET to True will stop almost all console messages
QUIET = False
################################################################################
# Function for outputting messages to different locations #
# depending on what options are enabled #
################################################################################
def fmessage(text,newline=True):
global QUIET
if (not QUIET):
if newline==True:
try:
sys.stdout.write(text)
sys.stdout.write("\n")
except:
pass
else:
try:
sys.stdout.write(text)
except:
pass
def message_box(title,message):
if VERSION == 3:
tkinter.messagebox.showinfo(title,message)
else:
tkMessageBox.showinfo(title,message)
pass
def message_ask_ok_cancel(title, mess):
if VERSION == 3:
result=tkinter.messagebox.askokcancel(title, mess)
else:
result=tkMessageBox.askokcancel(title, mess)
return result
def error_message(message):
error_report = Toplevel(width=525,height=60)
error_report.title("G-Code Ripper: G-Code Reading Errors")
error_report.iconname("G-Code Errors")
error_report.grab_set()
return_value = StringVar()
return_value.set("abort")
def Stop_Click(event):
return_value.set("abort")
error_report.destroy()
def Ignore_Click(event):
return_value.set("ignore")
error_report.destroy()
#Text Box
Error_Frame = Frame(error_report)
scrollbar = Scrollbar(Error_Frame, orient=VERTICAL)
Error_Text = Text(Error_Frame, width="80", height="20",yscrollcommand=scrollbar.set,bg='white')
for line in message:
Error_Text.insert(END,line+"\n")
scrollbar.config(command=Error_Text.yview)
scrollbar.pack(side=RIGHT,fill=Y)
#End Text Box
Button_Frame = Frame(error_report)
stop_button = Button(Button_Frame,text="Abort G-Code Reading")
stop_button.bind("<ButtonRelease-1>", Stop_Click)
ignore_button = Button(Button_Frame,text="Ignore Errors")
ignore_button.bind("<ButtonRelease-1>", Ignore_Click)
stop_button.pack(side=RIGHT,fill=X)
ignore_button.pack(side=LEFT,fill=X)
Error_Text.pack(side=LEFT,fill=BOTH,expand=1)
Button_Frame.pack(side=BOTTOM)
Error_Frame.pack(side=LEFT,fill=BOTH,expand=1)
try: #Attempt to create temporary icon bitmap file
f = open("g_code_ripper_icon",'w')
f.write("#define g_code_ripper_icon_width 16\n")
f.write("#define g_code_ripper_icon_height 16\n")
f.write("static unsigned char g_code_ripper_icon_bits[] = {\n")
f.write(" 0x3f, 0xfc, 0x1f, 0xf8, 0xcf, 0xf3, 0x6f, 0xe4, 0x6f, 0xed, 0xcf, 0xe5,\n")
f.write(" 0x1f, 0xf4, 0xfb, 0xf3, 0x73, 0x98, 0x47, 0xce, 0x0f, 0xe0, 0x3f, 0xf8,\n")
f.write(" 0x7f, 0xfe, 0x3f, 0xfc, 0x9f, 0xf9, 0xcf, 0xf3 };\n")
f.close()
gen_settings.iconbitmap("@g_code_ripper_icon")
os.remove("g_code_ripper_icon")
except:
pass
root.wait_window(error_report)
return return_value.get()
#Define cmp_new, cmp replacement for Python 3 compatability
def cmp_new(A,B):
if A==B:
return False
else:
return True
############################################################################
# routine takes an x and a y coords and does a coordinate transformation #
# to a new coordinate system at angle from the initial coordinate system #
# Returns new x,y tuple #
############################################################################
def Transform(x,y,angle):
newx = x * cos(angle) - y * sin(angle)
newy = x * sin(angle) + y * cos(angle)
return newx,newy
############################################################################
# routine takes an sin and cos and returns the angle (between 0 and 360) #
############################################################################
def Get_Angle(y,x):
angle = 90.0-degrees(atan2(x,y))
if angle < 0:
angle = 360 + angle
return angle
################################################################################
class Line:
def __init__(self, coords):
self.xstart, self.ystart, self.xend, self.yend = coords
self.xmax = max(self.xstart, self.xend)
self.ymax = max(self.ystart, self.yend)
self.ymin = min(self.ystart, self.yend)
def __repr__(self):
return "Line([%s, %s, %s, %s])" % (self.xstart, self.ystart, self.xend, self.yend)
################################################################################
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.w = 780
self.h = 490
frame = Frame(master, width= self.w, height=self.h)
self.master = master
self.x = -1
self.y = -1
#self.g_rip = gcode_ripper_lib.G_Code_Rip()
self.g_rip = G_Code_Rip()
self.createWidgets()
def createWidgets(self):
self.initComplete = 0
self.master.bind("<Configure>", self.Master_Configure)
self.master.bind('<Enter>', self.bindConfigure)
#self.master.bind('<Escape>', self.KEY_ESC)
self.master.bind('<F1>', self.KEY_F1)
self.master.bind('<F2>', self.KEY_F2)
self.master.bind('<F5>', self.KEY_F5) #self.Recalculate_Click)
self.master.bind('<Prior>', self.KEY_ZOOM_IN) # Page Up
self.master.bind('<Next>', self.KEY_ZOOM_OUT) # Page Down
self.master.bind('<Control-g>', self.KEY_CTRL_G)
self.show_axis = BooleanVar()
self.show_box = BooleanVar()
self.rotateb = BooleanVar()
self.plot_view = StringVar()
self.arc2line = BooleanVar()
self.var_dis = BooleanVar()
self.WriteAll = BooleanVar()
self.NoComments = BooleanVar()
self.SCALEXY = StringVar()
self.SCALEZ = StringVar()
self.ROTATE = StringVar()
self.SCALEF = StringVar()
self.gcode_op = StringVar()
self.SPLITA = StringVar()
self.SPLITX = StringVar()
self.SPLITY = StringVar()
self.ZSAFE = StringVar()
self.WRAP_DIA = StringVar()
self.WRAP_TYPE = StringVar()
self.WRAP_FSCALE= StringVar()
self.EXP_TYPE = StringVar()
self.Exp_Rapids = BooleanVar()
self.origin = StringVar()
self.units = StringVar()
self.segarc = StringVar()
self.accuracy = StringVar()
self.funits = StringVar()
self.FEED = StringVar()
self.gpre = StringVar()
self.gpost = StringVar()
self.DPlaces_L = StringVar()
self.DPlaces_R = StringVar()
self.DPlaces_F = StringVar()
self.sr_tool_dia= StringVar()
self.sr_step = StringVar()
self.sr_minx = StringVar()
self.sr_maxx = StringVar()
self.sr_zsafe = StringVar()
self.sr_feed = StringVar()
self.sr_remove = StringVar()
self.sr_plungef = StringVar()
self.SRmin_label= StringVar()
self.SRmax_label= StringVar()
self.sr_climb = BooleanVar()
self.Wrap_Rev_Rot = BooleanVar()
self.probe_feed = StringVar()
self.probe_depth = StringVar()
self.probe_safe = StringVar()
self.probe_nX = StringVar()
self.probe_nY = StringVar()
#self.probe_xPartitionLength = StringVar()
#self.probe_yPartitionLength = StringVar()
self.probe_istep = StringVar()
self.probe_offsetX = StringVar()
self.probe_offsetY = StringVar()
self.probe_offsetZ = StringVar()
self.probe_precodes= StringVar()
self.probe_pcodes = StringVar()
self.probe_soft = StringVar()
self.current_input_file = StringVar()
###########################################################################
# INITILIZE VARIABLES #
# if you want to change a default setting this is the place to do it #
###########################################################################
self.show_axis.set(1)
self.show_box.set(1)
self.rotateb.set(0)
self.arc2line.set(0)
self.var_dis.set(1)
self.plot_view.set("XY")
self.SCALEXY.set("100")
self.SCALEZ.set("100")
self.SCALEF.set("100")
self.gcode_op.set("split")
self.SPLITA.set("0.0")
self.SPLITX.set("0.0")
self.SPLITY.set("0.0")
self.ZSAFE.set("0.25")
self.ROTATE.set("0.0")
self.WRAP_DIA.set("10.0")
self.WRAP_TYPE.set("Y2A") # Options are: "Y2A","X2B","Y2B","X2A"
self.WRAP_FSCALE.set("Scale-Rotary") # Options are: "Scale-Rotary", "None"
self.EXP_TYPE.set("DXF")
self.Exp_Rapids.set(1)
self.origin.set("Default") # Options are "Default",
# "Top-Left", "Top-Center", "Top-Right",
# "Mid-Left", "Mid-Center", "Mid-Right",
# "Bot-Left", "Bot-Center", "Bot-Right"
self.units.set("in") # Options are "in" and "mm"
self.FEED.set("5.0")
self.segarc.set("5.0")
self.accuracy.set("0.001")
self.DPlaces_L.set("4")
self.DPlaces_R.set("3")
self.DPlaces_F.set("2")
self.WriteAll.set(0)
self.NoComments.set(0)
self.sr_tool_dia.set("0.25")
self.sr_step.set("25")
self.sr_minx.set("0")
self.sr_maxx.set("3")
self.sr_zsafe.set(".5")
self.sr_remove.set("-0.05")
self.sr_feed.set("10")
self.sr_plungef.set("5")
self.sr_climb.set(0)
self.Wrap_Rev_Rot.set(0)
self.probe_feed.set("5")
self.probe_depth.set("-.5")
self.probe_safe.set(".25")
self.probe_nX.set("3")
self.probe_nY.set("3")
self.probe_istep.set("4")
self.probe_offsetX.set("0.0")
self.probe_offsetY.set("0.0")
self.probe_offsetZ.set("0.0")
self.probe_precodes.set("(G Code)")
self.probe_pcodes.set("(G Code)")
self.probe_soft.set("LinuxCNC") # "LinuxCNC", "MACH3" or "MACH4"
self.segID = []
self.gcode = []
self.coords = []
self.probe_data = []
self.MAXX = 0
self.MINX = 0
self.MAXY = 0
self.MINY = 0
self.MAXZ = 0
self.MINZ = 0
self.HOME_DIR = os.path.expanduser("~")
self.NGC_OUTPUT = (self.HOME_DIR+"/None")
self.NGC_INPUT = (self.HOME_DIR+"/None")
self.PROBE_INPUT = (self.HOME_DIR+"/None")
self.current_input_file.set(" ")
# PAN and ZOOM STUFF
self.panx = 0
self.panx = 0
self.lastx = 0
self.lasty = 0
# Derived variables
if self.units.get() == 'in':
self.funits.set('in/min')
else:
self.units.set('mm')
self.funits.set('mm/min')
##########################################################################
# G-Code Default Preamble #
##########################################################################
self.gpre.set("(G-Code Preamble)")
##########################################################################
# G-Code Default Postamble #
##########################################################################
self.gpost.set("(G-Code Postamble)")
##########################################################################
### END INITILIZING VARIABLES ###
##########################################################################
self.config_file = "g-code-ripper_config.ngc"
home_config1 = self.HOME_DIR + "/" + self.config_file
config_file2 = ".gcoderipperrc"
home_config2 = self.HOME_DIR + "/" + config_file2
if ( os.path.isfile(self.config_file) ):
self.Open_Config_File(self.config_file)
elif ( os.path.isfile(home_config1) ):
self.Open_Config_File(home_config1)
elif ( os.path.isfile(home_config2) ):
self.Open_Config_File(home_config2)
opts, args = None, None
try:
opts, args = getopt.getopt(sys.argv[1:], "hg:c:d:",["help", "gcode_file=","config_file=","defdir="])
except:
fmessage('Unable interpret command line options')
sys.exit()
for option, value in opts:
if option in ('-h','--help'):
fmessage(' ')
fmessage('Usage: python g-code-ripper.py [-g file | -d directory ]')
fmessage('-c : config file to read (also --config_file)')
fmessage('-g : gcode file to read (also --gcode_file)')
fmessage('-d : default directory (also --defdir)')
fmessage('-h : print this help (also --help)\n')
sys.exit()
if option in ('-g','--gcode_file'):
self.Open_G_Code_File(value,Refresh=False)
self.NGC_INPUT = value
if option in ('-c','--config_file'):
self.Open_Config_File(value)
if option in ('-d','--defdir'):
self.HOME_DIR = value
if str.find(self.NGC_OUTPUT,'/None') != -1:
self.NGC_OUTPUT = (self.HOME_DIR+"/None")
if str.find(self.NGC_INPUT,'/None') != -1:
self.NGC_INPUT = (self.HOME_DIR+"/None")
##########################################################################
# make a Status Bar
self.statusMessage = StringVar()
self.statusMessage.set("")
self.statusbar = Label(self.master, textvariable=self.statusMessage, \
bd=1, relief=SUNKEN , height=1)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
self.statusMessage.set("Welcome to G-Code-Ripper")
# Buttons
self.Recalculate = Button(self.master,text="Recalculate")
self.Recalculate.bind("<ButtonRelease-1>", self.Recalculate_Click)
self.WriteBaseButton = Button(self.master,text="Save G-Code File - Base",
command=self.menu_File_Save_G_Code_Base)
self.WriteRightButton = Button(self.master,text="Save G-Code File - White",
command=self.menu_File_Save_G_Code_Right)
self.WriteLeftButton = Button(self.master,text="Save G-Code File - Black",
command=self.menu_File_Save_G_Code_Left)
# Canvas
lbframe = Frame( self.master )
self.PreviewCanvas_frame = lbframe
self.PreviewCanvas = Canvas(lbframe, width=self.w-525, \
height=self.h-200, background="grey")
self.PreviewCanvas.pack(side=LEFT, fill=BOTH, expand=1)
self.PreviewCanvas_frame.place(x=230, y=10)
self.PreviewCanvas.bind("<Button-4>" , self._mouseZoomIn)
self.PreviewCanvas.bind("<Button-5>" , self._mouseZoomOut)
self.PreviewCanvas.bind("<2>" , self.mousePanStart)
self.PreviewCanvas.bind("<B2-Motion>", self.mousePan)
self.PreviewCanvas.bind("<1>" , self.mouseZoomStart)
self.PreviewCanvas.bind("<B1-Motion>", self.mouseZoom)
self.PreviewCanvas.bind("<3>" , self.mousePanStart)
self.PreviewCanvas.bind("<B3-Motion>", self.mousePan)
# Left Column #
#----------------------
self.Label_Gcode_Operations = Label(self.master,text="G-Code Base Operations:", anchor=W)
self.Label_GscaleXY = Label(self.master,text="Scale XY", anchor=CENTER)
self.Label_GscaleXY_u = Label(self.master,text="%", anchor=W)
self.Entry_GscaleXY = Entry(self.master,width="15")
self.Entry_GscaleXY.configure(textvariable=self.SCALEXY)
self.Entry_GscaleXY.bind('<Return>', self.Recalculate_Click)
self.SCALEXY.trace_variable("w", self.Entry_GscaleXY_Callback)
self.NormalColor = self.Entry_GscaleXY.cget('bg')
self.Label_GscaleZ = Label(self.master,text="Scale Z", anchor=CENTER)
self.Label_GscaleZ_u = Label(self.master,text="%", anchor=W)
self.Entry_GscaleZ = Entry(self.master,width="15")
self.Entry_GscaleZ.configure(textvariable=self.SCALEZ)
self.Entry_GscaleZ.bind('<Return>', self.Recalculate_Click)
self.SCALEZ.trace_variable("w", self.Entry_GscaleZ_Callback)
self.NormalColor = self.Entry_GscaleZ.cget('bg')
self.Label_GscaleF = Label(self.master,text="Scale Feed", anchor=CENTER)
self.Label_GscaleF_u = Label(self.master,text="%", anchor=W)
self.Entry_GscaleF = Entry(self.master,width="15")
self.Entry_GscaleF.configure(textvariable=self.SCALEF)
self.Entry_GscaleF.bind('<Return>', self.Recalculate_Click)
self.SCALEF.trace_variable("w", self.Entry_GscaleF_Callback)
self.NormalColor = self.Entry_GscaleF.cget('bg')
self.Label_Rotate = Label(self.master,text="Rotate")
self.Label_Rotate_u = Label(self.master,text="deg", anchor=W)
self.Entry_Rotate = Entry(self.master,width="15")
self.Entry_Rotate.configure(textvariable=self.ROTATE)
self.Entry_Rotate.bind('<Return>', self.Recalculate_Click)
self.ROTATE.trace_variable("w", self.Entry_Rotate_Callback)
self.Label_Origin = Label(self.master,text="Origin", anchor=CENTER )
self.Origin_OptionMenu = OptionMenu(root, self.origin,
"Top-Left",
"Top-Center",
"Top-Right",
"Mid-Left",
"Mid-Center",
"Mid-Right",
"Bot-Left",
"Bot-Center",
"Bot-Right",
"Default", command=self.Recalculate_RQD_Click)
#----------------------
self.Label_view_opt = Label(self.master,text="View Plane:", anchor=W)
self.Radio_View_XY = Radiobutton(self.master,text="XY", value="XY",
width="100", anchor=W)
self.Radio_View_XY.configure(variable=self.plot_view)
self.Radio_View_XZ = Radiobutton(self.master,text="XZ", value="XZ",
width="100", anchor=W)
self.Radio_View_XZ.configure(variable=self.plot_view)
self.Radio_View_YZ = Radiobutton(self.master,text="YZ", value="YZ",
width="100", anchor=W)
self.Radio_View_YZ.configure(variable=self.plot_view)
self.Radio_View_ISO1 = Radiobutton(self.master,text="ISO1", value="ISO1",
width="100", anchor=W)
self.Radio_View_ISO1.configure(variable=self.plot_view)
self.Radio_View_ISO2 = Radiobutton(self.master,text="ISO2", value="ISO2",
width="100", anchor=W)
self.Radio_View_ISO2.configure(variable=self.plot_view)
self.Radio_View_ISO3 = Radiobutton(self.master,text="ISO3", value="ISO3",
width="100", anchor=W)
self.Radio_View_ISO3.configure(variable=self.plot_view)
self.plot_view.trace_variable("w", self.menu_View_Refresh_Callback)
#-----------------------
self.Label_code_ops = Label(self.master,text="G-Code Operations:", anchor=W)
self.Radio_Gcode_None = Radiobutton(self.master,text="None", value="none",
width="100", anchor=W)
self.Radio_Gcode_None.configure(variable=self.gcode_op )
self.Radio_Gcode_Split = Radiobutton(self.master,text="Split", value="split",
width="100", anchor=W)
self.Radio_Gcode_Split.configure(variable=self.gcode_op )
self.Radio_Gcode_Wrap = Radiobutton(self.master,text="Wrap", value="wrap",
width="100", anchor=W)
self.Radio_Gcode_Wrap.configure(variable=self.gcode_op )
self.Radio_Gcode_Export = Radiobutton(self.master,text="Export (DXF, CSV)", value="export",
width="100", anchor=W)
self.Radio_Gcode_Export.configure(variable=self.gcode_op )
self.Radio_Gcode_Probe = Radiobutton(self.master,text="Auto Probe", value="probe",
width="100", anchor=W)
self.Radio_Gcode_Probe.configure(variable=self.gcode_op )
self.gcode_op.trace_variable("w", self.Entry_recalc_var_Callback)
# End Left Column #
self.separator1 = Frame(height=2, bd=1, relief=SUNKEN)
self.separator2 = Frame(height=2, bd=1, relief=SUNKEN)
self.separator3 = Frame(height=2, bd=1, relief=SUNKEN)
self.separator4 = Frame(height=2, bd=1, relief=SUNKEN)
self.separator5 = Frame(height=2, bd=1, relief=SUNKEN)
self.separator6 = Frame(height=2, bd=1, relief=SUNKEN)
self.separator7 = Frame(height=2, bd=1, relief=SUNKEN)
# Right Column #
### SPLIT ###
self.Label_Gcode_Split_Properties = Label(self.master,text="G-Code Split Properties:",\
anchor=W)
self.Label_SplitX = Label(self.master,text="Split X Position", anchor=CENTER )
self.Label_SplitX_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_SplitX = Entry(self.master,width="15")
self.Entry_SplitX.configure(textvariable=self.SPLITX)
self.Entry_SplitX.bind('<Return>', self.Recalculate_Click)
self.SPLITX.trace_variable("w", self.Entry_SplitX_Callback)
self.Label_SplitY = Label(self.master,text="Split Y Position", anchor=CENTER )
self.Label_SplitY_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_SplitY = Entry(self.master,width="15")
self.Entry_SplitY.configure(textvariable=self.SPLITY)
self.Entry_SplitY.bind('<Return>', self.Recalculate_Click)
self.SPLITY.trace_variable("w", self.Entry_SplitY_Callback)
self.Label_SplitA = Label(self.master,text="Split Angle", anchor=CENTER )
self.Label_SplitA_u = Label(self.master,text="deg", anchor=W)
self.Entry_SplitA = Entry(self.master,width="15")
self.Entry_SplitA.configure(textvariable=self.SPLITA)
self.Entry_SplitA.bind('<Return>', self.Recalculate_Click)
self.SPLITA.trace_variable("w", self.Entry_SplitA_Callback)
self.Label_rotateb = Label(self.master,text="Rotate Black")
self.Checkbutton_rotateb = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_rotateb.configure(variable=self.rotateb)
self.rotateb.trace_variable("w", self.Entry_recalc_var_Callback)
self.Label_gcode_opt = Label(self.master,text="G-Code Properties:", anchor=W)
self.Label_Feed = Label(self.master,text="Plunge Feed")
self.Label_Feed_u = Label(self.master,textvariable=self.funits, anchor=W)
self.Entry_Feed = Entry(self.master,width="15")
self.Entry_Feed.configure(textvariable=self.FEED)
self.Entry_Feed.bind('<Return>', self.Recalculate_Click)
self.FEED.trace_variable("w", self.Entry_Feed_Callback)
self.Label_Zsafe = Label(self.master,text="Z Safe")
self.Label_Zsafe_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_Zsafe = Entry(self.master,width="15")
self.Entry_Zsafe.configure(textvariable=self.ZSAFE)
self.Entry_Zsafe.bind('<Return>', self.Recalculate_Click)
self.ZSAFE.trace_variable("w", self.Entry_Zsafe_Callback)
### WRAP ###
self.Label_Gcode_Wrap_Properties = Label(self.master,text="G-Code Wrap Properties:",\
anchor=W)
self.Label_Wrap_DIA = Label(self.master,text="Wrap Diameter", anchor=CENTER )
self.Label_Wrap_DIA_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_Wrap_DIA = Entry(self.master,width="15")
self.Entry_Wrap_DIA.configure(textvariable=self.WRAP_DIA)
self.Entry_Wrap_DIA.bind('<Return>', self.Recalculate_Click)
self.WRAP_DIA.trace_variable("w", self.Entry_Wrap_DIA_Callback)
self.Label_Radio_Wrap = Label(self.master,text="Axis Wrap Type:", anchor=W)
self.Radio_Wrap_Y2A = Radiobutton(self.master,text="Y-axis to A-axis", value="Y2A",
width="100", anchor=W)
self.Radio_Wrap_Y2A.configure(variable=self.WRAP_TYPE )
self.Radio_Wrap_X2B = Radiobutton(self.master,text="X-axis to B-axis", value="X2B",
width="100", anchor=W)
self.Radio_Wrap_X2B.configure(variable=self.WRAP_TYPE )
self.Radio_Wrap_Y2B = Radiobutton(self.master,text="Y-axis to B-axis", value="Y2B",
width="100", anchor=W)
self.Radio_Wrap_Y2B.configure(variable=self.WRAP_TYPE )
self.Radio_Wrap_X2A = Radiobutton(self.master,text="X-axis to A-axis", value="X2A",
width="100", anchor=W)
self.Radio_Wrap_X2A.configure(variable=self.WRAP_TYPE )
self.WRAP_TYPE.trace_variable("w", self.Entry_recalc_var_Callback)
self.Label_WRAP_FSCALE = Label(self.master,text="Feed Adjust:", anchor=W)
self.WRAP_FSCALE_OptionMenu = OptionMenu(root, self.WRAP_FSCALE, "Scale-Rotary", "None")
self.Label_WRAP_REV_ROT = Label(self.master,text="Reverse Rotary Axis", anchor=W)
self.Checkbutton_WRAP_REV_ROT = Checkbutton(self.master,text="", anchor=W)
self.Checkbutton_WRAP_REV_ROT.configure(variable=self.Wrap_Rev_Rot)
self.WriteWrapButton = Button(self.master,text="Save G-Code File - Wrap",
command=self.menu_File_Save_G_Code_Wrap)
self.WriteRoundButton = Button(self.master,text="Stock Rounding",
command=self.STOCK_Round_Window)
## Define "Export" mode input feilds here
self.Label_Gcode_Export_Properties = Label(self.master,text="Export Properties:",\
anchor=W)
self.Label_Radio_Export = Label(self.master,text="File Type:", anchor=W)
self.Radio_Export_DXF = Radiobutton(self.master,text="DXF", value="DXF",
width="100", anchor=W)
self.Radio_Export_DXF.configure(variable=self.EXP_TYPE )
self.Radio_Export_CSV = Radiobutton(self.master,text="CSV (text)", value="CSV",
width="100", anchor=W)
self.Radio_Export_CSV.configure(variable=self.EXP_TYPE )
self.WRAP_TYPE.trace_variable("w", self.Entry_recalc_var_Callback)
self.Label_EXP_RAPIDS = Label(self.master,text="Include Rapid Moves", anchor=W)
self.Checkbutton_EXP_RAPIDS = Checkbutton(self.master,text="", anchor=W)
self.Checkbutton_EXP_RAPIDS.configure(variable=self.Exp_Rapids)
self.WriteExportButton = Button(self.master,text="Export File",
command=self.menu_File_Save_Export_Write)
### PROBE ###
self.Label_Gcode_Probe_Properties = Label(self.master,text="Auto-Probe Properties:",\
anchor=W)
self.Label_ProbeOffsetX = Label(self.master,text="Probe X Offset", anchor=CENTER )
self.Label_ProbeOffsetX_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_ProbeOffsetX = Entry(self.master,width="15")
self.Entry_ProbeOffsetX.configure(textvariable=self.probe_offsetX)
self.Entry_ProbeOffsetX.bind('<Return>', self.Recalculate_Click)
self.probe_offsetX.trace_variable("w", self.Entry_ProbeOffsetX_Callback)
self.Label_ProbeOffsetY = Label(self.master,text="Probe Y Offset", anchor=CENTER )
self.Label_ProbeOffsetY_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_ProbeOffsetY = Entry(self.master,width="15")
self.Entry_ProbeOffsetY.configure(textvariable=self.probe_offsetY)
self.Entry_ProbeOffsetY.bind('<Return>', self.Recalculate_Click)
self.probe_offsetY.trace_variable("w", self.Entry_ProbeOffsetY_Callback)
self.Label_ProbeOffsetZ = Label(self.master,text="Probe Z Offset", anchor=CENTER )
self.Label_ProbeOffsetZ_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_ProbeOffsetZ = Entry(self.master,width="15")
self.Entry_ProbeOffsetZ.configure(textvariable=self.probe_offsetZ)
self.Entry_ProbeOffsetZ.bind('<Return>', self.Recalculate_Click)
self.probe_offsetZ.trace_variable("w", self.Entry_ProbeOffsetZ_Callback)
self.Label_ProbeSafe = Label(self.master,text="Probe Z Safe")
self.Label_ProbeSafe_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_ProbeSafe = Entry(self.master,width="15")
self.Entry_ProbeSafe.configure(textvariable=self.probe_safe)
self.probe_safe.trace_variable("w", self.Entry_ProbeSafe_Callback)
self.Label_ProbeDepth = Label(self.master,text="Probe Depth")
self.Label_ProbeDepth_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_ProbeDepth = Entry(self.master,width="15")
self.Entry_ProbeDepth.configure(textvariable=self.probe_depth)
self.Entry_ProbeDepth.bind('<Return>', self.Recalculate_Click)
self.probe_depth.trace_variable("w", self.Entry_ProbeDepth_Callback)
self.Label_ProbeFeed = Label(self.master,text="Probe Feed")
self.Label_ProbeFeed_u = Label(self.master,textvariable=self.funits, anchor=W)
self.Entry_ProbeFeed = Entry(self.master,width="15")
self.Entry_ProbeFeed.configure(textvariable=self.probe_feed)
self.probe_feed.trace_variable("w", self.Entry_ProbeFeed_Callback)
self.Label_Probe_Num_X = Label(self.master,text="X Points")
self.Entry_Probe_Num_X = Entry(self.master,width="15")
self.Entry_Probe_Num_X.configure(textvariable=self.probe_nX)
self.Entry_Probe_Num_X.bind('<Return>', self.Recalculate_Click)
self.probe_nX.trace_variable("w", self.Entry_probe_nX_Callback)
self.Label_Probe_Num_Y = Label(self.master,text="Y Points")
self.Entry_Probe_Num_Y = Entry(self.master,width="15")
self.Entry_Probe_Num_Y.configure(textvariable=self.probe_nY)
self.Entry_Probe_Num_Y.bind('<Return>', self.Recalculate_Click)
self.probe_nY.trace_variable("w", self.Entry_probe_nY_Callback)
# self.Label_ProbeInterpSpace = Label(self.master,text="Interp. Steps")
# self.Entry_ProbeInterpSpace = Entry(self.master,width="15")
# self.Entry_ProbeInterpSpace.configure(textvariable=self.probe_istep)
# self.probe_istep.trace_variable("w", self.Entry_ProbeIStep_Callback)
self.Label_ProbePreCodes = Label(self.master,text="Pre Probe")
self.Entry_ProbePreCodes = Entry(self.master,width="15")
self.Entry_ProbePreCodes.configure(textvariable=self.probe_precodes)
self.Label_ProbePauseCodes = Label(self.master,text="Post Probe")
self.Label_ProbePauseCodes_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_ProbePauseCodes = Entry(self.master,width="15")
self.Entry_ProbePauseCodes.configure(textvariable=self.probe_pcodes)
self.Label_ProbeSoft = Label(self.master,text="Controller:", anchor=W)
self.ProbeSoft_OptionMenu = OptionMenu(root, self.probe_soft, "LinuxCNC", "MACH3", "MACH4")
self.WriteProbeOnlyButton = Button(self.master,text="Save G-Code File - Probe Only",
command=self.menu_File_Save_G_Code_ProbeOnly)
self.ReadProbeButton = Button(self.master,text="Read Probe Data File",
command=self.menu_File_Read_Probe_data)
self.ClearProbeButton = Button(self.master,text="Clear Probe Data",
command=self.menu_Clear_Probe_data)
self.WriteAdjustedButton = Button(self.master,text="Save G-Code File - Adjusted",
command=self.menu_File_Save_G_Code_Adjusted)
self.WriteProbeButton = Button(self.master,text="Save G-Code File - Probe & Cut",
command=self.menu_File_Save_G_Code_Probe_n_Cut)
############
# End Right Column #
#GEN Setting Window Entry initialization
self.Entry_ArcAngle = Entry()
self.Entry_Accuracy = Entry()
self.Entry_DPlaces_L = Entry()
self.Entry_DPlaces_R = Entry()
self.Entry_DPlaces_F = Entry()
# Make Menu Bar
self.menuBar = Menu(self.master, relief = "raised", bd=2)
self.top_File = Menu(self.menuBar, tearoff=0)
self.top_File.add("command", label = "Open G-Code File", \
command = self.menu_File_Open_G_Code_File)
self.top_File.add("command", label = "Save G-Code File - Base", \
command = self.menu_File_Save_G_Code_Base)
#self.top_File.add("command", label = "Save G-Code File - Black", \
# command = self.menu_File_Save_G_Code_Left)
#self.top_File.add("command", label = "Save G-Code File - White", \
# command = self.menu_File_Save_G_Code_Right)
self.top_File.add("command", label = "Exit", command = self.menu_File_Quit)
self.menuBar.add("cascade", label="File", menu=self.top_File)
self.top_Edit = Menu(self.menuBar, tearoff=0)
self.top_Edit.add("command", label = "Copy G-Code Data to Clipboard - Base", \
command = self.menu_CopyClipboard_GCode_Base)
#self.top_Edit.add("command", label = "Copy G-Code Data to Clipboard - Black", \
# command = self.menu_CopyClipboard_GCode_Left)
#self.top_Edit.add("command", label = "Copy G-Code Data to Clipboard - White", \
# command = self.menu_CopyClipboard_GCode_Right)
self.menuBar.add("cascade", label="Edit", menu=self.top_Edit)
self.top_View = Menu(self.menuBar, tearoff=0)
self.top_View.add("command", label = "Recalculate", command = self.menu_View_Recalculate)
self.top_View.add_separator()
self.top_View.add("command", label = "Zoom In <Page Up>", command = self.menu_View_Zoom_in)
self.top_View.add("command", label = "Zoom Out <Page Down>", command = self.menu_View_Zoom_out)
self.top_View.add("command", label = "Zoom Fit <F5>", command = self.menu_View_Refresh)
self.top_View.add_separator()
self.top_View.add_checkbutton(label = "Show Origin Axis", variable=self.show_axis , \
command= self.menu_View_Refresh)
self.top_View.add_checkbutton(label = "Show Bounding Box", variable=self.show_box , \
command= self.menu_View_Refresh)
self.menuBar.add("cascade", label="View", menu=self.top_View)
self.top_Settings = Menu(self.menuBar, tearoff=0)
self.top_Settings.add("command", label = "General Settings", \
command = self.GEN_Settings_Window)
self.menuBar.add("cascade", label="Settings", menu=self.top_Settings)
self.top_Help = Menu(self.menuBar, tearoff=0)
self.top_Help.add("command", label = "About", command = self.menu_Help_About)
self.top_Help.add("command", label = "Help (Web Page)", command = self.menu_Help_Web)
self.menuBar.add("cascade", label="Help", menu=self.top_Help)
self.master.config(menu=self.menuBar)
## Load g-code file
self.Open_G_Code_File(self.NGC_INPUT,Refresh=False)
################################################################################
def entry_set(self, val2, calc_flag=0, new=0):
if calc_flag == 0 and new==0:
try:
self.statusbar.configure( bg = 'yellow' )
val2.configure( bg = 'yellow' )
self.statusMessage.set(" Recalculation required.")
except:
pass
elif calc_flag == 3:
try:
val2.configure( bg = 'red' )
self.statusbar.configure( bg = 'red' )
self.statusMessage.set(" Value should be a number. ")
except:
pass
elif calc_flag == 2:
try:
self.statusbar.configure( bg = 'red' )
val2.configure( bg = 'red' )
#self.statusMessage.set(message)
except:
pass
elif (calc_flag == 0 or calc_flag == 1) and new==1 :
try:
self.statusbar.configure( bg = 'white' )
self.statusMessage.set(" ")
val2.configure( bg = 'white' )
except:
pass
elif (calc_flag == 1) and new==0 :
try:
self.statusbar.configure( bg = 'white' )
self.statusMessage.set(" ")
val2.configure( bg = 'white' )
except:
pass
elif (calc_flag == 0 or calc_flag == 1) and new==2:
return 0
return 1
################################################################################
def Write_Config_File(self, event):
config = []
config.append('( Configuration File for G-Code Ripper-'+version+'.py widget )')
config.append('( by Scorch - 2017 )')
config.append("(=========================================================)")
# BOOL
config.append('(g-code_ripper_set show_axis %s )' %( int(self.show_axis.get()) ))
config.append('(g-code_ripper_set show_box %s )' %( int(self.show_box.get()) ))
config.append('(g-code_ripper_set rotateb %s )' %( int(self.rotateb.get()) ))
config.append('(g-code_ripper_set arc2line %s )' %( int(self.arc2line.get()) ))
config.append('(g-code_ripper_set var_dis %s )' %( int(self.var_dis.get()) ))
config.append('(g-code_ripper_set WriteAll %s )' %( int(self.WriteAll.get()) ))
config.append('(g-code_ripper_set NoComments %s )' %( int(self.NoComments.get()) ))
config.append('(g-code_ripper_set Exp_Rapids %s )' %( int(self.Exp_Rapids.get()) ))
# STRING.get()
config.append('(g-code_ripper_set units %s )' %( self.units.get() ))
config.append('(g-code_ripper_set SCALEXY %s )' %( self.SCALEXY.get() ))
config.append('(g-code_ripper_set SCALEZ %s )' %( self.SCALEZ.get() ))
config.append('(g-code_ripper_set SCALEF %s )' %( self.SCALEF.get() ))
config.append('(g-code_ripper_set ROTATE %s )' %( self.ROTATE.get() ))
config.append('(g-code_ripper_set SPLITA %s )' %( self.SPLITA.get() ))
config.append('(g-code_ripper_set SPLITX %s )' %( self.SPLITX.get() ))
config.append('(g-code_ripper_set SPLITY %s )' %( self.SPLITY.get() ))
config.append('(g-code_ripper_set ZSAFE %s )' %( self.ZSAFE.get() ))
config.append('(g-code_ripper_set origin %s )' %( self.origin.get() ))
config.append('(g-code_ripper_set segarc %s )' %( self.segarc.get() ))
config.append('(g-code_ripper_set accuracy %s )' %( self.accuracy.get() ))
config.append('(g-code_ripper_set FEED %s )' %( self.FEED.get() ))
config.append('(g-code_ripper_set GCODE_OP %s )' %( self.gcode_op.get() ))
config.append('(g-code_ripper_set WRAP_DIA %s )' %( self.WRAP_DIA.get() ))
config.append('(g-code_ripper_set WRAP_TYPE %s )' %( self.WRAP_TYPE.get()))
config.append('(g-code_ripper_set WRAP_FSCALE %s )' %( self.WRAP_FSCALE.get()))
config.append('(g-code_ripper_set EXP_TYPE %s )' %( self.EXP_TYPE.get()))
config.append('(g-code_ripper_set DPlaces_L %s )' %( self.DPlaces_L.get() ))
config.append('(g-code_ripper_set DPlaces_R %s )' %( self.DPlaces_R.get() ))
config.append('(g-code_ripper_set DPlaces_F %s )' %( self.DPlaces_F.get() ))
config.append('(g-code_ripper_set sr_tool_dia %s )' %( self.sr_tool_dia.get() ))
config.append('(g-code_ripper_set sr_step %s )' %( self.sr_step.get() ))
config.append('(g-code_ripper_set sr_minx %s )' %( self.sr_minx.get() ))
config.append('(g-code_ripper_set sr_maxx %s )' %( self.sr_maxx.get() ))
config.append('(g-code_ripper_set sr_zsafe %s )' %( self.sr_zsafe.get() ))
config.append('(g-code_ripper_set sr_remove %s )' %( self.sr_remove.get() ))
config.append('(g-code_ripper_set sr_feed %s )' %( self.sr_feed.get() ))