From 5203f741830d5eaac3c1b65ac274ea3f0a6d9e0f Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 16 Oct 2014 15:35:22 +0400 Subject: [PATCH] 0021802: Not all names are transferred from STEP to IGES via XDE Method IGESCAFControl_Writer::WriteNames now iterates over all nested assemblies and collects names for shapes. Regression fix Test-case for issue #21802 --- src/IGESCAFControl/IGESCAFControl_Writer.cxx | 124 +++++++++++++++---- tests/bugs/xde/bug21802 | 25 ++++ 2 files changed, 123 insertions(+), 26 deletions(-) create mode 100644 tests/bugs/xde/bug21802 diff --git a/src/IGESCAFControl/IGESCAFControl_Writer.cxx b/src/IGESCAFControl/IGESCAFControl_Writer.cxx index db52df5cfd..3c7ab22805 100644 --- a/src/IGESCAFControl/IGESCAFControl_Writer.cxx +++ b/src/IGESCAFControl/IGESCAFControl_Writer.cxx @@ -43,6 +43,62 @@ #include #include #include +#include + +namespace +{ + typedef NCollection_DataMap DataMapOfShapeNames; + + void CollectShapeNames (const TDF_Label& theLabel, + const TopLoc_Location& theLocation, + const Handle(TDataStd_Name)& thePrevName, + DataMapOfShapeNames& theMapOfShapeNames) + { + Standard_Boolean hasReferredShape = Standard_False; + Standard_Boolean hasComponents = Standard_False; + TDF_Label aReferredLabel; + + Handle(TDataStd_Name) aName; + theLabel.FindAttribute (TDataStd_Name::GetID(), aName); + + if ( XCAFDoc_ShapeTool::GetReferredShape ( theLabel, aReferredLabel ) ) + { + TopLoc_Location aSubLocation = theLocation.Multiplied ( XCAFDoc_ShapeTool::GetLocation ( theLabel ) ); + CollectShapeNames (aReferredLabel, aSubLocation, aName, theMapOfShapeNames); + hasReferredShape = Standard_True; + } + + TDF_LabelSequence aSeq; + if (XCAFDoc_ShapeTool::GetComponents (theLabel, aSeq)) + { + for (Standard_Integer anIter = 1; anIter <= aSeq.Length(); anIter++) + { + CollectShapeNames (aSeq.Value (anIter), theLocation, aName, theMapOfShapeNames ); + } + hasComponents = Standard_True; + } + + aSeq.Clear(); + if (XCAFDoc_ShapeTool::GetSubShapes (theLabel, aSeq)) + { + for (Standard_Integer anIter = 1; anIter <= aSeq.Length(); anIter++) + { + TopoDS_Shape aShape; + if (!XCAFDoc_ShapeTool::GetShape (aSeq.Value (anIter), aShape)) continue; + if (!aSeq.Value (anIter).FindAttribute (TDataStd_Name::GetID(), aName)) continue; + theMapOfShapeNames.Bind (aShape, aName->Get()); + } + } + + if (!hasReferredShape && !hasComponents) + { + TopoDS_Shape aShape; + if (!XCAFDoc_ShapeTool::GetShape (theLabel, aShape)) return; + aShape.Move (theLocation); + theMapOfShapeNames.Bind (aShape, thePrevName->Get()); + } + } +} //======================================================================= //function : IGESCAFControl_Writer @@ -399,38 +455,54 @@ Standard_Boolean IGESCAFControl_Writer::WriteLayers (const TDF_LabelSequence& la //purpose : //======================================================================= -Standard_Boolean IGESCAFControl_Writer::WriteNames (const TDF_LabelSequence& labels) +Standard_Boolean IGESCAFControl_Writer::WriteNames (const TDF_LabelSequence& theLabels) { - if ( labels.Length() <=0 ) return Standard_False; - Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( labels(1) ); - if ( STool.IsNull() ) return Standard_False; - TDF_ChildIterator labelShIt(STool->BaseLabel() , Standard_True); - for (; labelShIt.More(); labelShIt.Next() ) { - TDF_Label shLabel = labelShIt.Value(); + if (theLabels.Length() <= 0) return Standard_False; + + DataMapOfShapeNames aMapOfShapeNames; + + for (Standard_Integer anIter = 1; anIter <= theLabels.Length(); anIter++ ) + { + TDF_Label aLabel = theLabels.Value (anIter); + + TopoDS_Shape aShape; Handle(TDataStd_Name) aName; - if ( !shLabel.FindAttribute( TDataStd_Name::GetID(), aName) ) continue; - TCollection_ExtendedString shName = aName->Get(); - TopoDS_Shape Sh; - if ( !STool->GetShape(shLabel, Sh) ) continue; - Handle(Transfer_FinderProcess) FP = TransferProcess(); - Handle(IGESData_IGESEntity) Igesent; - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh ); - if ( FP->FindTypedTransient ( mapper, STANDARD_TYPE(IGESData_IGESEntity), Igesent ) ) { - Handle(TCollection_HAsciiString) HAname = new TCollection_HAsciiString ( " " ); - Standard_Integer len = 8 - shName.Length(); - if ( len <0 ) len = 0; - for ( Standard_Integer k=1; len <8; k++, len++ ) { - HAname->SetValue ( len+1, IsAnAscii(shName.Value(k)) ? (Standard_Character)shName.Value(k) : '?' ); - } - Igesent->SetLabel( HAname ); -// Handle(IGESData_NameEntity) aNameent = new IGESData_NameEntity; -// Igesent->AddProperty(aNameent); - } + if (!XCAFDoc_ShapeTool::GetShape (aLabel, aShape)) continue; + if (!aLabel.FindAttribute (TDataStd_Name::GetID(), aName)) continue; + + aMapOfShapeNames.Bind (aShape, aName->Get()); + + // Collect names for subshapes + TopLoc_Location aLocation; + CollectShapeNames (aLabel, aLocation, aName, aMapOfShapeNames); } + + for (DataMapOfShapeNames::Iterator anIter (aMapOfShapeNames); + anIter.More(); anIter.Next()) + { + const TopoDS_Shape& aShape = anIter.Key(); + const TCollection_ExtendedString& aName = anIter.Value(); + + Handle(Transfer_FinderProcess) aFinderProcess = TransferProcess(); + Handle(IGESData_IGESEntity) anIGESEntity; + Handle(TransferBRep_ShapeMapper) aShapeMapper = TransferBRep::ShapeMapper (aFinderProcess, aShape); + + if (aFinderProcess->FindTypedTransient (aShapeMapper, STANDARD_TYPE(IGESData_IGESEntity), anIGESEntity)) + { + Handle(TCollection_HAsciiString) anAsciiName = new TCollection_HAsciiString (" "); + Standard_Integer aNameLength = 8 - aName.Length(); + if (aNameLength < 0) aNameLength = 0; + for (Standard_Integer aCharPos = 1; aNameLength < 8; aCharPos++, aNameLength++) + { + anAsciiName->SetValue (aNameLength+1, IsAnAscii (aName.Value (aCharPos)) ? (Standard_Character )aName.Value (aCharPos) : '?'); + } + anIGESEntity->SetLabel (anAsciiName); + } + } + return Standard_True; } - //======================================================================= //function : SetColorMode //purpose : diff --git a/tests/bugs/xde/bug21802 b/tests/bugs/xde/bug21802 new file mode 100644 index 0000000000..c94af3a8ec --- /dev/null +++ b/tests/bugs/xde/bug21802 @@ -0,0 +1,25 @@ +puts "==========" +puts "OCC21802" +puts "==========" +puts "" +########################################################### +# Not all names are transferred from STEP to IGES via XDE +########################################################### + +ReadStep d [locate_data_file bug21802_as1-oc-214.stp] +catch {exec rm ${imagedir}/bug21802_as1-oc-214.igs} +WriteIges d ${imagedir}/bug21802_as1-oc-214.igs + +set is21802fixed "FALSE" +set file21802 [open ${imagedir}/bug21802_as1-oc-214.igs RDONLY] +while {[eof $file21802] == 0} { + set file21802line [string trim [gets $file21802]] + if {[string first "l-bracke" $file21802line] != -1} { + set is21802fixed "TRUE" + } +} +close $file21802 + +if {[string compare $is21802fixed "FALSE"] == 0} { + puts "ERROR: OCC21802 is reproduced" +}