]> OCCT Git - occt.git/commitdiff
Revert "Data Exchange - Step supplemental geometry support (#744)" (#768)
authorPasukhin Dmitry <dpasukhi@opencascade.com>
Mon, 27 Oct 2025 19:18:53 +0000 (19:18 +0000)
committerGitHub <noreply@github.com>
Mon, 27 Oct 2025 19:18:53 +0000 (19:18 +0000)
This reverts commit 4ca8112dabbb17db668e28570c32f2eb2992080e.

src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Reader.cxx
src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Reader.hxx
src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Writer.cxx
src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Writer.hxx
src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc.cxx
src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc.hxx

index d89b7021a33b51e8831d16389564a0163854dbde..52e992b6fa995e1b3516267259042a46ae59efc1 100644 (file)
 #include <STEPCAFControl_Reader.hxx>
 
 #include <BRep_Builder.hxx>
-#include <BRepBuilderAPI_MakeEdge.hxx>
-#include <BRepBuilderAPI_MakeFace.hxx>
 #include <Geom_Axis2Placement.hxx>
 #include <Geom_CartesianPoint.hxx>
-#include <Geom_Line.hxx>
 #include <Geom_Plane.hxx>
 #include <Interface_EntityIterator.hxx>
 #include <StepData_StepModel.hxx>
@@ -61,7 +58,6 @@
 #include <STEPControl_ActorRead.hxx>
 #include <STEPControl_Reader.hxx>
 #include <StepGeom_Axis2Placement3d.hxx>
-#include <StepGeom_Curve.hxx>
 #include <StepGeom_Direction.hxx>
 #include <StepData_Factors.hxx>
 #include <StepDimTol_AngularityTolerance.hxx>
 #include <TColStd_SequenceOfHAsciiString.hxx>
 #include <TDataStd_Name.hxx>
 #include <TDataStd_TreeNode.hxx>
-#include <TDataStd_UAttribute.hxx>
 #include <TDF_Label.hxx>
 #include <TDF_Tool.hxx>
 #include <TDocStd_Document.hxx>
 #include <Transfer_TransientProcess.hxx>
 #include <TransferBRep.hxx>
 #include <UnitsMethods.hxx>
-#include <XCAFDoc.hxx>
 #include <XCAFDoc_Area.hxx>
 #include <XCAFDoc_Centroid.hxx>
 #include <XCAFDoc_ClippingPlaneTool.hxx>
 #include <StepRepr_ValueRepresentationItem.hxx>
 
 #include <TColgp_HArray1OfXYZ.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
 #include <Transfer_ActorOfTransientProcess.hxx>
 #include <Bnd_Box.hxx>
 #include <BRepBndLib.hxx>
@@ -1991,8 +1986,11 @@ Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(
     {
       if (style != aHSeqOfInvisStyle->Value(si))
         continue;
-
       // found that current style is invisible.
+#ifdef OCCT_DEBUG
+      std::cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name()
+                << ") is invisible" << std::endl;
+#endif
       IsVisible = Standard_False;
       break;
     }
@@ -2588,55 +2586,6 @@ void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
   return;
 }
 
-//==================================================================================================
-
-// Compute position of shape contains in the shapeAspect
-Standard_Boolean computePMIReferensePosition(const Handle(StepRepr_ShapeAspect)& theReference,
-                                             const Interface_Graph&              theGraph,
-                                             gp_Pnt&                             thePosition)
-{
-  if (theReference.IsNull())
-  {
-    return Standard_False;
-  }
-
-  Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
-  for (Interface_EntityIterator anIt = theGraph.Sharings(theReference);
-       anIt.More() && aGISU.IsNull();
-       anIt.Next())
-  {
-    aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
-  }
-  if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0)
-  {
-    return Standard_False;
-  }
-
-  // Retrieve point from GISU.
-  const Handle(StepRepr_RepresentationItem)& anItem = aGISU->IdentifiedItem()->Value(1);
-  Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(anItem);
-  if (aPoint.IsNull())
-  {
-    // try Axis2Placement3d.location instead of CartesianPoint
-    const Handle(StepGeom_Axis2Placement3d) anA2P3D =
-      Handle(StepGeom_Axis2Placement3d)::DownCast(anItem);
-    if (!anA2P3D.IsNull())
-    {
-      aPoint = anA2P3D->Location();
-    }
-  }
-
-  if (aPoint.IsNull())
-  {
-    return Standard_False;
-  }
-
-  thePosition.SetX(aPoint->CoordinatesValue(1));
-  thePosition.SetY(aPoint->CoordinatesValue(2));
-  thePosition.SetZ(aPoint->CoordinatesValue(3));
-  return Standard_True;
-}
-
 //=======================================================================
 // function : readConnectionPoints
 // purpose  : read connection points for given dimension
@@ -2676,33 +2625,109 @@ void readConnectionPoints(const Handle(XSControl_TransferReader)&          theTR
   if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
   {
     // retrieve derived geometry
-    const Handle(StepShape_DimensionalSize) aDim =
-      Handle(StepShape_DimensionalSize)::DownCast(theGDT);
-    gp_Pnt aPnt;
-    if (computePMIReferensePosition(aDim->AppliesTo(), aGraph, aPnt))
+    Handle(StepShape_DimensionalSize)   aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT);
+    Handle(StepRepr_DerivedShapeAspect) aDSA =
+      Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo());
+    if (aDSA.IsNull())
+      return;
+    Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL;
+    for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More();
+         anIt.Next())
     {
-      // set connection point to object
-      aPnt.SetXYZ(aPnt.XYZ() * aFact);
-      theDimObject->SetPoint(aPnt);
+      aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
+    }
+    if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0)
+      return;
+    Handle(StepGeom_CartesianPoint) aPoint =
+      Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1));
+    if (aPoint.IsNull())
+    {
+      // try Axis2Placement3d.location instead of CartesianPoint
+      Handle(StepGeom_Axis2Placement3d) anA2P3D =
+        Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1));
+      if (anA2P3D.IsNull())
+        return;
+      aPoint = anA2P3D->Location();
     }
+
+    // set connection point to object
+    gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact,
+                aPoint->CoordinatesValue(2) * aFact,
+                aPoint->CoordinatesValue(3) * aFact);
+    theDimObject->SetPoint(aPnt);
   }
   else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
   {
     // retrieve derived geometry
-    const Handle(StepShape_DimensionalLocation) aDim =
+    Handle(StepShape_DimensionalLocation) aDim =
       Handle(StepShape_DimensionalLocation)::DownCast(theGDT);
-    gp_Pnt aPnt;
-    if (computePMIReferensePosition(aDim->RelatingShapeAspect(), aGraph, aPnt))
+    Handle(StepRepr_DerivedShapeAspect) aDSA1 =
+      Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect());
+    Handle(StepRepr_DerivedShapeAspect) aDSA2 =
+      Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect());
+    if (aDSA1.IsNull() && aDSA2.IsNull())
+      return;
+    Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL;
+    Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL;
+    if (!aDSA1.IsNull())
     {
-      // set connection point to object
-      aPnt.SetXYZ(aPnt.XYZ() * aFact);
-      theDimObject->SetPoint(aPnt);
+      for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More();
+           anIt.Next())
+      {
+        aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
+      }
+    }
+    if (!aDSA2.IsNull())
+    {
+      for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More();
+           anIt.Next())
+      {
+        aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
+      }
+    }
+    // first point
+    if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0)
+    {
+      Handle(StepGeom_CartesianPoint) aPoint =
+        Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1));
+      if (aPoint.IsNull())
+      {
+        // try Axis2Placement3d.location instead of CartesianPoint
+        Handle(StepGeom_Axis2Placement3d) anA2P3D =
+          Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1));
+        if (!anA2P3D.IsNull())
+          aPoint = anA2P3D->Location();
+      }
+      if (!aPoint.IsNull())
+      {
+        // set connection point to object
+        gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact,
+                    aPoint->CoordinatesValue(2) * aFact,
+                    aPoint->CoordinatesValue(3) * aFact);
+        theDimObject->SetPoint(aPnt);
+      }
     }
-    if (computePMIReferensePosition(aDim->RelatedShapeAspect(), aGraph, aPnt))
+    // second point
+    if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0)
     {
-      // set connection point to object
-      aPnt.SetXYZ(aPnt.XYZ() * aFact);
-      theDimObject->SetPoint2(aPnt);
+      Handle(StepGeom_CartesianPoint) aPoint =
+        Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1));
+      if (aPoint.IsNull())
+      {
+        // try Axis2Placement3d.location instead of CartesianPoint
+        Handle(StepGeom_Axis2Placement3d) anA2P3D =
+          Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1));
+        if (!anA2P3D.IsNull())
+          aPoint = anA2P3D->Location();
+      }
+      if (!aPoint.IsNull())
+      {
+        // set connection point to object
+        gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact,
+                    aPoint->CoordinatesValue(2) * aFact,
+                    aPoint->CoordinatesValue(3) * aFact);
+        theDimObject->SetPoint2(aPnt);
+      }
     }
   }
 }
@@ -3557,7 +3582,18 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
                   Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem);
                   if (!VR.IsNull())
                   {
-                    aName                                             = VR->Name();
+                    aName = VR->Name();
+                    // StepRepr_CompoundItemDefinition CID = VR->ItemElement();
+                    // if(CID.IsNull()) continue;
+                    // Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
+                    //   Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
+                    // if(CIDM.IsNull()) continue;
+                    // if(CIDM->ArrTransient().IsNull()) continue;
+                    // Handle(StepRepr_HArray1OfRepresentationItem) HARI;
+                    // if(CID.CaseMem(CIDM)==1)
+                    //   HARI = CID.ListRepresentationItem();
+                    // if(CID.CaseMem(CIDM)==2)
+                    //   HARI = CID.SetRepresentationItem();
                     Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
                     if (HARI.IsNull())
                       continue;
@@ -3611,6 +3647,7 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
               continue;
             if (dim2 < 0)
               dim2 = dim1;
+            // std::cout<<"DimensionalSize: dim1="<<dim1<<"  dim2="<<dim2<<std::endl;
             //  now we know edge_curve and value range therefore
             //  we can create corresponding D&GT labels
             Standard_Integer index = aTP->MapIndex(EC);
@@ -3777,20 +3814,38 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
   if (aSeqRI1.IsEmpty())
     return aGDTL;
 
+  TDF_LabelSequence aShLS1, aShLS2;
+
   // Collect shapes
-  TDF_LabelSequence aShLS1;
-  for (NCollection_Sequence<Handle(Standard_Transient)>::Iterator anIter1(aSeqRI1); anIter1.More();
-       anIter1.Next())
-  {
-    findReferenceGeometry(anIter1.Value(), aSTool, aShLS1, theLocalFactors);
-  }
-  TDF_LabelSequence aShLS2;
-  for (NCollection_Sequence<Handle(Standard_Transient)>::Iterator anIter2(aSeqRI2); anIter2.More();
-       anIter2.Next())
+  for (Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper(); i++)
   {
-    findReferenceGeometry(anIter2.Value(), aSTool, aShLS2, theLocalFactors);
+    Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS);
+    TopoDS_Shape     aSh;
+    if (anIndex > 0)
+    {
+      Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
+      aSh                             = TransferBRep::ShapeResult(aBinder);
+    }
+    if (!aSh.IsNull())
+    {
+      TDF_Label aShL;
+      aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
+      if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
+      {
+        TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
+        while (ex.More())
+        {
+          TDF_Label edgeL;
+          aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
+          if (!edgeL.IsNull())
+            aShLS1.Append(edgeL);
+          ex.Next();
+        }
+      }
+      if (!aShL.IsNull())
+        aShLS1.Append(aShL);
+    }
   }
-
   if (!aSeqRI2.IsEmpty())
   {
     // for dimensional location
@@ -3883,197 +3938,6 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
   return aGDTL;
 }
 
-//==================================================================================================
-
-Standard_Boolean STEPCAFControl_Reader::findReferenceGeometry(
-  const Handle(Standard_Transient)& theShapeStart,
-  const Handle(XCAFDoc_ShapeTool)&  theShTool,
-  TDF_LabelSequence&                theShLabelSeq,
-  const StepData_Factors&           theLocalFactors)
-{
-  const Handle(XSControl_TransferReader)&  aTransferReader   = myReader.WS()->TransferReader();
-  const Handle(Transfer_TransientProcess)& aTransientProcess = aTransferReader->TransientProcess();
-  TopoDS_Shape aShape = TransferBRep::ShapeResult(aTransientProcess, theShapeStart);
-  if (!aShape.IsNull())
-  {
-    TDF_Label aShapeLabel;
-    theShTool->Search(aShape, aShapeLabel, Standard_True, Standard_True, Standard_True);
-    if (aShapeLabel.IsNull() && aShape.ShapeType() == TopAbs_WIRE)
-    {
-      for (TopExp_Explorer anExp(aShape, TopAbs_EDGE, TopAbs_SHAPE); anExp.More(); anExp.Next())
-      {
-        TDF_Label anEdgeLabel;
-        theShTool->Search(anExp.Current(),
-                          anEdgeLabel,
-                          Standard_True,
-                          Standard_True,
-                          Standard_True);
-        if (!anEdgeLabel.IsNull())
-        {
-          theShLabelSeq.Append(anEdgeLabel);
-        }
-      }
-    }
-    if (!aShapeLabel.IsNull())
-    {
-      theShLabelSeq.Append(aShapeLabel);
-      return Standard_True;
-    }
-  }
-
-  TDF_Label aFindResultL;
-  if (myGDTMap.Find(theShapeStart, aFindResultL))
-  {
-    theShLabelSeq.Append(aFindResultL);
-    return Standard_True;
-  }
-
-  const Handle(StepGeom_GeometricRepresentationItem)& aGeomItem =
-    Handle(StepGeom_GeometricRepresentationItem)::DownCast(theShapeStart);
-  if (aGeomItem.IsNull())
-  {
-    return Standard_False;
-  }
-
-  if (theShapeStart->IsKind(STANDARD_TYPE(StepGeom_Curve)))
-  {
-    const Handle(StepGeom_Curve)& aStepCurve = Handle(StepGeom_Curve)::DownCast(theShapeStart);
-    Handle(Geom_Curve)            aCurve     = StepToGeom::MakeCurve(aStepCurve, theLocalFactors);
-    if (aCurve.IsNull())
-    {
-      return Standard_False;
-    }
-
-    BRepBuilderAPI_MakeEdge aMaker;
-    if (aCurve->IsKind(STANDARD_TYPE(Geom_Line)))
-    {
-      const Standard_Real aScale = theLocalFactors.LengthFactor();
-      aMaker.Init(aCurve, 0, 1. * aScale);
-    }
-    else
-    {
-      aMaker.Init(aCurve);
-    }
-    if (aMaker.IsDone())
-    {
-      aShape = aMaker.Shape();
-    }
-  }
-  else if (theShapeStart->IsKind(STANDARD_TYPE(StepGeom_Surface)))
-  {
-    const Handle(StepGeom_Surface)& aStepSurface =
-      Handle(StepGeom_Surface)::DownCast(theShapeStart);
-    Handle(Geom_Surface) aSurface = StepToGeom::MakeSurface(aStepSurface, theLocalFactors);
-    if (aSurface.IsNull())
-    {
-      return Standard_False;
-    }
-    BRepBuilderAPI_MakeFace aMaker;
-    if (aSurface->IsKind(STANDARD_TYPE(Geom_Plane)))
-    {
-      const Standard_Real aScale = theLocalFactors.LengthFactor();
-      aMaker.Init(aSurface, 0., 1. * aScale, 0., 1. * aScale, Precision::Confusion());
-    }
-    else
-    {
-      aMaker.Init(aSurface, Standard_True, Precision::Confusion());
-    }
-    if (aMaker.IsDone())
-    {
-      aShape = aMaker.Shape();
-    }
-  }
-  if (aShape.IsNull())
-  {
-    return Standard_False;
-  }
-
-  if (mySupplementalLabel.IsNull())
-  {
-    mySupplementalLabel = theShTool->NewShape();
-    TDataStd_Name::Set(mySupplementalLabel, "Supplemental Geometry");
-    TDataStd_UAttribute::Set(mySupplementalLabel, XCAFDoc::SupplementalContainerGUID());
-  }
-  TDF_Label aSupGeomLabel = theShTool->AddComponent(mySupplementalLabel, aShape);
-  if (aSupGeomLabel.IsNull())
-  {
-    return Standard_False;
-  }
-
-  TDataStd_UAttribute::Set(aSupGeomLabel, XCAFDoc::SupplementalGeometryGUID());
-
-  if (!aGeomItem->Name().IsNull())
-  {
-    TDataStd_Name::Set(aSupGeomLabel, aGeomItem->Name()->String());
-    TDF_Label aReferredShapeL;
-    theShTool->GetReferredShape(aSupGeomLabel, aReferredShapeL);
-    TDataStd_Name::Set(aReferredShapeL, aGeomItem->Name()->String());
-    TDataStd_UAttribute::Set(aReferredShapeL, XCAFDoc::SupplementalGeometryGUID());
-  }
-  TDF_Label              aRefLabel;
-  const Interface_Graph& aGraph = aTransientProcess->Graph();
-  for (Interface_EntityIterator anIter(aGraph.Sharings(theShapeStart));
-       anIter.More() && aRefLabel.IsNull();
-       anIter.Next())
-  {
-    Handle(StepAP242_GeometricItemSpecificUsage) aPGISU =
-      Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
-    if (aPGISU.IsNull())
-    {
-      continue;
-    }
-    Handle(StepRepr_ShapeAspect) aShAspect = aPGISU->Definition().ShapeAspect();
-    if (aShAspect.IsNull())
-    {
-      continue;
-    }
-    Handle(StepRepr_ProductDefinitionShape) aRefPDS = aShAspect->OfShape();
-    if (aRefPDS.IsNull())
-    {
-      continue;
-    }
-    const TopoDS_Shape aRefShape =
-      TransferBRep::ShapeResult(aTransientProcess, aRefPDS->Definition().Value());
-    theShTool->Search(aRefShape, aRefLabel, Standard_True, Standard_True, Standard_False);
-  }
-
-  if (aRefLabel.IsNull())
-  {
-    TDF_LabelSequence aFreeShapes;
-    theShTool->GetFreeShapes(aFreeShapes);
-    for (TDF_LabelSequence::Iterator anIter(aFreeShapes); anIter.More() && aRefLabel.IsNull();
-         anIter.Next())
-    {
-      const TDF_Label             aLabel = anIter.Value();
-      Handle(TDataStd_UAttribute) aSupGeomAttr;
-      if (aLabel.FindAttribute(XCAFDoc::SupplementalContainerGUID(), aSupGeomAttr))
-      {
-        continue;
-      }
-      TopoDS_Shape aTmpShape = theShTool->GetShape(aLabel);
-      if (!aTmpShape.IsNull())
-      {
-        aRefLabel = aLabel;
-      }
-    }
-  }
-  if (aRefLabel.IsNull())
-  {
-    return Standard_False;
-  }
-
-  // set reference
-  Handle(TDataStd_TreeNode) aMainNode =
-    TDataStd_TreeNode::Set(aRefLabel, XCAFDoc::SupplementalRefGUID());
-  Handle(TDataStd_TreeNode) aRefNode =
-    TDataStd_TreeNode::Set(aSupGeomLabel, XCAFDoc::SupplementalRefGUID());
-  aRefNode->Remove(); // abv: fix against bug in TreeNode::Append()
-  aMainNode->Append(aRefNode);
-  myGDTMap.Bind(theShapeStart, aSupGeomLabel);
-  theShLabelSeq.Append(aSupGeomLabel);
-  return Standard_True;
-}
-
 //=================================================================================================
 
 void convertAngleValue(const STEPConstruct_UnitContext& anUnitCtx, Standard_Real& aVal)
index ea69184d979386f9588f79bbc488eeab64784f07..85bebe97ba4a044783ae08fc723ab1f4623ed551 100644 (file)
@@ -427,17 +427,6 @@ private:
                                   const Handle(XSControl_WorkSession)& theWS,
                                   const StepData_Factors& theLocalFactors = StepData_Factors());
 
-  //! Finds reference geometry or create supplemental geometry label
-  //! @param[in] theShapeStart step entity to get reference
-  //! @param[in] theShTool tool to work with shape labels
-  //! @param[out] theShLabelSeq container to put reference label
-  //! @param[in] theLocalFactors structure to calculate units.
-  //! @return TRUE if a reference is found or supplemental geometry is added
-  Standard_Boolean findReferenceGeometry(const Handle(Standard_Transient)& theShapeStart,
-                                         const Handle(XCAFDoc_ShapeTool)&  theShTool,
-                                         TDF_LabelSequence&                theShLabelSeq,
-                                         const StepData_Factors&           theLocalFactors);
-
   //! Prepares units for transfer
   void prepareUnits(const Handle(StepData_StepModel)& theModel,
                     const Handle(TDocStd_Document)&   theDoc,
@@ -515,18 +504,17 @@ private:
   STEPControl_Reader                                                              myReader;
   NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;
   XCAFDoc_DataMapOfShapeLabel                                                     myMap;
-  TDF_Label                                                  mySupplementalLabel;
-  Standard_Boolean                                           myColorMode;
-  Standard_Boolean                                           myNameMode;
-  Standard_Boolean                                           myLayerMode;
-  Standard_Boolean                                           myPropsMode;
-  Standard_Boolean                                           myMetaMode;
-  Standard_Boolean                                           myProductMetaMode;
-  Standard_Boolean                                           mySHUOMode;
-  Standard_Boolean                                           myGDTMode;
-  Standard_Boolean                                           myMatMode;
-  Standard_Boolean                                           myViewMode;
-  NCollection_DataMap<Handle(Standard_Transient), TDF_Label> myGDTMap;
+  Standard_Boolean                                                                myColorMode;
+  Standard_Boolean                                                                myNameMode;
+  Standard_Boolean                                                                myLayerMode;
+  Standard_Boolean                                                                myPropsMode;
+  Standard_Boolean                                                                myMetaMode;
+  Standard_Boolean                                                                myProductMetaMode;
+  Standard_Boolean                                                                mySHUOMode;
+  Standard_Boolean                                                                myGDTMode;
+  Standard_Boolean                                                                myMatMode;
+  Standard_Boolean                                                                myViewMode;
+  NCollection_DataMap<Handle(Standard_Transient), TDF_Label>                      myGDTMap;
 };
 
 #endif // _STEPCAFControl_Reader_HeaderFile
index fc2ed7ed3f17ff7abb8955182c5e445804523e68..9d89fd2d3dba3c7bf72b4efc5d80972f156cf5da 100644 (file)
@@ -25,8 +25,6 @@
 #include <BRep_Builder.hxx>
 #include <GeomToStep_MakeAxis2Placement3d.hxx>
 #include <GeomToStep_MakeCartesianPoint.hxx>
-#include <GeomToStep_MakeCurve.hxx>
-#include <GeomToStep_MakeSurface.hxx>
 #include <HeaderSection_FileSchema.hxx>
 #include <Interface_EntityIterator.hxx>
 #include <Interface_Static.hxx>
@@ -96,7 +94,6 @@
 #include <StepDimTol_TotalRunoutTolerance.hxx>
 #include <StepGeom_Axis2Placement3d.hxx>
 #include <StepGeom_CartesianPoint.hxx>
-#include <StepGeom_Curve.hxx>
 #include <StepGeom_Direction.hxx>
 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
 #include <TDF_Label.hxx>
 #include <TDF_LabelSequence.hxx>
 #include <TDocStd_Document.hxx>
-#include <TopoDS.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS_Shape.hxx>
 #include <XSControl_WorkSession.hxx>
 #include <UnitsMethods.hxx>
 
