1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0027104: DownCast() cannot return null for mismatched handle

Method DownCast() is made template, to be available only when argument is actually a pointer or handle to a base class.

For compatibility with existing code, method DownCast() that can be used for the same type, derived, or unrelated class (i.e. where there is no actual down casting) is still available, its use shall cause "deprecated" compiler warning.

OCCT code is updated to remove meaningless DownCast()s; a few places where DownCast() was used with argument of unrelated type are corrected.

DRAW command QAHandleCast is removed (it was useful only during redesign of handles).
This commit is contained in:
abv
2016-01-25 10:14:20 +03:00
parent 5d351a0822
commit a9dde4a31b
65 changed files with 190 additions and 380 deletions

View File

@@ -1415,8 +1415,7 @@ static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &
if (subSHUO.IsNull())
return Standard_False;
Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subSHUO->NextUsage());
Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = subSHUO->NextUsage();
if (NUNAUO.IsNull())
return Standard_False;
// Handle(Interface_InterfaceModel) Model = WS->Model();
@@ -1454,8 +1453,7 @@ static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS,
// get upper usage NAUO from SHUO.
Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->NextUsage());
Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = SHUO->NextUsage();
if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) {
#ifdef OCCT_DEBUG
cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
@@ -1795,8 +1793,7 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
Handle(StepRepr_ShapeAspectRelationship) SAR =
Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterC.Value());
if(SAR.IsNull()) continue;
Handle(StepRepr_ShapeAspect) aS =
Handle(StepRepr_ShapeAspect)::DownCast(SAR->RelatedShapeAspect());
Handle(StepRepr_ShapeAspect) aS = SAR->RelatedShapeAspect();
if(aS.IsNull()) continue;
Interface_EntityIterator anIterSA = aGraph.Sharings(aS);
for(anIterSA.Start(); anIterSA.More() && aPGISU.IsNull(); anIterSA.Next()) {
@@ -1835,7 +1832,7 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
Handle(StepRepr_RepresentationItem) aRI;
for(Standard_Integer i = 1 ; i <= aPGISU->NbIdentifiedItem() && aRI.IsNull(); i++)
{
aRI = Handle(StepRepr_RepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(i));
aRI = aPGISU->IdentifiedItemValue(i);
}
if(aRI.IsNull()) continue;
Standard_Integer index = aTP->MapIndex(aRI);
@@ -1891,7 +1888,7 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
= Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
Handle(StepRepr_RepresentationItem) anItem;
if(aPGISU->NbIdentifiedItem() > 0) {
anItem = Handle(StepRepr_RepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
anItem = aPGISU->IdentifiedItemValue(1);
}
if(anItem.IsNull()) continue;
Standard_Integer anItemIndex = aTP->MapIndex(anItem);
@@ -2059,8 +2056,7 @@ static Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt
{
for(Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
{
Handle(StepDimTol_DatumReferenceCompartment) aDRC
= Handle(StepDimTol_DatumReferenceCompartment)::DownCast(aDRCA->Value(i));
Handle(StepDimTol_DatumReferenceCompartment) aDRC = aDRCA->Value(i);
//gete modifiers
Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
@@ -2328,8 +2324,7 @@ static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
if(HARI.IsNull()) continue;
if(HARI->Length()>0) {
Handle(StepRepr_RepresentationItem) RI1 =
Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(1));
Handle(StepRepr_RepresentationItem) RI1 = HARI->Value(1);
if(RI1.IsNull()) continue;
if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
@@ -2344,8 +2339,7 @@ static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
}
}
if(HARI->Length()>1) {
Handle(StepRepr_RepresentationItem) RI2 =
Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(2));
Handle(StepRepr_RepresentationItem) RI2 = HARI->Value(2);
if(RI2.IsNull()) continue;
if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
@@ -2635,8 +2629,7 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
{
for(Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++)
{
Handle(StepRepr_RepresentationItem) aDRI =
Handle(StepRepr_RepresentationItem)::DownCast(aHARI->Value(nr));
Handle(StepRepr_RepresentationItem) aDRI = aHARI->Value(nr);
if(aDRI.IsNull()) continue;
if(aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {

View File

@@ -949,8 +949,7 @@ static Standard_Boolean getStyledItem(const TopoDS_Shape& S,
for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
Handle(StepVisual_PresentationStyleAssignment) aFatherPSA =
Handle(StepVisual_PresentationStyleAssignment)::DownCast(aSelItm->StylesValue(jsi));
Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
// check for PSA for top-level (not Presentation style by contex for NAUO)
if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
continue;
@@ -973,8 +972,7 @@ static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledI
{
Standard_Boolean found = Standard_False;
for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
Handle(StepVisual_PresentationStyleAssignment) aFatherPSA =
Handle(StepVisual_PresentationStyleAssignment)::DownCast(aSelItm->StylesValue(jsi));
Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
// check for PSA for top-level (not Presentation style by contex for NAUO)
if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
return Standard_False;
@@ -1279,8 +1277,7 @@ Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_Work
for ( si=1; si <= oldLengthlen; si++ )
newItems->SetValue( el++, oldItems->Value( si ) );
for ( si=1; si <= Styles.NbStyles(); si++ ) {
newItems->SetValue( el++, Handle(StepRepr_RepresentationItem)::DownCast(Styles.Style(si)));
// WP->Model()->AddWithRefs ( Handle(StepRepr_RepresentationItem)::DownCast (Styles.Style(si)));
newItems->SetValue( el++, Styles.Style(si));
}
if (newItems->Length() > 0)
@@ -1294,8 +1291,7 @@ Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_Work
new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles());
// put all style item into the harray
for ( Standard_Integer si=1; si <= Styles.NbStyles(); si++ ) {
Handle(StepRepr_RepresentationItem) styledItm =
Handle(StepRepr_RepresentationItem)::DownCast(Styles.Style(si));
Handle(StepRepr_RepresentationItem) styledItm = Styles.Style(si);
StepVisual_InvisibleItem anInvItem;
anInvItem.SetValue( styledItm );
HInvsblItm->SetValue( si, anInvItem );
@@ -1909,7 +1905,7 @@ static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style,
Standard_Integer el = 1;
for ( si=1; si <= oldLengthlen; si++ )
newItems->SetValue( el++, oldItems->Value( si ) );
newItems->SetValue( el++, Handle(StepRepr_RepresentationItem)::DownCast(STEPstyle) );
newItems->SetValue (el++, STEPstyle);
// init MDGPR be new array of styled items
if (newItems->Length() > 0)
aMDGPR->SetItems( newItems );
@@ -2846,7 +2842,7 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const
StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
aDefinition.SetValue(aDS);
Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
Handle(StepRepr_RepresentationItem) anIdentifiedItem = Handle(StepRepr_RepresentationItem)::DownCast(anAxis);
Handle(StepRepr_RepresentationItem) anIdentifiedItem = anAxis;
anReprItems->SetValue(1, anIdentifiedItem);
Interface_EntityIterator subs = aGraph.Sharings(aFirstDatum->OfShape());
Handle(StepShape_ShapeDefinitionRepresentation) aSDR;