@@ -2993,12 +2993,7 @@ def twistExtrude(
2993
2993
2994
2994
r = Compound .makeCompound (shapes ).fuse ()
2995
2995
2996
- if isinstance (combine , str ) and combine == "cut" :
2997
- newS = self ._cutFromBase (r )
2998
- elif isinstance (combine , bool ) and combine :
2999
- newS = self ._combineWithBase (r )
3000
- else :
3001
- newS = self .newObject ([r ])
2996
+ newS = self ._combineWithBase (r , combine )
3002
2997
if clean :
3003
2998
newS = newS .clean ()
3004
2999
return newS
@@ -3061,10 +3056,8 @@ def extrude(
3061
3056
f"Do not know how to handle until argument of type { type (until )} "
3062
3057
)
3063
3058
3064
- if combine :
3065
- newS = self ._combineWithBase (r )
3066
- else :
3067
- newS = self .newObject ([r ])
3059
+ newS = self ._combineWithBase (r , combine )
3060
+
3068
3061
if clean :
3069
3062
newS = newS .clean ()
3070
3063
return newS
@@ -3131,12 +3124,7 @@ def revolve(
3131
3124
3132
3125
# returns a Solid (or a compound if there were multiple)
3133
3126
r = self ._revolve (angleDegrees , axisStart , axisEnd )
3134
- if isinstance (combine , str ) and combine == "cut" :
3135
- newS = self ._cutFromBase (r )
3136
- elif isinstance (combine , bool ) and combine :
3137
- newS = self ._combineWithBase (r )
3138
- else :
3139
- newS = self .newObject ([r ])
3127
+ newS = self ._combineWithBase (r , combine )
3140
3128
if clean :
3141
3129
newS = newS .clean ()
3142
3130
return newS
@@ -3189,19 +3177,34 @@ def sweep(
3189
3177
) # returns a Solid (or a compound if there were multiple)
3190
3178
3191
3179
newS : T
3192
- if isinstance (combine , str ) and combine == "cut" :
3193
- newS = self ._cutFromBase (r )
3194
- elif isinstance (combine , bool ) and combine :
3195
- newS = self ._combineWithBase (r )
3196
- else :
3197
- newS = self .newObject ([r ])
3180
+ newS = self ._combineWithBase (r , combine )
3198
3181
if clean :
3199
3182
newS = newS .clean ()
3200
3183
return newS
3201
3184
3202
- def _combineWithBase (self : T , obj : Shape ) -> T :
3185
+ def _combineWithBase (
3186
+ self : T , obj : Shape , combine_mode : Union [bool , str ] = True
3187
+ ) -> T :
3203
3188
"""
3204
3189
Combines the provided object with the base solid, if one can be found.
3190
+ :param obj: The object to be combined with the context solid
3191
+ :param combine_mode: The mode to combine with the base solid (True, False or "cut")
3192
+ :return: a new object that represents the result of combining the base object with obj,
3193
+ or obj if one could not be found
3194
+ """
3195
+
3196
+ if isinstance (combine_mode , str ) and combine_mode == "cut" :
3197
+ newS = self ._cutFromBase (obj )
3198
+ elif isinstance (combine_mode , bool ) and combine_mode :
3199
+ newS = self ._fuseWithBase (obj )
3200
+ elif not combine_mode :
3201
+ newS = self .newObject ([obj ])
3202
+
3203
+ return newS
3204
+
3205
+ def _fuseWithBase (self : T , obj : Shape ) -> T :
3206
+ """
3207
+ Fuse the provided object with the base solid, if one can be found.
3205
3208
:param obj:
3206
3209
:return: a new object that represents the result of combining the base object with obj,
3207
3210
or obj if one could not be found
@@ -3214,7 +3217,6 @@ def _combineWithBase(self: T, obj: Shape) -> T:
3214
3217
r = baseSolid .fuse (obj )
3215
3218
elif isinstance (obj , Compound ):
3216
3219
r = obj .fuse ()
3217
-
3218
3220
return self .newObject ([r ])
3219
3221
3220
3222
def _cutFromBase (self : T , obj : Shape ) -> T :
@@ -3514,14 +3516,7 @@ def loft(self: T, ruled: bool = False, combine: Union[bool, str] = True) -> T:
3514
3516
3515
3517
r : Shape = Solid .makeLoft (wiresToLoft , ruled )
3516
3518
3517
- if isinstance (combine , str ) and combine == "cut" :
3518
- newS = self ._cutFromBase (r )
3519
-
3520
- elif isinstance (combine , bool ) and combine :
3521
- newS = self ._combineWithBase (r )
3522
-
3523
- else :
3524
- newS = self .newObject ([r ])
3519
+ newS = self ._combineWithBase (r , combine )
3525
3520
3526
3521
return newS
3527
3522
@@ -4192,11 +4187,14 @@ def text(
4192
4187
)
4193
4188
4194
4189
if cut :
4195
- newS = self . _cutFromBase ( r )
4190
+ combine_mode = "cut"
4196
4191
elif combine :
4197
- newS = self . _combineWithBase ( r )
4192
+ combine_mode = True
4198
4193
else :
4199
- newS = self .newObject ([r ])
4194
+ combine_mode = False
4195
+
4196
+ newS = self ._combineWithBase (r , combine_mode )
4197
+
4200
4198
if clean :
4201
4199
newS = newS .clean ()
4202
4200
return newS
0 commit comments