-namespace
-{
-// Auxiliary function: take name of label and append it to str
+//=======================================================================
+// function : GetLabelName
+// purpose  : auxiliary function: take name of label and append it to str
+//=======================================================================
 static Standard_Boolean GetLabelName(const TDF_Label&                  theL,
                                      Handle(TCollection_HAsciiString)& theStr)
 {
@@ -247,1915 +244,2114 @@ static Standard_Boolean GetLabelName(const TDF_Label&                  theL,
   return Standard_True;
 }
 
-//==================================================================================================
+//=================================================================================================
 
-static Standard_Integer FindEntities(const Handle(Transfer_FinderProcess)& theFP,
-                                     const TopoDS_Shape&                   theShape,
-                                     TopLoc_Location&                      theLocation,
-                                     TColStd_SequenceOfTransient&          theSeqRI)
+STEPCAFControl_Writer::STEPCAFControl_Writer()
+    : myColorMode(Standard_True),
+      myNameMode(Standard_True),
+      myLayerMode(Standard_True),
+      myPropsMode(Standard_True),
+      myMetadataMode(Standard_True),
+      mySHUOMode(Standard_True),
+      myGDTMode(Standard_True),
+      myMatMode(Standard_True),
+      myVisMatMode(Standard_False),
+      myIsCleanDuplicates(Standard_False)
 {
-  Handle(StepRepr_RepresentationItem) anItem =
-    STEPConstruct::FindEntity(theFP, theShape, theLocation);
+  STEPCAFControl_Controller::Init();
+  Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession;
+  Init(aWS);
+}
 
-  if (!anItem.IsNull())
-  {
-    theSeqRI.Append(anItem);
-    return 1;
-  }
+//=================================================================================================
 
-  // may be S was split during shape processing
-  Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(theFP, theShape);
-  Handle(Transfer_Binder)          aBinder = theFP->Find(aMapper);
-  if (aBinder.IsNull())
-    return 0;
+STEPCAFControl_Writer::STEPCAFControl_Writer(const Handle(XSControl_WorkSession)& theWS,
+                                             const Standard_Boolean               theScratch)
+    : myColorMode(Standard_True),
+      myNameMode(Standard_True),
+      myLayerMode(Standard_True),
+      myPropsMode(Standard_True),
+      myMetadataMode(Standard_True),
+      mySHUOMode(Standard_True),
+      myGDTMode(Standard_True),
+      myMatMode(Standard_True),
+      myVisMatMode(Standard_False),
+      myIsCleanDuplicates(Standard_False)
+{
+  STEPCAFControl_Controller::Init();
+  Init(theWS, theScratch);
+}
 
-  Handle(Transfer_TransientListBinder) aTransientListBinder =
-    // Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
-    Handle(Transfer_TransientListBinder)::DownCast(aBinder);
-  Standard_Integer aResCount = 0;
-  if (aTransientListBinder.IsNull())
-  {
-    for (TopoDS_Iterator anIter(theShape); anIter.More(); anIter.Next())
-    {
-      Handle(StepRepr_RepresentationItem) aLocalItem =
-        STEPConstruct::FindEntity(theFP, anIter.Value(), theLocation);
-      if (aLocalItem.IsNull())
-        continue;
-      aResCount++;
-      theSeqRI.Append(aLocalItem);
-    }
-  }
-  else if (!aTransientListBinder.IsNull())
-  {
-    const Standard_Integer aNbTransient = aTransientListBinder->NbTransients();
-    for (Standard_Integer anInd = 1; anInd <= aNbTransient; anInd++)
-    {
-      Handle(Standard_Transient) anEntity = aTransientListBinder->Transient(anInd);
-      anItem                              = Handle(StepRepr_RepresentationItem)::DownCast(anEntity);
-      if (anItem.IsNull())
-        continue;
-      aResCount++;
-      theSeqRI.Append(anItem);
-    }
-  }
-  return aResCount;
+//=================================================================================================
+
+void STEPCAFControl_Writer::Init(const Handle(XSControl_WorkSession)& theWS,
+                                 const Standard_Boolean               theScratch)
+{
+  theWS->SelectNorm("STEP");
+  myWriter.SetWS(theWS, theScratch);
+  myFiles.Clear();
+  myLabEF.Clear();
+  myLabels.Clear();
+  myPureRefLabels.Clear();
+  myRootLabels.Clear();
+  myGDTPresentationDM = new StepVisual_DraughtingModel();
+  myGDTPrsCurveStyle  = new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
 }
 
-//==================================================================================================
+//=================================================================================================
 
-static Standard_Boolean getStyledItem(const TopoDS_Shape&                     theShape,
-                                      const Handle(XCAFDoc_ShapeTool)&        theShapeTool,
-                                      const STEPConstruct_Styles&             theStyles,
-                                      Handle(StepVisual_StyledItem)&          theResSelItem,
-                                      const MoniTool_DataMapOfShapeTransient& theMapCompMDGPR)
+IFSelect_ReturnStatus STEPCAFControl_Writer::Write(const Standard_CString theFileName)
 {
-  const TDF_Label  aTopShL   = theShapeTool->FindShape(theShape, Standard_False);
-  TopoDS_Shape     aTopLevSh = theShapeTool->GetShape(aTopShL);
-  Standard_Boolean anIsFound = Standard_False;
-  if (aTopLevSh.IsNull() || !theMapCompMDGPR.IsBound(aTopLevSh))
+  if (myIsCleanDuplicates)
   {
-    return Standard_False;
+    // remove duplicates
+    myWriter.CleanDuplicateEntities();
   }
-  Handle(StepVisual_PresentationRepresentation) aMDGPR =
-    Handle(StepVisual_PresentationRepresentation)::DownCast(theMapCompMDGPR.Find(aTopLevSh));
-  Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
-  if (anSelItmHArr.IsNull())
+
+  IFSelect_ReturnStatus aStatus = myWriter.Write(theFileName);
+  if (aStatus != IFSelect_RetDone)
   {
-    return Standard_False;
+    return aStatus;
   }
-  // Search for PSA of Manifold solid
-  TColStd_SequenceOfTransient aNewSeqRI;
-  Standard_Boolean            isFilled = Standard_False;
-  for (StepRepr_HArray1OfRepresentationItem::Iterator anIter(anSelItmHArr->Array1());
-       anIter.More() && !anIsFound;
-       anIter.Next())
+
+  // get directory name of the main file
+  TCollection_AsciiString aDirPath;
   {
-    const Handle(StepVisual_StyledItem)& aSelItm =
-      Handle(StepVisual_StyledItem)::DownCast(anIter.Value());
+    OSD_Path aMainFile(theFileName);
+    aMainFile.SetName("");
+    aMainFile.SetExtension("");
+    aMainFile.SystemName(aDirPath);
+  }
 
-    if (aSelItm.IsNull())
+  for (NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator
+         anExtFileIter(myFiles);
+       anExtFileIter.More();
+       anExtFileIter.Next())
+  {
+    const Handle(STEPCAFControl_ExternFile)& anExtFile = anExtFileIter.Value();
+    if (anExtFile->GetWriteStatus() != IFSelect_RetVoid)
     {
       continue;
     }
-    // Check that it is a styled item for manifold solid brep
-    if (!isFilled)
-    {
-      TopLoc_Location aLoc;
-      FindEntities(theStyles.FinderProcess(), aTopLevSh, aLoc, aNewSeqRI);
-      isFilled = Standard_True;
-    }
-    if (!aNewSeqRI.IsEmpty())
+
+    // construct extern file name
+    TCollection_AsciiString aFileName =
+      OSD_Path::AbsolutePath(aDirPath, anExtFile->GetName()->String());
+    if (aFileName.Length() <= 0)
     {
-      const Handle(StepRepr_RepresentationItem)& anItem         = aSelItm->Item();
-      Standard_Boolean                           isSameMonSolBR = Standard_False;
-      for (TColStd_SequenceOfTransient::Iterator aIterRI(aNewSeqRI); aIterRI.More(); aIterRI.Next())
-      {
-        if (!anItem.IsNull() && anItem == aIterRI.Value())
-        {
-          isSameMonSolBR = Standard_True;
-          break;
-        }
-      }
-      if (!isSameMonSolBR)
-        continue;
+      aFileName = anExtFile->GetName()->String();
     }
-    for (StepVisual_HArray1OfPresentationStyleAssignment::Iterator aStyleIter(
-           aSelItm->Styles()->Array1());
-         aStyleIter.More() && !anIsFound;
-         aStyleIter.Next())
+    Message::SendTrace() << "Writing external file: " << aFileName << "\n";
+
+    const IFSelect_ReturnStatus anExtStatus = anExtFile->GetWS()->SendAll(aFileName.ToCString());
+    anExtFile->SetWriteStatus(anExtStatus);
+    if (anExtStatus != IFSelect_RetDone)
     {
-      const Handle(StepVisual_PresentationStyleAssignment)& aFatherPSA = aStyleIter.Value();
-      // check for PSA for top-level (not Presentation style by context for NAUO)
-      if (aFatherPSA.IsNull()
-          || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
-        continue;
-      theResSelItem = aSelItm;
-      anIsFound     = Standard_True;
+      aStatus = anExtStatus;
     }
   }
-  return anIsFound;
+
+  return aStatus;
 }
 
-//==================================================================================================
+//=================================================================================================
 
-static Standard_Boolean setDefaultInstanceColor(
-  const Handle(StepVisual_StyledItem)&            theStyleItem,
-  Handle(StepVisual_PresentationStyleAssignment)& thePSA)
+void STEPCAFControl_Writer::prepareUnit(const TDF_Label&                  theLabel,
+                                        const Handle(StepData_StepModel)& theModel,
+                                        StepData_Factors&                 theLocalFactors)
 {
-  Standard_Boolean anIsFound = Standard_False;
-  for (StepVisual_HArray1OfPresentationStyleAssignment::Iterator aStyleIter(
-         theStyleItem->Styles()->Array1());
-       aStyleIter.More() && !anIsFound;
-       aStyleIter.Next())
+  Handle(XCAFDoc_LengthUnit) aLengthAttr;
+  if (!theLabel.IsNull() && theLabel.Root().FindAttribute(XCAFDoc_LengthUnit::GetID(), aLengthAttr))
   {
-    const Handle(StepVisual_PresentationStyleAssignment)& aFatherPSA = aStyleIter.Value();
-    // check for PSA for top-level (not Presentation style by context for NAUO)
-    if (aFatherPSA.IsNull()
-        || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
-      return Standard_False;
-
-    // get style select from father PSA
-    if (aFatherPSA->NbStyles() > 0)
-    {
-      Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
-        new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
-      Standard_Integer aSettingInd = 1;
-      for (StepVisual_HArray1OfPresentationStyleSelect::Iterator aFatherStyleIter(
-             aFatherPSA->Styles()->Array1());
-           aFatherStyleIter.More();
-           aFatherStyleIter.Next())
-      {
-        StepVisual_PresentationStyleSelect        aPSS;
-        const StepVisual_PresentationStyleSelect& anOlDPSS = aFatherStyleIter.Value();
-        if (!anOlDPSS.PointStyle().IsNull())
-          aPSS.SetValue(anOlDPSS.PointStyle());
-        else if (!anOlDPSS.CurveStyle().IsNull())
-          aPSS.SetValue(anOlDPSS.CurveStyle());
-        else if (!anOlDPSS.SurfaceStyleUsage().IsNull())
-          aPSS.SetValue(anOlDPSS.SurfaceStyleUsage());
-        else
-        {
-          anIsFound = Standard_False;
-          break;
-        }
-        aFatherStyles->SetValue(aSettingInd++, anOlDPSS);
-        anIsFound = Standard_True;
-      }
-      // init PSA of NAUO
-      if (anIsFound)
-      {
-        thePSA->Init(aFatherStyles);
-      }
-    }
+    theModel->SetLocalLengthUnit(aLengthAttr->GetUnitValue() * 1000); // convert to mm
+    theLocalFactors.SetCascadeUnit(aLengthAttr->GetUnitValue() * 1000);
+  }
+  else
+  {
+    XSAlgo_ShapeProcessor::PrepareForTransfer(); // update unit info
+    theModel->SetLocalLengthUnit(UnitsMethods::GetCasCadeLengthUnit());
+    theLocalFactors.SetCascadeUnit(UnitsMethods::GetCasCadeLengthUnit());
   }
-  return anIsFound;
 }
 
-//==================================================================================================
+//=================================================================================================
 
-static void MakeSTEPStyles(STEPConstruct_Styles&                        theStyles,
-                           const TopoDS_Shape&                          theShape,
-                           const XCAFPrs_IndexedDataMapOfShapeStyle&    theSettings,
-                           Handle(StepVisual_StyledItem)&               theOverride,
-                           TopTools_MapOfShape&                         theMap,
-                           const MoniTool_DataMapOfShapeTransient&      theMapCompMDGPR,
-                           STEPConstruct_DataMapOfAsciiStringTransient& theDPDCs,
-                           STEPConstruct_DataMapOfPointTransient&       theColRGBs,
-                           const Handle(XCAFDoc_ShapeTool)&             theShTool,
-                           const XCAFPrs_Style*                         theInherit,
-                           const Standard_Boolean                       theIsComponent,
-                           const Standard_Boolean                       theVisMaterialMode)
+IFSelect_ReturnStatus STEPCAFControl_Writer::WriteStream(std::ostream& theStream)
 {
-  // skip already processed shapes
-  if (!theMap.Add(theShape))
-    return;
-
-  // check if shape has its own style (r inherits from ancestor)
-  XCAFPrs_Style aStyle;
-  if (theInherit)
-    aStyle = *theInherit;
-  if (theSettings.Contains(theShape))
+  if (!myFiles.IsEmpty())
   {
-    const XCAFPrs_Style& anOwnStyle = theSettings.FindFromKey(theShape);
-    if (!anOwnStyle.IsVisible())
-      aStyle.SetVisibility(Standard_False);
-    if (anOwnStyle.IsSetColorCurv())
-      aStyle.SetColorCurv(anOwnStyle.GetColorCurv());
-    if (anOwnStyle.IsSetColorSurf())
-      aStyle.SetColorSurf(anOwnStyle.GetColorSurfRGBA());
-    if (!anOwnStyle.Material().IsNull())
-      aStyle.SetMaterial(anOwnStyle.Material());
+    // writing external files is unsupported via stream interface
+    return IFSelect_RetError;
   }
 
-  // translate colors to STEP
-  Handle(StepVisual_Colour) aSurfColor, aCurvColor;
-  Standard_Real             aRenderTransp = 0.0;
-  if (aStyle.IsSetColorSurf())
-  {
-    Quantity_ColorRGBA aSurfCol = aStyle.GetColorSurfRGBA();
-    aRenderTransp               = 1.0 - aSurfCol.Alpha();
-    aSurfColor                  = theStyles.EncodeColor(aSurfCol.GetRGB(), theDPDCs, theColRGBs);
-  }
-  if (aStyle.IsSetColorCurv())
-    aCurvColor = theStyles.EncodeColor(aStyle.GetColorCurv(), theDPDCs, theColRGBs);
+  return myWriter.WriteStream(theStream);
+}
 
-  Standard_Boolean aHasOwn = (!aSurfColor.IsNull() || !aCurvColor.IsNull() || !aStyle.IsVisible());
+//=================================================================================================
 
-  // find target item and assign style to it
-  Handle(StepVisual_StyledItem) aSTEPstyle = theOverride;
-  if (aHasOwn)
-  {
-    if (theShape.ShapeType() != TopAbs_COMPOUND || theIsComponent)
-    { // skip compounds, let subshapes inherit its colors
-      TopLoc_Location             aLocation;
-      TColStd_SequenceOfTransient aSeqRI;
-      Standard_Integer            aNbEntities =
-        FindEntities(theStyles.FinderProcess(), theShape, aLocation, aSeqRI);
-      if (aNbEntities <= 0)
-        Message::SendTrace() << "Warning: Cannot find RI for "
-                             << theShape.TShape()->DynamicType()->Name() << "\n";
-      // Get overridden style gka 10.06.03
-      if (theIsComponent && aNbEntities > 0)
-        getStyledItem(theShape, theShTool, theStyles, theOverride, theMapCompMDGPR);
+Standard_Boolean STEPCAFControl_Writer::Transfer(const Handle(TDocStd_Document)& theDoc,
+                                                 const STEPControl_StepModelType theMode,
+                                                 const Standard_CString          theMulti,
+                                                 const Message_ProgressRange&    theProgress)
+{
+  const Handle(StepData_StepModel) aModel =
+    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
+  aModel->InternalParameters.InitFromStatic();
+  return Transfer(theDoc, aModel->InternalParameters, theMode, theMulti, theProgress);
+}
 
-      for (TColStd_SequenceOfTransient::Iterator anEntIter(aSeqRI); anEntIter.More();
-           anEntIter.Next())
-      {
-        const Handle(StepRepr_RepresentationItem)& anItem =
-          Handle(StepRepr_RepresentationItem)::DownCast(anEntIter.Value());
-        Handle(StepVisual_PresentationStyleAssignment) aPSA;
-        if (aStyle.IsVisible() || !aSurfColor.IsNull() || !aCurvColor.IsNull()
-            || (theVisMaterialMode && !aStyle.Material().IsNull() && !aStyle.Material()->IsEmpty()))
-        {
-          STEPConstruct_RenderingProperties aRenderProps;
-          if (theVisMaterialMode && !aStyle.Material().IsNull() && !aStyle.Material()->IsEmpty())
-          {
-            aRenderProps.Init(aStyle.Material());
-          }
-          else if (aRenderTransp > 0.0)
-          {
-            aRenderProps.Init(aStyle.GetColorSurfRGBA());
-          }
-          aPSA =
-            theStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aRenderProps, theIsComponent);
-        }
-        else
-        {
-          // default white color
-          aSurfColor =
-            theStyles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE), theDPDCs, theColRGBs);
-          aPSA = theStyles.MakeColorPSA(anItem,
-                                        aSurfColor,
-                                        aCurvColor,
-                                        STEPConstruct_RenderingProperties(),
-                                        theIsComponent);
-          if (theIsComponent)
-            setDefaultInstanceColor(theOverride, aPSA);
+//=================================================================================================
 
-        } // end of component case
+Standard_Boolean STEPCAFControl_Writer::Transfer(const Handle(TDocStd_Document)& theDoc,
+                                                 const DESTEP_Parameters&        theParams,
+                                                 const STEPControl_StepModelType theMode,
+                                                 const Standard_CString          theMulti,
+                                                 const Message_ProgressRange&    theProgress)
+{
+  Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
+  if (aShTool.IsNull())
+    return Standard_False;
 
-        aSTEPstyle = theStyles.AddStyle(anItem, aPSA, theOverride);
-        aHasOwn    = Standard_False;
-      }
-    }
-  }
+  myRootLabels.Clear();
+  myRootLabels.Add(theDoc->Main().Root());
+  TDF_LabelSequence aLabels;
+  aShTool->GetFreeShapes(aLabels);
+  const Handle(StepData_StepModel) aModel =
+    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
+  aModel->InternalParameters = theParams;
+  return transfer(myWriter, aLabels, theMode, theMulti, Standard_False, theProgress);
+}
 
-  // iterate on subshapes (except vertices :)
-  if (theShape.ShapeType() == TopAbs_EDGE)
-    return;
-  if (theIsComponent)
-  {
-    return;
-  }
-  for (TopoDS_Iterator anIter(theShape); anIter.More(); anIter.Next())
-  {
-    MakeSTEPStyles(theStyles,
-                   anIter.Value(),
-                   theSettings,
-                   aSTEPstyle,
-                   theMap,
-                   theMapCompMDGPR,
-                   theDPDCs,
-                   theColRGBs,
-                   theShTool,
-                   (aHasOwn ? &aStyle : 0),
-                   Standard_False,
-                   theVisMaterialMode);
-  }
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_Label&                theLabel,
+                                                 const STEPControl_StepModelType theMode,
+                                                 const Standard_CString          theIsMulti,
+                                                 const Message_ProgressRange&    theProgress)
+{
+  const Handle(StepData_StepModel) aModel =
+    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
+  aModel->InternalParameters.InitFromStatic();
+  return Transfer(theLabel, aModel->InternalParameters, theMode, theIsMulti, theProgress);
 }
 
-//==================================================================================================
+//=================================================================================================
 
-// Auxiliary: find PDS for AdvancedFace or EdgeCurve for creation needed ShapeAspect in D&GT
-// structure
-static Standard_Boolean FindPDSforDGT(const Interface_Graph&                   theGraph,
-                                      const Handle(Standard_Transient)&        theEnt,
-                                      Handle(StepRepr_ProductDefinitionShape)& thePDS,
-                                      Handle(StepRepr_RepresentationContext)&  theRC,
-                                      Handle(StepShape_AdvancedFace)&          theAF,
-                                      Handle(StepShape_EdgeCurve)&             theEC)
+Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_Label&                theLabel,
+                                                 const DESTEP_Parameters&        theParams,
+                                                 const STEPControl_StepModelType theMode,
+                                                 const Standard_CString          theIsMulti,
+                                                 const Message_ProgressRange&    theProgress)
 {
-  if (theEnt.IsNull())
-    return Standard_False;
-  if (!theEnt->IsKind(STANDARD_TYPE(StepShape_EdgeCurve))
-      && !theEnt->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)))
+  if (theLabel.IsNull())
   {
     return Standard_False;
   }
+  TDF_LabelSequence aLabels;
+  aLabels.Append(theLabel);
+  myRootLabels.Clear();
+  myRootLabels.Add(theLabel.Root());
+  const Handle(StepData_StepModel) aModel =
+    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
+  aModel->InternalParameters = theParams;
+  return transfer(myWriter, aLabels, theMode, theIsMulti, Standard_False, theProgress);
+}
 
-  theAF = Handle(StepShape_AdvancedFace)::DownCast(theEnt);
-  if (theAF.IsNull())
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_LabelSequence&        theLabels,
+                                                 const STEPControl_StepModelType theMode,
+                                                 const Standard_CString          theIsMulti,
+                                                 const Message_ProgressRange&    theProgress)
+{
+  const Handle(StepData_StepModel) aModel =
+    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
+  aModel->InternalParameters.InitFromStatic();
+  return Transfer(theLabels, aModel->InternalParameters, theMode, theIsMulti, theProgress);
+}
+
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_LabelSequence&        theLabels,
+                                                 const DESTEP_Parameters&        theParams,
+                                                 const STEPControl_StepModelType theMode,
+                                                 const Standard_CString          theIsMulti,
+                                                 const Message_ProgressRange&    theProgress)
+{
+  myRootLabels.Clear();
+  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
   {
-    theEC = Handle(StepShape_EdgeCurve)::DownCast(theEnt);
-    for (Interface_EntityIterator aSharingsIter = theGraph.Sharings(theEC);
-         aSharingsIter.More() && theAF.IsNull();
-         aSharingsIter.Next())
+    const TDF_Label& aLabel = aLabelIter.Value();
+    if (!aLabel.IsNull())
     {
-      Handle(StepShape_OrientedEdge) anOE =
-        Handle(StepShape_OrientedEdge)::DownCast(aSharingsIter.Value());
-      if (anOE.IsNull())
-        continue;
-      for (Interface_EntityIterator aSubs1 = theGraph.Sharings(anOE);
-           aSubs1.More() && theAF.IsNull();
-           aSubs1.Next())
-      {
-        Handle(StepShape_EdgeLoop) aEL = Handle(StepShape_EdgeLoop)::DownCast(aSubs1.Value());
-        if (aEL.IsNull())
-          continue;
-        for (Interface_EntityIterator aSubs2 = theGraph.Sharings(aEL);
-             aSubs2.More() && theAF.IsNull();
-             aSubs2.Next())
-        {
-          Handle(StepShape_FaceBound) aFB = Handle(StepShape_FaceBound)::DownCast(aSubs2.Value());
-          if (aFB.IsNull())
-            continue;
-          for (Interface_EntityIterator aSubs3 = theGraph.Sharings(aFB);
-               aSubs3.More() && theAF.IsNull();
-               aSubs3.Next())
-          {
-            theAF = Handle(StepShape_AdvancedFace)::DownCast(aSubs3.Value());
-          }
-        }
-      }
+      myRootLabels.Add(aLabel.Root());
     }
   }
-  if (theAF.IsNull())
-    return Standard_False;
+  const Handle(StepData_StepModel) aModel =
+    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
+  aModel->InternalParameters = theParams;
+  return transfer(myWriter, theLabels, theMode, theIsMulti, Standard_False, theProgress);
+}
 
-  for (Interface_EntityIterator aSharingsIter = theGraph.Sharings(theAF);
-       aSharingsIter.More() && thePDS.IsNull();
-       aSharingsIter.Next())
-  {
-    Handle(StepShape_ConnectedFaceSet) aCFS =
-      Handle(StepShape_ConnectedFaceSet)::DownCast(aSharingsIter.Value());
-    if (aCFS.IsNull())
-      continue;
-    for (Interface_EntityIterator aSubs1 = theGraph.Sharings(aCFS);
-         aSubs1.More() && thePDS.IsNull();
-         aSubs1.Next())
-    {
-      Handle(StepRepr_RepresentationItem) aRI =
-        Handle(StepRepr_RepresentationItem)::DownCast(aSubs1.Value());
-      if (aRI.IsNull())
-        continue;
-      for (Interface_EntityIterator aSubs2 = theGraph.Sharings(aRI);
-           aSubs2.More() && thePDS.IsNull();
-           aSubs2.Next())
-      {
-        Handle(StepShape_ShapeRepresentation) aSR =
-          Handle(StepShape_ShapeRepresentation)::DownCast(aSubs2.Value());
-        if (aSR.IsNull())
-          continue;
-        theRC = aSR->ContextOfItems();
-        for (Interface_EntityIterator aSubs3 = theGraph.Sharings(aSR);
-             aSubs3.More() && thePDS.IsNull();
-             aSubs3.Next())
-        {
-          Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
-            Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSubs3.Value());
-          if (aSDR.IsNull())
-            continue;
-          Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
-          if (aPropD.IsNull())
-            continue;
-          thePDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD);
-        }
-      }
-    }
-  }
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::Perform(const Handle(TDocStd_Document)& theDoc,
+                                                const Standard_CString          theFileName,
+                                                const Message_ProgressRange&    theProgress)
+{
+  if (!Transfer(theDoc, STEPControl_AsIs, 0L, theProgress))
+    return Standard_False;
+  return Write(theFileName) == IFSelect_RetDone;
+}
+
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::Perform(const Handle(TDocStd_Document)& theDoc,
+                                                const Standard_CString          theFileName,
+                                                const DESTEP_Parameters&        theParams,
+                                                const Message_ProgressRange&    theProgress)
+{
+  if (!Transfer(theDoc, theParams, STEPControl_AsIs, 0L, theProgress))
+    return Standard_False;
+  return Write(theFileName) == IFSelect_RetDone;
+}
+
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::Perform(const Handle(TDocStd_Document)& theDoc,
+                                                const TCollection_AsciiString&  theFileName,
+                                                const Message_ProgressRange&    theProgress)
+{
+  if (!Transfer(theDoc, STEPControl_AsIs, 0L, theProgress))
+    return Standard_False;
+  return Write(theFileName.ToCString()) == IFSelect_RetDone;
+}
+
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::ExternFile(
+  const TDF_Label&                   theLabel,
+  Handle(STEPCAFControl_ExternFile)& theExtFile) const
+{
+  theExtFile.Nullify();
+  if (!myLabEF.IsBound(theLabel))
+    return Standard_False;
+  theExtFile = myLabEF.Find(theLabel);
   return Standard_True;
 }
 
-//==================================================================================================
+//=================================================================================================
 
-// Auxiliary: find Product_definition_shape entity for given entity
-static Handle(StepRepr_ProductDefinitionShape) FindPDS(
-  const Interface_Graph&                  theGraph,
-  const Handle(Standard_Transient)&       theEnt,
-  Handle(StepRepr_RepresentationContext)& theRC)
+Standard_Boolean STEPCAFControl_Writer::ExternFile(
+  const Standard_CString             theName,
+  Handle(STEPCAFControl_ExternFile)& theExtFile) const
 {
-  if (theEnt.IsNull())
-    return NULL;
-  Handle(StepRepr_ProductDefinitionShape) aPDS;
+  theExtFile.Nullify();
+  if (!myFiles.IsEmpty() || !myFiles.IsBound(theName))
+    return Standard_False;
+  theExtFile = myFiles.Find(theName);
+  return Standard_True;
+}
 
-  // try to find shape_representation in sharings
-  for (Interface_EntityIterator anIter = theGraph.Sharings(theEnt); anIter.More() && aPDS.IsNull();
-       anIter.Next())
-  {
-    Handle(StepShape_ShapeRepresentation) aSR =
-      Handle(StepShape_ShapeRepresentation)::DownCast(anIter.Value());
-    if (aSR.IsNull())
-      continue;
-    theRC                           = aSR->ContextOfItems();
-    Interface_EntityIterator aSDRIt = theGraph.Sharings(aSR);
-    for (aSDRIt.Start(); aSDRIt.More() && aPDS.IsNull(); aSDRIt.Next())
-    {
-      Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
-        Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
-      if (aSDR.IsNull())
-        continue;
-      Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
-      if (aPropD.IsNull())
-        continue;
-      aPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD);
-    }
-  }
-  if (!aPDS.IsNull())
-    return aPDS;
+//=============================================================================
 
-  for (Interface_EntityIterator anIter = theGraph.Sharings(theEnt); anIter.More(); anIter.Next())
-  {
-    if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem))
-        || anIter.Value()->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)))
-    {
-      aPDS = FindPDS(theGraph, anIter.Value(), theRC);
-      if (!aPDS.IsNull())
-        return aPDS;
-    }
-  }
-  return aPDS;
+void STEPCAFControl_Writer::SetShapeFixParameters(
+  const XSAlgo_ShapeProcessor::ParameterMap& theParameters)
+{
+  myWriter.SetShapeFixParameters(theParameters);
 }
 
-//==================================================================================================
+//=============================================================================
 
-static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theRC,
-                              const Standard_Boolean theIsAngle = Standard_False)
+void STEPCAFControl_Writer::SetShapeFixParameters(
+  XSAlgo_ShapeProcessor::ParameterMap&& theParameters)
 {
-  StepBasic_Unit              aUnit;
-  Handle(StepBasic_NamedUnit) aCurrentUnit;
-  if (theIsAngle)
+  myWriter.SetShapeFixParameters(std::move(theParameters));
+}
+
+//=============================================================================
+
+void STEPCAFControl_Writer::SetShapeFixParameters(
+  const DE_ShapeFixParameters&               theParameters,
+  const XSAlgo_ShapeProcessor::ParameterMap& theAdditionalParameters)
+{
+  myWriter.SetShapeFixParameters(theParameters, theAdditionalParameters);
+}
+
+//=============================================================================
+
+const XSAlgo_ShapeProcessor::ParameterMap& STEPCAFControl_Writer::GetShapeFixParameters() const
+{
+  return myWriter.GetShapeFixParameters();
+}
+
+//=============================================================================
+
+void STEPCAFControl_Writer::SetShapeProcessFlags(const ShapeProcess::OperationsFlags& theFlags)
+{
+  myWriter.SetShapeProcessFlags(theFlags);
+}
+
+//=============================================================================
+
+const XSAlgo_ShapeProcessor::ProcessingFlags& STEPCAFControl_Writer::GetShapeProcessFlags() const
+{
+  return myWriter.GetShapeProcessFlags();
+}
+
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::transfer(STEPControl_Writer&             theWriter,
+                                                 const TDF_LabelSequence&        theLabels,
+                                                 const STEPControl_StepModelType theMode,
+                                                 const Standard_CString          theIsMulti,
+                                                 const Standard_Boolean          theIsExternFile,
+                                                 const Message_ProgressRange&    theProgress)
+{
+  if (theLabels.IsEmpty())
+    return Standard_False;
+
+  Handle(STEPCAFControl_ActorWrite) anActor =
+    Handle(STEPCAFControl_ActorWrite)::DownCast(theWriter.WS()->NormAdaptor()->ActorWrite());
+
+  StepData_Factors                 aLocalFactors;
+  const Handle(StepData_StepModel) aModel =
+    Handle(StepData_StepModel)::DownCast(theWriter.WS()->Model());
+  prepareUnit(theLabels.First(), aModel, aLocalFactors); // set local length unit to the model
+  // translate free top-level shapes of the DECAF document
+  TDF_LabelSequence     aSubLabels;
+  Message_ProgressScope aPS(theProgress, "Labels", theLabels.Length());
+  // Iterate on requested shapes
+  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More() && aPS.More();
+       aLabelIter.Next())
   {
-    Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
-      Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
-    if (!aCtx.IsNull())
+    Message_ProgressRange aRange = aPS.Next();
+    TDF_Label             aCurL  = aLabelIter.Value();
+    if (myLabels.IsBound(aCurL))
+      continue; // already processed
+
+    TopoDS_Shape aCurShape = XCAFDoc_ShapeTool::GetShape(aCurL);
+    if (aCurShape.IsNull())
+      continue;
+    TopoDS_Shape aShapeForBind = aCurShape;
+    // write shape either as a whole, or as multifile (with extern refs)
+    if (!theIsMulti)
     {
-      for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx->Units()->Array1());
-           aUnitIter.More();
-           aUnitIter.Next())
+      anActor->SetStdMode(Standard_False);
+
+      TDF_LabelSequence aCompLabels;
+
+      // For case when only part of assembly structure should be written in the document
+      // if specified label is component of the assembly then
+      // in order to save location of this component in the high-level assembly
+      // and save name of high-level assembly it is necessary to represent structure of high-level
+      // assembly as assembly with one component specified by current label. For that compound
+      // containing only specified component is binded to the label of the high-level assembly. The
+      // such way full structure of high-level assembly was replaced on the assembly containing one
+      // component. For case when free shape reference is (located root) also create an auxiliary
+      // assembly.
+      if (XCAFDoc_ShapeTool::IsReference(aCurL))
       {
-        const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value();
-        if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))
-            || aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)))
+        TopoDS_Compound aComp;
+        BRep_Builder    aB;
+        aB.MakeCompound(aComp);
+        aB.Add(aComp, aCurShape);
+        aCurShape = aComp;
+        myPureRefLabels.Bind(aCurL, aComp);
+        aCompLabels.Append(aCurL);
+        TDF_Label aRefL;
+        if (XCAFDoc_ShapeTool::GetReferredShape(aCurL, aRefL))
         {
-          aCurrentUnit = aCurUnitValue;
-          break;
+          if (XCAFDoc_ShapeTool::IsAssembly(aRefL))
+            XCAFDoc_ShapeTool::GetComponents(aRefL, aCompLabels, Standard_True);
         }
+        if (!XCAFDoc_ShapeTool::IsFree(aCurL))
+          aCurL = aCurL.Father();
       }
-    }
-    if (aCurrentUnit.IsNull())
-    {
-      Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
-        Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
-      if (!aCtx1.IsNull())
+      else
       {
-        for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx1->Units()->Array1());
-             aUnitIter.More();
-             aUnitIter.Next())
-        {
-          const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value();
-          if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))
-              || aCurUnitValue->IsKind(
-                STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)))
-          {
-            aCurrentUnit = aCurUnitValue;
-            break;
-          }
-        }
+        // fill sequence of (sub) shapes for which attributes should be written
+        // and set actor to handle assemblies in a proper way
+        if (XCAFDoc_ShapeTool::IsAssembly(aCurL))
+          XCAFDoc_ShapeTool::GetComponents(aCurL, aCompLabels, Standard_True);
       }
-    }
-    if (aCurrentUnit.IsNull())
-      aCurrentUnit = new StepBasic_SiUnitAndPlaneAngleUnit;
-  }
-  else
-  {
-    Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
-      Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
-    if (!aCtx.IsNull())
-    {
-      for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx->Units()->Array1());
-           aUnitIter.More();
-           aUnitIter.Next())
+
+      for (TDF_LabelSequence::Iterator aCompIter(aCompLabels); aCompIter.More(); aCompIter.Next())
       {
-        const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value();
-        if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))
-            || aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)))
+        const TDF_Label aCurSubShL = aCompIter.Value();
+        if (myLabels.IsBound(aCurSubShL))
         {
-          aCurrentUnit = aCurUnitValue;
-          break;
+          continue;
         }
