]> OCCT Git - occt.git/commitdiff
0032679: Data Exchange - STEP writer loses assembly instance name
authormsv <msv@opencascade.com>
Mon, 22 Nov 2021 00:28:24 +0000 (03:28 +0300)
committersmoskvin <smoskvin@opencascade.com>
Wed, 24 Nov 2021 21:35:25 +0000 (00:35 +0300)
In STEPCAFControl_Writer::WriteNames, write the names of components
even if the name of the assembly is absent.

In STEPControl_ActorWrite::TransferSubShape, move assembly structure
information to the beginning of the list of results, so that CDSR
information of this assembly became preceding CDSR of any sub shapes.

src/STEPCAFControl/STEPCAFControl_Writer.cxx
src/STEPControl/STEPControl_ActorWrite.cxx
tests/bugs/step/bug32679 [new file with mode: 0644]

index fa9b2069d9c1d46ccafbc5cec83e7d6295e21fde..aadce19df2e8a9850624baf7d15bdbb735f94ea4 100644 (file)
@@ -1411,36 +1411,31 @@ 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;
-
-    // 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 );
+    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 );
 
-    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();
+      // 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 );
+      Prod->SetId ( hName );
+      Prod->SetName ( hName );
+    }
 
     // write names for components of assemblies
     if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
@@ -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) ) 
index 43092ac3a7468c2377670f0915930050b00319e9..e83fd172790d2f9207faff67b356cb5832d695a7 100644 (file)
@@ -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)
+  myContext.NextIndex();
 
   // 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 (file)
index 0000000..55eb831
--- /dev/null
@@ -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