-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwing.pyw
1577 lines (1382 loc) · 65.1 KB
/
wing.pyw
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/env python
# python wing.pyw
# Version $Id: wing.pyw 1.1 2021/01/19 07:02:33 swarf Exp $
# Dec 4 2007
# XYUV wing G-Code Generator for EMC2
# also YZ/XZ for GRBL for straight wings only
# also XYUZ for GRBL 4axis
"""
Copyright (C) <2008> <John Thornton>
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/>.
e-mail me any suggestions to "jet1024 at semo dot net"
If you make money using this software
you must donate self.20 USD to a local food bank
or the food police will get you! Think of others from time to time...
To make it a menu item in Ubuntu use the Alacarte Menu Editor and add
the command python YourPathToThisFile/face.py
make sure you have made the file execuatble by right
clicking and selecting properties then Permissions and Execute
To use with EMC2 see the instructions at:
http:#wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Simple_EMC_G-Code_Generators
2008-02-24 Rick Calder "rick at llamatrails dot com"
Added option/code to select X0-Y0 position: Left-Rear or Left-Front
To change the default, change line 171: 4=Left-Rear, 5=Left-Front
2010-01-06 Brad Hanken "chembal at gmail dot com"
Added option and code to change the lead in and lead out amount
If nothing is entered, the old calculated value of tool radius + .1 is still used
2014-11-00 swarfer: made metric the default
add option to cut unidirectional
2017-11-16 swarfer: modified into a wing cutter, based on gwing.php by the swarfer
python 2.x only...
2018-02-06 swarfer: cut wings in YZ or XZ only, straight wings on a gantry XYZ machine
2020-05-10 swarfer: add XYUZ output for 4axis GRBL from rckeith
2021-10-14 rcKeith: Python3 compatibility
2021-01-19 swarfer: fine tune for release for Python3
"""
from tkinter import *
from math import *
from tkinter.simpledialog import *
from tkinter.filedialog import *
import configparser
from decimal import *
import tkinter.messagebox
import os
import glob
import string
import re
# LinuxCNC variable
IN_AXIS = "AXIS_PROGRESS_BAR" in os.environ
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master, bd=1, padx=10)
self.grid()
self.pack()
self.createMenu()
if IN_AXIS:
self.ext = '.ngc'
else:
self.ext = '.nc'
self.inifile = os.path.join('.','wing.ini')
try:
self.DatDir = self.GetIniData(self.inifile,'Directories','DatFiles')
except:
# does not exist so write a default value
self.DatDir = os.path.join('.','coord')
self.WriteIniData(self.inifile,'Directories','DatFiles',self.DatDir)
try:
""" save in ini in the NC folder """
self.NcFileDirectory = self.GetIniData(self.inifile,'Directories','NcFiles')
except:
tkinter.messagebox.showinfo('Missing INI Data', 'You must set the\n' \
'G-code File Directory\n' \
'before saving a file.\n' \
'Go to Edit/G-code Directory\n' \
'in the menu to set this option')
return
#Pad Rows
for row in range(1,9):
self.rowconfigure(row,pad=5)
self.createWidgets()
#center the window
self.update_idletasks()
width = self.winfo_width()
frm_width = self.winfo_rootx() - self.winfo_x()
win_width = width + 2 * frm_width
height = self.winfo_height()
titlebar_height = self.winfo_rooty() - self.winfo_y()
win_height = height + titlebar_height + frm_width
x = self.winfo_screenwidth() # 2 - win_width # 2
y = self.winfo_screenheight() # 2 - win_height # 2
#self.At(1060,200)
#self.deiconify()
try: #try to read the last model saved
modelname = self.GetIniData(self.inifile,'autoload','model')
filename = os.path.join(self.NcFileDirectory, modelname + '.ini')
if os.path.exists(filename):
self.ReadModel(filename)
except:
pass
def createMenu(self):
#Create the Menu base
self.menu = Menu(self)
#Add the Menu
self.master.config(menu=self.menu)
#Create our File menu
self.FileMenu = Menu(self.menu,tearoff =FALSE)
#Add our Menu to the Base Menu
self.menu.add_cascade(label='File', menu=self.FileMenu)
#self.menu.option_add()
#Add items to the menu
#self.FileMenu.add_command(label='New', command=self.Simple)
#self.FileMenu.add_command(label='Open', command=self.Simple)
#self.FileMenu.add_separator()
self.FileMenu.add_command(label='Quit', command=self.quit)
self.EditMenu = Menu(self.menu, tearoff =FALSE)
self.menu.add_cascade(label='Edit', menu=self.EditMenu)
self.EditMenu.add_command(label='Copy', command=self.CopyClpBd)
self.EditMenu.add_command(label='Select All', command=self.SelectAllText)
self.EditMenu.add_command(label='Delete All', command=self.ClearTextBox)
self.EditMenu.add_separator()
#self.EditMenu.add_command(label='Preferences', command=self.Simple)
self.EditMenu.add_command(label='G-Code Directory', command=self.NcFileDirectory)
self.EditMenu.add_command(label='DAT (Airfoils) Directory', command=self.DatFileDirectory)
self.ModelMenu = Menu(self.menu,tearoff=FALSE)
self.menu.add_cascade(label='Model', menu=self.ModelMenu)
self.ModelMenu.add_command(label='Load Model', command=self.LoadModel)
self.ModelMenu.add_command(label='Save Model', command=self.SaveModel)
self.HelpMenu = Menu(self.menu,tearoff =FALSE )
self.menu.add_cascade(label='Help', menu=self.HelpMenu)
#self.HelpMenu.add_command(label='Help Info', command=self.HelpInfo)
self.HelpMenu.add_command(label='About', command=self.HelpAbout)
def createWidgets(self):
self.sp1 = Label(self)
self.sp1.grid(row=0)
self.st1 = Label(self, text='Model Name ')
self.st1.grid(row=1, column=0, sticky=E)
self.ModelNameVar = StringVar()
self.ModelNameVar.set('default')
self.ModelName = Entry(self, width=20, textvariable=self.ModelNameVar)
self.ModelName.grid(row=1, column=1, sticky=W)
self.ModelName.focus_set()
self.SaveModelButton = Button(self, text='Save Model',command=self.SaveModel)
self.SaveModelButton.grid(row=1, column=2)
self.LoadModelButton = Button(self, text='Load Model',command=self.LoadModel)
self.LoadModelButton.grid(row=1, column=3,pady=3)
self.st2 = Label(self, text='WingSpan ')
self.st2.grid(row=2, column=0, sticky=E)
self.WingSpanVar = StringVar()
self.WingSpanVar.set('500')
self.WingSpan = Entry(self, width=10, textvariable=self.WingSpanVar)
self.WingSpan.grid(row=2, column=1, sticky=W)
self.st22 = Label(self, text='Washout ')
self.st22.grid(row=2, column=2, sticky=E)
self.WashoutVar = StringVar()
self.WashoutVar.set('0')
self.Washout = Entry(self, width=10, textvariable=self.WashoutVar)
self.Washout.grid(row=2, column=3, sticky=W)
self.st3 = Label(self, text='Root Chord ')
self.st3.grid(row=3, column=0, sticky=E)
self.RootChordVar = StringVar()
self.RootChordVar.set('200')
self.RootChord = Entry(self, width=10, textvariable=self.RootChordVar)
self.RootChord.grid(row=3, column=1, sticky=W)
self.st4 = Label(self, text='Tip Chord ')
self.st4.grid(row=3, column=2, sticky=E)
self.TipChordVar = StringVar()
self.TipChordVar.set('190')
self.TipChord = Entry(self, width=10, textvariable=self.TipChordVar)
self.TipChord.grid(row=3, column=3, sticky=W)
self.profiles = glob.glob(os.path.join(self.DatDir, '*.dat'))
self.profiles.sort()
self.st5 = Label(self, text='Root Profile ')
self.st5.grid(row=4, column=0, sticky=E)
self.rootScrollbar = Scrollbar(self, orient=VERTICAL)
self.RootProfilelistbox = Listbox(self, exportselection=0, height=5, width=18, yscrollcommand=self.rootScrollbar.set)
self.rootScrollbar.config(command=self.RootProfilelistbox.yview)
self.rootScrollbar.grid(row=4,column=1, sticky=N+S+E)
self.RootProfilelistbox.grid(row=4, column=1, sticky=W)
for item in self.profiles:
nitem = str.replace(item,self.DatDir + os.sep,'')
self.RootProfilelistbox.insert(END, nitem)
if (len(self.profiles) > 0):
self.RootProfilelistbox.selection_set(0)
# self.st6 = Label(self, text='Tip Profile ')
# self.st6.grid(row=4, column=2, sticky=E)
# self.TipProfileVar = StringVar()
# self.TipProfile = Entry(self, width=10, textvariable=self.TipProfileVar)
# self.TipProfile.grid(row=4, column=3, sticky=W)
self.st6 = Label(self, text='Tip Profile ')
self.st6.grid(row=4, column=2, sticky=E)
self.tipScrollbar = Scrollbar(self, orient=VERTICAL)
self.TipProfilelistbox = Listbox(self, exportselection=0, height=5, yscrollcommand=self.tipScrollbar.set)
self.tipScrollbar.config(command=self.TipProfilelistbox.yview)
self.tipScrollbar.grid(row=4,column=4, sticky=N+S+W)
self.TipProfilelistbox.grid(row=4, column=3, sticky=W)
for item in self.profiles:
nitem = str.replace(item,self.DatDir + os.sep,'')
self.TipProfilelistbox.insert(END, nitem)
if (len(self.profiles) > 0):
self.TipProfilelistbox.selection_set(0)
self.st7 = Label(self, text='Foam Chord ')
self.st7.grid(row=5, column=0, sticky=E)
self.FoamChordVar = StringVar()
self.FoamChordVar.set(220)
self.FoamChord = Entry(self, width=10, textvariable=self.FoamChordVar)
self.FoamChord.grid(row=5, column=1, sticky=W)
self.st8 = Label(self, text='Foam Thickness ')
self.st8.grid(row=5, column=2, sticky=E)
self.FoamThicknessVar = StringVar()
self.FoamThicknessVar.set(50)
self.FoamThickness = Entry(self, width=10, textvariable=self.FoamThicknessVar)
self.FoamThickness.grid(row=5, column=3, sticky=W)
self.st9 = Label(self, text='Trailing Edge Limit ')
self.st9.grid(row=6, column=0, sticky=E)
self.TrailingEdgeLimitVar = StringVar()
self.TrailingEdgeLimitVar.set(3)
self.TrailingEdgeLimit = Entry(self, width=10, textvariable=self.TrailingEdgeLimitVar)
self.TrailingEdgeLimit.grid(row=6, column=1, sticky=W)
self.st10 = Label(self, text='Leading Edge Sweep ')
self.st10.grid(row=6, column=2, sticky=E)
self.LeadingEdgeSweepVar = StringVar()
self.LeadingEdgeSweepVar.set(5)
self.LeadingEdgeSweep = Entry(self, width=10, textvariable=self.LeadingEdgeSweepVar)
self.LeadingEdgeSweep.grid(row=6, column=3, sticky=W)
#self.st11 = Label(self, text='Gantry Length ') KH
self.st11 = Label(self, text='Carriage Length ')
self.st11.grid(row=7, column=0, sticky=E)
self.GantryLengthVar = StringVar()
self.GantryLengthVar.set(600)
self.GantryLength = Entry(self, width=10, textvariable=self.GantryLengthVar)
self.GantryLength.grid(row=7, column=1, sticky=W)
self.st12 = Label(self, text='Feedrate ')
self.st12.grid(row=7, column=2, sticky=E)
self.FeedrateVar = StringVar()
self.FeedrateVar.set(50)
self.Feedrate = Entry(self, width=10, textvariable=self.FeedrateVar)
self.Feedrate.grid(row=7, column=3, sticky=W)
#these two need to be radio boxes
# Units Radiobutton Callback # 5
# def radCallUnit():
# radSel=radVar.get()
# if radSel == 1: win.configure(background=COLOR1)
# elif radSel == 2: win.configure(background=COLOR2)
# elif radSel == 3: win.configure(background=COLOR3)
# create two Radiobuttons
self.XYsideVar = IntVar() # 0 for XY right, 1 for XY left
self.st13 = Label(self, text='XY side ')
self.st13.grid(row=8, column=0, sticky=E)
urad1 = Radiobutton(self, text='Right', variable=self.XYsideVar, value=0)
urad1.grid(row=8, column=1, sticky=E)
urad2 = Radiobutton(self, text='Left', variable=self.XYsideVar, value=1)
urad2.grid(row=8, column=1, sticky=W)
self.XYsideVar.set(0)
self.st14=Label(self,text='Units : ')
self.st14.grid(row=8,column=2)
UnitOptions=[('Inch',1,'E'),('MM',0,'W')]
self.UnitVar = IntVar()
for text, value, side in UnitOptions:
Radiobutton(self, text=text,value=value, variable=self.UnitVar,indicatoron=0,width=6,).grid(row=8, column=3,sticky=side)
self.UnitVar.set(0)
# XYUV/YZ/XZ
self.XYUVVar = IntVar() # 0 for XYUV , 1 for YZ, 2 for XZ, 3 for XYUZ (GRBL mode)
#self.st13 = Label(self, text='XYUV/YZ/XZ/XYUZ ')
#self.st13.grid(row=9, column=0, sticky=E)
urad1 = Radiobutton(self, text='XYUV', variable=self.XYUVVar, value=0)
urad1.grid(row=9, column=0, sticky=W)
urad2 = Radiobutton(self, text='YZ only', variable=self.XYUVVar, value=1)
urad2.grid(row=9, column=1, sticky=W)
urad1 = Radiobutton(self, text='XZ only', variable=self.XYUVVar, value=2)
urad1.grid(row=9, column=2, sticky=W)
urad3 = Radiobutton(self, text='XYUZ(GRBL)', variable=self.XYUVVar, value=3)
urad3.grid(row=9, column=3, sticky=W)
self.XYUVVar.set(3)
self.spacer3 = Label(self, text='')
self.spacer3.grid(row=10, column=0, columnspan=5)
# gcode block
self.g_code = Text(self,width=40,height=14,bd=3)
self.g_code.grid(row=11, column=0, columnspan=4, sticky=E+W+N+S,pady=5)
self.tbscroll = Scrollbar(self,command = self.g_code.yview)
self.tbscroll.grid(row=11, column=4, sticky=N+S+W)
self.g_code.configure(yscrollcommand = self.tbscroll.set)
self.sp4 = Label(self)
self.sp4.grid(row=12)
#make sure these exist so pressing save button before generate does not crash
self.g_code_left = list()
self.g_code_right = list()
self.g_code_both = list()
self.GenButton = Button(self, text='Generate G-Code',justify=CENTER,command=self.GenCode)
self.GenButton.grid(row=12, column=0)
# self.GenButton = Button(self, text='Generate G-Code bi',command=self.GenCode2)
# self.GenButton.grid(row=12, column=1)
# self.CopyButton = Button(self, text='Select All & Copy',command=self.SelectCopy)
# self.CopyButton.grid(row=12, column=2)
self.WriteButton = Button(self, text='Write to Files', justify=CENTER,command=self.WriteToFile)
self.WriteButton.grid(row=12, column=1)
if IN_AXIS:
self.quitButton1 = Button(self, text='Write LEFT to AXIS and Quit', command=self.WriteLeftToAxis)
self.quitButton1.grid(row=12, column=2, sticky=E)
self.quitButton2 = Button(self, text='Write RIGHT to AXIS and Quit', command=self.WriteRightToAxis)
self.quitButton2.grid(row=12, column=3, sticky=E)
self.quitButton3 = Button(self, text='Write BOTH to AXIS and Quit', command=self.WriteBothToAxis)
self.quitButton3.grid(row=12, column=4, sticky=E)
else:
self.quitButton = Button(self, text=' Quit Wing G-code', justify=CENTER,command=self.MyQuit)
self.quitButton.grid(row=12, column=3 ,pady=8)
def MyQuit(self):
if IN_AXIS:
sys.stdout.write('%')
self.quit()
else:
self.quit()
#python makes number formatting so hard....
def Format(self,val,dec):
s = '%0.' + str(int(dec)) + 'f'
return s % val
#get all the values from the widgets
def GetWValues(self):
self.modelname = self.ModelNameVar.get()
self.wingspan = self.FToD(self.WingSpanVar.get())
self.washout = self.FToD(self.WashoutVar.get())
self.rootchord = self.FToD(self.RootChordVar.get())
self.tipchord = self.FToD(self.TipChordVar.get())
items = self.RootProfilelistbox.curselection()
self.rootfile = self.RootProfilelistbox.get(items[0])
#do not use ACTIVE for this
items = self.TipProfilelistbox.curselection()
self.tipfile = self.TipProfilelistbox.get(items[0])
self.foamchord = self.FToD(self.FoamChordVar.get())
self.foamthickness = self.FToD(self.FoamThicknessVar.get())
self.trail = self.FToD(self.TrailingEdgeLimitVar.get())
self.sweep = self.FToD(self.LeadingEdgeSweepVar.get())
self.gantry = self.FToD(self.GantryLengthVar.get())
self.feedrate = self.FToD(self.FeedrateVar.get())
if self.feedrate == 0:
self.feedrate = 1
self.g_code.insert(END,'WARNING: feedrate cannot be ZERO\n')
self.xy = self.XYsideVar.get()
self.xyuv = self.XYUVVar.get()
if self.xyuv == 3:
self.xyuv = 0
self.grblmode = True
else:
self.grblmode = False
self.unit = self.UnitVar.get()
if self.unit:
self.units = '"'
else:
self.units = 'mm'
def Header(self,alist):
alist.append('%\n')
line = 'G17\nG90\n'
if self.UnitVar.get()==1:
line = line + 'G20\n'
dec = 3
self.Safe = 0.1 # 0.1 inch
else:
line = line + 'G21\n'
self.Safe = 1 #1 mm
dec = 1
if self.grblmode == FALSE:
line = line + 'M3 S100 '
if len(self.FeedrateVar.get())>0:
line = line + 'F%s\n' % self.FeedrateVar.get()
else:
line = line + '\n'
alist.append(line)
#these tell LinuxCNC where to put the XY and UV on the screen
line = "(AXIS,XY_Z_POS,0)\n"
alist.append(line)
line = "(AXIS,UV_Z_POS,%.3f)\n" % (self.gantry)
alist.append(line)
alist.append('(modelname ' + self.modelname + ')\n')
alist.append('(wingspan ' + self.Format(self.wingspan,dec) + ')\n')
alist.append('(rootchord ' + self.Format(self.rootchord,dec) + ')\n')
alist.append('(tipchord ' + self.Format(self.tipchord,dec) + ')\n')
alist.append('(rootfile ' + self.rootfile + ')\n')
alist.append('(tipfile ' + self.tipfile + ')\n')
alist.append('(foamchord ' + self.Format(self.foamchord,dec) + ')\n')
alist.append('(foamthickness ' + self.Format(self.foamthickness,dec) + ')\n')
alist.append('(trail ' + self.Format(self.trail,dec) + ')\n')
alist.append('(sweep ' + self.Format(self.sweep,dec) + ')\n')
alist.append('(washout ' + self.Format(self.washout,dec) + ')\n')
alist.append('(carriage ' + self.Format(self.gantry,dec) + ')\n')
alist.append('(feedrate ' + self.Format(self.feedrate,dec) + ')\n')
if (self.xy == 0):
alist.append('(xy right)\n')
else:
alist.append('(xy left)\n')
if (self.unit == 0):
alist.append('(unit MM)\n')
else:
alist.append('(unit inch)\n')
alist.append('(NOTE 0,0 is wire on table at front foam corner)\n')
def GenCode(self):
""" will generate all three gcode files as string lists """
self.g_code_left = []
self.g_code_right = []
self.g_code_both = []
self.g_code.delete("1.0",END)
self.GetWValues()
if (self.wingspan >= self.gantry):
self.g_code.insert(END,"PANIC: wingspan greater than carriage separation\n")
return None
#print "sweep %f" % self.sweep
self.gap = (self.gantry - self.wingspan) / 2 # gap between end of wing and gantry on each side
self.teoff = self.rootchord - self.sweep - self.tipchord # opposite of sweep
if (self.teoff < 0):
self.g_code.insert(END, " Swept Wing\n")
#print "teoff %f" %self.teoff
self.t1 = atan(self.sweep / self.wingspan)
self.t2 = atan(self.teoff / self.wingspan)
self.E1 = tan(self.t1) * self.gap
self.E2 = tan(self.t2) * self.gap
self.E3 = tan(self.t1) * (self.wingspan + self.gap)
self.E4 = tan(self.t2) * (self.wingspan + self.gap)
self.debug = 0
if self.debug:
print("E1 %0.4f" % self.E1)
print("E2 %0.4f" % self.E2)
print("E3 %0.4f" % self.E3)
print("E4 %0.4f" % self.E4)
self.rootlength = self.rootchord + self.E1 + self.E2 # gantry movement for root
if (self.teoff < 0):
self.waste = self.E1 # # wastage at trailing edge of tip profile
else:
self.waste = self.E2 # # wastage at trailing edge of root profile
self.tiplength = self.rootchord - self.E3 - self.E4 # gantry movement for tip
if (self.debug):
print("rootlength %0.4f" % self.rootlength)
print("tiplength %0.4f" % self.tiplength)
if (self.tiplength < 0):
self.g_code.insert(END, "\n PANIC: tip length is negative, I cannot plot this,\n you need to put the gantry closer together\n")
return None
self.toffset = self.E2 + self.E4 # tip offset for tip gantry
if (self.debug):
print("toffset %0.4f" % self.toffset)
self.g_code.insert(END, "rootfile " + self.rootfile + '\n')
self.g_code.insert(END, "tipfile " + self.tipfile + '\n')
#root file
if not(os.path.exists(self.rootfile)):
self.rootfile = os.path.join(self.DatDir, self.rootfile)
#tip
if not(os.path.exists(self.tipfile)):
self.tipfile = os.path.join(self.DatDir,self.tipfile)
if (not(os.path.exists(self.rootfile)) or not(os.path.exists(self.tipfile))):
self.g_code.insert(END, " PANIC: either root or tip file not found\n")
return None
# trailing edge thickness limit, does not work if number of points is low
if (self.trail > 0):
self.g_code.insert(END," Trailing edge " + str(self.trail) + '\n' )
# foam management
self.skintop = 0
self.skinbot = 0
# assume start at trailing edge on root and tip+self.toffset profile, wire on platten at 0,0
# then feed top surface
# then bottom
# then feed out
with open(self.rootfile) as f:
self.rootprofile = f.read().splitlines()
with open(self.tipfile) as f:
self.tipprofile = f.read().splitlines()
self.rootprofile = self.stripfile(self.rootprofile)
self.tipprofile = self.stripfile(self.tipprofile) # get rid of comment lines
if (len(self.rootprofile) != len(self.tipprofile)):
#self.g_code.insert(END," ERROR profile point counts not equal (%d,%d)\n" % (len(self.rootprofile) , len(self.tipprofile)))
#return None
if (len(self.rootprofile) > len(self.tipprofile)):
self.g_code.insert(END, "root bigger, resampling tip")
self.tipprofile = self.resample(self.rootprofile, self.tipprofile)
else:
self.g_code.insert(END,"tip bigger, resmapling root")
self.rootprofile = self.resample(self.tipprofile, self.rootprofile)
self.FindThicknessesRoot()
if self.debug: print("Actualrootthick " + str(self.actualrootthick))
self.CreateTip()
if self.washout != 0.0:
self.tip = self.rotatePolygon(self.tip, -self.washout) # rotate nose down, keep trailing edge straight
self.FindThicknessesTip()
self.TrailingEdgeLimits2()
self.FindStartPoints()
# info
self.g_code.insert(END, " startpoint sp= %0.3f%s above platten\n" % (self.sp, self.units) )
if self.need == 0:
self.g_code.insert(END, " startpoint spL= %0.3f%s above platten\n" % (self.spl, self.units))
self.g_code.insert(END, " startpoint spR= %0.3f%s above platten\n" % (self.spr, self.units))
self.l = self.rootchord + self.waste
if (self.debug):
print("L %.2f waste %.2f" % (self.l,self.waste))
if (self.l > self.foamchord):
self.g_code.insert(END, "WARNING: root length + waste(%.2f) is greater than the foam chord(%.2f) you specified\n" % (self.l, self.foamchord))
# Generate the G-Codes
self.Header(self.g_code_left)
self.Header(self.g_code_right)
self.Header(self.g_code_both)
if self.xy:
self.g_code.insert(END, 'XY carriage left\n')
else:
self.g_code.insert(END, 'XY carriage right\n')
# os.path.join(self.NcFileDirectory, self.modelname, '-right' + self.ext)
# os.path.join(self.NcFileDirectory, self.modelname, '-left' + self.nc)
# os.path.join(self.NcFileDirectory, self.modelname,'-both' + self.nc)
if (self.xy): #XY on left
self.plot(self.root, self.tip, 'right', self.g_code_right, self.sp, 1, 0)
self.plot(self.tip, self.root,'left' , self.g_code_left, self.sp, 1, 0)
if (self.need == 0):
self.g_code.insert(END, "Doing BOTH file\n")
self.plot(self.root, self.tip, 'right', self.g_code_both, self.spl, 1, 1)
self.plot(self.root, self.tip, 'right' , self.g_code_both, self.spr, -1, 1)
else:
self.g_code.insert(END, "Did not output BOTH file since foam is not thick enough\n")
else: #XY on right
self.plot(self.root, self.tip, 'left', self.g_code_left, self.sp, 1, 0)
self.plot(self.tip, self.root,'right' , self.g_code_right, self.sp, 1, 0)
# output combined foils for GRBL XYUV
if (self.need == 0):
self.g_code.insert(END, "Doing BOTH file\n")
self.plot(self.root, self.tip, 'left', self.g_code_both, self.spl, 1, 1)
self.plot(self.root, self.tip, 'left' , self.g_code_both, self.spr, -1, 1)
else:
self.g_code.insert(END, "Did not output BOTH file since foam is not thick enough\n")
#for line in self.g_code_left:
# self.g_code.insert(END, line)
"""
p1 first airfoil data
p2 seconds airfoil data
direc 'left' or 'right' for direction
fname the filename
sp start point , distance above X Zero
invert 1 for normal, -1 for invert
flag 0 for normal, 1 for BOTH mode
"""
def plot(self, p1, p2, direc, flist, sp, invert, flag):
#global $inch, $units, $trail, $E2, $wingspan, $params, $rootymax, $rootymin, $tipymax, $tipymin, self.toffset, $feedspeed, $rootlength, $tiplength, $waste, $foamthick, $foamchord, $skintop, $skinbot, $xy;
# if (flag):
# if (invert == 1):
# flist.append("%%\n")
# else:
# flist.append( "%%\n");
flist.append( "(Generated by wing.py. David the Swarfer, 2017, rcKeith 2021 for GRBL )\n")
flist.append( "(from ini file root " + os.path.basename(self.rootfile) + " tip " + os.path.basename(self.tipfile) + " offset %.2f )\n" % (self.toffset))
if (self.toffset > 0):
flist.append( "(minimum material chord is %0.1f with wastage of %.3f at trailing edge)\n" % (self.rootlength, self.waste))
else:
mmc = self.rootchord + self.waste
w = -self.E2
flist.append( "(Swept Wing)\n")
flist.append( "(minimum material chord is %0.3f%s with wastage of %0.3f%s at trailing edge)\n" % (mmc, self.units,w,self.units))
if (self.xyuv != 0):
flist.append("(generating cartesian gantry, taper ignored)\n")
flist.append( "(root carriage thickness = %0.1f%s)\n" % (self.rootymax - self.rootymin, self.units))
flist.append( "(tip carriage thickness = %0.1f%s)\n" % (self.tipymax - self.tipymin, self.units))
if (self.rootlength != self.tiplength):
flist.append( "(above sizes are for carriage travel, actual wing will be thinner)\n")
if (self.foamchord and self.foamthickness):
ws = self.wingspan
flist.append( "(foam block %.3f'wingspan' x %.3f x %.3f%s)\n" % (ws,self.foamchord,self.foamthickness,self.units));
if (self.xyuv == 0):
if (self.xy):
flist.append( "(XY carriage left)\n")
else:
flist.append( "(XY carriage right)\n")
else:
if (self.xyuv == 1):
self.g_code.insert(END, "YZ")
flist.append( "(YZ carriage)\n")
else:
self.g_code.insert(END, "XZ" )
flist.append( "(XZ carriage)\n")
#z = 0 - self.rootymin
flist.append( "(trailing edge will be AT LEAST %0.1f%s above bottom of panel)\n" % (self.sp, self.units))
#if (self.trail > 0):
# flist.append( "(Trailing edge limit %0.2f%s)\n" % (self.trail, self.units))
if (self.unit):
flist.append( "G20\n"); # inch mode
prec = '%0.4f' # thous/10 for inch mode
retract = -0.25
else:
flist.append( "G21\n") # metric mode
prec = '%0.3f' # 1/1000 mm for metricmode
retract = -5.0
if (self.xyuv == 0):
flist.append( "G90\n")
if self.grblmode == True:
flist.append("G49 \n")
else:
flist.append("G49 G64 P0.01\n") #G64 not implemented in GBRL
else:
flist.append( "G90 G49\n")
if self.debug: print("prec " + str(prec))
# you will need to add in any other header codes you need, here
if self.debug:
print(retract)
print(sp)
print(self.feedrate)
if (self.xyuv == 0):
if self.grblmode:
fmt = "G00 X"+prec+" Y"+prec+" U"+prec+" Z"+prec+" F%0.1f\n"
else:
fmt = "G00 X"+prec+" Y"+prec+" U"+prec+" V"+prec+" F%0.1f\n"
else:
if (self.xyuv == 1): # YZ
fmt = "G00 Y"+prec+" Z"+prec+" F%0.1f\n"
else: #XZ
fmt = "G00 X"+prec+" Z"+prec+" F%0.1f\n"
#start heights, sp + offset of first point on top surface
if flag and (invert == -1):
#doing an upside down profile, do lower side first, ie run loop backwards
start = len(p1) - 1
else:
start = 0
if (self.xy): # XY gantry on left
if (direc == 'right'): # means second profile is smaller,
shXY = sp + p1[start][1]
shUV = sp + p2[start][1]
else:
shXY = sp + p2[start][1]
shUV = sp + p1[start][1]
else: # XY gantry on right
if (direc == 'left'): # means second profile is smaller,
shXY = sp + p1[start][1]
shUV = sp + p2[start][1]
else:
shXY = sp + p2[start][1]
shUV = sp + p1[start][1]
flist.append("(seek to start height)\n")
if (self.xyuv == 0):
flist.append( fmt % (retract,shXY,retract,shUV,self.feedrate)) # EMC bleats if no feed speed on first G0 instructions
else:
flist.append( fmt % (retract,shXY,self.feedrate))
spt = [0,shXY,0,shUV]
# do skins and then cut, assume wire 0,0 on surface of platten
self.g_code.insert(END, " doing '%s' with Foamthick %.3f%s\n" % (direc,self.foamthickness, self.units))
"""
if (($skintop > 0) || ($skinbot > 0) && ( ($foamthick >0) && ($foamchord > 0) ))
{
fprintf($of, "(skinning $skintop $skinbot on block $wingspan x $foamchord x $foamthick)\n");
$top = $foamthick - $skintop;
fprintf($of,"G00 Y%0.2f V%0.2f\n",$top,$top);
$fc = $foamchord + 5;
fprintf($of,"G01 X%0.1f U%0.1f\n",$fc,$fc);
fprintf($of,"G00 Y%0.2f V%0.2f\n",$skinbot,$skinbot);
fprintf($of,"G01 X-5 U-5\n");
fprintf($of,"G00 Y%0.2f V%0.2f\n",$sp,$sp);
}
else
fprintf($of, "(no skins)\n");
"""
# seek to start point
# must create the format string before using it
if (self.xyuv == 0):
if self.grblmode:
fmt = "G01 X"+prec+" Y"+prec+" U"+prec+" Z"+prec+"\n"
else:
fmt = "G01 X"+prec+" Y"+prec+" U"+prec+" V"+prec+"\n"
else:
if (self.xyuv == 1):
fmt = "G01 Y"+prec+" Z"+prec+"\n"
else:
fmt = "G01 X"+prec+" Z"+prec+"\n"
if (self.xyuv != 0) and (self.toffset != 0):
flist.append("(Need a Straight wing please)\n")
self.g_code.insert(END, " Straight wings only! aborting")
return
#else:
#flist.append("(do we need a seek to trailing edge here?)\n")
if (self.toffset > 0):
flist.append("(seek to trailing edge)\n")
if (self.xy): # XY gantry on left
if (direc == 'right'): # means second profile is smaller,
spt = [0,shXY, self.toffset, shUV]
flist.append( fmt % (0,shXY, self.toffset, shUV))
else:
spt = [self.toffset,shXY,0,shUV]
flist.append( fmt % (self.toffset,shXY,0,shUV)) # first profile smaller
else: # XY gantry on right
if (direc == 'left'): # means second profile is smaller,
spt = [0,shXY,self.toffset,shUV]
flist.append( fmt % (0,shXY,self.toffset,shUV))
else:
spt = [ self.toffset,shXY,0,shUV]
flist.append( fmt % (self.toffset,shXY,0,shUV)) # first profile smaller
if (self.toffset < 0):
flist.append("(seek to trailing edge, swept)\n" )
if (self.xy): # XY gantry on left
if (direc == 'right'): # means second profile is smaller,
spt = [-self.toffset, shXY,0,shUV]
flist.append( fmt % (-self.toffset, shXY,0,shUV))
else:
spt = [ 0,shXY,-self.toffset,shUV]
flist.append( fmt % (0,shXY,-self.toffset,shUV)) # first profile smaller
else: # XY gantry on right
if (direc == 'left'): # means second profile is smaller,
spt = [-self.toffset,shXY,0,shUV]
flist.append( fmt % (-self.toffset,shXY,0,shUV))
else:
spt =[0,shXY,-self.toffset,shUV]
flist.append( fmt % (0,shXY,-self.toffset,shUV)) # first profile smaller
#$xoffset = ($toffset < 0) ? -$toffset : 0;
#$uoffset = ($toffset < 0) ? 0 : $toffset ;
if (self.toffset < 0):
xoffset = -self.toffset
uoffset = 0
else:
xoffset = 0
uoffset = self.toffset
if flag and (invert == -1):
#doing an upside down profile, do lower side first, ie run loop backwards
start = len(p1) - 1
end = -1
step = -1
else:
#do top surface first as normal
start = 0
end = len(p1)
step = 1
#print "%d %d %d" %(start,end,step)
#print len(p1), len(p2)
flist.append("(do profile)\n" )
for idx in range(start, end, step):
#print "idx %d" % idx
if (self.xyuv == 0):
if (self.xy): # XY gantry on left
if (direc == 'right'):
flist.append(fmt % (p1[idx][0] + xoffset, sp + p1[idx][1] * invert, p2[idx][0] + uoffset, sp + p2[idx][1] * invert))
else:
flist.append(fmt % (p1[idx][0] + uoffset, sp + p1[idx][1] * invert, p2[idx][0] + xoffset, sp + p2[idx][1] * invert))
else: # XY gantry on right
if (direc == 'left'):
flist.append(fmt % (p1[idx][0] + xoffset, sp + p1[idx][1] * invert, p2[idx][0] + uoffset, sp + p2[idx][1] * invert))
else:
flist.append(fmt % (p1[idx][0] + uoffset, sp + p1[idx][1] * invert, p2[idx][0] + xoffset, sp + p2[idx][1] * invert))
else:
#self.g_code.insert(END, fmt)
flist.append(fmt % (p1[idx][0] + xoffset, sp + p1[idx][1] * invert ))
#end idx loop
#close the trailing edge by going back to start point
flist.append("(close trailing edge)\n" )
if (self.xyuv == 0):
flist.append( fmt % (spt[0], spt[1], spt[2], spt[3]) )
else:
flist.append( fmt % (spt[0], spt[1]) )
if (self.xyuv != 0):
flist.append("G4 P0.075\n")
if self.unit:
retract = -0.25
else:
retract = -5
#retract
flist.append("(retract out of foam)\n" )
if (self.xyuv == 0):
flist.append( fmt % (retract,shXY,retract,shUV))
else:
flist.append( fmt % (retract*2,shXY))
flist.append("G4 P0.075\n")
if ( not(flag) or ( (invert == -1) and flag)):
if (self.xyuv == 0):
if self.grblmode:
fmt0 = "G00 X"+prec+" Y"+prec+" U"+prec+" Z"+prec+"\n"
else:
fmt0 = "G00 X"+prec+" Y"+prec+" U"+prec+" V"+prec+"\n"
flist.append( fmt0 % (2*retract,-2*retract,2*retract,-2*retract))
else:
if (self.xyuv == 1):
fmt0 = "G00 Y"+prec+" Z"+prec+"\n"
else:
fmt0 = "G00 X"+prec+" Z"+prec+"\n"
flist.append( fmt0 % (2*retract,-2*retract))
if (flag):
if (invert == -1):
flist.append("M5\nM30\n")
flist.append("%\n")
else:
flist.append("M5\nM30\n")
flist.append("%\n")
#end of plot()
status_bar_update("G-Code Generated")
def WriteLeftToAxis(self):
for line in self.g_code_left:
sys.stdout.write(line)
self.quit()
def WriteRightToAxis(self):
for line in self.g_code_right:
sys.stdout.write(line)
self.quit()
def WriteBothToAxis(self):
if len(self.g_code_both) > 100:
for line in self.g_code_both:
sys.stdout.write(line)
self.quit()
else:
self.g_code.insert(END,'ERROR: no BOTH data to write')
def SaveModel(self):
""" save an ini file like this
[drunk]
wingspan=770
root=340
tip=150
trail=1
sweep=50
gantry=900
rootfile=e374.dat
tipfile=e374.dat
foamchord=410
foamthick=50
feedspeed=345
xy=0
inch=0
"""
try:
""" save in ini in the NC folder """
self.NcFileDirectory = self.GetIniData(self.inifile,'Directories','NcFiles')
except:
tkinter.messagebox.showinfo('Missing INI Data', 'You must set the\n' \
'NC File Directory\n' \
'before saving a file.\n' \
'Go to Edit/NC Directory\n' \
'in the menu to set this option')
return
modelname = self.ModelNameVar.get()
modelname = modelname.strip()
if (modelname == ''):
tkinter.messagebox.showinfo('Need a model name in order to save a model')
return
inifile = self.NcFileDirectory +'/'+ modelname + '.ini'
config = configparser.ConfigParser()
# When adding sections or items, add them in the reverse order of
# how you want them to be displayed in the actual file.
# In addition, please note that using RawConfigParser's and the raw
# mode of ConfigParser's respective set functions, you can assign
# non-string values to keys internally, but will receive an error
# when attempting to write to a file or when you get it in non-raw
# mode. ConfigParser does not allow such assignments to take place.
config.add_section(modelname)
config.set(modelname, 'wingspan', self.WingSpanVar.get())
config.set(modelname, 'washout', self.WashoutVar.get())
config.set(modelname, 'root', self.RootChordVar.get())
config.set(modelname, 'tip' , self.TipChordVar.get())
items = self.RootProfilelistbox.curselection()
item = self.RootProfilelistbox.get(items[0])
config.set(modelname, 'rootfile', item)
items = self.TipProfilelistbox.curselection()
item = self.TipProfilelistbox.get(items[0])
config.set(modelname, 'tipfile', item)
config.set(modelname, 'foamchord', self.FoamChordVar.get())
config.set(modelname, 'foamthick', self.FoamThicknessVar.get())
config.set(modelname, 'trail', self.TrailingEdgeLimitVar.get())
config.set(modelname, 'sweep', self.LeadingEdgeSweepVar.get())
config.set(modelname, 'gantry', self.GantryLengthVar.get())
config.set(modelname, 'feedspeed', self.FeedrateVar.get())
xy = self.XYsideVar.get()
config.set(modelname, 'xy', str(xy))
unit = self.UnitVar.get()
config.set(modelname, 'inch', str(unit))
# Writing our configuration file to 'example.cfg'
with open(inifile, 'w') as configfile:
config.write(configfile)
self.g_code.insert(END, 'Saved model\n')
self.WriteIniData(self.inifile,'autoload','model',modelname) #write for autoload
status_bar_update("Model Settings Saved as " + modelname)
def ReadModel(self, filename):
config = configparser.ConfigParser()
config.read(filename)
#get the model name from the filename
modelname = os.path.splitext(os.path.basename(filename))[0]
if (config.has_section(modelname)):
self.ModelNameVar.set(modelname)
self.WingSpanVar.set( config.get(modelname, 'wingspan'))