1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0029362: Data Exchange - Crash during reading step file

Additional check for wires into searching of attached shapes,
Fix Dimension value processing,
This commit is contained in:
ika 2017-12-04 11:05:02 +03:00 committed by bugmaster
parent 77cd443b99
commit 5b7f8e0a69
5 changed files with 119 additions and 71 deletions

View File

@ -124,7 +124,9 @@
#include <StepRepr_RepresentationRelationship.hxx>
#include <StepRepr_RepresentedDefinition.hxx>
#include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
#include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
#include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
#include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
#include <StepRepr_SequenceOfRepresentationItem.hxx>
#include <StepRepr_ShapeAspect.hxx>
#include <StepRepr_ShapeAspectDerivingRelationship.hxx>
@ -3064,7 +3066,7 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
{
Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS);
TopoDS_Shape aSh;
if(anIndex >0) {
if(anIndex > 0) {
Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
aSh = TransferBRep::ShapeResult(aBinder);
}
@ -3072,7 +3074,20 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
{
TDF_Label aShL;
aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
aShLS1.Append(aShL);
if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
{
TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
while (ex.More())
{
TDF_Label edgeL;
aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
if (!edgeL.IsNull())
aShLS1.Append(edgeL);
ex.Next();
}
}
if (!aShL.IsNull())
aShLS1.Append(aShL);
}
}
if (!aSeqRI2.IsEmpty())
@ -3090,7 +3105,20 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
{
TDF_Label aShL;
aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
aShLS2.Append(aShL);
if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
{
TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
while (ex.More())
{
TDF_Label edgeL;
aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
if (!edgeL.IsNull())
aShLS2.Append(edgeL);
ex.Next();
}
}
if (!aShL.IsNull())
aShLS2.Append(aShL);
}
}
}
@ -3172,6 +3200,7 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
aDimObj = new XCAFDimTolObjects_DimensionObject();
Standard_Real aDim1=-1.,aDim2=-1.,aDim3=-1.;
Standard_Boolean isPlusMinusTolerance = Standard_False;
Handle(StepShape_TypeQualifier) aTQ;
Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
Handle(StepShape_ToleranceValue) aTV;
@ -3205,79 +3234,65 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
Handle(StepRepr_RepresentationItem) aDRI = aHARI->Value(nr);
if(aDRI.IsNull()) continue;
if(aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
//get values
Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aRILMWU =
Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aDRI);
Standard_Real aVal = aRILMWU->GetMeasureWithUnit()->ValueComponent();
StepBasic_Unit anUnit = aRILMWU->GetMeasureWithUnit()->UnitComponent();
Standard_Real aFact=1.;
if(anUnit.IsNull()) continue;
if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))) {
// simple value / range
Handle(StepRepr_ReprItemAndMeasureWithUnit) aMWU =
Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aDRI);
Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
Standard_Real aFact = 1.;
if (anUnit.IsNull())
continue;
if (!(anUnit.CaseNum(anUnit.Value()) == 1))
continue;
Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
if(aDim2 > 0)
{
if(aDim1 > aDim2)
{
Standard_Real aTmp = aDim1;
aDim1 = aDim2;
aDim2 = aTmp;
}
if(aVal < aDim1)
aDim1 = aVal;
else if(aVal > aDim2)
aDim2 = aVal;
}
else if(aDim1 > 0)
{
if (aVal > aDim1)
aDim2 = aVal;
else
{
aDim2 = aDim1;
aDim1 = aVal;
}
if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
if (GetLengthConversionFactor(NU, aFact))
aVal = aVal * aFact;
}
else
if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
if (GetAngleConversionFactor(NU, aFact))
aVal = aVal * aFact;
}
Handle(TCollection_HAsciiString) aName = aMWU->Name();
if (aName->Search("upper") > 0) // upper limit
aDim2 = aVal;
else // lower limit or simple nominal value
aDim1 = aVal;
}
else if(aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
//get values
Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) aRIPAMWU =
Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit)::DownCast(aDRI);
Standard_Real aVal = aRIPAMWU->GetMeasureWithUnit()->ValueComponent();
StepBasic_Unit anUnit = aRIPAMWU->GetMeasureWithUnit()->UnitComponent();
Standard_Real aFact=1.;
if(anUnit.IsNull()) continue;
if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnitAndQRI))) {
// value with qualifier (minimum/maximum/average)
Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI) aMWU =
Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI)::DownCast(aDRI);
Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
Standard_Real aFact = 1.;
if(anUnit.IsNull())
continue;
if( !(anUnit.CaseNum(anUnit.Value()) == 1) )
continue;
Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
if(GetAngleConversionFactor(NU,aFact)) aVal=aVal*aFact;
if(aDim2 > 0)
{
if(aDim1 > aDim2)
{
Standard_Real aTmp = aDim1;
aDim1 = aDim2;
aDim2 = aTmp;
}
if(aVal < aDim1)
aDim1 = aVal;
else if(aVal > aDim2)
aDim2 = aVal;
}
else if(aDim1 > 0)
{
if (aVal > aDim1)
aDim2 = aVal;
else
{
aDim2 = aDim1;
aDim1 = aVal;
}
if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) {
if (GetLengthConversionFactor(NU, aFact))
aVal = aVal * aFact;
}
else
if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) {
if (GetAngleConversionFactor(NU, aFact))
aVal = aVal * aFact;
}
Handle(StepShape_QualifiedRepresentationItem) aQRI = aMWU->GetQualifiedRepresentationItem();
if (aQRI->Qualifiers()->Length() == 0) {
aDim1 = aVal;
continue;
}
Handle(StepShape_TypeQualifier) aValueType = aQRI->Qualifiers()->Value(1).TypeQualifier();
if (aValueType->Name()->String().IsEqual("minimum"))
aDim2 = aVal;
else if (aValueType->Name()->String().IsEqual("maximum"))
aDim3 = aVal;
else aDim1 = aVal;
}
else if(aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) {
//get qualifier
@ -3307,6 +3322,7 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
}
else if (!aPMT.IsNull())
{
isPlusMinusTolerance = Standard_True;
StepShape_ToleranceMethodDefinition aTMD = aPMT->Range();
if(aPMT.IsNull()) continue;
if(aTMD.CaseNumber() == 1)
@ -3357,6 +3373,11 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
else
{
Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,3);
if (!isPlusMinusTolerance)
{
aDim2 = aDim1 - aDim2;
aDim3 = aDim3 - aDim1;
}
anArr->SetValue(1,aDim1);
anArr->SetValue(2,aDim2);
anArr->SetValue(3,aDim3);

19
tests/gdt/export/C2 Normal file
View File

@ -0,0 +1,19 @@
# !!!! This file is generated automatically, do not edit manually! See end script
set filename bug29362_MMT200.stp
set ref_data {
NbOfDimensions : 2
NbOfDimensionalSize : 1
NbOfDimensionalLocation: 1
NbOfAngular : 0
NbOfWithPath : 0
NbOfCommonLabels : 0
NbOfTolerances : 0
NbOfGTWithModifiers : 0
NbOfGTWithMaxTolerance : 0
NbOfGTWithDatums : 0
NbOfDatumFeature : 0
NbOfAttachedDatum : 0
NbOfDatumTarget : 0
}

View File

@ -2,7 +2,7 @@
set filename bug27808_nist_ftc_09_asme1_ct5240_rd.stp
set ref_data {
Centre of mass: -40.148168442038951 12.662743709548829 -20.675422904248919
Mass: 33730.842652736828
Centre of mass: -39.98246176261911 12.596839170418153 -21.235634697624899
Mass: 34084.671316201595
}

View File

@ -2,7 +2,7 @@
set filename bug27645_nist_ftc_09_asme1_ct5240_rd-1.stp
set ref_data {
Centre of mass: -1019.7633667828792 321.63378807296516 -525.15615589604056
Mass: 856763.26313637081
Centre of mass: -1015.5544287505505 319.95981300805124 -539.38551468015555
Mass: 865750.50341424928
}

View File

@ -0,0 +1,8 @@
# !!!! This file is generated automatically, do not edit manually! See end script
set filename bug29362_MMT200.stp
set ref_data {
Centre of mass: 0 0 0
Mass: 0
}