-      }
-    }
-    if (aCurrentUnit.IsNull())
-    {
-      Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
-        Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
-      if (!aCtx1.IsNull())
-      {
-        for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx1->Units()->Array1());
-             aUnitIter.More();
-             aUnitIter.Next())
+        const TopoDS_Shape aCurSh = XCAFDoc_ShapeTool::GetShape(aCurSubShL);
+        if (aCurSh.IsNull())
         {
-          const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value();
-          if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))
-              || aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)))
+          continue;
+        }
+        myLabels.Bind(aCurSubShL, aCurSh);
+        aSubLabels.Append(aCurSubShL);
+        TDF_Label aRefL;
+        if (!XCAFDoc_ShapeTool::GetReferredShape(aCurSubShL, aRefL))
+        {
+          continue;
+        }
+        if (!myLabels.IsBound(aRefL))
+        {
+          TopoDS_Shape aRefSh = XCAFDoc_ShapeTool::GetShape(aRefL);
+          myLabels.Bind(aRefL, aRefSh);
+          aSubLabels.Append(aRefL);
+          if (XCAFDoc_ShapeTool::IsAssembly(aRefL))
           {
-            aCurrentUnit = aCurUnitValue;
-            break;
+            anActor->RegisterAssembly(aRefSh);
           }
         }
       }
-    }
-    if (aCurrentUnit.IsNull())
-      aCurrentUnit = new StepBasic_SiUnitAndLengthUnit;
-  }
-
-  aUnit.SetValue(aCurrentUnit);
-  return aUnit;
-}
+      myLabels.Bind(aCurL, aShapeForBind);
+      aSubLabels.Append(aCurL);
 
-//==================================================================================================
+      if (XCAFDoc_ShapeTool::IsAssembly(aCurL) || XCAFDoc_ShapeTool::IsReference(aCurL))
+        anActor->RegisterAssembly(aCurShape);
 
-static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(
-  const Standard_Real                                  theValue,
-  const StepBasic_Unit&                                theUnit,
-  const Handle(TCollection_HAsciiString)&              theName,
-  const Standard_CString                               theMeasureName,
-  const Standard_Boolean                               theIsAngle,
-  const Standard_Boolean                               theIsQualified = Standard_False,
-  const Handle(StepShape_QualifiedRepresentationItem)& theQRI         = NULL)
-{
-  Handle(StepRepr_RepresentationItem) aReprItem = new StepRepr_RepresentationItem();
-  aReprItem->Init(new TCollection_HAsciiString(theName));
-  Handle(StepBasic_MeasureWithUnit)    aMWU         = new StepBasic_MeasureWithUnit();
-  Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
-  aValueMember->SetName(theMeasureName);
-  aValueMember->SetReal(theValue);
-  aMWU->Init(aValueMember, theUnit);
-  if (theIsQualified)
-  {
-    if (theIsAngle)
-    {
-      // Angle & with qualifiers
-      Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI) anItem =
-        new StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI();
-      anItem->Init(aMWU, aReprItem, theQRI);
-      return anItem;
-    }
-    else
-    {
-      // Length & with qualifiers
-      Handle(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI) anItem =
-        new StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI();
-      anItem->Init(aMWU, aReprItem, theQRI);
-      return anItem;
-    }
-  }
-  else
-  {
-    if (theIsAngle)
-    {
-      // Angle & without qualifiers
-      Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) anItem =
-        new StepRepr_ReprItemAndPlaneAngleMeasureWithUnit();
-      anItem->Init(aMWU, aReprItem);
-      return anItem;
+      theWriter.Transfer(aCurShape, theMode, aModel->InternalParameters, Standard_False, aRange);
+      anActor->SetStdMode(Standard_True); // restore default behaviour
     }
     else
     {
-      // Length & without qualifiers
-      Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) anItem =
-        new StepRepr_ReprItemAndLengthMeasureWithUnit();
-      anItem->Init(aMWU, aReprItem);
-      return anItem;
-    }
-  }
-}
+      // translate final solids
+      Message_ProgressScope aPS1(aRange, NULL, 2);
+      TopoDS_Shape          aSass =
+        transferExternFiles(aCurL, theMode, aSubLabels, aLocalFactors, theIsMulti, aPS1.Next());
+      if (aPS1.UserBreak())
+        return Standard_False;
 
-//==================================================================================================
-
-static Handle(StepRepr_ShapeAspect) WriteSupplementalGeometry(
-  const Handle(XSControl_WorkSession)&                              theWS,
-  const Handle(StepRepr_ConstructiveGeometryRepresentation)&        theCGRepr,
-  const TDF_Label&                                                  theLabel,
-  const TopoDS_Shape&                                               theShape,
-  Handle(StepRepr_RepresentationContext)&                           theRC,
-  Handle(StepAP242_GeometricItemSpecificUsage)&                     theGISU,
-  NCollection_Vector<Handle(StepGeom_GeometricRepresentationItem)>& theGeomItems,
-  const StepData_Factors&                                           theLocalFactors)
-{
-  // Get working data
-  const Handle(Interface_InterfaceModel)& aModel  = theWS->Model();
-  const Handle(XSControl_TransferWriter)& aTW     = theWS->TransferWriter();
-  const Handle(Transfer_FinderProcess)&   aFP     = aTW->FinderProcess();
-  const Handle(Interface_HGraph)          aHGraph = theWS->HGraph();
-  if (aHGraph.IsNull())
-  {
-    return nullptr;
+      DESTEP_Parameters::WriteMode_Assembly assemblymode = aModel->InternalParameters.WriteAssembly;
+      aModel->InternalParameters.WriteAssembly           = DESTEP_Parameters::WriteMode_Assembly_On;
+      theWriter.Transfer(aSass,
+                         STEPControl_AsIs,
+                         aModel->InternalParameters,
+                         Standard_True,
+                         aPS1.Next());
+      aModel->InternalParameters.WriteAssembly = assemblymode;
+    }
   }
-  Interface_Graph aGraph = aHGraph->Graph();
+  if (aPS.UserBreak())
+    return Standard_False;
 
-  // Shape_Aspect
-  Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString();
-  Handle(TDataStd_Name)            aNameAttr;
-  if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
-  {
-    aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get()));
-  }
-  // Description is empty
-  const Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString();
+  theWriter.WS()->ComputeGraph(Standard_True); // Setting to clear and regenerate graph
 
-  Handle(TDataStd_TreeNode) aRefNode;
-  if (!theLabel.FindAttribute(XCAFDoc::SupplementalRefGUID(), aRefNode)
-      || aRefNode->Father().IsNull() || aRefNode->Father()->Label().IsNull())
-  {
-    return nullptr;
-  }
+  // write names
+  if (GetNameMode())
+    writeNames(theWriter.WS(), aSubLabels);
 
-  TopoDS_Shape                aMainShape = XCAFDoc_ShapeTool::GetShape(aRefNode->Father()->Label());
-  TopLoc_Location             aLoc;
-  TColStd_SequenceOfTransient aSeqRI;
-  FindEntities(aFP, aMainShape, aLoc, aSeqRI);
-  if (aSeqRI.IsEmpty())
+  if (!theIsMulti)
   {
-    aFP->Messenger()->SendInfo() << "Warning: Cannot find RI for "
-                                 << aMainShape.TShape()->DynamicType()->Name() << std::endl;
-    return nullptr;
-  }
+    // write colors
+    if (GetColorMode())
+      writeColors(theWriter.WS(), aSubLabels);
 
-  Handle(StepRepr_RepresentationContext)  aRC;
-  Handle(StepRepr_ProductDefinitionShape) aPDS = FindPDS(aGraph, aSeqRI.Value(1), aRC);
-  if (aPDS.IsNull())
-  {
-    return nullptr;
-  }
+    // write layers
+    if (GetLayerMode())
+      writeLayers(theWriter.WS(), aSubLabels);
 
-  theRC = aRC;
+    // write SHUO entities
+    if (GetSHUOMode() && !theIsExternFile)
+      // do not store SHUO for extern reference for the moment
+      writeSHUOs(theWriter.WS(), aSubLabels);
 
-  Handle(StepGeom_GeometricRepresentationItem) anIdentifiedItem;
-  if (theShape.ShapeType() == TopAbs_FACE)
-  {
-    const TopoDS_Face&         aFace = TopoDS::Face(theShape);
-    const Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
-    GeomToStep_MakeSurface     aMaker(aSurf, theLocalFactors);
-    if (aMaker.IsDone())
+    // write G&DTs
+    if (GetDimTolMode())
     {
-      anIdentifiedItem = aMaker.Value();
+      if (aModel->InternalParameters.WriteSchema == 5)
+      {
+        writeDGTsAP242(theWriter.WS(), aSubLabels, aLocalFactors);
+      }
+      else
+      {
+        writeDGTs(theWriter.WS(), aSubLabels);
+      }
     }
-  }
-  else if (theShape.ShapeType() == TopAbs_EDGE)
-  {
-    const TopoDS_Edge&       anEdge = TopoDS::Edge(theShape);
-    Standard_Real            aTmpFirst, aTmpLast;
-    const Handle(Geom_Curve) aCurv = BRep_Tool::Curve(anEdge, aTmpFirst, aTmpLast);
-    GeomToStep_MakeCurve     aMaker(aCurv, theLocalFactors);
-    if (aMaker.IsDone())
+
+    // write Materials
+    if (GetMaterialMode())
+      writeMaterials(theWriter.WS(), aSubLabels);
+
+    // register all MDGPRs in model
+    for (MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR); anItr.More();
+         anItr.Next())
     {
-      anIdentifiedItem = aMaker.Value();
+      aModel->AddWithRefs(anItr.Value());
     }
   }
-  if (anIdentifiedItem.IsNull())
-  {
-    return nullptr;
+
+  if (theIsMulti)
+  { // external refs
+    writeExternRefs(theWriter.WS(), aSubLabels);
   }
 
-  Handle(StepRepr_ShapeAspect) aResSA = new StepRepr_ShapeAspect();
-  aResSA->Init(aName, aDescription, aPDS, StepData_LTrue);
-  // Geometric_Item_Specific_Usage
-  Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
-  StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
-  aDefinition.SetValue(aResSA);
-  Handle(StepRepr_HArray1OfRepresentationItem) anReprItems =
-    new StepRepr_HArray1OfRepresentationItem(1, 1);
+  // write validation props
+  if (GetPropsMode())
+    writeValProps(theWriter.WS(), aSubLabels, theIsMulti);
 
-  anIdentifiedItem->SetName(aName);
-  theGISU = aGISU;
-  anReprItems->SetValue(1, anIdentifiedItem);
-  theGeomItems.Append(anIdentifiedItem);
+  // write metadata
+  if (GetMetadataMode())
+    writeMetadata(theWriter.WS(), aSubLabels);
 
-  // Set entities to model
-  aGISU->Init(aName, aDescription, aDefinition, theCGRepr, anReprItems);
-  aModel->AddWithRefs(aResSA);
-  aModel->AddWithRefs(aGISU);
-  return aResSA;
-}
-} // namespace
+  // refresh graph
+  theWriter.WS()->ComputeGraph(Standard_True);
 
-//=================================================================================================
+  // Write names for the sub-shapes
+  if (aModel->InternalParameters.WriteSubshapeNames != 0)
+  {
+    const Handle(XSControl_TransferWriter)& TW  = this->ChangeWriter().WS()->TransferWriter();
+    const Handle(Transfer_FinderProcess)&   aFP = TW->FinderProcess();
 
-STEPCAFControl_Writer::STEPCAFControl_Writer()
-    : myColorMode(Standard_True),
-      myNameMode(Standard_True),
-      myLayerMode(Standard_True),
-      myPropsMode(Standard_True),
-      myMetadataMode(Standard_True),
-      mySHUOMode(Standard_True),
-      myGDTMode(Standard_True),
-      myMatMode(Standard_True),
-      myVisMatMode(Standard_False),
-      myIsCleanDuplicates(Standard_False)
-{
-  STEPCAFControl_Controller::Init();
-  Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession;
-  Init(aWS);
-}
+    // Iterate on requested sub shapes
+    for (TDF_LabelSequence::Iterator aLabelIter(aSubLabels); aLabelIter.More(); aLabelIter.Next())
+    {
+      const TDF_Label& aCurL = aLabelIter.Value();
 
-//=================================================================================================
+      for (TDF_ChildIterator aChildIter(aCurL, Standard_True); aChildIter.More(); aChildIter.Next())
+      {
+        const TDF_Label& aSubL = aChildIter.Value();
 
-STEPCAFControl_Writer::STEPCAFControl_Writer(const Handle(XSControl_WorkSession)& theWS,
-                                             const Standard_Boolean               theScratch)
-    : myColorMode(Standard_True),
-      myNameMode(Standard_True),
-      myLayerMode(Standard_True),
-      myPropsMode(Standard_True),
-      myMetadataMode(Standard_True),
-      mySHUOMode(Standard_True),
-      myGDTMode(Standard_True),
-      myMatMode(Standard_True),
-      myVisMatMode(Standard_False),
-      myIsCleanDuplicates(Standard_False)
-{
-  STEPCAFControl_Controller::Init();
-  Init(theWS, theScratch);
-}
+        // Access name recorded in OCAF TDataStd_Name attribute
+        Handle(TCollection_HAsciiString) aHSubName = new TCollection_HAsciiString;
+        if (!GetLabelName(aSubL, aHSubName))
+          continue;
 
-//=================================================================================================
+        // Access topological data
+        TopoDS_Shape aSubS = XCAFDoc_ShapeTool::GetShape(aSubL);
+        if (aSubS.IsNull())
+          continue;
 
-void STEPCAFControl_Writer::Init(const Handle(XSControl_WorkSession)& theWS,
-                                 const Standard_Boolean               theScratch)
-{
-  theWS->SelectNorm("STEP");
-  myWriter.SetWS(theWS, theScratch);
-  myFiles.Clear();
-  myLabEF.Clear();
-  myLabels.Clear();
-  myPureRefLabels.Clear();
-  myRootLabels.Clear();
-  myGDTPresentationDM = new StepVisual_DraughtingModel();
-  myGDTPrsCurveStyle  = new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
+        // Access the correspondent STEP Representation Item
+        Handle(StepRepr_RepresentationItem) aRI;
+        Handle(TransferBRep_ShapeMapper)    aShMapper = TransferBRep::ShapeMapper(aFP, aSubS);
+        if (!aFP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), aRI))
+          continue;
+
+        // Record the name
+        aRI->SetName(aHSubName);
+      }
+    }
+  }
+
+  return Standard_True;
 }
 
 //=================================================================================================
 
-IFSelect_ReturnStatus STEPCAFControl_Writer::Write(const Standard_CString theFileName)
+TopoDS_Shape STEPCAFControl_Writer::transferExternFiles(const TDF_Label&                theLabel,
+                                                        const STEPControl_StepModelType theMode,
+                                                        TDF_LabelSequence&              theLabels,
+                                                        const StepData_Factors& theLocalFactors,
+                                                        const Standard_CString  thePrefix,
+                                                        const Message_ProgressRange& theProgress)
 {
-  if (myIsCleanDuplicates)
+  // if label already translated, just return the shape
+  if (myLabels.IsBound(theLabel))
   {
-    // remove duplicates
-    myWriter.CleanDuplicateEntities();
+    return myLabels.Find(theLabel);
   }
 
-  IFSelect_ReturnStatus aStatus = myWriter.Write(theFileName);
-  if (aStatus != IFSelect_RetDone)
+  TopoDS_Compound aComp;
+  BRep_Builder    aBuilder;
+  aBuilder.MakeCompound(aComp);
+  // if not assembly, write to separate file
+  if (!XCAFDoc_ShapeTool::IsAssembly(theLabel) && !XCAFDoc_ShapeTool::IsComponent(theLabel))
   {
-    return aStatus;
+    theLabels.Append(theLabel);
+    // prepare for transfer
+    Handle(XSControl_WorkSession) aNewWS = new XSControl_WorkSession;
+    aNewWS->SelectNorm("STEP");
+    STEPControl_Writer aStepWriter(aNewWS, Standard_True);
+    TDF_LabelSequence  aLabelSeq;
+    aLabelSeq.Append(theLabel);
+
+    // construct the name for extern file
+    Handle(TCollection_HAsciiString) aBaseName = new TCollection_HAsciiString;
+    if (thePrefix && thePrefix[0])
+      aBaseName->AssignCat(thePrefix);
+    GetLabelName(theLabel, aBaseName);
+    Handle(TCollection_HAsciiString) aNewName = new TCollection_HAsciiString(aBaseName);
+    aNewName->AssignCat(".stp");
+    if (myFiles.IsBound(aNewName->ToCString()))
+    { // avoid confusions
+      for (Standard_Integer k = 1; k < 32000; k++)
+      {
+        aNewName = new TCollection_HAsciiString(aBaseName);
+        aNewName->AssignCat("_");
+        aNewName->AssignCat(TCollection_AsciiString(k).ToCString());
+        aNewName->AssignCat(".stp");
+        if (!myFiles.IsBound(aNewName->ToCString()))
+          break;
+      }
+    }
+
+    // translate and record extern file
+    Handle(STEPCAFControl_ExternFile) anExtFile = new STEPCAFControl_ExternFile;
+    anExtFile->SetWS(aNewWS);
+    anExtFile->SetName(aNewName);
+    anExtFile->SetLabel(theLabel);
+    DESTEP_Parameters::WriteMode_Assembly anAssemblymode =
+      aStepWriter.Model()->InternalParameters.WriteAssembly;
+    aStepWriter.Model()->InternalParameters.WriteAssembly =
+      DESTEP_Parameters::WriteMode_Assembly_Off;
+    const Standard_CString anIsMulti = 0;
+    anExtFile->SetTransferStatus(
+      transfer(aStepWriter, aLabelSeq, theMode, anIsMulti, Standard_True, theProgress));
+    aStepWriter.Model()->InternalParameters.WriteAssembly = anAssemblymode;
+    myLabEF.Bind(theLabel, anExtFile);
+    myFiles.Bind(aNewName->ToCString(), anExtFile);
+
+    // return empty compound as replacement for the shape
+    myLabels.Bind(theLabel, aComp);
+    return aComp;
+  }
+  TDF_LabelSequence aCompLabels;
+  TDF_Label         aLabel = theLabel;
+  // if specified shape is component then high-level assembly is considered
+  // to get valid structure with location
+  if (XCAFDoc_ShapeTool::IsComponent(theLabel))
+  {
+    aCompLabels.Append(theLabel);
+    aLabel = theLabel.Father();
   }
+  // else iterate on components add create structure of empty compounds
+  // representing the assembly
+  else if (XCAFDoc_ShapeTool::IsAssembly(theLabel))
+    XCAFDoc_ShapeTool::GetComponents(theLabel, aCompLabels, Standard_False);
 
-  // get directory name of the main file
-  TCollection_AsciiString aDirPath;
+  theLabels.Append(aLabel);
+  Message_ProgressScope aPS(theProgress, NULL, aCompLabels.Length());
+  // Iterate on requested shapes
+  for (TDF_LabelSequence::Iterator aLabelIter(aCompLabels); aLabelIter.More() && aPS.More();
+       aLabelIter.Next())
   {
-    OSD_Path aMainFile(theFileName);
-    aMainFile.SetName("");
-    aMainFile.SetExtension("");
-    aMainFile.SystemName(aDirPath);
+    const TDF_Label& aCurL = aLabelIter.Value();
+    TDF_Label        aRefL;
+    if (!XCAFDoc_ShapeTool::GetReferredShape(aCurL, aRefL))
+      continue;
+    TopoDS_Shape aShComp =
+      transferExternFiles(aRefL, theMode, theLabels, theLocalFactors, thePrefix, aPS.Next());
+    aShComp.Location(XCAFDoc_ShapeTool::GetLocation(aCurL));
+    aBuilder.Add(aComp, aShComp);
   }
+  myLabels.Bind(aLabel, aComp);
+  return aComp;
+}
 
-  for (NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator
-         anExtFileIter(myFiles);
-       anExtFileIter.More();
-       anExtFileIter.Next())
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::writeExternRefs(const Handle(XSControl_WorkSession)& theWS,
+                                                        const TDF_LabelSequence& theLabels) const
+{
+  if (theLabels.IsEmpty())
+    return Standard_False;
+
+  const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
+  const Handle(Transfer_FinderProcess)&   aFP = aTW->FinderProcess();
+  STEPConstruct_ExternRefs                anEFTool(theWS);
+  Handle(StepData_StepModel) aStepModel  = Handle(StepData_StepModel)::DownCast(theWS->Model());
+  Standard_Integer           aStepSchema = aStepModel->InternalParameters.WriteSchema;
+  // Iterate on requested shapes
+  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
   {
-    const Handle(STEPCAFControl_ExternFile)& anExtFile = anExtFileIter.Value();
-    if (anExtFile->GetWriteStatus() != IFSelect_RetVoid)
+    const TDF_Label& aLab = aLabelIter.Value();
+    if (XCAFDoc_ShapeTool::IsAssembly(aLab))
+      continue; // skip assemblies
+
+    // get extern file
+    Handle(STEPCAFControl_ExternFile) anExtFile;
+    if (!ExternFile(aLab, anExtFile))
+      continue; // should never be
+
+    // find SDR
+    if (!myLabels.IsBound(aLab))
+      continue; // not recorded as translated, skip
+    TopoDS_Shape aShape = myLabels.Find(aLab);
+
+    Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
+    Handle(TransferBRep_ShapeMapper)                mapper = TransferBRep::ShapeMapper(aFP, aShape);
+    if (!aFP->FindTypedTransient(mapper,
+                                 STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
+                                 aSDR))
     {
+      Message::SendTrace() << "Warning: Cannot find SDR for "
+                           << aShape.TShape()->DynamicType()->Name() << "\n";
       continue;
     }
 
-    // construct extern file name
-    TCollection_AsciiString aFileName =
-      OSD_Path::AbsolutePath(aDirPath, anExtFile->GetName()->String());
-    if (aFileName.Length() <= 0)
+    // add extern ref
+    const char* aStepFormat = (aStepSchema == 3 ? "STEP AP203" : "STEP AP214");
+    // try to get PD from SDR
+    StepRepr_RepresentedDefinition      aRD      = aSDR->Definition();
+    Handle(StepRepr_PropertyDefinition) aPropDef = aRD.PropertyDefinition();
+    if (aPropDef.IsNull())
     {
-      aFileName = anExtFile->GetName()->String();
+      Message::SendTrace() << "Warning: STEPCAFControl_Writer::writeExternRefs "
+                              "StepRepr_PropertyDefinition is null for "
+                           << aShape.TShape()->DynamicType()->Name() << "\n";
+      continue;
     }
-    Message::SendTrace() << "Writing external file: " << aFileName << "\n";
-
-    const IFSelect_ReturnStatus anExtStatus = anExtFile->GetWS()->SendAll(aFileName.ToCString());
-    anExtFile->SetWriteStatus(anExtStatus);
-    if (anExtStatus != IFSelect_RetDone)
+    StepRepr_CharacterizedDefinition    aCharDef = aPropDef->Definition();
+    Handle(StepBasic_ProductDefinition) aPD      = aCharDef.ProductDefinition();
+    if (aPD.IsNull())
     {
-      aStatus = anExtStatus;
+      Message::SendTrace() << "Warning: STEPCAFControl_Writer::writeExternRefs "
+                              "StepBasic_ProductDefinition is null for "
+                           << aShape.TShape()->DynamicType()->Name() << "\n";
+      continue;
     }
+    anEFTool.AddExternRef(anExtFile->GetName()->ToCString(), aPD, aStepFormat);
   }
-
-  return aStatus;
+  anEFTool.WriteExternRefs(aStepSchema);
+  return Standard_True;
 }
 
 //=================================================================================================
 
