]> OCCT Git - occt.git/commitdiff
Data Exchange - Losing attributes on NonManifold STEP #284 step_losing_attrs
authordpasukhi <dpasukhi@opencascade.com>
Fri, 24 Jan 2025 01:20:44 +0000 (01:20 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Fri, 24 Jan 2025 09:51:54 +0000 (09:51 +0000)
Move step related processing from XSBase to STP module.
Added history apply after reading of NonManifold

src/STEPControl/STEPControl_Controller.cxx
src/ShapeUpgrade/ShapeUpgrade_RemoveLocations.hxx
src/XSAlgo/XSAlgo_ShapeProcessor.cxx
src/XSAlgo/XSAlgo_ShapeProcessor.hxx
src/XSControl/XSControl_TransferWriter.cxx
tests/bugs/step/bug33815 [new file with mode: 0644]

index 62ba2982fbf28416d9721dfce936077bd9f675d4..f4cd4bbbb93d97ffb48fd2c2b5aec25491185f80 100644 (file)
 #include <STEPSelections_SelectForTransfer.hxx>
 #include <STEPSelections_SelectGSCurves.hxx>
 #include <STEPSelections_SelectInstances.hxx>
+#include <ShapeUpgrade_RemoveLocations.hxx>
 #include <TopoDS_Shape.hxx>
 #include <Transfer_ActorOfTransientProcess.hxx>
 #include <XSAlgo.hxx>
+#include <XSAlgo_ShapeProcessor.hxx>
 #include <XSControl_WorkSession.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(STEPControl_Controller,XSControl_Controller)
@@ -437,10 +439,22 @@ IFSelect_ReturnStatus  STEPControl_Controller::TransferWriteShape
   Handle(STEPControl_ActorWrite) ActWrite =
     Handle(STEPControl_ActorWrite)::DownCast(myAdaptorWrite);
 //    A PRESENT ON PASSE PAR LE PROFILE
+  Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(model);
   if (!ActWrite.IsNull()) 
-    ActWrite->SetGroupMode (Handle(StepData_StepModel)::DownCast(model)->InternalParameters.WriteAssembly);
-
-  return XSControl_Controller::TransferWriteShape(shape, FP, model, modeshape, theProgress);
+    ActWrite->SetGroupMode (aModel->InternalParameters.WriteAssembly);
+  TopoDS_Shape aShape = shape;
+  TopTools_DataMapOfShapeShape aModifedMap;
+  if (aModel->InternalParameters.WriteNonmanifold)
+  {
+    ShapeUpgrade_RemoveLocations aRemLoc;
+    aRemLoc.SetRemoveLevel(TopAbs_COMPOUND);
+    aRemLoc.Remove(aShape);
+    aShape = aRemLoc.GetResult();
+    aModifedMap = aRemLoc.GetModifiedShapesMap();
+  }
+  const IFSelect_ReturnStatus aStatus = XSControl_Controller::TransferWriteShape(aShape, FP, model, modeshape, theProgress);
+  XSAlgo_ShapeProcessor::MergeShapeTransferInfo(FP, aModifedMap, Handle(ShapeExtend_MsgRegistrator)());
+  return aStatus;
 }
 
 Standard_Boolean STEPControl_Controller::Init ()
index 4e80dfa3654dbb6fa764f6bc12c8c11d183be255..c8aa96881ef5371a559723603c5edfe108753e07 100644 (file)
@@ -57,24 +57,21 @@ public:
   //! Returns modified shape obtained from initial shape.
     TopoDS_Shape ModifiedShape (const TopoDS_Shape& theInitShape) const;
 
+  //! Returns map of modified shapes.
+  const TopTools_DataMapOfShapeShape& GetModifiedShapesMap() const { return myMapNewShapes; }
 
+    DEFINE_STANDARD_RTTIEXT(ShapeUpgrade_RemoveLocations, Standard_Transient)
 
