35
35
Dict ,
36
36
)
37
37
from typing_extensions import Literal
38
-
38
+ from inspect import Parameter , Signature
39
39
40
40
from .occ_impl .geom import Vector , Plane , Location
41
41
from .occ_impl .shapes import (
@@ -264,7 +264,15 @@ def _collectProperty(self, propName: str) -> List[CQObject]:
264
264
265
265
return list (all .values ())
266
266
267
+ @overload
267
268
def split (self : T , keepTop : bool = False , keepBottom : bool = False ) -> T :
269
+ ...
270
+
271
+ @overload
272
+ def split (self : T , splitter : Union [T , Shape ]) -> T :
273
+ ...
274
+
275
+ def split (self : T , * args , ** kwargs ) -> T :
268
276
"""
269
277
Splits a solid on the stack into two parts, optionally keeping the separate parts.
270
278
@@ -284,28 +292,64 @@ def split(self: T, keepTop: bool = False, keepBottom: bool = False) -> T:
284
292
c = c.faces(">Y").workplane(-0.5).split(keepTop=True)
285
293
"""
286
294
287
- if ( not keepTop ) and ( not keepBottom ):
288
- raise ValueError ( "You have to keep at least one half" )
295
+ # split using an object
296
+ if len ( args ) == 1 and isinstance ( args [ 0 ], ( Workplane , Shape )):
289
297
290
- solid = self . findSolid ()
298
+ arg = args [ 0 ]
291
299
292
- maxDim = solid .BoundingBox ().DiagonalLength * 10.0
293
- topCutBox = self .rect (maxDim , maxDim )._extrude (maxDim )
294
- bottomCutBox = self .rect (maxDim , maxDim )._extrude (- maxDim )
295
-
296
- top = solid .cut (bottomCutBox )
297
- bottom = solid .cut (topCutBox )
300
+ solid = self .findSolid ()
301
+ tools = (
302
+ (arg ,)
303
+ if isinstance (arg , Shape )
304
+ else [v for v in arg .vals () if isinstance (v , Shape )]
305
+ )
306
+ rv = [solid .split (* tools )]
298
307
299
- if keepTop and keepBottom :
300
- # Put both on the stack, leave original unchanged.
301
- return self .newObject ([top , bottom ])
308
+ # split using the current wokrplane
302
309
else :
303
- # Put the one we are keeping on the stack, and also update the
304
- # context solidto the one we kept.
305
- if keepTop :
306
- return self .newObject ([top ])
310
+
311
+ # boilerplate for arg/kwarg parsing
312
+ sig = Signature (
313
+ (
314
+ Parameter (
315
+ "keepTop" , Parameter .POSITIONAL_OR_KEYWORD , default = False
316
+ ),
317
+ Parameter (
318
+ "keepBottom" , Parameter .POSITIONAL_OR_KEYWORD , default = False
319
+ ),
320
+ )
321
+ )
322
+
323
+ bound_args = sig .bind (* args , ** kwargs )
324
+ bound_args .apply_defaults ()
325
+
326
+ keepTop = bound_args .arguments ["keepTop" ]
327
+ keepBottom = bound_args .arguments ["keepBottom" ]
328
+
329
+ if (not keepTop ) and (not keepBottom ):
330
+ raise ValueError ("You have to keep at least one half" )
331
+
332
+ solid = self .findSolid ()
333
+
334
+ maxDim = solid .BoundingBox ().DiagonalLength * 10.0
335
+ topCutBox = self .rect (maxDim , maxDim )._extrude (maxDim )
336
+ bottomCutBox = self .rect (maxDim , maxDim )._extrude (- maxDim )
337
+
338
+ top = solid .cut (bottomCutBox )
339
+ bottom = solid .cut (topCutBox )
340
+
341
+ if keepTop and keepBottom :
342
+ # Put both on the stack, leave original unchanged.
343
+ rv = [top , bottom ]
307
344
else :
308
- return self .newObject ([bottom ])
345
+ # Put the one we are keeping on the stack, and also update the
346
+ # context solidto the one we kept.
347
+ if keepTop :
348
+ rv = [top ]
349
+ else :
350
+ rv = [bottom ]
351
+
352
+ return self .newObject (rv )
309
353
310
354
@deprecate ()
311
355
def combineSolids (
@@ -1903,6 +1947,10 @@ def parametricCurve(
1903
1947
N : int = 400 ,
1904
1948
start : float = 0 ,
1905
1949
stop : float = 1 ,
1950
+ tol : float = 1e-6 ,
1951
+ minDeg : int = 1 ,
1952
+ maxDeg : int = 6 ,
1953
+ smoothing : Optional [Tuple [float , float , float ]] = (1 , 1 , 1 ),
1906
1954
makeWire : bool = True ,
1907
1955
) -> T :
1908
1956
"""
@@ -1913,6 +1961,10 @@ def parametricCurve(
1913
1961
:param N: number of points for discretization
1914
1962
:param start: starting value of the parameter t
1915
1963
:param stop: final value of the parameter t
1964
+ :param tol: tolerance of the algorithm (default: 1e-3)
1965
+ :param minDeg: minimum spline degree (default: 1)
1966
+ :param maxDeg: maximum spline degree (default: 6)
1967
+ :param smoothing: optional parameters for the variational smoothing algorithm (default: (1,1,1))
1916
1968
:param makeWire: convert the resulting spline edge to a wire
1917
1969
:return: a Workplane object with the current point unchanged
1918
1970
@@ -1923,7 +1975,9 @@ def parametricCurve(
1923
1975
(func (start + diff * t / N ) for t in range (N + 1 )), False
1924
1976
)
1925
1977
1926
- e = Edge .makeSplineApprox (allPoints )
1978
+ e = Edge .makeSplineApprox (
1979
+ allPoints , tol = tol , smoothing = smoothing , minDeg = minDeg , maxDeg = maxDeg
1980
+ )
1927
1981
1928
1982
if makeWire :
1929
1983
rv_w = Wire .assembleEdges ([e ])
@@ -1940,6 +1994,9 @@ def parametricSurface(
1940
1994
start : float = 0 ,
1941
1995
stop : float = 1 ,
1942
1996
tol : float = 1e-2 ,
1997
+ minDeg : int = 1 ,
1998
+ maxDeg : int = 6 ,
1999
+ smoothing : Optional [Tuple [float , float , float ]] = (1 , 1 , 1 ),
1943
2000
) -> T :
1944
2001
"""
1945
2002
Create a spline surface approximating the provided function.
@@ -1949,7 +2006,10 @@ def parametricSurface(
1949
2006
:param N: number of points for discretization in one direction
1950
2007
:param start: starting value of the parameters u,v
1951
2008
:param stop: final value of the parameters u,v
1952
- :param tol: tolerance used by the approximation algorithm
2009
+ :param tol: tolerance used by the approximation algorithm (default: 1e-3)
2010
+ :param minDeg: minimum spline degree (default: 1)
2011
+ :param maxDeg: maximum spline degree (default: 3)
2012
+ :param smoothing: optional parameters for the variational smoothing algorithm (default: (1,1,1))
1953
2013
:return: a Workplane object with the current point unchanged
1954
2014
1955
2015
This method might be unstable and may require tuning of the tol parameter.
@@ -1970,7 +2030,9 @@ def parametricSurface(
1970
2030
)
1971
2031
)
1972
2032
1973
- f = Face .makeSplineApprox (allPoints , tol = tol )
2033
+ f = Face .makeSplineApprox (
2034
+ allPoints , tol = tol , smoothing = smoothing , minDeg = minDeg , maxDeg = maxDeg
2035
+ )
1974
2036
1975
2037
return self .newObject ([f ])
1976
2038
0 commit comments