-void STEPCAFControl_Writer::prepareUnit(const TDF_Label&                  theLabel,
-                                        const Handle(StepData_StepModel)& theModel,
-                                        StepData_Factors&                 theLocalFactors)
-{
-  Handle(XCAFDoc_LengthUnit) aLengthAttr;
-  if (!theLabel.IsNull() && theLabel.Root().FindAttribute(XCAFDoc_LengthUnit::GetID(), aLengthAttr))
+static Standard_Integer FindEntities(const Handle(Transfer_FinderProcess)& theFP,
+                                     const TopoDS_Shape&                   theShape,
+                                     TopLoc_Location&                      theLocation,
+                                     TColStd_SequenceOfTransient&          theSeqRI)
+{
+  Handle(StepRepr_RepresentationItem) anItem =
+    STEPConstruct::FindEntity(theFP, theShape, theLocation);
+
+  if (!anItem.IsNull())
   {
-    theModel->SetLocalLengthUnit(aLengthAttr->GetUnitValue() * 1000); // convert to mm
-    theLocalFactors.SetCascadeUnit(aLengthAttr->GetUnitValue() * 1000);
+    theSeqRI.Append(anItem);
+    return 1;
   }
-  else
+
+  // may be S was split during shape processing
+  Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(theFP, theShape);
+  Handle(Transfer_Binder)          aBinder = theFP->Find(aMapper);
+  if (aBinder.IsNull())
+    return 0;
+
+  Handle(Transfer_TransientListBinder) aTransientListBinder =
+    // Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
+    Handle(Transfer_TransientListBinder)::DownCast(aBinder);
+  Standard_Integer aResCount = 0;
+  if (aTransientListBinder.IsNull())
   {
-    XSAlgo_ShapeProcessor::PrepareForTransfer(); // update unit info
-    theModel->SetLocalLengthUnit(UnitsMethods::GetCasCadeLengthUnit());
-    theLocalFactors.SetCascadeUnit(UnitsMethods::GetCasCadeLengthUnit());
+    for (TopoDS_Iterator anIter(theShape); anIter.More(); anIter.Next())
+    {
+      Handle(StepRepr_RepresentationItem) aLocalItem =
+        STEPConstruct::FindEntity(theFP, anIter.Value(), theLocation);
+      if (aLocalItem.IsNull())
+        continue;
+      aResCount++;
+      theSeqRI.Append(aLocalItem);
+    }
+  }
+  else if (!aTransientListBinder.IsNull())
+  {
+    const Standard_Integer aNbTransient = aTransientListBinder->NbTransients();
+    for (Standard_Integer anInd = 1; anInd <= aNbTransient; anInd++)
+    {
+      Handle(Standard_Transient) anEntity = aTransientListBinder->Transient(anInd);
+      anItem                              = Handle(StepRepr_RepresentationItem)::DownCast(anEntity);
+      if (anItem.IsNull())
+        continue;
+      aResCount++;
+      theSeqRI.Append(anItem);
+    }
   }
+  return aResCount;
 }
 
 //=================================================================================================
 
-IFSelect_ReturnStatus STEPCAFControl_Writer::WriteStream(std::ostream& theStream)
+static Standard_Boolean getStyledItem(const TopoDS_Shape&                     theShape,
+                                      const Handle(XCAFDoc_ShapeTool)&        theShapeTool,
+                                      const STEPConstruct_Styles&             theStyles,
+                                      Handle(StepVisual_StyledItem)&          theResSelItem,
+                                      const MoniTool_DataMapOfShapeTransient& theMapCompMDGPR)
 {
-  if (!myFiles.IsEmpty())
+  const TDF_Label  aTopShL   = theShapeTool->FindShape(theShape, Standard_False);
+  TopoDS_Shape     aTopLevSh = theShapeTool->GetShape(aTopShL);
+  Standard_Boolean anIsFound = Standard_False;
+  if (aTopLevSh.IsNull() || !theMapCompMDGPR.IsBound(aTopLevSh))
   {
-    // writing external files is unsupported via stream interface
-    return IFSelect_RetError;
+    return Standard_False;
   }
+  Handle(StepVisual_PresentationRepresentation) aMDGPR =
+    Handle(StepVisual_PresentationRepresentation)::DownCast(theMapCompMDGPR.Find(aTopLevSh));
+  Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
+  if (anSelItmHArr.IsNull())
+  {
+    return Standard_False;
+  }
+  // Search for PSA of Manifold solid
+  TColStd_SequenceOfTransient aNewSeqRI;
+  Standard_Boolean            isFilled = Standard_False;
+  for (StepRepr_HArray1OfRepresentationItem::Iterator anIter(anSelItmHArr->Array1());
+       anIter.More() && !anIsFound;
+       anIter.Next())
+  {
+    const Handle(StepVisual_StyledItem)& aSelItm =
+      Handle(StepVisual_StyledItem)::DownCast(anIter.Value());
 
-  return myWriter.WriteStream(theStream);
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::Transfer(const Handle(TDocStd_Document)& theDoc,
-                                                 const STEPControl_StepModelType theMode,
-                                                 const Standard_CString          theMulti,
-                                                 const Message_ProgressRange&    theProgress)
-{
-  const Handle(StepData_StepModel) aModel =
-    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
-  aModel->InternalParameters.InitFromStatic();
-  return Transfer(theDoc, aModel->InternalParameters, theMode, theMulti, theProgress);
+    if (aSelItm.IsNull())
+    {
+      continue;
+    }
+    // Check that it is a styled item for manifold solid brep
+    if (!isFilled)
+    {
+      TopLoc_Location aLoc;
+      FindEntities(theStyles.FinderProcess(), aTopLevSh, aLoc, aNewSeqRI);
+      isFilled = Standard_True;
+    }
+    if (!aNewSeqRI.IsEmpty())
+    {
+      const Handle(StepRepr_RepresentationItem)& anItem         = aSelItm->Item();
+      Standard_Boolean                           isSameMonSolBR = Standard_False;
+      for (TColStd_SequenceOfTransient::Iterator aIterRI(aNewSeqRI); aIterRI.More(); aIterRI.Next())
+      {
+        if (!anItem.IsNull() && anItem == aIterRI.Value())
+        {
+          isSameMonSolBR = Standard_True;
+          break;
+        }
+      }
+      if (!isSameMonSolBR)
+        continue;
+    }
+    for (StepVisual_HArray1OfPresentationStyleAssignment::Iterator aStyleIter(
+           aSelItm->Styles()->Array1());
+         aStyleIter.More() && !anIsFound;
+         aStyleIter.Next())
+    {
+      const Handle(StepVisual_PresentationStyleAssignment)& aFatherPSA = aStyleIter.Value();
+      // check for PSA for top-level (not Presentation style by context for NAUO)
+      if (aFatherPSA.IsNull()
+          || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
+        continue;
+      theResSelItem = aSelItm;
+      anIsFound     = Standard_True;
+    }
+  }
+  return anIsFound;
 }
 
 //=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::Transfer(const Handle(TDocStd_Document)& theDoc,
-                                                 const DESTEP_Parameters&        theParams,
-                                                 const STEPControl_StepModelType theMode,
-                                                 const Standard_CString          theMulti,
-                                                 const Message_ProgressRange&    theProgress)
+static Standard_Boolean setDefaultInstanceColor(
+  const Handle(StepVisual_StyledItem)&            theStyleItem,
+  Handle(StepVisual_PresentationStyleAssignment)& thePSA)
 {
-  Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
-  if (aShTool.IsNull())
-    return Standard_False;
+  Standard_Boolean anIsFound = Standard_False;
+  for (StepVisual_HArray1OfPresentationStyleAssignment::Iterator aStyleIter(
+         theStyleItem->Styles()->Array1());
+       aStyleIter.More() && !anIsFound;
+       aStyleIter.Next())
+  {
+    const Handle(StepVisual_PresentationStyleAssignment)& aFatherPSA = aStyleIter.Value();
+    // check for PSA for top-level (not Presentation style by context for NAUO)
+    if (aFatherPSA.IsNull()
+        || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
+      return Standard_False;
 
-  myRootLabels.Clear();
-  myRootLabels.Add(theDoc->Main().Root());
-  TDF_LabelSequence aLabels;
-  aShTool->GetFreeShapes(aLabels);
-  const Handle(StepData_StepModel) aModel =
-    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
-  aModel->InternalParameters = theParams;
-  return transfer(myWriter, aLabels, theMode, theMulti, Standard_False, theProgress);
+    // get style select from father PSA
+    if (aFatherPSA->NbStyles() > 0)
+    {
+      Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
+        new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
+      Standard_Integer aSettingInd = 1;
+      for (StepVisual_HArray1OfPresentationStyleSelect::Iterator aFatherStyleIter(
+             aFatherPSA->Styles()->Array1());
+           aFatherStyleIter.More();
+           aFatherStyleIter.Next())
+      {
+        StepVisual_PresentationStyleSelect        aPSS;
+        const StepVisual_PresentationStyleSelect& anOlDPSS = aFatherStyleIter.Value();
+        if (!anOlDPSS.PointStyle().IsNull())
+          aPSS.SetValue(anOlDPSS.PointStyle());
+        else if (!anOlDPSS.CurveStyle().IsNull())
+          aPSS.SetValue(anOlDPSS.CurveStyle());
+        else if (!anOlDPSS.SurfaceStyleUsage().IsNull())
+          aPSS.SetValue(anOlDPSS.SurfaceStyleUsage());
+        else
+        {
+          anIsFound = Standard_False;
+          break;
+        }
+        aFatherStyles->SetValue(aSettingInd++, anOlDPSS);
+        anIsFound = Standard_True;
+      }
+      // init PSA of NAUO
+      if (anIsFound)
+      {
+        thePSA->Init(aFatherStyles);
+      }
+    }
+  }
+  return anIsFound;
 }
 
 //=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_Label&                theLabel,
-                                                 const STEPControl_StepModelType theMode,
-                                                 const Standard_CString          theIsMulti,
-                                                 const Message_ProgressRange&    theProgress)
+static void MakeSTEPStyles(STEPConstruct_Styles&                        theStyles,
+                           const TopoDS_Shape&                          theShape,
+                           const XCAFPrs_IndexedDataMapOfShapeStyle&    theSettings,
+                           Handle(StepVisual_StyledItem)&               theOverride,
+                           TopTools_MapOfShape&                         theMap,
+                           const MoniTool_DataMapOfShapeTransient&      theMapCompMDGPR,
+                           STEPConstruct_DataMapOfAsciiStringTransient& theDPDCs,
+                           STEPConstruct_DataMapOfPointTransient&       theColRGBs,
+                           const Handle(XCAFDoc_ShapeTool)&             theShTool,
+                           const XCAFPrs_Style*                         theInherit,
+                           const Standard_Boolean                       theIsComponent,
+                           const Standard_Boolean                       theVisMaterialMode)
 {
-  const Handle(StepData_StepModel) aModel =
-    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
-  aModel->InternalParameters.InitFromStatic();
-  return Transfer(theLabel, aModel->InternalParameters, theMode, theIsMulti, theProgress);
-}
-
-//=================================================================================================
+  // skip already processed shapes
+  if (!theMap.Add(theShape))
+    return;
 
-Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_Label&                theLabel,
-                                                 const DESTEP_Parameters&        theParams,
-                                                 const STEPControl_StepModelType theMode,
-                                                 const Standard_CString          theIsMulti,
-                                                 const Message_ProgressRange&    theProgress)
-{
-  if (theLabel.IsNull())
+  // check if shape has its own style (r inherits from ancestor)
+  XCAFPrs_Style aStyle;
+  if (theInherit)
+    aStyle = *theInherit;
+  if (theSettings.Contains(theShape))
   {
-    return Standard_False;
+    const XCAFPrs_Style& anOwnStyle = theSettings.FindFromKey(theShape);
+    if (!anOwnStyle.IsVisible())
+      aStyle.SetVisibility(Standard_False);
+    if (anOwnStyle.IsSetColorCurv())
+      aStyle.SetColorCurv(anOwnStyle.GetColorCurv());
+    if (anOwnStyle.IsSetColorSurf())
+      aStyle.SetColorSurf(anOwnStyle.GetColorSurfRGBA());
+    if (!anOwnStyle.Material().IsNull())
+      aStyle.SetMaterial(anOwnStyle.Material());
   }
-  TDF_LabelSequence aLabels;
-  aLabels.Append(theLabel);
-  myRootLabels.Clear();
-  myRootLabels.Add(theLabel.Root());
-  const Handle(StepData_StepModel) aModel =
-    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
-  aModel->InternalParameters = theParams;
-  return transfer(myWriter, aLabels, theMode, theIsMulti, Standard_False, theProgress);
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_LabelSequence&        theLabels,
-                                                 const STEPControl_StepModelType theMode,
-                                                 const Standard_CString          theIsMulti,
-                                                 const Message_ProgressRange&    theProgress)
-{
-  const Handle(StepData_StepModel) aModel =
-    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
-  aModel->InternalParameters.InitFromStatic();
-  return Transfer(theLabels, aModel->InternalParameters, theMode, theIsMulti, theProgress);
-}
-
-//=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_LabelSequence&        theLabels,
-                                                 const DESTEP_Parameters&        theParams,
-                                                 const STEPControl_StepModelType theMode,
-                                                 const Standard_CString          theIsMulti,
-                                                 const Message_ProgressRange&    theProgress)
-{
-  myRootLabels.Clear();
-  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
+  // translate colors to STEP
+  Handle(StepVisual_Colour) aSurfColor, aCurvColor;
+  Standard_Real             aRenderTransp = 0.0;
+  if (aStyle.IsSetColorSurf())
   {
-    const TDF_Label& aLabel = aLabelIter.Value();
-    if (!aLabel.IsNull())
-    {
-      myRootLabels.Add(aLabel.Root());
-    }
+    Quantity_ColorRGBA aSurfCol = aStyle.GetColorSurfRGBA();
+    aRenderTransp               = 1.0 - aSurfCol.Alpha();
+    aSurfColor                  = theStyles.EncodeColor(aSurfCol.GetRGB(), theDPDCs, theColRGBs);
   }
-  const Handle(StepData_StepModel) aModel =
-    Handle(StepData_StepModel)::DownCast(myWriter.WS()->Model());
-  aModel->InternalParameters = theParams;
-  return transfer(myWriter, theLabels, theMode, theIsMulti, Standard_False, theProgress);
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::Perform(const Handle(TDocStd_Document)& theDoc,
-                                                const Standard_CString          theFileName,
-                                                const Message_ProgressRange&    theProgress)
-{
-  if (!Transfer(theDoc, STEPControl_AsIs, 0L, theProgress))
-    return Standard_False;
-  return Write(theFileName) == IFSelect_RetDone;
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::Perform(const Handle(TDocStd_Document)& theDoc,
-                                                const Standard_CString          theFileName,
-                                                const DESTEP_Parameters&        theParams,
-                                                const Message_ProgressRange&    theProgress)
-{
-  if (!Transfer(theDoc, theParams, STEPControl_AsIs, 0L, theProgress))
-    return Standard_False;
-  return Write(theFileName) == IFSelect_RetDone;
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::Perform(const Handle(TDocStd_Document)& theDoc,
-                                                const TCollection_AsciiString&  theFileName,
-                                                const Message_ProgressRange&    theProgress)
-{
-  if (!Transfer(theDoc, STEPControl_AsIs, 0L, theProgress))
-    return Standard_False;
-  return Write(theFileName.ToCString()) == IFSelect_RetDone;
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::ExternFile(
-  const TDF_Label&                   theLabel,
-  Handle(STEPCAFControl_ExternFile)& theExtFile) const
-{
-  theExtFile.Nullify();
-  if (!myLabEF.IsBound(theLabel))
-    return Standard_False;
-  theExtFile = myLabEF.Find(theLabel);
-  return Standard_True;
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::ExternFile(
-  const Standard_CString             theName,
-  Handle(STEPCAFControl_ExternFile)& theExtFile) const
-{
-  theExtFile.Nullify();
-  if (!myFiles.IsEmpty() || !myFiles.IsBound(theName))
-    return Standard_False;
-  theExtFile = myFiles.Find(theName);
-  return Standard_True;
-}
-
-//=============================================================================
-
-void STEPCAFControl_Writer::SetShapeFixParameters(
-  const XSAlgo_ShapeProcessor::ParameterMap& theParameters)
-{
-  myWriter.SetShapeFixParameters(theParameters);
-}
-
-//=============================================================================
-
-void STEPCAFControl_Writer::SetShapeFixParameters(
-  XSAlgo_ShapeProcessor::ParameterMap&& theParameters)
-{
-  myWriter.SetShapeFixParameters(std::move(theParameters));
-}
-
-//=============================================================================
-
-void STEPCAFControl_Writer::SetShapeFixParameters(
-  const DE_ShapeFixParameters&               theParameters,
-  const XSAlgo_ShapeProcessor::ParameterMap& theAdditionalParameters)
-{
-  myWriter.SetShapeFixParameters(theParameters, theAdditionalParameters);
-}
+  if (aStyle.IsSetColorCurv())
+    aCurvColor = theStyles.EncodeColor(aStyle.GetColorCurv(), theDPDCs, theColRGBs);
 
-//=============================================================================
+  Standard_Boolean aHasOwn = (!aSurfColor.IsNull() || !aCurvColor.IsNull() || !aStyle.IsVisible());
 
-const XSAlgo_ShapeProcessor::ParameterMap& STEPCAFControl_Writer::GetShapeFixParameters() const
-{
-  return myWriter.GetShapeFixParameters();
-}
+  // find target item and assign style to it
+  Handle(StepVisual_StyledItem) aSTEPstyle = theOverride;
+  if (aHasOwn)
+  {
+    if (theShape.ShapeType() != TopAbs_COMPOUND || theIsComponent)
+    { // skip compounds, let subshapes inherit its colors
+      TopLoc_Location             aLocation;
+      TColStd_SequenceOfTransient aSeqRI;
+      Standard_Integer            aNbEntities =
+        FindEntities(theStyles.FinderProcess(), theShape, aLocation, aSeqRI);
+      if (aNbEntities <= 0)
+        Message::SendTrace() << "Warning: Cannot find RI for "
+                             << theShape.TShape()->DynamicType()->Name() << "\n";
+      // Get overridden style gka 10.06.03
+      if (theIsComponent && aNbEntities > 0)
+        getStyledItem(theShape, theShTool, theStyles, theOverride, theMapCompMDGPR);
 
-//=============================================================================
+      for (TColStd_SequenceOfTransient::Iterator anEntIter(aSeqRI); anEntIter.More();
+           anEntIter.Next())
+      {
+        const Handle(StepRepr_RepresentationItem)& anItem =
+          Handle(StepRepr_RepresentationItem)::DownCast(anEntIter.Value());
+        Handle(StepVisual_PresentationStyleAssignment) aPSA;
+        if (aStyle.IsVisible() || !aSurfColor.IsNull() || !aCurvColor.IsNull()
+            || (theVisMaterialMode && !aStyle.Material().IsNull() && !aStyle.Material()->IsEmpty()))
+        {
+          STEPConstruct_RenderingProperties aRenderProps;
+          if (theVisMaterialMode && !aStyle.Material().IsNull() && !aStyle.Material()->IsEmpty())
+          {
+            aRenderProps.Init(aStyle.Material());
+          }
+          else if (aRenderTransp > 0.0)
+          {
+            aRenderProps.Init(aStyle.GetColorSurfRGBA());
+          }
+          aPSA =
+            theStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aRenderProps, theIsComponent);
+        }
+        else
+        {
+          // default white color
+          aSurfColor =
+            theStyles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE), theDPDCs, theColRGBs);
+          aPSA = theStyles.MakeColorPSA(anItem,
+                                        aSurfColor,
+                                        aCurvColor,
+                                        STEPConstruct_RenderingProperties(),
+                                        theIsComponent);
+          if (theIsComponent)
+            setDefaultInstanceColor(theOverride, aPSA);
 
-void STEPCAFControl_Writer::SetShapeProcessFlags(const ShapeProcess::OperationsFlags& theFlags)
-{
-  myWriter.SetShapeProcessFlags(theFlags);
-}
+        } // end of component case
 
-//=============================================================================
+        aSTEPstyle = theStyles.AddStyle(anItem, aPSA, theOverride);
+        aHasOwn    = Standard_False;
+      }
+    }
+  }
 
-const XSAlgo_ShapeProcessor::ProcessingFlags& STEPCAFControl_Writer::GetShapeProcessFlags() const
-{
-  return myWriter.GetShapeProcessFlags();
+  // iterate on subshapes (except vertices :)
+  if (theShape.ShapeType() == TopAbs_EDGE)
+    return;
+  if (theIsComponent)
+  {
+    return;
+  }
+  for (TopoDS_Iterator anIter(theShape); anIter.More(); anIter.Next())
+  {
+    MakeSTEPStyles(theStyles,
+                   anIter.Value(),
+                   theSettings,
+                   aSTEPstyle,
+                   theMap,
+                   theMapCompMDGPR,
+                   theDPDCs,
+                   theColRGBs,
+                   theShTool,
+                   (aHasOwn ? &aStyle : 0),
+                   Standard_False,
+                   theVisMaterialMode);
+  }
 }
 
 //=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::transfer(STEPControl_Writer&             theWriter,
-                                                 const TDF_LabelSequence&        theLabels,
-                                                 const STEPControl_StepModelType theMode,
-                                                 const Standard_CString          theIsMulti,
-                                                 const Standard_Boolean          theIsExternFile,
-                                                 const Message_ProgressRange&    theProgress)
+Standard_Boolean STEPCAFControl_Writer::writeColors(const Handle(XSControl_WorkSession)& theWS,
+                                                    const TDF_LabelSequence&             theLabels)
 {
   if (theLabels.IsEmpty())
     return Standard_False;
 
-  Handle(STEPCAFControl_ActorWrite) anActor =
-    Handle(STEPCAFControl_ActorWrite)::DownCast(theWriter.WS()->NormAdaptor()->ActorWrite());
-
-  StepData_Factors                 aLocalFactors;
-  const Handle(StepData_StepModel) aModel =
-    Handle(StepData_StepModel)::DownCast(theWriter.WS()->Model());
-  prepareUnit(theLabels.First(), aModel, aLocalFactors); // set local length unit to the model
-  // translate free top-level shapes of the DECAF document
-  TDF_LabelSequence     aSubLabels;
-  Message_ProgressScope aPS(theProgress, "Labels", theLabels.Length());
+  STEPConstruct_Styles                        Styles(theWS);
+  STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
+  STEPConstruct_DataMapOfPointTransient       ColRGBs;
   // Iterate on requested shapes
-  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More() && aPS.More();
-       aLabelIter.Next())
+  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
   {
-    Message_ProgressRange aRange = aPS.Next();
-    TDF_Label             aCurL  = aLabelIter.Value();
-    if (myLabels.IsBound(aCurL))
-      continue; // already processed
-
-    Handle(TDataStd_UAttribute) aSupGeomAttr;
-    if (aCurL.FindAttribute(XCAFDoc::SupplementalContainerGUID(), aSupGeomAttr))
-    {
-      continue;
-    }
-
-    TopoDS_Shape aCurShape = XCAFDoc_ShapeTool::GetShape(aCurL);
-    if (aCurShape.IsNull())
-      continue;
-    TopoDS_Shape aShapeForBind = aCurShape;
-    // write shape either as a whole, or as multifile (with extern refs)
-    if (!theIsMulti)
+    const TDF_Label aLabel = aLabelIter.Value();
+    // Iterate on shapes in the document
+    Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(aLabel);
+    // Skip assemblies: colors assigned to assemblies and their instances
+    // are not supported (it is not clear how to encode that in STEP)
+    if (XCAFDoc_ShapeTool::IsAssembly(aLabel))
     {
-      anActor->SetStdMode(Standard_False);
+      Message::SendTrace() << "Warning: Cannot write color  for Assembly" << "\n";
+      Message::SendTrace() << "Info: Check for colors assigned to components in assembly" << "\n";
+      // PTV 22.01.2003 Write color for instances.
+      TDF_LabelSequence compLabels;
+      if (!aSTool->GetComponents(aLabel, compLabels))
+        continue;
+      writeColors(theWS, compLabels);
+      continue;
+    }
+    Styles.ClearStyles();
 
-      TDF_LabelSequence aCompLabels;
+    // get a target shape and try to find corresponding context
+    // (all the colors set under that label will be put into that context)
+    TopoDS_Shape aShape;
+    if (!XCAFDoc_ShapeTool::GetShape(aLabel, aShape))
+      continue;
+    Standard_Boolean anIsComponent = aSTool->IsComponent(aLabel) || myPureRefLabels.IsBound(aLabel);
+    TopoDS_Shape     aTopSh        = aShape;
+    Handle(StepRepr_RepresentationContext) aContext = Styles.FindContext(aShape);
+    if (anIsComponent)
+    {
+      TDF_Label aTopShL = aSTool->FindShape(aShape, Standard_False);
+      if (aTopShL.IsNull())
+        continue;
+      aTopSh   = aSTool->GetShape(aTopShL);
+      aContext = Styles.FindContext(aTopSh);
+    }
+    if (aContext.IsNull())
+      continue;
 
-      // For case when only part of assembly structure should be written in the document
-      // if specified label is component of the assembly then
-      // in order to save location of this component in the high-level assembly
-      // and save name of high-level assembly it is necessary to represent structure of high-level
-      // assembly as assembly with one component specified by current label. For that compound
-      // containing only specified component is binded to the label of the high-level assembly. The
-      // such way full structure of high-level assembly was replaced on the assembly containing one
-      // component. For case when free shape reference is (located root) also create an auxiliary
-      // assembly.
-      if (XCAFDoc_ShapeTool::IsReference(aCurL))
+    // collect settings set on that label
+    XCAFPrs_IndexedDataMapOfShapeStyle aSettings;
+    TDF_LabelSequence                  aSeq;
+    aSeq.Append(aLabel);
+    XCAFDoc_ShapeTool::GetSubShapes(aLabel, aSeq);
+    Standard_Boolean anIsVisible = Standard_True;
+    for (TDF_LabelSequence::Iterator aSeqIter(aSeq); aSeqIter.More(); aSeqIter.Next())
+    {
+      const TDF_Label&   aSeqValue = aSeqIter.Value();
+      XCAFPrs_Style      aStyle;
+      Quantity_ColorRGBA aColor;
+      if (aSeqValue == aLabel)
       {
-        TopoDS_Compound aComp;
-        BRep_Builder    aB;
-        aB.MakeCompound(aComp);
-        aB.Add(aComp, aCurShape);
-        aCurShape = aComp;
-        myPureRefLabels.Bind(aCurL, aComp);
-        aCompLabels.Append(aCurL);
-        TDF_Label aRefL;
-        if (XCAFDoc_ShapeTool::GetReferredShape(aCurL, aRefL))
+        // check for invisible status of object on label
+        if (!XCAFDoc_ColorTool::IsVisible(aSeqValue))
         {
-          if (XCAFDoc_ShapeTool::IsAssembly(aRefL))
-            XCAFDoc_ShapeTool::GetComponents(aRefL, aCompLabels, Standard_True);
+          anIsVisible = Standard_False;
+          aStyle.SetVisibility(Standard_False);
         }
-        if (!XCAFDoc_ShapeTool::IsFree(aCurL))
-          aCurL = aCurL.Father();
       }
-      else
+      if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorGen, aColor))
       {
-        // fill sequence of (sub) shapes for which attributes should be written
-        // and set actor to handle assemblies in a proper way
-        if (XCAFDoc_ShapeTool::IsAssembly(aCurL))
-          XCAFDoc_ShapeTool::GetComponents(aCurL, aCompLabels, Standard_True);
+        aStyle.SetColorCurv(aColor.GetRGB());
+        aStyle.SetColorSurf(aColor);
       }
-
-      for (TDF_LabelSequence::Iterator aCompIter(aCompLabels); aCompIter.More(); aCompIter.Next())
+      if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorSurf, aColor))
+        aStyle.SetColorSurf(aColor);
+      if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorCurv, aColor))
+        aStyle.SetColorCurv(aColor.GetRGB());
+      if (!aStyle.IsSetColorSurf())
       {
-        const TDF_Label aCurSubShL = aCompIter.Value();
-        if (myLabels.IsBound(aCurSubShL))
-        {
-          continue;
-        }
-        const TopoDS_Shape aCurSh = XCAFDoc_ShapeTool::GetShape(aCurSubShL);
-        if (aCurSh.IsNull())
-        {
-          continue;
-        }
-        myLabels.Bind(aCurSubShL, aCurSh);
-        aSubLabels.Append(aCurSubShL);
-        TDF_Label aRefL;
-        if (!XCAFDoc_ShapeTool::GetReferredShape(aCurSubShL, aRefL))
-        {
-          continue;
-        }
-        if (!myLabels.IsBound(aRefL))
+        Handle(XCAFDoc_VisMaterial) aVisMat = XCAFDoc_VisMaterialTool::GetShapeMaterial(aSeqValue);
+        if (!aVisMat.IsNull() && !aVisMat->IsEmpty())
         {
-          TopoDS_Shape aRefSh = XCAFDoc_ShapeTool::GetShape(aRefL);
-          myLabels.Bind(aRefL, aRefSh);
-          aSubLabels.Append(aRefL);
-          if (XCAFDoc_ShapeTool::IsAssembly(aRefL))
-          {
-            anActor->RegisterAssembly(aRefSh);
-          }
+          // only color can be stored in STEP
+          aStyle.SetColorSurf(aVisMat->BaseColor());
         }
       }
-      myLabels.Bind(aCurL, aShapeForBind);
-      aSubLabels.Append(aCurL);
-
-      if (XCAFDoc_ShapeTool::IsAssembly(aCurL) || XCAFDoc_ShapeTool::IsReference(aCurL))
-        anActor->RegisterAssembly(aCurShape);
-
-      theWriter.Transfer(aCurShape, theMode, aModel->InternalParameters, Standard_False, aRange);
-      anActor->SetStdMode(Standard_True); // restore default behaviour
-    }
-    else
-    {
-      // translate final solids
-      Message_ProgressScope aPS1(aRange, NULL, 2);
-      TopoDS_Shape          aSass =
-        transferExternFiles(aCurL, theMode, aSubLabels, aLocalFactors, theIsMulti, aPS1.Next());
-      if (aPS1.UserBreak())
-        return Standard_False;
+      if (!aStyle.IsSetColorCurv() && !aStyle.IsSetColorSurf() && anIsVisible)
+        continue;
 
-      DESTEP_Parameters::WriteMode_Assembly assemblymode = aModel->InternalParameters.WriteAssembly;
-      aModel->InternalParameters.WriteAssembly           = DESTEP_Parameters::WriteMode_Assembly_On;
-      theWriter.Transfer(aSass,
-                         STEPControl_AsIs,
-                         aModel->InternalParameters,
-                         Standard_True,
-                         aPS1.Next());
-      aModel->InternalParameters.WriteAssembly = assemblymode;
+      TopoDS_Shape   aSub      = XCAFDoc_ShapeTool::GetShape(aSeqValue);
+      XCAFPrs_Style* aMapStyle = aSettings.ChangeSeek(aSub);
+      if (aMapStyle == NULL)
+        aSettings.Add(aSub, aStyle);
+      else
+        *aMapStyle = aStyle;
     }
-  }
-  if (aPS.UserBreak())
-    return Standard_False;
 
-  theWriter.WS()->ComputeGraph(Standard_True); // Setting to clear and regenerate graph
+    if (aSettings.Extent() <= 0)
+      continue;
 
-  // write names
-  if (GetNameMode())
-    writeNames(theWriter.WS(), aSubLabels);
+    // iterate on subshapes and create STEP styles
+    Handle(StepVisual_StyledItem) anOverride;
+    TopTools_MapOfShape           aMap;
 
-  if (!theIsMulti)
-  {
-    // write colors
-    if (GetColorMode())
-      writeColors(theWriter.WS(), aSubLabels);
+    MakeSTEPStyles(Styles,
+                   aShape,
+                   aSettings,
+                   anOverride,
+                   aMap,
+                   myMapCompMDGPR,
+                   DPDCs,
+                   ColRGBs,
+                   aSTool,
+                   0,
+                   anIsComponent,
+                   GetVisualMaterialMode());
 
-    // write layers
-    if (GetLayerMode())
-      writeLayers(theWriter.WS(), aSubLabels);
+    const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
+    const Handle(Transfer_FinderProcess)&   aFP = aTW->FinderProcess();
+    Handle(StepData_StepModel) aStepModel = Handle(StepData_StepModel)::DownCast(aFP->Model());
 
-    // write SHUO entities
-    if (GetSHUOMode() && !theIsExternFile)
-      // do not store SHUO for extern reference for the moment
-      writeSHUOs(theWriter.WS(), aSubLabels);
+    // create MDGPR and record it in model
+    Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
 
-    // write G&DTs
-    if (GetDimTolMode())
+    if (!anIsComponent)
     {
-      if (aModel->InternalParameters.WriteSchema == 5)
-      {
-        writeDGTsAP242(theWriter.WS(), aSubLabels, aLocalFactors);
-      }
-      else
+      if (myMapCompMDGPR.IsBound(aTopSh))
       {
-        writeDGTs(theWriter.WS(), aSubLabels);
+        Message::SendTrace() << "Error: Current Top-Level shape have MDGPR already " << "\n";
       }
+      Styles.CreateMDGPR(aContext, aMDGPR, aStepModel);
+      if (!aMDGPR.IsNull())
+        myMapCompMDGPR.Bind(aTopSh, aMDGPR);
     }
-
-    // write Materials
-    if (GetMaterialMode())
-      writeMaterials(theWriter.WS(), aSubLabels);
-
-    // register all MDGPRs in model
-    for (MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR); anItr.More();
-         anItr.Next())
+    else
     {
-      aModel->AddWithRefs(anItr.Value());
-    }
-  }
-
-  if (theIsMulti)
-  { // external refs
-    writeExternRefs(theWriter.WS(), aSubLabels);
-  }
-
-  // write validation props
-  if (GetPropsMode())
-    writeValProps(theWriter.WS(), aSubLabels, theIsMulti);
-
-  // write metadata
-  if (GetMetadataMode())
-    writeMetadata(theWriter.WS(), aSubLabels);
-
-  // refresh graph
-  theWriter.WS()->ComputeGraph(Standard_True);
+      // create SDR and add to model.
+      Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, aShape);
+      Handle(StepShape_ContextDependentShapeRepresentation) aCDSR;
+      if (aFP->FindTypedTransient(aMapper,
+                                  STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
+                                  aCDSR))
+      {
+        // create SDR for NAUO
+        Handle(StepRepr_ProductDefinitionShape) aNullPDS; // important to be NULL
+        Styles.CreateNAUOSRD(aContext, aCDSR, aNullPDS);
 
-  // Write names for the sub-shapes
-  if (aModel->InternalParameters.WriteSubshapeNames != 0)
-  {
-    const Handle(XSControl_TransferWriter)& TW  = this->ChangeWriter().WS()->TransferWriter();
-    const Handle(Transfer_FinderProcess)&   aFP = TW->FinderProcess();
+        // search for MDGPR of the component top-level shape
+        if (myMapCompMDGPR.IsBound(aTopSh))
+        {
+          aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast(
+            myMapCompMDGPR.Find(aTopSh));
+        }
+        else
+        {
+          aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
+          Handle(TCollection_HAsciiString) aReprName = new TCollection_HAsciiString("");
+          aMDGPR->SetName(aReprName);
+          aMDGPR->SetContextOfItems(aContext);
+          myMapCompMDGPR.Bind(aTopSh, aMDGPR);
+        }
+        Handle(StepRepr_HArray1OfRepresentationItem) anOldItems   = aMDGPR->Items();
+        Standard_Integer                             oldLengthlen = 0;
+        if (!anOldItems.IsNull())
+          oldLengthlen = anOldItems->Length();
+        const Standard_Integer aNbIt = oldLengthlen + Styles.NbStyles();
+        if (!aNbIt)
+          continue;
+        Handle(StepRepr_HArray1OfRepresentationItem) aNewItems =
+          new StepRepr_HArray1OfRepresentationItem(1, aNbIt);
+        Standard_Integer anElemInd = 1;
+        for (Standard_Integer aStyleInd = 1; aStyleInd <= oldLengthlen; aStyleInd++)
+        {
+          aNewItems->SetValue(anElemInd++, anOldItems->Value(aStyleInd));
+        }
+        for (Standard_Integer aStyleInd = 1; aStyleInd <= Styles.NbStyles(); aStyleInd++)
+        {
+          aNewItems->SetValue(anElemInd++, Styles.Style(aStyleInd));
+        }
 
-    // Iterate on requested sub shapes
-    for (TDF_LabelSequence::Iterator aLabelIter(aSubLabels); aLabelIter.More(); aLabelIter.Next())
+        if (aNewItems->Length() > 0)
+          aMDGPR->SetItems(aNewItems);
+      } // end of work with CDSR
+    }
+    if (!anIsVisible)
     {
-      const TDF_Label& aCurL = aLabelIter.Value();
-
-      for (TDF_ChildIterator aChildIter(aCurL, Standard_True); aChildIter.More(); aChildIter.Next())
+      // create invisibility item and refer for styledItem
+      Handle(StepVisual_Invisibility)           anInvisibility = new StepVisual_Invisibility();
+      Handle(StepVisual_HArray1OfInvisibleItem) anInvisibilitySeq =
+        new StepVisual_HArray1OfInvisibleItem(1, Styles.NbStyles());
+      // put all style item into the harray
+      for (Standard_Integer aStyleInd = 1; aStyleInd <= Styles.NbStyles(); aStyleInd++)
       {
-        const TDF_Label& aSubL = aChildIter.Value();
-
-        // Access name recorded in OCAF TDataStd_Name attribute
-        Handle(TCollection_HAsciiString) aHSubName = new TCollection_HAsciiString;
-        if (!GetLabelName(aSubL, aHSubName))
-          continue;
-
-        // Access topological data
-        TopoDS_Shape aSubS = XCAFDoc_ShapeTool::GetShape(aSubL);
-        if (aSubS.IsNull())
-          continue;
-
-        // Access the correspondent STEP Representation Item
-        Handle(StepRepr_RepresentationItem) aRI;
-        Handle(TransferBRep_ShapeMapper)    aShMapper = TransferBRep::ShapeMapper(aFP, aSubS);
-        if (!aFP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), aRI))
-          continue;
-
-        // Record the name
-        aRI->SetName(aHSubName);
+        Handle(StepRepr_RepresentationItem) aStyledItm = Styles.Style(aStyleInd);
+        StepVisual_InvisibleItem            anInvItem;
+        anInvItem.SetValue(aStyledItm);
+        anInvisibilitySeq->SetValue(aStyleInd, anInvItem);
       }
