diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index fa9b2069d9..aadce19df2 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -1411,37 +1411,32 @@ Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkS // get name Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString; - if ( ! GetLabelName (L, hName) ) continue; -// Handle(TDataStd_Name) N; -// if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) continue; -// TCollection_ExtendedString name = N->Get(); -// if ( name.Length() <=0 ) continue; + if (GetLabelName (L, hName)) + { + // find target STEP entity for the current shape + if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip + TopoDS_Shape S = myLabels.Find ( L ); - // find target STEP entity for the current shape -// TopoDS_Shape S; -// if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue; - if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip - TopoDS_Shape S = myLabels.Find ( L ); - - Handle(StepShape_ShapeDefinitionRepresentation) SDR; - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S ); - if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) { + Handle(StepShape_ShapeDefinitionRepresentation) SDR; + Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S ); + if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) { #ifdef OCCT_DEBUG - std::cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << std::endl; + std::cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << std::endl; #endif - continue; + continue; + } + + // set the name to the PRODUCT + Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition(); + if ( PropD.IsNull() ) continue; + Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition(); + if ( PD.IsNull() ) continue; + Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct(); + + Prod->SetId ( hName ); + Prod->SetName ( hName ); } - // set the name to the PRODUCT - Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition(); - if ( PropD.IsNull() ) continue; - Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition(); - if ( PD.IsNull() ) continue; - Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct(); - - Prod->SetId ( hName ); - Prod->SetName ( hName ); - // write names for components of assemblies if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) { TDF_LabelSequence seq; @@ -1453,14 +1448,14 @@ Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkS TDF_Label Lref; if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) || ! myLabels.IsBound ( Lref ) ) continue; - S = myLabels.Find ( Lref ); + TopoDS_Shape S = myLabels.Find ( Lref ); S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) ); hName = new TCollection_HAsciiString; if ( ! GetLabelName (lab, hName) ) continue; // find the target CDSR corresponding to a shape - mapper = TransferBRep::ShapeMapper ( FP, S ); + Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S ); Handle(Transfer_Binder) binder = FP->Find ( mapper ); Handle(StepShape_ContextDependentShapeRepresentation) CDSR; if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) ) diff --git a/src/STEPControl/STEPControl_ActorWrite.cxx b/src/STEPControl/STEPControl_ActorWrite.cxx index 43092ac3a7..e83fd17279 100644 --- a/src/STEPControl/STEPControl_ActorWrite.cxx +++ b/src/STEPControl/STEPControl_ActorWrite.cxx @@ -1466,15 +1466,15 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferSubShape // if shape itself not yet translated, do it now //:abv 20.05.02: see comment in TransferShape(): added "! iasdr ||" Handle(Transfer_Binder) resprod = TransientResult(sdr); //KA - OCC7141(skl 10.11.2004) + bool isJustTransferred = false; if ( ! iasdr || resbind.IsNull() ) { resbind = TransferShape(mapper, sdr, FP, shapeGroup, isManifold, theProgress); + if (resbind.IsNull()) + return resbind; Handle(Transfer_Binder) oldbind = FP->Find ( mapper ); if ( ! oldbind.IsNull() && !resbind.IsNull()) resbind->AddResult ( oldbind ); - FP->Bind (mapper,resbind); - resprod=resbind; //KA - OCC7141(skl 10.11.2004) + isJustTransferred = true; } - if (resprod.IsNull()) - return resprod; // A new resbind may have been produced // DeclareAndCast(Transfer_SimpleBinderOfTransient,restrans,resbind); @@ -1498,20 +1498,28 @@ Handle(Transfer_Binder) STEPControl_ActorWrite::TransferSubShape //KA: we need only the current subshape in resprod, since the binder is copied // in Transfershape which calls Transfersubshape [ OCC7141(skl 10.11.2004) ] if ( ! iasdr ) { - resprod->AddResult ( TransientResult ( SDRTool.SDRValue() ) ); - resbind->AddResult ( TransientResult ( SDRTool.SDRValue() ) ); //KA - OCC7141(skl 10.11.2004) + resprod->AddResult (TransientResult (sdr)); + if (resprod != resbind) + resbind->AddResult (TransientResult (sdr)); //KA - OCC7141(skl 10.11.2004) roots->Append ( myContext.GetRootsForPart ( SDRTool ) ); } for ( Standard_Integer i=1; i <= roots->Length(); i++ ) { resprod->AddResult ( TransientResult ( roots->Value(i) ) ); - resbind->AddResult ( TransientResult ( roots->Value(i) ) ); //KA - OCC7141(skl 10.11.2004) + if (resprod != resbind) + resbind->AddResult (TransientResult (roots->Value(i))); //KA - OCC7141(skl 10.11.2004) } + if (isJustTransferred) + { + // We make CDSR of the current shape preceding CDSR of any subshapes, + // therefore add resbind at the end. + resprod->AddResult (resbind); + FP->Bind (mapper, resprod); + } + myContext.NextIndex(); - //FP->Bind (mapper,resprod); //KA - OCC7141(skl 10.11.2004) - // abv 16.10.00: bind CDSR (et al) to located shape in order to be able to track instances - if ( mapper != start ) { + if (mapper != start && aLoc.Form() != gp_Identity) { Handle(Transfer_Binder) bnd = FP->Find ( start ); for ( Standard_Integer j=1; j <= roots->Length(); j++ ) if ( bnd.IsNull() ) bnd = TransientResult ( roots->Value(j) ); diff --git a/tests/bugs/step/bug32679 b/tests/bugs/step/bug32679 new file mode 100644 index 0000000000..55eb8310e7 --- /dev/null +++ b/tests/bugs/step/bug32679 @@ -0,0 +1,36 @@ +puts "====================================" +puts "0032679: Data Exchange - STEP writer loses assembly instance name" +puts "====================================" +puts "" + +pload OCAF + +proc CheckName {doc1 doc2 lab} { + upvar $doc1 d1 $doc2 d2 + puts "Checking name [set name1 [GetName d1 $lab]]" + if [catch {set name2 [GetName d2 $lab]}] { + puts "Error: name at label $lab is not found" + } + if {$name1 != $name2} { + puts "Error: at label $lab expected name $name1 but found $name2" + } +} + +proc RunTestWithFile {file} { + global imagedir + puts "Testing file $file" + XOpen [locate_data_file $file] d1 + WriteStep d1 ${imagedir}/${file}.step + ReadStep d2 ${imagedir}/${file}.step + + CheckName d1 d2 0:1:1:1:1 + CheckName d1 d2 0:1:1:2:1 + CheckName d1 d2 0:1:1:3:1 + + Close d1 + Close d2 + file delete ${imagedir}/${file}.step +} + +RunTestWithFile as1-no-ass-name.xbf +RunTestWithFile as1-with-ass-name.xbf