Toposhape/Part: Transfer in _makETransform, makETransform, makEGTransform

This commit is contained in:
Zheng, Lei
2024-02-20 10:10:57 -05:00
committed by bgbsww
parent 5e0e746629
commit 75296929d6
2 changed files with 219 additions and 0 deletions

View File

@@ -84,6 +84,8 @@
#include <App/ElementNamingUtils.h>
#include <BRepLib.hxx>
#include <BRepBuilderAPI_GTransform.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include "Geometry.h"
FC_LOG_LEVEL_INIT("TopoShape", true, true) // NOLINT
@@ -2506,6 +2508,88 @@ TopoShape& TopoShape::makeElementOrderedWires(const std::vector<TopoShape>& shap
return makeElementCompound(wires, nullptr, SingleShapeCompoundCreationPolicy::returnShape);
}
bool TopoShape::_makeElementTransform(const TopoShape &shape,
const Base::Matrix4D &rclTrf, const char *op, bool checkScale, bool copy)
{
if(checkScale) {
auto scaleType = rclTrf.hasScale();
if (scaleType != Base::ScaleType::NoScaling && scaleType != Base::ScaleType::Uniform) {
makeElementGTransform(shape,rclTrf,op,copy);
return true;
}
}
makeElementTransform(shape,convert(rclTrf),op,copy);
return false;
}
TopoShape &TopoShape::makeElementTransform(const TopoShape &shape, const gp_Trsf &trsf, const char *op, bool copy) {
if(!copy) {
// OCCT checks the ScaleFactor against gp::Resolution() which is DBL_MIN!!!
copy = trsf.ScaleFactor()*trsf.HVectorialPart().Determinant() < 0. ||
Abs(Abs(trsf.ScaleFactor()) - 1) > Precision::Confusion();
}
TopoShape tmp(shape);
if(copy) {
if(shape.isNull())
FC_THROWM(NullShapeException, "Null input shape");
BRepBuilderAPI_Transform mkTrf(shape.getShape(), trsf, Standard_True);
// TODO: calling Moved() is to make sure the shape has some Location,
// which is necessary for STEP export to work. However, if we reach
// here, it porabably means BRepBuilderAPI_Transform has modified
// underlying shapes (because of scaling), it will break compound child
// parent relationship anyway. In short, STEP import/export will most
// likely break badly if there is any scaling involved
tmp.setShape(mkTrf.Shape().Moved(gp_Trsf()), false);
} else
tmp.move(trsf);
if(op || (shape.Tag && shape.Tag!=Tag)) {
setShape(tmp._Shape);
initCache();
if (!Hasher)
Hasher = tmp.Hasher;
copyElementMap(tmp, op);
} else
*this = tmp;
return *this;
}
TopoShape &TopoShape::makeElementGTransform(const TopoShape &shape,
const Base::Matrix4D &rclTrf, const char *op, bool copy)
{
if(shape.isNull())
FC_THROWM(NullShapeException, "Null input shape");
// if(!op) op = Part::OpCodes::Gtransform;
gp_GTrsf mat;
mat.SetValue(1,1,rclTrf[0][0]);
mat.SetValue(2,1,rclTrf[1][0]);
mat.SetValue(3,1,rclTrf[2][0]);
mat.SetValue(1,2,rclTrf[0][1]);
mat.SetValue(2,2,rclTrf[1][1]);
mat.SetValue(3,2,rclTrf[2][1]);
mat.SetValue(1,3,rclTrf[0][2]);
mat.SetValue(2,3,rclTrf[1][2]);
mat.SetValue(3,3,rclTrf[2][2]);
mat.SetValue(1,4,rclTrf[0][3]);
mat.SetValue(2,4,rclTrf[1][3]);
mat.SetValue(3,4,rclTrf[2][3]);
// geometric transformation
TopoShape tmp(shape);
BRepBuilderAPI_GTransform mkTrf(shape.getShape(), mat, copy);
tmp.setShape(mkTrf.Shape(), false);
if(op || (shape.Tag && shape.Tag!=Tag)) {
setShape(tmp._Shape);
initCache();
if (!Hasher)
Hasher = tmp.Hasher;
copyElementMap(tmp, op);
} else
*this = tmp;
return *this;
}
TopoShape&
TopoShape::makeElementCopy(const TopoShape& shape, const char* op, bool copyGeom, bool copyMesh)