+      // set the invisibility of items
+      anInvisibility->Init(anInvisibilitySeq);
+      theWS->Model()->AddWithRefs(anInvisibility);
     }
   }
-
   return Standard_True;
 }
 
 //=================================================================================================
 
-TopoDS_Shape STEPCAFControl_Writer::transferExternFiles(const TDF_Label&                theLabel,
-                                                        const STEPControl_StepModelType theMode,
-                                                        TDF_LabelSequence&              theLabels,
-                                                        const StepData_Factors& theLocalFactors,
-                                                        const Standard_CString  thePrefix,
-                                                        const Message_ProgressRange& theProgress)
+Standard_Boolean STEPCAFControl_Writer::writeNames(const Handle(XSControl_WorkSession)& theWS,
+                                                   const TDF_LabelSequence& theLabels) const
 {
-  // if label already translated, just return the shape
-  if (myLabels.IsBound(theLabel))
-  {
-    return myLabels.Find(theLabel);
-  }
+  if (theLabels.IsEmpty())
+    return Standard_False;
 
-  TopoDS_Compound aComp;
-  BRep_Builder    aBuilder;
-  aBuilder.MakeCompound(aComp);
-  // if not assembly, write to separate file
-  if (!XCAFDoc_ShapeTool::IsAssembly(theLabel) && !XCAFDoc_ShapeTool::IsComponent(theLabel))
-  {
-    theLabels.Append(theLabel);
-    // prepare for transfer
-    Handle(XSControl_WorkSession) aNewWS = new XSControl_WorkSession;
-    aNewWS->SelectNorm("STEP");
-    STEPControl_Writer aStepWriter(aNewWS, Standard_True);
-    TDF_LabelSequence  aLabelSeq;
-    aLabelSeq.Append(theLabel);
+  // get working data
+  const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
+  const Handle(Transfer_FinderProcess)&   aFP = aTW->FinderProcess();
 
-    // construct the name for extern file
-    Handle(TCollection_HAsciiString) aBaseName = new TCollection_HAsciiString;
-    if (thePrefix && thePrefix[0])
-      aBaseName->AssignCat(thePrefix);
-    GetLabelName(theLabel, aBaseName);
-    Handle(TCollection_HAsciiString) aNewName = new TCollection_HAsciiString(aBaseName);
-    aNewName->AssignCat(".stp");
-    if (myFiles.IsBound(aNewName->ToCString()))
-    { // avoid confusions
-      for (Standard_Integer k = 1; k < 32000; k++)
+  // Iterate on requested shapes
+  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
+  {
+    const TDF_Label& aLabel = aLabelIter.Value();
+    // find target STEP entity for the current shape
+    if (!myLabels.IsBound(aLabel))
+      continue; // not recorded as translated, skip
+    // get name
+    Handle(TCollection_HAsciiString) aHName = new TCollection_HAsciiString;
+    if (!GetLabelName(aLabel, aHName))
+    {
+      continue;
+    }
+    const TopoDS_Shape&                                   aShape = myLabels.Find(aLabel);
+    Handle(StepShape_ShapeDefinitionRepresentation)       aSDR;
+    Handle(StepShape_ContextDependentShapeRepresentation) aCDSR;
+    Standard_Boolean                                      isComponent =
+      XCAFDoc_ShapeTool::IsComponent(aLabel) || myPureRefLabels.IsBound(aLabel);
+    Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, aShape);
+    if (isComponent
+        && aFP->FindTypedTransient(aMapper,
+                                   STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
+                                   aCDSR))
+    {
+      Handle(StepRepr_ProductDefinitionShape)         aPDS = aCDSR->RepresentedProductRelation();
+      Handle(StepBasic_ProductDefinitionRelationship) aNAUO =
+        aPDS->Definition().ProductDefinitionRelationship();
+      if (!aNAUO.IsNull())
+        aNAUO->SetName(aHName);
+      TopoDS_Shape anInternalAssembly;
+      if (myPureRefLabels.Find(aLabel, anInternalAssembly))
       {
-        aNewName = new TCollection_HAsciiString(aBaseName);
-        aNewName->AssignCat("_");
-        aNewName->AssignCat(TCollection_AsciiString(k).ToCString());
-        aNewName->AssignCat(".stp");
-        if (!myFiles.IsBound(aNewName->ToCString()))
-          break;
+        Handle(TransferBRep_ShapeMapper) aMapperOfInternalShape =
+          TransferBRep::ShapeMapper(aFP, anInternalAssembly);
+        aFP->FindTypedTransient(aMapperOfInternalShape,
+                                STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
+                                aSDR);
       }
     }
+    if (!aSDR.IsNull()
+        || (aCDSR.IsNull()
+            && aFP->FindTypedTransient(aMapper,
+                                       STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
+                                       aSDR)))
+    {
+      // set the name to the PRODUCT
+      Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
+      if (aPropD.IsNull())
+        continue;
+      Handle(StepBasic_ProductDefinition) aPD = aPropD->Definition().ProductDefinition();
+      if (aPD.IsNull())
+        continue;
+      Handle(StepBasic_Product) aProd = aPD->Formation()->OfProduct();
 
-    // translate and record extern file
-    Handle(STEPCAFControl_ExternFile) anExtFile = new STEPCAFControl_ExternFile;
-    anExtFile->SetWS(aNewWS);
-    anExtFile->SetName(aNewName);
-    anExtFile->SetLabel(theLabel);
-    DESTEP_Parameters::WriteMode_Assembly anAssemblymode =
-      aStepWriter.Model()->InternalParameters.WriteAssembly;
-    aStepWriter.Model()->InternalParameters.WriteAssembly =
-      DESTEP_Parameters::WriteMode_Assembly_Off;
-    const Standard_CString anIsMulti = 0;
-    anExtFile->SetTransferStatus(
-      transfer(aStepWriter, aLabelSeq, theMode, anIsMulti, Standard_True, theProgress));
-    aStepWriter.Model()->InternalParameters.WriteAssembly = anAssemblymode;
-    myLabEF.Bind(theLabel, anExtFile);
-    myFiles.Bind(aNewName->ToCString(), anExtFile);
-
-    // return empty compound as replacement for the shape
-    myLabels.Bind(theLabel, aComp);
-    return aComp;
+      aProd->SetId(aHName);
+      aProd->SetName(aHName);
+    }
+    else
+    {
+      Message::SendTrace() << "Warning: Cannot find RI for "
+                           << aShape.TShape()->DynamicType()->Name() << "\n";
+      continue;
+    }
   }
-  TDF_LabelSequence aCompLabels;
-  TDF_Label         aLabel = theLabel;
-  // if specified shape is component then high-level assembly is considered
-  // to get valid structure with location
-  if (XCAFDoc_ShapeTool::IsComponent(theLabel))
+  return Standard_True;
+}
+
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::writeMetadata(const Handle(XSControl_WorkSession)& theWS,
+                                                      const TDF_LabelSequence& theLabels) const
+{
+  if (theLabels.IsEmpty())
   {
-    aCompLabels.Append(theLabel);
-    aLabel = theLabel.Father();
+    return Standard_False;
   }
-  // else iterate on components add create structure of empty compounds
-  // representing the assembly
-  else if (XCAFDoc_ShapeTool::IsAssembly(theLabel))
-    XCAFDoc_ShapeTool::GetComponents(theLabel, aCompLabels, Standard_False);
 
-  theLabels.Append(aLabel);
-  Message_ProgressScope aPS(theProgress, NULL, aCompLabels.Length());
-  // Iterate on requested shapes
-  for (TDF_LabelSequence::Iterator aLabelIter(aCompLabels); aLabelIter.More() && aPS.More();
-       aLabelIter.Next())
+  // Iterate on requested shapes.
+  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
   {
-    const TDF_Label& aCurL = aLabelIter.Value();
-    TDF_Label        aRefL;
-    if (!XCAFDoc_ShapeTool::GetReferredShape(aCurL, aRefL))
-      continue;
-    TopoDS_Shape aShComp =
-      transferExternFiles(aRefL, theMode, theLabels, theLocalFactors, thePrefix, aPS.Next());
-    aShComp.Location(XCAFDoc_ShapeTool::GetLocation(aCurL));
-    aBuilder.Add(aComp, aShComp);
+    writeMetadataForLabel(theWS, aLabelIter.Value());
   }
-  myLabels.Bind(aLabel, aComp);
-  return aComp;
+
+  return Standard_True;
 }
 
 //=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::writeExternRefs(const Handle(XSControl_WorkSession)& theWS,
-                                                        const TDF_LabelSequence& theLabels) const
+Standard_Boolean STEPCAFControl_Writer::writeMetadataForLabel(
+  const Handle(XSControl_WorkSession)& theWS,
+  const TDF_Label&                     theLabel) const
 {
-  if (theLabels.IsEmpty())
+  if (theLabel.IsNull())
+  {
     return Standard_False;
+  }
 
+  // Get working data:
   const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
   const Handle(Transfer_FinderProcess)&   aFP = aTW->FinderProcess();
-  STEPConstruct_ExternRefs                anEFTool(theWS);
-  Handle(StepData_StepModel) aStepModel  = Handle(StepData_StepModel)::DownCast(theWS->Model());
-  Standard_Integer           aStepSchema = aStepModel->InternalParameters.WriteSchema;
-  // Iterate on requested shapes
-  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
+  const Handle(StepData_StepModel)& aModel = Handle(StepData_StepModel)::DownCast(theWS->Model());
+
+  // Check if label has metadata (NamedData):
+  Handle(TDataStd_NamedData) aNamedData;
+  if (!theLabel.FindAttribute(TDataStd_NamedData::GetID(), aNamedData))
+    return Standard_False; // No metadata on this label
+
+  // Find target STEP entity for the current shape:
+  if (!myLabels.IsBound(theLabel))
+    return Standard_False; // Not recorded as translated, skip
+
+  const TopoDS_Shape&                             aShape = myLabels.Find(theLabel);
+  Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
+  const Handle(TransferBRep_ShapeMapper)          aMapper = TransferBRep::ShapeMapper(aFP, aShape);
+  if (!aFP->FindTypedTransient(aMapper,
+                               STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
+                               aSDR))
   {
-    const TDF_Label& aLab = aLabelIter.Value();
-    if (XCAFDoc_ShapeTool::IsAssembly(aLab))
-      continue; // skip assemblies
+    return Standard_False; // Cannot find STEP representation
+  }
 
-    // get extern file
-    Handle(STEPCAFControl_ExternFile) anExtFile;
-    if (!ExternFile(aLab, anExtFile))
-      continue; // should never be
+  // Get the product definition from the shape definition representation:
+  const Handle(StepRepr_PropertyDefinition) aPropDef = aSDR->Definition().PropertyDefinition();
+  if (aPropDef.IsNull())
+    return Standard_False;
+  const Handle(StepBasic_ProductDefinition) aProdDef = aPropDef->Definition().ProductDefinition();
+  if (aProdDef.IsNull())
+    return Standard_False;
 
-    // find SDR
-    if (!myLabels.IsBound(aLab))
-      continue; // not recorded as translated, skip
-    TopoDS_Shape aShape = myLabels.Find(aLab);
+  // Export string metadata.
+  const TDataStd_DataMapOfStringString& aStringMap = aNamedData->GetStringsContainer();
+  for (TDataStd_DataMapOfStringString::Iterator anIter(aStringMap); anIter.More(); anIter.Next())
+  {
+    const TCollection_ExtendedString& aKey   = anIter.Key();
+    const TCollection_ExtendedString& aValue = anIter.Value();
 
-    Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
-    Handle(TransferBRep_ShapeMapper)                mapper = TransferBRep::ShapeMapper(aFP, aShape);
-    if (!aFP->FindTypedTransient(mapper,
-                                 STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
-                                 aSDR))
+    // Create descriptive representation item for the value.
+    const Handle(StepRepr_DescriptiveRepresentationItem) aDescrItem =
+      new StepRepr_DescriptiveRepresentationItem();
+    const Handle(TCollection_HAsciiString) aItemName  = new TCollection_HAsciiString(aKey);
+    const Handle(TCollection_HAsciiString) aItemValue = new TCollection_HAsciiString(aValue);
+    aDescrItem->SetName(aItemName);
+    aDescrItem->SetDescription(aItemValue);
+
+    writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aDescrItem);
+  }
+
+  // Export integer metadata.
+  const TColStd_DataMapOfStringInteger& aIntMap = aNamedData->GetIntegersContainer();
+  for (TColStd_DataMapOfStringInteger::Iterator anIter(aIntMap); anIter.More(); anIter.Next())
+  {
+    const TCollection_ExtendedString& aKey   = anIter.Key();
+    const Standard_Integer            aValue = anIter.Value();
+    // Create integer representation item for the value.
+    const Handle(StepRepr_IntegerRepresentationItem) aIntItem =
+      new StepRepr_IntegerRepresentationItem();
+    const Handle(TCollection_HAsciiString) aItemName = new TCollection_HAsciiString(aKey);
+    aIntItem->Init(aItemName, aValue);
+
+    writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aIntItem);
+  }
+
+  // Export real metadata.
+  const TDataStd_DataMapOfStringReal& aRealMap = aNamedData->GetRealsContainer();
+  for (TDataStd_DataMapOfStringReal::Iterator anIter(aRealMap); anIter.More(); anIter.Next())
+  {
+    const TCollection_ExtendedString& aKey   = anIter.Key();
+    const Standard_Real               aValue = anIter.Value();
+    // Create real representation item for the value.
+    const Handle(StepRepr_RealRepresentationItem) aRealItem = new StepRepr_RealRepresentationItem();
+    const Handle(TCollection_HAsciiString)        aItemName = new TCollection_HAsciiString(aKey);
+    aRealItem->Init(aItemName, aValue);
+
+    writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aRealItem);
+  }
+
+  // Process label children recursively:
+  if (theLabel.HasChild())
+  {
+    for (Standard_Integer aChildInd = 1; aChildInd <= theLabel.NbChildren(); aChildInd++)
     {
-      Message::SendTrace() << "Warning: Cannot find SDR for "
-                           << aShape.TShape()->DynamicType()->Name() << "\n";
-      continue;
+      const TDF_Label& aChildLabel = theLabel.FindChild(aChildInd);
+      writeMetadataForLabel(theWS, aChildLabel);
     }
+  }
 
-    // add extern ref
-    const char* aStepFormat = (aStepSchema == 3 ? "STEP AP203" : "STEP AP214");
-    // try to get PD from SDR
-    StepRepr_RepresentedDefinition      aRD      = aSDR->Definition();
-    Handle(StepRepr_PropertyDefinition) aPropDef = aRD.PropertyDefinition();
-    if (aPropDef.IsNull())
+  return Standard_True;
+}
+
+//=================================================================================================
+
+void STEPCAFControl_Writer::writeMetadataRepresentationItem(
+  const TCollection_AsciiString&                        theKey,
+  const Handle(StepData_StepModel)&                     theModel,
+  const Handle(StepShape_ShapeDefinitionRepresentation) theShapeDefRep,
+  const Handle(StepBasic_ProductDefinition)&            theProdDef,
+  const Handle(StepRepr_RepresentationItem)&            theItem) const
+{
+  // Empty string to use for empty values:
+  const Handle(TCollection_HAsciiString) anEmptyStr = new TCollection_HAsciiString("");
+
+  // Create property_definition:
+  const Handle(StepRepr_PropertyDefinition) aMetaPropDef = new StepRepr_PropertyDefinition();
+  const Handle(TCollection_HAsciiString)    aPropName    = new TCollection_HAsciiString(theKey);
+  const Handle(TCollection_HAsciiString)    aPropDesc =
+    new TCollection_HAsciiString("user defined attribute");
+  aMetaPropDef->SetName(aPropName);
+  aMetaPropDef->SetDescription(aPropDesc);
+
+  // Create a general_property:
+  const Handle(StepBasic_GeneralProperty) aGeneralProp = new StepBasic_GeneralProperty();
+  aGeneralProp->SetId(anEmptyStr);
+  aGeneralProp->SetName(aPropName);
+  aGeneralProp->SetDescription(anEmptyStr);
+
+  // Create a general_property_association:
+  const Handle(StepBasic_GeneralPropertyAssociation) aGeneralPropAssoc =
+    new StepBasic_GeneralPropertyAssociation();
+  aGeneralPropAssoc->SetName(anEmptyStr);
+  aGeneralPropAssoc->SetDescription(anEmptyStr);
+  aGeneralPropAssoc->SetPropertyDefinition(aMetaPropDef);
+  aGeneralPropAssoc->SetGeneralProperty(aGeneralProp);
+
+  // Set the definition to point to the product definition:
+  StepRepr_CharacterizedDefinition aCharDef;
+  aCharDef.SetValue(theProdDef);
+  aMetaPropDef->SetDefinition(aCharDef);
+
+  // Create property_definition_representation:
+  const Handle(StepRepr_PropertyDefinitionRepresentation) aPropDefRepr =
+    new StepRepr_PropertyDefinitionRepresentation();
+  StepRepr_RepresentedDefinition aRepDef;
+  aRepDef.SetValue(aMetaPropDef);
+  aPropDefRepr->SetDefinition(aRepDef);
+
+  // Create representation with descriptive_representation_item:
+  const Handle(StepRepr_Representation)  aRepr     = new StepRepr_Representation();
+  const Handle(TCollection_HAsciiString) aReprName = new TCollection_HAsciiString(theKey);
+  aRepr->SetName(aReprName);
+
+  // Add item to representation:
+  const Handle(StepRepr_HArray1OfRepresentationItem) aItems =
+    new StepRepr_HArray1OfRepresentationItem(1, 1);
+  aItems->SetValue(1, theItem);
+  aRepr->SetItems(aItems);
+
+  // Set representation context (reuse from shape representation):
+  const Handle(StepRepr_RepresentationContext) aRC =
+    theShapeDefRep->UsedRepresentation()->ContextOfItems();
+  aRepr->SetContextOfItems(aRC);
+
+  aPropDefRepr->SetUsedRepresentation(aRepr);
+
+  // Add entities to the model:
+  theModel->AddWithRefs(aMetaPropDef);
+  theModel->AddWithRefs(aGeneralProp);
+  theModel->AddWithRefs(aGeneralPropAssoc);
+  theModel->AddWithRefs(aPropDefRepr);
+  theModel->AddWithRefs(aRepr);
+  theModel->AddWithRefs(theItem);
+}
+
+//=================================================================================================
+
+static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession)&      theWS,
+                                           const STEPCAFControl_DataMapOfLabelShape& theLabels,
+                                           const TDF_Label&                          theLabel,
+                                           const Standard_CString                    theIsMulti)
+{
+  if (theLabel.IsNull())
+    return Standard_False;
+
+  STEPConstruct_ValidationProps aProps(theWS);
+
+  TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theLabel);
+  if (aShape.IsNull())
+    return Standard_False;
+
+  if (!theIsMulti || XCAFDoc_ShapeTool::IsAssembly(theLabel))
+  {
+    // write area
+    Handle(XCAFDoc_Area) anArea;
+    theLabel.FindAttribute(XCAFDoc_Area::GetID(), anArea);
+    if (!anArea.IsNull())
     {
-      Message::SendTrace() << "Warning: STEPCAFControl_Writer::writeExternRefs "
-                              "StepRepr_PropertyDefinition is null for "
-                           << aShape.TShape()->DynamicType()->Name() << "\n";
-      continue;
+      aProps.AddArea(aShape, anArea->Get());
     }
-    StepRepr_CharacterizedDefinition    aCharDef = aPropDef->Definition();
-    Handle(StepBasic_ProductDefinition) aPD      = aCharDef.ProductDefinition();
-    if (aPD.IsNull())
+    // write volume
+    Handle(XCAFDoc_Volume) aVolume;
+    theLabel.FindAttribute(XCAFDoc_Volume::GetID(), aVolume);
+    if (!aVolume.IsNull())
     {
-      Message::SendTrace() << "Warning: STEPCAFControl_Writer::writeExternRefs "
-                              "StepBasic_ProductDefinition is null for "
-                           << aShape.TShape()->DynamicType()->Name() << "\n";
-      continue;
+      aProps.AddVolume(aShape, aVolume->Get());
     }
-    anEFTool.AddExternRef(anExtFile->GetName()->ToCString(), aPD, aStepFormat);
   }
-  anEFTool.WriteExternRefs(aStepSchema);
+  // write centroid
+  Handle(XCAFDoc_Centroid) aCentroid;
+  theLabel.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid);
+  if (!aCentroid.IsNull())
+  {
+    aProps.AddCentroid(aShape, aCentroid->Get());
+  }
+
+  if (XCAFDoc_ShapeTool::IsCompound(theLabel) || XCAFDoc_ShapeTool::IsAssembly(theLabel))
+  {
+    if (theLabel.HasChild())
+    {
+      for (Standard_Integer aChildInd = 1; aChildInd <= theLabel.NbChildren(); aChildInd++)
+      {
+        WritePropsForLabel(theWS, theLabels, theLabel.FindChild(aChildInd), theIsMulti);
+      }
+    }
+  }
+
   return Standard_True;
 }
 
 //=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::writeColors(const Handle(XSControl_WorkSession)& theWS,
-                                                    const TDF_LabelSequence&             theLabels)
+Standard_Boolean STEPCAFControl_Writer::writeValProps(const Handle(XSControl_WorkSession)& theWS,
+                                                      const TDF_LabelSequence& theLabels,
+                                                      const Standard_CString   theIsMulti) const
 {
   if (theLabels.IsEmpty())
     return Standard_False;
 
-  STEPConstruct_Styles                        Styles(theWS);
-  STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
-  STEPConstruct_DataMapOfPointTransient       ColRGBs;
   // Iterate on requested shapes
   for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
   {
-    const TDF_Label aLabel = aLabelIter.Value();
-    // Iterate on shapes in the document
-    Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(aLabel);
-    // Skip assemblies: colors assigned to assemblies and their instances
-    // are not supported (it is not clear how to encode that in STEP)
-    if (XCAFDoc_ShapeTool::IsAssembly(aLabel))
-    {
-      Message::SendTrace() << "Warning: Cannot write color  for Assembly" << "\n";
-      Message::SendTrace() << "Info: Check for colors assigned to components in assembly" << "\n";
-      // PTV 22.01.2003 Write color for instances.
-      TDF_LabelSequence compLabels;
-      if (!aSTool->GetComponents(aLabel, compLabels))
-        continue;
-      writeColors(theWS, compLabels);
-      continue;
-    }
-    Styles.ClearStyles();
+    const TDF_Label& aLabel = aLabelIter.Value();
 
-    // get a target shape and try to find corresponding context
-    // (all the colors set under that label will be put into that context)
-    TopoDS_Shape aShape;
-    if (!XCAFDoc_ShapeTool::GetShape(aLabel, aShape))
+    WritePropsForLabel(theWS, myLabels, aLabel, theIsMulti);
+  }
+
+  return Standard_True;
+}
+
+//=================================================================================================
+
+Standard_Boolean STEPCAFControl_Writer::writeLayers(const Handle(XSControl_WorkSession)& theWS,
+                                                    const TDF_LabelSequence& theLabels) const
+{
+
+  if (theLabels.IsEmpty())
+    return Standard_False;
+
+  // get working data
+  const Handle(Interface_InterfaceModel)& aModel = theWS->Model();
+  const Handle(XSControl_TransferWriter)& aTW    = theWS->TransferWriter();
+  const Handle(Transfer_FinderProcess)&   aFP    = aTW->FinderProcess();
+  TDF_LabelSequence                       aGlobalLayerLS;
+  // Iterate on requested shapes collect Tools
+  for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); aLabelIter.More(); aLabelIter.Next())
+  {
+    const TDF_Label&          aLabel = aLabelIter.Value();
+    Handle(XCAFDoc_LayerTool) aLTool = XCAFDoc_DocumentTool::LayerTool(aLabel);
+    TDF_LabelSequence         aLayerLS;
+    aLTool->GetLayerLabels(aLayerLS);
+    aGlobalLayerLS.Append(aLayerLS);
+  }
+  for (TDF_LabelSequence::Iterator aLayerIter(aGlobalLayerLS); aLayerIter.More(); aLayerIter.Next())
+  {
+    const TDF_Label& aLayerL = aLayerIter.Value();
+    // get labels of shapes in that layer
+    TDF_LabelSequence aShapeLabels;
+    XCAFDoc_LayerTool::GetShapesOfLayer(aLayerL, aShapeLabels);
+    if (aShapeLabels.IsEmpty())
       continue;
-    Standard_Boolean anIsComponent = aSTool->IsComponent(aLabel) || myPureRefLabels.IsBound(aLabel);
-    TopoDS_Shape     aTopSh        = aShape;
-    Handle(StepRepr_RepresentationContext) aContext = Styles.FindContext(aShape);
-    if (anIsComponent)
+
+    // name of layer: if not set, is considered as being empty
+    Handle(TCollection_HAsciiString) aHName = new TCollection_HAsciiString;
+    GetLabelName(aLayerL, aHName);
+
+    // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment
+    // items.
+    TColStd_SequenceOfTransient aSeqRI;
+    for (TDF_LabelSequence::Iterator aShapeIter(aShapeLabels); aShapeIter.More(); aShapeIter.Next())
     {
-      TDF_Label aTopShL = aSTool->FindShape(aShape, Standard_False);
-      if (aTopShL.IsNull())
+      const TDF_Label& aShLabel = aShapeIter.Value();
+      if (aShLabel.IsNull())
         continue;
-      aTopSh   = aSTool->GetShape(aTopShL);
-      aContext = Styles.FindContext(aTopSh);
-    }
-    if (aContext.IsNull())
-      continue;
 
-    // collect settings set on that label
-    XCAFPrs_IndexedDataMapOfShapeStyle aSettings;
-    TDF_LabelSequence                  aSeq;
-    aSeq.Append(aLabel);
-    XCAFDoc_ShapeTool::GetSubShapes(aLabel, aSeq);
-    Standard_Boolean anIsVisible = Standard_True;
-    for (TDF_LabelSequence::Iterator aSeqIter(aSeq); aSeqIter.More(); aSeqIter.Next())
-    {
-      const TDF_Label&   aSeqValue = aSeqIter.Value();
-      XCAFPrs_Style      aStyle;
-      Quantity_ColorRGBA aColor;
-      if (aSeqValue == aLabel)
-      {
-        // check for invisible status of object on label
-        if (!XCAFDoc_ColorTool::IsVisible(aSeqValue))
-        {
-          anIsVisible = Standard_False;
-          aStyle.SetVisibility(Standard_False);
-        }
-      }
-      if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorGen, aColor))
+      // there is no way to assign layer to instance in STEP
+      if (XCAFDoc_ShapeTool::IsAssembly(aShLabel) || XCAFDoc_ShapeTool::IsReference(aShLabel))
       {
-        aStyle.SetColorCurv(aColor.GetRGB());
-        aStyle.SetColorSurf(aColor);
+        continue;
       }
-      if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorSurf, aColor))
-        aStyle.SetColorSurf(aColor);
-      if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorCurv, aColor))
-        aStyle.SetColorCurv(aColor.GetRGB());
-      if (!aStyle.IsSetColorSurf())
+      // check that the shape is one of (uub)labels written during current transfer
+      Standard_Boolean anIsWritten = Standard_False;
+      for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
       {
-        Handle(XCAFDoc_VisMaterial) aVisMat = XCAFDoc_VisMaterialTool::GetShapeMaterial(aSeqValue);
-        if (!aVisMat.IsNull() && !aVisMat->IsEmpty())
+        if (aShLabel.IsDescendant(aLabelIter.Value()))
         {
-          // only color can be stored in STEP
-          aStyle.SetColorSurf(aVisMat->BaseColor());
+          anIsWritten = Standard_True;
+          break;
         }
       }
-      if (!aStyle.IsSetColorCurv() && !aStyle.IsSetColorSurf() && anIsVisible)
+      if (!anIsWritten)
+      {
         continue;
+      }
 
-      TopoDS_Shape   aSub      = XCAFDoc_ShapeTool::GetShape(aSeqValue);
-      XCAFPrs_Style* aMapStyle = aSettings.ChangeSeek(aSub);
-      if (aMapStyle == NULL)
-        aSettings.Add(aSub, aStyle);
-      else
-        *aMapStyle = aStyle;
-    }
+      // get target STEP entity
+      TopoDS_Shape anOneShape = XCAFDoc_ShapeTool::GetShape(aShLabel);
 
-    if (aSettings.Extent() <= 0)
+      TopLoc_Location  aLoc;
+      Standard_Integer aNb = FindEntities(aFP, anOneShape, aLoc, aSeqRI);
+      if (aNb <= 0)
+      {
+        Message::SendTrace() << "Warning: Cannot find RI for "
+                             << anOneShape.TShape()->DynamicType()->Name() << "\n";
+      }
+    }
+    if (aSeqRI.IsEmpty())
       continue;
 
