BinTools_ShapeSet::AddGeometry() now writes NULL surface with 0 index.
myWithTriangles is ignored for TopoDS_Face with NULL surface so that
triangulation-only faces are not lost with defaults.
Added Draw Harness command StoreTriangulation defining
WithTriangulation flag for BinXCAF/BinOcaf storage drivers.
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
+#include <BinDrivers_DocumentStorageDriver.hxx>
#include <BinDrivers.hxx>
-#include <BinDrivers_DocumentStorageDriver.hxx>
#include <BinLDrivers_DocumentSection.hxx>
#include <BinMDF_ADriver.hxx>
#include <BinMDF_ADriverTable.hxx>
#include <BinMNaming_NamedShapeDriver.hxx>
#include <CDM_MessageDriver.hxx>
#include <Standard_ErrorHandler.hxx>
+#include <Standard_NotImplemented.hxx>
#include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx>
#include <TNaming_NamedShape.hxx>
return BinDrivers::AttributeDrivers (theMessageDriver);
}
+//=======================================================================
+//function : IsWithTriangles
+//purpose :
+//=======================================================================
+Standard_Boolean BinDrivers_DocumentStorageDriver::IsWithTriangles() const
+{
+ if (myDrivers.IsNull())
+ {
+ return Standard_False;
+ }
+
+ Handle(BinMDF_ADriver) aDriver;
+ myDrivers->GetDriver (STANDARD_TYPE(TNaming_NamedShape), aDriver);
+ Handle(BinMNaming_NamedShapeDriver) aShapesDriver = Handle(BinMNaming_NamedShapeDriver)::DownCast(aDriver);
+ return !aShapesDriver.IsNull()
+ && aShapesDriver->IsWithTriangles();
+}
+
+//=======================================================================
+//function : SetWithTriangles
+//purpose :
+//=======================================================================
+void BinDrivers_DocumentStorageDriver::SetWithTriangles (const Handle(CDM_MessageDriver)& theMessageDriver,
+ const Standard_Boolean theWithTriangulation)
+{
+ if (myDrivers.IsNull())
+ {
+ myDrivers = AttributeDrivers (theMessageDriver);
+ }
+ if (myDrivers.IsNull())
+ {
+ return;
+ }
+
+ Handle(BinMDF_ADriver) aDriver;
+ myDrivers->GetDriver (STANDARD_TYPE(TNaming_NamedShape), aDriver);
+ Handle(BinMNaming_NamedShapeDriver) aShapesDriver = Handle(BinMNaming_NamedShapeDriver)::DownCast(aDriver);
+ if (aShapesDriver.IsNull())
+ {
+ Standard_NotImplemented::Raise("Internal Error - TNaming_NamedShape is not found!");
+ }
+
+ aShapesDriver->SetWithTriangles (theWithTriangulation);
+}
+
//=======================================================================
//function : WriteShapeSection
//purpose : Implements WriteShapeSection
//! implements the procedure of writing a shape section to file
Standard_EXPORT virtual void WriteShapeSection (BinLDrivers_DocumentSection& theDocSection, Standard_OStream& theOS) Standard_OVERRIDE;
+ //! Return true if shape should be stored with triangles.
+ Standard_EXPORT Standard_Boolean IsWithTriangles() const;
-
+ //! Set if triangulation should be stored or not.
+ Standard_EXPORT void SetWithTriangles (const Handle(CDM_MessageDriver)& theMessageDriver,
+ const Standard_Boolean theWithTriangulation);
DEFINE_STANDARD_RTTIEXT(BinDrivers_DocumentStorageDriver,BinLDrivers_DocumentStorageDriver)
//! Clear myShapeSet
Standard_EXPORT void Clear();
-
+
+ //! Return true if shape should be stored with triangles.
+ Standard_Boolean IsWithTriangles() const { return myShapeSet.IsWithTriangles(); }
+
//! set whether to store triangulation
- void SetWithTriangles (const Standard_Boolean isWithTriangles);
+ void SetWithTriangles (const Standard_Boolean isWithTriangles);
//! set the format of topology
//! First : does not write CurveOnSurface UV Points into the file
BinTools_ShapeSet::~BinTools_ShapeSet()
{}
-//=======================================================================
-//function : SetWithTriangles
-//purpose :
-//=======================================================================
-void BinTools_ShapeSet::SetWithTriangles(const Standard_Boolean isWithTriangles)
-{
- myWithTriangles = isWithTriangles;
-}
-
//=======================================================================
//function : SetFormatNb
//purpose :
Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
- if (myWithTriangles) {
+ if (myWithTriangles
+ || TF->Surface().IsNull())
+ {
Handle(Poly_Triangulation) Tr = TF->Triangulation();
if (!Tr.IsNull()) myTriangulations.Add(Tr);
}
Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
const TopoDS_Face& F = TopoDS::Face(S);
-
- if (!(TF->Surface()).IsNull()) {
- Standard_Boolean aNatRes = (BRep_Tool::NaturalRestriction(F)) ? Standard_True : Standard_False;
- BinTools::PutBool(OS, aNatRes);
// Write the surface geometry
- BinTools::PutReal(OS, TF->Tolerance());
- BinTools::PutInteger(OS, mySurfaces.Index(TF->Surface()));
- BinTools::PutInteger(OS, Locations().Index(TF->Location()));
- }
- if (myWithTriangles) {
+ Standard_Boolean aNatRes = (BRep_Tool::NaturalRestriction(F)) ? Standard_True : Standard_False;
+ BinTools::PutBool (OS, aNatRes);
+ BinTools::PutReal (OS, TF->Tolerance());
+ BinTools::PutInteger (OS, !TF->Surface().IsNull()
+ ? mySurfaces.Index (TF->Surface())
+ : 0);
+ BinTools::PutInteger (OS, Locations().Index (TF->Location()));
+
+ if (myWithTriangles
+ || TF->Surface().IsNull())
+ {
if (!(TF->Triangulation()).IsNull()) {
OS << (Standard_Byte) 2;
// Write the triangulation
BinTools::GetReal(IS, tol);
BinTools::GetInteger(IS, s); //surface indx
BinTools::GetInteger(IS, l); //location indx
- if (!mySurfaces.Surface(s).IsNull()) {
- myBuilder.UpdateFace(TopoDS::Face(S),
- mySurfaces.Surface(s),
- Locations().Location(l),tol);
- myBuilder.NaturalRestriction(TopoDS::Face(S),bval );
- }
+ myBuilder.UpdateFace (F,
+ s > 0 ? mySurfaces.Surface(s) : Handle(Geom_Surface)(),
+ Locations().Location(l),
+ tol);
+ myBuilder.NaturalRestriction (F, bval);
Standard_Byte aByte = (Standard_Byte)IS.get();
// cas triangulation
Standard_EXPORT BinTools_ShapeSet(const Standard_Boolean isWithTriangles = Standard_False);
Standard_EXPORT virtual ~BinTools_ShapeSet();
-
- //! Define if shape will be stored with triangles
- Standard_EXPORT void SetWithTriangles (const Standard_Boolean isWithTriangles);
-
+
+ //! Return true if shape should be stored with triangles.
+ Standard_Boolean IsWithTriangles() const { return myWithTriangles; }
+
+ //! Define if shape will be stored with triangles.
+ //! Ignored (always written) if face defines only triangulation (no surface).
+ void SetWithTriangles (const Standard_Boolean isWithTriangles) { myWithTriangles = isWithTriangles; }
+
Standard_EXPORT void SetFormatNb (const Standard_Integer theFormatNb);
//! two formats available for the moment:
#include <DDocStd.hxx>
+#include <BinDrivers_DocumentStorageDriver.hxx>
#include <DDF.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
return 1;
}
+//=======================================================================
+//function : DDocStd_StoreTriangulation
+//purpose :
+//=======================================================================
+
+static Standard_Integer DDocStd_StoreTriangulation (Draw_Interpretor& theDi,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
+{
+ const Handle(TDocStd_Application)& anApp = DDocStd::GetApplication();
+ Handle(BinDrivers_DocumentStorageDriver) aDriverXCaf = Handle(BinDrivers_DocumentStorageDriver)::DownCast(anApp->WriterFromFormat ("BinXCAF"));
+ Handle(BinDrivers_DocumentStorageDriver) aDriverOcaf = Handle(BinDrivers_DocumentStorageDriver)::DownCast(anApp->WriterFromFormat ("BinOcaf"));
+ if (aDriverXCaf.IsNull()
+ || aDriverOcaf.IsNull())
+ {
+ std::cout << "Error: BinXCAF or BinOcaf storage formats are not registered\n";
+ return 1;
+ }
+
+ if (theNbArgs == 1)
+ {
+ theDi << (aDriverXCaf->IsWithTriangles() ? "1" : "0");
+ return 0;
+ }
+ else if (theNbArgs != 2)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ const Standard_Boolean toEnable = (Draw::Atoi (theArgVec[1]) != 0);
+ aDriverXCaf->SetWithTriangles (anApp->MessageDriver(), toEnable);
+ aDriverOcaf->SetWithTriangles (anApp->MessageDriver(), toEnable);
+ return 0;
+}
+
//=======================================================================
//function : DocumentCommands
//purpose :
"DumpDocument (DOC)",
__FILE__, DDocStd_DumpDocument, g);
+ theCommands.Add ("StoreTriangulation",
+ "StoreTriangulation [toStore={0|1}]"
+ "\nSetup BinXCAF/BinOcaf storage drivers to write triangulation",
+ __FILE__, DDocStd_StoreTriangulation, g);
+
// XREF
theCommands.Add("Copy","Copy DOC entry XDOC xentry",
--- /dev/null
+puts "========"
+puts "OCC27835"
+puts "BinXCAF - handle correctly faces with NULL surface within BinTools_ShapeSet"
+puts "========"
+puts ""
+
+set anImgDoc1 $imagedir/${casename}_doc1.png
+set anImgDoc2 $imagedir/${casename}_doc2.png
+set anImgDiff $imagedir/${casename}_diff.png
+
+pload XDE OCAF MODELING VISUALIZATION
+
+restore [locate_data_file bug27821_nullsurf.brep] s
+explode s F
+
+NewDocument D BinXCAF
+XAddShape D s
+XSetColor D s_1 1 0 0
+XShow D
+vaxo
+vfit
+vrotate 3 0 0
+vsetdispmode 1
+vdump $anImgDoc1
+
+StoreTriangulation 1
+SaveAs D test.xbf
+Close D
+
+XOpen test.xbf D
+XShow D
+vsetdispmode 1
+vaxo
+vfit
+vrotate 3 0 0
+vdump $anImgDoc2
+
+set aDiffRes [diffimage $anImgDoc2 $anImgDoc1 0.0 0 0 $anImgDiff]
+if {$aDiffRes != 0} {
+ puts "Error: document has changed after Save/Read"
+}