MOD: OPENSCAD clean (#20558)

clean code
This commit is contained in:
mosfet80
2025-04-03 05:07:52 +02:00
committed by GitHub
parent 8f35742f1f
commit c78e8ae4ce
8 changed files with 6 additions and 35 deletions

View File

@@ -155,8 +155,7 @@ class OpenSCADWorkbench(Workbench):
self.appendToolbar(
QT_TRANSLATE_NOOP("Workbench", "Frequently-used Part WB tools"), parttoolbarcommands
)
# self.appendMenu('OpenSCAD',["AddOpenSCADElement"])
###self.appendCommandbar("&Generic Tools",["ColorCodeShape"])
FreeCADGui.addIconPath(":/icons")
FreeCADGui.addLanguagePath(":/translations")
FreeCADGui.addPreferencePage(":/ui/openscadprefs-base.ui", "OpenSCAD")

View File

@@ -323,8 +323,7 @@ class AddSCADWidget(QtGui.QWidget):
# Main text area
self.textEdit=QtGui.QTextEdit()
self.textEdit.setAcceptRichText(False)
#print(self.textEdit.maximumHeight())
#print(self.textEdit.maximumViewportSize())
# Message Area
self.textMsg=QtGui.QPlainTextEdit()
self.textMsg.setReadOnly(True)

View File

@@ -53,8 +53,7 @@ except (ImportError, AttributeError):
class OpenSCADError(BaseError):
def __init__(self, value):
self.value = value
#def __repr__(self):
# return self.msg
def __str__(self):
return repr(self.value)

View File

@@ -45,7 +45,7 @@ def mostbasiccompound(comp):
wires = shapeset(comp.Wires)
edges = shapeset(comp.Edges)
vertexes = shapeset(comp.Vertexes)
#FreeCAD.Console.PrintMessage('%s\n' % (str((len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes)))))
for shape in comp.Solids:
shells -= shapeset(shape.Shells)
faces -= shapeset(shape.Faces)
@@ -66,8 +66,7 @@ def mostbasiccompound(comp):
vertexes -= shapeset(shape.Vertexes)
for shape in comp.Edges:
vertexes -= shapeset(shape.Vertexes)
#FreeCAD.Console.PrintMessage('%s\n' % (str((len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes)))))
#return len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes)
if vertexes:
return "Vertex"
elif edges:
@@ -110,4 +109,3 @@ def colorcodeshapes(objs):
except Exception:
raise
#colorcodeshapes(App.ActiveDocument.Objects)

View File

@@ -58,7 +58,6 @@ def expandplacementsmatrix(obj,matrix):
replaceobj.replaceobj(parent, obj, obj.Base)
out.Document.removeObject(obj.Name)
elif likeprimitive(obj, True):
#if isspecialorthogonalpython(fcsubmatrix(ownmatrix)):
if isspecialorthogonal(ownmatrix):
obj.Placement = FreeCAD.Placement()
#this should never happen unless matrices cancel out
@@ -93,7 +92,6 @@ def expandplacementsmatrix(obj,matrix):
def expandplacements(obj,placement):
ownplacement = placement.multiply(obj.Placement)
if obj.isDerivedFrom('Part::FeaturePython') and isinstance(obj.Proxy, MatrixTransform):
#expandplacementsmatrix(obj,ownplacement.toMatrix())
expandplacementsmatrix(obj,placement.toMatrix())
elif likeprimitive(obj, False):
obj.Placement = ownplacement
@@ -110,7 +108,6 @@ def expandplacements(obj,placement):
obj.Dir = ownplacement.Rotation.multVec(obj.Dir)
elif obj.isDerivedFrom('Part::Revolution'):
obj.Axis = ownplacement.Rotation.multVec(obj.Axis)
#obj.Base=ownplacement.Rotation.multVec(obj.Base)
expandplacements(outobj, ownplacement)
obj.Placement = FreeCAD.Placement()

View File

@@ -145,7 +145,6 @@ def process_object(csg,ob):
elif ob.TypeId == "Part::Prism":
import math
f = str(ob.Polygon)
# r = str(ob.Length/2.0/math.sin(math.pi/ob.Polygon))
r = str(ob.Circumradius) # length seems to be the outer radius
h = str(ob.Height.Value)
mm = check_multmatrix(csg, ob, 0, 0, -float(h)/2)

View File

@@ -780,8 +780,6 @@ def process_linear_extrude_with_transform(base,height,twist,scale) :
ViewProviderTree(newobj.ViewObject)
else:
newobj.ViewObject.Proxy = 0
#import ViewProviderTree from OpenSCADFeatures
#ViewProviderTree(obj.ViewObject)
return newobj
def p_linear_extrude_with_transform(p):

View File

@@ -24,7 +24,6 @@ def openscadmesh(doc, scadstr, objname):
import OpenSCADUtils
tmpfilename = OpenSCADUtils.callopenscadstring(scadstr,'stl')
if tmpfilename:
#mesh1 = doc.getObject(objname) #reuse imported object
Mesh.insert(tmpfilename)
os.unlink(tmpfilename)
mesh1 = doc.getObject(objname) #blog
@@ -38,7 +37,7 @@ def openscadmesh(doc, scadstr, objname):
solid = solid.removeSplitter()
if solid.Volume < 0:
solid.complement()
obj.Shape = solid#.removeSplitter()
obj.Shape = solid
return obj
else:
print(scadstr)
@@ -148,7 +147,6 @@ class Node:
obj.Height = h
if self.arguments['center']:
center(obj,0,0,h)
#base.ViewObject.hide()
elif False: #use Frustum Feature with makeRuledSurface
obj = doc.addObject("Part::FeaturePython",'frustum')
Frustum(obj,r1,r2,int(self.arguments['$fn']), h)
@@ -361,7 +359,6 @@ class Node:
sh.makeShapeFromMesh(mesh1.Mesh.Topology,0.1)
solid = Part.Solid(sh)
obj = doc.addObject("Part::FeaturePython",'import_%s_%s'%(extension,objname))
#obj=doc.addObject('Part::Feature',)
ImportObject(obj,mesh1) #This object is not mutable from the GUI
ViewProviderTree(obj.ViewObject)
solid = solid.removeSplitter()
@@ -400,7 +397,6 @@ class Node:
FreeCAD.Console.PrintError('processing of dxf import failed\nPlease rework \'%s\' manually\n' % layera)
f = Part.Shape() #empty Shape
obj = doc.addObject("Part::FeaturePython",'import_dxf_%s_%s'%(objname,layera))
#obj=doc.addObject('Part::Feature',)
ImportObject(obj,groupobj[0]) #This object is not mutable from the GUI
ViewProviderTree(obj.ViewObject)
obj.Shape=f
@@ -484,12 +480,6 @@ class Node:
if self.arguments['center']:
center(obj,xoff,yoff,0.0)
return obj
#import os
#scadstr = 'surface(file = "%s", center = %s );' % \
# (self.arguments['file'], 'true' if self.arguments['center'] else 'false')
#docname=os.path.split(self.arguments['file'])[1]
#objname,extension = docname.split('.',1)
#obj = openscadmesh(doc,scadstr,objname)
elif namel in ['glide','hull']:
raise(NotImplementedError)
@@ -566,7 +556,6 @@ class Node:
def parseexpression(e):
e = e.strip()
el = e.lower()
@@ -590,8 +579,6 @@ def parseexpression(e):
else:
import FreeCAD
FreeCAD.Console.PrintMessage('%s\n' % (el))
#return eval(el)
#assert(False) #Malformed
else:
return e #Return the string
@@ -611,9 +598,6 @@ def parseargs(argstring):
tok.append(''.join(a).strip())
#print(tok)
argdict = dict(zip(tok[0::2],[parseexpression(argstring) for argstring in tok[1::2]]))
# argdict = {}
# for key, value in re.findall(r"(\$?\w+)\s*=\s*(\[?\w+]?),?\s*",argstring):
# argdict[key] = parseexpression(value)
return argdict
else:
return parseexpression(argstring)
@@ -688,8 +672,6 @@ def insert(filename,docname):
except NameError:
doc = FreeCAD.newDocument(docname)
readfile(filename).addtofreecad(doc)
#doc.recompute()
global dxfcache