]> 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)
committermsv <msv@opencascade.com>
Mon, 22 Nov 2021 08:56:57 +0000 (11:56 +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

index 30646bc99b8699733efd7b318b1b0709bb96ebad..ffb8091d985f2ea8c5bc878a948a52237f487608 100644 (file)
@@ -1387,36 +1387,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 ) ) {
@@ -1429,14 +1424,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 54295e103084f4473027d91ea4e530d67f60223f..f6d8c3c851f0cad679906a545a6d43678da701d7 100644 (file)
@@ -1464,15 +1464,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);
@@ -1496,20 +1496,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) );