Preliminary implementation of the prism feature
This commit is contained in:
@ -111,6 +111,8 @@ from OCC.Core.Addons import (text_to_brep,
|
|||||||
Font_FA_Italic,
|
Font_FA_Italic,
|
||||||
Font_FA_Bold)
|
Font_FA_Bold)
|
||||||
|
|
||||||
|
from OCC.Core.BRepFeat import BRepFeat_MakePrism
|
||||||
|
|
||||||
from math import pi, sqrt
|
from math import pi, sqrt
|
||||||
|
|
||||||
TOLERANCE = 1e-6
|
TOLERANCE = 1e-6
|
||||||
@ -644,9 +646,9 @@ class Mixin1D(object):
|
|||||||
brepgprop_LinearProperties(self.wrapped, Properties)
|
brepgprop_LinearProperties(self.wrapped, Properties)
|
||||||
|
|
||||||
return Properties.Mass()
|
return Properties.Mass()
|
||||||
|
|
||||||
def IsClosed(self):
|
def IsClosed(self):
|
||||||
|
|
||||||
return BRep_Tool.IsClosed(self.wrapped)
|
return BRep_Tool.IsClosed(self.wrapped)
|
||||||
|
|
||||||
|
|
||||||
@ -754,12 +756,12 @@ class Edge(Shape, Mixin1D):
|
|||||||
pnts = TColgp_HArray1OfPnt(1, len(listOfVector))
|
pnts = TColgp_HArray1OfPnt(1, len(listOfVector))
|
||||||
for ix, v in enumerate(listOfVector):
|
for ix, v in enumerate(listOfVector):
|
||||||
pnts.SetValue(ix+1, v.toPnt())
|
pnts.SetValue(ix+1, v.toPnt())
|
||||||
|
|
||||||
spline_builder = GeomAPI_Interpolate(pnts.GetHandle(), periodic, tol)
|
spline_builder = GeomAPI_Interpolate(pnts.GetHandle(), periodic, tol)
|
||||||
if tangents:
|
if tangents:
|
||||||
v1,v2 = tangents
|
v1,v2 = tangents
|
||||||
spline_builder.Load(v1.wrapped,v2.wrapped)
|
spline_builder.Load(v1.wrapped,v2.wrapped)
|
||||||
|
|
||||||
spline_builder.Perform()
|
spline_builder.Perform()
|
||||||
spline_geom = spline_builder.Curve()
|
spline_geom = spline_builder.Curve()
|
||||||
|
|
||||||
@ -856,7 +858,7 @@ class Wire(Shape, Mixin1D):
|
|||||||
return w
|
return w
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def makeHelix(cls, pitch, height, radius, center=Vector(0, 0, 0),
|
def makeHelix(cls, pitch, height, radius, center=Vector(0, 0, 0),
|
||||||
dir=Vector(0, 0, 1), angle=360.0, lefthand=False):
|
dir=Vector(0, 0, 1), angle=360.0, lefthand=False):
|
||||||
"""
|
"""
|
||||||
Make a helix with a given pitch, height and radius
|
Make a helix with a given pitch, height and radius
|
||||||
@ -1339,9 +1341,9 @@ class Solid(Shape, Mixin3D):
|
|||||||
prism_builder = LocOpe_DPrism(face.wrapped,
|
prism_builder = LocOpe_DPrism(face.wrapped,
|
||||||
d * vecNormal.Length,
|
d * vecNormal.Length,
|
||||||
d * taper * DEG2RAD)
|
d * taper * DEG2RAD)
|
||||||
|
|
||||||
return cls(prism_builder.Shape())
|
return cls(prism_builder.Shape())
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def revolve(cls, outerWire, innerWires, angleDegrees, axisStart, axisEnd):
|
def revolve(cls, outerWire, innerWires, angleDegrees, axisStart, axisEnd):
|
||||||
@ -1405,11 +1407,11 @@ class Solid(Shape, Mixin3D):
|
|||||||
builder.SetMode(isFrenet)
|
builder.SetMode(isFrenet)
|
||||||
builder.Add(w.wrapped)
|
builder.Add(w.wrapped)
|
||||||
shapes.append(cls(builder.Shape()))
|
shapes.append(cls(builder.Shape()))
|
||||||
|
|
||||||
rv = Compound.makeCompound(shapes)
|
rv = Compound.makeCompound(shapes)
|
||||||
|
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sweep_multi(cls, profiles, path, makeSolid=True, isFrenet=False):
|
def sweep_multi(cls, profiles, path, makeSolid=True, isFrenet=False):
|
||||||
"""
|
"""
|
||||||
@ -1423,20 +1425,39 @@ class Solid(Shape, Mixin3D):
|
|||||||
path = Wire.assembleEdges([path, ])
|
path = Wire.assembleEdges([path, ])
|
||||||
|
|
||||||
builder = BRepOffsetAPI_MakePipeShell(path.wrapped)
|
builder = BRepOffsetAPI_MakePipeShell(path.wrapped)
|
||||||
|
|
||||||
for p in profiles:
|
for p in profiles:
|
||||||
builder.Add(p.wrapped)
|
builder.Add(p.wrapped)
|
||||||
|
|
||||||
builder.SetMode(isFrenet)
|
builder.SetMode(isFrenet)
|
||||||
builder.Build()
|
builder.Build()
|
||||||
|
|
||||||
if makeSolid:
|
if makeSolid:
|
||||||
builder.MakeSolid()
|
builder.MakeSolid()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return cls(builder.Shape())
|
return cls(builder.Shape())
|
||||||
|
|
||||||
|
def prism(self, basis, profile, depth=None, thruAll=True, additive=True):
|
||||||
|
"""
|
||||||
|
Make a prismatic feature (additive or subtractive)
|
||||||
|
"""
|
||||||
|
|
||||||
|
face = Face.makeFromWires(profile)
|
||||||
|
feat = BRepFeat_MakePrism(self.wrapped,
|
||||||
|
basis.wrapped,
|
||||||
|
face.wrapped,
|
||||||
|
basis.normalAt().wrapped,
|
||||||
|
additive,
|
||||||
|
False)
|
||||||
|
|
||||||
|
if thruAll:
|
||||||
|
feat.PerformThruAll()
|
||||||
|
else:
|
||||||
|
feat.Perform(depth)
|
||||||
|
|
||||||
|
return self.__class__(feat.Shape())
|
||||||
|
|
||||||
class Compound(Shape, Mixin3D):
|
class Compound(Shape, Mixin3D):
|
||||||
"""
|
"""
|
||||||
@ -1456,23 +1477,23 @@ class Compound(Shape, Mixin3D):
|
|||||||
comp_builder.Add(comp, s.wrapped)
|
comp_builder.Add(comp, s.wrapped)
|
||||||
|
|
||||||
return cls(comp)
|
return cls(comp)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def makeText(cls, text, size, height, font="Arial", kind='regular',
|
def makeText(cls, text, size, height, font="Arial", kind='regular',
|
||||||
position=Plane.XY()):
|
position=Plane.XY()):
|
||||||
"""
|
"""
|
||||||
Create a 3D text
|
Create a 3D text
|
||||||
"""
|
"""
|
||||||
|
|
||||||
font_kind = {'regular' : Font_FA_Regular,
|
font_kind = {'regular' : Font_FA_Regular,
|
||||||
'bold' : Font_FA_Bold,
|
'bold' : Font_FA_Bold,
|
||||||
'italic' : Font_FA_Italic}[kind]
|
'italic' : Font_FA_Italic}[kind]
|
||||||
|
|
||||||
text_flat = Shape(text_to_brep(text, font, font_kind, size, False))
|
text_flat = Shape(text_to_brep(text, font, font_kind, size, False))
|
||||||
vecNormal = text_flat.Faces()[0].normalAt()*height
|
vecNormal = text_flat.Faces()[0].normalAt()*height
|
||||||
|
|
||||||
text_3d = BRepPrimAPI_MakePrism(text_flat.wrapped, vecNormal.wrapped)
|
text_3d = BRepPrimAPI_MakePrism(text_flat.wrapped, vecNormal.wrapped)
|
||||||
|
|
||||||
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
|
# TODO this is likely not needed if sing PythonOCC.Core.correclty but we will see
|
||||||
|
|||||||
Reference in New Issue
Block a user