-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added combine="cut" option for 3D operations #954
Conversation
added the option to combine="cut" for revolve and loft, added tests removed old arg of loft that was actually unused
added combine cut for twistextrude sweep. Didn't added it for extrude as it already as cutBlind and the option to extrude until a given face is combine by default and would need a little bit more change to handle combine=cut (but its still possible)
Codecov Report
@@ Coverage Diff @@
## master #954 +/- ##
==========================================
+ Coverage 96.08% 96.17% +0.08%
==========================================
Files 40 40
Lines 9257 9286 +29
Branches 1112 1109 -3
==========================================
+ Hits 8895 8931 +36
+ Misses 209 208 -1
+ Partials 153 147 -6
Continue to review full report at Codecov.
|
I've added test to target the lines marked as non tested but it keeps failing |
I think it's fine. We have to sometimes ignore codecov when it complains about minor things. |
cadquery/cq.py
Outdated
@@ -2993,7 +2993,9 @@ def twistExtrude( | |||
|
|||
r = Compound.makeCompound(shapes).fuse() | |||
|
|||
if combine: | |||
if isinstance(combine, str) and combine == "cut": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this section of code ends up being repeated quite a bit, but I'm not sure that there's an quick/efficient way to avoid the code duplication. Probably best just to leave it for now unless someone has an idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd propose to refactor and move it to _combineWithBase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand what we are talking about. The plan would be to move what to _combineWithBase
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of repetitive code like:
if isinstance(combine, str) and combine == "cut":
newS = self._cutFromBase(r)
elif isinstance(combine, bool) and combine:
newS = self._combineWithBase(r)
else:
newS = self.newObject([r])
it could be refactored to:
return self._combineWithBase(r, combine)
(ofc you'd need to update _combineWithBase
accordingly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think I've refactored _combineWithBase
like you thought about it.
I'm proposing to add a breaking change to text
that has both cut
and combine
kwarg. In my opinion we should get rid of the cut
kwarg and keep the combine
consistent with other methods. It would be fairly easy for user to make the change but would result in errors in model that still use it
Let me know if there is an agreement on this or not so I can make the change (or not) @adam-urbanczyk @jmwright @marcus7070
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long term it is fine, but please use this for now:
Line 8 in ea66ded
class deprecate_kwarg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Jojain !
Well ok, just let me know if there is something I missed, I'm not really used to add tests so I'm not always sure if it's done right or not |
Co-authored-by: Jeremy Wright <wrightjmf@gmail.com>
As discussed on discord I'm not sure it make sense to add the option for I've not added it to Finally github says there is conflicts but there isnt, I cannot solve it so a lead dev will have to resolve the so called conflicts |
My vote would probably be to keep |
Well I don't think it makes sense to have combine/cut with |
To make everything self-consistent (make the code shorter and get rid of special cases) it would make sense to add the option to every method that allows to use combine. For now forget about |
Hopefully this is done. In the end I didn't added combine option to I still don't know about the merging issues I let you check that, all test are green on my side. |
I see that there were commits after the last comment that this was ready. Is it ready for a final review now? |
@jmwright yes it is |
Please don't forget to update |
* _combineWithBase allows to clean too * added missing clean params
Needed for backward compatibility (one test failing).
else: | ||
newS = self.newObject([r]) | ||
# do not combine branch | ||
newS = self.newObject(obj if not isinstance(obj, Shape) else [obj]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that that is the optimal way. We might want to rewrite the failing test
@@ -61,6 +62,7 @@ | |||
|
|||
CQObject = Union[Vector, Location, Shape, Sketch] | |||
VectorLike = Union[Tuple[float, float], Tuple[float, float, float], Vector] | |||
CombineMode = Union[bool, Literal["cut", "a", "s"]] # a : additive, s: subtractive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added also modes used in Sketch. Note that it is better to use Literal for typing.
Thanks for the contribution @Jojain ! I did some rework, let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments aside I'm good with what you came up with. I think the code simplification is great.
It would be useful to document the changes in the docs as they introduce a "new concept" which is that every protusion method can also be used to remove material.
I think we should lead newcomers in the docs to use the combine
argument so hopefully CQ scripts would be more unified
cadquery/cq.py
Outdated
|
||
r = self._extrude(None, both=both, taper=taper, upToFace=faceIndex) | ||
# Handle `until` multiple values | ||
if isinstance(until, str) and until in ("next", "last") and combine: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If combine is "cut" the conditional test will be True but the executed code won't be what's expected.
That's why I added an explicit condition to check if combine=="cut"
and if this True we call the cutBlind
method.
I think we should keep my first check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, missed that. I think it is now fixed.
@@ -2392,7 +2393,7 @@ def each( | |||
self: T, | |||
callback: Callable[[CQObject], Shape], | |||
useLocalCoordinates: bool = False, | |||
combine: Union[bool, str] = True, | |||
combine: CombineMode = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already discussed my opinion on adding combine
arg for this method so I won't talk about it again but in any case if we decide to add it we should probably write somewhere that the new default behaviour is to combine
with the base which wasnt the case before. Same remark goes for eachpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Do you think it would make sense to set it to False? I'm kind of hesitating about it. What do you think @jmwright?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting it to False would make things transparent but we would loose consistency with other methods.
I don't think each and eachpoint are that used so a breaking change here would probably not be a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I added a note in changes.md
@Jojain This looks good to me. Do you think it is ready to merge? |
@jmwright @adam-urbanczyk It's all good for me |
Thanks! |
Aims to target #30 I added the possibility to use combine="cut" for 3D operations to remove material from the context solid.
It's essentially a shorcut of calling
cut()
later.I didn't added it for
extrude
as it has alreadycutBlind
that does the same thing, I didn't added it totext
since it has acut
kwarg. I think it should be changed to be consistent with all the other methods but since it will probably not be agreed on I didn't changed it.As I already said in #832, I still think everything should be made consistent and that we should remove/deprecate things that aren't consistent. I know it would require breaking change but not doing it will likely confuse more and more new users.