forked from vlachoudis/bCNC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToolsPage.py
1509 lines (1358 loc) · 48.3 KB
/
ToolsPage.py
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
# -*- coding: ascii -*-
# $Id$
#
# Author: [email protected]
# Date: 24-Aug-2014
__author__ = "Vasilis Vlachoudis"
__email__ = "[email protected]"
import traceback
try:
from Tkinter import *
import tkMessageBox
except ImportError:
from tkinter import *
import tkinter.messagebox as tkMessageBox
from operator import attrgetter
import os
import time
import glob
import Utils
import Ribbon
import tkExtra
import Unicode
import CNCRibbon
from CNC import CNC
_EXE_FONT = ("Helvetica",12,"bold")
#===============================================================================
class InPlaceText(tkExtra.InPlaceText):
def defaultBinds(self):
tkExtra.InPlaceText.defaultBinds(self)
self.edit.bind("<Escape>", self.ok)
#==============================================================================
# Tools Base class
#==============================================================================
class _Base:
def __init__(self, master):
self.master = master
self.name = None
self.icon = None
self.plugin = False
self.variables = [] # name, type, default, label
self.values = {} # database of values
self.listdb = {} # lists database
self.current = None # currently editing index
self.n = 0
self.buttons = []
# ----------------------------------------------------------------------
def __setitem__(self, name, value):
if self.current is None:
self.values[name] = value
else:
self.values["%s.%d"%(name,self.current)] = value
# ----------------------------------------------------------------------
def __getitem__(self, name):
if self.current is None:
return self.values.get(name,"")
else:
return self.values.get("%s.%d"%(name,self.current),"")
# ----------------------------------------------------------------------
def gcode(self):
return self.master.gcode
# ----------------------------------------------------------------------
# Return a sorted list of all names
# ----------------------------------------------------------------------
def names(self):
lst = []
for i in range(1000):
key = "name.%d"%(i)
value = self.values.get(key)
if value is None: break
lst.append(value)
lst.sort()
return lst
# ----------------------------------------------------------------------
def _get(self, key, t, default):
if t in ("float","mm"):
return Utils.getFloat(self.name, key, default)
elif t == "int":
return Utils.getInt(self.name, key, default)
elif t == "bool":
return Utils.getInt(self.name, key, default)
else:
return Utils.getStr(self.name, key, default)
# ----------------------------------------------------------------------
# Override with execute command
# ----------------------------------------------------------------------
def execute(self, app):
pass
# ----------------------------------------------------------------------
# Update variables after edit command
# ----------------------------------------------------------------------
def update(self):
return False
# ----------------------------------------------------------------------
def event_generate(self, msg, **kwargs):
self.master.listbox.event_generate(msg, **kwargs)
# ----------------------------------------------------------------------
def beforeChange(self, app):
pass
# ----------------------------------------------------------------------
def populate(self):
self.master.listbox.delete(0,END)
for n, t, d, l in self.variables:
value = self[n]
if t == "bool":
if value:
value = Unicode.BALLOT_BOX_WITH_X
else:
value = Unicode.BALLOT_BOX
elif t == "mm" and self.master.inches:
try:
value /= 25.4
value = round(value, self.master.digits)
except:
value = ""
elif t == "float":
try:
value = round(value, self.master.digits)
except:
value = ""
#elif t == "list":
# value += " " + Unicode.BLACK_DOWN_POINTING_TRIANGLE
self.master.listbox.insert(END, (l, value))
if t=="color":
try:
self.master.listbox.lists[1].itemconfig(END, background=value)
except TclError:
pass
#----------------------------------------------------------------------
def _sendReturn(self, active):
self.master.listbox.selection_clear(0,END)
self.master.listbox.selection_set(active)
self.master.listbox.activate(active)
self.master.listbox.see(active)
n, t, d, l = self.variables[active]
if t=="bool": return # Forbid changing value of bool
self.master.listbox.event_generate("<Return>")
#----------------------------------------------------------------------
def _editPrev(self):
active = self.master.listbox.index(ACTIVE)-1
if active<0: return
self._sendReturn(active)
#----------------------------------------------------------------------
def _editNext(self):
active = self.master.listbox.index(ACTIVE)+1
if active>=self.master.listbox.size(): return
self._sendReturn(active)
#----------------------------------------------------------------------
# Make current "name" from the database
#----------------------------------------------------------------------
def makeCurrent(self, name):
if not name: return
# special handling
for i in range(1000):
if name==self.values.get("name.%d"%(i)):
self.current = i
self.update()
return True
return False
#----------------------------------------------------------------------
# Edit tool listbox
#----------------------------------------------------------------------
def edit(self, event=None, rename=False):
lb = self.master.listbox.lists[1]
if event is None or event.type=="2":
keyboard = True
else:
keyboard = False
if keyboard:
# keyboard event
active = lb.index(ACTIVE)
else:
active = lb.nearest(event.y)
self.master.listbox.activate(active)
ypos = lb.yview()[0] # remember y position
save = lb.get(ACTIVE)
n, t, d, l = self.variables[active]
if t == "int":
edit = tkExtra.InPlaceInteger(lb)
elif t in ("float", "mm"):
edit = tkExtra.InPlaceFloat(lb)
elif t == "bool":
edit = None
value = int(lb.get(active) == Unicode.BALLOT_BOX)
if value:
lb.set(active, Unicode.BALLOT_BOX_WITH_X)
else:
lb.set(active, Unicode.BALLOT_BOX)
elif t == "list":
edit = tkExtra.InPlaceList(lb, values=self.listdb[n])
elif t == "db":
if n=="name":
# Current database
if rename:
edit = tkExtra.InPlaceEdit(lb)
else:
edit = tkExtra.InPlaceList(lb, values=self.names())
else:
# Refers to names from another database
tool = self.master[n]
names = tool.names()
names.insert(0,"")
edit = tkExtra.InPlaceList(lb, values=names)
elif t == "text":
edit = InPlaceText(lb)
elif "," in t:
choices = [""]
choices.extend(t.split(","))
edit = tkExtra.InPlaceList(lb, values=choices)
elif t == "file":
edit = tkExtra.InPlaceFile(lb, save=False)
elif t == "output":
edit = tkExtra.InPlaceFile(lb, save=True)
elif t == "color":
edit = tkExtra.InPlaceColor(lb)
if edit.value is not None:
try:
lb.itemconfig(ACTIVE, background=edit.value)
except TclError:
pass
else:
edit = tkExtra.InPlaceEdit(lb)
if edit is not None:
value = edit.value
if value is None:
return
if value == save:
if edit.lastkey == "Up":
self._editPrev()
elif edit.lastkey in ("Return", "KP_Enter", "Down"):
self._editNext()
return
if t == "int":
try:
value = int(value)
except ValueError:
value = ""
elif t in ("float","mm"):
try:
value = float(value)
if t=="mm" and self.master.inches:
value *= 25.4
except ValueError:
value = ""
if n=="name" and not rename:
if self.makeCurrent(value):
self.populate()
else:
self[n] = value
if self.update():
self.populate()
self.master.listbox.selection_set(active)
self.master.listbox.activate(active)
self.master.listbox.yview_moveto(ypos)
if edit is not None and not rename:
if edit.lastkey == "Up":
self._editPrev()
elif edit.lastkey in ("Return", "KP_Enter", "Down") and active>0:
self._editNext()
#==============================================================================
# Additional persistence class for config
#==============================================================================
#class _Config:
# ----------------------------------------------------------------------
# Load from a configuration file
# ----------------------------------------------------------------------
def load(self):
# Load lists
lists = []
for n, t, d, l in self.variables:
if t=="list":
lists.append(n)
if lists:
for p in lists:
self.listdb[p] = []
for i in range(1000):
key = "_%s.%d"%(p, i)
value = Utils.getStr(self.name, key).strip()
if value:
self.listdb[p].append(value)
else:
break
# Check if there is a current
try:
self.current = int(Utils.config.get(self.name, "current"))
except:
self.current = None
# Load values
if self.current is not None:
self.n = self._get("n", "int", 0)
for i in range(self.n):
key = "name.%d"%(i)
self.values[key] = Utils.getStr(self.name, key)
for n, t, d, l in self.variables:
key = "%s.%d"%(n,i)
self.values[key] = self._get(key, t, d)
else:
for n, t, d, l in self.variables:
self.values[n] = self._get(n, t, d)
self.update()
# ----------------------------------------------------------------------
# Save to a configuration file
# ----------------------------------------------------------------------
def save(self):
# if section do not exist add it
Utils.addSection(self.name)
if self.listdb:
for name,lst in self.listdb.items():
for i,value in enumerate(lst):
Utils.setStr(self.name, "_%s.%d"%(name,i), value)
# Save values
if self.current is not None:
Utils.setStr(self.name, "current", str(self.current))
Utils.setStr(self.name, "n", str(self.n))
for i in range(self.n):
key = "name.%d"%(i)
value = self.values.get(key)
if value is None: break
Utils.setStr(self.name, key, value)
for n, t, d, l in self.variables:
key = "%s.%d"%(n,i)
Utils.setStr(self.name, key,
str(self.values.get(key,d)))
else:
for n, t, d, l in self.variables:
Utils.setStr(self.name, n, str(self.values.get(n,d)))
# ----------------------------------------------------------------------
def fromMm(self, name, default=0.0):
try:
return self.master.fromMm(float(self[name]))
except ValueError:
return default
#==============================================================================
# Base class of all databases
#==============================================================================
class DataBase(_Base):
def __init__(self, master):
_Base.__init__(self, master)
self.buttons = ["add","delete","clone","rename"]
# ----------------------------------------------------------------------
# Add a new item
# ----------------------------------------------------------------------
def add(self, rename=True):
self.current = self.n
self.values["name.%d"%(self.n)] = "%s %02d"%(self.name, self.n+1)
self.n += 1
self.populate()
if rename:
self.rename()
# ----------------------------------------------------------------------
# Delete selected item
# ----------------------------------------------------------------------
def delete(self):
if self.n==0: return
for n, t, d, l in self.variables:
for i in range(self.current, self.n):
try:
self.values["%s.%d"%(n,i)] = self.values["%s.%d"%(n,i+1)]
except KeyError:
try:
del self.values["%s.%d"%(n,i)]
except KeyError:
pass
self.n -= 1
if self.current >= self.n:
self.current = self.n - 1
self.populate()
# ----------------------------------------------------------------------
# Clone selected item
# ----------------------------------------------------------------------
def clone(self):
if self.n==0: return
for n, t, d, l in self.variables:
try:
if n=="name":
self.values["%s.%d"%(n,self.n)] = \
self.values["%s.%d"%(n,self.current)] + " clone"
else:
self.values["%s.%d"%(n,self.n)] = \
self.values["%s.%d"%(n,self.current)]
except KeyError:
pass
self.n += 1
self.current = self.n - 1
self.populate()
# ----------------------------------------------------------------------
# Rename current item
# ----------------------------------------------------------------------
def rename(self):
self.master.listbox.selection_clear(0,END)
self.master.listbox.selection_set(0)
self.master.listbox.activate(0)
self.master.listbox.see(0)
self.edit(None,True)
#==============================================================================
class Plugin(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.plugin = True
self.group = "Macros"
#==============================================================================
# Generic ini configuration
#==============================================================================
class Ini(_Base):
def __init__(self, master, name, vartype):
_Base.__init__(self, master)
self.name = name
# detect variables from ini file
self.variables = []
for name,value in Utils.config.items(self.name):
self.variables.append((name, vartype, value, name))
#------------------------------------------------------------------------------
class Font(Ini):
def __init__(self, master):
Ini.__init__(self, master, "Font", "str")
#------------------------------------------------------------------------------
class Color(Ini):
def __init__(self, master):
Ini.__init__(self, master, "Color", "color")
#------------------------------------------------------------------------------
class Camera(Ini):
def __init__(self, master):
Ini.__init__(self, master, "Camera", "int")
#------------------------------------------------------------------------------
class Events(Ini):
def __init__(self, master):
Ini.__init__(self, master, "Events", "str")
#------------------------------------------------------------------------------
class Shortcut(Ini):
def __init__(self, master):
Ini.__init__(self, master, "Shortcut", "str")
self.buttons.append("exe")
#----------------------------------------------------------------------
def execute(self, app):
self.save()
app.loadShortcuts()
#==============================================================================
# CNC machine configuration
#==============================================================================
class Config(_Base):
def __init__(self, master):
_Base.__init__(self, master)
self.name = "CNC"
self.variables = [
("units" , "bool", 0 , _("Units (inches)")) ,
("lasercutter" , "bool", 0 , _("Lasercutter")) ,
("doublesizeicon", "bool", 0 , _("Double Size Icon")) ,
("acceleration_x", "mm" , 25.0 , _("Acceleration x")) ,
("acceleration_y", "mm" , 25.0 , _("Acceleration y")) ,
("acceleration_z", "mm" , 5.0 , _("Acceleration z")) ,
("feedmax_x" , "mm" , 3000., _("Feed max x")) ,
("feedmax_y" , "mm" , 3000., _("Feed max y")) ,
("feedmax_z" , "mm" , 2000., _("Feed max z")) ,
("travel_x" , "mm" , 200 , _("Travel x")) ,
("travel_y" , "mm" , 200 , _("Travel y")) ,
("travel_z" , "mm" , 100 , _("Travel z")) ,
("round" , "int" , 4 , _("Decimal digits")) ,
("accuracy" , "mm" , 0.1 , _("Plotting Arc accuracy")),
("startup" , "str" , "G90", _("Start up")) ,
("spindlemin" , "int" , 0 , _("Spindle min (RPM)")),
("spindlemax" , "int" , 12000, _("Spindle max (RPM)")),
("drozeropad" , "int" , 0 , _("DRO Zero padding")),
("header" , "text" , "", _("Header gcode")),
("footer" , "text" , "", _("Footer gcode"))
]
# ----------------------------------------------------------------------
# Update variables after edit command
# ----------------------------------------------------------------------
def update(self):
self.master.inches = self["units"]
self.master.digits = int(self["round"])
self.master.cnc().decimal = self.master.digits
self.master.cnc().startup = self["startup"]
self.master.gcode.header = self["header"]
self.master.gcode.footer = self["footer"]
return False
#==============================================================================
# Material database
#==============================================================================
class Material(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.name = "Material"
self.variables = [
("name", "db", "", _("Name")),
("comment","str", "", _("Comment")),
("feed", "mm" , 10., _("Feed")),
("feedz", "mm" , 1., _("Plunge Feed")),
("stepz", "mm" , 1., _("Depth Increment"))
]
# ----------------------------------------------------------------------
# Update variables after edit command
# ----------------------------------------------------------------------
def update(self):
# update ONLY if stock material is empty:
stockmat = self.master["stock"]["material"]
if stockmat=="" or stockmat==self["name"]:
self.master.cnc()["cutfeed"] = self.fromMm("feed")
self.master.cnc()["cutfeedz"] = self.fromMm("feedz")
self.master.cnc()["stepz"] = self.fromMm("stepz")
return False
#==============================================================================
# EndMill Bit database
#==============================================================================
class EndMill(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.name = "EndMill"
self.variables = [
("name", "db", "", _("Name")),
("comment", "str", "", _("Comment")),
("type", "list", "", _("Type")),
("shape", "list", "", _("Shape")),
("material", "list", "", _("Material")),
("coating", "list", "", _("Coating")),
("diameter", "mm", 3.175, _("Diameter")),
("axis", "mm", 3.175, _("Mount Axis")),
("flutes", "int", 2, _("Flutes")),
("length", "mm", 20.0, _("Length")),
("angle", "float", "", _("Angle")),
("stepover","float", 40.0, _("Stepover %"))
]
# ----------------------------------------------------------------------
# Update variables after edit command
# ----------------------------------------------------------------------
def update(self):
self.master.cnc()["diameter"] = self.fromMm("diameter")
self.master.cnc()["stepover"] = self["stepover"]
return False
#==============================================================================
# Stock material on worksurface
#==============================================================================
class Stock(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.name = "Stock"
self.variables = [
("name", "db" , "", _("Name")),
("comment", "str", "", _("Comment")),
("material", "db" , "", _("Material")),
("safe" , "mm" , 3.0, _("Safe Z")),
("surface", "mm" , 0.0, _("Surface Z")),
("thickness", "mm" , 5.0, _("Thickness"))
]
# ----------------------------------------------------------------------
# Update variables after edit command
# ----------------------------------------------------------------------
def update(self):
self.master.cnc()["safe"] = self.fromMm("safe")
self.master.cnc()["surface"] = self.fromMm("surface")
self.master.cnc()["thickness"] = self.fromMm("thickness")
if self["material"]:
self.master["material"].makeCurrent(self["material"])
return False
#==============================================================================
# Cut material
#==============================================================================
class Cut(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.name = "Cut"
self.variables = [
("name", "db" , "", _("Name")),
("surface", "mm" , "", _("Surface Z")),
("depth" , "mm" , "", _("Target Depth")),
("stepz" , "mm" , "", _("Depth Increment")),
("feed", "mm" , "", _("Feed")),
("feedz", "mm" , "", _("Plunge Feed")),
("cutFromTop", "bool" , False, _("First cut at surface height"))
]
self.buttons.append("exe")
# ----------------------------------------------------------------------
def execute(self, app):
surface = self.fromMm("surface", None)
depth = self.fromMm("depth", None)
step = self.fromMm("stepz", None)
try: feed = self.fromMm("feed", None)
except: feed = None
try: feedz = self.fromMm("feedz", None)
except: feedz = None
cutFromTop = self["cutFromTop"]
app.executeOnSelection("CUT", True, depth, step, surface, feed, feedz, cutFromTop)
app.setStatus(_("CUT selected paths"))
#==============================================================================
# Drill material
#==============================================================================
class Drill(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.name = "Drill"
self.variables = [
("name", "db" , "", _("Name")),
("depth", "mm" , "", _("Target Depth")),
("peck", "mm" , "", _("Peck depth")),
("dwell", "float" , "", _("Dwell (s)")),
("distance", "mm" , "", _("Distance (mm)")),
("number", "int" , "", _("Number"))
]
self.buttons.append("exe")
# ----------------------------------------------------------------------
def execute(self, app):
h = self.fromMm("depth", None)
p = self.fromMm("peck", None)
e = self.fromMm("distance", None)
try:
d = self["dwell"]
except:
d = None
try:
n = int(self["number"])
except:
n = 0
app.executeOnSelection("DRILL", True, h, p, d, e, n)
app.setStatus(_("DRILL selected points"))
#==============================================================================
# Profile
#==============================================================================
class Profile(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.name = "Profile"
self.variables = [
("name", "db" , "", _("Name")),
("endmill", "db" , "", _("End Mill")),
("direction","inside,outside" , "outside", _("Direction")),
("offset", "float", 0.0, _("Additional offset distance")),
("overcut", "bool", 1, _("Overcut"))
]
self.buttons.append("exe")
# ----------------------------------------------------------------------
def execute(self, app):
if self["endmill"]:
self.master["endmill"].makeCurrent(self["endmill"])
direction = self["direction"]
name = self["name"]
if name=="default" or name=="": name=None
app.profile(direction, self["offset"], self["overcut"], name)
app.setStatus(_("Generate profile path"))
#==============================================================================
# Pocket
#==============================================================================
class Pocket(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.name = "Pocket"
self.variables = [
("name", "db" , "", _("Name")),
("endmill", "db" , "", _("End Mill")),
]
self.buttons.append("exe")
# ----------------------------------------------------------------------
def execute(self, app):
if self["endmill"]:
self.master["endmill"].makeCurrent(self["endmill"])
name = self["name"]
if name=="default" or name=="": name=None
app.pocket(name)
app.setStatus(_("Generate pocket path"))
#==============================================================================
# Tabs
#==============================================================================
class Tabs(DataBase):
def __init__(self, master):
DataBase.__init__(self, master)
self.name = "Tabs"
self.variables = [
("name", "db" , "", _("Name")),
("ntabs", "int", 5, _("Number of tabs")),
("dtabs", "mm", 0.0, _("Min. Distance of tabs")),
("dx", "mm", 5.0, "Dx"),
("dy", "mm", 5.0, "Dy"),
("z", "mm", -3.0, _("Height"))
]
self.buttons.append("exe")
# ----------------------------------------------------------------------
def execute(self,app):
try:
ntabs = int(self["ntabs"])
except:
ntabs = 0
dtabs = self.fromMm("dtabs", 0.)
dx = self.fromMm("dx", self.master.fromMm(5.))
dy = self.fromMm("dy", self.master.fromMm(5.))
z = self.fromMm("z", -self.master.fromMm(3.))
if ntabs<0: ntabs=0
if dtabs<0.: dtabs=0
if ntabs==0 and dtabs==0:
tkMessageBox.showerror(_("Tabs error"),
_("You cannot have both the number of tabs or distance equal to zero"))
app.executeOnSelection("TABS", True, ntabs, dtabs, dx, dy, z)
app.setStatus(_("Create tabs on blocks"))
#==============================================================================
# Controller setup
#==============================================================================
class Controller(_Base):
def __init__(self, master):
_Base.__init__(self, master)
self.name = "Controller"
self.variables = [
("grbl_0", "int", 10, _("$0 Step pulse time [us]")),
("grbl_1", "int", 25, _("$1 Step idle delay [ms]")),
("grbl_2", "int", 0, _("$2 Step pulse invert [mask]")),
("grbl_3", "int", 0, _("$3 Step direction invert [mask]")),
("grbl_4", "bool", 0, _("$4 Invert step enable pin")),
("grbl_5", "bool", 0, _("$5 Invert limit pins")),
("grbl_6", "bool", 0, _("$6 Invert probe pin")),
("grbl_10", "int", 1, _("$10 Status report options [mask]")),
("grbl_11", "float", 0.010, _("$11 Junction deviation [mm]")),
("grbl_12", "float", 0.002, _("$12 Arc tolerance [mm]")),
("grbl_13", "bool", 0, _("$13 Report in inches")),
("grbl_20", "bool", 0, _("$20 Soft limits enable")),
("grbl_21", "bool", 0, _("$21 Hard limits enable")),
("grbl_22", "bool", 0, _("$22 Homing cycle enable")),
("grbl_23", "int", 0, _("$23 Homing direction invert [mask]")),
("grbl_24", "float", 25., _("$24 Homing locate feed rate [mm/min]")),
("grbl_25", "float", 500., _("$25 Homing search seek rate [mm/min]")),
("grbl_26", "int", 250, _("$26 Homing switch debounce delay, ms")),
("grbl_27", "float", 1., _("$27 Homing switch pull-off distance [mm]")),
("grbl_30", "float", 1000., _("$30 Maximum spindle speed [RPM]")),
("grbl_31", "float", 0., _("$31 Minimum spindle speed [RPM]")),
("grbl_32", "bool", 0, _("$32 Laser-mode enable")),
("grbl_100", "float", 250., _("$100 X-axis steps per mm")),
("grbl_101", "float", 250., _("$101 Y-axis steps per mm")),
("grbl_102", "float", 250., _("$102 Z-axis steps per mm")),
("grbl_110", "float", 500., _("$110 X-axis maximum rate [mm/min]")),
("grbl_111", "float", 500., _("$111 Y-axis maximum rate [mm/min]")),
("grbl_112", "float", 500., _("$112 Z-axis maximum rate [mm/min]")),
("grbl_120", "float", 10., _("$120 X-axis acceleration [mm/sec^2]")),
("grbl_121", "float", 10., _("$121 Y-axis acceleration [mm/sec^2]")),
("grbl_122", "float", 10., _("$122 Z-axis acceleration [mm/sec^2]")),
("grbl_130", "float", 200., _("$130 X-axis maximum travel [mm]")),
("grbl_131", "float", 200., _("$131 Y-axis maximum travel [mm]")),
("grbl_132", "float", 200., _("$132 Z-axis maximum travel [mm]"))]
self.buttons.append("exe")
# ----------------------------------------------------------------------
def execute(self, app):
lines = []
for n,t,d,c in self.variables:
v = self[n]
try:
if t=="float":
if v == float(CNC.vars[n]): continue
else:
if v == int(CNC.vars[n]): continue
except:
continue
lines.append("$%s=%s"%(n[5:],str(v)))
lines.append("%wait")
lines.append("$$")
app.run(lines=lines)
# ----------------------------------------------------------------------
def beforeChange(self, app):
app.sendGCode("$$")
time.sleep(1)
# ----------------------------------------------------------------------
def populate(self):
for n, t, d, l in self.variables:
try:
if t=="float":
self.values[n] = float(CNC.vars[n])
else:
self.values[n] = int(CNC.vars[n])
except KeyError:
pass
_Base.populate(self)
#==============================================================================
# Tools container class
#==============================================================================
class Tools:
def __init__(self, gcode):
self.gcode = gcode
self.inches = False
self.digits = 4
self.active = StringVar()
self.tools = {}
self.buttons = {}
self.listbox = None
# CNC should be first to load the inches
for cls in [ Config, Font, Color, Controller, Cut, Drill, EndMill, Events,
Material, Pocket, Profile, Shortcut, Stock,
Tabs]:
tool = cls(self)
self.addTool(tool)
# Find plugins in the plugins directory and load them
for f in glob.glob("%s/plugins/*.py"%(Utils.prgpath)):
name,ext = os.path.splitext(os.path.basename(f))
try:
exec("import %s"%(name))
tool = eval("%s.Tool(self)"%(name))
self.addTool(tool)
except (ImportError, AttributeError):
typ, val, tb = sys.exc_info()
traceback.print_exception(typ, val, tb)
# ----------------------------------------------------------------------
def addTool(self, tool):
self.tools[tool.name.upper()] = tool
# ----------------------------------------------------------------------
# Return a list of plugins
# ----------------------------------------------------------------------
def pluginList(self):
plugins = [x for x in self.tools.values() if x.plugin]
return sorted(plugins, key=attrgetter('name'))
# ----------------------------------------------------------------------
def setListbox(self, listbox):
self.listbox = listbox
# ----------------------------------------------------------------------
def __getitem__(self, name):
return self.tools[name.upper()]
# ----------------------------------------------------------------------
def getActive(self):
try:
return self.tools[self.active.get().upper()]
except:
self.active.set("CNC")
return self.tools["CNC"]
# ----------------------------------------------------------------------
def setActive(self, value):
self.active.set(value)
# ----------------------------------------------------------------------
def toMm(self, value):
if self.inches:
return value*25.4
else:
return value
# ----------------------------------------------------------------------
def fromMm(self, value):
if self.inches:
return value/25.4
else:
return value
# ----------------------------------------------------------------------
def names(self):
lst = [x.name for x in self.tools.values()]
lst.sort()
return lst
# ----------------------------------------------------------------------
# Load from config file
# ----------------------------------------------------------------------
def loadConfig(self):
self.active.set(Utils.getStr(Utils.__prg__, "tool", "CNC"))
for tool in self.tools.values():
tool.load()
# ----------------------------------------------------------------------
# Save to config file
# ----------------------------------------------------------------------
def saveConfig(self):
Utils.setStr(Utils.__prg__, "tool", self.active.get())
for tool in self.tools.values():
tool.save()
# ----------------------------------------------------------------------
def cnc(self):
return self.gcode.cnc
# ----------------------------------------------------------------------
def addButton(self, name, button):
self.buttons[name] = button
# ----------------------------------------------------------------------
def activateButtons(self, tool):
for btn in self.buttons.values():
btn.config(state=DISABLED)
for name in tool.buttons:
self.buttons[name].config(state=NORMAL)
self.buttons["exe"].config(text=self.active.get())
#===============================================================================
# DataBase Group
#===============================================================================
class DataBaseGroup(CNCRibbon.ButtonGroup):
def __init__(self, master, app):
CNCRibbon.ButtonGroup.__init__(self, master, N_("Database"), app)
self.grid3rows()
# ---
col,row=0,0
b = Ribbon.LabelRadiobutton(self.frame,
image=Utils.icons["stock32"],
text=_("Stock"),
compound=TOP,
anchor=W,
variable=app.tools.active,
value="Stock",
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, rowspan=3, padx=2, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Stock material currently on machine"))
self.addWidget(b)
# ===
col,row=1,0
b = Ribbon.LabelRadiobutton(self.frame,
image=Utils.icons["material"],
text=_("Material"),
compound=LEFT,
anchor=W,
variable=app.tools.active,
value="Material",
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Editable database of material properties"))
self.addWidget(b)
# ---
row += 1
b = Ribbon.LabelRadiobutton(self.frame,