Location in 3D space. Depending on usage can be absolute or relative. This class wraps the TopLoc_Location class from OCCT. It can be used to move Shape objects in both relative and absolute manner. It is the preferred type to locate objects in CQ.
| 1020 | |
| 1021 | |
| 1022 | class Location(object): |
| 1023 | """Location in 3D space. Depending on usage can be absolute or relative. |
| 1024 | |
| 1025 | This class wraps the TopLoc_Location class from OCCT. It can be used to move Shape |
| 1026 | objects in both relative and absolute manner. It is the preferred type to locate objects |
| 1027 | in CQ. |
| 1028 | """ |
| 1029 | |
| 1030 | wrapped: TopLoc_Location |
| 1031 | |
| 1032 | @multidispatch |
| 1033 | def __init__(self, t: VectorLike) -> None: |
| 1034 | """Location with translation t with respect to the original location.""" |
| 1035 | |
| 1036 | T = gp_Trsf() |
| 1037 | T.SetTranslationPart(Vector(t).wrapped) |
| 1038 | |
| 1039 | self.wrapped = TopLoc_Location(T) |
| 1040 | |
| 1041 | @multidispatch |
| 1042 | def __init__( |
| 1043 | self, |
| 1044 | x: Real = 0, |
| 1045 | y: Real = 0, |
| 1046 | z: Real = 0, |
| 1047 | rx: Real = 0, |
| 1048 | ry: Real = 0, |
| 1049 | rz: Real = 0, |
| 1050 | ) -> None: |
| 1051 | """Location with translation (x,y,z) and 3 rotation angles.""" |
| 1052 | |
| 1053 | if any((x, y, z, rx, ry, rz)): |
| 1054 | |
| 1055 | T = gp_Trsf() |
| 1056 | |
| 1057 | q = gp_Quaternion() |
| 1058 | q.SetEulerAngles(gp_Extrinsic_XYZ, radians(rx), radians(ry), radians(rz)) |
| 1059 | |
| 1060 | T.SetRotation(q) |
| 1061 | T.SetTranslationPart(Vector(x, y, z).wrapped) |
| 1062 | |
| 1063 | loc = TopLoc_Location(T) |
| 1064 | else: |
| 1065 | # in this case location is flagged as identity |
| 1066 | loc = TopLoc_Location() |
| 1067 | |
| 1068 | self.wrapped = loc |
| 1069 | |
| 1070 | @multidispatch |
| 1071 | def __init__(self, t: Plane) -> None: |
| 1072 | """Location corresponding to the location of the Plane t.""" |
| 1073 | |
| 1074 | T = gp_Trsf() |
| 1075 | T.SetTransformation(gp_Ax3(t.origin.toPnt(), t.zDir.toDir(), t.xDir.toDir())) |
| 1076 | T.Invert() |
| 1077 | |
| 1078 | self.wrapped = TopLoc_Location(T) |
| 1079 |
no outgoing calls