From 1fc1a207b019b530df115b4299b10707e55e2751 Mon Sep 17 00:00:00 2001 From: akaftasev Date: Fri, 22 May 2020 13:04:49 +0300 Subject: [PATCH] 0031504: Data Exchange - Wrong output of progress indicator when writing to stl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added new condition for first indicated element at Draw_ProgressIndicator::Show(), because it’s more logical that at start progress starts at 0 Changed usage of Next() to Next(step) for increment progress to IND_THRESHOLD in RWStl::writeASCII() and RWStl::writeBinary() Changed condition for continuation of writing and add interrupt to this function Added possibility to use Progress indicator in writestl Changed paremeter in constructor Message_ProgressSentry aPS() IND_THRESHOLD to 1 Changed test --- src/Draw/Draw_ProgressIndicator.cxx | 4 ++-- src/RWStl/RWStl.cxx | 18 +++++++++------ src/StlAPI/StlAPI_Writer.cxx | 7 +++--- src/StlAPI/StlAPI_Writer.hxx | 4 +++- src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx | 3 ++- tests/bugs/fclasses/bug28478 | 2 +- tests/bugs/fclasses/bug31092 | 2 +- tests/de_mesh/shape_write_stl/B1 | 35 +++++++++++++++++++++++++++++ 8 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 tests/de_mesh/shape_write_stl/B1 diff --git a/src/Draw/Draw_ProgressIndicator.cxx b/src/Draw/Draw_ProgressIndicator.cxx index 6c92b2dda6..72e694453d 100644 --- a/src/Draw/Draw_ProgressIndicator.cxx +++ b/src/Draw/Draw_ProgressIndicator.cxx @@ -102,8 +102,8 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force) if ( scale.GetName().IsNull() ) continue; // skip unnamed scopes aText << " " << scale.GetName()->ToCString() << ": "; - // if scope has subscopes, print end of subscope as its current position - Standard_Real locPos = ( i >1 ? GetScope ( i-1 ).GetLast() : GetPosition() ); + // if scope has subscopes, print end of subscope as it s current position + Standard_Real locPos = ( (i >1 && GetPosition()!=0) ? GetScope ( i-1 ).GetLast() : GetPosition() ); // print progress info differently for finite and infinite scopes if ( scale.GetInfinite() ) { diff --git a/src/RWStl/RWStl.cxx b/src/RWStl/RWStl.cxx index 505b6f68ea..347e24d01f 100644 --- a/src/RWStl/RWStl.cxx +++ b/src/RWStl/RWStl.cxx @@ -281,12 +281,12 @@ Standard_Boolean RWStl::writeASCII (const Handle(Poly_Triangulation)& theMesh, char aBuffer[512]; memset (aBuffer, 0, sizeof(aBuffer)); + const Standard_Integer NBTriangles = theMesh->NbTriangles(); Message_ProgressSentry aPS (theProgInd, "Triangles", 0, - theMesh->NbTriangles(), IND_THRESHOLD); + NBTriangles, 1); const TColgp_Array1OfPnt& aNodes = theMesh->Nodes(); const Poly_Array1OfTriangle& aTriangles = theMesh->Triangles(); - const Standard_Integer NBTriangles = theMesh->NbTriangles(); Standard_Integer anElem[3] = {0, 0, 0}; for (Standard_Integer aTriIter = 1; aTriIter <= NBTriangles; ++aTriIter) { @@ -330,7 +330,9 @@ Standard_Boolean RWStl::writeASCII (const Handle(Poly_Triangulation)& theMesh, // update progress only per 1k triangles if ((aTriIter % IND_THRESHOLD) == 0) { - aPS.Next(); + if (!aPS.More()) + return Standard_False; + aPS.Next(IND_THRESHOLD); } } @@ -355,9 +357,10 @@ Standard_Boolean RWStl::writeBinary (const Handle(Poly_Triangulation)& theMesh, { return Standard_False; } - + + const Standard_Integer aNBTriangles = theMesh->NbTriangles(); Message_ProgressSentry aPS (theProgInd, "Triangles", 0, - theMesh->NbTriangles(), IND_THRESHOLD); + aNBTriangles, 1); const Standard_Size aNbChunkTriangles = 4096; const Standard_Size aChunkSize = aNbChunkTriangles * THE_STL_SIZEOF_FACET; @@ -366,7 +369,6 @@ Standard_Boolean RWStl::writeBinary (const Handle(Poly_Triangulation)& theMesh, const TColgp_Array1OfPnt& aNodes = theMesh->Nodes(); const Poly_Array1OfTriangle& aTriangles = theMesh->Triangles(); - const Standard_Integer aNBTriangles = theMesh->NbTriangles(); Standard_Character aConv[4]; convertInteger (aNBTriangles, aConv); @@ -431,7 +433,9 @@ Standard_Boolean RWStl::writeBinary (const Handle(Poly_Triangulation)& theMesh, // update progress only per 1k triangles if ((aTriIter % IND_THRESHOLD) == 0) { - aPS.Next(); + if (!aPS.More()) + return Standard_False; + aPS.Next(IND_THRESHOLD); } } diff --git a/src/StlAPI/StlAPI_Writer.cxx b/src/StlAPI/StlAPI_Writer.cxx index 277e490327..c25048f9af 100644 --- a/src/StlAPI/StlAPI_Writer.cxx +++ b/src/StlAPI/StlAPI_Writer.cxx @@ -41,7 +41,8 @@ StlAPI_Writer::StlAPI_Writer() //purpose : //============================================================================= Standard_Boolean StlAPI_Writer::Write (const TopoDS_Shape& theShape, - const Standard_CString theFileName) + const Standard_CString theFileName, + const Handle(Message_ProgressIndicator)& theProgress) { Standard_Integer aNbNodes = 0; Standard_Integer aNbTriangles = 0; @@ -125,8 +126,8 @@ Standard_Boolean StlAPI_Writer::Write (const TopoDS_Shape& theShape, OSD_Path aPath (theFileName); Standard_Boolean isDone = (myASCIIMode - ? RWStl::WriteAscii (aMesh, aPath) - : RWStl::WriteBinary (aMesh, aPath)); + ? RWStl::WriteAscii(aMesh, aPath, theProgress) + : RWStl::WriteBinary(aMesh, aPath, theProgress)); if (isDone && (aNbFacesNoTri > 0)) { diff --git a/src/StlAPI/StlAPI_Writer.hxx b/src/StlAPI/StlAPI_Writer.hxx index 257212e4dc..c517e8b03c 100644 --- a/src/StlAPI/StlAPI_Writer.hxx +++ b/src/StlAPI/StlAPI_Writer.hxx @@ -22,6 +22,7 @@ #include #include #include +#include class TopoDS_Shape; @@ -45,7 +46,8 @@ public: //! Converts a given shape to STL format and writes it to file with a given filename. //! \return the error state. Standard_EXPORT Standard_Boolean Write (const TopoDS_Shape& theShape, - const Standard_CString theFileName); + const Standard_CString theFileName, + const Handle(Message_ProgressIndicator)& theProgress = NULL); private: Standard_Boolean myASCIIMode; diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx index 5c3630a6d5..636c538d2e 100644 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx @@ -333,7 +333,8 @@ static Standard_Integer writestl } StlAPI_Writer aWriter; aWriter.ASCIIMode() = isASCIIMode; - Standard_Boolean isOK = aWriter.Write (aShape, argv[2]); + Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1); + Standard_Boolean isOK = aWriter.Write (aShape, argv[2], aProgress); if (!isOK) di << "** Error **: Mesh writing has been failed.\n"; } diff --git a/tests/bugs/fclasses/bug28478 b/tests/bugs/fclasses/bug28478 index 513f3f9cb7..30325d82b4 100644 --- a/tests/bugs/fclasses/bug28478 +++ b/tests/bugs/fclasses/bug28478 @@ -8,7 +8,7 @@ pload QAcommands set out [OCC28478 3 2] set expected { - {Progress: 0% Outer: 1 / 3} + {Progress: 0% Outer: 0 / 3} {Progress: 17% Outer: 1 / 3 Inner: 1 / 2} {Progress: 33% Outer: 1 / 3 Inner: 2 / 2} {Progress: 50% Outer: 2 / 3 Inner: 1 / 2} diff --git a/tests/bugs/fclasses/bug31092 b/tests/bugs/fclasses/bug31092 index 989dfb6ad3..0ab00529d7 100644 --- a/tests/bugs/fclasses/bug31092 +++ b/tests/bugs/fclasses/bug31092 @@ -8,7 +8,7 @@ pload QAcommands set out [OCC28478 3 2 -inf] set expected { - {Progress: 0% Outer: 1 / 3} + {Progress: 0% Outer: 0 / 3} {Progress: 11% Outer: 1 / 3 Inner: 1} {Progress: 17% Outer: 1 / 3 Inner: 2} {Progress: 20% Outer: 1 / 3 Inner: 3} diff --git a/tests/de_mesh/shape_write_stl/B1 b/tests/de_mesh/shape_write_stl/B1 new file mode 100644 index 0000000000..1c09e79653 --- /dev/null +++ b/tests/de_mesh/shape_write_stl/B1 @@ -0,0 +1,35 @@ +sphere s 10 +tessellate result s 100 100 +XProgress -tclOutput +XProgress +t +set out [writestl result s.stl] + +set expected { + {Progress: 0% Triangles: 0 / 20000} + {Progress: 5% Triangles: 1001 / 20000} + {Progress: 10% Triangles: 2001 / 20000} + {Progress: 15% Triangles: 3001 / 20000} + {Progress: 20% Triangles: 4001 / 20000} + {Progress: 25% Triangles: 5001 / 20000} + {Progress: 30% Triangles: 6001 / 20000} + {Progress: 35% Triangles: 7001 / 20000} + {Progress: 40% Triangles: 8001 / 20000} + {Progress: 45% Triangles: 9001 / 20000} + {Progress: 50% Triangles: 10001 / 20000} + {Progress: 55% Triangles: 11001 / 20000} + {Progress: 60% Triangles: 12001 / 20000} + {Progress: 65% Triangles: 13001 / 20000} + {Progress: 70% Triangles: 14001 / 20000} + {Progress: 75% Triangles: 15001 / 20000} + {Progress: 80% Triangles: 16001 / 20000} + {Progress: 85% Triangles: 17001 / 20000} + {Progress: 90% Triangles: 18001 / 20000} + {Progress: 95% Triangles: 19001 / 20000} + {Progress: 100% Triangles: 20000 / 20000} +} + +if { [string compare [string trim $out] [join $expected "\n"]] } { + puts "Error: output (see above) does not match expected one:" + puts "[join $expected "\n"]" + puts "" +}