From aa00364da7f3f2c7d01a6c086dfd3dee4cd60182 Mon Sep 17 00:00:00 2001 From: abv Date: Wed, 17 Feb 2016 17:33:18 +0300 Subject: [PATCH] 0026377: Passing Handle objects as arguments to functions as non-const reference to base type is dangerous Operator of cast to non-const reference is declared deprecated to produce compiler warning if used (usually implicitly). OCCT code is updated to avoid that cast, occurring when function accepting non-const reference to handle is called with handle to derived type. For that, local variable of argument type is passed instead, and down-cast is used to get it to desired type after the call. A few occurrences of use of uninitialized variable are corrected. --- src/AIS/AIS_AngleDimension.cxx | 4 +-- src/AIS/AIS_Chamf2dDimension.cxx | 6 ++-- src/AIS/AIS_SymmetricRelation.cxx | 16 +++++---- .../BinDrivers_DocumentRetrievalDriver.cxx | 30 +++++++++-------- .../BinDrivers_DocumentStorageDriver.cxx | 10 ++++-- src/BinMXCAFDoc/BinMXCAFDoc.cxx | 6 ++-- src/DDF/DDF.hxx | 8 +++++ src/DDocStd/DDocStd.hxx | 8 +++++ src/Dico/Dico_DictionaryOfTransient.hxx | 16 +++++++++ src/DrawTrSurf/DrawTrSurf.cxx | 33 +++++++++---------- src/GeomTools/GeomTools.cxx | 6 ++-- src/GeomTools/GeomTools_Curve2dSet.cxx | 16 ++++----- src/GeomTools/GeomTools_Curve2dSet.hxx | 4 +-- src/GeomTools/GeomTools_CurveSet.cxx | 16 ++++----- src/GeomTools/GeomTools_CurveSet.hxx | 4 +-- src/GeomTools/GeomTools_SurfaceSet.cxx | 22 +++++-------- src/GeomTools/GeomTools_SurfaceSet.hxx | 4 +-- src/IFSelect/IFSelect_Activator.cxx | 11 ++++--- src/IGESData/IGESData_BasicEditor.cxx | 16 +++++---- src/IGESData/IGESData_FreeFormatEntity.cxx | 6 +++- src/IGESData/IGESData_IGESReaderTool.cxx | 9 +++-- src/IGESData/IGESData_ParamReader.cxx | 6 ++++ src/IGESData/IGESData_ParamReader.hxx | 20 +++++++++++ src/IGESData/IGESData_ToolLocation.cxx | 6 ++-- src/IGESDraw/IGESDraw_ToolViewsVisible.cxx | 2 +- .../IGESDraw_ToolViewsVisibleWithAttr.cxx | 2 +- src/IGESGeom/IGESGeom_ToolBoundedSurface.cxx | 4 +-- src/IGESSelect/IGESSelect_RebuildDrawings.cxx | 11 ++++--- src/IGESSolid/IGESSolid_ToolManifoldSolid.cxx | 4 +-- .../IGESSolid_ToolToroidalSurface.cxx | 4 +-- src/IntTools/IntTools_FaceFace.cxx | 4 +-- src/Interface/Interface_CopyTool.cxx | 18 +++++++--- src/MoniTool/MoniTool_Profile.cxx | 8 +++-- src/OpenGl/OpenGl_Context.cxx | 10 ------ src/OpenGl/OpenGl_Context.hxx | 7 +++- src/OpenGl/OpenGl_View_Raytrace.cxx | 3 +- src/PrsMgr/PrsMgr_PresentationManager.cxx | 5 +-- src/QANCollection/QANCollection_Handle.cxx | 8 ++--- src/STEPCAFControl/STEPCAFControl_Writer.cxx | 13 +++++--- src/Select3D/Select3D_SensitiveGroup.cxx | 2 +- src/Standard/Standard_Handle.hxx | 1 + src/StdObjMgt/StdObjMgt_ReadData.hxx | 4 ++- src/StepData/StepData_StepReaderData.cxx | 17 +++++++--- src/StepData/StepData_StepReaderData.hxx | 16 +++++++++ src/StepData/StepData_StepReaderTool.cxx | 9 +++-- src/TDF/TDF_Attribute.hxx | 8 +++++ src/TDF/TDF_Label.hxx | 8 +++++ src/TDF/TDF_RelocationTable.hxx | 8 +++++ src/TNaming/TNaming_NamedShape.cxx | 4 +-- src/TPrsStd/TPrsStd_ConstraintTools.cxx | 9 +++-- src/Transfer/Transfer_ProcessForFinder.hxx | 16 +++++++++ src/VrmlData/VrmlData_IndexedFaceSet.cxx | 24 +++++++++++--- src/VrmlData/VrmlData_IndexedLineSet.cxx | 12 +++++-- src/VrmlData/VrmlData_Node.cxx | 30 ++++++++++++++--- .../XmlDrivers_DocumentRetrievalDriver.cxx | 11 ++++--- .../XmlDrivers_DocumentStorageDriver.cxx | 8 +++-- src/XmlMXCAFDoc/XmlMXCAFDoc.cxx | 6 ++-- tests/de/iges_2/F9 | 2 +- tests/perf/fclasses/handle | 25 -------------- 59 files changed, 395 insertions(+), 211 deletions(-) diff --git a/src/AIS/AIS_AngleDimension.cxx b/src/AIS/AIS_AngleDimension.cxx index a9596edc39..d2d30fa324 100644 --- a/src/AIS/AIS_AngleDimension.cxx +++ b/src/AIS/AIS_AngleDimension.cxx @@ -860,9 +860,9 @@ Standard_Boolean AIS_AngleDimension::InitTwoEdgesAngle (gp_Pln& theComputedPlane // Compute geometry for this plane and edges Standard_Boolean isInfinite1,isInfinite2; gp_Pnt aFirstPoint1, aLastPoint1, aFirstPoint2, aLastPoint2; - + Handle(Geom_Curve) aFirstCurve = aFirstLine, aSecondCurve = aSecondLine; if (!AIS::ComputeGeometry (aFirstEdge, aSecondEdge, - aFirstLine, aSecondLine, + aFirstCurve, aSecondCurve, aFirstPoint1, aLastPoint1, aFirstPoint2, aLastPoint2, isInfinite1, isInfinite2)) diff --git a/src/AIS/AIS_Chamf2dDimension.cxx b/src/AIS/AIS_Chamf2dDimension.cxx index 3b87603070..1be69f41bd 100644 --- a/src/AIS/AIS_Chamf2dDimension.cxx +++ b/src/AIS/AIS_Chamf2dDimension.cxx @@ -106,13 +106,13 @@ void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& , { aPresentation->Clear(); - Handle(Geom_Line) glin; + Handle(Geom_Curve) gcurv; gp_Pnt pfirst,plast; const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape); - if (!AIS::ComputeGeometry(thechamfedge, glin,pfirst,plast) ) + if (!AIS::ComputeGeometry (thechamfedge, gcurv, pfirst, plast)) return; - + Handle(Geom_Line) glin = Handle(Geom_Line)::DownCast (gcurv); gp_Dir dir1 (glin->Position().Direction()); gp_Dir norm1 = myPlane->Pln().Axis().Direction(); myDir = norm1.Crossed(dir1); diff --git a/src/AIS/AIS_SymmetricRelation.cxx b/src/AIS/AIS_SymmetricRelation.cxx index 633c9f9d64..8865a9dac7 100644 --- a/src/AIS/AIS_SymmetricRelation.cxx +++ b/src/AIS/AIS_SymmetricRelation.cxx @@ -154,7 +154,7 @@ void AIS_SymmetricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7); Standard_Real F,L; - Handle(Geom_Line) geom_axis,extcurve; + Handle(Geom_Curve) geom_axis, extcurve; gp_Pnt p1,p2; Standard_Boolean isinfinite,isonplane; if (!AIS::ComputeGeometry(TopoDS::Edge(myTool), @@ -164,7 +164,8 @@ void AIS_SymmetricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& isonplane, myPlane)) return; - gp_Lin laxis (geom_axis->Lin()); + Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis); + gp_Lin laxis (geom_line->Lin()); if(myFShape.ShapeType() != TopAbs_VERTEX){ BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape)); @@ -402,7 +403,7 @@ void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presenta return; } aprs->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape !=0)); - Handle(Geom_Line) geom_axis,extcurve; + Handle(Geom_Curve) geom_axis,extcurve; gp_Pnt p1,p2; Standard_Boolean isinfinite,isonplane; if (!AIS::ComputeGeometry(TopoDS::Edge(myTool), @@ -412,7 +413,8 @@ void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presenta isonplane, myPlane)) return; - gp_Lin laxis (geom_axis->Lin()); + Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis); + gp_Lin laxis (geom_line->Lin()); myAxisDirAttach = laxis.Direction(); if(cu1.GetType() == GeomAbs_Line){ @@ -578,7 +580,7 @@ void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presenta void AIS_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Presentation)& aprs) { if(myFShape.ShapeType() != TopAbs_VERTEX || mySShape.ShapeType() != TopAbs_VERTEX) return; - Handle(Geom_Line) geom_axis,extcurve; + Handle(Geom_Curve) geom_axis,extcurve; gp_Pnt p1,p2; Standard_Boolean isinfinite,isonplane; if (!AIS::ComputeGeometry(TopoDS::Edge(myTool), @@ -604,7 +606,9 @@ void AIS_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Prese myExtShape = 1; else return ; - gp_Lin laxis (geom_axis->Lin()); + + Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis); + gp_Lin laxis (geom_line->Lin()); myAxisDirAttach = laxis.Direction(); // recherche points attache diff --git a/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx b/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx index 0a823a6cd2..f953dbc89c 100644 --- a/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx @@ -62,21 +62,23 @@ void BinDrivers_DocumentRetrievalDriver::ReadShapeSection { // Read Shapes - Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver; - if (myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape),aNamedShapeDriver)) - { - try { - OCC_CATCH_SIGNALS - aNamedShapeDriver->ReadShapeSection (theIS); - } - catch(Standard_Failure) { - Handle(Standard_Failure) aFailure = Standard_Failure::Caught(); - const TCollection_ExtendedString aMethStr - ("BinDrivers_DocumentRetrievalDriver: "); - WriteMessage (aMethStr + "error of Shape Section " + - aFailure->GetMessageString()); - } + Handle(BinMDF_ADriver) aDriver; + if (myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape),aDriver)) + { + try { + OCC_CATCH_SIGNALS + Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver = + Handle(BinMNaming_NamedShapeDriver)::DownCast (aDriver); + aNamedShapeDriver->ReadShapeSection (theIS); } + catch(Standard_Failure) { + Handle(Standard_Failure) aFailure = Standard_Failure::Caught(); + const TCollection_ExtendedString aMethStr + ("BinDrivers_DocumentRetrievalDriver: "); + WriteMessage (aMethStr + "error of Shape Section " + + aFailure->GetMessageString()); + } + } } //======================================================================= diff --git a/src/BinDrivers/BinDrivers_DocumentStorageDriver.cxx b/src/BinDrivers/BinDrivers_DocumentStorageDriver.cxx index a6db4870bd..730f7f15f2 100644 --- a/src/BinDrivers/BinDrivers_DocumentStorageDriver.cxx +++ b/src/BinDrivers/BinDrivers_DocumentStorageDriver.cxx @@ -57,10 +57,14 @@ void BinDrivers_DocumentStorageDriver::WriteShapeSection { const Standard_Size aShapesSectionOffset = (Standard_Size) theOS.tellp(); - Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver; - if (myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aNamedShapeDriver)) { + Handle(BinMDF_ADriver) aDriver; + if (myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aDriver)) + { try { - OCC_CATCH_SIGNALS aNamedShapeDriver->WriteShapeSection (theOS); + OCC_CATCH_SIGNALS + Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver = + Handle(BinMNaming_NamedShapeDriver)::DownCast (aDriver); + aNamedShapeDriver->WriteShapeSection (theOS); } catch(Standard_Failure) { TCollection_ExtendedString anErrorStr ("Error: "); diff --git a/src/BinMXCAFDoc/BinMXCAFDoc.cxx b/src/BinMXCAFDoc/BinMXCAFDoc.cxx index 6e11985667..de00b93f79 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc.cxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc.cxx @@ -47,8 +47,10 @@ void BinMXCAFDoc::AddDrivers(const Handle(BinMDF_ADriverTable)& theDriverTable, theDriverTable->AddDriver( new BinMXCAFDoc_GraphNodeDriver(theMsgDrv)); //oan: changes for sharing locations map - Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver; - theDriverTable->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aNamedShapeDriver); + Handle(BinMDF_ADriver) aNSDriver; + theDriverTable->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aNSDriver); + Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver = + Handle(BinMNaming_NamedShapeDriver)::DownCast (aNSDriver); Handle(BinMXCAFDoc_LocationDriver) aLocationDriver = new BinMXCAFDoc_LocationDriver (theMsgDrv); if( !aNamedShapeDriver.IsNull() ) diff --git a/src/DDF/DDF.hxx b/src/DDF/DDF.hxx index b0b3d4a859..6b3db337b0 100644 --- a/src/DDF/DDF.hxx +++ b/src/DDF/DDF.hxx @@ -61,6 +61,14 @@ public: //! that case A is setted. Standard_EXPORT static Standard_Boolean Find (const Handle(TDF_Data)& DF, const Standard_CString Entry, const Standard_GUID& ID, Handle(TDF_Attribute)& A, const Standard_Boolean Complain = Standard_True); + //! Safe variant for arbitrary type of argument + template + static Standard_Boolean Find (const Handle(TDF_Data)& DF, const Standard_CString Entry, const Standard_GUID& ID, Handle(T)& A, const Standard_Boolean Complain = Standard_True) + { + Handle(TDF_Attribute) anAttr = A; + return Find (DF, Entry, ID, anAttr, Complain) && ! (A = Handle(T)::DownCast(anAttr)).IsNull(); + } + Standard_EXPORT static Draw_Interpretor& ReturnLabel (Draw_Interpretor& theCommands, const TDF_Label& L); Standard_EXPORT static void AllCommands (Draw_Interpretor& theCommands); diff --git a/src/DDocStd/DDocStd.hxx b/src/DDocStd/DDocStd.hxx index 52bbd19f2c..cbca7da93d 100644 --- a/src/DDocStd/DDocStd.hxx +++ b/src/DDocStd/DDocStd.hxx @@ -60,6 +60,14 @@ public: Standard_EXPORT static Standard_Boolean Find (const Handle(TDocStd_Document)& Document, const Standard_CString Entry, const Standard_GUID& ID, Handle(TDF_Attribute)& A, const Standard_Boolean Complain = Standard_True); + //! Safe variant for arbitrary type of argument + template + static Standard_Boolean Find (const Handle(TDocStd_Document)& Document, const Standard_CString Entry, const Standard_GUID& ID, Handle(T)& A, const Standard_Boolean Complain = Standard_True) + { + Handle(TDF_Attribute) anAttr = A; + return Find (Document, Entry, ID, anAttr, Complain) && ! (A = Handle(T)::DownCast(anAttr)).IsNull(); + } + Standard_EXPORT static Draw_Interpretor& ReturnLabel (Draw_Interpretor& theCommands, const TDF_Label& L); Standard_EXPORT static void AllCommands (Draw_Interpretor& theCommands); diff --git a/src/Dico/Dico_DictionaryOfTransient.hxx b/src/Dico/Dico_DictionaryOfTransient.hxx index 5e04c94a00..b5cf0dd1c4 100644 --- a/src/Dico/Dico_DictionaryOfTransient.hxx +++ b/src/Dico/Dico_DictionaryOfTransient.hxx @@ -72,9 +72,25 @@ public: //! : same as for HasItem Standard_EXPORT Standard_Boolean GetItem (const Standard_CString name, Handle(Standard_Transient)& anitem, const Standard_Boolean exact = Standard_True) const; + //! Safe variant of GetItem() for arbitrary type of argument + template + Standard_Boolean GetItem (const Standard_CString theName, Handle(T)& theItem, const Standard_Boolean theExact = Standard_True) const + { + Handle(Standard_Transient) anItem = theItem; + return GetItem (theName, anItem, theExact) && ! (theItem = Handle(T)::DownCast(anItem)).IsNull(); + } + //! Works as above method but accepts a String from TCollection Standard_EXPORT Standard_Boolean GetItem (const TCollection_AsciiString& name, Handle(Standard_Transient)& anitem, const Standard_Boolean exact = Standard_True) const; + //! Safe variant of GetItem() for arbitrary type of argument + template + Standard_Boolean GetItem (const TCollection_AsciiString& theName, Handle(T)& theItem, const Standard_Boolean theExact = Standard_True) const + { + Handle(Standard_Transient) anItem = theItem; + return GetItem (theName, anItem, theExact) && ! (theItem = Handle(T)::DownCast(anItem)).IsNull(); + } + //! Binds an item to a dictionnary entry //! If is already known in the dictionary, its value //! is changed. Else, the dictionary entry is created. diff --git a/src/DrawTrSurf/DrawTrSurf.cxx b/src/DrawTrSurf/DrawTrSurf.cxx index 39250cea50..57cdc5ef17 100644 --- a/src/DrawTrSurf/DrawTrSurf.cxx +++ b/src/DrawTrSurf/DrawTrSurf.cxx @@ -1438,8 +1438,7 @@ static void csave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) crestore (istream& is) { - Handle(Geom_Curve) G; - GeomTools_CurveSet::ReadCurve(is,G); + Handle(Geom_Curve) G = GeomTools_CurveSet::ReadCurve(is); Handle(DrawTrSurf_Curve) N = new DrawTrSurf_Curve(G,CurvColor,Discret,Deflection,DrawMode); return N; @@ -1470,8 +1469,8 @@ static void bzcsave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) bzcrestore (istream& is) { - Handle(Geom_BezierCurve) G; - GeomTools_CurveSet::ReadCurve(is,G); + Handle(Geom_BezierCurve) G = + Handle(Geom_BezierCurve)::DownCast (GeomTools_CurveSet::ReadCurve(is)); Handle(DrawTrSurf_BezierCurve) N = new DrawTrSurf_BezierCurve(G,CurvColor,PolesColor,ShowPoles, Discret,Deflection,DrawMode); @@ -1503,8 +1502,8 @@ static void bscsave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) bscrestore (istream& is) { - Handle(Geom_BSplineCurve) G; - GeomTools_CurveSet::ReadCurve(is,G); + Handle(Geom_BSplineCurve) G = + Handle(Geom_BSplineCurve)::DownCast (GeomTools_CurveSet::ReadCurve(is)); Handle(DrawTrSurf_BSplineCurve) N = new DrawTrSurf_BSplineCurve(G, CurvColor,PolesColor, KnotsColor, @@ -1536,8 +1535,7 @@ static void c2dsave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) c2drestore (istream& is) { - Handle(Geom2d_Curve) G; - GeomTools_Curve2dSet::ReadCurve2d(is,G); + Handle(Geom2d_Curve) G = GeomTools_Curve2dSet::ReadCurve2d(is); Handle(DrawTrSurf_Curve2d) N = new DrawTrSurf_Curve2d(G,CurvColor,Discret); return N; @@ -1568,8 +1566,8 @@ static void bzc2dsave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) bzc2drestore (istream& is) { - Handle(Geom2d_BezierCurve) G; - GeomTools_Curve2dSet::ReadCurve2d(is,G); + Handle(Geom2d_BezierCurve) G = + Handle(Geom2d_BezierCurve)::DownCast (GeomTools_Curve2dSet::ReadCurve2d(is)); Handle(DrawTrSurf_BezierCurve2d) N = new DrawTrSurf_BezierCurve2d(G,CurvColor,PolesColor,ShowPoles, Discret); @@ -1601,8 +1599,8 @@ static void bsc2dsave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) bsc2drestore (istream& is) { - Handle(Geom2d_BSplineCurve) G; - GeomTools_Curve2dSet::ReadCurve2d(is,G); + Handle(Geom2d_BSplineCurve) G = + Handle(Geom2d_BSplineCurve)::DownCast (GeomTools_Curve2dSet::ReadCurve2d(is)); Handle(DrawTrSurf_BSplineCurve2d) N = new DrawTrSurf_BSplineCurve2d(G, CurvColor,PolesColor, KnotsColor, @@ -1634,8 +1632,7 @@ static void ssave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) srestore (istream& is) { - Handle(Geom_Surface) G; - GeomTools_SurfaceSet::ReadSurface(is,G); + Handle(Geom_Surface) G = GeomTools_SurfaceSet::ReadSurface(is); Handle(DrawTrSurf_Surface) N = new DrawTrSurf_Surface(G, NbUIsos,NbVIsos, @@ -1669,8 +1666,8 @@ static void bzssave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) bzsrestore (istream& is) { - Handle(Geom_BezierSurface) G; - GeomTools_SurfaceSet::ReadSurface(is,G); + Handle(Geom_BezierSurface) G = + Handle(Geom_BezierSurface)::DownCast (GeomTools_SurfaceSet::ReadSurface(is)); Handle(DrawTrSurf_BezierSurface) N = new DrawTrSurf_BezierSurface(G,NbUIsos,NbVIsos, BoundsColor,IsosColor,PolesColor, @@ -1704,8 +1701,8 @@ static void bsssave(const Handle(Draw_Drawable3D)&d, ostream& OS) static Handle(Draw_Drawable3D) bssrestore (istream& is) { - Handle(Geom_BSplineSurface) G; - GeomTools_SurfaceSet::ReadSurface(is,G); + Handle(Geom_BSplineSurface) G = + Handle(Geom_BSplineSurface)::DownCast (GeomTools_SurfaceSet::ReadSurface(is)); Handle(DrawTrSurf_BSplineSurface) N; if (!knotsIsos) N = new DrawTrSurf_BSplineSurface(G, diff --git a/src/GeomTools/GeomTools.cxx b/src/GeomTools/GeomTools.cxx index 78f8813283..a488cd7500 100644 --- a/src/GeomTools/GeomTools.cxx +++ b/src/GeomTools/GeomTools.cxx @@ -38,7 +38,7 @@ void GeomTools::Write(const Handle(Geom_Surface)& S, Standard_OStream& OS) void GeomTools::Read(Handle(Geom_Surface)& S, Standard_IStream& IS) { - GeomTools_SurfaceSet::ReadSurface(IS,S); + S = GeomTools_SurfaceSet::ReadSurface(IS); } void GeomTools::Dump(const Handle(Geom_Curve)& C, Standard_OStream& OS) @@ -53,7 +53,7 @@ void GeomTools::Write(const Handle(Geom_Curve)& C, Standard_OStream& OS) void GeomTools::Read(Handle(Geom_Curve)& C, Standard_IStream& IS) { - GeomTools_CurveSet::ReadCurve(IS,C); + C = GeomTools_CurveSet::ReadCurve(IS); } void GeomTools::Dump(const Handle(Geom2d_Curve)& C, Standard_OStream& OS) @@ -68,7 +68,7 @@ void GeomTools::Write(const Handle(Geom2d_Curve)& C, Standard_OStream& OS) void GeomTools::Read(Handle(Geom2d_Curve)& C, Standard_IStream& IS) { - GeomTools_Curve2dSet::ReadCurve2d(IS,C); + C = GeomTools_Curve2dSet::ReadCurve2d(IS); } //======================================================================= diff --git a/src/GeomTools/GeomTools_Curve2dSet.cxx b/src/GeomTools/GeomTools_Curve2dSet.cxx index d679f17f70..d3db350e77 100644 --- a/src/GeomTools/GeomTools_Curve2dSet.cxx +++ b/src/GeomTools/GeomTools_Curve2dSet.cxx @@ -709,8 +709,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Standard_Real p1=0.,p2=0.; GeomTools::GetReal(IS, p1); GeomTools::GetReal(IS, p2); - Handle(Geom2d_Curve) BC; - GeomTools_Curve2dSet::ReadCurve2d(IS,BC); + Handle(Geom2d_Curve) BC = GeomTools_Curve2dSet::ReadCurve2d(IS); C = new Geom2d_TrimmedCurve(BC,p1,p2); return IS; } @@ -725,8 +724,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, { Standard_Real p=0.; GeomTools::GetReal(IS, p); - Handle(Geom2d_Curve) BC; - GeomTools_Curve2dSet::ReadCurve2d(IS,BC); + Handle(Geom2d_Curve) BC = GeomTools_Curve2dSet::ReadCurve2d(IS); C = new Geom2d_OffsetCurve(BC,p); return IS; } @@ -736,11 +734,11 @@ static Standard_IStream& operator>>(Standard_IStream& IS, //purpose : //======================================================================= -Standard_IStream& GeomTools_Curve2dSet::ReadCurve2d(Standard_IStream& IS, - Handle(Geom2d_Curve)& C) +Handle(Geom2d_Curve) GeomTools_Curve2dSet::ReadCurve2d(Standard_IStream& IS) { Standard_Integer ctype; + Handle(Geom2d_Curve) C; try { OCC_CATCH_SIGNALS IS >> ctype; @@ -833,9 +831,8 @@ Standard_IStream& GeomTools_Curve2dSet::ReadCurve2d(Standard_IStream& IS, cout <<"EXCEPTION in GeomTools_Curve2dSet::ReadCurve2d(..)!!!" << endl; cout << anExc << endl; #endif - C = NULL; } - return IS; + return C; } //======================================================================= @@ -852,14 +849,13 @@ void GeomTools_Curve2dSet::Read(Standard_IStream& IS) return; } - Handle(Geom2d_Curve) C; Standard_Integer i, nbcurve; IS >> nbcurve; //OCC19559 Handle(Message_ProgressIndicator) progress = GetProgress(); Message_ProgressSentry PS(progress, "2D Curves", 0, nbcurve, 1); for (i = 1; i <= nbcurve && PS.More(); i++, PS.Next()) { - GeomTools_Curve2dSet::ReadCurve2d(IS,C); + Handle(Geom2d_Curve) C = GeomTools_Curve2dSet::ReadCurve2d (IS); myMap.Add(C); } } diff --git a/src/GeomTools/GeomTools_Curve2dSet.hxx b/src/GeomTools/GeomTools_Curve2dSet.hxx index 7bed4fc039..8111f6d29f 100644 --- a/src/GeomTools/GeomTools_Curve2dSet.hxx +++ b/src/GeomTools/GeomTools_Curve2dSet.hxx @@ -71,9 +71,9 @@ public: Standard_EXPORT static void PrintCurve2d (const Handle(Geom2d_Curve)& C, Standard_OStream& OS, const Standard_Boolean compact = Standard_False); //! Reads the curve from the stream. The curve is - //! assumed to have been writtent with the Print + //! assumed to have been written with the Print //! method (compact = True). - Standard_EXPORT static Standard_IStream& ReadCurve2d (Standard_IStream& IS, Handle(Geom2d_Curve)& C); + Standard_EXPORT static Handle(Geom2d_Curve) ReadCurve2d (Standard_IStream& IS); Standard_EXPORT void SetProgress (const Handle(Message_ProgressIndicator)& PR); diff --git a/src/GeomTools/GeomTools_CurveSet.cxx b/src/GeomTools/GeomTools_CurveSet.cxx index 4937925f84..0f20d6a087 100644 --- a/src/GeomTools/GeomTools_CurveSet.cxx +++ b/src/GeomTools/GeomTools_CurveSet.cxx @@ -729,8 +729,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Standard_Real p1=0.,p2=0.; GeomTools::GetReal(IS, p1); GeomTools::GetReal(IS, p2); - Handle(Geom_Curve) BC; - GeomTools_CurveSet::ReadCurve(IS,BC); + Handle(Geom_Curve) BC = GeomTools_CurveSet::ReadCurve(IS); C = new Geom_TrimmedCurve(BC,p1,p2); return IS; } @@ -747,8 +746,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, GeomTools::GetReal(IS, p); gp_Dir D(1.,0.,0.); IS >> D; - Handle(Geom_Curve) BC; - GeomTools_CurveSet::ReadCurve(IS,BC); + Handle(Geom_Curve) BC = GeomTools_CurveSet::ReadCurve(IS); C = new Geom_OffsetCurve(BC,p,D); return IS; } @@ -758,11 +756,11 @@ static Standard_IStream& operator>>(Standard_IStream& IS, //purpose : //======================================================================= -Standard_IStream& GeomTools_CurveSet::ReadCurve(Standard_IStream& IS, - Handle(Geom_Curve)& C) +Handle(Geom_Curve) GeomTools_CurveSet::ReadCurve (Standard_IStream& IS) { Standard_Integer ctype; + Handle(Geom_Curve) C; try { OCC_CATCH_SIGNALS IS >> ctype; @@ -854,9 +852,8 @@ Standard_IStream& GeomTools_CurveSet::ReadCurve(Standard_IStream& IS, cout <<"EXCEPTION in GeomTools_CurveSet::ReadCurve(..)!!!" << endl; cout << anExc << endl; #endif - C = NULL; } - return IS; + return C; } //======================================================================= @@ -873,14 +870,13 @@ void GeomTools_CurveSet::Read(Standard_IStream& IS) return; } - Handle(Geom_Curve) C; Standard_Integer i, nbcurve; IS >> nbcurve; //OCC19559 Handle(Message_ProgressIndicator) progress = GetProgress(); Message_ProgressSentry PS(progress, "3D Curves", 0, nbcurve, 1); for (i = 1; i <= nbcurve && PS.More(); i++, PS.Next()) { - GeomTools_CurveSet::ReadCurve(IS,C); + Handle(Geom_Curve) C = GeomTools_CurveSet::ReadCurve (IS); myMap.Add(C); } } diff --git a/src/GeomTools/GeomTools_CurveSet.hxx b/src/GeomTools/GeomTools_CurveSet.hxx index 7394c30cba..fbe59daf7b 100644 --- a/src/GeomTools/GeomTools_CurveSet.hxx +++ b/src/GeomTools/GeomTools_CurveSet.hxx @@ -71,9 +71,9 @@ public: Standard_EXPORT static void PrintCurve (const Handle(Geom_Curve)& C, Standard_OStream& OS, const Standard_Boolean compact = Standard_False); //! Reads the curve from the stream. The curve is - //! assumed to have been writtent with the Print + //! assumed to have been written with the Print //! method (compact = True). - Standard_EXPORT static Standard_IStream& ReadCurve (Standard_IStream& IS, Handle(Geom_Curve)& C); + Standard_EXPORT static Handle(Geom_Curve) ReadCurve (Standard_IStream& IS); Standard_EXPORT void SetProgress (const Handle(Message_ProgressIndicator)& PR); diff --git a/src/GeomTools/GeomTools_SurfaceSet.cxx b/src/GeomTools/GeomTools_SurfaceSet.cxx index 9f9b51f876..c09aafc03e 100644 --- a/src/GeomTools/GeomTools_SurfaceSet.cxx +++ b/src/GeomTools/GeomTools_SurfaceSet.cxx @@ -786,9 +786,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_SurfaceOfLinearExtrusion)& S) { gp_Dir D(1.,0.,0.); - Handle(Geom_Curve) C; IS >> D; - GeomTools_CurveSet::ReadCurve(IS,C); + Handle(Geom_Curve) C = GeomTools_CurveSet::ReadCurve(IS); S = new Geom_SurfaceOfLinearExtrusion(C,D); return IS; } @@ -803,9 +802,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, { gp_Pnt P(0.,0.,0.); gp_Dir D(1.,0.,0.); - Handle(Geom_Curve) C; IS >> P >> D; - GeomTools_CurveSet::ReadCurve(IS,C); + Handle(Geom_Curve) C = GeomTools_CurveSet::ReadCurve(IS); S = new Geom_SurfaceOfRevolution(C,gp_Ax1(P,D)); return IS; } @@ -906,8 +904,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, GeomTools::GetReal(IS, U2); GeomTools::GetReal(IS, V1); GeomTools::GetReal(IS, V2); - Handle(Geom_Surface) BS; - GeomTools_SurfaceSet::ReadSurface(IS,BS); + Handle(Geom_Surface) BS = GeomTools_SurfaceSet::ReadSurface(IS); S = new Geom_RectangularTrimmedSurface(BS,U1,U2,V1,V2); return IS; } @@ -922,8 +919,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, { Standard_Real O=0.; GeomTools::GetReal(IS, O); - Handle(Geom_Surface) BS; - GeomTools_SurfaceSet::ReadSurface(IS,BS); + Handle(Geom_Surface) BS = GeomTools_SurfaceSet::ReadSurface(IS); S = new Geom_OffsetSurface(BS,O,Standard_True); return IS; } @@ -934,11 +930,11 @@ static Standard_IStream& operator>>(Standard_IStream& IS, //purpose : //======================================================================= -Standard_IStream& GeomTools_SurfaceSet::ReadSurface(Standard_IStream& IS, - Handle(Geom_Surface)& S) +Handle(Geom_Surface) GeomTools_SurfaceSet::ReadSurface(Standard_IStream& IS) { Standard_Integer stype; + Handle(Geom_Surface) S; try { OCC_CATCH_SIGNALS IS >> stype; @@ -1047,9 +1043,8 @@ Standard_IStream& GeomTools_SurfaceSet::ReadSurface(Standard_IStream& IS, cout <<"EXCEPTION in GeomTools_SurfaceSet::ReadSurface(..)!!!" << endl; cout << anExc << endl; #endif - S = NULL; } - return IS; + return S; } //======================================================================= @@ -1066,14 +1061,13 @@ void GeomTools_SurfaceSet::Read(Standard_IStream& IS) return; } - Handle(Geom_Surface) S; Standard_Integer i, nbsurf; IS >> nbsurf; //OCC19559 Handle(Message_ProgressIndicator) progress = GetProgress(); Message_ProgressSentry PS(progress, "Surfaces", 0, nbsurf, 1); for (i = 1; i <= nbsurf && PS.More(); i++, PS.Next()) { - GeomTools_SurfaceSet::ReadSurface(IS,S); + Handle(Geom_Surface) S = GeomTools_SurfaceSet::ReadSurface (IS); myMap.Add(S); } } diff --git a/src/GeomTools/GeomTools_SurfaceSet.hxx b/src/GeomTools/GeomTools_SurfaceSet.hxx index a1ee7c71b1..83639fa5bc 100644 --- a/src/GeomTools/GeomTools_SurfaceSet.hxx +++ b/src/GeomTools/GeomTools_SurfaceSet.hxx @@ -71,9 +71,9 @@ public: Standard_EXPORT static void PrintSurface (const Handle(Geom_Surface)& S, Standard_OStream& OS, const Standard_Boolean compact = Standard_False); //! Reads the surface from the stream. The surface is - //! assumed to have been writtent with the Print + //! assumed to have been written with the Print //! method (compact = True). - Standard_EXPORT static Standard_IStream& ReadSurface (Standard_IStream& IS, Handle(Geom_Surface)& S); + Standard_EXPORT static Handle(Geom_Surface) ReadSurface (Standard_IStream& IS); Standard_EXPORT void SetProgress (const Handle(Message_ProgressIndicator)& PR); diff --git a/src/IFSelect/IFSelect_Activator.cxx b/src/IFSelect/IFSelect_Activator.cxx index f703792921..d25787cd8b 100644 --- a/src/IFSelect/IFSelect_Activator.cxx +++ b/src/IFSelect/IFSelect_Activator.cxx @@ -100,10 +100,13 @@ static Handle(MoniTool_Profile) thealiases; { TCollection_AsciiString str; if (thealiases.IsNull()) return str; - Handle(TCollection_HAsciiString) val; - if (!thealiases->Value(command,val)) return str; - str.AssignCat (val->ToCString()); - return str; + Handle(Standard_Transient) aVal; + if (!thealiases->Value(command,aVal)) return str; + Handle(TCollection_HAsciiString) val = + Handle(TCollection_HAsciiString)::DownCast (aVal); + if (!val.IsNull()) + str.AssignCat (val->ToCString()); + return str; } diff --git a/src/IGESData/IGESData_BasicEditor.cxx b/src/IGESData/IGESData_BasicEditor.cxx index ee415f5563..067c34a425 100644 --- a/src/IGESData/IGESData_BasicEditor.cxx +++ b/src/IGESData/IGESData_BasicEditor.cxx @@ -180,14 +180,16 @@ Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name) // Traites actuellement (necessaires) : // 1(Annotation), aussi 4(pour maillage). 5(ParamUV) traite par AutoCorrect - Handle(IGESData_GeneralModule) gmod; Standard_Integer CN; Standard_Integer i; // svv Jan11 2000 : porting on DEC for (i = 1; i <= nb; i ++) { // Subordinate (sur directs en propre seulement) Handle(IGESData_IGESEntity) ent = themodel->Entity(i); Standard_Integer igt = ent->TypeNumber(); - if (theglib.Select (ent,gmod,CN)) { + Handle(Interface_GeneralModule) gmodule; + if (theglib.Select (ent,gmodule,CN)) { + Handle(IGESData_GeneralModule) gmod = + Handle(IGESData_GeneralModule)::DownCast (gmodule); Interface_EntityIterator sh; gmod->OwnSharedCase (CN,ent,sh); for (sh.Start(); sh.More(); sh.Next()) { @@ -301,14 +303,16 @@ Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name) } // Corrections specifiques - Handle(IGESData_GeneralModule) gmod; - Handle(IGESData_SpecificModule) smod; Standard_Integer CN; - - if (theglib.Select (ent,gmod,CN)) { + Handle(Interface_GeneralModule) gmodule; + if (theglib.Select (ent,gmodule,CN)) { + Handle(IGESData_GeneralModule) gmod = + Handle(IGESData_GeneralModule)::DownCast (gmodule); IGESData_DirChecker DC = gmod->DirChecker(CN,ent); done |= DC.Correct(ent); } + + Handle(IGESData_SpecificModule) smod; if (theslib.Select (ent,smod,CN)) done |= smod->OwnCorrect (CN,ent); return done; diff --git a/src/IGESData/IGESData_FreeFormatEntity.cxx b/src/IGESData/IGESData_FreeFormatEntity.cxx index 0a27c4ce8f..f72bb423fa 100644 --- a/src/IGESData/IGESData_FreeFormatEntity.cxx +++ b/src/IGESData/IGESData_FreeFormatEntity.cxx @@ -43,7 +43,11 @@ IGESData_FreeFormatEntity::IGESData_FreeFormatEntity () { } Standard_Boolean IGESData_FreeFormatEntity::ParamData (const Standard_Integer num, Interface_ParamType& ptype, Handle(IGESData_IGESEntity)& ent, Handle(TCollection_HAsciiString)& val) const -{ return UndefinedContent()->ParamData (num,ptype,ent,val); } +{ + Handle(Standard_Transient) anEnt = ent; + return UndefinedContent()->ParamData (num, ptype, anEnt, val) && + ! (ent = Handle(IGESData_IGESEntity)::DownCast (anEnt)).IsNull(); +} Interface_ParamType IGESData_FreeFormatEntity::ParamType diff --git a/src/IGESData/IGESData_IGESReaderTool.cxx b/src/IGESData/IGESData_IGESReaderTool.cxx index 427ab677bf..1c67f28c76 100644 --- a/src/IGESData/IGESData_IGESReaderTool.cxx +++ b/src/IGESData/IGESData_IGESReaderTool.cxx @@ -334,11 +334,16 @@ IGESData_IGESReaderTool::IGESData_IGESReaderTool IGESData_ParamReader& PR) const { Handle(Interface_Check) ach = new Interface_Check;; - Handle(IGESData_ReadWriteModule) module; Standard_Integer CN; + Handle(Interface_ReaderModule) imodule; + Standard_Integer CN; // Les Modules font tout - if (therlib.Select(ent,module,CN)) + if (therlib.Select(ent,imodule,CN)) + { + Handle(IGESData_ReadWriteModule) module = + Handle(IGESData_ReadWriteModule)::DownCast (imodule); module->ReadOwnParams(CN,ent,IR,PR); + } else if (ent.IsNull()) { // Pas trouve dutout // Sending of message : Null Entity diff --git a/src/IGESData/IGESData_ParamReader.cxx b/src/IGESData/IGESData_ParamReader.cxx index 7958c56bec..66b63e4b19 100644 --- a/src/IGESData/IGESData_ParamReader.cxx +++ b/src/IGESData/IGESData_ParamReader.cxx @@ -716,6 +716,7 @@ Standard_Boolean IGESData_ParamReader::ReadEntity (const Handle(IGESData_IGESRea Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul) { + aStatus = IGESData_EntityError; if (!PrepareRead(PC,Standard_False)) return Standard_False; Standard_Integer nval; // if (!ReadingEntityNumber(theindex,amsg,nval)) return Standard_False; @@ -730,6 +731,8 @@ Standard_Boolean IGESData_ParamReader::ReadEntity (const Handle(IGESData_IGESRea thelast = Standard_True; } + else + aStatus = IGESData_EntityOK; return canbenul; } else val = GetCasted(IGESData_IGESEntity,IR->BoundEntity(nval)); @@ -745,6 +748,8 @@ Standard_Boolean IGESData_ParamReader::ReadEntity (const Handle(IGESData_IGESRea //SendFail (amsg); thelast = Standard_True; } + else + aStatus = IGESData_EntityOK; return canbenul; } } @@ -1344,6 +1349,7 @@ Standard_Boolean IGESData_ParamReader::ReadingReal } else if (FP.ParamType() == Interface_ParamVoid) { val = 0.0; // DEFAULT } else { + val = 0.0; // DEFAULT char ssem[100]; sprintf(ssem,": not given as Real, rank %d",num); AddFail (mess,ssem,": not given as Real, rank %d"); diff --git a/src/IGESData/IGESData_ParamReader.hxx b/src/IGESData/IGESData_ParamReader.hxx index 4a6a90b28b..fa708501ef 100644 --- a/src/IGESData/IGESData_ParamReader.hxx +++ b/src/IGESData/IGESData_ParamReader.hxx @@ -224,6 +224,16 @@ public: Standard_EXPORT Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, IGESData_Status& aStatus, const Handle(Standard_Type)& type, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul = Standard_False); + //! Safe variant for arbitrary type of argument + template + Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, IGESData_Status& aStatus, const Handle(Standard_Type)& type, Handle(T)& val, const Standard_Boolean canbenul = Standard_False) + { + Handle(IGESData_IGESEntity) aVal = val; + Standard_Boolean aRes = ReadEntity (IR, PC, aStatus, type, aVal, canbenul); + val = Handle(T)::DownCast(aVal); + return aRes && (canbenul || ! val.IsNull()); + } + //! Works as ReadEntity without Type, but in addition checks the //! Type of the Entity, which must be "kind of" a given //! Then, gives the same fail cases as ReadEntity without Type, @@ -231,6 +241,16 @@ public: //! (in such a case, returns False and givel = Null) Standard_EXPORT Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, const Handle(Standard_Type)& type, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul = Standard_False); + //! Safe variant for arbitrary type of argument + template + Standard_Boolean ReadEntity (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC, const Standard_CString mess, const Handle(Standard_Type)& type, Handle(T)& val, const Standard_Boolean canbenul = Standard_False) + { + Handle(IGESData_IGESEntity) aVal = val; + Standard_Boolean aRes = ReadEntity (IR, PC, mess, type, aVal, canbenul); + val = Handle(T)::DownCast(aVal); + return aRes && (canbenul || ! val.IsNull()); + } + Standard_EXPORT Standard_Boolean ReadInts (const IGESData_ParamCursor& PC, const Message_Msg& amsg, Handle(TColStd_HArray1OfInteger)& val, const Standard_Integer index = 1); //! Reads a list of Integer values, defined by PC (with a count of diff --git a/src/IGESData/IGESData_ToolLocation.cxx b/src/IGESData/IGESData_ToolLocation.cxx index 5438478a57..95ccc16b1b 100644 --- a/src/IGESData/IGESData_ToolLocation.cxx +++ b/src/IGESData/IGESData_ToolLocation.cxx @@ -104,9 +104,11 @@ void IGESData_ToolLocation::ResetDependences (const Handle(IGESData_IGESEntity) void IGESData_ToolLocation::SetOwnAsDependent (const Handle(IGESData_IGESEntity)& ent) { - Handle(IGESData_GeneralModule) module; Standard_Integer CN; - if (!thelib.Select(ent,module,CN)) return; + Handle(Interface_GeneralModule) gmodule; + if (!thelib.Select(ent,gmodule,CN)) return; + Handle(IGESData_GeneralModule) module = + Handle(IGESData_GeneralModule)::DownCast (gmodule); Interface_EntityIterator list; module->OwnSharedCase(CN,ent,list); // Remarque : en toute rigueur, il faudrait ignorer les entites referencees diff --git a/src/IGESDraw/IGESDraw_ToolViewsVisible.cxx b/src/IGESDraw/IGESDraw_ToolViewsVisible.cxx index d235fcd84d..19ae99752a 100644 --- a/src/IGESDraw/IGESDraw_ToolViewsVisible.cxx +++ b/src/IGESDraw/IGESDraw_ToolViewsVisible.cxx @@ -169,7 +169,7 @@ void IGESDraw_ToolViewsVisible::OwnRenew up = another->NbDisplayedEntities(); if (up == 0) return; Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities; - Handle(IGESData_IGESEntity) anew; + Handle(Standard_Transient) anew; for (I = 1; I <= up; I++) { if (TC.Search (another->DisplayedEntity(I),anew)) newdisp.GetOneItem(anew); } diff --git a/src/IGESDraw/IGESDraw_ToolViewsVisibleWithAttr.cxx b/src/IGESDraw/IGESDraw_ToolViewsVisibleWithAttr.cxx index c9ebce1287..213216427d 100644 --- a/src/IGESDraw/IGESDraw_ToolViewsVisibleWithAttr.cxx +++ b/src/IGESDraw/IGESDraw_ToolViewsVisibleWithAttr.cxx @@ -272,7 +272,7 @@ void IGESDraw_ToolViewsVisibleWithAttr::OwnRenew up = another->NbDisplayedEntities(); if (up == 0) return; Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities; - Handle(IGESData_IGESEntity) anew; + Handle(Standard_Transient) anew; for (I = 1; I <= up; I++) { if (TC.Search (another->DisplayedEntity(I),anew)) newdisp.GetOneItem(anew); } diff --git a/src/IGESGeom/IGESGeom_ToolBoundedSurface.cxx b/src/IGESGeom/IGESGeom_ToolBoundedSurface.cxx index e63532620b..d8da8c5020 100644 --- a/src/IGESGeom/IGESGeom_ToolBoundedSurface.cxx +++ b/src/IGESGeom/IGESGeom_ToolBoundedSurface.cxx @@ -109,11 +109,11 @@ void IGESGeom_ToolBoundedSurface::ReadOwnParams(const Handle(IGESGeom_BoundedSur if (!tempBounds.IsNull()){ for ( i = 1; i <= num; i++ ) { - Handle(IGESGeom_Boundary) tempEnt; + Handle(IGESData_IGESEntity) tempEnt; //st = PR.ReadEntity(IR, PR.Current(), Msg168, tempEnt); //szv#4:S4163:12Mar99 moved in if //st = PR.ReadEntity(IR, PR.Current(), "Boundary Entities", tempEnt); if (PR.ReadEntity(IR, PR.Current(), aStatus, tempEnt)) - tempBounds->SetValue(i, tempEnt); + tempBounds->SetValue(i, Handle(IGESGeom_Boundary)::DownCast (tempEnt)); else{ Message_Msg Msg168("XTSEP_168"); switch(aStatus) { diff --git a/src/IGESSelect/IGESSelect_RebuildDrawings.cxx b/src/IGESSelect/IGESSelect_RebuildDrawings.cxx index 216c2ed988..b2ce1ee5ab 100644 --- a/src/IGESSelect/IGESSelect_RebuildDrawings.cxx +++ b/src/IGESSelect/IGESSelect_RebuildDrawings.cxx @@ -165,11 +165,14 @@ IGESSelect_RebuildDrawings::IGESSelect_RebuildDrawings () // si View() transfere, mettre a jour ... for (setl.Start(); setl.More(); setl.Next()) { DeclareAndCast(IGESData_IGESEntity,ent,setl.Value()); - Handle(IGESData_ViewKindEntity) vieworig, viewnew; - vieworig = ent->View(); + Handle(IGESData_ViewKindEntity) vieworig = ent->View(); if (vieworig.IsNull()) continue; - if (!TC.Search(vieworig,viewnew)) continue; - ent->InitView(viewnew); + Handle(Standard_Transient) aView; + if (!TC.Search(vieworig,aView)) continue; + Handle(IGESData_ViewKindEntity) viewnew = + Handle(IGESData_ViewKindEntity)::DownCast (aView); + if (! viewnew.IsNull()) + ent->InitView(viewnew); } } diff --git a/src/IGESSolid/IGESSolid_ToolManifoldSolid.cxx b/src/IGESSolid/IGESSolid_ToolManifoldSolid.cxx index d6d1f91497..60e8c9b2e9 100644 --- a/src/IGESSolid/IGESSolid_ToolManifoldSolid.cxx +++ b/src/IGESSolid/IGESSolid_ToolManifoldSolid.cxx @@ -56,7 +56,7 @@ void IGESSolid_ToolManifoldSolid::ReadOwnParams Standard_Boolean abool, shellFlag; //szv#4:S4163:12Mar99 `st` moved down Standard_Integer nbshells, i; Handle(TColStd_HArray1OfInteger) voidShellFlags; - Handle(IGESSolid_Shell) shell; + Handle(IGESData_IGESEntity) shell; Handle(IGESSolid_Shell) ashell; Handle(IGESSolid_HArray1OfShell) voidShells; IGESData_Status aStatus; @@ -132,7 +132,7 @@ void IGESSolid_ToolManifoldSolid::ReadOwnParams } } DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent); - ent->Init (shell, shellFlag, voidShells, voidShellFlags); + ent->Init (Handle(IGESSolid_Shell)::DownCast (shell), shellFlag, voidShells, voidShellFlags); } void IGESSolid_ToolManifoldSolid::WriteOwnParams diff --git a/src/IGESSolid/IGESSolid_ToolToroidalSurface.cxx b/src/IGESSolid/IGESSolid_ToolToroidalSurface.cxx index 9c4f8a62d9..1106c165e0 100644 --- a/src/IGESSolid/IGESSolid_ToolToroidalSurface.cxx +++ b/src/IGESSolid/IGESSolid_ToolToroidalSurface.cxx @@ -44,7 +44,7 @@ void IGESSolid_ToolToroidalSurface::ReadOwnParams Handle(IGESGeom_Point) tempCenter; Standard_Real majRad, minRad; Handle(IGESGeom_Direction) tempAxis; // default Unparametrised - Handle(IGESGeom_Direction) tempRefdir; // default Unparametrised + Handle(IGESData_IGESEntity) tempRefdir; // default Unparametrised //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed PR.ReadEntity(IR, PR.Current(), "Center point", @@ -61,7 +61,7 @@ void IGESSolid_ToolToroidalSurface::ReadOwnParams PR.ReadEntity(IR, PR.Current(), "Reference direction", tempRefdir); //szv#4:S4163:12Mar99 `st=` not needed DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent); - ent->Init (tempCenter, tempAxis, majRad, minRad, tempRefdir); + ent->Init (tempCenter, tempAxis, majRad, minRad, Handle(IGESGeom_Direction)::DownCast (tempRefdir)); } void IGESSolid_ToolToroidalSurface::WriteOwnParams diff --git a/src/IntTools/IntTools_FaceFace.cxx b/src/IntTools/IntTools_FaceFace.cxx index e6ead52fca..a4146aecd8 100644 --- a/src/IntTools/IntTools_FaceFace.cxx +++ b/src/IntTools/IntTools_FaceFace.cxx @@ -143,7 +143,7 @@ static const Handle(IntTools_Context)& ); static - Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve); + Standard_Boolean IsCurveValid(const Handle(Geom2d_Curve)& thePCurve); static Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl, @@ -2622,7 +2622,7 @@ Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter, //function : IsCurveValid //purpose : //======================================================================= -Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve) +Standard_Boolean IsCurveValid (const Handle(Geom2d_Curve)& thePCurve) { if(thePCurve.IsNull()) return Standard_False; diff --git a/src/Interface/Interface_CopyTool.cxx b/src/Interface/Interface_CopyTool.cxx index 6411238f91..f281f79c38 100644 --- a/src/Interface/Interface_CopyTool.cxx +++ b/src/Interface/Interface_CopyTool.cxx @@ -268,9 +268,17 @@ Interface_CopyTool::Interface_CopyTool Handle(Standard_Transient) res; if (!themap->Search(ent,res)) continue; // entite pas transferee // Reconduction des references "Imply". Attention, ne pas copier si non chargee - Handle(Interface_ReportEntity) rep; - if (!therep->Search(ent,rep)) Implied (ent,res); - else if (!rep->HasNewContent()) Implied (ent,res); + Handle(Standard_Transient) aRep; + if (!therep->Search(ent,aRep)) + { + Implied (ent,res); + } + else + { + Handle(Interface_ReportEntity) rep = Handle(Interface_ReportEntity)::DownCast (aRep); + if (! rep.IsNull() && ! rep->HasNewContent()) + Implied (ent,res); + } } } @@ -302,7 +310,7 @@ Interface_CopyTool::Interface_CopyTool Handle(Standard_Transient) res; if (!themap->Search(ent,res)) continue; if (withreports) { - Handle(Interface_ReportEntity) rep; + Handle(Standard_Transient) rep; if (therep->Search(ent,rep)) res = rep; } iter.GetOneItem(res); @@ -321,7 +329,7 @@ Interface_CopyTool::Interface_CopyTool Handle(Standard_Transient) res; if (!themap->Search(ent,res)) continue; if (withreports) { - Handle(Interface_ReportEntity) rep; + Handle(Standard_Transient) rep; if (therep->Search(ent,rep)) res = rep; } iter.GetOneItem(res); diff --git a/src/MoniTool/MoniTool_Profile.cxx b/src/MoniTool/MoniTool_Profile.cxx index f9e7e8a72b..2071be16f0 100644 --- a/src/MoniTool/MoniTool_Profile.cxx +++ b/src/MoniTool/MoniTool_Profile.cxx @@ -280,10 +280,14 @@ static Standard_Boolean IsCurrent (const Standard_CString name) Handle(TCollection_HAsciiString) sw, val; if (!thecurconf->GetItem (name,sw,Standard_True)) sw.Nullify(); + Handle(Standard_Transient) aVal; if (!sw.IsNull()) { - if (!opt->Item (sw->ToCString(),val)) val.Nullify(); + if (!opt->Item (sw->ToCString(),aVal)) + aVal.Nullify(); } - if (val.IsNull() && !proper) opt->Value(val); + if (aVal.IsNull() && !proper) + opt->Value(aVal); + val = Handle(TCollection_HAsciiString)::DownCast (aVal); // On applique if (!val.IsNull()) tv->SetHStringValue (val); diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 2259b8100e..3762d4b2fc 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -2401,16 +2401,6 @@ void OpenGl_Context::ReleaseResource (const TCollection_AsciiString& theKey, } } -// ======================================================================= -// function : DelayedRelease -// purpose : -// ======================================================================= -void OpenGl_Context::DelayedRelease (Handle(OpenGl_Resource)& theResource) -{ - myUnusedResources->Prepend (theResource); - theResource.Nullify(); -} - // ======================================================================= // function : ReleaseDelayed // purpose : diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index f18f571fb3..a41b111f60 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -401,7 +401,12 @@ public: //! Append resource to queue for delayed clean up. //! Resources in this queue will be released at next redraw call. - Standard_EXPORT void DelayedRelease (Handle(OpenGl_Resource)& theResource); + template + void DelayedRelease (Handle(T)& theResource) + { + myUnusedResources->Prepend (theResource); + theResource.Nullify(); + } //! Clean up the delayed release queue. Standard_EXPORT void ReleaseDelayed(); diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index 0839951abd..09e48f63e2 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -1589,8 +1589,9 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context // function : nullifyResource // purpose : // ======================================================================= +template inline void nullifyResource (const Handle(OpenGl_Context)& theGlContext, - Handle(OpenGl_Resource)& theResource) + Handle(T)& theResource) { if (!theResource.IsNull()) { diff --git a/src/PrsMgr/PrsMgr_PresentationManager.cxx b/src/PrsMgr/PrsMgr_PresentationManager.cxx index 6c3d1bf2fd..65b313cb16 100644 --- a/src/PrsMgr/PrsMgr_PresentationManager.cxx +++ b/src/PrsMgr/PrsMgr_PresentationManager.cxx @@ -352,12 +352,13 @@ void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& the if (aPrs.IsNull()) continue; - Handle(Prs3d_Presentation) aViewDepPrs; + Handle(Graphic3d_Structure) aViewDepPrs; Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs); if (!aShadowPrs.IsNull() && aView->IsComputed (aShadowPrs->ParentId(), aViewDepPrs)) { aShadowPrs.Nullify(); - aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, aViewDepPrs); + aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, + Handle(Prs3d_Presentation)::DownCast (aViewDepPrs)); aShadowPrs->SetZLayer (aViewDepPrs->CStructure()->ZLayer()); aShadowPrs->SetClipPlanes (aViewDepPrs->GetClipPlanes()); aShadowPrs->CStructure()->IsForHighlight = 1; diff --git a/src/QANCollection/QANCollection_Handle.cxx b/src/QANCollection/QANCollection_Handle.cxx index 4ccfd25897..df52bb17c2 100644 --- a/src/QANCollection/QANCollection_Handle.cxx +++ b/src/QANCollection/QANCollection_Handle.cxx @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -50,8 +51,6 @@ inline void func (const Handle(gp_Pnt)&) {} inline void func (const Handle(gp_XYZ)&) {} inline void func (const Handle(gp_Trsf)&) {} -inline void gunc (Handle(Geom_Curve)&) {} - static Standard_Integer QAHandleOps (Draw_Interpretor& theDI, Standard_Integer /*theArgNb*/, const char** /*theArgVec*/) @@ -117,10 +116,7 @@ static Standard_Integer QAHandleOps (Draw_Interpretor& theDI, func (cLine); #endif - // passing handle as non-const reference to base type - // currently allowed for compatibility - gunc (aLine); - Handle(Geom_Curve)& aCurve2 = aLine; // cast to base non-const ref + const Handle(Geom_Curve)& aCurve2 = aLine; // cast to base const ref Handle(Geom_Line) qLine = cpLine; // constructor from const pointer -- could be made explicit... diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index 31c1f9cb4c..b9ab6305c7 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -2754,7 +2754,9 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers; if (aDatumSeqPos.Length() == 1) { // Datum entity - theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFirstDatum); + Handle(Standard_Transient) aFDValue; + if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue)) + aFirstDatum = Handle(StepDimTol_Datum)::DownCast (aFDValue); aDatumRef.SetValue(aFirstDatum); // Modifiers XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(1)->GetModifiers(); @@ -2776,7 +2778,9 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const for (Standard_Integer j = 1; j <= aDatumSeqPos.Length(); j++) { // Datum entity Handle(StepDimTol_Datum) aDatum; - theDatumMap.Find(aDatumSeqPos.Value(j)->GetName()->String(), aDatum); + Handle(Standard_Transient) aDValue; + if (theDatumMap.Find(aDatumSeqPos.Value(j)->GetName()->String(), aDValue)) + aDatum = Handle(StepDimTol_Datum)::DownCast (aDValue); StepDimTol_DatumOrCommonDatum anElemDatumRef; anElemDatumRef.SetValue(aDatum); if (aFirstDatum.IsNull()) @@ -3497,9 +3501,10 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W TCollection_AsciiString aDatumTargetId = TCollection_AsciiString(anObject->GetDatumTargetNumber()); if (!aNameIdMap.Add(aDatumName.Cat(aDatumTargetId))) continue; - Handle(StepDimTol_Datum) aWrittenDatum; + Handle(Standard_Transient) aWrittenDatum; Standard_Boolean isFirstDT = !aDatumMap.Find(aDatumName, aWrittenDatum); - Handle(StepDimTol_Datum) aDatum = WriteDatumAP242(WS, aShapeL.First(), aDatumL, isFirstDT, aWrittenDatum); + Handle(StepDimTol_Datum) aDatum = WriteDatumAP242(WS, aShapeL.First(), aDatumL, isFirstDT, + Handle(StepDimTol_Datum)::DownCast (aWrittenDatum)); // Add created Datum into Map aDatumMap.Bind(aDatumName, aDatum); } diff --git a/src/Select3D/Select3D_SensitiveGroup.cxx b/src/Select3D/Select3D_SensitiveGroup.cxx index e3b518e3e0..fa5cb64111 100644 --- a/src/Select3D/Select3D_SensitiveGroup.cxx +++ b/src/Select3D/Select3D_SensitiveGroup.cxx @@ -198,7 +198,7 @@ Standard_Boolean Select3D_SensitiveGroup::Matches (SelectBasics_SelectingVolumeM for (Select3D_EntitySequenceIter anIt (myEntities); anIt.More(); anIt.Next()) { SelectBasics_PickResult aMatchResult; - Handle(SelectBasics_SensitiveEntity)& aChild = anIt.ChangeValue(); + Handle(Select3D_SensitiveEntity)& aChild = anIt.ChangeValue(); if (!aChild->Matches (theMgr, aMatchResult)) { aMatchResult = SelectBasics_PickResult (RealLast(), RealLast()); diff --git a/src/Standard/Standard_Handle.hxx b/src/Standard/Standard_Handle.hxx index 896500a447..c037e608e2 100644 --- a/src/Standard/Standard_Handle.hxx +++ b/src/Standard/Standard_Handle.hxx @@ -239,6 +239,7 @@ namespace opencascade { //! Upcast to non-const reference to base type. //! NB: this cast can be dangerous, but required for legacy code; see #26377 template + Standard_DEPRECATED("Passing non-const reference to handle of base type in function is unsafe; use variable of exact type") operator handle& () { // error "type is not a member of enable_if" will be generated if T2 is not sub-type of T diff --git a/src/StdObjMgt/StdObjMgt_ReadData.hxx b/src/StdObjMgt/StdObjMgt_ReadData.hxx index 342eac0e54..3f6391413e 100644 --- a/src/StdObjMgt/StdObjMgt_ReadData.hxx +++ b/src/StdObjMgt/StdObjMgt_ReadData.hxx @@ -49,7 +49,9 @@ public: template StdObjMgt_ReadData& operator >> (Handle(Type)& theTarget) { - ReadReference (theTarget); + Handle(StdObjMgt_Persistent) aTarget = theTarget; + ReadReference (aTarget); + theTarget = Handle(Type)::DownCast (aTarget); return *this; } diff --git a/src/StepData/StepData_StepReaderData.cxx b/src/StepData/StepData_StepReaderData.cxx index cc0b497fe5..1691ba2a8e 100644 --- a/src/StepData/StepData_StepReaderData.cxx +++ b/src/StepData/StepData_StepReaderData.cxx @@ -515,7 +515,8 @@ Standard_Integer StepData_StepReaderData::ReadSub(const Standard_Integer numsub, Handle(StepData_SelectNamed) sn = new StepData_SelectNamed; val = sn; sn->SetName (rectyp.ToCString()); - if (ReadAny (numsub,1,mess,ach,descr,sn)) return sn->Kind(); + Handle(Standard_Transient) aSN = sn; + if (ReadAny (numsub,1,mess,ach,descr,aSN)) return sn->Kind(); else return 0; } @@ -686,7 +687,11 @@ Standard_Boolean StepData_StepReaderData::ReadMember(const Standard_Integer num, { Handle(Standard_Transient) v = val; Handle(StepData_PDescr) nuldescr; - if (v.IsNull()) return ReadAny (num,nump,mess,ach,nuldescr,val); + if (v.IsNull()) + { + return ReadAny (num,nump,mess,ach,nuldescr,v) && + ! (val = Handle(StepData_SelectMember)::DownCast(v)).IsNull(); + } Standard_Boolean res = ReadAny (num,nump,mess,ach,nuldescr,v); if (v == val) return res; // changement -> refus @@ -886,9 +891,11 @@ Standard_Boolean StepData_StepReaderData::ReadAny(const Standard_Integer num, Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal; for(Standard_Integer i=1; i<=nbp2; i++) { if( Param(numsub2,i).ParamType() != Interface_ParamReal ) continue; - Handle(StepData_SelectReal) sm1 = new StepData_SelectReal; - if( !ReadAny(numsub2,i,mess,ach,descr,sm1) ) continue; - aSeq->Append(sm1->Real()); + Handle(Standard_Transient) asr = new StepData_SelectReal; + if( !ReadAny(numsub2,i,mess,ach,descr,asr) ) continue; + Handle(StepData_SelectReal) sm1 = Handle(StepData_SelectReal)::DownCast (asr); + if (! sm1.IsNull()) + aSeq->Append(sm1->Real()); } Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,aSeq->Length()); for(Standard_Integer nr=1; nr<=aSeq->Length(); nr++) { diff --git a/src/StepData/StepData_StepReaderData.hxx b/src/StepData/StepData_StepReaderData.hxx index 65be5790b6..5e830520f3 100644 --- a/src/StepData/StepData_StepReaderData.hxx +++ b/src/StepData/StepData_StepReaderData.hxx @@ -175,6 +175,14 @@ public: //! some members as Entity, some other not) Standard_EXPORT Standard_Boolean ReadMember (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Handle(StepData_SelectMember)& val) const; + //! Safe variant for arbitrary type of argument + template + Standard_Boolean ReadMember (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, Handle(T)& val) const + { + Handle(StepData_SelectMember) aVal = val; + return ReadMember (num, nump, mess, ach, aVal) && ! (val = Handle(T)::DownCast(aVal)).IsNull(); + } + //! reads parameter of record into a Field, //! controlled by a Parameter Descriptor (PDescr), which controls //! its allowed type(s) and value @@ -230,6 +238,14 @@ public: //! is an Entity but is not Kind of required type Standard_EXPORT Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& ent) const; + //! Safe variant for arbitrary type of argument + template + Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, const Handle(Standard_Type)& atype, Handle(T)& ent) const + { + Handle(Standard_Transient) anEnt = ent; + return ReadEntity (num, nump, mess, ach, atype, anEnt) && ! (ent = Handle(T)::DownCast(anEnt)).IsNull(); + } + //! Same as above, but a SelectType checks Type Matching, and //! records the read Entity (see method Value from SelectType) Standard_EXPORT Standard_Boolean ReadEntity (const Standard_Integer num, const Standard_Integer nump, const Standard_CString mess, Handle(Interface_Check)& ach, StepData_SelectType& sel) const; diff --git a/src/StepData/StepData_StepReaderTool.cxx b/src/StepData/StepData_StepReaderTool.cxx index 5ab5db6454..074352a09c 100644 --- a/src/StepData/StepData_StepReaderTool.cxx +++ b/src/StepData/StepData_StepReaderTool.cxx @@ -211,9 +211,14 @@ Standard_Boolean StepData_StepReaderTool::AnalyseRecord Handle(Interface_Check)& acheck) { DeclareAndCast(StepData_StepReaderData,stepdat,Data()); - Handle(StepData_ReadWriteModule) module; Standard_Integer CN; - if (therlib.Select(anent,module,CN)) + Handle(Interface_ReaderModule) imodule; + Standard_Integer CN; + if (therlib.Select(anent,imodule,CN)) + { + Handle(StepData_ReadWriteModule) module = + Handle(StepData_ReadWriteModule)::DownCast (imodule); module->ReadStep(CN,stepdat,num,acheck,anent); + } else { // Pas trouve : tenter UndefinedEntity de StepData DeclareAndCast(StepData_UndefinedEntity,und,anent); diff --git a/src/TDF/TDF_Attribute.hxx b/src/TDF/TDF_Attribute.hxx index d8c42fad20..ac2fe9eacd 100644 --- a/src/TDF/TDF_Attribute.hxx +++ b/src/TDF/TDF_Attribute.hxx @@ -185,6 +185,14 @@ public: //! this method. Standard_EXPORT Standard_Boolean FindAttribute (const Standard_GUID& anID, Handle(TDF_Attribute)& anAttribute) const; + //! Safe variant for arbitrary type of argument + template + Standard_Boolean FindAttribute (const Standard_GUID& theID, Handle(T)& theAttr) const + { + Handle(TDF_Attribute) anAttr = theAttr; + return FindAttribute (theID, anAttr) && ! (theAttr = Handle(T)::DownCast(anAttr)).IsNull(); + } + //! Adds an Attribute to the label of //! .Raises if there is already one of the same //! GUID fhan . diff --git a/src/TDF/TDF_Label.hxx b/src/TDF/TDF_Label.hxx index 067b459f44..ac2fa195fe 100644 --- a/src/TDF/TDF_Label.hxx +++ b/src/TDF/TDF_Label.hxx @@ -150,6 +150,14 @@ public: //! A removed attribute cannot be found. Standard_EXPORT Standard_Boolean FindAttribute (const Standard_GUID& anID, Handle(TDF_Attribute)& anAttribute) const; + //! Safe variant of FindAttribute() for arbitrary type of argument + template + Standard_Boolean FindAttribute (const Standard_GUID& theID, Handle(T)& theAttr) const + { + Handle(TDF_Attribute) anAttr = theAttr; + return FindAttribute (theID, anAttr) && ! (theAttr = Handle(T)::DownCast(anAttr)).IsNull(); + } + //! Finds an attribute of the current label, according //! to and . This attribute //! has/had to be a valid one for the given diff --git a/src/TDF/TDF_RelocationTable.hxx b/src/TDF/TDF_RelocationTable.hxx index 5594a7f365..725ebf905c 100644 --- a/src/TDF/TDF_RelocationTable.hxx +++ b/src/TDF/TDF_RelocationTable.hxx @@ -106,6 +106,14 @@ public: //! explanation about the method behavior) Standard_EXPORT Standard_Boolean HasRelocation (const Handle(TDF_Attribute)& aSourceAttribute, Handle(TDF_Attribute)& aTargetAttribute) const; + //! Safe variant for arbitrary type of argument + template + Standard_Boolean HasRelocation (const Handle(TDF_Attribute)& theSource, Handle(T)& theTarget) const + { + Handle(TDF_Attribute) anAttr = theTarget; + return HasRelocation (theSource, anAttr) && ! (theTarget = Handle(T)::DownCast(anAttr)).IsNull(); + } + //! Sets the relocation value of to //! . Standard_EXPORT void SetTransientRelocation (const Handle(Standard_Transient)& aSourceTransient, const Handle(Standard_Transient)& aTargetTransient); diff --git a/src/TNaming/TNaming_NamedShape.cxx b/src/TNaming/TNaming_NamedShape.cxx index f7fae006bc..d09714f0e9 100644 --- a/src/TNaming/TNaming_NamedShape.cxx +++ b/src/TNaming/TNaming_NamedShape.cxx @@ -881,9 +881,9 @@ TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab, const Standard_Integer Trans) :myTrans(Trans) { - Handle(TNaming_NamedShape) Att; + Handle(TDF_Attribute) Att; if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) { - myNode = Att->myNode; + myNode = Handle(TNaming_NamedShape)::DownCast (Att)->myNode; } else { myNode = 0L; diff --git a/src/TPrsStd/TPrsStd_ConstraintTools.cxx b/src/TPrsStd/TPrsStd_ConstraintTools.cxx index 92acd55c01..9ea0e33bc9 100644 --- a/src/TPrsStd/TPrsStd_ConstraintTools.cxx +++ b/src/TPrsStd/TPrsStd_ConstraintTools.cxx @@ -1762,7 +1762,9 @@ void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)& Standard_Boolean is_planar (aConst->IsPlanar()); Handle(Geom_Plane) aplane; if (is_planar) { - GetGeom (aConst,aplane); + Handle(Geom_Geometry) ageom; + GetGeom (aConst,ageom); + aplane = Handle(Geom_Plane)::DownCast (ageom); if (aplane.IsNull()) { #ifdef OCCT_DEBUG cout << "TPrsStd_ConstraintTools::ComputeOffset: null plane" << endl; @@ -2090,8 +2092,9 @@ void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint } TopoDS_Shape shape1,shape2 ; - Handle(Geom_Plane) aplane; - GetShapesAndGeom(aConst,shape1,shape2,aplane); + Handle(Geom_Geometry) ageom; + GetShapesAndGeom(aConst,shape1,shape2,ageom); + Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast (ageom); if (shape1.IsNull() || shape2.IsNull()) { #ifdef OCCT_DEBUG cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul shape" << endl; diff --git a/src/Transfer/Transfer_ProcessForFinder.hxx b/src/Transfer/Transfer_ProcessForFinder.hxx index 57fa9cb0a8..d84700e9d8 100644 --- a/src/Transfer/Transfer_ProcessForFinder.hxx +++ b/src/Transfer/Transfer_ProcessForFinder.hxx @@ -240,6 +240,14 @@ public: //! immediately used, well initialised Standard_EXPORT Standard_Boolean FindTypedTransient (const Handle(Transfer_Finder)& start, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& val) const; + //! Safe variant for arbitrary type of argument + template + Standard_Boolean FindTypedTransient (const Handle(Transfer_Finder)& start, const Handle(Standard_Type)& atype, Handle(T)& val) const + { + Handle(Standard_Transient) aVal = val; + return FindTypedTransient (start, atype, aVal) && ! (val = Handle(T)::DownCast(aVal)).IsNull(); + } + //! Searches for a transient result recorded in a Binder, whatever //! this Binder is recorded or not in //! @@ -249,6 +257,14 @@ public: //! Apart from this, works as FindTypedTransient Standard_EXPORT Standard_Boolean GetTypedTransient (const Handle(Transfer_Binder)& binder, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& val) const; + //! Safe variant for arbitrary type of argument + template + Standard_Boolean GetTypedTransient (const Handle(Transfer_Binder)& start, const Handle(Standard_Type)& atype, Handle(T)& val) const + { + Handle(Standard_Transient) aVal = val; + return GetTypedTransient (start, atype, aVal) && ! (val = Handle(T)::DownCast(aVal)).IsNull(); + } + //! Returns the maximum possible value for Map Index //! (no result can be bound with a value greater than it) Standard_EXPORT Standard_Integer NbMapped() const; diff --git a/src/VrmlData/VrmlData_IndexedFaceSet.cxx b/src/VrmlData/VrmlData_IndexedFaceSet.cxx index 9d5d8ee9b2..0e5f8c4fe8 100644 --- a/src/VrmlData/VrmlData_IndexedFaceSet.cxx +++ b/src/VrmlData/VrmlData_IndexedFaceSet.cxx @@ -290,17 +290,33 @@ VrmlData_ErrorStatus VrmlData_IndexedFaceSet::Read(VrmlData_InBuffer& theBuffer) // These four checks should be the last one to avoid their interference // with the other tokens (e.g., coordIndex) else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "texCoord")) - aStatus = ReadNode (theBuffer, myTxCoords, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_TextureCoordinate)); + myTxCoords = Handle(VrmlData_TextureCoordinate)::DownCast (aNode); + } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "color")) - aStatus = ReadNode (theBuffer, myColors, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_Color)); + myColors = Handle(VrmlData_Color)::DownCast (aNode); + } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coord")) - aStatus = ReadNode (theBuffer, myCoords, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_Coordinate)); + myCoords = Handle(VrmlData_Coordinate)::DownCast (aNode); + } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "normal")) - aStatus = ReadNode (theBuffer, myNormals, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_Normal)); + myNormals = Handle(VrmlData_Normal)::DownCast (aNode); + } if (!OK(aStatus)) break; } diff --git a/src/VrmlData/VrmlData_IndexedLineSet.cxx b/src/VrmlData/VrmlData_IndexedLineSet.cxx index 45c3397b94..7f15d7a66d 100644 --- a/src/VrmlData/VrmlData_IndexedLineSet.cxx +++ b/src/VrmlData/VrmlData_IndexedLineSet.cxx @@ -144,11 +144,19 @@ VrmlData_ErrorStatus VrmlData_IndexedLineSet::Read // These two checks should be the last one to avoid their interference // with the other tokens (e.g., coordIndex) else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "color")) - aStatus = ReadNode (theBuffer, myColors, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_Color)); + myColors = Handle(VrmlData_Color)::DownCast (aNode); + } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coord")) - aStatus = ReadNode (theBuffer, myCoords, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_Coordinate)); + myCoords = Handle(VrmlData_Coordinate)::DownCast (aNode); + } else break; if (!OK(aStatus)) diff --git a/src/VrmlData/VrmlData_Node.cxx b/src/VrmlData/VrmlData_Node.cxx index 23ff39d68a..68cd03bfc0 100644 --- a/src/VrmlData/VrmlData_Node.cxx +++ b/src/VrmlData/VrmlData_Node.cxx @@ -370,13 +370,21 @@ VrmlData_ErrorStatus VrmlData_ShapeNode::Read (VrmlData_InBuffer& theBuffer) VrmlData_ErrorStatus aStatus; while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "appearance")) - aStatus = ReadNode (theBuffer, myAppearance, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_Appearance)); + myAppearance = Handle(VrmlData_Appearance)::DownCast (aNode); + } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "geometry")) - aStatus = ReadNode (theBuffer, myGeometry); + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode); + myGeometry = Handle(VrmlData_Geometry)::DownCast (aNode); // here we do not check for the Geometry type because unknown node types can // occur (IndexedLineSet, etc.) // STANDARD_TYPE(VrmlData_Geometry)); + } else break; @@ -509,14 +517,26 @@ VrmlData_ErrorStatus VrmlData_Appearance::Read (VrmlData_InBuffer& theBuffer) VrmlData_ErrorStatus aStatus; while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "material")) - aStatus = ReadNode (theBuffer, myMaterial, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_Material)); + myMaterial = Handle(VrmlData_Material)::DownCast (aNode); + } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "textureTransform")) - aStatus = ReadNode (theBuffer, myTTransform + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode /*,STANDARD_TYPE(VrmlData_TextureTransform)*/); + myTTransform = Handle(VrmlData_TextureTransform)::DownCast (aNode); + } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "texture")) - aStatus = ReadNode (theBuffer, myTexture, + { + Handle(VrmlData_Node) aNode; + aStatus = ReadNode (theBuffer, aNode, STANDARD_TYPE(VrmlData_Texture)); + myTexture = Handle(VrmlData_Texture)::DownCast (aNode); + } else break; diff --git a/src/XmlDrivers/XmlDrivers_DocumentRetrievalDriver.cxx b/src/XmlDrivers/XmlDrivers_DocumentRetrievalDriver.cxx index 360c4b9c9b..98fa1819d8 100644 --- a/src/XmlDrivers/XmlDrivers_DocumentRetrievalDriver.cxx +++ b/src/XmlDrivers/XmlDrivers_DocumentRetrievalDriver.cxx @@ -66,11 +66,14 @@ Handle(XmlMDF_ADriver) XmlDrivers_DocumentRetrievalDriver::ReadShapeSection( const Handle(CDM_MessageDriver)& theMsgDriver) { if (myDrivers.IsNull()) myDrivers = AttributeDrivers (theMsgDriver); - Handle(XmlMNaming_NamedShapeDriver) aNamedShapeDriver; - if (myDrivers -> GetDriver (STANDARD_TYPE(TNaming_NamedShape), - aNamedShapeDriver)) + Handle(XmlMDF_ADriver) aDriver; + if (myDrivers->GetDriver (STANDARD_TYPE(TNaming_NamedShape), aDriver)) + { + Handle(XmlMNaming_NamedShapeDriver) aNamedShapeDriver = + Handle(XmlMNaming_NamedShapeDriver)::DownCast (aDriver); aNamedShapeDriver -> ReadShapeSection (theElement); - return aNamedShapeDriver; + } + return aDriver; } //======================================================================= diff --git a/src/XmlDrivers/XmlDrivers_DocumentStorageDriver.cxx b/src/XmlDrivers/XmlDrivers_DocumentStorageDriver.cxx index eeedbdaff8..85d80c8f52 100644 --- a/src/XmlDrivers/XmlDrivers_DocumentStorageDriver.cxx +++ b/src/XmlDrivers/XmlDrivers_DocumentStorageDriver.cxx @@ -53,10 +53,12 @@ Handle(XmlMDF_ADriverTable) XmlDrivers_DocumentStorageDriver::AttributeDrivers Standard_Boolean XmlDrivers_DocumentStorageDriver::WriteShapeSection (XmlObjMgt_Element& theElement) { - Handle(XmlMNaming_NamedShapeDriver) aNamedShapeDriver; Standard_Boolean isShape(Standard_False); - if (myDrivers -> GetDriver (STANDARD_TYPE(TNaming_NamedShape), - aNamedShapeDriver)) { + Handle(XmlMDF_ADriver) aDriver; + if (myDrivers->GetDriver (STANDARD_TYPE(TNaming_NamedShape), aDriver)) + { + Handle(XmlMNaming_NamedShapeDriver) aNamedShapeDriver = + Handle(XmlMNaming_NamedShapeDriver)::DownCast (aDriver); aNamedShapeDriver -> WriteShapeSection (theElement); isShape = Standard_True; } diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc.cxx b/src/XmlMXCAFDoc/XmlMXCAFDoc.cxx index 24277d89b0..c2f76a22b3 100644 --- a/src/XmlMXCAFDoc/XmlMXCAFDoc.cxx +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc.cxx @@ -48,8 +48,10 @@ void XmlMXCAFDoc::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable, aDriverTable -> AddDriver (new XmlMXCAFDoc_GraphNodeDriver (anMsgDrv)); //oan: changes for sharing locations map - Handle(XmlMNaming_NamedShapeDriver) aNamedShapeDriver; - aDriverTable->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aNamedShapeDriver); + Handle(XmlMDF_ADriver) aDriver; + aDriverTable->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aDriver); + Handle(XmlMNaming_NamedShapeDriver) aNamedShapeDriver = + Handle(XmlMNaming_NamedShapeDriver)::DownCast (aDriver); Handle(XmlMXCAFDoc_LocationDriver) aLocationDriver = new XmlMXCAFDoc_LocationDriver (anMsgDrv); if( !aNamedShapeDriver.IsNull() ) diff --git a/tests/de/iges_2/F9 b/tests/de/iges_2/F9 index d5a7159743..752acf760f 100644 --- a/tests/de/iges_2/F9 +++ b/tests/de/iges_2/F9 @@ -6,7 +6,7 @@ puts "TODO CR23096 ALL: LABELS : Faulty" set filename 919-004-T03-04-CP-VL.igs set ref_data { -DATA : Faulties = 0 ( 0 ) Warnings = 0 ( 0 ) Summary = 0 ( 0 ) +DATA : Faulties = 0 ( 2 ) Warnings = 0 ( 0 ) Summary = 0 ( 2 ) TPSTAT : Faulties = 0 ( 2 ) Warnings = 310 ( 2179 ) Summary = 310 ( 2181 ) CHECKSHAPE : Wires = 0 ( 3 ) Faces = 0 ( 3 ) Shells = 0 ( 0 ) Solids = 0 ( 0 ) NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 1457 ( 1455 ) Summary = 38832 ( 38834 ) diff --git a/tests/perf/fclasses/handle b/tests/perf/fclasses/handle index ac43e5bb4d..1e9d985193 100644 --- a/tests/perf/fclasses/handle +++ b/tests/perf/fclasses/handle @@ -23,28 +23,3 @@ set ratio [expr $time_occt / $time_std] if { $ratio > 1.05 } { puts "Error: OCCT handle is too slow: $time_occt vs. $time_std of shared_ptr" } - -# Check performance of down casting at different nesting depths. -# OCCT is expected to be the same as C++ -set depths {3 5 10 50} -set threshold_std 4.0 -set threshold_ptr 2.5 -for {set i 0} {$i < [llength $depths]} {incr i} { - set depth [lindex $depths $i] - puts "\nTesting DownCast at nesting depth $depth" - - set res [QAHandleCast $depth 0 100000] - set res_lines [split $res \n] - set time_occt [lindex [lindex [split [lindex $res_lines end-2] :] end] end] - set time_std [lindex [lindex [split [lindex $res_lines end-1] :] end] end] - set time_ptr [lindex [lindex [split [lindex $res_lines end ] :] end] end] - set ratio_std [expr $time_occt / $time_std] - set ratio_ptr [expr $time_occt / $time_ptr] - - puts "Ratio of time of OCCT DownCast() to dynamic_cast<>: $ratio_std" - puts "Ratio of time of OCCT DownCast() to dynamic_pointer_cast<>: $ratio_ptr" - - if { $ratio_std > $threshold_std || $ratio_ptr > $threshold_ptr } { - puts "Error: OCCT DownCast is expected to be faster!" - } -} \ No newline at end of file