+  protected:
+  private:
+    Standard_EXPORT Standard_Boolean MakeNewShape(const TopoDS_Shape&    theShape,
+                                                  const TopoDS_Shape&    theAncShape,
+                                                  TopoDS_Shape&          theNewShape,
+                                                  const Standard_Boolean theRemoveLoc);
 
-  DEFINE_STANDARD_RTTIEXT(ShapeUpgrade_RemoveLocations,Standard_Transient)
-
-protected:
-
-
-
-
-private:
-
-  
-  Standard_EXPORT Standard_Boolean MakeNewShape (const TopoDS_Shape& theShape, const TopoDS_Shape& theAncShape, TopoDS_Shape& theNewShape, const Standard_Boolean theRemoveLoc);
-
-  TopAbs_ShapeEnum myLevelRemoving;
-  TopoDS_Shape myShape;
-  TopTools_DataMapOfShapeShape myMapNewShapes;
+    TopAbs_ShapeEnum             myLevelRemoving;
+    TopoDS_Shape                 myShape;
+    TopTools_DataMapOfShapeShape myMapNewShapes;
 
 
 };
index f41bce0505a60ebfa5cb6c62aa8c44c90c9c64a9..18c0868e5153b8d24612aadc598e7243974a28ef 100644 (file)
@@ -160,24 +160,22 @@ void XSAlgo_ShapeProcessor::addMessages(const Handle(ShapeExtend_MsgRegistrator)
 
 //=============================================================================
 
-void XSAlgo_ShapeProcessor::MergeTransferInfo(const Handle(Transfer_TransientProcess)& theTransientProcess,
-                                              const Standard_Integer                   theFirstTPItemIndex) const
+void XSAlgo_ShapeProcessor::MergeShapeTransferInfo(
+  const Handle(Transfer_TransientProcess)& theTransientProcess,
+  const TopTools_DataMapOfShapeShape&      theModifiedShapesMap,
+  const Standard_Integer                   theFirstTPItemIndex,
+  Handle(ShapeExtend_MsgRegistrator)       theMessages)
 {
-  if (myContext.IsNull())
+  if (theModifiedShapesMap.IsEmpty())
   {
     return;
   }
-
-  const TopTools_DataMapOfShapeShape& aShapesMap = myContext->Map();
-  Handle(ShapeExtend_MsgRegistrator)  aMessages  = myContext->Messages();
-  if (aShapesMap.IsEmpty() && (aMessages.IsNull() || aMessages->MapShape().IsEmpty()))
+  const bool aToPrint = !theMessages.IsNull() && !theMessages->MapShape().IsEmpty();
+  for (Standard_Integer i = std::max(theFirstTPItemIndex, 1); i <= theTransientProcess->NbMapped();
+       ++i)
   {
-    return;
-  }
-
-  for (Standard_Integer i = std::max(theFirstTPItemIndex, 1); i <= theTransientProcess->NbMapped(); ++i)
-  {
-    Handle(TransferBRep_ShapeBinder) aShapeBinder = Handle(TransferBRep_ShapeBinder)::DownCast(theTransientProcess->MapItem(i));
+    Handle(TransferBRep_ShapeBinder) aShapeBinder =
+      Handle(TransferBRep_ShapeBinder)::DownCast(theTransientProcess->MapItem(i));
     if (aShapeBinder.IsNull() || aShapeBinder->Result().IsNull())
     {
       continue;
@@ -185,17 +183,17 @@ void XSAlgo_ShapeProcessor::MergeTransferInfo(const Handle(Transfer_TransientPro
 
     const TopoDS_Shape anOriginalShape = aShapeBinder->Result();
 
-    if (aShapesMap.IsBound(anOriginalShape))
+    if (theModifiedShapesMap.IsBound(anOriginalShape))
     {
-      aShapeBinder->SetResult(aShapesMap.Find(anOriginalShape));
+      aShapeBinder->SetResult(theModifiedShapesMap.Find(anOriginalShape));
     }
     else if (!anOriginalShape.Location().IsIdentity())
     {
       TopLoc_Location aNullLoc;
       TopoDS_Shape    aTemporaryShape = anOriginalShape.Located(aNullLoc);
-      if (aShapesMap.IsBound(aTemporaryShape))
+      if (theModifiedShapesMap.IsBound(aTemporaryShape))
       {
-        aShapeBinder->SetResult(aShapesMap.Find(aTemporaryShape));
+        aShapeBinder->SetResult(theModifiedShapesMap.Find(aTemporaryShape));
       }
     }
     else
@@ -206,10 +204,10 @@ void XSAlgo_ShapeProcessor::MergeTransferInfo(const Handle(Transfer_TransientPro
       // Remember modifications.
       for (TopExp_Explorer anExpSE(anOriginalShape, TopAbs_EDGE); anExpSE.More(); anExpSE.Next())
       {
-        if (aShapesMap.IsBound(anExpSE.Current()))
+        if (theModifiedShapesMap.IsBound(anExpSE.Current()))
         {
           aHasModifiedEdges           = Standard_True;
-          TopoDS_Shape aModifiedShape = aShapesMap.Find(anExpSE.Current());
+          TopoDS_Shape aModifiedShape = theModifiedShapesMap.Find(anExpSE.Current());
           aReShaper.Replace(anExpSE.Current(), aModifiedShape);
         }
       }
@@ -222,50 +220,76 @@ void XSAlgo_ShapeProcessor::MergeTransferInfo(const Handle(Transfer_TransientPro
     }
 
     // update messages
-    addMessages(aMessages, anOriginalShape, aShapeBinder);
+    if (aToPrint)
+    {
+      addMessages(theMessages, anOriginalShape, aShapeBinder);
+    }
   }
 }
 
 //=============================================================================
 
-void XSAlgo_ShapeProcessor::MergeTransferInfo(const Handle(Transfer_FinderProcess)& theFinderProcess) const
+void XSAlgo_ShapeProcessor::MergeTransferInfo(
+  const Handle(Transfer_TransientProcess)& theTransientProcess,
+  const Standard_Integer                   theFirstTPItemIndex) const
 {
   if (myContext.IsNull())
   {
     return;
   }
+  return MergeShapeTransferInfo(theTransientProcess,
+                                myContext->Map(),
+                                theFirstTPItemIndex,
+                                myContext->Messages());
+}
 
-  const TopTools_DataMapOfShapeShape& aShapesMap = myContext->Map();
-  Handle(ShapeExtend_MsgRegistrator)  aMessages  = myContext->Messages();
+//=============================================================================
+
+void XSAlgo_ShapeProcessor::MergeShapeTransferInfo(
+  const Handle(Transfer_FinderProcess)& theFinderProcess,
+  const TopTools_DataMapOfShapeShape&   theModifiedShapesMap,
+  Handle(ShapeExtend_MsgRegistrator)    theMessages)
+{
+  if (theModifiedShapesMap.IsEmpty())
+  {
+    return;
+  }
+  const bool aToPrint = !theMessages.IsNull() && !theMessages->MapShape().IsEmpty();
 
-  for (TopTools_DataMapIteratorOfDataMapOfShapeShape ShapeShapeIterator(aShapesMap); ShapeShapeIterator.More();
+  for (TopTools_DataMapIteratorOfDataMapOfShapeShape ShapeShapeIterator(theModifiedShapesMap);
+       ShapeShapeIterator.More();
        ShapeShapeIterator.Next())
   {
-    const TopoDS_Shape anOriginalShape             = ShapeShapeIterator.Key();
-    const TopoDS_Shape aResultShape                = ShapeShapeIterator.Value();
+    const TopoDS_Shape anOriginalShape = ShapeShapeIterator.Key();
+    const TopoDS_Shape aResultShape    = ShapeShapeIterator.Value();
 
-    Handle(TransferBRep_ShapeMapper) aResultMapper = TransferBRep::ShapeMapper(theFinderProcess, aResultShape);
-    Handle(Transfer_Binder)          aResultBinder = theFinderProcess->Find(aResultMapper);
+    Handle(TransferBRep_ShapeMapper) aResultMapper =
+      TransferBRep::ShapeMapper(theFinderProcess, aResultShape);
+    Handle(Transfer_Binder) aResultBinder = theFinderProcess->Find(aResultMapper);
 
     if (aResultBinder.IsNull())
     {
       aResultBinder = new TransferBRep_ShapeBinder(aResultShape);
-      //if <orig> shape was split, put entities corresponding to new shapes
-      // into Transfer_TransientListBinder.
+      // if <orig> shape was split, put entities corresponding to new shapes
+      //  into Transfer_TransientListBinder.
       if (anOriginalShape.ShapeType() > aResultShape.ShapeType())
       {
         TopoDS_Shape                         aSubShape;
-        Handle(Transfer_TransientListBinder) aTransientListBinder = new Transfer_TransientListBinder;
-        for (TopoDS_Iterator aSubShapeIter(aResultShape); aSubShapeIter.More(); aSubShapeIter.Next())
+        Handle(Transfer_TransientListBinder) aTransientListBinder =
+          new Transfer_TransientListBinder;
+        for (TopoDS_Iterator aSubShapeIter(aResultShape); aSubShapeIter.More();
+             aSubShapeIter.Next())
         {
           const TopoDS_Shape      aCurrentSubShape = aSubShapeIter.Value();
-          Handle(Transfer_Finder) aSubShapeMapper  = TransferBRep::ShapeMapper(theFinderProcess, aCurrentSubShape);
+          Handle(Transfer_Finder) aSubShapeMapper =
+            TransferBRep::ShapeMapper(theFinderProcess, aCurrentSubShape);
           if (aSubShapeMapper.IsNull())
           {
             continue;
           }
 
-          Handle(Standard_Transient) aTransientResult = theFinderProcess->FindTransient(aSubShapeMapper);
+          Handle(Standard_Transient) aTransientResult =
+            theFinderProcess->FindTransient(aSubShapeMapper);
           if (aTransientResult.IsNull())
           {
             continue;
@@ -284,8 +308,9 @@ void XSAlgo_ShapeProcessor::MergeTransferInfo(const Handle(Transfer_FinderProces
       }
     }
 
-    Handle(TransferBRep_ShapeMapper) anOriginalMapper = TransferBRep::ShapeMapper(theFinderProcess, anOriginalShape);
-    Handle(Transfer_Binder)          anOriginalBinder = theFinderProcess->Find(anOriginalMapper);
+    Handle(TransferBRep_ShapeMapper) anOriginalMapper =
+      TransferBRep::ShapeMapper(theFinderProcess, anOriginalShape);
+    Handle(Transfer_Binder) anOriginalBinder = theFinderProcess->Find(anOriginalMapper);
     if (anOriginalBinder.IsNull())
     {
       theFinderProcess->Bind(anOriginalMapper, aResultBinder);
@@ -296,8 +321,22 @@ void XSAlgo_ShapeProcessor::MergeTransferInfo(const Handle(Transfer_FinderProces
     }
 
     // update messages
-    addMessages(aMessages, anOriginalShape, aResultBinder);
+    if (aToPrint)
+    {
+      addMessages(theMessages, anOriginalShape, aResultBinder);
+    }
+  }
+}
+
+//=============================================================================
+
+void XSAlgo_ShapeProcessor::MergeTransferInfo(const Handle(Transfer_FinderProcess)& theFinderProcess) const
+{
+  if (myContext.IsNull())
+  {
+    return;
   }
+  return MergeShapeTransferInfo(theFinderProcess, myContext->Map(), myContext->Messages());
 }
 
 //=============================================================================
index 57f332825d2106b9f18c5541554153cce3f59fe4..8ce3dda32d2d14197387b8c92515a55b7a8bb180 100644 (file)
@@ -17,6 +17,7 @@
 #include <DE_ShapeFixParameters.hxx>
 #include <ShapeProcess.hxx>
 #include <TopAbs_ShapeEnum.hxx>
+#include <TopTools_DataMapOfShapeShape.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Face.hxx>
 
@@ -134,6 +135,27 @@ public:
   //! value associated with the key "xstep.cascade.unit".
   Standard_EXPORT static void PrepareForTransfer();
 
+  //! Merge the results of the shape processing with the finder process.
+  //! @param theTransientProcess Transfer process to merge with.
+  //! @param theModifiedShapesMap Map of modified shapes.
+  //! @param theFirstTPItemIndex Index of the first item in the transfer process to merge with.
+  //! @param theMessages Messages to add.
+  Standard_EXPORT static void MergeShapeTransferInfo(
+    const Handle(Transfer_TransientProcess)& theFinderProcess,
+    const TopTools_DataMapOfShapeShape&   theModifiedShapesMap,
+    const Standard_Integer                theFirstTPItemIndex,
+    Handle(ShapeExtend_MsgRegistrator)    theMessages);
+
+  //! Merge the results of the shape processing with the transfer process.
+  //! @param theTransientProcess Transfer process to merge with.
+  //! @param theModifiedShapesMap Map of modified shapes.
+  //! @param theFirstTPItemIndex Index of the first item in the transfer process to merge with.
+  //! @param theMessages Messages to add.
+  Standard_EXPORT static void MergeShapeTransferInfo(
+    const Handle(Transfer_FinderProcess)& theTransientProcess,
+    const TopTools_DataMapOfShapeShape&   theModifiedShapesMap,
+    Handle(ShapeExtend_MsgRegistrator)    theMessages);
+
 private:
   //! Initialize the context with the specified shape.
   //! @param theShape Shape to process.
index ec6871d8f7e809bc1a71ecf00b3bac24e069068e..838f832f65e161a8383d59ec471d0ad1c30b32d8 100644 (file)
@@ -26,7 +26,6 @@
 #include <XSControl_Controller.hxx>
 #include <XSControl_TransferWriter.hxx>
 #include <XSControl_Utils.hxx>
-#include <ShapeUpgrade_RemoveLocations.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(XSControl_TransferWriter,Standard_Transient)
 
@@ -141,14 +140,6 @@ IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteShape
   if (theModel.IsNull()) return IFSelect_RetVoid;
 
   TopoDS_Shape aShape = theShape;
-  Standard_Boolean isNMMode = Interface_Static::IVal("write.step.nonmanifold") != 0;
-  if (isNMMode)
-  {
-    ShapeUpgrade_RemoveLocations aRemLoc;
-    aRemLoc.SetRemoveLevel(TopAbs_COMPOUND);
-    aRemLoc.Remove(aShape);
-    aShape = aRemLoc.GetResult();
-  }
 
   if (myTransferWriter.IsNull()) myTransferWriter = new Transfer_FinderProcess;
 //  effacer l actor : Controller s en charge
diff --git a/tests/bugs/step/bug33815 b/tests/bugs/step/bug33815
new file mode 100644 (file)
index 0000000..cb71e00
--- /dev/null
@@ -0,0 +1,30 @@
+puts "===================================="
+puts "0033815: Data Exchange, Step Export - No names in STEP file when writing in non-manifold mode"
+puts "===================================="
+puts ""
+
+pload OCAF
+Close D -silent
+
+XNewDoc D
+box box 1 1 1
+XAddShape D box
+
+param write.step.nonmanifold 1
+
+SetName D 0:1:1:1 "a'''\\b\n\t\\c\\\\\\\\"
+set original_name [GetName D 0:1:1:1]
+
+WriteStep D "$imagedir/${casename}.stp"
+Close D
+
+ReadStep D "$imagedir/${casename}.stp"
+set imported_name [GetName D 0:1:1:1]
+
+file delete "$imagedir/${casename}.stp"
+
+if {$original_name != $imported_name} {
+  puts "Error: 'Incorrect exporting name: $original_name != $imported_name"
+}
+
+Close D