-
-
Notifications
You must be signed in to change notification settings - Fork 524
Better imprint for assy #2069
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
Open
adam-urbanczyk
wants to merge
6
commits into
master
Choose a base branch
from
adam-imprint-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−13
Open
Better imprint for assy #2069
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f688133
Better imprint for assy
adam-urbanczyk a4acc30
Typing fix
adam-urbanczyk bd53fc8
Add a note about glue and threads.
adam-urbanczyk f66dbfb
Tweak comments and docstrings
adam-urbanczyk 4d80f4c
Add a test for subassy imprinting
adam-urbanczyk 48a005a
Changed the default option to partial
adam-urbanczyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,7 +37,7 @@ | |||||
| ) | ||||||
| from OCP.BRepAlgoAPI import BRepAlgoAPI_Fuse | ||||||
| from OCP.TopTools import TopTools_ListOfShape | ||||||
| from OCP.BOPAlgo import BOPAlgo_GlueEnum, BOPAlgo_MakeConnected | ||||||
| from OCP.BOPAlgo import BOPAlgo_GlueEnum, BOPAlgo_Builder | ||||||
| from OCP.TopoDS import TopoDS_Shape | ||||||
| from OCP.gp import gp_EulerSequence | ||||||
|
|
||||||
|
|
@@ -49,7 +49,7 @@ | |||||
| ) | ||||||
|
|
||||||
| from .geom import Location | ||||||
| from .shapes import Shape, Solid, Compound | ||||||
| from .shapes import Shape, Solid, Compound, GlueLiteral, _set_glue, _set_builder_options | ||||||
| from .exporters.vtk import toString, extractEdgesFaces | ||||||
| from ..cq import Workplane | ||||||
| from ..utils import BiDict | ||||||
|
|
@@ -855,9 +855,14 @@ def toFusedCAF( | |||||
| return top_level_lbl, doc | ||||||
|
|
||||||
|
|
||||||
| def imprint(assy: AssemblyProtocol) -> Tuple[Shape, Dict[Shape, Tuple[str, ...]]]: | ||||||
| def imprint( | ||||||
| assy: AssemblyProtocol, tol: float = 0.0, glue: GlueLiteral = "partial", | ||||||
| ) -> Tuple[Shape, Dict[Shape, Tuple[str, ...]]]: | ||||||
| """ | ||||||
| Imprint all the solids and construct a dictionary mapping imprinted solids to names from the input assy. | ||||||
|
|
||||||
| Depending on the use case, it might be required do use different `glue` option. Moreover, for large models | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| it might be needed to limit the number of threads using :meth:`cadquery.func.setThreads` | ||||||
| """ | ||||||
|
|
||||||
| # make the id map | ||||||
|
|
@@ -868,22 +873,28 @@ def imprint(assy: AssemblyProtocol) -> Tuple[Shape, Dict[Shape, Tuple[str, ...]] | |||||
| id_map[s] = name | ||||||
|
|
||||||
| # connect topologically | ||||||
| bldr = BOPAlgo_MakeConnected() | ||||||
| bldr.SetRunParallel(True) | ||||||
| bldr.SetUseOBB(True) | ||||||
| builder = BOPAlgo_Builder() | ||||||
|
|
||||||
| _set_glue(builder, glue) | ||||||
| _set_builder_options(builder, tol) | ||||||
|
|
||||||
| for obj in id_map: | ||||||
| bldr.AddArgument(obj.wrapped) | ||||||
| builder.AddArgument(obj.wrapped) | ||||||
|
|
||||||
| bldr.Perform() | ||||||
| res = Shape(bldr.Shape()) | ||||||
| builder.Perform() | ||||||
| res = Shape(builder.Shape()) | ||||||
|
|
||||||
| # make the connected solid -> id map | ||||||
| ocp_origins = builder.Origins() | ||||||
| origins: Dict[Shape, Tuple[str, ...]] = {} | ||||||
|
|
||||||
| for s in res.Solids(): | ||||||
| ids = tuple(id_map[Solid(el)] for el in bldr.GetOrigins(s.wrapped)) | ||||||
| # if GetOrigins yields nothing, solid was not modified | ||||||
| if ocp_origins.IsBound(s.wrapped): | ||||||
| # if ocp_origins does not contain the solid, it was not modified | ||||||
| ids = tuple(id_map[Solid(el)] for el in ocp_origins.Find(s.wrapped)) | ||||||
| else: | ||||||
| ids = () | ||||||
|
|
||||||
| origins[s] = ids if ids else (id_map[s],) | ||||||
|
|
||||||
| return res, origins | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6956,12 +6956,15 @@ def enclose( | |||||
| def imprint( | ||||||
| *shapes: Shape, | ||||||
| tol: float = 0.0, | ||||||
| glue: GlueLiteral = "full", | ||||||
| glue: GlueLiteral = "partial", | ||||||
| history: History | None = None, | ||||||
| name: str | None = None, | ||||||
| ) -> Shape: | ||||||
| """ | ||||||
| Imprint arbitrary number of shapes. | ||||||
|
|
||||||
| Depending on the use case, it might be required do use different `glue` option. Moreover, for large models | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| it might be needed to limit the number of threads using :meth:`cadquery.func.setThreads` | ||||||
| """ | ||||||
|
|
||||||
| builder = BOPAlgo_Builder() | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.