-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
348 lines (239 loc) · 9.85 KB
/
main.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
from importlib import reload
from inspect import getmembers, isfunction
FREECADPATH = 'C:/FreeCadBeta/bin'
import sys
sys.path.append(FREECADPATH)
import FreeCAD
import Path
print("\n\nAvailable functions in PAth")
print(getmembers(Path, isfunction))
txt=dir(Path)
print("txt:",txt)
print("Done ....Available functions in PAth")
print ("::::::::::::::::::::::::::::::::")
import PathScripts
#from PathScripts import PathUtils as pu
print("\n\nAvailable functions in PAthScrits")
print(getmembers(Path, isfunction))
txt1=dir(PathScripts)
print("txt:",txt1)
print("Done ....Available functions in PAthScrits")
print ("::::::::::::::::::::::::::::::::")
import JobUtils
print("\n\nAvailable functions in JobUtils")
print(getmembers(JobUtils, isfunction))
txt2=dir(JobUtils)
print("txt:",txt2)
print("Done ....Available functions in JobUtils")
print ("::::::::::::::::::::::::::::::::")
import Tests.PathTestUtils as PathTestUtils
#from PathScripts import PathPost
from Path.Post.scripts import refactored_linuxcnc_post as postprocessor
from Path.Post.Processor import PostProcessor
from cnc_controller import cnc_controller
from linuxcnc_controller import linuxcnc_controller
from grbl_controller import grbl_controller
from masso_controller import masso_controller
from mach_controller import mach_controller
class post_it(PostProcessor):
pass
print("======================Starting Code ===================================================\n")
#doc = FreeCAD.newDocument()
filepath = "test1.FCStd"
doc=FreeCAD.open(filepath)
print(type(doc))
print("Doc Label:",doc.Label)
print("\n\n\nThese are global app settings:")
print("\t- Available lib paths for tools",JobUtils._get_available_tool_library_paths())
# HARD CODED FOR NOW
toolDirs=JobUtils._get_available_tool_library_paths()
print("\t- toolDirs[0][2]", toolDirs[0][2])
toolList=JobUtils._read_library(toolDirs[0][2])
print("\n")
print ("\t- toolList: ")
for aTool in toolList:
print("\t\t:",aTool)
print("Done with tools\n\n\n\n")
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
print("Walking the CAM details\n")
docObjs=doc.Objects
#print(type(docObjs))
opArray=[]
toolArray=[]
jobArray=[]
print("Parsing out CAM objects:")
for obj in docObjs:
match obj.TypeId:
case "App::FeaturePython":
pass
case "App::DocumentObjectGroup":
pass
case "App::Line":
pass
case "App::Origin":
pass
case "App::Plane":
pass
case "Part::FeaturePython":
pass
case "PartDesign::Body":
pass
case "PartDesign::Pad":
pass
case "PartDesign::Pocket":
pass
case "Sketcher::SketchObject":
pass
case "Path::FeaturePython":
#print("Processing Path::FeaturePython")
typeAsString=str(type(obj.Proxy))
#print("typeAsString: ", typeAsString)
if "Path.Main.Job" in typeAsString:
jobArray.append(obj)
if "Path.Tool" in typeAsString:
toolArray.append(obj)
if "Path.Op" in typeAsString:
opArray.append(obj)
case _:
print("Don't know this object type",obj.TypeId)
print("\tjobArray size: ",len(jobArray))
print("\ttoolArray size: ",len(toolArray))
print("\topArray size: ",len(opArray))
if len(jobArray) > 0:
lclCnt=0
while lclCnt < len(jobArray):
print("\n\nPrinting JobArray[",lclCnt,"]:")
print(dir(jobArray[lclCnt]))
# Content has ALL the data
# print("\tContent:",jobArray[lclCnt].Content)
print("\tLabel:",jobArray[lclCnt].Label)
print("\tFixtures:",jobArray[lclCnt].Fixtures)
print("\tPostProcessor:",jobArray[lclCnt].PostProcessor)
print("\tPostProcessorArgs:",jobArray[lclCnt].PostProcessorArgs)
print("\tPostProcessorOutputFile:",jobArray[lclCnt].PostProcessorOutputFile)
print("\tSplitOutput:",jobArray[lclCnt].SplitOutput)
print("\tStock:",jobArray[lclCnt].Stock)
print("\tCycleTime:",jobArray[lclCnt].CycleTime)
print("\tDescription:",jobArray[lclCnt].Description)
#print("\tGroup:",jobArray[lclCnt].Group)
print("\n")
for elem in jobArray[lclCnt].Group:
print("\t\tGroup:",elem)
print("\tOperations:",jobArray[lclCnt].Operations)
jobArray[lclCnt].dumpContent()
Ops=jobArray[lclCnt].Operations
opCnt=0
opTotCnt=len(jobArray[lclCnt].Operations.Group)
for op in jobArray[lclCnt].Operations.Group:
opCnt=opCnt+1
print("\t\tOp:",opCnt," of ",opTotCnt)
print("\t\t\tDir Op:",dir(op))
#print("\n")
print("\t\t\tLabel:",op.Label)
print("\t\t\tActive:",op.Active)
print("\t\t\tBase:",op.Base)
print("\t\t\tClearanceHeight:",op.ClearanceHeight)
print("\t\t\tCoolantMode:",op.CoolantMode)
print("\t\t\tCycleTime:",op.CycleTime)
#print("\n")
print("\t\t\tTool Controller:")
print("\t\t\t\t Dir ToolController :",dir(op.ToolController))
print("\t\t\t\t Label:",op.ToolController.Label)
print("\t\t\t\t Name:",op.ToolController.Name)
print("\t\t\t\t FullName:",op.ToolController.FullName)
print("\t\t\t\t ToolNumber:",op.ToolController.ToolNumber)
print("\t\t\t\t SpindleSpeed:",op.ToolController.SpindleSpeed)
print("\t\t\t\t SpindleDir:",op.ToolController.SpindleDir)
print("\t\t\t\t HorizFeed:",op.ToolController.HorizFeed)
print("\t\t\t\t VertFeed:",op.ToolController.VertFeed)
print("\n")
print("\t\t\tPath:")
print("\t\t\t\tDir Op Path:",dir(op.Path))
print("\t\t\t\t BoundBox:",op.Path.BoundBox)
print("\t\t\t\t Center:",op.Path.Center)
print("\t\t\t\t Length:",op.Path.Length)
print("\t\t\t\t Module:",op.Path.Module)
print("\t\t\t\t GCode Commands:")
for lclCmd in op.Path.Commands:
print("\t\t\t\t\t\t Commands:",lclCmd.toGCode())
print("\n")
lclCnt += 1
print("Jobs are Done\n\n\n\n")
exit
print("Walking ALL the tools: (in all jobs)")
lclCnt=0
while lclCnt < len(toolArray):
print("\tPrinting Tool[",lclCnt,"]:")
#print(dir(toolArray[0]))
print("\t\tLabel:",toolArray[lclCnt].Label)
print("\t\tToolNumber:",toolArray[lclCnt].ToolNumber)
print("\t\tSpindleSpeed:",toolArray[lclCnt].SpindleSpeed)
print("\t\tSpindleDir:",toolArray[lclCnt].SpindleDir)
print("\t\tHorizFeed:",toolArray[lclCnt].HorizFeed)
print("\t\tVertFeed:",toolArray[lclCnt].VertFeed)
lclCnt += 1
print("\n\n")
print("Walking ALL the operations: (in all jobs)")
lclCnt=0
while lclCnt <len(opArray):
print("\tPrinting Op[",lclCnt,"]:")
print("\t\tLabel:",opArray[lclCnt].Label)
#print(dir(opArray[lclCnt]))
print("\t\tActive:",opArray[lclCnt].Active)
print("\t\tState:",opArray[lclCnt].State)
print("\t\tClearanceHeight:",opArray[lclCnt].ClearanceHeight)
print("\t\tCycleTime:",opArray[lclCnt].CycleTime)
if hasattr(opArray[lclCnt] ,"Direction"):
print("\t\tDirection:",opArray[lclCnt].Direction)
else:
print("\t\tDirection:Undefined")
if hasattr(opArray[lclCnt] ,"FinalDepth"):
print("\t\tFinalDepth:",opArray[lclCnt].FinalDepth)
else:
print("\t\tFinalDepth:Undefined")
print("\t\tParents:",opArray[lclCnt].Parents)
print("\t\tCoolantMode:",opArray[lclCnt].CoolantMode)
lclCnt += 1
print("============================Starting PATH stuff =============================================\n")
#Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
#Path.Log.trackModule(Path.Log.thisModule())
#c = Path.Command("G0 X10 Y20 Z30")
#print(c)
print("---------------Creating lcl_linux_post ----------------------------------")
lcl_linux_controller=linuxcnc_controller(PostProcessor)
lcl_linux_controller.print_values()
print("---------------Printing linuxcnc_post ----------------------------------")
print("\n\n\n")
print("---------------Creating lcl_grbl_post ----------------------------------")
lcl_grbl_controller=grbl_controller(PostProcessor)
lcl_grbl_controller.print_values()
print("---------------Printing lcl_grbl_post ----------------------------------")
print("\n\n\n")
print("---------------Creating lcl_masso_post ----------------------------------")
lcl_masso_controller=masso_controller(PostProcessor)
lcl_masso_controller.print_values()
print("---------------Printing lcl_masso_post ----------------------------------")
print("\n\n\n")
print("---------------Creating lcl_mach_post ----------------------------------")
lcl_mach_controller=mach_controller(PostProcessor)
lcl_mach_controller.print_values()
print("---------------Printing lcl_mach_post ----------------------------------")
print("=========================================================================\n")
CreateThisPost= 'grbl'
CreateThisPost= 'haas'
CreateThisPost= 'linuxcnc'
CreateThisPost= 'mach'
CreateThisPost= 'masso'
CreateThisPost=CreateThisPost.upper()
print("CreateThisPost: ", CreateThisPost)
if CreateThisPost == 'GRBL':
lcl_post=grbl_controller(PostProcessor)
elif CreateThisPost == 'LINUXCNC':
lcl_post=linuxcnc_controller(PostProcessor)
elif CreateThisPost == 'MACH':
lcl_post=mach_controller(PostProcessor)
elif CreateThisPost == 'MASSO':
lcl_post=masso_controller(PostProcessor)
else:
print("Unknown Post Processor")
exit()