From 3b1129a5465a5ed2cd4129ddbc99b11e1fa3bfcb Mon Sep 17 00:00:00 2001 From: asuraven Date: Tue, 15 Dec 2020 12:31:52 +0300 Subject: [PATCH] 0029723: Modeling Data - Get rid of second writing format (additional save of UV points) Default BinTools_ShapeSet format version has been changed from 3 to 1. BinMNaming_NamedShapeDriver (Bin OCAF) now writes shapes in 1st version of Binary format instead of 3rd. XmlMNaming_NamedShapeDriver (Xml OCAF) now writes shapes in 1st version of ASCII format instead of 2nd. writebrep now by default writes into 1st binary format version instead of 3rd. --- src/BRepTools/BRepTools_ShapeSet.cxx | 8 ++-- .../BinMNaming_NamedShapeDriver.cxx | 2 +- src/BinTools/BinTools_FormatVersion.hxx | 2 +- src/BinTools/BinTools_ShapeSet.cxx | 44 ++++++++++++------- src/DBRep/DBRep.cxx | 4 +- src/TopTools/TopTools_FormatVersion.hxx | 7 ++- src/TopTools/TopTools_ShapeSet.cxx | 9 ++-- .../XmlMNaming_NamedShapeDriver.cxx | 2 +- tests/bugs/moddata_3/bug29723 | 29 ++++++++++++ 9 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 tests/bugs/moddata_3/bug29723 diff --git a/src/BRepTools/BRepTools_ShapeSet.cxx b/src/BRepTools/BRepTools_ShapeSet.cxx index ab569703cc..f26089109c 100644 --- a/src/BRepTools/BRepTools_ShapeSet.cxx +++ b/src/BRepTools/BRepTools_ShapeSet.cxx @@ -599,7 +599,7 @@ void BRepTools_ShapeSet::WriteGeometry (const TopoDS_Shape& S, Standard_OStream OS << "\n"; // Write UV Points // for XML Persistence higher performance - if (FormatNb() >= TopTools_FormatVersion_VERSION_2) + if (FormatNb() == TopTools_FormatVersion_VERSION_2) { gp_Pnt2d Pf,Pl; if (CR->IsCurveOnClosedSurface()) { @@ -909,7 +909,7 @@ void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T, GeomTools::GetReal(IS, last); // read UV Points // for XML Persistence higher performance - if (FormatNb() >= TopTools_FormatVersion_VERSION_2) + if (FormatNb() == TopTools_FormatVersion_VERSION_2) { GeomTools::GetReal(IS, PfX); GeomTools::GetReal(IS, PfY); @@ -927,7 +927,7 @@ void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T, // Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End if (closed) { - if (FormatNb() >= TopTools_FormatVersion_VERSION_2) + if (FormatNb() == TopTools_FormatVersion_VERSION_2) myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc), myCurves2d.Curve2d(pc2), mySurfaces.Surface(s), @@ -948,7 +948,7 @@ void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T, } else { - if (FormatNb() >= TopTools_FormatVersion_VERSION_2) + if (FormatNb() == TopTools_FormatVersion_VERSION_2) myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc), mySurfaces.Surface(s), Locations().Location(l),tol, diff --git a/src/BinMNaming/BinMNaming_NamedShapeDriver.cxx b/src/BinMNaming/BinMNaming_NamedShapeDriver.cxx index eeb1a35354..98e3bab1ff 100644 --- a/src/BinMNaming/BinMNaming_NamedShapeDriver.cxx +++ b/src/BinMNaming/BinMNaming_NamedShapeDriver.cxx @@ -143,7 +143,7 @@ BinMNaming_NamedShapeDriver::BinMNaming_NamedShapeDriver (const Handle(Message_Messenger)& theMsgDriver) : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TNaming_NamedShape)->Name()), myShapeSet (Standard_False), - myFormatNb (BinTools_FormatVersion_VERSION_3) + myFormatNb (BinTools_FormatVersion_VERSION_1) { } diff --git a/src/BinTools/BinTools_FormatVersion.hxx b/src/BinTools/BinTools_FormatVersion.hxx index 6255f6ce10..faced8fb5a 100644 --- a/src/BinTools/BinTools_FormatVersion.hxx +++ b/src/BinTools/BinTools_FormatVersion.hxx @@ -24,7 +24,7 @@ enum BinTools_FormatVersion BinTools_FormatVersion_VERSION_3 = 3, //!< (OCCT 6.2.1) Correctly processes geometry with points on Curve, //! or point on Surface, or points on curve of surface [#0009745] - BinTools_FormatVersion_CURRENT = BinTools_FormatVersion_VERSION_3 //!< The current version. + BinTools_FormatVersion_CURRENT = BinTools_FormatVersion_VERSION_1 //!< The current version. }; #endif diff --git a/src/BinTools/BinTools_ShapeSet.cxx b/src/BinTools/BinTools_ShapeSet.cxx index 59303c7c78..2709dd2444 100644 --- a/src/BinTools/BinTools_ShapeSet.cxx +++ b/src/BinTools/BinTools_ShapeSet.cxx @@ -94,8 +94,9 @@ BinTools_ShapeSet::~BinTools_ShapeSet() //======================================================================= void BinTools_ShapeSet::SetFormatNb(const Standard_Integer theFormatNb) { - Standard_ASSERT_RETURN(theFormatNb >= BinTools_FormatVersion_VERSION_1 && - theFormatNb <= BinTools_FormatVersion_CURRENT, + Standard_ASSERT_RETURN(theFormatNb == BinTools_FormatVersion_VERSION_1 || + theFormatNb == BinTools_FormatVersion_VERSION_2 || + theFormatNb == BinTools_FormatVersion_VERSION_3, "Error: unsupported BinTools version.", ); myFormatNb = theFormatNb; @@ -500,10 +501,12 @@ void BinTools_ShapeSet::Read (Standard_IStream& IS, S.Free(aFree); S.Modified(aMod); - if (myFormatNb >= BinTools_FormatVersion_VERSION_2) - S.Checked(aChecked); - else - S.Checked (Standard_False); // force check at reading.. + if (myFormatNb != BinTools_FormatVersion_VERSION_2 + && myFormatNb != BinTools_FormatVersion_VERSION_3) + { + aChecked = false; // force check at reading + } + S.Checked (aChecked); S.Orientable(anOrient); S.Closed (aClosed); S.Infinite (anInf); @@ -703,17 +706,16 @@ void BinTools_ShapeSet::WriteGeometry (const TopoDS_Shape& S, BinTools::PutReal(OS, last); // Write UV Points for higher performance - if (myFormatNb >= BinTools_FormatVersion_VERSION_2) + if (myFormatNb == BinTools_FormatVersion_VERSION_2 + || myFormatNb == BinTools_FormatVersion_VERSION_3) { gp_Pnt2d Pf,Pl; if (CR->IsCurveOnClosedSurface()) { - Handle(BRep_CurveOnClosedSurface) COCS = - Handle(BRep_CurveOnClosedSurface)::DownCast(CR); + Handle(BRep_CurveOnClosedSurface) COCS = Handle(BRep_CurveOnClosedSurface)::DownCast(CR); COCS->UVPoints2(Pf,Pl); } else { - Handle(BRep_CurveOnSurface) COS = - Handle(BRep_CurveOnSurface)::DownCast(CR); + Handle(BRep_CurveOnSurface) COS = Handle(BRep_CurveOnSurface)::DownCast(CR); COS->UVPoints(Pf,Pl); } BinTools::PutReal(OS, Pf.X()); @@ -847,9 +849,8 @@ void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, BRep_ListOfPointRepresentation& lpr = TV->ChangePoints(); TopLoc_Location L; - Standard_Boolean aNewF = (myFormatNb >= BinTools_FormatVersion_VERSION_3); do { - if(aNewF) { + if(myFormatNb == BinTools_FormatVersion_VERSION_3) { val = (Standard_Integer)IS.get();//case {0|1|2|3} if (val > 0 && val <= 3) BinTools::GetReal(IS, p1); @@ -1011,7 +1012,8 @@ void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, BinTools::GetReal(IS, last); // read UV Points // for XML Persistence higher performance - if (myFormatNb >= BinTools_FormatVersion_VERSION_2) + if (myFormatNb == BinTools_FormatVersion_VERSION_2 + || myFormatNb == BinTools_FormatVersion_VERSION_3) { BinTools::GetReal(IS, PfX); BinTools::GetReal(IS, PfY); @@ -1027,17 +1029,22 @@ void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, break; if (closed) { - if (myFormatNb >= BinTools_FormatVersion_VERSION_2) + if (myFormatNb == BinTools_FormatVersion_VERSION_2 + || myFormatNb == BinTools_FormatVersion_VERSION_3) + { myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc), myCurves2d.Curve2d(pc2), mySurfaces.Surface(s), Locations().Location(l),tol, aPf, aPl); + } else + { myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc), myCurves2d.Curve2d(pc2), mySurfaces.Surface(s), Locations().Location(l),tol); + } myBuilder.Continuity(E, mySurfaces.Surface(s), @@ -1048,15 +1055,20 @@ void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, } else { - if (myFormatNb >= BinTools_FormatVersion_VERSION_2) + if (myFormatNb == BinTools_FormatVersion_VERSION_2 + || myFormatNb == BinTools_FormatVersion_VERSION_3) + { myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc), mySurfaces.Surface(s), Locations().Location(l),tol, aPf, aPl); + } else + { myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc), mySurfaces.Surface(s), Locations().Location(l),tol); + } } myBuilder.Range(E, mySurfaces.Surface(s), diff --git a/src/DBRep/DBRep.cxx b/src/DBRep/DBRep.cxx index 4355685412..973a762203 100644 --- a/src/DBRep/DBRep.cxx +++ b/src/DBRep/DBRep.cxx @@ -1458,7 +1458,7 @@ static Standard_Integer writebrep (Draw_Interpretor& theDI, Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI); if (isBinaryFormat) { - if (aVersion > BinTools_FormatVersion_CURRENT) + if (aVersion > BinTools_FormatVersion_VERSION_3) { theDI << "Syntax error: unknown format version"; return 1; @@ -1657,7 +1657,7 @@ void DBRep::BasicCommands(Draw_Interpretor& theCommands) "\n\t\t: -binary write into the binary format (ASCII when unspecified)" "\n\t\t: -version a number of format version to save;" "\n\t\t: ASCII versions: 1, 2 (1 for ASCII when unspecified);" - "\n\t\t: Binary versions: 1, 2 and 3 (3 for Binary when unspecified)." + "\n\t\t: Binary versions: 1, 2 and 3 (1 for Binary when unspecified)." "\n\t\t: -noTriangles skip triangulation data (OFF when unspecified).", __FILE__, writebrep, g); theCommands.Add("readbrep", diff --git a/src/TopTools/TopTools_FormatVersion.hxx b/src/TopTools/TopTools_FormatVersion.hxx index a852cfbbe0..2cc523e897 100644 --- a/src/TopTools/TopTools_FormatVersion.hxx +++ b/src/TopTools/TopTools_FormatVersion.hxx @@ -17,8 +17,11 @@ //! Defined TopTools format version enum TopTools_FormatVersion { - TopTools_FormatVersion_VERSION_1 = 1, //!< Does not write CurveOnSurface UV Points into the file. On reading calls Check() method. - TopTools_FormatVersion_VERSION_2 = 2, //!< Stores CurveOnSurface UV Points. On reading format is recognized from Version string. + TopTools_FormatVersion_VERSION_1 = 1, //!< Does not write CurveOnSurface UV Points into the file. + //! On reading calls Check() method. + //! This is default version. + TopTools_FormatVersion_VERSION_2 = 2, //!< Stores CurveOnSurface UV Points. + //! On reading format is recognized from Version string. TopTools_FormatVersion_CURRENT = TopTools_FormatVersion_VERSION_1 //!< The current version. }; diff --git a/src/TopTools/TopTools_ShapeSet.cxx b/src/TopTools/TopTools_ShapeSet.cxx index b3a4359439..417fd66785 100644 --- a/src/TopTools/TopTools_ShapeSet.cxx +++ b/src/TopTools/TopTools_ShapeSet.cxx @@ -42,7 +42,7 @@ Standard_CString TopTools_ShapeSet::Version_2 = "CASCADE Topology V2, (c) Matra- //purpose : //======================================================================= TopTools_ShapeSet::TopTools_ShapeSet() -: myFormatNb (TopTools_FormatVersion_VERSION_1) +: myFormatNb (TopTools_FormatVersion_CURRENT) { } @@ -700,10 +700,9 @@ void TopTools_ShapeSet::Read(Standard_IStream& IS, const Message_ProgressRange& S.Free (buffer[0] == '1'); S.Modified (buffer[1] == '1'); - if (myFormatNb >= TopTools_FormatVersion_VERSION_2) - S.Checked (buffer[2] == '1'); - else - S.Checked (Standard_False); // force check at reading.. + const bool isChecked = myFormatNb == TopTools_FormatVersion_VERSION_2 + && buffer[2] == '1'; + S.Checked (isChecked); S.Orientable(buffer[3] == '1'); S.Closed (buffer[4] == '1'); diff --git a/src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx b/src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx index a3c04f7eaf..21408ff537 100644 --- a/src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx +++ b/src/XmlMNaming/XmlMNaming_NamedShapeDriver.cxx @@ -370,7 +370,7 @@ void XmlMNaming_NamedShapeDriver::WriteShapeSection (XmlObjMgt_Element& theEleme // Add text to the "shapes" element if (myShapeSet.NbShapes() > 0) { - myShapeSet.SetFormatNb(TopTools_FormatVersion_VERSION_2); + myShapeSet.SetFormatNb(TopTools_FormatVersion_VERSION_1); LDOM_OSStream aStream (16 * 1024); // ostrstream aStream; // aStream.rdbuf() -> setbuf (0, 16380); diff --git a/tests/bugs/moddata_3/bug29723 b/tests/bugs/moddata_3/bug29723 new file mode 100644 index 0000000000..748949e70a --- /dev/null +++ b/tests/bugs/moddata_3/bug29723 @@ -0,0 +1,29 @@ +puts "==========" +puts "0029723: Modeling Data - Get rid of second writing format (additional save of UV points)" +puts "==========" +puts "" + +pload MODELING VISUALIZATION + +box testBox 10 20 30 +nurbsconvert nurbsBox testBox + +writebrep nurbsBox "${imagedir}/${casename}_topBox1.brep" -version 1 +readbrep "${imagedir}/${casename}_topBox1.brep" topBox1 +checkprops topBox1 -equal nurbsBox + +writebrep nurbsBox "${imagedir}/${casename}_topBox2.brep" -version 2 +readbrep "${imagedir}/${casename}_topBox2.brep" topBox2 +checkprops topBox2 -equal nurbsBox + +writebrep nurbsBox "${imagedir}/${casename}_topBox3.bbrep" -version 1 -binary on +readbrep "${imagedir}/${casename}_topBox3.bbrep" topBox3 +checkprops topBox3 -equal nurbsBox + +writebrep nurbsBox "${imagedir}/${casename}_topBox4.bbrep" -version 2 -binary on +readbrep "${imagedir}/${casename}_topBox4.bbrep" topBox4 +checkprops topBox4 -equal nurbsBox + +writebrep nurbsBox "${imagedir}/${casename}_topBox5.bbrep" -version 3 -binary on +readbrep "${imagedir}/${casename}_topBox5.bbrep" topBox5 +checkprops topBox5 -equal nurbsBox