-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPocket.py
173 lines (143 loc) · 6.82 KB
/
Pocket.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
from SketchOp import SketchOp
import geom
import cad
import Tool
from Object import PyChoiceProperty
from Object import PyProperty
from Object import PyPropertyLength
from SpeedOp import SpeedOp
import wx
from nc.nc import *
import kurve_funcs
import area_funcs
from HeeksConfig import HeeksConfig
import math
from consts import *
type = 0
PROFILE_CONVENTIONAL = 0
PROFILE_CLIMB = 1
ENTRY_STYLE_PLUNGE = 0
ENTRY_STYLE_RAMP = 1
ENTRY_STYLE_HELICAL = 2
ENTRY_STYLE_UNDEFINED = 3
class Pocket(SketchOp):
def __init__(self, sketch = 0):
SketchOp.__init__(self, sketch)
self.step_over = 1.0
self.cut_mode = PROFILE_CLIMB
self.from_center = True
self.material_allowance = 0.0
self.keep_tool_down_if_poss = True
self.use_zig_zag = False
self.zig_angle = 0.0
self.zig_unidirectional = False
self.entry_move = ENTRY_STYLE_PLUNGE
def WriteXml(self):
cad.BeginXmlChild('params')
cad.SetXmlValue('step', self.step_over)
cad.SetXmlValue('cut_mode', self.cut_mode)
cad.SetXmlValue('mat', self.material_allowance)
cad.SetXmlValue('from_center', self.from_center)
cad.SetXmlValue('keep_tool_down', self.keep_tool_down_if_poss)
cad.SetXmlValue('use_zig_zag', self.use_zig_zag)
cad.SetXmlValue('zig_angle', self.zig_angle)
cad.SetXmlValue('zig_unidirectional', self.zig_unidirectional)
cad.SetXmlValue('entry_move', self.entry_move)
cad.EndXmlChild()
SketchOp.WriteXml(self)
def ReadXml(self):
child_element = cad.GetFirstXmlChild()
while child_element != None:
if child_element == 'params':
self.step_over = cad.GetXmlFloat('step', self.step_over)
self.cut_mode = cad.GetXmlInt('cut_mode', self.cut_mode)
self.material_allowance = cad.GetXmlFloat('mat', self.material_allowance)
self.from_center = cad.GetXmlInt('from_center', self.from_center)
self.keep_tool_down_if_poss = cad.GetXmlBool('keep_tool_down', self.keep_tool_down_if_poss)
self.use_zig_zag = cad.GetXmlBool('use_zig_zag', self.use_zig_zag)
self.zig_angle = cad.GetXmlFloat('zig_angle', self.zig_angle)
self.zig_unidirectional = cad.GetXmlBool('zig_unidirectional', self.zig_unidirectional)
self.entry_move = cad.GetXmlInt('entry_move', self.entry_move)
child_element = cad.GetNextXmlChild()
SketchOp.ReadXml(self)
def ReadDefaultValues(self):
SketchOp.ReadDefaultValues(self)
config = HeeksConfig()
self.step_over = config.ReadFloat("Stepover", 1.0)
self.cut_mode = config.ReadInt("CutMode", PROFILE_CLIMB)
self.from_center = config.ReadInt("FromCenter", True)
self.material_allowance = config.ReadFloat("MaterialAllowance", 0.0)
self.keep_tool_down_if_poss = config.ReadBool("KeepToolDown", True)
self.use_zig_zag = config.ReadBool("UseZigZag", False)
self.zig_angle = config.ReadFloat("ZigAngle", 0.0)
self.zig_unidirectional = config.ReadBool("ZigUnidirectional", False)
self.entry_move = config.ReadInt("DecentStrategy", ENTRY_STYLE_PLUNGE)
self.SetDefaultTool(TOOL_TYPE_SLOTCUTTER)
def WriteDefaultValues(self):
SketchOp.WriteDefaultValues(self)
config = HeeksConfig()
config.WriteFloat("Stepover", self.step_over)
config.WriteInt("CutMode", self.cut_mode)
config.WriteBool("FromCenter", self.from_center)
config.WriteFloat("MaterialAllowance", self.material_allowance)
config.WriteBool("KeepToolDown", self.keep_tool_down_if_poss)
config.WriteBool("UseZigZag", self.use_zig_zag)
config.WriteFloat("ZigAngle", self.zig_angle)
config.WriteBool("ZigUnidirectional", self.zig_unidirectional)
config.WriteInt("DecentStrategy", self.entry_move)
def TypeName(self):
return "Pocket"
def GetType(self):
return type
def op_icon(self):
# the name of the PNG file in the HeeksCNC icons folder
return "pocket"
def HasEdit(self):
return True
def Edit(self):
import PocketDlg
res = PocketDlg.Do(self)
return res
def MakeACopy(self):
copy = Pocket(self.sketch)
copy.CopyFrom(self)
return copy
def CopyFrom(self, object):
SketchOp.CopyFrom(self, object)
self.step_over = object.step_over
self.cut_mode = object.cut_mode
self.material_allowance = object.material_allowance
self.keep_tool_down_if_poss = object.keep_tool_down_if_poss
self.use_zig_zag = object.use_zig_zag
self.zig_angle = object.zig_angle
self.zig_unidirectional = object.zig_unidirectional
self.entry_move = object.entry_move
def GetProperties(self):
properties = []
properties.append(PyPropertyLength("Step Over", 'step_over', self))
properties.append(PyPropertyLength("Material Allowance", 'material_allowance', self))
properties.append(PyChoiceProperty("Cut Mode", 'cut_mode', ['Conventional', 'Climb'], self))
properties.append(PyChoiceProperty("Starting Place", 'from_center', ['Center', 'Boundary'], self, [True, False]))
properties.append(PyChoiceProperty("Entry Move", 'entry_move', ['Plunge', 'Ramp', 'Helical'], self, [0,1,2]))
properties.append(PyProperty("Keep Tool Down", 'keep_tool_down_if_poss', self))
properties.append(PyProperty("Use Zig Zag", 'use_zig_zag', self))
properties.append(PyProperty("Zig Angle", 'zig_angle', self))
properties.append(PyProperty("Unidirectional", 'zig_unidirectional', self))
properties += SketchOp.GetProperties(self)
return properties
def DoGCodeCallsForSketch(self, sketch, data):
cut_mode, depth_params, tool_diameter = data
a = sketch.GetArea()
a.Reorder()
area_funcs.pocket(a, tool_diameter/2, self.material_allowance/wx.GetApp().program.units, self.step_over/wx.GetApp().program.units, depth_params, self.from_center != 0, self.keep_tool_down_if_poss, self.use_zig_zag, self.zig_angle)
rapid(z = self.clearance_height)
def DoGCodeCalls(self):
failure = self.CheckToolExists()
if failure: return failure
tool = Tool.FindTool(self.tool_number)
depth_params = self.GetDepthParams()
tool_diameter = tool.CuttingRadius(True) * 2.0
SpeedOp.DoGCodeCalls(self)
object = cad.GetObjectFromId(cad.OBJECT_TYPE_SKETCH, self.sketch)
if object != None:
self.DoGCodeCallsForSketch(object, (self.cut_mode, depth_params, tool_diameter))