-
-
Notifications
You must be signed in to change notification settings - Fork 511
(Part 2/3) Project 3D part to plane #2002
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
base: master
Are you sure you want to change the base?
Changes from all commits
4552668
a635e08
7e0a42f
d8fb549
e780119
98d8f1a
403b694
ef1c187
7412ba8
6f597fe
af418fe
d824877
6e798eb
1263b15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,6 +159,9 @@ | |
| BRepAlgoAPI_Check, | ||
| ) | ||
|
|
||
| from OCP.HLRAlgo import HLRAlgo_Projector | ||
| from OCP.HLRBRep import HLRBRep_Algo, HLRBRep_HLRToShape | ||
|
|
||
| from OCP.Geom import ( | ||
| Geom_BezierCurve, | ||
| Geom_ConicalSurface, | ||
|
|
@@ -7971,3 +7974,63 @@ def closest(s1: Shape, s2: Shape) -> tuple[Vector, Vector]: | |
| assert ext.Perform() | ||
|
|
||
| return Vector(ext.PointOnShape1(1)), Vector(ext.PointOnShape2(1)) | ||
|
|
||
|
|
||
| def hlr( | ||
|
adam-urbanczyk marked this conversation as resolved.
|
||
| shape, pnt: VectorLike, dir: VectorLike, focus: float | None = None, | ||
|
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. I would like to provide an "up" direction with default (0, 0, 1) either in this PR or follow up. Otherwise we continue to have the problem of uncontrolled orientation.
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. +1 |
||
| ) -> tuple[Compound, Compound]: | ||
| """ | ||
| Project shape onto a plane defined by pnt and dir and apply hidden line removal. Useful for | ||
| generating views for technical drawings. | ||
| """ | ||
| hlr = HLRBRep_Algo() | ||
| hlr.Add(shape.wrapped) | ||
|
|
||
| coordinate_system = gp_Ax2(Vector(pnt).toPnt(), Vector(dir).toDir()) | ||
|
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.
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. Sure, go for it. |
||
|
|
||
| if focus is not None: | ||
| projector = HLRAlgo_Projector(coordinate_system, focus) | ||
| else: | ||
| projector = HLRAlgo_Projector(coordinate_system) | ||
|
|
||
| hlr.Projector(projector) | ||
| hlr.Update() | ||
| hlr.Hide() | ||
|
|
||
| hlr_shapes = HLRBRep_HLRToShape(hlr) | ||
|
|
||
| visible = [] | ||
|
|
||
| visible_sharp_edges = hlr_shapes.VCompound() | ||
| if not visible_sharp_edges.IsNull(): | ||
| visible.append(visible_sharp_edges) | ||
|
|
||
| visible_smooth_edges = hlr_shapes.Rg1LineVCompound() | ||
| if not visible_smooth_edges.IsNull(): | ||
| visible.append(visible_smooth_edges) | ||
|
|
||
| visible_contour_edges = hlr_shapes.OutLineVCompound() | ||
| if not visible_contour_edges.IsNull(): | ||
| visible.append(visible_contour_edges) | ||
|
|
||
| hidden = [] | ||
|
|
||
| hidden_sharp_edges = hlr_shapes.HCompound() | ||
| if not hidden_sharp_edges.IsNull(): | ||
| hidden.append(hidden_sharp_edges) | ||
|
|
||
| hidden_contour_edges = hlr_shapes.OutLineHCompound() | ||
| if not hidden_contour_edges.IsNull(): | ||
| hidden.append(hidden_contour_edges) | ||
|
|
||
| # Fix the underlying geometry - otherwise we will get segfaults | ||
| for el in visible: | ||
| BRepLib.BuildCurves3d_s(el, TOLERANCE) | ||
| for el in hidden: | ||
| BRepLib.BuildCurves3d_s(el, TOLERANCE) | ||
|
|
||
| # Extract edges | ||
| visible_edges = compound(_compound_or_shape(visible).Edges()) | ||
| hidden_edges = compound(_compound_or_shape(hidden).Edges()) | ||
|
|
||
| return visible_edges, hidden_edges | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from cadquery import Workplane, exporters | ||
|
|
||
| viewpoint = { | ||
| "top": (0, 0, 1), | ||
| "left": (1, 0, 0), | ||
| "front": (0, 1, 0), | ||
| "ortho": (1, 1, 1), | ||
| } | ||
|
|
||
|
|
||
| def exportDXF3rdAngleProjection(my_part: Workplane, prefix: str) -> None: | ||
| for name, direction in viewpoint.items(): | ||
| exporters.exportDXFProjection( | ||
| my_part, (0, 0, 0), direction, f"{prefix}{name}.dxf", doc_units=6, | ||
| ) | ||
|
|
||
|
|
||
| def exportSVG3rdAngleProjection(my_part, prefix: str) -> None: | ||
| for name, direction in viewpoint.items(): | ||
| exporters.exportSVG( | ||
| my_part, f"{prefix}{name}.svg", opts={"projectionDir": direction,}, | ||
| ) | ||
|
|
||
|
|
||
| # Build the part | ||
| width = 10 | ||
| depth = 10 | ||
| height = 10 | ||
| hole_dia = 3.0 | ||
|
|
||
| baseplate = Workplane("XY").box(width, depth, height).edges("|Z").fillet(2.0) # | ||
| drilled = baseplate.faces(">Z").workplane().cskHole(hole_dia, hole_dia * 2, 82.0) # | ||
|
|
||
| # Expected DXF output to be identical to SVG output | ||
| exportSVG3rdAngleProjection(drilled, "") | ||
| exportDXF3rdAngleProjection(drilled, "") | ||
| exportDXF3rdAngleProjection(drilled.val(), "shape_") |
Uh oh!
There was an error while loading. Please reload this page.