MCPcopy Index your code
hub / github.com/CadQuery/cadquery / Location

Class Location

cadquery/occ_impl/geom.py:1022–1177  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

1020
1021
1022class 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

Callers 15

showablesFunction · 0.90
test_showFunction · 0.90
test_Plane_from_LocationFunction · 0.90
test_assy_vtk_rotationFunction · 0.90
make_modelFunction · 0.90
__init__Method · 0.85
faceMethod · 0.85
rarrayMethod · 0.85
parrayMethod · 0.85
distributeMethod · 0.85
pushMethod · 0.85

Calls

no outgoing calls

Tested by 15

showablesFunction · 0.72
test_showFunction · 0.72
test_Plane_from_LocationFunction · 0.72
test_assy_vtk_rotationFunction · 0.72
make_modelFunction · 0.72
testLocationMethod · 0.68
test_locatedFunction · 0.68
testLocatedMovedMethod · 0.68
testEachpointMethod · 0.68
testSketchMethod · 0.68
test_utilsFunction · 0.68