From 5da15d23cff219de06071fc5f4fc4e5d99095aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Br=C3=A6strup=20Sayoc?= Date: Wed, 5 Apr 2023 13:53:27 +0200 Subject: [PATCH] [TechDraw] Improve readability of DrawGeomHatch.cpp --- src/Mod/TechDraw/App/DrawGeomHatch.cpp | 90 ++++++++++++-------------- 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.cpp b/src/Mod/TechDraw/App/DrawGeomHatch.cpp index 10ac1bf3c9..66a8bf3d3a 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.cpp +++ b/src/Mod/TechDraw/App/DrawGeomHatch.cpp @@ -176,8 +176,8 @@ void DrawGeomHatch::unsetupObject() void DrawGeomHatch::makeLineSets() { // Base::Console().Message("DGH::makeLineSets()\n"); - if ((!PatIncluded.isEmpty()) && - (!NamePattern.isEmpty())) { + if (!PatIncluded.isEmpty() && + !NamePattern.isEmpty()) { m_lineSets.clear(); m_lineSets = makeLineSets(PatIncluded.getValue(), NamePattern.getValue()); @@ -188,17 +188,18 @@ void DrawGeomHatch::makeLineSets() std::vector DrawGeomHatch::makeLineSets(std::string fileSpec, std::string myPattern) { std::vector lineSets; - if (!fileSpec.empty() && - !myPattern.empty()) { - std::vector specs = - DrawGeomHatch::getDecodedSpecsFromFile(fileSpec, - myPattern); - for (auto& hl: specs) { - //hl.dump("hl from section"); - LineSet ls; - ls.setPATLineSpec(hl); - lineSets.push_back(ls); - } + if (fileSpec.empty() && myPattern.empty()) { + return lineSets; + } + + std::vector specs = + DrawGeomHatch::getDecodedSpecsFromFile(fileSpec, + myPattern); + for (auto& hl: specs) { + //hl.dump("hl from section"); + LineSet ls; + ls.setPATLineSpec(hl); + lineSets.push_back(ls); } return lineSets; } @@ -222,15 +223,12 @@ std::vector DrawGeomHatch::getDecodedSpecsFromFile() /*static*/ std::vector DrawGeomHatch::getDecodedSpecsFromFile(std::string fileSpec, std::string myPattern) { - std::vector result; Base::FileInfo fi(fileSpec); if (!fi.isReadable()) { Base::Console().Error("DrawGeomHatch::getDecodedSpecsFromFile not able to open %s!\n", fileSpec.c_str()); - return result; + return std::vector(); } - result = PATLineSpec::getSpecsForPattern(fileSpec, myPattern); - - return result; + return PATLineSpec::getSpecsForPattern(fileSpec, myPattern); } std::vector DrawGeomHatch::getTrimmedLines(int i) //get the trimmed hatch lines for face i @@ -239,11 +237,10 @@ std::vector DrawGeomHatch::getTrimmedLines(int i) //get the trimmed makeLineSets(); } - std::vector result; DrawViewPart* source = getSourceView(); if (!source || !source->hasGeometry()) { - return result; + return std::vector(); } return getTrimmedLines(source, m_lineSets, i, ScalePattern.getValue(), PatternRotation.getValue(), PatternOffset.getValue()); @@ -273,13 +270,14 @@ std::vector DrawGeomHatch::getTrimmedLinesSection(DrawViewSection* sou TopoDS_Shape moved = TechDraw::moveShape(f, offset); TopoDS_Face fMoved = TopoDS::Face(GeometryObject::invertGeometry(moved)); - result = getTrimmedLines(source, - lineSets, - fMoved, - scale, - hatchRotation, - hatchOffset ); - return result; + return getTrimmedLines( + source, + lineSets, + fMoved, + scale, + hatchRotation, + hatchOffset + ); } //! get hatch lines trimmed to face outline @@ -288,13 +286,14 @@ std::vector DrawGeomHatch::getTrimmedLines(DrawViewPart* source, std::v Base::Vector3d hatchOffset) { TopoDS_Face face = extractFace(source, iface); - std::vector result = getTrimmedLines(source, - lineSets, - face, - scale, - hatchRotation, - hatchOffset ); - return result; + return getTrimmedLines( + source, + lineSets, + face, + scale, + hatchRotation, + hatchOffset + ); } std::vector DrawGeomHatch::getTrimmedLines(DrawViewPart* source, @@ -346,8 +345,8 @@ std::vector DrawGeomHatch::getTrimmedLines(DrawViewPart* source, //Common(Compound, Face) BRepAlgoAPI_Common mkCommon(face, grid); - if ((!mkCommon.IsDone()) || - (mkCommon.Shape().IsNull()) ) { + if (!mkCommon.IsDone() || + mkCommon.Shape().IsNull()) { return result; } TopoDS_Shape common = mkCommon.Shape(); @@ -431,8 +430,8 @@ std::vector DrawGeomHatch::makeEdgeOverlay(PATLineSpec hl, Bnd_Box TopoDS_Edge newLine = makeLine(newStart, newEnd); result.push_back(newLine); } - } else if ((angle == 90.0) || - (angle == -90.0)) { //odd case 2: vertical lines + } else if (angle == 90.0 || + angle == -90.0) { //odd case 2: vertical lines interval = hl.getInterval() * scale; double atomX = origin.x; int repeatRight = (int) fabs((maxX - atomX)/interval); @@ -493,14 +492,12 @@ std::vector DrawGeomHatch::makeEdgeOverlay(PATLineSpec hl, Bnd_Box TopoDS_Edge DrawGeomHatch::makeLine(Base::Vector3d s, Base::Vector3d e) { - TopoDS_Edge result; gp_Pnt start(s.x, s.y, 0.0); gp_Pnt end(e.x, e.y, 0.0); TopoDS_Vertex v1 = BRepBuilderAPI_MakeVertex(start); TopoDS_Vertex v2 = BRepBuilderAPI_MakeVertex(end); BRepBuilderAPI_MakeEdge makeEdge1(v1, v2); - result = makeEdge1.Edge(); - return result; + return makeEdge1.Edge(); } //! get all the untrimmed hatchlines for a face @@ -549,8 +546,6 @@ std::vector DrawGeomHatch::getFaceOverlay(int fdx) //! TODO: DVP can serve these up ready to use TopoDS_Face DrawGeomHatch::extractFace(DrawViewPart* source, int iface ) { - TopoDS_Face result; - std::vector faceWires = source->getWireForFace(iface); //build face(s) from geometry @@ -564,7 +559,7 @@ TopoDS_Face DrawGeomHatch::extractFace(DrawViewPart* source, int iface ) mkFace.Add(*itWire); } if (!mkFace.IsDone()) { - return result; + return TopoDS_Face(); } TopoDS_Face face = mkFace.Face(); @@ -577,10 +572,9 @@ TopoDS_Face DrawGeomHatch::extractFace(DrawViewPart* source, int iface ) temp = mkTrf.Shape(); } catch (...) { - return result; + return TopoDS_Face(); } - result = TopoDS::Face(temp); - return result; + return TopoDS::Face(temp); } //-------------------------------------------------------------------------------------------------- @@ -605,7 +599,7 @@ std::string DrawGeomHatch::prefGeomHatchName() std::string defaultNamePattern = "Diamond"; std::string result = hGrp->GetASCII("NamePattern", defaultNamePattern.c_str()); if (result.empty()) { - result = defaultNamePattern; + return defaultNamePattern; } return result; }