-    // iterate on subshapes and create STEP styles
-    Handle(StepVisual_StyledItem) anOverride;
-    TopTools_MapOfShape           aMap;
+    // analyze visibility
+    Handle(StepVisual_PresentationLayerAssignment) aStepLayerAs =
+      new StepVisual_PresentationLayerAssignment;
+    Handle(TCollection_HAsciiString) aDescr;
+    Handle(TDataStd_UAttribute)      aUAttr;
+    Standard_Boolean                 isLinv = Standard_False;
+    if (aLayerL.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr))
+    {
+      aDescr = new TCollection_HAsciiString("invisible");
+      Message::SendTrace() << "\tLayer \"" << aHName->String().ToCString() << "\" is invisible"
+                           << "\n";
+      isLinv = Standard_True;
+    }
+    else
+    {
+      aDescr = new TCollection_HAsciiString("visible");
+    }
 
-    MakeSTEPStyles(Styles,
-                   aShape,
-                   aSettings,
-                   anOverride,
-                   aMap,
-                   myMapCompMDGPR,
-                   DPDCs,
-                   ColRGBs,
-                   aSTool,
-                   0,
-                   anIsComponent,
-                   GetVisualMaterialMode());
+    // create layer entity
+    Standard_Integer                        anSetStyleInd = 1;
+    Handle(StepVisual_HArray1OfLayeredItem) aHArrayOfLItem =
+      new StepVisual_HArray1OfLayeredItem(1, aSeqRI.Length());
+    for (TColStd_SequenceOfTransient::Iterator aRIIter(aSeqRI); aRIIter.More(); aRIIter.Next())
+    {
+      StepVisual_LayeredItem aLI;
+      aLI.SetValue(aRIIter.Value());
+      aHArrayOfLItem->SetValue(anSetStyleInd++, aLI);
+    }
+    aStepLayerAs->Init(aHName, aDescr, aHArrayOfLItem);
+    aModel->AddWithRefs(aStepLayerAs);
+    // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
+    // add the invisibility for the layer
+    if (isLinv)
+    {
+      // Invisibility Item for containing invisible layers.
+      Handle(StepVisual_HArray1OfInvisibleItem) aHInvsblItm =
+        new StepVisual_HArray1OfInvisibleItem(1, 1);
+      StepVisual_InvisibleItem aInvIt;
+      aInvIt.SetValue(aStepLayerAs);
+      aHInvsblItm->SetValue(1, aInvIt);
 
-    const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
-    const Handle(Transfer_FinderProcess)&   aFP = aTW->FinderProcess();
-    Handle(StepData_StepModel) aStepModel = Handle(StepData_StepModel)::DownCast(aFP->Model());
+      Handle(StepVisual_Invisibility) aInvsblt = new StepVisual_Invisibility();
+      aInvsblt->Init(aHInvsblItm);
+      aModel->AddWithRefs(aInvsblt);
+    }
+  }
+  return Standard_True;
+}
 
-    // create MDGPR and record it in model
-    Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
+//=================================================================================================
 
-    if (!anIsComponent)
+static Standard_Boolean getSHUOstyle(const TDF_Label& theSHUOlab, XCAFPrs_Style& theSHUOstyle)
+{
+  Quantity_Color aColor;
+  if (!XCAFDoc_ColorTool::IsVisible(theSHUOlab))
+  {
+    theSHUOstyle.SetVisibility(Standard_False);
+  }
+  else
+  {
+    if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorGen, aColor))
     {
-      if (myMapCompMDGPR.IsBound(aTopSh))
-      {
-        Message::SendTrace() << "Error: Current Top-Level shape have MDGPR already " << "\n";
-      }
-      Styles.CreateMDGPR(aContext, aMDGPR, aStepModel);
-      if (!aMDGPR.IsNull())
-        myMapCompMDGPR.Bind(aTopSh, aMDGPR);
+      theSHUOstyle.SetColorCurv(aColor);
+      theSHUOstyle.SetColorSurf(aColor);
     }
-    else
+    if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorSurf, aColor))
+      theSHUOstyle.SetColorSurf(aColor);
+    if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorCurv, aColor))
+      theSHUOstyle.SetColorCurv(aColor);
+    if (!theSHUOstyle.IsSetColorSurf())
     {
-      // create SDR and add to model.
-      Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, aShape);
-      Handle(StepShape_ContextDependentShapeRepresentation) aCDSR;
-      if (aFP->FindTypedTransient(aMapper,
-                                  STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
-                                  aCDSR))
+      Handle(XCAFDoc_VisMaterial) aVisMat = XCAFDoc_VisMaterialTool::GetShapeMaterial(theSHUOlab);
+      if (!aVisMat.IsNull() && !aVisMat->IsEmpty())
       {
-        // create SDR for NAUO
-        Handle(StepRepr_ProductDefinitionShape) aNullPDS; // important to be NULL
-        Styles.CreateNAUOSRD(aContext, aCDSR, aNullPDS);
+        // only color can be stored in STEP
+        theSHUOstyle.SetColorSurf(aVisMat->BaseColor());
+      }
+    }
+  }
+  if (!theSHUOstyle.IsSetColorCurv() && !theSHUOstyle.IsSetColorSurf() && theSHUOstyle.IsVisible())
+  {
+    return Standard_False;
+  }
+  return Standard_True;
+}
 
-        // search for MDGPR of the component top-level shape
-        if (myMapCompMDGPR.IsBound(aTopSh))
-        {
-          aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast(
-            myMapCompMDGPR.Find(aTopSh));
-        }
-        else
-        {
-          aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
-          Handle(TCollection_HAsciiString) aReprName = new TCollection_HAsciiString("");
-          aMDGPR->SetName(aReprName);
-          aMDGPR->SetContextOfItems(aContext);
-          myMapCompMDGPR.Bind(aTopSh, aMDGPR);
-        }
-        Handle(StepRepr_HArray1OfRepresentationItem) anOldItems   = aMDGPR->Items();
-        Standard_Integer                             oldLengthlen = 0;
-        if (!anOldItems.IsNull())
-          oldLengthlen = anOldItems->Length();
-        const Standard_Integer aNbIt = oldLengthlen + Styles.NbStyles();
-        if (!aNbIt)
-          continue;
-        Handle(StepRepr_HArray1OfRepresentationItem) aNewItems =
-          new StepRepr_HArray1OfRepresentationItem(1, aNbIt);
-        Standard_Integer anElemInd = 1;
-        for (Standard_Integer aStyleInd = 1; aStyleInd <= oldLengthlen; aStyleInd++)
-        {
-          aNewItems->SetValue(anElemInd++, anOldItems->Value(aStyleInd));
-        }
-        for (Standard_Integer aStyleInd = 1; aStyleInd <= Styles.NbStyles(); aStyleInd++)
-        {
-          aNewItems->SetValue(anElemInd++, Styles.Style(aStyleInd));
-        }
+//=================================================================================================
 
-        if (aNewItems->Length() > 0)
-          aMDGPR->SetItems(aNewItems);
-      } // end of work with CDSR
-    }
-    if (!anIsVisible)
+static Standard_Boolean getProDefinitionOfNAUO(
+  const Handle(XSControl_WorkSession)&          theWS,
+  const TopoDS_Shape&                           theShape,
+  Handle(StepBasic_ProductDefinition)&          thePD,
+  Handle(StepRepr_NextAssemblyUsageOccurrence)& theNAUO,
+  Standard_Boolean                              theIsRelating)
+{
+  if (theShape.IsNull())
+    return Standard_False;
+  // get CDSR
+  const Handle(XSControl_TransferWriter)&               aTW = theWS->TransferWriter();
+  const Handle(Transfer_FinderProcess)&                 aFP = aTW->FinderProcess();
+  Handle(StepShape_ContextDependentShapeRepresentation) aCDSR;
+  Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, theShape);
+  if (!aFP->FindTypedTransient(aMapper,
+                               STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
+                               aCDSR))
+  {
+    return Standard_False;
+  }
+  // get PDS of NAUO
+  Handle(StepRepr_ProductDefinitionShape) aPDS = aCDSR->RepresentedProductRelation();
+  if (aPDS.IsNull())
+    return Standard_False;
+  // get the NAUO entity
+  Interface_Graph aGraph = theWS->HGraph()->Graph();
+  for (Interface_EntityIterator aShareds = aGraph.Shareds(aPDS); aShareds.More(); aShareds.Next())
+  {
+    theNAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(aShareds.Value());
+    if (!theNAUO.IsNull())
     {
-      // create invisibility item and refer for styledItem
-      Handle(StepVisual_Invisibility)           anInvisibility = new StepVisual_Invisibility();
-      Handle(StepVisual_HArray1OfInvisibleItem) anInvisibilitySeq =
-        new StepVisual_HArray1OfInvisibleItem(1, Styles.NbStyles());
-      // put all style item into the harray
-      for (Standard_Integer aStyleInd = 1; aStyleInd <= Styles.NbStyles(); aStyleInd++)
-      {
-        Handle(StepRepr_RepresentationItem) aStyledItm = Styles.Style(aStyleInd);
-        StepVisual_InvisibleItem            anInvItem;
-        anInvItem.SetValue(aStyledItm);
-        anInvisibilitySeq->SetValue(aStyleInd, anInvItem);
-      }
-      // set the invisibility of items
-      anInvisibility->Init(anInvisibilitySeq);
-      theWS->Model()->AddWithRefs(anInvisibility);
+      break;
     }
   }
+  if (theNAUO.IsNull())
+    return Standard_False;
+  // get Relatinf or Related product definition
+  if (!theIsRelating)
+    thePD = theNAUO->RelatedProductDefinition();
+  else
+    thePD = theNAUO->RelatingProductDefinition();
+  if (thePD.IsNull())
+    return Standard_False;
   return Standard_True;
 }
 
 //=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::writeNames(const Handle(XSControl_WorkSession)& theWS,
-                                                   const TDF_LabelSequence& theLabels) const
+static Standard_Boolean writeSHUO(const Handle(XCAFDoc_GraphNode)&                 theSHUO,
+                                  const Handle(XSControl_WorkSession)&             theWS,
+                                  Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
+                                  TopoDS_Shape&                                    theNAUOShape,
+                                  Handle(StepBasic_ProductDefinition)&             theRelatingPD,
+                                  Standard_Boolean&                                theIsDeepest)
 {
-  if (theLabels.IsEmpty())
-    return Standard_False;
-
-  // get working data
-  const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
-  const Handle(Transfer_FinderProcess)&   aFP = aTW->FinderProcess();
+  // set the ProductDefinitionRelationship descriptin information as empty strings.
+  Handle(TCollection_HAsciiString) anEmptyString = new TCollection_HAsciiString("");
 
-  // Iterate on requested shapes
-  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
+  TDF_LabelSequence aNextUsageLabs;
+  XCAFDoc_ShapeTool::GetSHUONextUsage(theSHUO->Label(), aNextUsageLabs);
+  Handle(XCAFDoc_GraphNode) aNuSHUO;
+  if (theTopSHUO.IsNull())
   {
-    const TDF_Label& aLabel = aLabelIter.Value();
-    // find target STEP entity for the current shape
-    if (!myLabels.IsBound(aLabel))
-      continue; // not recorded as translated, skip
-    // get name
-    Handle(TCollection_HAsciiString) aHName = new TCollection_HAsciiString;
-    if (!GetLabelName(aLabel, aHName))
+    // the top SHUO
+    if (aNextUsageLabs.Length() < 1)
+      return Standard_False;
+    XCAFDoc_ShapeTool::GetSHUO(aNextUsageLabs.Value(1), aNuSHUO);
+    if (aNuSHUO.IsNull())
+      return Standard_False;
+    // get relating product definition
+    TopoDS_Shape aTopCompShape = XCAFDoc_ShapeTool::GetShape(theSHUO->Label().Father());
+    Handle(StepRepr_NextAssemblyUsageOccurrence) aRelatingNAUO;
+    if (!getProDefinitionOfNAUO(theWS, aTopCompShape, theRelatingPD, aRelatingNAUO, Standard_True))
     {
-      continue;
+      return Standard_False;
     }
-    const TopoDS_Shape&                                   aShape = myLabels.Find(aLabel);
-    Handle(StepShape_ShapeDefinitionRepresentation)       aSDR;
-    Handle(StepShape_ContextDependentShapeRepresentation) aCDSR;
-    Standard_Boolean                                      isComponent =
-      XCAFDoc_ShapeTool::IsComponent(aLabel) || myPureRefLabels.IsBound(aLabel);
-    Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, aShape);
-    if (isComponent
-        && aFP->FindTypedTransient(aMapper,
-                                   STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
-                                   aCDSR))
+    // get related product definition
+    TopoDS_Shape aNUShape = XCAFDoc_ShapeTool::GetShape(aNuSHUO->Label().Father());
+    Handle(StepBasic_ProductDefinition)          aRelatedPD;
+    Handle(StepRepr_NextAssemblyUsageOccurrence) aRelatedNAUO;
+    if (!getProDefinitionOfNAUO(theWS, aNUShape, aRelatedPD, aRelatedNAUO, Standard_False))
     {
-      Handle(StepRepr_ProductDefinitionShape)         aPDS = aCDSR->RepresentedProductRelation();
-      Handle(StepBasic_ProductDefinitionRelationship) aNAUO =
-        aPDS->Definition().ProductDefinitionRelationship();
-      if (!aNAUO.IsNull())
-        aNAUO->SetName(aHName);
-      TopoDS_Shape anInternalAssembly;
-      if (myPureRefLabels.Find(aLabel, anInternalAssembly))
-      {
-        Handle(TransferBRep_ShapeMapper) aMapperOfInternalShape =
-          TransferBRep::ShapeMapper(aFP, anInternalAssembly);
-        aFP->FindTypedTransient(aMapperOfInternalShape,
-                                STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
-                                aSDR);
-      }
+      return Standard_False;
     }
-    if (!aSDR.IsNull()
-        || (aCDSR.IsNull()
-            && aFP->FindTypedTransient(aMapper,
-                                       STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
-                                       aSDR)))
+
+    theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
+    // create deepest shuo EmptyString
+    theTopSHUO->Init(/*id*/ anEmptyString,
+                     /*name*/ anEmptyString,
+                     /*no description*/ Standard_False,
+                     /*description*/ anEmptyString,
+                     theRelatingPD,
+                     aRelatedPD,
+                     /*no ACURefDesignator*/ Standard_False,
+                     /*ACURefDesignator*/ anEmptyString,
+                     /*upper_usage*/ aRelatingNAUO,
+                     /*next_usage*/ aRelatedNAUO);
+    // write the other SHUO.
+    if (!writeSHUO(aNuSHUO, theWS, theTopSHUO, theNAUOShape, theRelatingPD, theIsDeepest))
     {
-      // set the name to the PRODUCT
-      Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
-      if (aPropD.IsNull())
-        continue;
-      Handle(StepBasic_ProductDefinition) aPD = aPropD->Definition().ProductDefinition();
-      if (aPD.IsNull())
-        continue;
-      Handle(StepBasic_Product) aProd = aPD->Formation()->OfProduct();
+      theTopSHUO.Nullify();
+      return Standard_False;
+    }
 
-      aProd->SetId(aHName);
-      aProd->SetName(aHName);
+    return Standard_True;
+  }
+  //   Handle(XCAFDoc_GraphNode) NuSHUO;
+  if (aNextUsageLabs.Length() > 0)
+  {
+    // store SHUO recursive
+    if (aNextUsageLabs.Length() > 1)
+      Message::SendTrace() << "Warning: store only one next_usage of current SHUO" << "\n";
+    XCAFDoc_ShapeTool::GetSHUO(aNextUsageLabs.Value(1), aNuSHUO);
+    Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
+      new StepRepr_SpecifiedHigherUsageOccurrence;
+    if (!writeSHUO(aNuSHUO, theWS, aNUEntSHUO, theNAUOShape, theRelatingPD, theIsDeepest))
+      return Standard_False;
+
+    // store the deepest SHUO to the dociment
+    TopoDS_Shape aNUSh, aUUSh;
+    aNUSh = XCAFDoc_ShapeTool::GetShape(aNuSHUO->Label().Father());
+    aUUSh = XCAFDoc_ShapeTool::GetShape(theSHUO->Label().Father());
+    // get relating PD with upper_usage and related PD with next_usage
+    Handle(StepBasic_ProductDefinition) nullPD; // no need to use,case have shared <theRelatingPD>
+    Handle(StepBasic_ProductDefinition) aRelatedPD;
+    Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
+    if (!getProDefinitionOfNAUO(theWS, aUUSh, nullPD, UUNAUO, Standard_True)
+        || !getProDefinitionOfNAUO(theWS, aNUSh, aRelatedPD, NUNAUO, Standard_False))
+    {
+      Message::SendTrace() << "Warning: cannot get related or relating PD" << "\n";
+      return Standard_False;
     }
-    else
+    aNUEntSHUO->Init(/*id*/ anEmptyString,
+                     /*name*/ anEmptyString,
+                     /*no description*/ Standard_False,
+                     /*description*/ anEmptyString,
+                     theRelatingPD,
+                     aRelatedPD,
+                     /*no ACURefDesignator*/ Standard_False,
+                     /*ACURefDesignator*/ anEmptyString,
+                     /*upper_usage*/ theTopSHUO,
+                     /*next_usage*/ NUNAUO);
+    if (theIsDeepest)
     {
-      Message::SendTrace() << "Warning: Cannot find RI for "
-                           << aShape.TShape()->DynamicType()->Name() << "\n";
-      continue;
+      theIsDeepest = Standard_False;
     }
-  }
+    theWS->Model()->AddWithRefs(aNUEntSHUO);
+    return Standard_True;
+  } // end of recurse storing
+
+  // get shape
+  TDF_Label aShapeL = theSHUO->Label().Father();
+  theNAUOShape      = XCAFDoc_ShapeTool::GetShape(aShapeL);
+  // return to the deepest level from SHUO shape level
+  // it is because SHUO is attribute on deep level and shape level.
+  theIsDeepest = Standard_True;
   return Standard_True;
 }
 
 //=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::writeMetadata(const Handle(XSControl_WorkSession)& theWS,
-                                                      const TDF_LabelSequence& theLabels) const
+static Standard_Boolean createSHUOStyledItem(const XCAFPrs_Style& theStyle,
+                                             const Handle(StepRepr_ProductDefinitionShape)& thePDS,
+                                             const Handle(XSControl_WorkSession)&           theWS,
+                                             const TopoDS_Shape&               theShape,
+                                             const Handle(XCAFDoc_ShapeTool)&  theSTool,
+                                             MoniTool_DataMapOfShapeTransient& theMapCompMDGPR)
 {
-  if (theLabels.IsEmpty())
+  // create styled item for the indicated SHUO and store to the model
+  STEPConstruct_Styles aStyles(theWS);
+  // translate colors to STEP
+  Handle(StepVisual_Colour) aSurfColor, aCurvColor;
+  Standard_Real             aRenderTransp = 0.0;
+  if (theStyle.IsSetColorSurf())
   {
-    return Standard_False;
+    Quantity_ColorRGBA aSurfCol = theStyle.GetColorSurfRGBA();
+    aRenderTransp               = 1.0 - aSurfCol.Alpha();
+    aSurfColor                  = aStyles.EncodeColor(aSurfCol.GetRGB());
   }
-
-  // Iterate on requested shapes.
-  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
+  if (theStyle.IsSetColorCurv())
+    aCurvColor = aStyles.EncodeColor(theStyle.GetColorCurv());
+  Standard_Boolean                    isComponent = Standard_True; // cause need to get PSBC
+  Handle(StepRepr_RepresentationItem) anItem;
+  // set default color for invisible SHUO.
+  Standard_Boolean isSetDefaultColor = Standard_False;
+  if (aSurfColor.IsNull() && aCurvColor.IsNull() && !theStyle.IsVisible())
   {
-    writeMetadataForLabel(theWS, aLabelIter.Value());
+    aSurfColor        = aStyles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE));
+    isSetDefaultColor = Standard_True;
   }
-
-  return Standard_True;
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::writeMetadataForLabel(
-  const Handle(XSControl_WorkSession)& theWS,
-  const TDF_Label&                     theLabel) const
-{
-  if (theLabel.IsNull())
+  STEPConstruct_RenderingProperties aRenderProps;
+  if (aRenderTransp > 0.0)
   {
-    return Standard_False;
+    aRenderProps.Init(theStyle.GetColorSurfRGBA());
   }
+  Handle(StepVisual_PresentationStyleAssignment) aPSA =
+    aStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aRenderProps, isComponent);
+  Handle(StepVisual_StyledItem) anOverride; // null styled item
 
-  // Get working data:
+  // find the repr item of the shape
   const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
   const Handle(Transfer_FinderProcess)&   aFP = aTW->FinderProcess();
-  const Handle(StepData_StepModel)& aModel = Handle(StepData_StepModel)::DownCast(theWS->Model());
-
-  // Check if label has metadata (NamedData):
-  Handle(TDataStd_NamedData) aNamedData;
-  if (!theLabel.FindAttribute(TDataStd_NamedData::GetID(), aNamedData))
-    return Standard_False; // No metadata on this label
-
-  // Find target STEP entity for the current shape:
-  if (!myLabels.IsBound(theLabel))
-    return Standard_False; // Not recorded as translated, skip
-
-  const TopoDS_Shape&                             aShape = myLabels.Find(theLabel);
-  Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
-  const Handle(TransferBRep_ShapeMapper)          aMapper = TransferBRep::ShapeMapper(aFP, aShape);
-  if (!aFP->FindTypedTransient(aMapper,
-                               STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
-                               aSDR))
+  Handle(StepData_StepModel)       aStepModel = Handle(StepData_StepModel)::DownCast(aFP->Model());
+  Handle(TransferBRep_ShapeMapper) aMapper    = TransferBRep::ShapeMapper(aFP, theShape);
+  Handle(StepShape_ContextDependentShapeRepresentation) aCDSR;
+  aFP->FindTypedTransient(aMapper,
+                          STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
+                          aCDSR);
+  if (aCDSR.IsNull())
+    return Standard_False;
+  // find context
+  Handle(StepRepr_RepresentationContext) aContext = aStyles.FindContext(theShape);
+  TopoDS_Shape                           aTopSh   = theShape;
+  if (aContext.IsNull())
   {
-    return Standard_False; // Cannot find STEP representation
+    TDF_Label aTopShL = theSTool->FindShape(theShape, Standard_False);
+    if (aTopShL.IsNull())
+      return Standard_False;
+    aTopSh   = XCAFDoc_ShapeTool::GetShape(aTopShL);
+    aContext = aStyles.FindContext(aTopSh);
   }
-
-  // Get the product definition from the shape definition representation:
-  const Handle(StepRepr_PropertyDefinition) aPropDef = aSDR->Definition().PropertyDefinition();
-  if (aPropDef.IsNull())
-    return Standard_False;
-  const Handle(StepBasic_ProductDefinition) aProdDef = aPropDef->Definition().ProductDefinition();
-  if (aProdDef.IsNull())
+  if (aContext.IsNull())
     return Standard_False;
+  // get representation item of the shape
+  TopLoc_Location             aLocation;
+  TColStd_SequenceOfTransient aSeqRI;
+  FindEntities(aFP, theShape, aLocation, aSeqRI);
+  if (aSeqRI.Length() <= 0)
+    Message::SendTrace() << "Warning: Cannot find RI for "
+                         << theShape.TShape()->DynamicType()->Name() << "\n";
+  anItem = Handle(StepRepr_RepresentationItem)::DownCast(aSeqRI(1));
+  // get overridden styled item
+  getStyledItem(theShape, theSTool, aStyles, anOverride, theMapCompMDGPR);
 
-  // Export string metadata.
-  const TDataStd_DataMapOfStringString& aStringMap = aNamedData->GetStringsContainer();
-  for (TDataStd_DataMapOfStringString::Iterator anIter(aStringMap); anIter.More(); anIter.Next())
-  {
-    const TCollection_ExtendedString& aKey   = anIter.Key();
-    const TCollection_ExtendedString& aValue = anIter.Value();
-
-    // Create descriptive representation item for the value.
-    const Handle(StepRepr_DescriptiveRepresentationItem) aDescrItem =
-      new StepRepr_DescriptiveRepresentationItem();
-    const Handle(TCollection_HAsciiString) aItemName  = new TCollection_HAsciiString(aKey);
-    const Handle(TCollection_HAsciiString) aItemValue = new TCollection_HAsciiString(aValue);
-    aDescrItem->SetName(aItemName);
-    aDescrItem->SetDescription(aItemValue);
+  // get STEP STYLED ITEM
+  Handle(StepVisual_StyledItem) aSTEPstyle = aStyles.AddStyle(anItem, aPSA, anOverride);
+  // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
+  aStyles.CreateNAUOSRD(aContext, aCDSR, thePDS);
 
-    writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aDescrItem);
+  // add step styled item of SHUO to the model
+  // do it by additing styled item to the MDGPR
+  if (!aTopSh.IsNull() && !theMapCompMDGPR.IsBound(aTopSh))
+  {
+    // create MDGPR and record it in model
+    Message::SendTrace() << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance"
+                         << "\n";
+    Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
+    aStyles.CreateMDGPR(aContext, aMDGPR, aStepModel);
+    if (!aMDGPR.IsNull())
+      theMapCompMDGPR.Bind(aTopSh, aMDGPR);
   }
-
-  // Export integer metadata.
-  const TColStd_DataMapOfStringInteger& aIntMap = aNamedData->GetIntegersContainer();
-  for (TColStd_DataMapOfStringInteger::Iterator anIter(aIntMap); anIter.More(); anIter.Next())
+  else if (!aTopSh.IsNull() && theMapCompMDGPR.IsBound(aTopSh))
   {
-    const TCollection_ExtendedString& aKey   = anIter.Key();
-    const Standard_Integer            aValue = anIter.Value();
-    // Create integer representation item for the value.
-    const Handle(StepRepr_IntegerRepresentationItem) aIntItem =
-      new StepRepr_IntegerRepresentationItem();
-    const Handle(TCollection_HAsciiString) aItemName = new TCollection_HAsciiString(aKey);
-    aIntItem->Init(aItemName, aValue);
-
-    writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aIntItem);
+    // get MDGPR of the top-level shape
+    Handle(StepVisual_PresentationRepresentation) aMDGPR =
+      Handle(StepVisual_PresentationRepresentation)::DownCast(theMapCompMDGPR.Find(aTopSh));
+    // get old styled items to not lose it
+    Handle(StepRepr_HArray1OfRepresentationItem) anOldItems     = aMDGPR->Items();
+    Standard_Integer                             anOldLengthlen = 0;
+    if (!anOldItems.IsNull())
+      anOldLengthlen = anOldItems->Length();
+    // create new array of styled items by an olds and new one
+    Handle(StepRepr_HArray1OfRepresentationItem) aNewItems =
+      new StepRepr_HArray1OfRepresentationItem(1, anOldLengthlen + 1);
+    Standard_Integer aSetStyleInd = 1;
+    for (StepRepr_HArray1OfRepresentationItem::Iterator aStyleIter(anOldItems->Array1());
+         aStyleIter.More();
+         aStyleIter.Next())
+    {
+      aNewItems->SetValue(aSetStyleInd++, aStyleIter.Value());
+    }
+    aNewItems->SetValue(aSetStyleInd++, aSTEPstyle);
+    // init MDGPR be new array of styled items
+    if (aNewItems->Length() > 0)
+      aMDGPR->SetItems(aNewItems);
   }
-
-  // Export real metadata.
-  const TDataStd_DataMapOfStringReal& aRealMap = aNamedData->GetRealsContainer();
-  for (TDataStd_DataMapOfStringReal::Iterator anIter(aRealMap); anIter.More(); anIter.Next())
+  else
   {
-    const TCollection_ExtendedString& aKey   = anIter.Key();
-    const Standard_Real               aValue = anIter.Value();
-    // Create real representation item for the value.
-    const Handle(StepRepr_RealRepresentationItem) aRealItem = new StepRepr_RealRepresentationItem();
-    const Handle(TCollection_HAsciiString)        aItemName = new TCollection_HAsciiString(aKey);
-    aRealItem->Init(aItemName, aValue);
-
-    writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aRealItem);
+    theWS->Model()->AddWithRefs(aSTEPstyle); // add as root to the model, but it is not good
+    Message::SendTrace() << "Warning: " << __FILE__
+                         << ": adds styled item of SHUO as root, cause cannot find MDGPR" << "\n";
   }
-
-  // Process label children recursively:
-  if (theLabel.HasChild())
+  // create invisibility item for the styled item
+  if (!theStyle.IsVisible())
   {
-    for (Standard_Integer aChildInd = 1; aChildInd <= theLabel.NbChildren(); aChildInd++)
+    if (isSetDefaultColor)
     {
-      const TDF_Label& aChildLabel = theLabel.FindChild(aChildInd);
-      writeMetadataForLabel(theWS, aChildLabel);
+      // try to set default color from top-level shape
+
+      setDefaultInstanceColor(anOverride, aPSA);
     }
+    // create invisibility item and refer for styledItem
+    Handle(StepVisual_Invisibility)           aInvsblt = new StepVisual_Invisibility();
+    Handle(StepVisual_HArray1OfInvisibleItem) aHInvsblItm =
+      new StepVisual_HArray1OfInvisibleItem(1, 1);
+    // put all style item into the harray
+    StepVisual_InvisibleItem anInvItem;
+    anInvItem.SetValue(aSTEPstyle);
+    aHInvsblItm->SetValue(1, anInvItem);
+    aInvsblt->Init(aHInvsblItm);
+    theWS->Model()->AddWithRefs(aInvsblt);
   }
 
   return Standard_True;
