MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / getAlignedSize

Method getAlignedSize

src/Mod/TechDraw/App/DrawComplexSection.cpp:1217–1251  ·  view source on GitHub ↗

align a copy of the piece with OXYZ so we can use bounding box to get width, depth, height of the piece. We copy the piece so the transformation does not affect the original.

Source from the content-addressed store, hash-verified

1215//! width, depth, height of the piece. We copy the piece so the transformation
1216//! does not affect the original.
1217AlignedSizeResponse DrawComplexSection::getAlignedSize(const TopoDS_Shape& pieceRotated,
1218 int iPiece) const
1219{
1220 gp_Ax3 stdCS; //OXYZ
1221 BRepBuilderAPI_Copy BuilderPieceCopy(pieceRotated);
1222 TopoDS_Shape copyPieceRotatedShape = BuilderPieceCopy.Shape();
1223 gp_Trsf xPieceAlign;
1224 xPieceAlign.SetTransformation(stdCS, getProjectionCS());
1225 BRepBuilderAPI_Transform mkTransAlign(copyPieceRotatedShape, xPieceAlign);
1226 TopoDS_Shape pieceAligned = mkTransAlign.Shape();
1227 // we may have shifted our piece off center, so we better recenter here
1228 gp_Trsf xPieceRecenter;
1229 gp_Vec rotatedCentroid = gp_Vec(ShapeUtils::findCentroid(pieceAligned).XYZ());
1230 xPieceRecenter.SetTranslation(rotatedCentroid * -1.0);
1231 BRepBuilderAPI_Transform mkTransRecenter(pieceAligned, xPieceRecenter, true);
1232 pieceAligned = mkTransRecenter.Shape();
1233
1234 if (debugSection()) {
1235 stringstream ss;
1236 ss << "DCSDpieceAligned" << iPiece << ".brep";
1237 BRepTools::Write(pieceAligned, ss.str().c_str());//debug
1238 ss.clear();
1239 ss.str(std::string());
1240 }
1241 Bnd_Box shapeBox;
1242 shapeBox.SetGap(0.0);
1243 BRepBndLib::AddOptimal(pieceAligned, shapeBox);
1244 double xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0; //NOLINT
1245 shapeBox.Get(xMin, yMin, zMin, xMax, yMax, zMax);
1246 double pieceXSize(xMax - xMin);
1247 double pieceYSize(yMax - yMin);
1248 double pieceZSize(zMax - zMin);
1249 Base::Vector3d pieceSize{pieceXSize, pieceYSize, pieceZSize};
1250 return {pieceAligned, pieceSize, zMax};
1251}
1252
1253//! cut the rawShape with a tool derived from the segmentFace and align the result with the
1254//! page plane. Also supplies the piece size.

Callers

nothing calls this directly

Calls 7

XYZMethod · 0.80
gp_VecClass · 0.50
ShapeMethod · 0.45
c_strMethod · 0.45
strMethod · 0.45
clearMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected