FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SimpleCADAPI/src/simplecadapi/kernel/ocp_transforms.py at master · PhySpace/SimpleCADAPI · GitHub
PhySpace
/
SimpleCADAPI
Public
Notifications
You must be signed in to change notification settings
Fork
22
Star
140
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_transforms.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
119 lines (103 loc) · 3.39 KB
Breadcrumbs
SimpleCADAPI
/
src
/
simplecadapi
/
kernel
/
ocp_transforms.py
Copy path
File metadata and controls
119 lines (103 loc) · 3.39 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""Thin OCP-native transform helpers for public geometry wrappers."""
from
__future__
import
annotations
import
math
from
typing
import
Tuple
from
OCP
.
BRepBuilderAPI
import
BRepBuilderAPI_Transform
from
OCP
.
TopAbs
import
(
TopAbs_COMPOUND
,
TopAbs_EDGE
,
TopAbs_FACE
,
TopAbs_SHELL
,
TopAbs_SOLID
,
TopAbs_VERTEX
,
TopAbs_WIRE
,
)
from
OCP
.
TopoDS
import
TopoDS
from
OCP
.
gp
import
gp_Ax1
,
gp_Ax2
,
gp_Dir
,
gp_Pnt
,
gp_Trsf
,
gp_Vec
from
..
core
import
AnyShape
,
Compound
,
Edge
,
Face
,
Shell
,
Solid
,
Vertex
,
Wire
def
_shape_from_transformed
(
shape
:
AnyShape
,
transformed
)
->
AnyShape
:
shape_type
=
transformed
.
ShapeType
()
if
shape_type
==
TopAbs_VERTEX
:
return
Vertex
(
TopoDS
.
Vertex_s
(
transformed
))
if
shape_type
==
TopAbs_EDGE
:
return
Edge
(
TopoDS
.
Edge_s
(
transformed
))
if
shape_type
==
TopAbs_WIRE
:
return
Wire
(
TopoDS
.
Wire_s
(
transformed
))
if
shape_type
==
TopAbs_FACE
:
return
Face
(
TopoDS
.
Face_s
(
transformed
))
if
shape_type
==
TopAbs_SHELL
:
return
Shell
(
TopoDS
.
Shell_s
(
transformed
))
if
shape_type
==
TopAbs_SOLID
:
return
Solid
(
TopoDS
.
Solid_s
(
transformed
))
if
shape_type
==
TopAbs_COMPOUND
:
return
Compound
(
TopoDS
.
Compound_s
(
transformed
))
raise
ValueError
(
f"Unsupported transformed shape type:
{
shape_type
}
"
)
def
apply_transform
(
shape
:
AnyShape
,
trsf
:
gp_Trsf
)
->
AnyShape
:
xform
=
BRepBuilderAPI_Transform
(
shape
.
wrapped
,
trsf
,
True
)
xform
.
Build
()
if
not
xform
.
IsDone
():
raise
ValueError
(
"OCP transform build failed"
)
return
_shape_from_transformed
(
shape
,
xform
.
Shape
())
def
translate_shape_ocp
(
shape
:
AnyShape
,
vector
:
Tuple
[
float
,
float
,
float
]
)
->
AnyShape
:
trsf
=
gp_Trsf
()
trsf
.
SetTranslation
(
gp_Vec
(
float
(
vector
[
0
]),
float
(
vector
[
1
]),
float
(
vector
[
2
])))
return
apply_transform
(
shape
,
trsf
)
def
rotate_shape_ocp
(
shape
:
AnyShape
,
angle_degrees
:
float
,
axis
:
Tuple
[
float
,
float
,
float
],
origin
:
Tuple
[
float
,
float
,
float
],
)
->
AnyShape
:
trsf
=
gp_Trsf
()
trsf
.
SetRotation
(
gp_Ax1
(
gp_Pnt
(
float
(
origin
[
0
]),
float
(
origin
[
1
]),
float
(
origin
[
2
])),
gp_Dir
(
float
(
axis
[
0
]),
float
(
axis
[
1
]),
float
(
axis
[
2
])),
),
math
.
radians
(
float
(
angle_degrees
)),
)
return
apply_transform
(
shape
,
trsf
)
def
mirror_shape_ocp
(
shape
:
AnyShape
,
plane_origin
:
Tuple
[
float
,
float
,
float
],
plane_normal
:
Tuple
[
float
,
float
,
float
],
)
->
AnyShape
:
trsf
=
gp_Trsf
()
trsf
.
SetMirror
(
gp_Ax2
(
gp_Pnt
(
float
(
plane_origin
[
0
]),
float
(
plane_origin
[
1
]),
float
(
plane_origin
[
2
])
),
gp_Dir
(
float
(
plane_normal
[
0
]),
float
(
plane_normal
[
1
]),
float
(
plane_normal
[
2
]),
),
)
)
return
apply_transform
(
shape
,
trsf
)
def
place_shape_ocp
(
shape
:
AnyShape
,
origin
:
Tuple
[
float
,
float
,
float
],
x_axis
:
Tuple
[
float
,
float
,
float
],
y_axis
:
Tuple
[
float
,
float
,
float
],
z_axis
:
Tuple
[
float
,
float
,
float
],
)
->
AnyShape
:
trsf
=
gp_Trsf
()
trsf
.
SetValues
(
float
(
x_axis
[
0
]),
float
(
y_axis
[
0
]),
float
(
z_axis
[
0
]),
float
(
origin
[
0
]),
float
(
x_axis
[
1
]),
float
(
y_axis
[
1
]),
float
(
z_axis
[
1
]),
float
(
origin
[
1
]),
float
(
x_axis
[
2
]),
float
(
y_axis
[
2
]),
float
(
z_axis
[
2
]),
float
(
origin
[
2
]),
)
return
apply_transform
(
shape
,
trsf
)
Back
|
FazBrowse Home
|
New Git URL