@@ -2163,710 +2359,398 @@ Standard_Boolean STEPCAFControl_Writer::writeMetadataForLabel(
 
 //=================================================================================================
 
-void STEPCAFControl_Writer::writeMetadataRepresentationItem(
-  const TCollection_AsciiString&                        theKey,
-  const Handle(StepData_StepModel)&                     theModel,
-  const Handle(StepShape_ShapeDefinitionRepresentation) theShapeDefRep,
-  const Handle(StepBasic_ProductDefinition)&            theProdDef,
-  const Handle(StepRepr_RepresentationItem)&            theItem) const
+Standard_Boolean STEPCAFControl_Writer::writeSHUOs(const Handle(XSControl_WorkSession)& theWS,
+                                                   const TDF_LabelSequence&             theLabels)
 {
-  // Empty string to use for empty values:
-  const Handle(TCollection_HAsciiString) anEmptyStr = new TCollection_HAsciiString("");
-
-  // Create property_definition:
-  const Handle(StepRepr_PropertyDefinition) aMetaPropDef = new StepRepr_PropertyDefinition();
-  const Handle(TCollection_HAsciiString)    aPropName    = new TCollection_HAsciiString(theKey);
-  const Handle(TCollection_HAsciiString)    aPropDesc =
-    new TCollection_HAsciiString("user defined attribute");
-  aMetaPropDef->SetName(aPropName);
-  aMetaPropDef->SetDescription(aPropDesc);
-
-  // Create a general_property:
-  const Handle(StepBasic_GeneralProperty) aGeneralProp = new StepBasic_GeneralProperty();
-  aGeneralProp->SetId(anEmptyStr);
-  aGeneralProp->SetName(aPropName);
-  aGeneralProp->SetDescription(anEmptyStr);
-
-  // Create a general_property_association:
-  const Handle(StepBasic_GeneralPropertyAssociation) aGeneralPropAssoc =
-    new StepBasic_GeneralPropertyAssociation();
-  aGeneralPropAssoc->SetName(anEmptyStr);
-  aGeneralPropAssoc->SetDescription(anEmptyStr);
-  aGeneralPropAssoc->SetPropertyDefinition(aMetaPropDef);
-  aGeneralPropAssoc->SetGeneralProperty(aGeneralProp);
-
-  // Set the definition to point to the product definition:
-  StepRepr_CharacterizedDefinition aCharDef;
-  aCharDef.SetValue(theProdDef);
-  aMetaPropDef->SetDefinition(aCharDef);
-
-  // Create property_definition_representation:
-  const Handle(StepRepr_PropertyDefinitionRepresentation) aPropDefRepr =
-    new StepRepr_PropertyDefinitionRepresentation();
-  StepRepr_RepresentedDefinition aRepDef;
-  aRepDef.SetValue(aMetaPropDef);
-  aPropDefRepr->SetDefinition(aRepDef);
-
-  // Create representation with descriptive_representation_item:
-  const Handle(StepRepr_Representation)  aRepr     = new StepRepr_Representation();
-  const Handle(TCollection_HAsciiString) aReprName = new TCollection_HAsciiString(theKey);
-  aRepr->SetName(aReprName);
+  if (theLabels.IsEmpty())
+    return Standard_False;
 
-  // Add item to representation:
-  const Handle(StepRepr_HArray1OfRepresentationItem) aItems =
-    new StepRepr_HArray1OfRepresentationItem(1, 1);
-  aItems->SetValue(1, theItem);
-  aRepr->SetItems(aItems);
-
-  // Set representation context (reuse from shape representation):
-  const Handle(StepRepr_RepresentationContext) aRC =
-    theShapeDefRep->UsedRepresentation()->ContextOfItems();
-  aRepr->SetContextOfItems(aRC);
+  // map of transferred SHUO
+  TColStd_MapOfTransient aMapOfMainSHUO;
+  // Iterate on requested shapes
+  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
+  {
+    const TDF_Label& aLabel = aLabelIter.Value();
+    if (!myLabels.IsBound(aLabel))
+      continue; // not recorded as translated, skip
+    if (!XCAFDoc_ShapeTool::IsAssembly(aLabel))
+    {
+      continue;
+    }
+    TDF_LabelSequence aLabelSeq;
+    XCAFDoc_ShapeTool::GetComponents(aLabel, aLabelSeq);
+    // iterates on components of assembly
+    for (TDF_LabelSequence::Iterator aCompIter(aLabelSeq); aCompIter.More(); aCompIter.Next())
+    {
+      const TDF_Label&      aCompL = aCompIter.Value();
+      TDF_AttributeSequence anAttrSeq;
+      XCAFDoc_ShapeTool::GetAllComponentSHUO(aCompL, anAttrSeq);
+      // work with SHUO
+      for (TDF_AttributeSequence::Iterator anAttrIter(anAttrSeq); anAttrIter.More();
+           anAttrIter.Next())
+      {
+        Handle(XCAFDoc_GraphNode) aSHUO = Handle(XCAFDoc_GraphNode)::DownCast(anAttrIter.Value());
+        // take label of SHUO
+        TDF_Label         aSHUOlab = aSHUO->Label();
+        TDF_LabelSequence aUpLabels;
+        // check is it SHUO of upper_usage
+        XCAFDoc_ShapeTool::GetSHUOUpperUsage(aSHUOlab, aUpLabels);
+        if (aUpLabels.Length() > 0)
+          continue; // transfer only main SHUO
+        if (aMapOfMainSHUO.Contains(aSHUO))
+          continue; // do not try to transfer SHUO twice
+        aMapOfMainSHUO.Add(aSHUO);
+        // check if it is styled SHUO
+        XCAFPrs_Style aSHUOstyle;
+        if (!getSHUOstyle(aSHUOlab, aSHUOstyle))
+        {
+          Message::SendTrace() << "Warning: " << __FILE__
+                               << ": do not store SHUO without any style to the STEP model" << "\n";
+          continue;
+        }
+        // write SHUO to the model amd then add structure type.
+        TopoDS_Shape     aNAUOShape; // shape of the deepest NAUO in the SHUO structure
+        Standard_Boolean isDeepest = Standard_False;
+        Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
+        Handle(StepBasic_ProductDefinition)             aRelatingPD;
+        // create the top SHUO and all other.
+        writeSHUO(aSHUO, theWS, anEntOfSHUO, aNAUOShape, aRelatingPD, isDeepest);
+        if (anEntOfSHUO.IsNull() || aNAUOShape.IsNull())
+        {
+          Message::SendTrace() << "Warning: " << __FILE__ << ": Cannot store SHUO" << "\n";
+          continue;
+        }
+        // create new Product Definition Shape for TOP SHUO
+        Message::SendTrace() << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO "
+                             << "\n";
+        Handle(StepRepr_ProductDefinitionShape) aPDS      = new StepRepr_ProductDefinitionShape;
+        Handle(TCollection_HAsciiString)        aPDSname  = new TCollection_HAsciiString("SHUO");
+        Handle(TCollection_HAsciiString)        aDescrStr = new TCollection_HAsciiString("");
+        StepRepr_CharacterizedDefinition        aCharDef;
+        aCharDef.SetValue(anEntOfSHUO);
+        aPDS->Init(aPDSname, Standard_False, aDescrStr, aCharDef);
 
-  aPropDefRepr->SetUsedRepresentation(aRepr);
+        // create styled item for SHUO and add to the model
+        createSHUOStyledItem(aSHUOstyle,
+                             aPDS,
+                             theWS,
+                             aNAUOShape,
+                             XCAFDoc_DocumentTool::ShapeTool(aLabel),
+                             myMapCompMDGPR);
 
-  // Add entities to the model:
-  theModel->AddWithRefs(aMetaPropDef);
-  theModel->AddWithRefs(aGeneralProp);
-  theModel->AddWithRefs(aGeneralPropAssoc);
-  theModel->AddWithRefs(aPropDefRepr);
-  theModel->AddWithRefs(aRepr);
-  theModel->AddWithRefs(theItem);
+      } // end work with SHUO
+    } // end of an assembly components
+  } // end of iterates on indicated labels
+  return Standard_True;
 }
 
-//=================================================================================================
-
-static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession)&      theWS,
-                                           const STEPCAFControl_DataMapOfLabelShape& theLabels,
-                                           const TDF_Label&                          theLabel,
-                                           const Standard_CString                    theIsMulti)
+//=======================================================================
+// function : FindPDSforDGT
+// purpose  : auxiliary: find PDS for AdvancedFace or EdgeCurve for creation
+//                     needed ShapeAspect in D&GT structure
+//=======================================================================
+static Standard_Boolean FindPDSforDGT(const Interface_Graph&                   theGraph,
+                                      const Handle(Standard_Transient)&        theEnt,
+                                      Handle(StepRepr_ProductDefinitionShape)& thePDS,
+                                      Handle(StepRepr_RepresentationContext)&  theRC,
+                                      Handle(StepShape_AdvancedFace)&          theAF,
+                                      Handle(StepShape_EdgeCurve)&             theEC)
 {
-  if (theLabel.IsNull())
+  if (theEnt.IsNull())
     return Standard_False;
-
-  STEPConstruct_ValidationProps aProps(theWS);
-
-  TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theLabel);
-  if (aShape.IsNull())
+  if (!theEnt->IsKind(STANDARD_TYPE(StepShape_EdgeCurve))
+      && !theEnt->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)))
+  {
     return Standard_False;
+  }
 
-  if (!theIsMulti || XCAFDoc_ShapeTool::IsAssembly(theLabel))
+  theAF = Handle(StepShape_AdvancedFace)::DownCast(theEnt);
+  if (theAF.IsNull())
   {
-    // write area
-    Handle(XCAFDoc_Area) anArea;
-    theLabel.FindAttribute(XCAFDoc_Area::GetID(), anArea);
-    if (!anArea.IsNull())
-    {
-      aProps.AddArea(aShape, anArea->Get());
-    }
-    // write volume
-    Handle(XCAFDoc_Volume) aVolume;
-    theLabel.FindAttribute(XCAFDoc_Volume::GetID(), aVolume);
-    if (!aVolume.IsNull())
+    theEC = Handle(StepShape_EdgeCurve)::DownCast(theEnt);
+    for (Interface_EntityIterator aSharingsIter = theGraph.Sharings(theEC);
+         aSharingsIter.More() && theAF.IsNull();
+         aSharingsIter.Next())
     {
-      aProps.AddVolume(aShape, aVolume->Get());
+      Handle(StepShape_OrientedEdge) anOE =
+        Handle(StepShape_OrientedEdge)::DownCast(aSharingsIter.Value());
+      if (anOE.IsNull())
+        continue;
+      for (Interface_EntityIterator aSubs1 = theGraph.Sharings(anOE);
+           aSubs1.More() && theAF.IsNull();
+           aSubs1.Next())
+      {
+        Handle(StepShape_EdgeLoop) aEL = Handle(StepShape_EdgeLoop)::DownCast(aSubs1.Value());
+        if (aEL.IsNull())
+          continue;
+        for (Interface_EntityIterator aSubs2 = theGraph.Sharings(aEL);
+             aSubs2.More() && theAF.IsNull();
+             aSubs2.Next())
+        {
+          Handle(StepShape_FaceBound) aFB = Handle(StepShape_FaceBound)::DownCast(aSubs2.Value());
+          if (aFB.IsNull())
+            continue;
+          for (Interface_EntityIterator aSubs3 = theGraph.Sharings(aFB);
+               aSubs3.More() && theAF.IsNull();
+               aSubs3.Next())
+          {
+            theAF = Handle(StepShape_AdvancedFace)::DownCast(aSubs3.Value());
+          }
+        }
+      }
     }
   }
-  // write centroid
-  Handle(XCAFDoc_Centroid) aCentroid;
-  theLabel.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid);
-  if (!aCentroid.IsNull())
-  {
-    aProps.AddCentroid(aShape, aCentroid->Get());
-  }
+  if (theAF.IsNull())
+    return Standard_False;
 
-  if (XCAFDoc_ShapeTool::IsCompound(theLabel) || XCAFDoc_ShapeTool::IsAssembly(theLabel))
+  for (Interface_EntityIterator aSharingsIter = theGraph.Sharings(theAF);
+       aSharingsIter.More() && thePDS.IsNull();
+       aSharingsIter.Next())
   {
-    if (theLabel.HasChild())
+    Handle(StepShape_ConnectedFaceSet) aCFS =
+      Handle(StepShape_ConnectedFaceSet)::DownCast(aSharingsIter.Value());
+    if (aCFS.IsNull())
+      continue;
+    for (Interface_EntityIterator aSubs1 = theGraph.Sharings(aCFS);
+         aSubs1.More() && thePDS.IsNull();
+         aSubs1.Next())
     {
-      for (Standard_Integer aChildInd = 1; aChildInd <= theLabel.NbChildren(); aChildInd++)
+      Handle(StepRepr_RepresentationItem) aRI =
+        Handle(StepRepr_RepresentationItem)::DownCast(aSubs1.Value());
+      if (aRI.IsNull())
+        continue;
+      for (Interface_EntityIterator aSubs2 = theGraph.Sharings(aRI);
+           aSubs2.More() && thePDS.IsNull();
+           aSubs2.Next())
       {
-        WritePropsForLabel(theWS, theLabels, theLabel.FindChild(aChildInd), theIsMulti);
+        Handle(StepShape_ShapeRepresentation) aSR =
+          Handle(StepShape_ShapeRepresentation)::DownCast(aSubs2.Value());
+        if (aSR.IsNull())
+          continue;
+        theRC = aSR->ContextOfItems();
+        for (Interface_EntityIterator aSubs3 = theGraph.Sharings(aSR);
+             aSubs3.More() && thePDS.IsNull();
+             aSubs3.Next())
+        {
+          Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
+            Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSubs3.Value());
+          if (aSDR.IsNull())
+            continue;
+          Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
+          if (aPropD.IsNull())
+            continue;
+          thePDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD);
+        }
       }
     }
   }
-
   return Standard_True;
 }
 
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::writeValProps(const Handle(XSControl_WorkSession)& theWS,
-                                                      const TDF_LabelSequence& theLabels,
-                                                      const Standard_CString   theIsMulti) const
+//=======================================================================
+// function : FindPDS
+// purpose  : auxiliary: find Product_definition_shape entity for given entity
+//=======================================================================
+static Handle(StepRepr_ProductDefinitionShape) FindPDS(
+  const Interface_Graph&                  theGraph,
+  const Handle(Standard_Transient)&       theEnt,
+  Handle(StepRepr_RepresentationContext)& theRC)
 {
-  if (theLabels.IsEmpty())
-    return Standard_False;
+  if (theEnt.IsNull())
+    return NULL;
+  Handle(StepRepr_ProductDefinitionShape) aPDS;
 
-  // Iterate on requested shapes
-  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
+  // try to find shape_representation in sharings
+  for (Interface_EntityIterator anIter = theGraph.Sharings(theEnt); anIter.More() && aPDS.IsNull();
+       anIter.Next())
   {
-    const TDF_Label& aLabel = aLabelIter.Value();
-
-    WritePropsForLabel(theWS, myLabels, aLabel, theIsMulti);
+    Handle(StepShape_ShapeRepresentation) aSR =
+      Handle(StepShape_ShapeRepresentation)::DownCast(anIter.Value());
+    if (aSR.IsNull())
+      continue;
+    theRC                           = aSR->ContextOfItems();
+    Interface_EntityIterator aSDRIt = theGraph.Sharings(aSR);
+    for (aSDRIt.Start(); aSDRIt.More() && aPDS.IsNull(); aSDRIt.Next())
+    {
+      Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
+        Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
+      if (aSDR.IsNull())
+        continue;
+      Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
+      if (aPropD.IsNull())
+        continue;
+      aPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD);
+    }
   }
+  if (!aPDS.IsNull())
+    return aPDS;
 
-  return Standard_True;
-}
-
-//=================================================================================================
-
-Standard_Boolean STEPCAFControl_Writer::writeLayers(const Handle(XSControl_WorkSession)& theWS,
-                                                    const TDF_LabelSequence& theLabels) const
-{
-
-  if (theLabels.IsEmpty())
-    return Standard_False;
-
-  // get working data
-  const Handle(Interface_InterfaceModel)& aModel = theWS->Model();
-  const Handle(XSControl_TransferWriter)& aTW    = theWS->TransferWriter();
-  const Handle(Transfer_FinderProcess)&   aFP    = aTW->FinderProcess();
-  TDF_LabelSequence                       aGlobalLayerLS;
-  // Iterate on requested shapes collect Tools
-  for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); aLabelIter.More(); aLabelIter.Next())
-  {
-    const TDF_Label&          aLabel = aLabelIter.Value();
-    Handle(XCAFDoc_LayerTool) aLTool = XCAFDoc_DocumentTool::LayerTool(aLabel);
-    TDF_LabelSequence         aLayerLS;
-    aLTool->GetLayerLabels(aLayerLS);
-    aGlobalLayerLS.Append(aLayerLS);
-  }
-  for (TDF_LabelSequence::Iterator aLayerIter(aGlobalLayerLS); aLayerIter.More(); aLayerIter.Next())
+  for (Interface_EntityIterator anIter = theGraph.Sharings(theEnt); anIter.More(); anIter.Next())
   {
-    const TDF_Label& aLayerL = aLayerIter.Value();
-    // get labels of shapes in that layer
-    TDF_LabelSequence aShapeLabels;
-    XCAFDoc_LayerTool::GetShapesOfLayer(aLayerL, aShapeLabels);
-    if (aShapeLabels.IsEmpty())
-      continue;
-
-    // name of layer: if not set, is considered as being empty
-    Handle(TCollection_HAsciiString) aHName = new TCollection_HAsciiString;
-    GetLabelName(aLayerL, aHName);
-
-    // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment
-    // items.
-    TColStd_SequenceOfTransient aSeqRI;
-    for (TDF_LabelSequence::Iterator aShapeIter(aShapeLabels); aShapeIter.More(); aShapeIter.Next())
-    {
-      const TDF_Label& aShLabel = aShapeIter.Value();
-      if (aShLabel.IsNull())
-        continue;
-
-      // there is no way to assign layer to instance in STEP
-      if (XCAFDoc_ShapeTool::IsAssembly(aShLabel) || XCAFDoc_ShapeTool::IsReference(aShLabel))
-      {
-        continue;
-      }
-      // check that the shape is one of (uub)labels written during current transfer
-      Standard_Boolean anIsWritten = Standard_False;
-      for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
-      {
-        if (aShLabel.IsDescendant(aLabelIter.Value()))
-        {
-          anIsWritten = Standard_True;
-          break;
-        }
-      }
-      if (!anIsWritten)
-      {
-        continue;
-      }
-
-      // get target STEP entity
-      TopoDS_Shape anOneShape = XCAFDoc_ShapeTool::GetShape(aShLabel);
-
-      TopLoc_Location  aLoc;
-      Standard_Integer aNb = FindEntities(aFP, anOneShape, aLoc, aSeqRI);
-      if (aNb <= 0)
-      {
-        Message::SendTrace() << "Warning: Cannot find RI for "
-                             << anOneShape.TShape()->DynamicType()->Name() << "\n";
-      }
-    }
-    if (aSeqRI.IsEmpty())
-      continue;
-
-    // analyze visibility
-    Handle(StepVisual_PresentationLayerAssignment) aStepLayerAs =
-      new StepVisual_PresentationLayerAssignment;
-    Handle(TCollection_HAsciiString) aDescr;
-    Handle(TDataStd_UAttribute)      aUAttr;
-    Standard_Boolean                 isLinv = Standard_False;
-    if (aLayerL.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr))
-    {
-      aDescr = new TCollection_HAsciiString("invisible");
-      Message::SendTrace() << "\tLayer \"" << aHName->String().ToCString() << "\" is invisible"
-                           << "\n";
-      isLinv = Standard_True;
-    }
-    else
-    {
-      aDescr = new TCollection_HAsciiString("visible");
-    }
-
-    // create layer entity
-    Standard_Integer                        anSetStyleInd = 1;
-    Handle(StepVisual_HArray1OfLayeredItem) aHArrayOfLItem =
-      new StepVisual_HArray1OfLayeredItem(1, aSeqRI.Length());
-    for (TColStd_SequenceOfTransient::Iterator aRIIter(aSeqRI); aRIIter.More(); aRIIter.Next())
-    {
-      StepVisual_LayeredItem aLI;
-      aLI.SetValue(aRIIter.Value());
-      aHArrayOfLItem->SetValue(anSetStyleInd++, aLI);
-    }
-    aStepLayerAs->Init(aHName, aDescr, aHArrayOfLItem);
-    aModel->AddWithRefs(aStepLayerAs);
-    // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
-    // add the invisibility for the layer
-    if (isLinv)
+    if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem))
+        || anIter.Value()->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)))
     {
-      // Invisibility Item for containing invisible layers.
-      Handle(StepVisual_HArray1OfInvisibleItem) aHInvsblItm =
-        new StepVisual_HArray1OfInvisibleItem(1, 1);
-      StepVisual_InvisibleItem aInvIt;
-      aInvIt.SetValue(aStepLayerAs);
-      aHInvsblItm->SetValue(1, aInvIt);
-
-      Handle(StepVisual_Invisibility) aInvsblt = new StepVisual_Invisibility();
-      aInvsblt->Init(aHInvsblItm);
-      aModel->AddWithRefs(aInvsblt);
+      aPDS = FindPDS(theGraph, anIter.Value(), theRC);
+      if (!aPDS.IsNull())
+        return aPDS;
     }
   }
-  return Standard_True;
+  return aPDS;
 }
 
 //=================================================================================================
 
-static Standard_Boolean getSHUOstyle(const TDF_Label& theSHUOlab, XCAFPrs_Style& theSHUOstyle)
+static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theRC,
+                              const Standard_Boolean theIsAngle = Standard_False)
 {
-  Quantity_Color aColor;
-  if (!XCAFDoc_ColorTool::IsVisible(theSHUOlab))
-  {
-    theSHUOstyle.SetVisibility(Standard_False);
-  }
-  else
+  StepBasic_Unit              aUnit;
+  Handle(StepBasic_NamedUnit) aCurrentUnit;
+  if (theIsAngle)
   {
-    if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorGen, aColor))
-    {
-      theSHUOstyle.SetColorCurv(aColor);
-      theSHUOstyle.SetColorSurf(aColor);
-    }
-    if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorSurf, aColor))
-      theSHUOstyle.SetColorSurf(aColor);
-    if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorCurv, aColor))
-      theSHUOstyle.SetColorCurv(aColor);
-    if (!theSHUOstyle.IsSetColorSurf())
+    Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
+      Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
+    if (!aCtx.IsNull())
     {
-      Handle(XCAFDoc_VisMaterial) aVisMat = XCAFDoc_VisMaterialTool::GetShapeMaterial(theSHUOlab);
-      if (!aVisMat.IsNull() && !aVisMat->IsEmpty())
+      for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx->Units()->Array1());
+           aUnitIter.More();
+           aUnitIter.Next())
       {
-        // only color can be stored in STEP
-        theSHUOstyle.SetColorSurf(aVisMat->BaseColor());
+        const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value();
+        if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))
+            || aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)))
+        {
+          aCurrentUnit = aCurUnitValue;
+          break;
+        }
       }
     }
-  }
-  if (!theSHUOstyle.IsSetColorCurv() && !theSHUOstyle.IsSetColorSurf() && theSHUOstyle.IsVisible())
-  {
-    return Standard_False;
-  }
-  return Standard_True;
-}
-
-//=================================================================================================
-
-static Standard_Boolean getProDefinitionOfNAUO(
-  const Handle(XSControl_WorkSession)&          theWS,
-  const TopoDS_Shape&                           theShape,
-  Handle(StepBasic_ProductDefinition)&          thePD,
-  Handle(StepRepr_NextAssemblyUsageOccurrence)& theNAUO,
-  Standard_Boolean                              theIsRelating)
-{
-  if (theShape.IsNull())
-    return Standard_False;
-  // get CDSR
-  const Handle(XSControl_TransferWriter)&               aTW = theWS->TransferWriter();
-  const Handle(Transfer_FinderProcess)&                 aFP = aTW->FinderProcess();
-  Handle(StepShape_ContextDependentShapeRepresentation) aCDSR;
-  Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, theShape);
-  if (!aFP->FindTypedTransient(aMapper,
-                               STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
-                               aCDSR))
-  {
-    return Standard_False;
-  }
-  // get PDS of NAUO
-  Handle(StepRepr_ProductDefinitionShape) aPDS = aCDSR->RepresentedProductRelation();
-  if (aPDS.IsNull())
-    return Standard_False;
-  // get the NAUO entity
-  Interface_Graph aGraph = theWS->HGraph()->Graph();
-  for (Interface_EntityIterator aShareds = aGraph.Shareds(aPDS); aShareds.More(); aShareds.Next())
-  {
-    theNAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(aShareds.Value());
-    if (!theNAUO.IsNull())
-    {
-      break;
-    }
-  }
-  if (theNAUO.IsNull())
-    return Standard_False;
-  // get Relatinf or Related product definition
-  if (!theIsRelating)
-    thePD = theNAUO->RelatedProductDefinition();
-  else
-    thePD = theNAUO->RelatingProductDefinition();
-  if (thePD.IsNull())
-    return Standard_False;
-  return Standard_True;
-}
-
-//=================================================================================================
-
-static Standard_Boolean writeSHUO(const Handle(XCAFDoc_GraphNode)&                 theSHUO,
-                                  const Handle(XSControl_WorkSession)&             theWS,
-                                  Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
-                                  TopoDS_Shape&                                    theNAUOShape,
-                                  Handle(StepBasic_ProductDefinition)&             theRelatingPD,
-                                  Standard_Boolean&                                theIsDeepest)
-{
-  // set the ProductDefinitionRelationship descriptin information as empty strings.
-  Handle(TCollection_HAsciiString) anEmptyString = new TCollection_HAsciiString("");
-
-  TDF_LabelSequence aNextUsageLabs;
-  XCAFDoc_ShapeTool::GetSHUONextUsage(theSHUO->Label(), aNextUsageLabs);
-  Handle(XCAFDoc_GraphNode) aNuSHUO;
-  if (theTopSHUO.IsNull())
-  {
-    // the top SHUO
-    if (aNextUsageLabs.Length() < 1)
-      return Standard_False;
-    XCAFDoc_ShapeTool::GetSHUO(aNextUsageLabs.Value(1), aNuSHUO);
-    if (aNuSHUO.IsNull())
-      return Standard_False;
-    // get relating product definition
-    TopoDS_Shape aTopCompShape = XCAFDoc_ShapeTool::GetShape(theSHUO->Label().Father());
-    Handle(StepRepr_NextAssemblyUsageOccurrence) aRelatingNAUO;
-    if (!getProDefinitionOfNAUO(theWS, aTopCompShape, theRelatingPD, aRelatingNAUO, Standard_True))
-    {
-      return Standard_False;
-    }
-    // get related product definition
-    TopoDS_Shape aNUShape = XCAFDoc_ShapeTool::GetShape(aNuSHUO->Label().Father());
-    Handle(StepBasic_ProductDefinition)          aRelatedPD;
-    Handle(StepRepr_NextAssemblyUsageOccurrence) aRelatedNAUO;
-    if (!getProDefinitionOfNAUO(theWS, aNUShape, aRelatedPD, aRelatedNAUO, Standard_False))
-    {
-      return Standard_False;
-    }
-
-    theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
-    // create deepest shuo EmptyString
-    theTopSHUO->Init(/*id*/ anEmptyString,
-                     /*name*/ anEmptyString,
-                     /*no description*/ Standard_False,
-                     /*description*/ anEmptyString,
-                     theRelatingPD,
-                     aRelatedPD,
-                     /*no ACURefDesignator*/ Standard_False,
-                     /*ACURefDesignator*/ anEmptyString,
-                     /*upper_usage*/ aRelatingNAUO,
-                     /*next_usage*/ aRelatedNAUO);
-    // write the other SHUO.
-    if (!writeSHUO(aNuSHUO, theWS, theTopSHUO, theNAUOShape, theRelatingPD, theIsDeepest))
-    {
-      theTopSHUO.Nullify();
-      return Standard_False;
-    }
-
-    return Standard_True;
-  }
-  //   Handle(XCAFDoc_GraphNode) NuSHUO;
-  if (aNextUsageLabs.Length() > 0)
-  {
-    // store SHUO recursive
-    if (aNextUsageLabs.Length() > 1)
-      Message::SendTrace() << "Warning: store only one next_usage of current SHUO" << "\n";
-    XCAFDoc_ShapeTool::GetSHUO(aNextUsageLabs.Value(1), aNuSHUO);
-    Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
-      new StepRepr_SpecifiedHigherUsageOccurrence;
-    if (!writeSHUO(aNuSHUO, theWS, aNUEntSHUO, theNAUOShape, theRelatingPD, theIsDeepest))
-      return Standard_False;
-
-    // store the deepest SHUO to the dociment
-    TopoDS_Shape aNUSh, aUUSh;
-    aNUSh = XCAFDoc_ShapeTool::GetShape(aNuSHUO->Label().Father());
-    aUUSh = XCAFDoc_ShapeTool::GetShape(theSHUO->Label().Father());
-    // get relating PD with upper_usage and related PD with next_usage
-    Handle(StepBasic_ProductDefinition) nullPD; // no need to use,case have shared <theRelatingPD>
-    Handle(StepBasic_ProductDefinition) aRelatedPD;
-    Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
-    if (!getProDefinitionOfNAUO(theWS, aUUSh, nullPD, UUNAUO, Standard_True)
-        || !getProDefinitionOfNAUO(theWS, aNUSh, aRelatedPD, NUNAUO, Standard_False))
-    {
-      Message::SendTrace() << "Warning: cannot get related or relating PD" << "\n";
-      return Standard_False;
-    }
-    aNUEntSHUO->Init(/*id*/ anEmptyString,
-                     /*name*/ anEmptyString,
-                     /*no description*/ Standard_False,
-                     /*description*/ anEmptyString,
-                     theRelatingPD,
-                     aRelatedPD,
-                     /*no ACURefDesignator*/ Standard_False,
-                     /*ACURefDesignator*/ anEmptyString,
-                     /*upper_usage*/ theTopSHUO,
-                     /*next_usage*/ NUNAUO);
-    if (theIsDeepest)
-    {
-      theIsDeepest = Standard_False;
-    }
-    theWS->Model()->AddWithRefs(aNUEntSHUO);
-    return Standard_True;
-  } // end of recurse storing
-
-  // get shape
-  TDF_Label aShapeL = theSHUO->Label().Father();
-  theNAUOShape      = XCAFDoc_ShapeTool::GetShape(aShapeL);
-  // return to the deepest level from SHUO shape level
-  // it is because SHUO is attribute on deep level and shape level.
-  theIsDeepest = Standard_True;
-  return Standard_True;
-}
-
-//=================================================================================================
-
-static Standard_Boolean createSHUOStyledItem(const XCAFPrs_Style& theStyle,
-                                             const Handle(StepRepr_ProductDefinitionShape)& thePDS,
-                                             const Handle(XSControl_WorkSession)&           theWS,
-                                             const TopoDS_Shape&               theShape,
-                                             const Handle(XCAFDoc_ShapeTool)&  theSTool,
-                                             MoniTool_DataMapOfShapeTransient& theMapCompMDGPR)
-{
-  // create styled item for the indicated SHUO and store to the model
-  STEPConstruct_Styles aStyles(theWS);
-  // translate colors to STEP
-  Handle(StepVisual_Colour) aSurfColor, aCurvColor;
-  Standard_Real             aRenderTransp = 0.0;
-  if (theStyle.IsSetColorSurf())
-  {
-    Quantity_ColorRGBA aSurfCol = theStyle.GetColorSurfRGBA();
-    aRenderTransp               = 1.0 - aSurfCol.Alpha();
-    aSurfColor                  = aStyles.EncodeColor(aSurfCol.GetRGB());
-  }
-  if (theStyle.IsSetColorCurv())
-    aCurvColor = aStyles.EncodeColor(theStyle.GetColorCurv());
-  Standard_Boolean                    isComponent = Standard_True; // cause need to get PSBC
-  Handle(StepRepr_RepresentationItem) anItem;
-  // set default color for invisible SHUO.
-  Standard_Boolean isSetDefaultColor = Standard_False;
-  if (aSurfColor.IsNull() && aCurvColor.IsNull() && !theStyle.IsVisible())
-  {
-    aSurfColor        = aStyles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE));
-    isSetDefaultColor = Standard_True;
-  }
-  STEPConstruct_RenderingProperties aRenderProps;
-  if (aRenderTransp > 0.0)
-  {
-    aRenderProps.Init(theStyle.GetColorSurfRGBA());
-  }
-  Handle(StepVisual_PresentationStyleAssignment) aPSA =
-    aStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aRenderProps, isComponent);
-  Handle(StepVisual_StyledItem) anOverride; // null styled item
-
-  // find the repr item of the shape
-  const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
-  const Handle(Transfer_FinderProcess)&   aFP = aTW->FinderProcess();
-  Handle(StepData_StepModel)       aStepModel = Handle(StepData_StepModel)::DownCast(aFP->Model());
-  Handle(TransferBRep_ShapeMapper) aMapper    = TransferBRep::ShapeMapper(aFP, theShape);
-  Handle(StepShape_ContextDependentShapeRepresentation) aCDSR;
-  aFP->FindTypedTransient(aMapper,
-                          STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
-                          aCDSR);
-  if (aCDSR.IsNull())
-    return Standard_False;
-  // find context
-  Handle(StepRepr_RepresentationContext) aContext = aStyles.FindContext(theShape);
-  TopoDS_Shape                           aTopSh   = theShape;
-  if (aContext.IsNull())
-  {
-    TDF_Label aTopShL = theSTool->FindShape(theShape, Standard_False);
-    if (aTopShL.IsNull())
-      return Standard_False;
-    aTopSh   = XCAFDoc_ShapeTool::GetShape(aTopShL);
-    aContext = aStyles.FindContext(aTopSh);
-  }
-  if (aContext.IsNull())
-    return Standard_False;
-  // get representation item of the shape
-  TopLoc_Location             aLocation;
-  TColStd_SequenceOfTransient aSeqRI;
-  FindEntities(aFP, theShape, aLocation, aSeqRI);
-  if (aSeqRI.Length() <= 0)
-    Message::SendTrace() << "Warning: Cannot find RI for "
-                         << theShape.TShape()->DynamicType()->Name() << "\n";
-  anItem = Handle(StepRepr_RepresentationItem)::DownCast(aSeqRI(1));
-  // get overridden styled item
-  getStyledItem(theShape, theSTool, aStyles, anOverride, theMapCompMDGPR);
-
-  // get STEP STYLED ITEM
-  Handle(StepVisual_StyledItem) aSTEPstyle = aStyles.AddStyle(anItem, aPSA, anOverride);
-  // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
-  aStyles.CreateNAUOSRD(aContext, aCDSR, thePDS);
-
-  // add step styled item of SHUO to the model
-  // do it by additing styled item to the MDGPR
-  if (!aTopSh.IsNull() && !theMapCompMDGPR.IsBound(aTopSh))
-  {
-    // create MDGPR and record it in model
-    Message::SendTrace() << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance"
-                         << "\n";
-    Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
-    aStyles.CreateMDGPR(aContext, aMDGPR, aStepModel);
-    if (!aMDGPR.IsNull())
-      theMapCompMDGPR.Bind(aTopSh, aMDGPR);
-  }
-  else if (!aTopSh.IsNull() && theMapCompMDGPR.IsBound(aTopSh))
-  {
-    // get MDGPR of the top-level shape
-    Handle(StepVisual_PresentationRepresentation) aMDGPR =
-      Handle(StepVisual_PresentationRepresentation)::DownCast(theMapCompMDGPR.Find(aTopSh));
-    // get old styled items to not lose it
-    Handle(StepRepr_HArray1OfRepresentationItem) anOldItems     = aMDGPR->Items();
-    Standard_Integer                             anOldLengthlen = 0;
-    if (!anOldItems.IsNull())
-      anOldLengthlen = anOldItems->Length();
-    // create new array of styled items by an olds and new one
-    Handle(StepRepr_HArray1OfRepresentationItem) aNewItems =
-      new StepRepr_HArray1OfRepresentationItem(1, anOldLengthlen + 1);
-    Standard_Integer aSetStyleInd = 1;
-    for (StepRepr_HArray1OfRepresentationItem::Iterator aStyleIter(anOldItems->Array1());
-         aStyleIter.More();
-         aStyleIter.Next())
+    if (aCurrentUnit.IsNull())
     {
-      aNewItems->SetValue(aSetStyleInd++, aStyleIter.Value());
+      Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
+        Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
+      if (!aCtx1.IsNull())
+      {
+        for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx1->Units()->Array1());
+             aUnitIter.More();
+             aUnitIter.Next())
+        {
+          const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value();
+          if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))
+              || aCurUnitValue->IsKind(
+                STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)))
+          {
+            aCurrentUnit = aCurUnitValue;
+            break;
+          }
+        }
+      }
     }
