[TD]Lint brushing

This commit is contained in:
wandererfan
2025-04-29 09:22:11 -04:00
parent 59801c8366
commit b4a9c2222c
5 changed files with 63 additions and 77 deletions

View File

@@ -100,11 +100,11 @@ using namespace TechDraw;
using DU = DrawUtil;
// class to store geometry of points where the section line changes direction
ChangePoint::ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection)
ChangePoint::ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection) :
m_location(location),
m_preDirection(preDirection),
m_postDirection(postDirection)
{
m_location = location;
m_preDirection = preDirection;
m_postDirection = postDirection;
}
ChangePoint::ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection)
@@ -122,10 +122,12 @@ void ChangePoint::scale(double scaleFactor)
m_location = m_location * scaleFactor;
}
//NOLINTBEGIN
const char* DrawViewSection::SectionDirEnums[] =
{"Right", "Left", "Up", "Down", "Aligned", nullptr};
const char* DrawViewSection::CutSurfaceEnums[] = {"Hide", "Color", "SvgHatch", "PatHatch", nullptr};
//NOLINTEND
constexpr double stretchMinimum{EWTOLERANCE};
constexpr double stretchMaximum{std::numeric_limits<double>::max()};
@@ -174,7 +176,7 @@ DrawViewSection::DrawViewSection()
// TODO: SectionDirection is a legacy from when SectionViews were only
// available along cardinal directions. It should be made obsolete and
// replaced with Aligned sections and local unit vectors.
SectionDirection.setEnums(SectionDirEnums);
SectionDirection.setEnums(SectionDirEnums); //NOLINT
ADD_PROPERTY_TYPE(SectionDirection,
((long)0),
sgroup,
@@ -199,7 +201,7 @@ DrawViewSection::DrawViewSection()
"Use the cut shape from the base view instead of the original object");
// properties related to the display of the cut surface
CutSurfaceDisplay.setEnums(CutSurfaceEnums);
CutSurfaceDisplay.setEnums(CutSurfaceEnums); //NOLINT
ADD_PROPERTY_TYPE(CutSurfaceDisplay,
(prefCutSurface()),
fgroup,
@@ -362,7 +364,7 @@ TopoDS_Shape DrawViewSection::getShapeToCut()
TechDraw::DrawViewSection* dvs = nullptr;
TechDraw::DrawViewDetail* dvd = nullptr;
if (!base) {
return TopoDS_Shape();
return {};
}
TopoDS_Shape shapeToCut;
@@ -388,7 +390,7 @@ TopoDS_Shape DrawViewSection::getShapeToCut()
}
else {
Base::Console().Message("DVS::getShapeToCut - base is weird\n");
return TopoDS_Shape();
return {};
}
return shapeToCut;
}
@@ -409,13 +411,13 @@ App::DocumentObjectExecReturn* DrawViewSection::execute()
}
if (waitingForCut() || waitingForHlr()) {
return DrawView::execute();
return DrawView::execute(); //NOLINT
}
TopoDS_Shape baseShape = getShapeToCut();
if (baseShape.IsNull()) {
return DrawView::execute();
return DrawView::execute(); //NOLINT
}
// is SectionOrigin valid?
@@ -445,16 +447,13 @@ App::DocumentObjectExecReturn* DrawViewSection::execute()
sectionExec(baseShape);
addPoints();
return DrawView::execute();
return DrawView::execute(); //NOLINT
}
bool DrawViewSection::isBaseValid() const
{
App::DocumentObject* base = BaseView.getValue();
if (base && base->isDerivedFrom<TechDraw::DrawViewPart>()) {
return true;
}
return false;
return base && base->isDerivedFrom<TechDraw::DrawViewPart>();
}
void DrawViewSection::sectionExec(TopoDS_Shape& baseShape)
@@ -613,15 +612,14 @@ TopoDS_Shape DrawViewSection::makeCuttingTool(double shapeSize)
gp_Pln pln = getSectionPlane();
gp_Dir gpNormal = pln.Axis().Direction();
BRepBuilderAPI_MakeFace mkFace(pln, -shapeSize, shapeSize, -shapeSize, shapeSize);
TopoDS_Face aProjFace = mkFace.Face();
if (aProjFace.IsNull()) {
return TopoDS_Shape();
if (mkFace.Face().IsNull()) {
return {};
}
if (debugSection()) {
BRepTools::Write(aProjFace, "DVSSectionFace.brep");// debug
BRepTools::Write(mkFace.Face(), "DVSSectionFace.brep");// debug
}
gp_Vec extrudeDir = shapeSize * gp_Vec(gpNormal);
return BRepPrimAPI_MakePrism(aProjFace, extrudeDir, false, true).Shape();
return BRepPrimAPI_MakePrism(mkFace.Face(), extrudeDir, false, true).Shape();
}
void DrawViewSection::onSectionCutFinished()
@@ -646,7 +644,7 @@ void DrawViewSection::onSectionCutFinished()
}
// activities that depend on updated geometry object
void DrawViewSection::postHlrTasks(void)
void DrawViewSection::postHlrTasks()
{
DrawViewPart::postHlrTasks();
@@ -683,7 +681,7 @@ void DrawViewSection::postHlrTasks(void)
}
m_tdSectionFaces = makeTDSectionFaces(m_sectionTopoDSFaces);
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(BaseView.getValue());
auto* dvp = dynamic_cast<TechDraw::DrawViewPart*>(BaseView.getValue());
if (dvp) {
dvp->requestPaint();// to refresh section line
}
@@ -705,10 +703,7 @@ void DrawViewSection::postSectionCutTasks()
bool DrawViewSection::waitingForResult() const
{
if (DrawViewPart::waitingForResult() || waitingForCut()) {
return true;
}
return false;
return DrawViewPart::waitingForResult() || waitingForCut();
}
gp_Pln DrawViewSection::getSectionPlane() const
@@ -716,7 +711,7 @@ gp_Pln DrawViewSection::getSectionPlane() const
gp_Ax2 viewAxis = getSectionCS();
gp_Ax3 viewAxis3(viewAxis);
return gp_Pln(viewAxis3);
return {viewAxis3};
}
//! tries to find the intersection of the section plane with the shape giving a
@@ -732,7 +727,7 @@ TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shap
Base::Console().Warning(
"DrawViewSection::findSectionPlaneInter - %s - input shape is Null\n",
getNameInDocument());
return TopoDS_Compound();
return {};
}
gp_Pln plnSection = getSectionPlane();
@@ -765,7 +760,7 @@ TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shap
}
// move section faces to line up with cut shape
TopoDS_Compound DrawViewSection::alignSectionFaces(TopoDS_Shape faceIntersections)
TopoDS_Compound DrawViewSection::alignSectionFaces(const TopoDS_Shape& faceIntersections)
{
TopoDS_Compound sectionFaces;
TopoDS_Shape centeredShape =
@@ -784,7 +779,7 @@ TopoDS_Compound DrawViewSection::alignSectionFaces(TopoDS_Shape faceIntersection
return mapToPage(scaledSection);
}
TopoDS_Compound DrawViewSection::mapToPage(TopoDS_Shape& shapeToAlign)
TopoDS_Compound DrawViewSection::mapToPage(const TopoDS_Shape& shapeToAlign)
{
// shapeToAlign is compound of TopoDS_Face intersections, but aligned to
// pln(origin, sectionNormal) needs to be aligned to paper plane (origin,
@@ -829,7 +824,7 @@ TopoDS_Compound DrawViewSection::mapToPage(TopoDS_Shape& shapeToAlign)
wireEdges.push_back(edge);
}
TopoDS_Wire cleanWire = EdgeWalker::makeCleanWire(wireEdges, 2.0 * EWTOLERANCE);
TopoDS_Wire cleanWire = EdgeWalker::makeCleanWire(wireEdges, 2 * EWTOLERANCE);
faceWires.push_back(cleanWire);
}
@@ -890,14 +885,14 @@ TopoDS_Shape DrawViewSection::makeFaceFromWires(std::vector<TopoDS_Wire>& inWire
TopoDS_Wire orientedWire = TopoDS::Wire(orientedShape);
orientedWire.Orientation(TopAbs_FORWARD);
TopoDS_Face blankFace = BRepBuilderAPI_MakeFace(orientedWire);
int wireCount = goodWires.size();
size_t wireCount = goodWires.size();
if (wireCount < 2) {
faceToFix = blankFace;
}
else {
// add the holes
BRepBuilderAPI_MakeFace mkFace(blankFace);
for (int iWire = 1; iWire < wireCount; iWire++) {
for (size_t iWire = 1; iWire < wireCount; iWire++) {
// make holes in the face with the rest of the wires
orientedShape = goodWires.at(iWire).Oriented(TopAbs_REVERSED);
orientedWire = TopoDS::Wire(orientedShape);
@@ -907,7 +902,7 @@ TopoDS_Shape DrawViewSection::makeFaceFromWires(std::vector<TopoDS_Wire>& inWire
if (!mkFace.IsDone()) {
Base::Console().Warning("DVS::makeFaceFromWires - %s - failed to make section face.\n",
getNameInDocument());
return TopoDS_Shape();
return {};
}
faceToFix = mkFace.Face();
}
@@ -921,7 +916,7 @@ TopoDS_Shape DrawViewSection::makeFaceFromWires(std::vector<TopoDS_Wire>& inWire
}
// turn OCC section faces into TD geometry
std::vector<TechDraw::FacePtr> DrawViewSection::makeTDSectionFaces(TopoDS_Compound topoDSFaces)
std::vector<TechDraw::FacePtr> DrawViewSection::makeTDSectionFaces(const TopoDS_Compound& topoDSFaces)
{
// Base::Console().Message("DVS::makeTDSectionFaces()\n");
std::vector<TechDraw::FacePtr> tdSectionFaces;
@@ -931,7 +926,7 @@ std::vector<TechDraw::FacePtr> DrawViewSection::makeTDSectionFaces(TopoDS_Compou
TechDraw::FacePtr sectionFace(std::make_shared<TechDraw::Face>());
TopExp_Explorer expFace(face, TopAbs_WIRE);
for (; expFace.More(); expFace.Next()) {
TechDraw::Wire* w = new TechDraw::Wire();
auto* w = new TechDraw::Wire();
const TopoDS_Wire& wire = TopoDS::Wire(expFace.Current());
TopExp_Explorer expWire(wire, TopAbs_EDGE);
for (; expWire.More(); expWire.Next()) {
@@ -958,7 +953,7 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawViewSection::sectionLineEnds()
Base::Vector3d sectionOrg = SectionOrigin.getValue() - getBaseDVP()->getOriginalCentroid();
sectionOrg = getBaseDVP()->projectPoint(sectionOrg);// convert to base view CS
double halfSize = (getBaseDVP()->getSizeAlongVector(dir) / 2.0) * SectionLineStretch.getValue();
double halfSize = (getBaseDVP()->getSizeAlongVector(dir) / 2) * SectionLineStretch.getValue();
result.first = sectionOrg + dir * halfSize;
result.second = sectionOrg - dir * halfSize;
@@ -984,14 +979,14 @@ ChangePointVector DrawViewSection::getChangePointsFromSectionLine()
// Base::Console().Message("Dvs::getChangePointsFromSectionLine()\n");
ChangePointVector result;
std::vector<gp_Pnt> allPoints;
DrawViewPart* baseDvp = freecad_cast<DrawViewPart*>(BaseView.getValue());
auto* baseDvp = freecad_cast<DrawViewPart*>(BaseView.getValue());
if (baseDvp) {
std::pair<Base::Vector3d, Base::Vector3d> lineEnds = sectionLineEnds();
// make start and end marks
gp_Pnt location0 = Base::convertTo<gp_Pnt>(lineEnds.first);
gp_Pnt location1 = Base::convertTo<gp_Pnt>(lineEnds.second);
gp_Dir postDir = gp_Dir(location1.XYZ() - location0.XYZ());
gp_Dir preDir = postDir.Reversed();
auto location0 = Base::convertTo<gp_Pnt>(lineEnds.first);
auto location1 = Base::convertTo<gp_Pnt>(lineEnds.second);
auto postDir = gp_Dir(location1.XYZ() - location0.XYZ());
auto preDir = postDir.Reversed();
ChangePoint startPoint(location0, preDir, postDir);
result.push_back(startPoint);
preDir = gp_Dir(location0.XYZ() - location1.XYZ());
@@ -1005,7 +1000,7 @@ ChangePointVector DrawViewSection::getChangePointsFromSectionLine()
// this should really be in BoundBox.h
//! check if point is in box or on boundary of box
//! compare to isInBox which doesn't allow on boundary
bool DrawViewSection::isReallyInBox(const Base::Vector3d vec, const Base::BoundBox3d bb) const
bool DrawViewSection::isReallyInBox(const Base::Vector3d& vec, const Base::BoundBox3d& bb) const
{
if (vec.x <= bb.MinX || vec.x >= bb.MaxX) {
return false;
@@ -1050,8 +1045,6 @@ Base::Vector3d DrawViewSection::getXDirection() const
void DrawViewSection::setCSFromBase(const std::string& sectionName)
{
// Base::Console().Message("DVS::setCSFromBase(%s)\n",
// sectionName.c_str());
gp_Dir gDir = getCSFromBase(sectionName).Direction();
Base::Vector3d vDir(gDir.X(), gDir.Y(), gDir.Z());
Direction.setValue(vDir);
@@ -1080,12 +1073,12 @@ void DrawViewSection::setCSFromBase(const Base::Vector3d& localUnit)
// reset the section CS based on an XY vector in current section CS
void DrawViewSection::setCSFromLocalUnit(const Base::Vector3d& localUnit)
{
gp_Dir verticalDir = getSectionCS().YDirection();
auto verticalDir = getSectionCS().YDirection();
gp_Ax1 verticalAxis(Base::convertTo<gp_Pnt>(SectionOrigin.getValue()), verticalDir);
gp_Dir oldNormal = getSectionCS().Direction();
gp_Dir newNormal = Base::convertTo<gp_Dir>(projectPoint(localUnit));
double angle = oldNormal.AngleWithRef(newNormal, verticalDir);
gp_Ax2 newCS = getSectionCS().Rotated(verticalAxis, angle);
auto oldNormal = getSectionCS().Direction();
auto newNormal = Base::convertTo<gp_Dir>(projectPoint(localUnit));
auto angle = oldNormal.AngleWithRef(newNormal, verticalDir);
auto newCS = getSectionCS().Rotated(verticalAxis, angle);
SectionNormal.setValue(Base::convertTo<Base::Vector3d>(newCS.Direction()));
XDirection.setValue(Base::convertTo<Base::Vector3d>(newCS.XDirection()));
}
@@ -1196,14 +1189,14 @@ TopoDS_Face DrawViewSection::getSectionTopoDSFace(int i)
return TopoDS::Face(expl.Current());
}
}
return TopoDS_Face();
return {};
}
TechDraw::DrawViewPart* DrawViewSection::getBaseDVP() const
{
App::DocumentObject* base = BaseView.getValue();
if (base && base->isDerivedFrom<TechDraw::DrawViewPart>()) {
TechDraw::DrawViewPart* baseDVP = static_cast<TechDraw::DrawViewPart*>(base);
auto* baseDVP = static_cast<TechDraw::DrawViewPart*>(base);
return baseDVP;
}
return nullptr;
@@ -1283,16 +1276,13 @@ bool DrawViewSection::checkSectionCS() const
}
auto orthoDot = std::fabs(vNormal.Dot(vXDirection));
if (orthoDot > EWTOLERANCE) {
return false;
}
return true;
return orthoDot <= EWTOLERANCE;
}
// hatch file routines
// create geometric hatch lines
void DrawViewSection::makeLineSets(void)
void DrawViewSection::makeLineSets()
{
if (PatIncluded.isEmpty()) {
return;
@@ -1315,7 +1305,7 @@ void DrawViewSection::makeLineSets(void)
}
}
void DrawViewSection::replaceSvgIncluded(std::string newSvgFile)
void DrawViewSection::replaceSvgIncluded(const std::string& newSvgFile)
{
if (newSvgFile.empty()) {
return;
@@ -1330,7 +1320,7 @@ void DrawViewSection::replaceSvgIncluded(std::string newSvgFile)
}
}
void DrawViewSection::replacePatIncluded(std::string newPatFile)
void DrawViewSection::replacePatIncluded(const std::string& newPatFile)
{
if (newPatFile.empty()) {
return;
@@ -1353,18 +1343,19 @@ void DrawViewSection::getParameters()
FuseBeforeCut.setValue(fuseFirst);
}
bool DrawViewSection::debugSection(void) const
bool DrawViewSection::debugSection() const
{
return Preferences::getPreferenceGroup("debug")->GetBool("debugSection", false);
}
int DrawViewSection::prefCutSurface(void) const
int DrawViewSection::prefCutSurface() const
{
//NOLINTNEXTLINE
return Preferences::getPreferenceGroup("Decorations")
->GetInt("CutSurfaceDisplay", 2);// default to SvgHatch
}
bool DrawViewSection::showSectionEdges(void)
bool DrawViewSection::showSectionEdges()
{
return Preferences::getPreferenceGroup("General")->GetBool("ShowSectionEdges", true);
}