[TechDraw] Improve CosmeticExtension.cpp typing

Make type safe by using const keywords when appropriate and improve memory handling by using references when appropriate.
This commit is contained in:
Benjamin Bræstrup Sayoc
2023-07-17 14:19:05 +02:00
committed by WandererFan
parent 5cb05ce3c1
commit 4051e29188
2 changed files with 18 additions and 21 deletions

View File

@@ -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<TechDraw::CosmeticVertex*> 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<App::DocumentObject*> (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<CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
@@ -223,7 +223,7 @@ void CosmeticExtension::removeCosmeticVertex(std::string delTag)
CosmeticVertexes.setValues(newVerts);
}
void CosmeticExtension::removeCosmeticVertex(std::vector<std::string> delTags)
void CosmeticExtension::removeCosmeticVertex(const std::vector<std::string>& delTags)
{
for (auto& t: delTags) {
removeCosmeticVertex(t);

View File

@@ -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<std::string> 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<std::string>& 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<std::string> 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);