add convenience methods to directly set/get a placement to/from a shape

This commit is contained in:
wmayer
2017-09-19 15:43:28 +02:00
parent c9fb691afe
commit 33baa4a9f2
2 changed files with 34 additions and 0 deletions

View File

@@ -433,6 +433,36 @@ Base::Matrix4D TopoShape::getTransform(void) const
return mtrx;
}
void TopoShape::setPlacement(const Base::Placement& rclTrf)
{
const Base::Vector3d& pos = rclTrf.getPosition();
Base::Vector3d axis;
double angle;
rclTrf.getRotation().getValue(axis, angle);
gp_Trsf trsf;
trsf.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Dir(axis.x, axis.y, axis.z)), angle);
trsf.SetTranslationPart(gp_Vec(pos.x, pos.y, pos.z));
TopLoc_Location loc(trsf);
_Shape.Location(loc);
}
Base::Placement TopoShape::getPlacemet(void) const
{
TopLoc_Location loc = _Shape.Location();
gp_Trsf trsf = loc.Transformation();
gp_XYZ pos = trsf.TranslationPart();
gp_XYZ axis;
Standard_Real angle;
trsf.GetRotation(axis, angle);
Base::Rotation rot(Base::Vector3d(axis.X(), axis.Y(), axis.Z()), angle);
Base::Placement placement(Base::Vector3d(pos.X(), pos.Y(), pos.Z()), rot);
return placement;
}
void TopoShape::read(const char *FileName)
{
Base::FileInfo File(FileName);

View File

@@ -77,8 +77,12 @@ public:
//@{
/// set the transformation of the CasCade Shape
void setTransform(const Base::Matrix4D& rclTrf);
/// set the transformation of the CasCade Shape
void setPlacement(const Base::Placement& rclTrf);
/// get the transformation of the CasCade Shape
Base::Matrix4D getTransform(void) const;
/// get the transformation of the CasCade Shape
Base::Placement getPlacemet(void) const;
/// Bound box from the CasCade shape
Base::BoundBox3d getBoundBox(void)const;
virtual bool getCenterOfGravity(Base::Vector3d& center) const;