refactored shape fixing, fixed makeShell and added makeSolid
This commit is contained in:
@ -14,6 +14,8 @@ from OCC.Core.BRepBuilderAPI import (BRepBuilderAPI_MakeVertex,
|
|||||||
BRepBuilderAPI_MakeFace,
|
BRepBuilderAPI_MakeFace,
|
||||||
BRepBuilderAPI_MakePolygon,
|
BRepBuilderAPI_MakePolygon,
|
||||||
BRepBuilderAPI_MakeWire,
|
BRepBuilderAPI_MakeWire,
|
||||||
|
BRepBuilderAPI_Sewing,
|
||||||
|
BRepBuilderAPI_MakeSolid,
|
||||||
BRepBuilderAPI_Copy,
|
BRepBuilderAPI_Copy,
|
||||||
BRepBuilderAPI_GTransform,
|
BRepBuilderAPI_GTransform,
|
||||||
BRepBuilderAPI_Transform,
|
BRepBuilderAPI_Transform,
|
||||||
@ -217,6 +219,17 @@ class Shape(object):
|
|||||||
|
|
||||||
return self.cast(upgrader.Shape())
|
return self.cast(upgrader.Shape())
|
||||||
|
|
||||||
|
def fix(self):
|
||||||
|
"""Try to fix shape if not valid"""
|
||||||
|
if not BRepCheck_Analyzer(self.wrapped).IsValid():
|
||||||
|
sf = ShapeFix_Shape(self.wrapped)
|
||||||
|
sf.Perform()
|
||||||
|
fixed = downcast(sf.Shape())
|
||||||
|
|
||||||
|
return self.cast(fixed)
|
||||||
|
|
||||||
|
return self
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cast(cls, obj, forConstruction=False):
|
def cast(cls, obj, forConstruction=False):
|
||||||
"Returns the right type of wrapper, given a FreeCAD object"
|
"Returns the right type of wrapper, given a FreeCAD object"
|
||||||
@ -1020,20 +1033,16 @@ class Face(Shape):
|
|||||||
'''
|
'''
|
||||||
Makes a planar face from one or more wires
|
Makes a planar face from one or more wires
|
||||||
'''
|
'''
|
||||||
|
|
||||||
face_builder = BRepBuilderAPI_MakeFace(outerWire.wrapped,True)
|
face_builder = BRepBuilderAPI_MakeFace(outerWire.wrapped,True)
|
||||||
|
|
||||||
for w in innerWires:
|
for w in innerWires:
|
||||||
face_builder.Add(w.wrapped)
|
face_builder.Add(w.wrapped)
|
||||||
face_builder.Build()
|
|
||||||
|
|
||||||
|
face_builder.Build()
|
||||||
face = face_builder.Shape()
|
face = face_builder.Shape()
|
||||||
|
|
||||||
if not BRepCheck_Analyzer(face).IsValid():
|
return cls.cast(face).fix()
|
||||||
sf = ShapeFix_Shape(face)
|
|
||||||
sf.Perform()
|
|
||||||
face = sf.Shape()
|
|
||||||
|
|
||||||
return cls.cast(face)
|
|
||||||
|
|
||||||
|
|
||||||
class Shell(Shape):
|
class Shell(Shape):
|
||||||
@ -1044,14 +1053,14 @@ class Shell(Shape):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def makeShell(cls, listOfFaces):
|
def makeShell(cls, listOfFaces):
|
||||||
|
|
||||||
shell_wrapped = TopoDS_Shell()
|
shell_builder = BRepBuilderAPI_Sewing()
|
||||||
shell_builder = TopoDS_Builder()
|
|
||||||
shell_builder.MakeShell(shell_wrapped)
|
|
||||||
|
|
||||||
for face in listOfFaces:
|
for face in listOfFaces:
|
||||||
shell_builder.Add(face.wrapped)
|
shell_builder.Add(face.wrapped)
|
||||||
|
|
||||||
return cls(shell_wrapped)
|
shell_builder.Perform()
|
||||||
|
|
||||||
|
return cls.cast(shell_builder.SewedShape())
|
||||||
|
|
||||||
|
|
||||||
class Mixin3D(object):
|
class Mixin3D(object):
|
||||||
@ -1165,6 +1174,11 @@ class Solid(Shape, Mixin3D):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def makeSolid(cls, shell):
|
||||||
|
|
||||||
|
return cls(BRepBuilderAPI_MakeSolid(shell.wrapped).Solid())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def makeBox(cls, length, width, height, pnt=Vector(0, 0, 0), dir=Vector(0, 0, 1)):
|
def makeBox(cls, length, width, height, pnt=Vector(0, 0, 0), dir=Vector(0, 0, 1)):
|
||||||
"""
|
"""
|
||||||
@ -1553,9 +1567,6 @@ class Compound(Shape, Mixin3D):
|
|||||||
|
|
||||||
return cls(text_3d.Shape()).transformShape(position.rG)
|
return cls(text_3d.Shape()).transformShape(position.rG)
|
||||||
|
|
||||||
# TODO this is likely not needed if sing PythonOCC.Core.correclty but we will see
|
|
||||||
|
|
||||||
|
|
||||||
def sortWiresByBuildOrder(wireList, result={}):
|
def sortWiresByBuildOrder(wireList, result={}):
|
||||||
"""Tries to determine how wires should be combined into faces.
|
"""Tries to determine how wires should be combined into faces.
|
||||||
|
|
||||||
@ -1577,7 +1588,7 @@ def sortWiresByBuildOrder(wireList, result={}):
|
|||||||
if len(wireList) < 2:
|
if len(wireList) < 2:
|
||||||
return [wireList, ]
|
return [wireList, ]
|
||||||
|
|
||||||
# make a Face, NB: this might return
|
# make a Face, NB: this might return a compound of faces
|
||||||
faces = Face.makeFromWires(wireList[0], wireList[1:])
|
faces = Face.makeFromWires(wireList[0], wireList[1:])
|
||||||
|
|
||||||
rv = []
|
rv = []
|
||||||
|
|||||||
Reference in New Issue
Block a user