-    aNewItems->SetValue(aSetStyleInd++, aSTEPstyle);
-    // init MDGPR be new array of styled items
-    if (aNewItems->Length() > 0)
-      aMDGPR->SetItems(aNewItems);
+    if (aCurrentUnit.IsNull())
+      aCurrentUnit = new StepBasic_SiUnitAndPlaneAngleUnit;
   }
   else
   {
-    theWS->Model()->AddWithRefs(aSTEPstyle); // add as root to the model, but it is not good
-    Message::SendTrace() << "Warning: " << __FILE__
-                         << ": adds styled item of SHUO as root, cause cannot find MDGPR" << "\n";
-  }
-  // create invisibility item for the styled item
-  if (!theStyle.IsVisible())
-  {
-    if (isSetDefaultColor)
+    Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
+      Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
+    if (!aCtx.IsNull())
     {
-      // try to set default color from top-level shape
-
-      setDefaultInstanceColor(anOverride, aPSA);
+      for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx->Units()->Array1());
+           aUnitIter.More();
+           aUnitIter.Next())
+      {
+        const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value();
+        if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))
+            || aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)))
+        {
+          aCurrentUnit = aCurUnitValue;
+          break;
+        }
+      }
     }
-    // create invisibility item and refer for styledItem
-    Handle(StepVisual_Invisibility)           aInvsblt = new StepVisual_Invisibility();
-    Handle(StepVisual_HArray1OfInvisibleItem) aHInvsblItm =
-      new StepVisual_HArray1OfInvisibleItem(1, 1);
-    // put all style item into the harray
-    StepVisual_InvisibleItem anInvItem;
-    anInvItem.SetValue(aSTEPstyle);
-    aHInvsblItm->SetValue(1, anInvItem);
-    aInvsblt->Init(aHInvsblItm);
-    theWS->Model()->AddWithRefs(aInvsblt);
+    if (aCurrentUnit.IsNull())
+    {
+      Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
+        Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
+      if (!aCtx1.IsNull())
+      {
+        for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx1->Units()->Array1());
+             aUnitIter.More();
+             aUnitIter.Next())
+        {
+          const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value();
+          if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))
+              || aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)))
+          {
+            aCurrentUnit = aCurUnitValue;
+            break;
+          }
+        }
+      }
+    }
+    if (aCurrentUnit.IsNull())
+      aCurrentUnit = new StepBasic_SiUnitAndLengthUnit;
   }
 
-  return Standard_True;
+  aUnit.SetValue(aCurrentUnit);
+  return aUnit;
 }
 
 //=================================================================================================
 
-Standard_Boolean STEPCAFControl_Writer::writeSHUOs(const Handle(XSControl_WorkSession)& theWS,
-                                                   const TDF_LabelSequence&             theLabels)
+static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(
+  const Standard_Real                                  theValue,
+  const StepBasic_Unit&                                theUnit,
+  const Handle(TCollection_HAsciiString)&              theName,
+  const Standard_CString                               theMeasureName,
+  const Standard_Boolean                               theIsAngle,
+  const Standard_Boolean                               theIsQualified = Standard_False,
+  const Handle(StepShape_QualifiedRepresentationItem)& theQRI         = NULL)
 {
-  if (theLabels.IsEmpty())
-    return Standard_False;
-
-  // map of transferred SHUO
-  TColStd_MapOfTransient aMapOfMainSHUO;
-  // Iterate on requested shapes
-  for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
+  Handle(StepRepr_RepresentationItem) aReprItem = new StepRepr_RepresentationItem();
+  aReprItem->Init(new TCollection_HAsciiString(theName));
+  Handle(StepBasic_MeasureWithUnit)    aMWU         = new StepBasic_MeasureWithUnit();
+  Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
+  aValueMember->SetName(theMeasureName);
+  aValueMember->SetReal(theValue);
+  aMWU->Init(aValueMember, theUnit);
+  if (theIsQualified)
   {
-    const TDF_Label& aLabel = aLabelIter.Value();
-    if (!myLabels.IsBound(aLabel))
-      continue; // not recorded as translated, skip
-    if (!XCAFDoc_ShapeTool::IsAssembly(aLabel))
+    if (theIsAngle)
     {
-      continue;
+      // Angle & with qualifiers
+      Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI) anItem =
+        new StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI();
+      anItem->Init(aMWU, aReprItem, theQRI);
+      return anItem;
     }
-    TDF_LabelSequence aLabelSeq;
-    XCAFDoc_ShapeTool::GetComponents(aLabel, aLabelSeq);
-    // iterates on components of assembly
-    for (TDF_LabelSequence::Iterator aCompIter(aLabelSeq); aCompIter.More(); aCompIter.Next())
+    else
     {
-      const TDF_Label&      aCompL = aCompIter.Value();
-      TDF_AttributeSequence anAttrSeq;
-      XCAFDoc_ShapeTool::GetAllComponentSHUO(aCompL, anAttrSeq);
-      // work with SHUO
-      for (TDF_AttributeSequence::Iterator anAttrIter(anAttrSeq); anAttrIter.More();
-           anAttrIter.Next())
-      {
-        Handle(XCAFDoc_GraphNode) aSHUO = Handle(XCAFDoc_GraphNode)::DownCast(anAttrIter.Value());
-        // take label of SHUO
-        TDF_Label         aSHUOlab = aSHUO->Label();
-        TDF_LabelSequence aUpLabels;
-        // check is it SHUO of upper_usage
-        XCAFDoc_ShapeTool::GetSHUOUpperUsage(aSHUOlab, aUpLabels);
-        if (aUpLabels.Length() > 0)
-          continue; // transfer only main SHUO
-        if (aMapOfMainSHUO.Contains(aSHUO))
-          continue; // do not try to transfer SHUO twice
-        aMapOfMainSHUO.Add(aSHUO);
-        // check if it is styled SHUO
-        XCAFPrs_Style aSHUOstyle;
-        if (!getSHUOstyle(aSHUOlab, aSHUOstyle))
-        {
-          Message::SendTrace() << "Warning: " << __FILE__
-                               << ": do not store SHUO without any style to the STEP model" << "\n";
-          continue;
-        }
-        // write SHUO to the model amd then add structure type.
-        TopoDS_Shape     aNAUOShape; // shape of the deepest NAUO in the SHUO structure
-        Standard_Boolean isDeepest = Standard_False;
-        Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
-        Handle(StepBasic_ProductDefinition)             aRelatingPD;
-        // create the top SHUO and all other.
-        writeSHUO(aSHUO, theWS, anEntOfSHUO, aNAUOShape, aRelatingPD, isDeepest);
-        if (anEntOfSHUO.IsNull() || aNAUOShape.IsNull())
-        {
-          Message::SendTrace() << "Warning: " << __FILE__ << ": Cannot store SHUO" << "\n";
-          continue;
-        }
-        // create new Product Definition Shape for TOP SHUO
-        Message::SendTrace() << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO "
-                             << "\n";
-        Handle(StepRepr_ProductDefinitionShape) aPDS      = new StepRepr_ProductDefinitionShape;
-        Handle(TCollection_HAsciiString)        aPDSname  = new TCollection_HAsciiString("SHUO");
-        Handle(TCollection_HAsciiString)        aDescrStr = new TCollection_HAsciiString("");
-        StepRepr_CharacterizedDefinition        aCharDef;
-        aCharDef.SetValue(anEntOfSHUO);
-        aPDS->Init(aPDSname, Standard_False, aDescrStr, aCharDef);
-
-        // create styled item for SHUO and add to the model
-        createSHUOStyledItem(aSHUOstyle,
-                             aPDS,
-                             theWS,
-                             aNAUOShape,
-                             XCAFDoc_DocumentTool::ShapeTool(aLabel),
-                             myMapCompMDGPR);
-
-      } // end work with SHUO
-    } // end of an assembly components
-  } // end of iterates on indicated labels
-  return Standard_True;
+      // Length & with qualifiers
+      Handle(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI) anItem =
+        new StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI();
+      anItem->Init(aMWU, aReprItem, theQRI);
+      return anItem;
+    }
+  }
+  else
+  {
+    if (theIsAngle)
+    {
+      // Angle & without qualifiers
+      Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) anItem =
+        new StepRepr_ReprItemAndPlaneAngleMeasureWithUnit();
+      anItem->Init(aMWU, aReprItem);
+      return anItem;
+    }
+    else
+    {
+      // Length & without qualifiers
+      Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) anItem =
+        new StepRepr_ReprItemAndLengthMeasureWithUnit();
+      anItem->Init(aMWU, aReprItem);
+      return anItem;
+    }
+  }
 }
 
 //=======================================================================
@@ -3626,17 +3510,17 @@ static void WriteDimValues(const Handle(XSControl_WorkSession)&             theW
   }
 }
 
-//==================================================================================================
-
-// Wwrite connection point for dimensions
-static void WriteDerivedGeometry(
-  const Handle(XSControl_WorkSession)&                              theWS,
-  const Handle(XCAFDimTolObjects_DimensionObject)&                  theObject,
-  const Handle(StepRepr_ConstructiveGeometryRepresentation)&        theRepr,
-  Handle(StepRepr_ShapeAspect)&                                     theFirstSA,
-  Handle(StepRepr_ShapeAspect)&                                     theSecondSA,
-  NCollection_Vector<Handle(StepGeom_GeometricRepresentationItem)>& theGeoms,
-  const StepData_Factors&                                           theLocalFactors)
+//=======================================================================
+// function : WriteDerivedGeometry
+// purpose  : auxiliary (write connection point for dimensions)
+//======================================================================
+static void WriteDerivedGeometry(const Handle(XSControl_WorkSession)&             theWS,
+                                 const Handle(XCAFDimTolObjects_DimensionObject)& theObject,
+                                 const Handle(StepRepr_ConstructiveGeometryRepresentation)& theRepr,
+                                 Handle(StepRepr_ShapeAspect)&                        theFirstSA,
+                                 Handle(StepRepr_ShapeAspect)&                        theSecondSA,
+                                 NCollection_Vector<Handle(StepGeom_CartesianPoint)>& thePnts,
+                                 const StepData_Factors& theLocalFactors)
 {
   const Handle(Interface_InterfaceModel)& aModel = theWS->Model();
   // First point
@@ -3645,7 +3529,7 @@ static void WriteDerivedGeometry(
     GeomToStep_MakeCartesianPoint   aPointMaker(theObject->GetPoint(),
                                               theLocalFactors.LengthFactor());
     Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
-    theGeoms.Append(aPoint);
+    thePnts.Append(aPoint);
     Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
     aDSA->Init(new TCollection_HAsciiString(),
                new TCollection_HAsciiString(),
@@ -3680,7 +3564,7 @@ static void WriteDerivedGeometry(
     GeomToStep_MakeCartesianPoint   aPointMaker(theObject->GetPoint2(),
                                               theLocalFactors.LengthFactor());
     Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
-    theGeoms.Append(aPoint);
+    thePnts.Append(aPoint);
     Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
     aDSA->Init(new TCollection_HAsciiString(),
                new TCollection_HAsciiString(),
@@ -4001,8 +3885,11 @@ void STEPCAFControl_Writer::writeToleranceZone(
   aModel->AddWithRefs(aPAMWU);
 }
 
-//==================================================================================================
-
+//=======================================================================
+// function : writeGeomTolerance
+// purpose  : auxiliary (write Geometric_Tolerance entity for given shapes,
+//           label and datum system)
+//======================================================================
 void STEPCAFControl_Writer::writeGeomTolerance(
   const Handle(XSControl_WorkSession)&                      theWS,
   const TDF_LabelSequence&                                  theShapeSeqL,
@@ -4029,37 +3916,14 @@ void STEPCAFControl_Writer::writeGeomTolerance(
   aLMWU->Init(aValueMember, aUnit);
   aModel->AddWithRefs(aLMWU);
 
-  // Auxiliary entities for derived geometry
-  Handle(StepRepr_ConstructiveGeometryRepresentation) aCGRepr =
-    new StepRepr_ConstructiveGeometryRepresentation();
-  Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel =
-    new StepRepr_ConstructiveGeometryRepresentationRelationship();
-  NCollection_Vector<Handle(StepGeom_GeometricRepresentationItem)> aConnectionGeometry;
-
   // Geometric_Tolerance target
   Handle(StepRepr_ShapeAspect)                 aMainSA;
   Handle(StepRepr_RepresentationContext)       dummyRC;
   Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
   if (theShapeSeqL.Length() == 1)
   {
-    const TDF_Label&            aShLabel = theShapeSeqL.Value(1);
-    Handle(TDataStd_UAttribute) aSupAttr;
-    TopoDS_Shape                aShape = XCAFDoc_ShapeTool::GetShape(aShLabel);
-    if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr))
-    {
-      aMainSA = WriteSupplementalGeometry(theWS,
-                                          aCGRepr,
-                                          aShLabel,
-                                          aShape,
-                                          dummyRC,
-                                          dummyGISU,
-                                          aConnectionGeometry,
-                                          theLocalFactors);
-    }
-    else
-    {
-      aMainSA = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU);
-    }
+    TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(1));
+    aMainSA             = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU);
     aModel->AddWithRefs(aMainSA);
   }
   else
@@ -4067,25 +3931,9 @@ void STEPCAFControl_Writer::writeGeomTolerance(
     Handle(StepRepr_CompositeShapeAspect) aCSA;
     for (TDF_LabelSequence::Iterator aShIter(theShapeSeqL); aShIter.More(); aShIter.Next())
     {
-      const TDF_Label&             aShLabel = aShIter.Value();
-      Handle(TDataStd_UAttribute)  aSupAttr;
-      TopoDS_Shape                 aShape = XCAFDoc_ShapeTool::GetShape(aShLabel);
-      Handle(StepRepr_ShapeAspect) aSA;
-      if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr))
-      {
-        aSA = WriteSupplementalGeometry(theWS,
-                                        aCGRepr,
-                                        aShLabel,
-                                        aShape,
-                                        dummyRC,
-                                        dummyGISU,
-                                        aConnectionGeometry,
-                                        theLocalFactors);
-      }
-      else
-      {
-        aSA = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU);
-      }
+      TopoDS_Shape                 aShape = XCAFDoc_ShapeTool::GetShape(aShIter.Value());
+      Handle(StepRepr_ShapeAspect) aSA =
+        writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU);
       if (aSA.IsNull())
         continue;
       if (aCSA.IsNull())
@@ -4100,22 +3948,6 @@ void STEPCAFControl_Writer::writeGeomTolerance(
     }
     aMainSA = aCSA;
   }
-
-  // Write Derived geometry
-  if (aConnectionGeometry.Length() > 0)
-  {
-    Handle(StepRepr_HArray1OfRepresentationItem) anItems =
-      new StepRepr_HArray1OfRepresentationItem(1, aConnectionGeometry.Length());
-    for (Standard_Integer i = 0; i < aConnectionGeometry.Length(); ++i)
-      anItems->SetValue(i + 1, aConnectionGeometry(i));
-    aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC);
-    aCGReprRel->Init(new TCollection_HAsciiString(),
-                     new TCollection_HAsciiString(),
-                     dummyGISU->UsedRepresentation(),
-                     aCGRepr);
-    aModel->AddWithRefs(aCGReprRel);
-  }
-
   StepDimTol_GeometricToleranceTarget aGTTarget;
   aGTTarget.SetValue(aMainSA);
 
@@ -4729,9 +4561,9 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo
     new StepRepr_ConstructiveGeometryRepresentation();
   Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel =
     new StepRepr_ConstructiveGeometryRepresentationRelationship();
-  NCollection_Vector<Handle(StepGeom_GeometricRepresentationItem)> aConnectionGeometry;
-  Handle(StepRepr_RepresentationContext)                           dummyRC;
-  Handle(StepAP242_GeometricItemSpecificUsage)                     dummyGISU;
+  NCollection_Vector<Handle(StepGeom_CartesianPoint)> aConnectionPnts;
+  Handle(StepRepr_RepresentationContext)              dummyRC;
+  Handle(StepAP242_GeometricItemSpecificUsage)        dummyGISU;
   for (TDF_LabelSequence::Iterator aDGTIter(aDGTLabels); aDGTIter.More(); aDGTIter.Next())
   {
     const TDF_Label&          aDimensionL = aDGTIter.Value();
@@ -4768,24 +4600,8 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo
     Handle(StepRepr_ShapeAspect) aFirstSA, aSecondSA;
     if (aFirstShapeL.Length() == 1)
     {
-      const TDF_Label&            aShLabel = aFirstShapeL.Value(1);
-      TopoDS_Shape                aShape   = XCAFDoc_ShapeTool::GetShape(aShLabel);
-      Handle(TDataStd_UAttribute) aSupAttr;
-      if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr))
-      {
-        aFirstSA = WriteSupplementalGeometry(theWS,
-                                             aCGRepr,
-                                             aShLabel,
-                                             aShape,
-                                             dummyRC,
-                                             dummyGISU,
-                                             aConnectionGeometry,
-                                             theLocalFactors);
-      }
-      else
-      {
-        aFirstSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU);
-      }
+      TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(1));
+      aFirstSA            = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU);
       if (aRC.IsNull() && !dummyRC.IsNull())
         aRC = dummyRC;
     }
@@ -4794,25 +4610,9 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo
       Handle(StepRepr_CompositeShapeAspect) aCSA;
       for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++)
       {
-        const TDF_Label&             aShLabel = aFirstShapeL.Value(shIt);
-        TopoDS_Shape                 aShape   = XCAFDoc_ShapeTool::GetShape(aShLabel);
-        Handle(TDataStd_UAttribute)  aSupAttr;
-        Handle(StepRepr_ShapeAspect) aSA;
-        if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr))
-        {
-          aSA = WriteSupplementalGeometry(theWS,
-                                          aCGRepr,
-                                          aShLabel,
-                                          aShape,
-                                          dummyRC,
-                                          dummyGISU,
-                                          aConnectionGeometry,
-                                          theLocalFactors);
-        }
-        else
-        {
-          aSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU);
-        }
+        TopoDS_Shape                 aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt));
+        Handle(StepRepr_ShapeAspect) aSA =
+          writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU);
         if (aSA.IsNull())
           continue;
         if (aCSA.IsNull())
@@ -4833,27 +4633,10 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo
       }
       aFirstSA = aCSA;
     }
-
     if (aSecondShapeL.Length() == 1)
     {
-      const TDF_Label&            aShLabel = aSecondShapeL.Value(1);
-      TopoDS_Shape                aShape   = XCAFDoc_ShapeTool::GetShape(aShLabel);
-      Handle(TDataStd_UAttribute) aSupAttr;
-      if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr))
-      {
-        aSecondSA = WriteSupplementalGeometry(theWS,
-                                              aCGRepr,
-                                              aShLabel,
-                                              aShape,
-                                              dummyRC,
-                                              dummyGISU,
-                                              aConnectionGeometry,
-                                              theLocalFactors);
-      }
-      else
-      {
-        aSecondSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU);
-      }
+      TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(1));
+      aSecondSA           = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU);
       if (aRC.IsNull() && !dummyRC.IsNull())
         aRC = dummyRC;
     }
@@ -4862,25 +4645,9 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo
       Handle(StepRepr_CompositeShapeAspect) aCSA;
       for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++)
       {
-        const TDF_Label&             aShLabel = aSecondShapeL.Value(shIt);
-        TopoDS_Shape                 aShape   = XCAFDoc_ShapeTool::GetShape(aShLabel);
-        Handle(TDataStd_UAttribute)  aSupAttr;
-        Handle(StepRepr_ShapeAspect) aSA;
-        if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr))
-        {
-          aSA = WriteSupplementalGeometry(theWS,
-                                          aCGRepr,
-                                          aShLabel,
-                                          aShape,
-                                          dummyRC,
-                                          dummyGISU,
-                                          aConnectionGeometry,
-                                          theLocalFactors);
-        }
-        else
-        {
-          aSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU);
-        }
+        TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(shIt));
+        Handle(StepRepr_ShapeAspect) aSA =
+          writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU);
         if (aCSA.IsNull() && !aSA.IsNull())
         {
           aCSA = new StepRepr_CompositeShapeAspect();
@@ -4924,7 +4691,7 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo
                            aCGRepr,
                            aFirstSA,
                            aSecondSA,
-                           aConnectionGeometry,
+                           aConnectionPnts,
                            theLocalFactors);
     XCAFDimTolObjects_DimensionType aDimType = anObject->GetType();
     if (XCAFDimTolObjects_DimensionObject::IsDimensionalLocation(aDimType))
@@ -5027,12 +4794,12 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo
                       theLocalFactors);
   }
   // Write Derived geometry
-  if (aConnectionGeometry.Length() > 0)
+  if (aConnectionPnts.Length() > 0)
   {
     Handle(StepRepr_HArray1OfRepresentationItem) anItems =
-      new StepRepr_HArray1OfRepresentationItem(1, aConnectionGeometry.Length());
-    for (Standard_Integer i = 0; i < aConnectionGeometry.Length(); i++)
-      anItems->SetValue(i + 1, aConnectionGeometry(i));
+      new StepRepr_HArray1OfRepresentationItem(1, aConnectionPnts.Length());
+    for (Standard_Integer i = 0; i < aConnectionPnts.Length(); i++)
+      anItems->SetValue(i + 1, aConnectionPnts(i));
     aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC);
     aCGReprRel->Init(new TCollection_HAsciiString(),
                      new TCollection_HAsciiString(),
index d5b0339e2c7801e8aa81a61261dead6bd5e63487..ee39daf9449dbb845a73922c31824a388b522915 100644 (file)
@@ -408,7 +408,6 @@ protected:
                           const Handle(StepDimTol_GeometricTolerance)&         theEntity,
                           const Handle(StepRepr_RepresentationContext)&        theRC);
 
-  //! Write Geometric_Tolerance entity for given shapes, label and datum system.
   void writeGeomTolerance(const Handle(XSControl_WorkSession)&                      theWS,
                           const TDF_LabelSequence&                                  theShapeSeqL,
                           const TDF_Label&                                          theGeomTolL,
index 87fa85fa491edbcdb1376258178cd21913c3b316..8b5e8ab7f8d4ff11ea48b57ec0009b6be7cf0b21 100644 (file)
@@ -238,30 +238,6 @@ const Standard_GUID& XCAFDoc::ViewRefAnnotationGUID()
   return ID;
 }
 
-//==================================================================================================
-
-const Standard_GUID& XCAFDoc::SupplementalContainerGUID()
-{
-  static const Standard_GUID ID("da071945-9557-41b4-9e44-19e649f98b54");
-  return ID;
-}
-
-//==================================================================================================
-
-const Standard_GUID& XCAFDoc::SupplementalRefGUID()
-{
-  static const Standard_GUID ID("85a1b8d7-0936-4e8b-a953-a8bd7731411a");
-  return ID;
-}
-
-//==================================================================================================
-
-const Standard_GUID& XCAFDoc::SupplementalGeometryGUID()
-{
-  static const Standard_GUID ID("e17cce33-1aa2-4b7f-9060-6e469a7954a9");
-  return ID;
-}
-
 //=================================================================================================
 
 const Standard_GUID& XCAFDoc::LockGUID()
index eddf019ea472f56d59fa191258af938484bf343f..248854b33e9eff60921c74cc6c8a494bea4ef61c 100644 (file)
@@ -108,15 +108,6 @@ public:
   Standard_EXPORT static const Standard_GUID& ViewRefNoteGUID();
   Standard_EXPORT static const Standard_GUID& ViewRefAnnotationGUID();
 
-  //! Returns GUID for TreeNode representing compound of supplemental geometry
-  Standard_EXPORT static const Standard_GUID& SupplementalContainerGUID();
-
-  //! Returns GUID for TreeNode representing reference for supplemental geometry
-  Standard_EXPORT static const Standard_GUID& SupplementalRefGUID();
-
-  //! Returns GUID for TreeNode representing supplemental geometry
-  Standard_EXPORT static const Standard_GUID& SupplementalGeometryGUID();
-
   //! Returns GUID for UAttribute identifying lock flag
   Standard_EXPORT static const Standard_GUID& LockGUID();