Clean importCSG.py
Clean code Update importCSG.py
This commit is contained in:
@@ -139,7 +139,6 @@ def insert(filename, docname):
|
||||
original_root_objects.append(obj)
|
||||
except NameError:
|
||||
doc = FreeCAD.newDocument(docname)
|
||||
#importgroup = doc.addObject("App::DocumentObjectGroup",groupname)
|
||||
if filename.lower().endswith('.scad'):
|
||||
tmpfile = callopenscad(filename)
|
||||
pathName = os.path.dirname(os.path.normpath(filename))
|
||||
@@ -167,14 +166,11 @@ def processcsg(filename):
|
||||
# as it requires a writable location
|
||||
parser = yacc.yacc(debug=False, write_tables=False)
|
||||
if printverbose: print('Parser Loaded')
|
||||
# Give the lexer some input
|
||||
#f=open('test.scad', 'r')
|
||||
|
||||
f = io.open(filename, 'r', encoding="utf8")
|
||||
#lexer.input(f.read())
|
||||
|
||||
if printverbose: print('Start Parser')
|
||||
# Swap statements to enable Parser debugging
|
||||
#result = parser.parse(f.read(),debug=1)
|
||||
|
||||
result = parser.parse(f.read())
|
||||
f.close()
|
||||
if printverbose:
|
||||
@@ -195,15 +191,12 @@ def p_block_list_(p):
|
||||
| statementwithmod
|
||||
| block_list statementwithmod
|
||||
'''
|
||||
#if printverbose: print("Block List")
|
||||
#if printverbose: print(p[1])
|
||||
|
||||
if(len(p) > 2):
|
||||
if printverbose: print(p[2])
|
||||
p[0] = p[1] + p[2]
|
||||
else:
|
||||
p[0] = p[1]
|
||||
#if printverbose: print("End Block List")
|
||||
|
||||
|
||||
def p_render_action(p):
|
||||
'render_action : render LPAREN keywordargument_list RPAREN OBRACE block_list EBRACE'
|
||||
@@ -242,10 +235,6 @@ def p_boolean(p):
|
||||
'''
|
||||
p[0] = p[1]
|
||||
|
||||
#def p_string(p):
|
||||
# 'string : QUOTE ID QUOTE'
|
||||
# p[0] = p[2]
|
||||
|
||||
|
||||
def p_stripped_string(p):
|
||||
'stripped_string : STRING'
|
||||
@@ -316,9 +305,6 @@ def p_points_list_2d(p):
|
||||
| points_list_2d 2d_point
|
||||
'''
|
||||
if p[2] == ',':
|
||||
#if printverbose:
|
||||
# print("Start List")
|
||||
# print(p[1])
|
||||
p[0] = [p[1]]
|
||||
else:
|
||||
if printverbose:
|
||||
@@ -326,7 +312,6 @@ def p_points_list_2d(p):
|
||||
print(p[2])
|
||||
p[1].append(p[2])
|
||||
p[0] = p[1]
|
||||
#if printverbose: print(p[0])
|
||||
|
||||
|
||||
def p_3d_point(p):
|
||||
@@ -359,24 +344,16 @@ def p_path_points(p):
|
||||
| path_points NUMBER COMMA
|
||||
| path_points NUMBER
|
||||
'''
|
||||
#if printverbose: print("Path point")
|
||||
|
||||
if p[2] == ',':
|
||||
#if printverbose: print('Start list')
|
||||
#if printverbose: print(p[1])
|
||||
p[0] = [int(p[1])]
|
||||
else:
|
||||
#if printverbose: print(p[1])
|
||||
#if printverbose: print(len(p[1]))
|
||||
#if printverbose: print(p[2])
|
||||
p[1].append(int(p[2]))
|
||||
p[0] = p[1]
|
||||
#if printverbose: print(p[0])
|
||||
|
||||
|
||||
def p_path_list(p):
|
||||
'path_list : OSQUARE path_points ESQUARE'
|
||||
#if printverbose: print('Path List ')
|
||||
#if printverbose: print(p[2])
|
||||
p[0] = p[2]
|
||||
|
||||
|
||||
@@ -385,14 +362,11 @@ def p_path_set(p):
|
||||
path_set : path_list
|
||||
| path_set COMMA path_list
|
||||
'''
|
||||
#if printverbose: print('Path Set')
|
||||
#if printverbose: print(len(p))
|
||||
if len(p) == 2:
|
||||
p[0] = [p[1]]
|
||||
else:
|
||||
p[1].append(p[3])
|
||||
p[0] = p[1]
|
||||
#if printverbose: print(p[0])
|
||||
|
||||
def p_operation(p):
|
||||
'''
|
||||
@@ -468,12 +442,6 @@ def p_offset_action(p):
|
||||
newobj.Document.recompute()
|
||||
if gui:
|
||||
subobj.ViewObject.hide()
|
||||
# if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\
|
||||
# GetBool('useViewProviderTree'):
|
||||
# from OpenSCADFeatures import ViewProviderTree
|
||||
# ViewProviderTree(newobj.ViewObject)
|
||||
# else:
|
||||
# newobj.ViewObject.Proxy = 0
|
||||
p[0] = [newobj]
|
||||
|
||||
def checkObjShape(obj):
|
||||
@@ -905,8 +873,6 @@ def processSVG(fname, ext):
|
||||
if printverbose: print(obj.Name)
|
||||
if printverbose: print(obj.Shape)
|
||||
shapes.append(obj.Shape)
|
||||
#compoundSVG = Part.makeCompound(shapes)
|
||||
#compoundSVG = Draft.join(objects)
|
||||
FreeCAD.closeDocument(docSVG.Name)
|
||||
FreeCAD.ActiveDocument=doc
|
||||
obj=doc.addObject('Part::Feature',fname)
|
||||
@@ -930,14 +896,11 @@ def process_mesh_file(fname,ext):
|
||||
sh.makeShapeFromMesh(mesh1.Mesh.Topology,0.1)
|
||||
solid = Part.Solid(sh)
|
||||
obj = doc.addObject('Part::Feature',"Mesh")
|
||||
#ImportObject(obj,mesh1) #This object is not mutable from the GUI
|
||||
#ViewProviderTree(obj.ViewObject)
|
||||
|
||||
solid = solid.removeSplitter()
|
||||
if solid.Volume < 0:
|
||||
#sh.reverse()
|
||||
#sh = sh.copy()
|
||||
solid.complement()
|
||||
obj.Shape = solid#.removeSplitter()
|
||||
obj.Shape = solid
|
||||
else: #mesh1 is None
|
||||
FreeCAD.Console.PrintError('Mesh not imported %s.%s %s\n' % \
|
||||
(objname,ext,filename))
|
||||
@@ -1127,7 +1090,6 @@ def p_cylinder_action(p):
|
||||
h = float(p[3]['h'])
|
||||
r1 = float(p[3]['r1'])
|
||||
r2 = float(p[3]['r2'])
|
||||
#n = int(p[3]['$fn'])
|
||||
n = int(round(float(p[3]['$fn'])))
|
||||
fnmax = FreeCAD.ParamGet(\
|
||||
"User parameter:BaseApp/Preferences/Mod/OpenSCAD").\
|
||||
@@ -1155,7 +1117,6 @@ def p_cylinder_action(p):
|
||||
if printverbose:
|
||||
print("Draft makePolygon Failed, falling back on manual polygon")
|
||||
mycyl.Base = myPolygon(n,r1)
|
||||
# mycyl.Solid = True
|
||||
|
||||
else :
|
||||
pass
|
||||
@@ -1252,10 +1213,7 @@ def p_circle_action(p) :
|
||||
mycircle.MakeFace = True
|
||||
mycircle = Draft.makeCircle(r,face=True) # would call doc.recompute
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
#mycircle = doc.addObject('Part::Circle',p[1]) #would not create a face
|
||||
#mycircle.Radius = r
|
||||
else :
|
||||
#mycircle = Draft.makePolygon(n,r) # would call doc.recompute
|
||||
mycircle = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",'polygon')
|
||||
Draft._Polygon(mycircle)
|
||||
mycircle.FacesNumber = n
|
||||
@@ -1390,7 +1348,6 @@ def p_polyhedron_action(p) :
|
||||
except Exception:
|
||||
secWireList = w.Edges[:]
|
||||
f = Part.makeFilledFace(Part.__sortEdges__(secWireList))
|
||||
#f = make_face(v[int(i[0])],v[int(i[1])],v[int(i[2])])
|
||||
faces_list.append(f)
|
||||
shell=Part.makeShell(faces_list)
|
||||
solid=Part.Solid(shell).removeSplitter()
|
||||
|
||||
Reference in New Issue
Block a user