]> OCCT Git - occt.git/commitdiff
Data Exchange, Step Export - Ignoring unit factors during tessellation export (#577)
authorikochetkova <irina.kochetkova@opencascade.com>
Fri, 20 Jun 2025 14:38:33 +0000 (15:38 +0100)
committerGitHub <noreply@github.com>
Fri, 20 Jun 2025 14:38:33 +0000 (15:38 +0100)
Provide unit factors into the tessellation export methods.

src/DataExchange/TKDESTEP/TopoDSToStep/TopoDSToStep_Builder.cxx
src/DataExchange/TKDESTEP/TopoDSToStep/TopoDSToStep_MakeTessellatedItem.cxx
src/DataExchange/TKDESTEP/TopoDSToStep/TopoDSToStep_MakeTessellatedItem.hxx
tests/bugs/step/bug_ocp1949
tests/bugs/step/bug_ocp1949_2 [new file with mode: 0644]

index 09e5579f7f87dbbae3801586e23ac7a9a59ee332..fff8e937a904de1a7a810a5205c868a67a7b546f 100644 (file)
@@ -173,7 +173,11 @@ void TopoDSToStep_Builder::Init(const TopoDS_Shape&                   aShape,
 
       if (theTessellatedGeomParam == 1 || (theTessellatedGeomParam == 2 && myResult.IsNull()))
       {
-        TopoDSToStep_MakeTessellatedItem MkTessShell(myShell, myTool, FP, aPS.Next());
+        TopoDSToStep_MakeTessellatedItem MkTessShell(myShell,
+                                                     myTool,
+                                                     FP,
+                                                     theLocalFactors,
+                                                     aPS.Next());
         if (MkTessShell.IsDone())
         {
           myTessellatedResult = MkTessShell.Value();
@@ -199,7 +203,7 @@ void TopoDSToStep_Builder::Init(const TopoDS_Shape&                   aShape,
         Message_ProgressScope aPS(theProgress, NULL, 1);
         // fourth parameter is true in order to create a tessellated_surface_set entity
         // or put false to create a triangulated_face instead
-        MkTessFace.Init(Face, myTool, FP, Standard_True, aPS.Next());
+        MkTessFace.Init(Face, myTool, FP, Standard_True, theLocalFactors, aPS.Next());
       }
 
       if (MkFace.IsDone() || MkTessFace.IsDone())
index 2bf496b879251c08eae0495e619501a6f5e7e50d..80ad10bdaeeda2830f8fd7c1c714d795235da725 100644 (file)
@@ -15,6 +15,7 @@
 #include <MoniTool_DataMapOfShapeTransient.hxx>
 #include <Poly.hxx>
 #include <StdFail_NotDone.hxx>
+#include <StepData_Factors.hxx>
 #include <StepVisual_FaceOrSurface.hxx>
 #include <StepShape_TopologicalRepresentationItem.hxx>
 #include <StepVisual_TessellatedShell.hxx>
@@ -40,11 +41,13 @@ static void InitTriangulation(const Handle(Poly_Triangulation)&       theMesh,
                               Handle(TColgp_HArray1OfXYZ)&            thePoints,
                               Handle(TColStd_HArray2OfReal)&          theNormals,
                               Handle(TColStd_HArray1OfInteger)&       theIndices,
-                              Handle(TColStd_HArray2OfInteger)&       theTrias)
+                              Handle(TColStd_HArray2OfInteger)&       theTrias,
+                              const StepData_Factors&                 theLocalFactors)
 {
+  Standard_Real aFactor = theLocalFactors.LengthFactor();
   for (Standard_Integer aNodeIndex = 1; aNodeIndex <= theMesh->NbNodes(); ++aNodeIndex)
   {
-    thePoints->SetValue(aNodeIndex, theMesh->Node(aNodeIndex).XYZ());
+    thePoints->SetValue(aNodeIndex, theMesh->Node(aNodeIndex).XYZ() / aFactor);
   }
   theCoordinates->Init(theName, thePoints);
   if (!theMesh->HasNormals())
@@ -86,10 +89,11 @@ TopoDSToStep_MakeTessellatedItem::TopoDSToStep_MakeTessellatedItem(
   TopoDSToStep_Tool&                    theTool,
   const Handle(Transfer_FinderProcess)& theFP,
   const Standard_Boolean                theToPreferSurfaceSet,
+  const StepData_Factors&               theLocalFactors,
   const Message_ProgressRange&          theProgress)
     : TopoDSToStep_Root()
 {
-  Init(theFace, theTool, theFP, theToPreferSurfaceSet, theProgress);
+  Init(theFace, theTool, theFP, theToPreferSurfaceSet, theLocalFactors, theProgress);
 }
 
 //=================================================================================================
@@ -98,10 +102,11 @@ TopoDSToStep_MakeTessellatedItem::TopoDSToStep_MakeTessellatedItem(
   const TopoDS_Shell&                   theShell,
   TopoDSToStep_Tool&                    theTool,
   const Handle(Transfer_FinderProcess)& theFP,
+  const StepData_Factors&               theLocalFactors,
   const Message_ProgressRange&          theProgress)
     : TopoDSToStep_Root()
 {
-  Init(theShell, theTool, theFP, theProgress);
+  Init(theShell, theTool, theFP, theLocalFactors, theProgress);
 }
 
 //=============================================================================
@@ -113,6 +118,7 @@ void TopoDSToStep_MakeTessellatedItem::Init(const TopoDS_Face&
                                             TopoDSToStep_Tool&                    theTool,
                                             const Handle(Transfer_FinderProcess)& theFP,
                                             const Standard_Boolean       theToPreferSurfaceSet,
+                                            const StepData_Factors&      theLocalFactors,
                                             const Message_ProgressRange& theProgress)
 {
   done = Standard_False;
@@ -133,7 +139,14 @@ void TopoDSToStep_MakeTessellatedItem::Init(const TopoDS_Face&
   Handle(TColStd_HArray1OfInteger) anIndices = new TColStd_HArray1OfInteger(1, aMesh->NbNodes());
   Handle(TColStd_HArray2OfInteger) aTrias =
     new TColStd_HArray2OfInteger(1, aMesh->NbTriangles(), 1, 3);
-  InitTriangulation(aMesh, aName, aCoordinates, aPoints, aNormals, anIndices, aTrias);
+  InitTriangulation(aMesh,
+                    aName,
+                    aCoordinates,
+                    aPoints,
+                    aNormals,
+                    anIndices,
+                    aTrias,
+                    theLocalFactors);
 
   const Standard_Boolean   aHasGeomLink = theTool.IsBound(theFace);
   StepVisual_FaceOrSurface aGeomLink;
@@ -182,6 +195,7 @@ void TopoDSToStep_MakeTessellatedItem::Init(const TopoDS_Face&
 void TopoDSToStep_MakeTessellatedItem::Init(const TopoDS_Shell&                   theShell,
                                             TopoDSToStep_Tool&                    theTool,
                                             const Handle(Transfer_FinderProcess)& theFP,
+                                            const StepData_Factors&               theLocalFactors,
                                             const Message_ProgressRange&          theProgress)
 {
   done = Standard_False;
@@ -202,7 +216,12 @@ void TopoDSToStep_MakeTessellatedItem::Init(const TopoDS_Shell&
   for (anExp.Init(theShell, TopAbs_FACE); anExp.More() && aPS.More(); anExp.Next(), aPS.Next())
   {
     const TopoDS_Face                aFace = TopoDS::Face(anExp.Current());
-    TopoDSToStep_MakeTessellatedItem aMakeFace(aFace, theTool, theFP, Standard_False, aPS.Next());
+    TopoDSToStep_MakeTessellatedItem aMakeFace(aFace,
+                                               theTool,
+                                               theFP,
+                                               Standard_False,
+                                               theLocalFactors,
+                                               aPS.Next());
     if (aMakeFace.IsDone())
     {
       aTessFaces.Append(Handle(StepVisual_TessellatedStructuredItem)::DownCast(aMakeFace.Value()));
index 8ade32c26e9cde29dcf73c43c51d4f821183fb06..dbfb5f594bf3455f6ae072c552c857d6d39f6882 100644 (file)
@@ -21,6 +21,7 @@
 #include <TopoDSToStep_Root.hxx>
 #include <Message_ProgressRange.hxx>
 
+class StepData_Factors;
 class StepVisual_TessellatedItem;
 class TopoDS_Face;
 class TopoDS_Shell;
@@ -40,23 +41,27 @@ public:
     TopoDSToStep_Tool&                    theTool,
     const Handle(Transfer_FinderProcess)& theFP,
     const Standard_Boolean                theToPreferSurfaceSet,
+    const StepData_Factors&               theLocalFactors,
     const Message_ProgressRange&          theProgress = Message_ProgressRange());
 
   Standard_EXPORT TopoDSToStep_MakeTessellatedItem(
     const TopoDS_Shell&                   theShell,
     TopoDSToStep_Tool&                    theTool,
     const Handle(Transfer_FinderProcess)& theFP,
+    const StepData_Factors&               theLocalFactors,
     const Message_ProgressRange&          theProgress = Message_ProgressRange());
 
   Standard_EXPORT void Init(const TopoDS_Face&                    theFace,
                             TopoDSToStep_Tool&                    theTool,
                             const Handle(Transfer_FinderProcess)& theFP,
                             const Standard_Boolean                theToPreferSurfaceSet,
+                            const StepData_Factors&               theLocalFactors,
                             const Message_ProgressRange& theProgress = Message_ProgressRange());
 
   Standard_EXPORT void Init(const TopoDS_Shell&                   theShell,
                             TopoDSToStep_Tool&                    theTool,
                             const Handle(Transfer_FinderProcess)& theFP,
+                            const StepData_Factors&               theLocalFactors,
                             const Message_ProgressRange& theProgress = Message_ProgressRange());
 
   Standard_EXPORT const Handle(StepVisual_TessellatedItem)& Value() const;
index 6e3d5b7af30fea250dfaec37f721c06675986585..ae51e8f1e3806264da4698e6809615632ac4eb7e 100644 (file)
@@ -15,12 +15,9 @@ set conf "
 provider.STEP.OCC.write.schema :        5
 provider.STEP.OCC.write.tessellated :   1
 "
-LoadConfiguration ${conf} -recursive on
-param write.step.schema 5
-param write.step.tessellated 1
 
-WriteStep D1 "$imagedir/${casename}.stp"
-ReadStep D2 "$imagedir/${casename}.stp"
+WriteFile D1 "$imagedir/${casename}.stp" -conf ${conf}
+ReadFile D2 "$imagedir/${casename}.stp"
 
 XGetOneShape a1 D1
 XGetOneShape a2 D2
@@ -44,8 +41,4 @@ if {([expr abs($REF_X - [lindex $pos2  9])] > $tol) ||
 Close D1
 Close D2
 file delete "$imagedir/${casename}.stp"
-set conf "
-provider.STEP.OCC.write.schema :        4
-provider.STEP.OCC.write.tessellated :   2
-"
-LoadConfiguration ${conf} -recursive on
+
diff --git a/tests/bugs/step/bug_ocp1949_2 b/tests/bugs/step/bug_ocp1949_2
new file mode 100644 (file)
index 0000000..a7d2f74
--- /dev/null
@@ -0,0 +1,48 @@
+puts "================================================"
+puts "OCP-1949: Apply a scaling transformation to STEP"
+puts "================================================"
+puts ""
+
+pload OCAF
+
+Close D1 -silent
+Close D2 -silent
+
+# Create simple mesh
+box b 1 1 1
+incmesh b 1
+writestl b "$imagedir/${casename}.stl"
+readstl b "$imagedir/${casename}.stl"
+
+# Create document with meters as internal units
+XNewDoc D1
+XSetLengthUnit D1 m
+XAddShape D1 b
+
+# apply parameters for tessellation export
+set conf "
+provider.STEP.OCC.write.schema :        5
+provider.STEP.OCC.write.tessellated :   1
+"
+
+WriteFile D1 "$imagedir/${casename}.stp" -conf ${conf}
+ReadFile D2 "$imagedir/${casename}.stp"
+
+XGetOneShape a1 D1
+XGetOneShape a2 D2
+
+# check sizes
+set m_diag [eval distpp [bounding a1]]
+set mm_diag [eval distpp [bounding a2]]
+set tol 0.1
+
+if {([expr abs($m_diag * 1000 - $mm_diag)] > $tol)} {
+  puts "Error: wrong size of models."
+  }
+
+# cleaning
+Close D1
+Close D2
+file delete "$imagedir/${casename}.stp"
+file delete "$imagedir/${casename}.stl"
+