From b4a9c2222c1336f8381724eecb6426ce78927242 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Tue, 29 Apr 2025 09:22:11 -0400 Subject: [PATCH] [TD]Lint brushing --- src/Mod/TechDraw/App/DrawComplexSection.cpp | 7 +- src/Mod/TechDraw/App/DrawComplexSection.h | 2 +- src/Mod/TechDraw/App/DrawViewSection.cpp | 115 +++++++++----------- src/Mod/TechDraw/App/DrawViewSection.h | 12 +- src/Mod/TechDraw/Gui/TaskComplexSection.cpp | 4 +- 5 files changed, 63 insertions(+), 77 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawComplexSection.cpp b/src/Mod/TechDraw/App/DrawComplexSection.cpp index de5fe95b09..76425f6a30 100644 --- a/src/Mod/TechDraw/App/DrawComplexSection.cpp +++ b/src/Mod/TechDraw/App/DrawComplexSection.cpp @@ -555,7 +555,7 @@ TopoDS_Compound DrawComplexSection::alignedToolIntersections(const TopoDS_Shape& return result; } -TopoDS_Compound DrawComplexSection::alignSectionFaces(TopoDS_Shape faceIntersections) +TopoDS_Compound DrawComplexSection::alignSectionFaces(const TopoDS_Shape& faceIntersections) { if (ProjectionStrategy.getValue() == 0) { //Offset. Use regular section behaviour @@ -624,7 +624,6 @@ gp_Vec DrawComplexSection::makeProfileVector(const TopoDS_Wire& profileWire) //make drawable td geometry for section line BaseGeomPtrVector DrawComplexSection::makeSectionLineGeometry() { - // Base::Console().Message("DCS::makeSectionLineGeometry()\n"); BaseGeomPtrVector result; auto* baseDvp = freecad_cast(BaseView.getValue()); if (baseDvp) { @@ -643,7 +642,6 @@ BaseGeomPtrVector DrawComplexSection::makeSectionLineGeometry() //get the end points of the section wire std::pair DrawComplexSection::sectionLineEnds() { - // Base::Console().Message("DCS::sectionLineEnds()\n"); std::pair result; TopoDS_Wire lineWire = makeSectionLineWire(); if (lineWire.IsNull()) { @@ -744,7 +742,6 @@ TopoDS_Wire DrawComplexSection::makeSectionLineWire() //of the profile before and after the point ChangePointVector DrawComplexSection::getChangePointsFromSectionLine() { - // Base::Console().Message("DCS::getChangePointsFromSectionLine()\n"); ChangePointVector result; std::vector allPoints; DrawViewPart* baseDvp = freecad_cast(BaseView.getValue()); @@ -796,7 +793,6 @@ ChangePointVector DrawComplexSection::getChangePointsFromSectionLine() gp_Ax2 DrawComplexSection::getCSFromBase(const std::string& sectionName) const { - // Base::Console().Message("DCS::getCSFromBase()\n"); App::DocumentObject* base = BaseView.getValue(); if (!base || !base->isDerivedFrom()) {//is second clause necessary? @@ -1052,7 +1048,6 @@ TopoDS_Shape DrawComplexSection::shapeShapeIntersect(const TopoDS_Shape& shape0, std::vector DrawComplexSection::faceShapeIntersect(const TopoDS_Face& face, const TopoDS_Shape& shape) { - // Base::Console().Message("DCS::faceShapeIntersect()\n"); TopoDS_Shape intersect = shapeShapeIntersect(face, shape); if (intersect.IsNull()) { return {}; diff --git a/src/Mod/TechDraw/App/DrawComplexSection.h b/src/Mod/TechDraw/App/DrawComplexSection.h index 7ec068e77e..83f3a9852d 100644 --- a/src/Mod/TechDraw/App/DrawComplexSection.h +++ b/src/Mod/TechDraw/App/DrawComplexSection.h @@ -71,7 +71,7 @@ public: TopoDS_Shape getShapeToPrepare() const override; TopoDS_Shape getShapeToIntersect() override; gp_Pln getSectionPlane() const override; - TopoDS_Compound alignSectionFaces(TopoDS_Shape faceIntersections) override; + TopoDS_Compound alignSectionFaces(const TopoDS_Shape& faceIntersections) override; std::pair sectionLineEnds() override; void makeSectionCut(const TopoDS_Shape& baseShape) override; diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 994e50ace8..8f6e5dd597 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -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::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()) { - return true; - } - return false; + return base && base->isDerivedFrom(); } 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(BaseView.getValue()); + auto* dvp = dynamic_cast(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& 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& 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& inWire } // turn OCC section faces into TD geometry -std::vector DrawViewSection::makeTDSectionFaces(TopoDS_Compound topoDSFaces) +std::vector DrawViewSection::makeTDSectionFaces(const TopoDS_Compound& topoDSFaces) { // Base::Console().Message("DVS::makeTDSectionFaces()\n"); std::vector tdSectionFaces; @@ -931,7 +926,7 @@ std::vector DrawViewSection::makeTDSectionFaces(TopoDS_Compou TechDraw::FacePtr sectionFace(std::make_shared()); 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 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 allPoints; - DrawViewPart* baseDvp = freecad_cast(BaseView.getValue()); + auto* baseDvp = freecad_cast(BaseView.getValue()); if (baseDvp) { std::pair lineEnds = sectionLineEnds(); // make start and end marks - gp_Pnt location0 = Base::convertTo(lineEnds.first); - gp_Pnt location1 = Base::convertTo(lineEnds.second); - gp_Dir postDir = gp_Dir(location1.XYZ() - location0.XYZ()); - gp_Dir preDir = postDir.Reversed(); + auto location0 = Base::convertTo(lineEnds.first); + auto location1 = Base::convertTo(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(SectionOrigin.getValue()), verticalDir); - gp_Dir oldNormal = getSectionCS().Direction(); - gp_Dir newNormal = Base::convertTo(projectPoint(localUnit)); - double angle = oldNormal.AngleWithRef(newNormal, verticalDir); - gp_Ax2 newCS = getSectionCS().Rotated(verticalAxis, angle); + auto oldNormal = getSectionCS().Direction(); + auto newNormal = Base::convertTo(projectPoint(localUnit)); + auto angle = oldNormal.AngleWithRef(newNormal, verticalDir); + auto newCS = getSectionCS().Rotated(verticalAxis, angle); SectionNormal.setValue(Base::convertTo(newCS.Direction())); XDirection.setValue(Base::convertTo(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* baseDVP = static_cast(base); + auto* baseDVP = static_cast(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); } diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index b38e6b8329..5d85978511 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -110,7 +110,7 @@ public: App::PropertyFloatConstraint SectionLineStretch; // new v022 //NOLINTEND - bool isReallyInBox(const Base::Vector3d vec, const Base::BoundBox3d bb) const; + bool isReallyInBox(const Base::Vector3d& vec, const Base::BoundBox3d& bb) const; bool isReallyInBox(const gp_Pnt& point, const Bnd_Box& bb) const; App::DocumentObjectExecReturn* execute() override; @@ -151,9 +151,9 @@ public: //section face related methods std::vector getTDFaceGeometry() { return m_tdSectionFaces; } TopoDS_Face getSectionTopoDSFace(int i); - virtual TopoDS_Compound alignSectionFaces(TopoDS_Shape faceIntersections); - TopoDS_Compound mapToPage(TopoDS_Shape& shapeToAlign); - virtual std::vector makeTDSectionFaces(TopoDS_Compound topoDSFaces); + virtual TopoDS_Compound alignSectionFaces(const TopoDS_Shape& faceIntersections); + TopoDS_Compound mapToPage(const TopoDS_Shape& shapeToAlign); + virtual std::vector makeTDSectionFaces(const TopoDS_Compound& topoDSFaces); virtual TopoDS_Shape getShapeToIntersect() { return m_cutPieces; } void makeLineSets(); @@ -200,8 +200,8 @@ protected: void onDocumentRestored() override; void setupObject() override; - void replaceSvgIncluded(std::string newSvgFile); - void replacePatIncluded(std::string newPatFile); + void replaceSvgIncluded(const std::string& newSvgFile); + void replacePatIncluded(const std::string& newPatFile); TopoDS_Shape m_cutPieces;//the shape after cutting, but before centering & scaling gp_Ax2 m_projectionCS; diff --git a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp index 4fb7846c7e..a62a1fa41c 100644 --- a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp +++ b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp @@ -166,7 +166,7 @@ void TaskComplexSection::setUiPrimary() std::pair dirs = DrawGuiUtil::get3DDirAndRot(); m_saveNormal = dirs.first; m_saveXDir = dirs.second; - m_viewDirectionWidget->setValue(m_saveNormal * -1.0);//this will propagate to m_compass + m_viewDirectionWidget->setValue(m_saveNormal * -1);//this will propagate to m_compass } //don't allow updates until a direction is picked @@ -195,7 +195,7 @@ void TaskComplexSection::setUiEdit() Base::Vector3d projectedViewDirection = m_baseView->projectPoint(sectionNormalVec, false); double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x); m_compass->setDialAngle(Base::toDegrees(viewAngle)); - m_viewDirectionWidget->setValueNoNotify(projectedViewDirection * -1.0); + m_viewDirectionWidget->setValueNoNotify(projectedViewDirection * -1); } else { //no local angle makes sense if there is no baseView?