From 4051e291886ef60df291c5689909bca109c68616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Br=C3=A6strup=20Sayoc?= Date: Mon, 17 Jul 2023 14:19:05 +0200 Subject: [PATCH] [TechDraw] Improve CosmeticExtension.cpp typing Make type safe by using const keywords when appropriate and improve memory handling by using references when appropriate. --- src/Mod/TechDraw/App/CosmeticExtension.cpp | 14 ++++++------ src/Mod/TechDraw/App/CosmeticExtension.h | 25 ++++++++++------------ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/Mod/TechDraw/App/CosmeticExtension.cpp b/src/Mod/TechDraw/App/CosmeticExtension.cpp index 183d5761d4..fe3a41dc92 100644 --- a/src/Mod/TechDraw/App/CosmeticExtension.cpp +++ b/src/Mod/TechDraw/App/CosmeticExtension.cpp @@ -153,7 +153,7 @@ int CosmeticExtension::getCVIndex(std::string tag) //returns unique CV id //only adds cv to cvlist property. does not add to display geometry until dvp executes. -std::string CosmeticExtension::addCosmeticVertex(Base::Vector3d pos) +std::string CosmeticExtension::addCosmeticVertex(const Base::Vector3d& pos) { // Base::Console().Message("CEx::addCosmeticVertex(%s)\n", // DrawUtil::formatVector(pos).c_str()); @@ -167,13 +167,13 @@ std::string CosmeticExtension::addCosmeticVertex(Base::Vector3d pos) } //get CV by unique id -TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertex(std::string tagString) const +TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertex(const std::string& tag) const { // Base::Console().Message("CEx::getCosmeticVertex(%s)\n", tagString.c_str()); const std::vector verts = CosmeticVertexes.getValues(); for (auto& cv: verts) { std::string cvTag = cv->getTagAsString(); - if (cvTag == tagString) { + if (cvTag == tag) { return cv; } } @@ -182,7 +182,7 @@ TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertex(std::string tagSt // find the cosmetic vertex corresponding to selection name (Vertex5) // used when selecting -TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(std::string name) const +TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(const std::string& name) const { // Base::Console().Message("CEx::getCVBySelection(%s)\n", name.c_str()); App::DocumentObject* extObj = const_cast (getExtendedObject()); @@ -199,7 +199,7 @@ TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(std::s } //overload for index only -TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(int i) const +TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(const int i) const { // Base::Console().Message("CEx::getCVBySelection(%d)\n", i); std::stringstream ss; @@ -208,7 +208,7 @@ TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(int i) return getCosmeticVertexBySelection(vName); } -void CosmeticExtension::removeCosmeticVertex(std::string delTag) +void CosmeticExtension::removeCosmeticVertex(const std::string& delTag) { // Base::Console().Message("DVP::removeCV(%s)\n", delTag.c_str()); std::vector cVerts = CosmeticVertexes.getValues(); @@ -223,7 +223,7 @@ void CosmeticExtension::removeCosmeticVertex(std::string delTag) CosmeticVertexes.setValues(newVerts); } -void CosmeticExtension::removeCosmeticVertex(std::vector delTags) +void CosmeticExtension::removeCosmeticVertex(const std::vector& delTags) { for (auto& t: delTags) { removeCosmeticVertex(t); diff --git a/src/Mod/TechDraw/App/CosmeticExtension.h b/src/Mod/TechDraw/App/CosmeticExtension.h index d80df8e3b3..dff4428e36 100644 --- a/src/Mod/TechDraw/App/CosmeticExtension.h +++ b/src/Mod/TechDraw/App/CosmeticExtension.h @@ -51,22 +51,17 @@ public: TechDraw::PropertyCenterLineList CenterLines; TechDraw::PropertyGeomFormatList GeomFormats; //formats for geometric edges - virtual void addCosmeticVertexesToGeom(); - virtual void refreshCVGeoms(); + virtual CosmeticVertex* getCosmeticVertexBySelection(const int i) const; + virtual CosmeticVertex* getCosmeticVertexBySelection(const std::string& name) const; + virtual CosmeticVertex* getCosmeticVertex(const std::string& tag) const; virtual int add1CVToGV(std::string tag); virtual int getCVIndex(std::string tag); - - virtual std::string addCosmeticVertex(Base::Vector3d pos); - virtual CosmeticVertex* getCosmeticVertexBySelection(std::string name) const; - virtual CosmeticVertex* getCosmeticVertexBySelection(int i) const; - virtual CosmeticVertex* getCosmeticVertex(std::string id) const; - virtual void removeCosmeticVertex(std::string tag); - virtual void removeCosmeticVertex(std::vector delTags); + virtual std::string addCosmeticVertex(const Base::Vector3d& pos); + virtual void addCosmeticVertexesToGeom(); virtual void clearCosmeticVertexes(); - - virtual void refreshCEGeoms(); - virtual void addCosmeticEdgesToGeom(); - virtual int add1CEToGE(std::string tag); + virtual void refreshCVGeoms(); + virtual void removeCosmeticVertex(const std::string& tag); + virtual void removeCosmeticVertex(const std::vector& tags); virtual std::string addCosmeticEdge(Base::Vector3d start, Base::Vector3d end); virtual std::string addCosmeticEdge(TechDraw::BaseGeomPtr bg); @@ -76,11 +71,13 @@ public: virtual void removeCosmeticEdge(std::string tag); virtual void removeCosmeticEdge(std::vector delTags); virtual void clearCosmeticEdges(); + virtual int add1CEToGE(std::string tag); + virtual void addCosmeticEdgesToGeom(); + virtual void refreshCEGeoms(); virtual void refreshCLGeoms(); virtual void addCenterLinesToGeom(); virtual int add1CLToGE(std::string tag); - virtual std::string addCenterLine(Base::Vector3d start, Base::Vector3d end); virtual std::string addCenterLine(TechDraw::CenterLine* cl); virtual std::string addCenterLine(TechDraw::BaseGeomPtr bg);