Skip to content

Commit

Permalink
FEM: Fix several issues
Browse files Browse the repository at this point in the history
* Move global (non-static) variables into anonymous namespace to avoid possible linking issues that may cause UB
* Fix compiler warnings
* Do not reinvent the wheel and use boost::to_upper_copy instead of own implementation
  • Loading branch information
wwmayer committed Jun 17, 2024
1 parent 4a11652 commit 3fd2a8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/Mod/Fem/Gui/PreCompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <vector>

// boost
#include <boost/algorithm/string.hpp>
#include <boost/bind/bind.hpp>
#include <boost/lexical_cast.hpp>

Expand Down
22 changes: 8 additions & 14 deletions src/Mod/Fem/Gui/TaskCreateElementSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@

#include "PreCompiled.h"
#ifndef _PreComp_
#include <boost/algorithm/string.hpp>

#include <Inventor/events/SoMouseButtonEvent.h>
#include <Inventor/nodes/SoCamera.h>
#include <Inventor/nodes/SoEventCallback.h>


#include <QAction>
#include <QApplication>
#include <QMessageBox>
Expand Down Expand Up @@ -68,15 +69,17 @@ using namespace Gui;
using namespace FemGui;
using namespace std;

std::string TaskCreateElementSet::currentProject = "";

Check warning on line 72 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 72 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'currentProject' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

namespace
{
std::string inp_file = "abaqusOutputFileEraseElements.inp";

Check warning on line 76 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 76 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'inp_file' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

std::string createdMesh = "cDUMMY";

Check warning on line 78 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 78 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'createdMesh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
std::string startResultMesh = "StartResultMesh"; // StartResultMesh";

Check warning on line 79 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 79 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'startResultMesh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
std::string newResultMesh = "NewResultMesh";

Check warning on line 80 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 80 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'newResultMesh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
std::string newFemMesh = "NewFemMesh";

Check warning on line 81 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 81 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'newFemMesh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

std::string TaskCreateElementSet::currentProject = "";

std::string uniqueMesh = "";

Check warning on line 83 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 83 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'uniqueMesh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
std::string newProject = "";

Check warning on line 84 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 84 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'newProject' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
std::string resultMesh = "Result";

Check warning on line 85 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Static/global string variables are not permitted. [runtime/string] [4]

Check warning on line 85 in src/Mod/Fem/Gui/TaskCreateElementSet.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'resultMesh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
Expand All @@ -86,19 +89,9 @@ std::string highLightMesh; // name of highlighted mesh
std::string meshType; // type of - either 'result' or 'femmesh'
int passResult = 0;
int passFemMesh = 0;
int maxProject = 10;
double** nodeCoords; // these are node coords
int* nodeNumbers; // these are node numbers - probably not required[100];


string myToUpper(std::string str)
{
for (int i = 0; i < str.length(); i++) {
str[i] = toupper(str[i]);
}
return str;
}

void addFaceToMesh(const std::vector<const SMDS_MeshNode*> nodes, SMESHDS_Mesh* MeshDS, int EID)
{
int nbNodes = nodes.size();
Expand Down Expand Up @@ -446,6 +439,7 @@ void writeToFile(std::string fileName,
fclose(fptr);
return;
}
} // namespace

TaskCreateElementSet::TaskCreateElementSet(Fem::FemSetElementNodesObject* pcObject, QWidget* parent)
: TaskBox(Gui::BitmapFactory().pixmap("FEM_CreateElementsSet"),
Expand Down Expand Up @@ -626,7 +620,7 @@ void TaskCreateElementSet::DefineNodes(const Base::Polygon2d& polygon,
highLightMesh = selection[0].FeatName;

meshType = "NULL";
std::size_t found = myToUpper(highLightMesh).find(myToUpper(resultMesh));
std::size_t found = boost::to_upper_copy(highLightMesh).find(boost::to_upper_copy(resultMesh));
actualResultMesh = highLightMesh;
// highLightMesh.find(myToUpper(resultMesh));

Expand Down

0 comments on commit 3fd2a8e

Please sign in to comment.