FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SimpleCADAPI/src/simplecadapi/kernel/ocp_features.py at master · PhySpace/SimpleCADAPI · GitHub
PhySpace
/
SimpleCADAPI
Public
Notifications
You must be signed in to change notification settings
Fork
22
Star
128
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SimpleCADAPI
/
src
/
simplecadapi
/
kernel
/
ocp_features.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
95 lines (78 loc) · 3.13 KB
Breadcrumbs
SimpleCADAPI
/
src
/
simplecadapi
/
kernel
/
ocp_features.py
Copy path
File metadata and controls
95 lines (78 loc) · 3.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""Thin OCP-native feature builders for loft/sweep/helical sweep."""
from
__future__
import
annotations
from
typing
import
Any
,
Iterable
,
Optional
,
Sequence
from
OCP
.
BRepBuilderAPI
import
BRepBuilderAPI_MakeFace
,
BRepBuilderAPI_Transform
from
OCP
.
BRepOffsetAPI
import
BRepOffsetAPI_MakePipeShell
,
BRepOffsetAPI_ThruSections
from
OCP
.
TopAbs
import
TopAbs_VERTEX
,
TopAbs_WIRE
from
OCP
.
gp
import
gp_Trsf
,
gp_Vec
from
OCP
.
TopoDS
import
TopoDS
from
.
ocp_curves
import
make_helix_wire
def
make_face_from_wire
(
wire
):
builder
=
BRepBuilderAPI_MakeFace
(
wire
,
True
)
if
not
builder
.
IsDone
():
raise
ValueError
(
"OCP face builder failed"
)
return
builder
.
Face
()
def
make_face_from_wires
(
outer_wire
,
inner_wires
:
Sequence
[
Any
]):
builder
=
BRepBuilderAPI_MakeFace
(
outer_wire
,
True
)
if
not
builder
.
IsDone
():
raise
ValueError
(
"OCP face builder failed for outer wire"
)
for
inner_wire
in
inner_wires
:
builder
.
Add
(
TopoDS
.
Wire_s
(
inner_wire
.
Reversed
()))
if
not
builder
.
IsDone
():
raise
ValueError
(
"OCP face builder failed while adding inner wire"
)
return
builder
.
Face
()
def
make_loft_solid
(
sections
:
Iterable
[
Any
],
ruled
:
bool
=
False
):
builder
=
BRepOffsetAPI_ThruSections
(
True
,
bool
(
ruled
))
builder
.
CheckCompatibility
(
True
)
for
section
in
sections
:
if
section
.
ShapeType
()
==
TopAbs_VERTEX
:
builder
.
AddVertex
(
TopoDS
.
Vertex_s
(
section
))
elif
section
.
ShapeType
()
==
TopAbs_WIRE
:
builder
.
AddWire
(
TopoDS
.
Wire_s
(
section
))
else
:
raise
TypeError
(
"loft sections must contain only vertices or wires"
)
builder
.
Build
()
if
not
builder
.
IsDone
():
raise
ValueError
(
"OCP loft builder failed"
)
return
builder
.
Shape
()
def
make_sweep_solid
(
profile_wire
,
path_wire
,
is_frenet
:
bool
=
False
):
builder
=
BRepOffsetAPI_MakePipeShell
(
path_wire
)
builder
.
SetMode
(
bool
(
is_frenet
))
builder
.
Add
(
profile_wire
,
False
,
False
)
builder
.
Build
()
if
not
builder
.
IsDone
():
raise
ValueError
(
"OCP sweep builder failed"
)
if
not
builder
.
MakeSolid
():
raise
ValueError
(
"OCP sweep solid conversion failed"
)
return
builder
.
Shape
()
def
translate_shape
(
shape
,
vector
:
Sequence
[
float
]):
trsf
=
gp_Trsf
()
trsf
.
SetTranslation
(
gp_Vec
(
float
(
vector
[
0
]),
float
(
vector
[
1
]),
float
(
vector
[
2
])))
builder
=
BRepBuilderAPI_Transform
(
shape
,
trsf
,
True
)
builder
.
Build
()
if
not
builder
.
IsDone
():
raise
ValueError
(
"OCP feature translation failed"
)
return
builder
.
Shape
()
def
make_helical_sweep_solid
(
profile_wire
,
pitch
:
float
,
height
:
float
,
radius
:
float
,
center
:
Sequence
[
float
],
direction
:
Sequence
[
float
],
x_direction
:
Optional
[
Sequence
[
float
]]
=
None
,
):
helix
=
make_helix_wire
(
pitch
,
height
,
radius
,
center
,
direction
,
x_direction
=
x_direction
,
)
radial_direction
=
x_direction
if
x_direction
is
not
None
else
(
1.0
,
0.0
,
0.0
)
moved_profile
=
translate_shape
(
profile_wire
,
tuple
(
float
(
radius
)
*
float
(
component
)
for
component
in
radial_direction
),
)
return
make_sweep_solid
(
moved_profile
,
helix
,
is_frenet
=
True
)
Back
|
FazBrowse Home
|
New Git URL