Skip to content

Commit a175cb8

Browse files
More shape/free func improvements (#1692)
* Initial commit of better paramAt, solid and a new function check * mypy fix * isSolid fix * Implement outerShell, innerShells * Imports cleanup * Typo fix * Make paramAt fully compatibile with Wires * Typo fix * Add check test * Fix orientation handling * Add test * paramAt test * More tests * Add orientation fix and optimize check * Switch to miniforge * Add missing newline * Use OBB (perf) and modified frenet * overload normalAt for parameters * bulk normals calculation * workaround for bad fonts * first pass at loft to vertex * Add trim and more loft to vertex tweaks * Some mypy fixes * Loft improvements and sewing fixes. * Add loft to vertox to workplane * Add dummy kwargs for better unified codebase support (raw / CQ-editor) * Add continuity * Use seperate builders for loft * Add parametrization to loft and aux spine to sweep * Add params to spline interpolation * Add missing arg * Add tol and smoothing * Fix cap handling * Fix crash * Fix loft args * Typo * Fix test * Fix show test * 2nd show fix * Some loft tests * Logic fix * Add curvature calculation * Add multimethod docstrings * Some tests * Add and fix tests * More tests * Another overload * Loft to vertex tests * Imporve coverage * Remove dead code * Readd code with better explanation * Better coverage * Extend vis * Mypy fixes * Add alpha * Mypy fix * Fix vtk rotation order * Second vtk rot fix * Typo fixes
1 parent 3cf8742 commit a175cb8

File tree

8 files changed

+763
-121
lines changed

8 files changed

+763
-121
lines changed

cadquery/cq.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@
4242
from .occ_impl.geom import Vector, Plane, Location
4343
from .occ_impl.shapes import (
4444
Shape,
45+
Vertex,
4546
Edge,
4647
Wire,
4748
Face,
4849
Solid,
4950
Compound,
5051
wiresToFaces,
5152
Shapes,
53+
loft,
5254
)
5355

5456
from .occ_impl.exporters.svg import getSVG, exportSVG
@@ -3697,15 +3699,22 @@ def loft(
36973699
36983700
"""
36993701

3702+
toLoft: List[Union[Wire, Vertex]] = []
3703+
37003704
if self.ctx.pendingWires:
3701-
wiresToLoft = self.ctx.popPendingWires()
3705+
toLoft.extend(self.ctx.popPendingWires())
37023706
else:
3703-
wiresToLoft = [f.outerWire() for f in self._getFaces()]
3707+
toLoft = [
3708+
el if isinstance(el, Vertex) else el.outerWire()
3709+
for el in self._getFacesVertices()
3710+
]
37043711

3705-
if not wiresToLoft:
3712+
if not toLoft:
37063713
raise ValueError("Nothing to loft")
3714+
elif len(toLoft) == 1:
3715+
raise ValueError("More than one wire or face is required")
37073716

3708-
r: Shape = Solid.makeLoft(wiresToLoft, ruled)
3717+
r: Shape = loft(toLoft, cap=True, ruled=ruled)
37093718

37103719
newS = self._combineWithBase(r, combine, clean)
37113720

@@ -3731,6 +3740,23 @@ def _getFaces(self) -> List[Face]:
37313740

37323741
return rv
37333742

3743+
def _getFacesVertices(self) -> List[Union[Face, Vertex]]:
3744+
"""
3745+
Convert pending wires or sketches to faces/vertices for subsequent operation
3746+
"""
3747+
3748+
rv: List[Union[Face, Vertex]] = []
3749+
3750+
for el in self.objects:
3751+
if isinstance(el, Sketch):
3752+
rv.extend(el)
3753+
elif isinstance(el, (Face, Vertex)):
3754+
rv.append(el)
3755+
elif isinstance(el, Compound):
3756+
rv.extend(subel for subel in el if isinstance(subel, (Face, Vertex)))
3757+
3758+
return rv
3759+
37343760
def _extrude(
37353761
self,
37363762
distance: Optional[float] = None,
@@ -4574,7 +4600,7 @@ def export(
45744600
) -> T:
45754601
"""
45764602
Export Workplane to file.
4577-
4603+
45784604
:param path: Filename.
45794605
:param tolerance: the deflection tolerance, in model units. Default 0.1.
45804606
:param angularTolerance: the angular tolerance, in radians. Default 0.1.

cadquery/occ_impl/assembly.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,23 @@ def _toCAF(el, ancestor, color) -> TDF_Label:
261261
return top, doc
262262

263263

264+
def _loc2vtk(
265+
loc: Location,
266+
) -> Tuple[Tuple[float, float, float], Tuple[float, float, float]]:
267+
"""
268+
Convert location to t,rot pair following vtk conventions
269+
"""
270+
271+
T = loc.wrapped.Transformation()
272+
273+
trans = T.TranslationPart().Coord()
274+
rot = tuple(
275+
map(degrees, T.GetRotation().GetEulerAngles(gp_EulerSequence.gp_Intrinsic_ZXY),)
276+
)
277+
278+
return trans, (rot[1], rot[2], rot[0])
279+
280+
264281
def toVTK(
265282
assy: AssemblyProtocol,
266283
color: Tuple[float, float, float, float] = (1.0, 1.0, 1.0, 1.0),
@@ -273,14 +290,8 @@ def toVTK(
273290
for shape, _, loc, col_ in assy:
274291

275292
col = col_.toTuple() if col_ else color
276-
T = loc.wrapped.Transformation()
277-
trans = T.TranslationPart().Coord()
278-
rot = tuple(
279-
map(
280-
degrees,
281-
T.GetRotation().GetEulerAngles(gp_EulerSequence.gp_Intrinsic_ZXY),
282-
)
283-
)
293+
294+
trans, rot = _loc2vtk(loc)
284295

285296
data = shape.toVtkPolyData(tolerance, angularTolerance)
286297

@@ -311,7 +322,7 @@ def toVTK(
311322
actor = vtkActor()
312323
actor.SetMapper(mapper)
313324
actor.SetPosition(*trans)
314-
actor.SetOrientation(rot[1], rot[2], rot[0])
325+
actor.SetOrientation(*rot)
315326
actor.GetProperty().SetColor(*col[:3])
316327
actor.GetProperty().SetOpacity(col[3])
317328

@@ -323,7 +334,7 @@ def toVTK(
323334
actor = vtkActor()
324335
actor.SetMapper(mapper)
325336
actor.SetPosition(*trans)
326-
actor.SetOrientation(rot[1], rot[2], rot[0])
337+
actor.SetOrientation(*rot)
327338
actor.GetProperty().SetColor(0, 0, 0)
328339
actor.GetProperty().SetLineWidth(2)
329340

0 commit comments

Comments
 (0)