From acdfde774a7951180981958cb62081ddd9e03053 Mon Sep 17 00:00:00 2001 From: marioalexis Date: Fri, 17 Jun 2022 12:12:09 -0300 Subject: [PATCH] Part: Replace C cast --- src/Mod/Part/App/AppPartPy.cpp | 4 ++-- src/Mod/Part/App/AttachEnginePyImp.cpp | 2 +- src/Mod/Part/App/FT2FC.cpp | 8 ++++---- src/Mod/Part/App/Geometry.cpp | 2 +- src/Mod/Part/App/PropertyGeometryList.cpp | 2 +- src/Mod/Part/App/PropertyTopoShape.cpp | 4 ++-- src/Mod/Part/App/TopoShape.cpp | 6 +++--- src/Mod/Part/Gui/Command.cpp | 2 +- src/Mod/Part/Gui/SoBrepFaceSet.cpp | 24 +++++++++++------------ src/Mod/Part/Gui/ViewProviderCurveNet.cpp | 4 ++-- 10 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index db2e4dd024..de5b3a6a82 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -2278,7 +2278,7 @@ private: TopoDS_Shape* shape = new TopoDS_Shape(); (*shape) = static_cast(pcObj)->getTopoShapePtr()->getShape(); PyObject* proxy = nullptr; - proxy = Base::Interpreter().createSWIGPointerObj("OCC.TopoDS", "TopoDS_Shape *", (void*)shape, 1); + proxy = Base::Interpreter().createSWIGPointerObj("OCC.TopoDS", "TopoDS_Shape *", static_cast(shape), 1); return Py::asObject(proxy); } catch (const Base::Exception& e) { @@ -2295,7 +2295,7 @@ private: try { TopoShape* shape = new TopoShape(); Base::Interpreter().convertSWIGPointerObj("OCC.TopoDS","TopoDS_Shape *", proxy, &ptr, 0); - TopoDS_Shape* s = reinterpret_cast(ptr); + TopoDS_Shape* s = static_cast(ptr); shape->setShape(*s); return Py::asObject(new TopoShapePy(shape)); } diff --git a/src/Mod/Part/App/AttachEnginePyImp.cpp b/src/Mod/Part/App/AttachEnginePyImp.cpp index f160a0b8f5..7b7ab19ebb 100644 --- a/src/Mod/Part/App/AttachEnginePyImp.cpp +++ b/src/Mod/Part/App/AttachEnginePyImp.cpp @@ -122,7 +122,7 @@ void AttachEnginePy::setMode(Py::String arg) { try { AttachEngine &attacher = *(this->getAttachEnginePtr()); - std::string modeName = (std::string)arg; + std::string modeName = static_cast(arg); attacher.mapMode = attacher.getModeByName(modeName); } ATTACHERPY_STDCATCH_ATTR; } diff --git a/src/Mod/Part/App/FT2FC.cpp b/src/Mod/Part/App/FT2FC.cpp index 86e9998ac8..2eb86de428 100644 --- a/src/Mod/Part/App/FT2FC.cpp +++ b/src/Mod/Part/App/FT2FC.cpp @@ -214,7 +214,7 @@ struct FTDC_Ctx { // move_cb called for start of new contour. pt is xy of contour start. // p points to the context where we remember what happened previously (last point, etc) static int move_cb(const FT_Vector* pt, void* p) { - FTDC_Ctx* dc = (FTDC_Ctx*) p; + FTDC_Ctx* dc = static_cast(p); if (!dc->Edges.empty()){ TopoDS_Wire newwire = edgesToWire(dc->Edges); dc->Wires.push_back(newwire); @@ -232,7 +232,7 @@ static int move_cb(const FT_Vector* pt, void* p) { // line_cb called for line segment in the current contour: line(LastVert -- pt) static int line_cb(const FT_Vector* pt, void* p) { - FTDC_Ctx* dc = (FTDC_Ctx*) p; + FTDC_Ctx* dc = static_cast(p); gp_Pnt2d v1(dc->LastVert.x, dc->LastVert.y); gp_Pnt2d v2(pt->x, pt->y); if (!v1.IsEqual(v2, Precision::Confusion())) { @@ -248,7 +248,7 @@ static int line_cb(const FT_Vector* pt, void* p) { // quad_cb called for quadratic (conic) BCurve segment in the current contour // (ie V-C-V in TTF fonts). BCurve(LastVert -- pt0 -- pt1) static int quad_cb(const FT_Vector* pt0, const FT_Vector* pt1, void* p) { - FTDC_Ctx* dc = (FTDC_Ctx*) p; + FTDC_Ctx* dc = static_cast(p); TColgp_Array1OfPnt2d Poles(1,3); gp_Pnt2d v1(dc->LastVert.x, dc->LastVert.y); gp_Pnt2d c1(pt0->x, pt0->y); @@ -275,7 +275,7 @@ static int quad_cb(const FT_Vector* pt0, const FT_Vector* pt1, void* p) { // cubic_cb called for cubic BCurve segment in the current contour (ie V-C-C-V in // Type 1 fonts). BCurve(LastVert -- pt0 -- pt1 -- pt2) static int cubic_cb(const FT_Vector* pt0, const FT_Vector* pt1, const FT_Vector* pt2, void* p) { - FTDC_Ctx* dc = (FTDC_Ctx*) p; + FTDC_Ctx* dc = static_cast(p); TColgp_Array1OfPnt2d Poles(1,4); gp_Pnt2d v1(dc->LastVert.x, dc->LastVert.y); gp_Pnt2d c1(pt0->x, pt0->y); diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 118f0bb16b..f8d2584ff2 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -241,7 +241,7 @@ void Geometry::Restore(Base::XMLReader &reader) reader.readElement("GeoExtension"); const char* TypeName = reader.getAttribute("type"); Base::Type type = Base::Type::fromName(TypeName); - GeometryPersistenceExtension *newE = (GeometryPersistenceExtension *)type.createInstance(); + GeometryPersistenceExtension *newE = static_cast(type.createInstance()); newE->Restore(reader); extensions.push_back(std::shared_ptr(newE)); diff --git a/src/Mod/Part/App/PropertyGeometryList.cpp b/src/Mod/Part/App/PropertyGeometryList.cpp index 26ea2096be..995c2f7157 100644 --- a/src/Mod/Part/App/PropertyGeometryList.cpp +++ b/src/Mod/Part/App/PropertyGeometryList.cpp @@ -192,7 +192,7 @@ void PropertyGeometryList::Restore(Base::XMLReader &reader) for (int i = 0; i < count; i++) { reader.readElement("Geometry"); const char* TypeName = reader.getAttribute("type"); - Geometry *newG = (Geometry *)Base::Type::fromName(TypeName).createInstance(); + Geometry *newG = static_cast(Base::Type::fromName(TypeName).createInstance()); newG->Restore(reader); if(reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInObject)) { diff --git a/src/Mod/Part/App/PropertyTopoShape.cpp b/src/Mod/Part/App/PropertyTopoShape.cpp index 3ab84199bf..fc473a1b74 100644 --- a/src/Mod/Part/App/PropertyTopoShape.cpp +++ b/src/Mod/Part/App/PropertyTopoShape.cpp @@ -271,7 +271,7 @@ void PropertyPartShape::saveToFile(Base::Writer &writer) const static Base::FileInfo fi(App::Application::getTempFileName()); TopoDS_Shape myShape = _Shape.getShape(); - if (!BRepTools_Write(myShape,(Standard_CString)fi.filePath().c_str())) { + if (!BRepTools_Write(myShape,static_cast(fi.filePath().c_str()))) { // Note: Do NOT throw an exception here because if the tmp. file could // not be created we should not abort. // We only print an error message but continue writing the next files to the @@ -323,7 +323,7 @@ void PropertyPartShape::loadFromFile(Base::Reader &reader) // If it's still empty after reading the (non-empty) file there must occurred an error. TopoDS_Shape shape; if (ulSize > 0) { - if (!BRepTools::Read(shape, (Standard_CString)fi.filePath().c_str(), builder)) { + if (!BRepTools::Read(shape, static_cast(fi.filePath().c_str()), builder)) { // Note: Do NOT throw an exception here because if the tmp. created file could // not be read it's NOT an indication for an invalid input stream 'reader'. // We only print an error message but continue reading the next files from the diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index babf0d76dc..24096e8ab3 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -470,7 +470,7 @@ TopAbs_ShapeEnum TopoShape::shapeType(const char *type, bool silent) { initShapeNameMap(); for(size_t idx=0;idx<_ShapeNames.size();++idx) { if(!_ShapeNames[idx].empty() && boost::starts_with(type,_ShapeNames[idx])) - return (TopAbs_ShapeEnum)idx; + return static_cast(idx); } } if(!silent) { @@ -817,7 +817,7 @@ void TopoShape::importBrep(const char *FileName) BRepTools::Read(aShape,encodeFilename(FileName).c_str(),aBuilder,pi); pi->EndScope(); #else - BRepTools::Read(aShape,(Standard_CString)FileName,aBuilder); + BRepTools::Read(aShape,static_cast(FileName),aBuilder); #endif this->_Shape = aShape; } @@ -2184,7 +2184,7 @@ TopoDS_Shape TopoShape::makeSweep(const TopoDS_Shape& profile, double tol, int f if (hProfile.IsNull()) Standard_Failure::Raise("invalid curve in profile edge"); - GeomFill_Pipe mkSweep(hPath, hProfile, (GeomFill_Trihedron)fillMode); + GeomFill_Pipe mkSweep(hPath, hProfile, static_cast(fillMode)); mkSweep.GenerateParticularCase(Standard_True); mkSweep.Perform(tol, Standard_False, GeomAbs_C1, BSplCLib::MaxDegree(), 1000); diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index b8f61c3bc3..5a09d225c1 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -2542,7 +2542,7 @@ CmdPartSectionCut::CmdPartSectionCut() Gui::Action* CmdPartSectionCut::createAction() { - Gui::Action* pcAction = (Gui::Action*)Gui::Command::createAction(); + Gui::Action* pcAction = Gui::Command::createAction(); #if 0 pcAction->setCheckable(true); #endif diff --git a/src/Mod/Part/Gui/SoBrepFaceSet.cpp b/src/Mod/Part/Gui/SoBrepFaceSet.cpp index 5ebb702337..00c70dff8f 100644 --- a/src/Mod/Part/Gui/SoBrepFaceSet.cpp +++ b/src/Mod/Part/Gui/SoBrepFaceSet.cpp @@ -1417,10 +1417,8 @@ void SoBrepFaceSet::VBO::render(SoGLRenderAction * action, SbBool texture) { (void)texcoords; (void)texindices; (void)texture; - const SbVec3f * coords3d = nullptr; - SbVec3f * cur_coords3d = nullptr; - coords3d = vertexlist->getArrayPtr3(); - cur_coords3d = ( SbVec3f *)coords3d; + const SbVec3f * coords3d = vertexlist->getArrayPtr3(); + SbVec3f * cur_coords3d = const_cast(coords3d); const int32_t *viptr = vertexindices; const int32_t *viendptr = viptr + num_indices; @@ -1439,9 +1437,9 @@ void SoBrepFaceSet::VBO::render(SoGLRenderAction * action, float * vertex_array = nullptr; GLuint * index_array = nullptr; SbColor mycolor1,mycolor2,mycolor3; - SbVec3f *mynormal1 = (SbVec3f *)currnormal; - SbVec3f *mynormal2 = (SbVec3f *)currnormal; - SbVec3f *mynormal3 = (SbVec3f *)currnormal; + SbVec3f *mynormal1 = const_cast(currnormal); + SbVec3f *mynormal2 = const_cast(currnormal); + SbVec3f *mynormal3 = const_cast(currnormal); int indice=0; uint32_t RGBA,R,G,B,A; float Rf,Gf,Bf,Af; @@ -1543,11 +1541,11 @@ void SoBrepFaceSet::VBO::render(SoGLRenderAction * action, if (normals) { if (nbind == PER_VERTEX || nbind == PER_FACE) { currnormal = normals++; - mynormal1=(SbVec3f *)currnormal; + mynormal1 = const_cast(currnormal); } else if (nbind == PER_VERTEX_INDEXED || nbind == PER_FACE_INDEXED) { currnormal = &normals[*normalindices++]; - mynormal1 =(SbVec3f *) currnormal; + mynormal1 = const_cast(currnormal); } } if (mbind == PER_VERTEX) @@ -1558,11 +1556,11 @@ void SoBrepFaceSet::VBO::render(SoGLRenderAction * action, if (normals) { if (nbind == PER_VERTEX) { currnormal = normals++; - mynormal2 = (SbVec3f *)currnormal; + mynormal2 = const_cast(currnormal); } else if (nbind == PER_VERTEX_INDEXED) { currnormal = &normals[*normalindices++]; - mynormal2 = (SbVec3f *)currnormal; + mynormal2 = const_cast(currnormal); } } @@ -1573,11 +1571,11 @@ void SoBrepFaceSet::VBO::render(SoGLRenderAction * action, if (normals) { if (nbind == PER_VERTEX) { currnormal = normals++; - mynormal3 =(SbVec3f *)currnormal; + mynormal3 =const_cast(currnormal); } else if (nbind == PER_VERTEX_INDEXED) { currnormal = &normals[*normalindices++]; - mynormal3 = (SbVec3f *)currnormal; + mynormal3 = const_cast(currnormal); } } if (nbind == PER_VERTEX_INDEXED) diff --git a/src/Mod/Part/Gui/ViewProviderCurveNet.cpp b/src/Mod/Part/Gui/ViewProviderCurveNet.cpp index fb5dd51d85..37c4de96bd 100644 --- a/src/Mod/Part/Gui/ViewProviderCurveNet.cpp +++ b/src/Mod/Part/Gui/ViewProviderCurveNet.cpp @@ -163,7 +163,7 @@ bool ViewProviderCurveNet::handleEvent(const SoEvent * const ev, Gui::View3DInve // Keyboard events if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { - SoKeyboardEvent * ke = (SoKeyboardEvent *)ev; + const SoKeyboardEvent * ke = static_cast(ev); switch (ke->getKey()) { case SoKeyboardEvent::LEFT_ALT: case SoKeyboardEvent::RIGHT_ALT: @@ -179,7 +179,7 @@ bool ViewProviderCurveNet::handleEvent(const SoEvent * const ev, Gui::View3DInve // switching the mouse buttons if (ev->getTypeId().isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) { - const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev; + const SoMouseButtonEvent * const event = static_cast(ev); const int button = event->getButton(); const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;