From: ika Date: Tue, 28 Jun 2016 09:00:13 +0000 (+0300) Subject: 0027313: Exception during WriteStep with PMI X-Git-Tag: V7_1_0_beta~147 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=c10703215e98d146187a49290de9057876f38191 0027313: Exception during WriteStep with PMI Add check for datum position during export of datum_system Add Draw commands for set/get datum position update test cases Correction of case bugs/step/bug27313 --- diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index 1076d49e9f..20c44fe5bc 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -2881,6 +2881,8 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const aDatums.Append(aDatumObj); aMaxDatumNum = Max(aMaxDatumNum, aDatumObj->GetPosition()); } + if (aMaxDatumNum == 0) + return NULL; Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aConstituents = new StepDimTol_HArray1OfDatumReferenceCompartment(1, aMaxDatumNum); diff --git a/src/XDEDRAW/XDEDRAW_GDTs.cxx b/src/XDEDRAW/XDEDRAW_GDTs.cxx index 6475344cfc..9ea57065e9 100644 --- a/src/XDEDRAW/XDEDRAW_GDTs.cxx +++ b/src/XDEDRAW/XDEDRAW_GDTs.cxx @@ -635,10 +635,93 @@ static Standard_Integer setDatum (Draw_Interpretor& di, Standard_Integer argc, c return 1; } + // check datum position number + Handle(XCAFDoc_Datum) aDatumAttr; + if (!aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr)) + { + di<<"Invalid datum object\n"; + return 1; + } + Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject(); + if (aDatumObj.IsNull()) + { + di<<"Invalid datum object\n"; + return 1; + } + + if (aDatumObj->GetPosition() < 1 || aDatumObj->GetPosition() > 3) + { + di<<"Invalid datum position number: use XSetDatumPosition\n"; + return 1; + } + aDimTolTool->SetDatumToGeomTol(aLabel, aTol); return 0; } +static Standard_Integer setDatumPosition (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc < 4) { + di<<"Use: XSetDatumPosition Doc Datum_Label position[1-3]\n"; + return 1; + } + + if (Draw::Atoi(argv[3]) < 1 || Draw::Atoi(argv[3]) > 3) { + di<<"Datum position should be 1, 2 or 3\n"; + return 1; + } + + Handle(TDocStd_Document) Doc; + DDocStd::GetDocument(argv[1], Doc); + if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } + Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main()); + Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); + + TDF_Label aLabel; + TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); + if ( aLabel.IsNull() ) + { + di<<"Datum "<GetObject(); + anObj->SetPosition(Draw::Atoi(argv[3])); + aDatum->SetObject(anObj); + } + return 0; +} + +static Standard_Integer getDatumPosition (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc < 3) { + di<<"Use: XGetDatumPosition Doc Datum_Label\n"; + return 1; + } + Handle(TDocStd_Document) Doc; + DDocStd::GetDocument(argv[1], Doc); + if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } + Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(Doc->Main()); + Handle(XCAFDoc_ShapeTool) aShapeTool= XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); + + TDF_Label aLabel; + TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); + if ( aLabel.IsNull() ) + { + di<<"Datum "<GetObject()->GetPosition(); + } + return 0; +} + + static Standard_Integer getDatum (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { if (argc < 3) { @@ -2480,6 +2563,13 @@ void XDEDRAW_GDTs::InitCommands(Draw_Interpretor& di) di.Add ("XGetDatumName","XGetDatumName Doc Datum_Label", __FILE__, getDatumName, g); + di.Add ("XSetDatumPosition","XSetDatumPosition Doc Datum_Label position[1-3]" + "Set datum position number in geometric tolerance datum system", + __FILE__, setDatumPosition, g); + + di.Add ("XGetDatumPosition","XGetDatumPosition Doc Datum_Label", + __FILE__, getDatumPosition, g); + di.Add ("XSetTypeOfTolerance","XSetTypeOfTolerance Doc GTol_Label type" "Values:\n" "\t 0 type is absent\n" diff --git a/tests/bugs/step/bug27313 b/tests/bugs/step/bug27313 new file mode 100644 index 0000000000..8c353520fa --- /dev/null +++ b/tests/bugs/step/bug27313 @@ -0,0 +1,31 @@ +puts "========" +puts "OCC27313" +puts "========" +puts "" +########################################################################## +# Exception during WriteStep with PMI +########################################################################## + +pload DCAF + +box b 10 10 10 +explode b +explode b_1 +NewDocument D +XAddShape D b +XAddGeomTolerance D b_1_1 +XAddDatum D b_1_2 +#0:1:4:1 +#0:1:4:2 +XSetDatumName D 0:1:4:2 A +XAddDatumModifier D 0:1:4:2 10 +XSetDatumPosition D 0:1:4:2 1 +XSetDatum D 0:1:4:2 0:1:4:1 +XSetToleranceValue D 0:1:4:1 0.5 +XSetTypeOfTolerance D 0:1:4:1 1 +XSetTypeOfToleranceValue D 0:1:4:1 1 +param write.step.schema 5 +newmodel +WriteStep D $imagedir/${casename}_D.stp +param write.step.schema 4 +newmodel diff --git a/tests/gdt/tolerances/A1 b/tests/gdt/tolerances/A1 index 5c55789e1b..8e0ad28071 100644 --- a/tests/gdt/tolerances/A1 +++ b/tests/gdt/tolerances/A1 @@ -11,6 +11,7 @@ XAddDatum D b_1_2 #0:1:4:2 XSetDatumName D 0:1:4:2 A XAddDatumModifier D 0:1:4:2 10 +XSetDatumPosition D 0:1:4:2 1 XSetDatum D 0:1:4:2 0:1:4:1 XSetToleranceValue D 0:1:4:1 0.5 XSetTypeOfTolerance D 0:1:4:1 1 diff --git a/tests/gdt/tolerances/A2 b/tests/gdt/tolerances/A2 index d687bd5c14..cecdf42ce8 100644 --- a/tests/gdt/tolerances/A2 +++ b/tests/gdt/tolerances/A2 @@ -12,7 +12,9 @@ XAddDatum D b_1_3 #0:1:4:2 #0:1:4:3 XSetDatumName D 0:1:4:2 A +XSetDatumPosition D 0:1:4:2 1 XSetDatumName D 0:1:4:3 B +XSetDatumPosition D 0:1:4:3 2 XAddDatumModifier D 0:1:4:2 10 XSetDatum D 0:1:4:2 0:1:4:1 XSetDatum D 0:1:4:3 0:1:4:1