0032490: Data Exchange - provide OSD_FileSystem::OpenOStream() for output streams IR-2021-08-06 WEEK-31
authormkrylova <mkrylova@opencascade.com>
Mon, 26 Jul 2021 08:09:57 +0000 (11:09 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 4 Aug 2021 17:13:20 +0000 (20:13 +0300)
- provided OSD_FileSystem::OpenOStream() for output streams
- replaced OSD_OpenStream() usage with OSD_FileSystem::DefaultFileSystem()

22 files changed:
src/BRepTools/BRepTools.cxx
src/BinLDrivers/BinLDrivers_DocumentStorageDriver.cxx
src/BinTools/BinTools.cxx
src/DDocStd/DDocStd_ApplicationCommands.cxx
src/Draw/Draw_VariableCommands.cxx
src/IGESControl/IGESControl_Writer.cxx
src/IGESSelect/IGESSelect_WorkLibrary.cxx
src/Image/Image_Texture.cxx
src/OSD/OSD_CachedFileSystem.cxx
src/OSD/OSD_CachedFileSystem.hxx
src/OSD/OSD_FileSystem.cxx
src/OSD/OSD_FileSystem.hxx
src/OSD/OSD_FileSystemSelector.cxx
src/OSD/OSD_FileSystemSelector.hxx
src/OSD/OSD_LocalFileSystem.cxx
src/OSD/OSD_LocalFileSystem.hxx
src/RWGltf/RWGltf_CafWriter.cxx
src/StepSelect/StepSelect_WorkLibrary.cxx
src/TObjDRAW/TObjDRAW.cxx
src/ViewerTest/ViewerTest_OpenGlCommands.cxx
src/VrmlAPI/VrmlAPI_Writer.cxx
src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx

index 156ca3f..8f0c3b3 100644 (file)
@@ -38,7 +38,6 @@
 #include <gp_Vec2d.hxx>
 #include <Message.hxx>
 #include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
 #include <Poly_PolygonOnTriangulation.hxx>
 #include <Poly_Triangulation.hxx>
 #include <Precision.hxx>
@@ -707,12 +706,14 @@ Standard_Boolean  BRepTools::Write (const TopoDS_Shape& theShape,
                                     const TopTools_FormatVersion theVersion,
                                     const Message_ProgressRange& theProgress)
 {
-  std::ofstream os;
-  OSD_OpenStream(os, theFile, std::ios::out);
-  if (!os.is_open() || !os.good())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (theFile, std::ios::out);
+  if (aStream.get() == NULL || !aStream->good())
+  {
     return Standard_False;
+  }
 
-  Standard_Boolean isGood = (os.good() && !os.eof());
+  Standard_Boolean isGood = (aStream->good() && !aStream->eof());
   if(!isGood)
     return isGood;
 
@@ -720,19 +721,19 @@ Standard_Boolean  BRepTools::Write (const TopoDS_Shape& theShape,
   SS.SetFormatNb (theVersion);
   SS.Add (theShape);
 
-  os << "DBRep_DrawableShape\n";  // for easy Draw read
-  SS.Write(os, theProgress);
-  isGood = os.good();
+  *aStream << "DBRep_DrawableShape\n";  // for easy Draw read
+  SS.Write (*aStream, theProgress);
+  isGood = aStream->good();
   if (isGood)
   {
-    SS.Write (theShape, os);
+    SS.Write (theShape, *aStream);
   }
-  os.flush();
-  isGood = os.good();
+  aStream->flush();
+  isGood = aStream->good();
 
   errno = 0;
-  os.close();
-  isGood = os.good() && isGood && !errno;
+  isGood = aStream->good() && isGood && !errno;
+  aStream.reset();
 
   return isGood;
 }
index 39ad9b0..2dd4bac 100644 (file)
@@ -27,7 +27,7 @@
 #include <Message_Messenger.hxx>
 #include <FSD_BinaryFile.hxx>
 #include <FSD_FileHeader.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <PCDM_ReadWriter.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Type.hxx>
@@ -74,12 +74,12 @@ void BinLDrivers_DocumentStorageDriver::Write
 
   myFileName = theFileName;
 
-  std::ofstream aFileStream;
-  OSD_OpenStream (aFileStream, theFileName, std::ios::out | std::ios::binary);
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aFileStream = aFileSystem->OpenOStream (theFileName, std::ios::out | std::ios::binary);
 
-  if (aFileStream.is_open() && aFileStream.good())
+  if (aFileStream.get() != NULL && aFileStream->good())
   {
-    Write(theDocument, aFileStream, theRange);
+    Write (theDocument, *aFileStream, theRange);
   }
   else
   {
index 9bffcea..686a0c6 100644 (file)
@@ -18,7 +18,6 @@
 #include <BinTools_ShapeSet.hxx>
 #include <FSD_FileHeader.hxx>
 #include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
 #include <Storage_StreamTypeMismatchError.hxx>
 
 //=======================================================================
@@ -215,15 +214,15 @@ Standard_Boolean BinTools::Write (const TopoDS_Shape& theShape,
                                   const BinTools_FormatVersion theVersion,
                                   const Message_ProgressRange& theRange)
 {
-  std::ofstream aStream;
-  aStream.precision (15);
-  OSD_OpenStream (aStream, theFile, std::ios::out | std::ios::binary);
-  if (!aStream.good())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (theFile, std::ios::out | std::ios::binary);
+  aStream->precision (15);
+  if (aStream.get() == NULL || !aStream->good())
     return Standard_False;
 
-  Write (theShape, aStream, theWithTriangles, theWithNormals, theVersion, theRange);
-  aStream.close();
-  return aStream.good();
+  Write (theShape, *aStream, theWithTriangles, theWithNormals, theVersion, theRange);
+  aStream->flush();
+  return aStream->good();
 }
 
 //=======================================================================
index a035d99..f0c16d3 100644 (file)
@@ -35,7 +35,6 @@
 
 #include <OSD_FileSystem.hxx>
 #include <OSD_Path.hxx>
-#include <OSD_OpenFile.hxx>
 #include <TDocStd_PathParser.hxx>
 #include <XmlLDrivers.hxx>
 
@@ -298,9 +297,9 @@ static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
     Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1);
     if (anUseStream)
     {
-      std::ofstream aFileStream;
-      OSD_OpenStream (aFileStream, path, std::ios::out | std::ios::binary);
-      theStatus = A->SaveAs (D, aFileStream, aProgress->Start());
+      const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+      opencascade::std::shared_ptr<std::ostream> aFileStream = aFileSystem->OpenOStream (path, std::ios::out | std::ios::binary);
+      theStatus = A->SaveAs (D, *aFileStream, aProgress->Start());
     }
     else
     {
index bb502d7..7368c92 100644 (file)
@@ -91,10 +91,10 @@ static Standard_Integer save (Draw_Interpretor& theDI,
   }
 
   const char* aName = theArgVec[2];
-  std::ofstream aStream;
-  aStream.precision (15);
-  OSD_OpenStream (aStream, aName, std::ios::out);
-  if (!aStream.is_open() || !aStream.good())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (aName, std::ios::out);
+  aStream->precision (15);
+  if (aStream.get() == NULL || !aStream->good())
   {
     theDI << "Error: cannot open file for writing " << aName;
     return 1;
@@ -104,21 +104,21 @@ static Standard_Integer save (Draw_Interpretor& theDI,
   {
     Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
     Standard_CString aToolTypeName = aDrawable->DynamicType()->Name();
-    aStream << aToolTypeName << "\n";
+    *aStream << aToolTypeName << "\n";
     Draw::SetProgressBar (aProgress);
-    aDrawable->Save (aStream);
+    aDrawable->Save (*aStream);
   }
   catch (const Standard_NotImplemented& )
   {
     theDI << "Error: no method for saving " << theArgVec[1];
     return 1;
   }
-  aStream << "\n";
-  aStream << "0\n\n";
+  *aStream << "\n";
+  *aStream << "0\n\n";
   Draw::SetProgressBar (Handle(Draw_ProgressIndicator)());
 
   errno = 0;
-  const Standard_Boolean aRes = aStream.good() && !errno;
+  const Standard_Boolean aRes = aStream->good() && !errno;
   if (!aRes)
   {
     theDI << "Error: file has not been written";
index 3d4913a..565c1c2 100644 (file)
@@ -38,7 +38,7 @@
 #include <Interface_Macros.hxx>
 #include <Interface_Static.hxx>
 #include <Message_ProgressScope.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <ShapeAnalysis_ShapeTolerance.hxx>
 #include <Standard_Stream.hxx>
 #include <Standard_Transient.hxx>
@@ -253,17 +253,21 @@ Standard_Boolean IGESControl_Writer::Write
 Standard_Boolean IGESControl_Writer::Write
   (const Standard_CString file, const Standard_Boolean fnes)
 {
-  std::ofstream fout;
-  OSD_OpenStream(fout,file,std::ios::out);
-  if (!fout) return Standard_False;
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (file, std::ios::out);
+  if (aStream.get() == NULL)
+  {
+    return Standard_False;
+  }
 #ifdef OCCT_DEBUG
   std::cout<<" Ecriture fichier ("<< (fnes ? "fnes" : "IGES") <<"): "<<file<<std::endl;
 #endif
-  Standard_Boolean res = Write (fout,fnes);
+  Standard_Boolean res = Write (*aStream,fnes);
 
   errno = 0;
-  fout.close();
-  res = fout.good() && res && !errno;
+  aStream->flush();
+  res = aStream->good() && res && !errno;
+  aStream.reset();
 
   return res;
 }
index a2952aa..ddb4305 100644 (file)
@@ -36,7 +36,7 @@
 #include <Interface_ReportEntity.hxx>
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Stream.hxx>
 #include <Standard_Transient.hxx>
@@ -101,9 +101,10 @@ static  Handle(IGESData_FileProtocol) IGESProto;
   DeclareAndCast(IGESData_Protocol,prot,ctx.Protocol());
 
   if (igesmod.IsNull() || prot.IsNull()) return Standard_False;
-  std::ofstream fout;
-  OSD_OpenStream(fout,ctx.FileName(),std::ios::out );
-  if (!fout) {
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (ctx.FileName(), std::ios::out);
+  if (aStream.get() == NULL)
+  {
     ctx.CCheck(0)->AddFail("IGES File could not be created");
     sout<<" - IGES File could not be created : " << ctx.FileName() << std::endl; return 0;
   }
@@ -128,11 +129,12 @@ static  Handle(IGESData_FileProtocol) IGESProto;
   VW.SendModel(prot);            
   sout<<" Write ";
   if (themodefnes) VW.WriteMode() = 10;
-  Standard_Boolean status = VW.Print(fout);                sout<<" Done"<<std::endl;
+  Standard_Boolean status = VW.Print (*aStream);                sout<<" Done"<<std::endl;
 
   errno = 0;
-  fout.close();
-  status = fout.good() && status && !errno;
+  aStream->flush();
+  status = aStream->good() && status && !errno;
+  aStream.reset();
   if(errno)
     sout << strerror(errno) << std::endl;
 
index df635ce..9892b63 100644 (file)
@@ -20,7 +20,6 @@
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
 #include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(Image_Texture, Standard_Transient)
 
@@ -316,25 +315,26 @@ TCollection_AsciiString Image_Texture::ProbeImageFileFormat() const
 // ================================================================
 Standard_Boolean Image_Texture::WriteImage (const TCollection_AsciiString& theFile)
 {
-  std::ofstream aFileOut;
-  OSD_OpenStream (aFileOut, theFile.ToCString(), std::ios::out | std::ios::binary | std::ios::trunc);
-  if (!aFileOut)
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aFileOut = aFileSystem->OpenOStream (theFile, std::ios::out | std::ios::binary | std::ios::trunc);
+  if (aFileOut.get() == NULL)
   {
     Message::SendFail (TCollection_AsciiString ("Error: Unable to create file '") + theFile + "'");
     return false;
   }
 
-  if (!WriteImage (aFileOut, theFile))
+  if (!WriteImage (*aFileOut, theFile))
   {
     return false;
   }
 
-  aFileOut.close();
-  if (!aFileOut.good())
+  aFileOut->flush();
+  if (!aFileOut->good())
   {
     Message::SendFail (TCollection_AsciiString ("Error: Unable to write file '") + theFile + "'");
     return false;
   }
+  aFileOut.reset();
   return true;
 }
 
index 2002bc3..e7c119a 100644 (file)
@@ -34,6 +34,15 @@ Standard_Boolean OSD_CachedFileSystem::IsOpenIStream (const opencascade::std::sh
   return OSD_FileSystem::DefaultFileSystem()->IsOpenIStream (theStream);
 }
 
+//=======================================================================
+// function : IsOpenOStream
+// purpose :
+//=======================================================================
+Standard_Boolean OSD_CachedFileSystem::IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const
+{
+  return OSD_FileSystem::DefaultFileSystem()->IsOpenOStream (theStream);
+}
+
 //=======================================================================
 // function : OpenIStream
 // purpose :
@@ -52,6 +61,16 @@ opencascade::std::shared_ptr<std::istream> OSD_CachedFileSystem::OpenIStream (co
   return myStream.Stream;
 }
 
+//=======================================================================
+// function : OpenOStream
+// purpose :
+//=======================================================================
+opencascade::std::shared_ptr<std::ostream> OSD_CachedFileSystem::OpenOStream (const TCollection_AsciiString& theUrl,
+                                                                              const std::ios_base::openmode theMode)
+{
+  return OSD_FileSystem::DefaultFileSystem()->OpenOStream (theUrl, theMode);
+}
+
 //=======================================================================
 // function : OpenStreamBuffer
 // purpose :
@@ -61,6 +80,10 @@ opencascade::std::shared_ptr<std::streambuf> OSD_CachedFileSystem::OpenStreamBuf
                                                                                      const int64_t theOffset,
                                                                                      int64_t* theOutBufSize)
 {
+  if ((theMode & std::ios::out) == std::ios::out)
+  {
+    return OSD_FileSystem::DefaultFileSystem()->OpenStreamBuffer (theUrl, theMode, theOffset, theOutBufSize);
+  }
   if (myStream.Url != theUrl)
   {
     myStream.Url = theUrl;
index 37f4153..b7389ec 100644 (file)
@@ -34,6 +34,9 @@ public:
   //! Returns TRUE if current input stream is opened for reading operations.
   Standard_EXPORT virtual Standard_Boolean IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const Standard_OVERRIDE;
 
+  //! Returns TRUE if current output stream is opened for writing operations.
+  Standard_EXPORT virtual Standard_Boolean IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const Standard_OVERRIDE;
+
   //! Opens stream for specified file URL for reading operations or returns previously created stream pointing to the same URL.
   Standard_EXPORT virtual opencascade::std::shared_ptr<std::istream> OpenIStream
                           (const TCollection_AsciiString& theUrl,
@@ -41,6 +44,10 @@ public:
                            const int64_t theOffset,
                            const opencascade::std::shared_ptr<std::istream>& theOldStream) Standard_OVERRIDE;
 
+  //! Opens stream for specified file URL for writing operations (std::ostream) by calling parent's method.
+  Standard_EXPORT virtual opencascade::std::shared_ptr<std::ostream> OpenOStream (const TCollection_AsciiString& theUrl,
+                                                                                  const std::ios_base::openmode theMode) Standard_OVERRIDE;
+
   //! Opens stream buffer for specified file URL.
   Standard_EXPORT virtual opencascade::std::shared_ptr<std::streambuf> OpenStreamBuffer
                           (const TCollection_AsciiString& theUrl,
index a0e4f62..81fc4c2 100644 (file)
@@ -98,3 +98,21 @@ opencascade::std::shared_ptr<std::istream> OSD_FileSystem::OpenIStream (const TC
   }
   return aNewStream;
 }
+
+//=======================================================================
+// function : OpenOStream
+// purpose :
+//=======================================================================
+opencascade::std::shared_ptr<std::ostream> OSD_FileSystem::OpenOStream (const TCollection_AsciiString& theUrl,
+                                                                        const std::ios_base::openmode theMode)
+{
+  opencascade::std::shared_ptr<std::ostream> aNewStream;
+  opencascade::std::shared_ptr<std::streambuf> aFileBuf = OpenStreamBuffer (theUrl, theMode | std::ios_base::out);
+  if (aFileBuf.get() == NULL)
+  {
+    return opencascade::std::shared_ptr<std::ostream>();
+  }
+
+  aNewStream.reset(new OSD_OStreamBuffer (theUrl.ToCString(), aFileBuf));
+  return aNewStream;
+}
index 744fe8f..19334f9 100644 (file)
@@ -35,6 +35,9 @@ public:
   //! Returns TRUE if current input stream is opened for reading operations.
   virtual Standard_Boolean IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const = 0;
 
+  //! Returns TRUE if current output stream is opened for writing operations.
+  virtual Standard_Boolean IsOpenOStream(const opencascade::std::shared_ptr<std::ostream>& theStream) const = 0;
+
   //! Opens stream for specified file URL for reading operations (std::istream).
   //! Default implementation create a stream from file buffer returned by OSD_FileSystem::OpenFileBuffer().
   //! @param theUrl       [in] path to open
@@ -49,6 +52,14 @@ public:
                            const int64_t theOffset = 0,
                            const opencascade::std::shared_ptr<std::istream>& theOldStream = opencascade::std::shared_ptr<std::istream>());
 
+  //! Opens stream for specified file URL for writing operations (std::ostream).
+  //! Default implementation create a stream from file buffer returned by OSD_FileSystem::OpenFileBuffer().
+  //! @param theUrl       [in] path to open
+  //! @param theMode      [in] flags describing the requested output mode for the stream (std::ios_base::out will be implicitly added)
+  //! @return pointer to newly created opened stream or NULL in case of failure.
+  Standard_EXPORT virtual opencascade::std::shared_ptr<std::ostream> OpenOStream (const TCollection_AsciiString& theUrl,
+                                                                                  const std::ios_base::openmode theMode);
+
   //! Opens stream buffer for specified file URL.
   //! @param theUrl        [in]  path to open
   //! @param theMode       [in]  flags describing the requested input mode for the stream
index 18cff9c..0733ecb 100644 (file)
@@ -82,6 +82,31 @@ Standard_Boolean OSD_FileSystemSelector::IsOpenIStream (const opencascade::std::
   return false;
 }
 
+//=======================================================================
+// function : IsOpenOStream
+// purpose :
+//=======================================================================
+Standard_Boolean OSD_FileSystemSelector::IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const
+{
+  opencascade::std::shared_ptr<OSD_OStreamBuffer> aFileStream = opencascade::std::dynamic_pointer_cast<OSD_OStreamBuffer> (theStream);
+  if (aFileStream.get() == NULL)
+  {
+    return false;
+  }
+  for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter (myProtocols); aProtIter.More(); aProtIter.Next())
+  {
+    const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
+    if (aFileSystem->IsSupportedPath (TCollection_AsciiString (aFileStream->Url().c_str())))
+    {
+      if (aFileSystem->IsOpenOStream (theStream))
+      {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
 //=======================================================================
 // function : OpenIStream
 // purpose :
@@ -106,6 +131,27 @@ opencascade::std::shared_ptr<std::istream> OSD_FileSystemSelector::OpenIStream (
   return opencascade::std::shared_ptr<std::istream>();
 }
 
+//=======================================================================
+// function : OpenOStream
+// purpose :
+//=======================================================================
+opencascade::std::shared_ptr<std::ostream> OSD_FileSystemSelector::OpenOStream (const TCollection_AsciiString& theUrl,
+                                                                                const std::ios_base::openmode theMode)
+{
+  for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter (myProtocols); aProtIter.More(); aProtIter.Next())
+  {
+    const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
+    if (aFileSystem->IsSupportedPath (theUrl))
+    {
+      opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (theUrl, theMode);
+      if (aStream.get() != NULL)
+      {
+        return aStream;
+      }
+    }
+  }
+  return opencascade::std::shared_ptr<std::ostream>();
+}
 
 //=======================================================================
 // function : OpenStreamBuffer
index 79d3adc..60aa5e1 100644 (file)
@@ -43,6 +43,9 @@ public:
   //! Returns TRUE if current input stream is opened for reading operations.
   Standard_EXPORT virtual Standard_Boolean IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const Standard_OVERRIDE;
 
+  //! Returns TRUE if current output stream is opened for writing operations.
+  Standard_EXPORT virtual Standard_Boolean IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const Standard_OVERRIDE;
+
   //! Opens input stream using one of registered protocols.
   Standard_EXPORT virtual opencascade::std::shared_ptr<std::istream> OpenIStream
                           (const TCollection_AsciiString& theUrl,
@@ -50,6 +53,10 @@ public:
                            const int64_t theOffset = 0,
                            const opencascade::std::shared_ptr<std::istream>& theOldStream = opencascade::std::shared_ptr<std::istream>()) Standard_OVERRIDE;
 
+  //! Opens output stream using one of registered protocols.
+  Standard_EXPORT virtual opencascade::std::shared_ptr<std::ostream> OpenOStream (const TCollection_AsciiString& theUrl,
+                                                                                  const std::ios_base::openmode theMode) Standard_OVERRIDE;
+
   //! Opens stream buffer using one of registered protocols.
   Standard_EXPORT virtual opencascade::std::shared_ptr<std::streambuf> OpenStreamBuffer
                           (const TCollection_AsciiString& theUrl,
index b13a466..2666bc1 100644 (file)
@@ -42,6 +42,21 @@ Standard_Boolean OSD_LocalFileSystem::IsOpenIStream (const opencascade::std::sha
   return (aFileBuf != NULL) ? aFileBuf->is_open() : false;
 }
 
+//=======================================================================
+// function : IsOpenOStream
+// purpose :
+//=======================================================================
+Standard_Boolean OSD_LocalFileSystem::IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const
+{
+  opencascade::std::shared_ptr<OSD_OStreamBuffer> aFileStream = opencascade::std::dynamic_pointer_cast<OSD_OStreamBuffer> (theStream);
+  if (aFileStream.get() == NULL)
+  {
+    return false;
+  }
+  const std::filebuf* aFileBuf = dynamic_cast<const std::filebuf*> (aFileStream->rdbuf());
+  return (aFileBuf != NULL) ? aFileBuf->is_open() : false;
+}
+
 //=======================================================================
 // function : OpenStreamBuffer
 // purpose :
index 789461c..fbe2db9 100644 (file)
@@ -31,6 +31,9 @@ public:
   //! Returns TRUE if current input stream is opened for reading operations.
   Standard_EXPORT virtual Standard_Boolean IsOpenIStream (const opencascade::std::shared_ptr<std::istream>& theStream) const Standard_OVERRIDE;
 
+  //! Returns TRUE if current output stream is opened for writing operations.
+  Standard_EXPORT virtual Standard_Boolean IsOpenOStream (const opencascade::std::shared_ptr<std::ostream>& theStream) const Standard_OVERRIDE;
+
   //! Opens stream buffer for specified file URL.
   Standard_EXPORT virtual opencascade::std::shared_ptr<std::streambuf> OpenStreamBuffer
                           (const TCollection_AsciiString& theUrl,
index bf4e8d7..3888e72 100644 (file)
@@ -19,7 +19,6 @@
 #include <Message_ProgressScope.hxx>
 #include <NCollection_DataMap.hxx>
 #include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
 #include <OSD_File.hxx>
 #include <OSD_Path.hxx>
 #include <Poly_Triangulation.hxx>
@@ -359,10 +358,10 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
   myBinDataMap.Clear();
   myBinDataLen64 = 0;
 
-  std::ofstream aBinFile;
-  OSD_OpenStream (aBinFile, myBinFileNameFull.ToCString(), std::ios::out | std::ios::binary);
-  if (!aBinFile.is_open()
-   || !aBinFile.good())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aBinFile = aFileSystem->OpenOStream (myBinFileNameFull, std::ios::out | std::ios::binary);
+  if (aBinFile.get() == NULL
+   || !aBinFile->good())
   {
     Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' can not be created");
     return false;
@@ -373,7 +372,7 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
   Standard_Integer aNbAccessors = 0;
 
   // write positions
-  myBuffViewPos.ByteOffset = aBinFile.tellp();
+  myBuffViewPos.ByteOffset = aBinFile->tellp();
   for (XCAFPrs_DocumentExplorer aDocExplorer (theDocument, theRootLabels, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
        aDocExplorer.More() && aPSentryBin.More(); aDocExplorer.Next())
   {
@@ -394,9 +393,9 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
       }
 
       RWGltf_GltfFace aGltfFace;
-      saveNodes (aGltfFace, aBinFile, aFaceIter, aNbAccessors);
+      saveNodes (aGltfFace, *aBinFile, aFaceIter, aNbAccessors);
 
-      if (!aBinFile.good())
+      if (!aBinFile->good())
       {
         Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' can not be written");
         return false;
@@ -405,7 +404,7 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
       myBinDataMap.Bind (aFaceIter.Face(), aGltfFace);
     }
   }
-  myBuffViewPos.ByteLength = (int64_t )aBinFile.tellp() - myBuffViewPos.ByteOffset;
+  myBuffViewPos.ByteLength = (int64_t )aBinFile->tellp() - myBuffViewPos.ByteOffset;
   if (!aPSentryBin.More())
   {
     return false;
@@ -413,7 +412,7 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
   aPSentryBin.Next();
 
   // write normals
-  myBuffViewNorm.ByteOffset = aBinFile.tellp();
+  myBuffViewNorm.ByteOffset = aBinFile->tellp();
   for (XCAFPrs_DocumentExplorer aDocExplorer (theDocument, theRootLabels, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
        aDocExplorer.More() && aPSentryBin.More(); aDocExplorer.Next())
   {
@@ -436,16 +435,16 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
         continue;
       }
 
-      saveNormals (aGltfFace, aBinFile, aFaceIter, aNbAccessors);
+      saveNormals (aGltfFace, *aBinFile, aFaceIter, aNbAccessors);
 
-      if (!aBinFile.good())
+      if (!aBinFile->good())
       {
         Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' can not be written");
         return false;
       }
     }
   }
-  myBuffViewNorm.ByteLength = (int64_t )aBinFile.tellp() - myBuffViewNorm.ByteOffset;
+  myBuffViewNorm.ByteLength = (int64_t )aBinFile->tellp() - myBuffViewNorm.ByteOffset;
   if (!aPSentryBin.More())
   {
     return false;
@@ -453,7 +452,7 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
   aPSentryBin.Next();
 
   // write texture coordinates
-  myBuffViewTextCoord.ByteOffset = aBinFile.tellp();
+  myBuffViewTextCoord.ByteOffset = aBinFile->tellp();
   for (XCAFPrs_DocumentExplorer aDocExplorer (theDocument, theRootLabels, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
        aDocExplorer.More() && aPSentryBin.More(); aDocExplorer.Next())
   {
@@ -477,16 +476,16 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
         continue;
       }
 
-      saveTextCoords (aGltfFace, aBinFile, aFaceIter, aNbAccessors);
+      saveTextCoords (aGltfFace, *aBinFile, aFaceIter, aNbAccessors);
 
-      if (!aBinFile.good())
+      if (!aBinFile->good())
       {
         Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' can not be written");
         return false;
       }
     }
   }
-  myBuffViewTextCoord.ByteLength = (int64_t )aBinFile.tellp() - myBuffViewTextCoord.ByteOffset;
+  myBuffViewTextCoord.ByteLength = (int64_t )aBinFile->tellp() - myBuffViewTextCoord.ByteOffset;
   if (!aPSentryBin.More())
   {
     return false;
@@ -494,7 +493,7 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
   aPSentryBin.Next();
 
   // write indices
-  myBuffViewInd.ByteOffset = aBinFile.tellp();
+  myBuffViewInd.ByteOffset = aBinFile->tellp();
   for (XCAFPrs_DocumentExplorer aDocExplorer (theDocument, theRootLabels, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
        aDocExplorer.More() && aPSentryBin.More(); aDocExplorer.Next())
   {
@@ -518,16 +517,16 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
         continue;
       }
 
-      saveIndices (aGltfFace, aBinFile, aFaceIter, aNbAccessors);
+      saveIndices (aGltfFace, *aBinFile, aFaceIter, aNbAccessors);
 
-      if (!aBinFile.good())
+      if (!aBinFile->good())
       {
         Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' can not be written");
         return false;
       }
     }
   }
-  myBuffViewInd.ByteLength = (int64_t )aBinFile.tellp() - myBuffViewInd.ByteOffset;
+  myBuffViewInd.ByteLength = (int64_t )aBinFile->tellp() - myBuffViewInd.ByteOffset;
 
   if (myIsBinary
    && myToEmbedTexturesInGlb)
@@ -551,7 +550,7 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
           continue;
         }
 
-        myMaterialMap->AddGlbImages (aBinFile, aFaceIter.FaceStyle());
+        myMaterialMap->AddGlbImages (*aBinFile, aFaceIter.FaceStyle());
       }
     }
   }
@@ -575,13 +574,14 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
   }
   // myMaterialMap->FlushGlbBufferViews() will put image bufferView's IDs at the end of list
 
-  myBinDataLen64 = aBinFile.tellp();
-  aBinFile.close();
-  if (!aBinFile.good())
+  myBinDataLen64 = aBinFile->tellp();
+  aBinFile->flush();
+  if (!aBinFile->good())
   {
     Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' can not be written");
     return false;
   }
+  aBinFile.reset();
   return true;
 }
 
@@ -605,10 +605,10 @@ bool RWGltf_CafWriter::writeJson (const Handle(TDocStd_Document)&  theDocument,
   const Standard_Integer aDefSceneId      = 0;
 
   const TCollection_AsciiString aFileNameGltf = myFile;
-  std::ofstream aGltfContentFile;
-  OSD_OpenStream (aGltfContentFile, aFileNameGltf.ToCString(), std::ios::out | std::ios::binary);
-  if (!aGltfContentFile.is_open()
-   || !aGltfContentFile.good())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aGltfContentFile = aFileSystem->OpenOStream (aFileNameGltf, std::ios::out | std::ios::binary);
+  if (aGltfContentFile.get() == NULL
+   || !aGltfContentFile->good())
   {
     Message::SendFail (TCollection_AsciiString ("File '") + aFileNameGltf + "' can not be created");
     return false;
@@ -621,11 +621,11 @@ bool RWGltf_CafWriter::writeJson (const Handle(TDocStd_Document)&  theDocument,
     uint32_t aContentLength = 0;
     uint32_t aContentType   = 0x4E4F534A;
 
-    aGltfContentFile.write (aMagic, 4);
-    aGltfContentFile.write ((const char* )&aVersion,       sizeof(aVersion));
-    aGltfContentFile.write ((const char* )&aLength,        sizeof(aLength));
-    aGltfContentFile.write ((const char* )&aContentLength, sizeof(aContentLength));
-    aGltfContentFile.write ((const char* )&aContentType,   sizeof(aContentType));
+    aGltfContentFile->write (aMagic, 4);
+    aGltfContentFile->write ((const char* )&aVersion,       sizeof(aVersion));
+    aGltfContentFile->write ((const char* )&aLength,        sizeof(aLength));
+    aGltfContentFile->write ((const char* )&aContentLength, sizeof(aContentLength));
+    aGltfContentFile->write ((const char* )&aContentType,   sizeof(aContentType));
   }
 
   // Prepare an indexed map of scene nodes (without assemblies) in correct order.
@@ -665,7 +665,7 @@ bool RWGltf_CafWriter::writeJson (const Handle(TDocStd_Document)&  theDocument,
     }
   }
 
-  rapidjson::OStreamWrapper aFileStream (aGltfContentFile);
+  rapidjson::OStreamWrapper aFileStream (*aGltfContentFile);
   myWriter.reset (new RWGltf_GltfOStreamWriter (aFileStream));
 
   myWriter->StartObject();
@@ -700,32 +700,32 @@ bool RWGltf_CafWriter::writeJson (const Handle(TDocStd_Document)&  theDocument,
 
   if (!myIsBinary)
   {
-    aGltfContentFile.close();
-    if (!aGltfContentFile.good())
+    aGltfContentFile->flush();
+    if (!aGltfContentFile->good())
     {
       Message::SendFail (TCollection_AsciiString ("File '") + aFileNameGltf + "' can not be written");
       return false;
     }
+    aGltfContentFile.reset();
     return true;
   }
 
-  int64_t aContentLen64 = (int64_t )aGltfContentFile.tellp() - 20;
+  int64_t aContentLen64 = (int64_t )aGltfContentFile->tellp() - 20;
   while (aContentLen64 % 4 != 0)
   {
-    aGltfContentFile.write (" ", 1);
+    aGltfContentFile->write (" ", 1);
     ++aContentLen64;
   }
 
   const uint32_t aBinLength = (uint32_t )myBinDataLen64;
   const uint32_t aBinType   = 0x004E4942;
-  aGltfContentFile.write ((const char*)&aBinLength, 4);
-  aGltfContentFile.write ((const char*)&aBinType,   4);
+  aGltfContentFile->write ((const char*)&aBinLength, 4);
+  aGltfContentFile->write ((const char*)&aBinType,   4);
 
   const int64_t aFullLen64 = aContentLen64 + 20 + myBinDataLen64 + 8;
   if (aFullLen64 < std::numeric_limits<uint32_t>::max())
   {
     {
-      const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
       opencascade::std::shared_ptr<std::istream> aBinFile = aFileSystem->OpenIStream (myBinFileNameFull, std::ios::in | std::ios::binary);
       if (aBinFile.get() == NULL || !aBinFile->good())
       {
@@ -741,7 +741,7 @@ bool RWGltf_CafWriter::writeJson (const Handle(TDocStd_Document)&  theDocument,
         {
           break;
         }
-        aGltfContentFile.write (aBuffer, aReadLen);
+        aGltfContentFile->write (aBuffer, aReadLen);
       }
     }
     OSD_Path aBinFilePath (myBinFileNameFull);
@@ -759,17 +759,17 @@ bool RWGltf_CafWriter::writeJson (const Handle(TDocStd_Document)&  theDocument,
 
   const uint32_t aLength        = (uint32_t )aFullLen64;
   const uint32_t aContentLength = (uint32_t )aContentLen64;
-  aGltfContentFile.seekp (8);
-  aGltfContentFile.write ((const char* )&aLength,        4);
-  aGltfContentFile.write ((const char* )&aContentLength, 4);
+  aGltfContentFile->seekp (8);
+  aGltfContentFile->write ((const char* )&aLength,        4);
+  aGltfContentFile->write ((const char* )&aContentLength, 4);
 
-  aGltfContentFile.close();
-  if (!aGltfContentFile.good())
+  aGltfContentFile->flush();
+  if (!aGltfContentFile->good())
   {
     Message::SendFail (TCollection_AsciiString ("File '") + aFileNameGltf + "' can not be written");
     return false;
   }
-
+  aGltfContentFile.reset();
   myWriter.reset();
   return true;
 #else
index b1e136a..4d9f589 100644 (file)
@@ -26,7 +26,7 @@
 #include <Interface_UndefinedContent.hxx>
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <Standard_Transient.hxx>
 #include <Standard_Type.hxx>
 #include <StepData_Protocol.hxx>
@@ -100,10 +100,10 @@ Standard_Boolean  StepSelect_WorkLibrary::WriteFile
   DeclareAndCast(StepData_Protocol,stepro,ctx.Protocol());
   if (stepmodel.IsNull() || stepro.IsNull()) return Standard_False;
 
-  std::ofstream fout;
-  OSD_OpenStream(fout,ctx.FileName(),std::ios::out|std::ios::trunc);
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (ctx.FileName(), std::ios::out | std::ios::trunc);
 
-  if (!fout || !fout.is_open()) {
+  if (aStream.get() == NULL) {
     ctx.CCheck(0)->AddFail("Step File could not be created");
     sout<<" Step File could not be created : " << ctx.FileName() << std::endl; return 0;
   }
@@ -130,12 +130,13 @@ Standard_Boolean  StepSelect_WorkLibrary::WriteFile
   for (chl.Start(); chl.More(); chl.Next())
     ctx.CCheck(chl.Number())->GetMessages(chl.Value());
   sout<<" Write ";
-  Standard_Boolean isGood = SW.Print(fout);                 
+  Standard_Boolean isGood = SW.Print (*aStream);                 
   sout<<" Done"<<std::endl;
       
   errno = 0;
-  fout.close();
-  isGood = fout.good() && isGood && !errno;
+  aStream->flush();
+  isGood = aStream->good() && isGood && !errno;
+  aStream.reset();
   if(errno)
     sout << strerror(errno) << std::endl;
   return isGood;  
index a42e88f..af3e257 100644 (file)
@@ -38,7 +38,6 @@
 #include <BinTObjDrivers.hxx>
 #include <XmlTObjDrivers.hxx>
 #include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
 
 #include <stdio.h>
 
@@ -208,9 +207,9 @@ static Standard_Integer saveModel (Draw_Interpretor& di, Standard_Integer argc,
     }
     if (anUseStream)
     {
-      std::ofstream aFileStream;
-      OSD_OpenStream (aFileStream, argv[2], std::ios::out | std::ios::binary);
-      isSaved = aModel->SaveAs (aFileStream);
+      const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+      opencascade::std::shared_ptr<std::ostream> aFileStream = aFileSystem->OpenOStream (argv[2], std::ios::out | std::ios::binary);
+      isSaved = aModel->SaveAs (*aFileStream);
     }
     else
       isSaved = aModel->SaveAs ( TCollection_ExtendedString (argv[2], Standard_True) );
index 3273204..dd42d4a 100644 (file)
@@ -21,7 +21,7 @@
 #include <Image_AlienPixMap.hxx>
 #include <Message.hxx>
 #include <OSD_File.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <V3d_View.hxx>
 #include <V3d_Viewer.hxx>
 
@@ -637,23 +637,24 @@ static Standard_Integer VListMaterials (Draw_Interpretor& theDI,
     Graphic3d_Vec4i (5, 1, 4, 8)
   };
 
-  std::ofstream aMatFile, anObjFile, anHtmlFile;
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aMatFile, anObjFile, aHtmlFile;
   if (aDumpFile.EndsWith (".obj")
    || aDumpFile.EndsWith (".mtl"))
   {
     const TCollection_AsciiString aMatFilePath  = aDumpFile.SubString (1, aDumpFile.Length() - 3) + "mtl";
     const TCollection_AsciiString anObjFilePath = aDumpFile.SubString (1, aDumpFile.Length() - 3) + "obj";
 
-    OSD_OpenStream (aMatFile,  aMatFilePath.ToCString(),  std::ios::out | std::ios::binary);
-    if (!aMatFile.is_open())
+    aMatFile = aFileSystem->OpenOStream (aMatFilePath, std::ios::out | std::ios::binary);
+    if (aMatFile.get() == NULL)
     {
       Message::SendFail ("Error: unable creating material file");
       return 0;
     }
     if (!aDumpFile.EndsWith (".mtl"))
     {
-      OSD_OpenStream (anObjFile, anObjFilePath.ToCString(), std::ios::out | std::ios::binary);
-      if (!anObjFile.is_open())
+      anObjFile = aFileSystem->OpenOStream (anObjFilePath, std::ios::out | std::ios::binary);
+      if (anObjFile.get() == NULL)
       {
         Message::SendFail ("Error: unable creating OBJ file");
         return 0;
@@ -661,19 +662,19 @@ static Standard_Integer VListMaterials (Draw_Interpretor& theDI,
 
       TCollection_AsciiString anMtlName, aFolder;
       OSD_Path::FolderAndFileFromPath (aMatFilePath, aFolder, anMtlName);
-      anObjFile << "mtllib " << anMtlName << "\n";
+      *anObjFile << "mtllib " << anMtlName << "\n";
     }
   }
   else if (aDumpFile.EndsWith (".htm")
         || aDumpFile.EndsWith (".html"))
   {
-    OSD_OpenStream (anHtmlFile, aDumpFile.ToCString(), std::ios::out | std::ios::binary);
-    if (!anHtmlFile.is_open())
+    aHtmlFile = aFileSystem->OpenOStream (aDumpFile, std::ios::out | std::ios::binary);
+    if (aHtmlFile.get() == NULL)
     {
       Message::SendFail ("Error: unable creating HTML file");
       return 0;
     }
-    anHtmlFile << "<html>\n"
+    *aHtmlFile << "<html>\n"
                   "<head><title>OCCT Material table</title></head>\n"
                   "<body>\n"
                   "<table border='1'><tbody>\n"
@@ -743,45 +744,45 @@ static Standard_Integer VListMaterials (Draw_Interpretor& theDI,
     const Graphic3d_Vec3 aSpecular  = (Graphic3d_Vec3 )aMat.SpecularColor();
     const Graphic3d_Vec3 anEmission = (Graphic3d_Vec3 )aMat.EmissiveColor();
     const Standard_Real  aShiness  = aMat.Shininess() * 1000.0;
-    if (aMatFile.is_open())
+    if (aMatFile.get() != NULL)
     {
-      aMatFile << "newmtl " << aMatName << "\n";
-      aMatFile << "Ka " << Quantity_Color::Convert_LinearRGB_To_sRGB (anAmbient) << "\n";
-      aMatFile << "Kd " << Quantity_Color::Convert_LinearRGB_To_sRGB (aDiffuse)  << "\n";
-      aMatFile << "Ks " << Quantity_Color::Convert_LinearRGB_To_sRGB (aSpecular) << "\n";
-      aMatFile << "Ns " << aShiness  << "\n";
+      *aMatFile << "newmtl " << aMatName << "\n";
+      *aMatFile << "Ka " << Quantity_Color::Convert_LinearRGB_To_sRGB (anAmbient) << "\n";
+      *aMatFile << "Kd " << Quantity_Color::Convert_LinearRGB_To_sRGB (aDiffuse)  << "\n";
+      *aMatFile << "Ks " << Quantity_Color::Convert_LinearRGB_To_sRGB (aSpecular) << "\n";
+      *aMatFile << "Ns " << aShiness  << "\n";
       if (aMat.Transparency() >= 0.0001)
       {
-        aMatFile << "Tr " << aMat.Transparency() << "\n";
+        *aMatFile << "Tr " << aMat.Transparency() << "\n";
       }
-      aMatFile << "\n";
+      *aMatFile << "\n";
     }
-    else if (anHtmlFile.is_open())
+    else if (aHtmlFile.get() != NULL)
     {
-      anHtmlFile << "<tr>\n";
-      anHtmlFile << "<td>" << aMat.StringName() << "</td>\n";
-      anHtmlFile << "<td>" << (aMat.MaterialType() == Graphic3d_MATERIAL_PHYSIC ? "PHYSIC" : "ASPECT")  << "</td>\n";
-      anHtmlFile << "<td>" << aMat.Transparency() << "</td>\n";
-      anHtmlFile << "<td>" << formatSvgColoredRect (aMat.PBRMaterial().Color().GetRGB()) << (Graphic3d_Vec3 )aMat.PBRMaterial().Color().GetRGB() << "</td>\n";
-      anHtmlFile << "<td>" << aMat.PBRMaterial().Metallic() << "</td>\n";
-      anHtmlFile << "<td>" << aMat.PBRMaterial().NormalizedRoughness() << "</td>\n";
-      anHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (aMat.PBRMaterial().Emission())) << aMat.PBRMaterial().Emission() << "</td>\n";
-      anHtmlFile << "<td>" << aMat.PBRMaterial().IOR() << "</td>\n";
-      anHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (anAmbient))  << anAmbient  << "</td>\n";
-      anHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (aDiffuse))   << aDiffuse   << "</td>\n";
-      anHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (aSpecular))  << aSpecular  << "</td>\n";
-      anHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (anEmission)) << anEmission << "</td>\n";
-      anHtmlFile << "<td>" << aMat.Shininess() << "</td>\n";
-      anHtmlFile << "<td>" << aMat.BSDF().Kc << "</td>\n";
-      anHtmlFile << "<td>" << aMat.BSDF().Kd << "</td>\n";
-      anHtmlFile << "<td>" << aMat.BSDF().Ks << "</td>\n";
-      anHtmlFile << "<td>" << aMat.BSDF().Kt << "</td>\n";
-      anHtmlFile << "<td>" << aMat.BSDF().Le << "</td>\n";
-      anHtmlFile << "<td>" << aMat.BSDF().Absorption << "</td>\n";
-      anHtmlFile << "<td>" << fresnelModelString (aMat.BSDF().FresnelCoat.FresnelType()) << "</td>\n";
-      anHtmlFile << "<td>" << fresnelModelString (aMat.BSDF().FresnelBase.FresnelType()) << "</td>\n";
-      anHtmlFile << "<td>" << aMat.RefractionIndex() << "</td>\n";
-      anHtmlFile << "</tr>\n";
+      *aHtmlFile << "<tr>\n";
+      *aHtmlFile << "<td>" << aMat.StringName() << "</td>\n";
+      *aHtmlFile << "<td>" << (aMat.MaterialType() == Graphic3d_MATERIAL_PHYSIC ? "PHYSIC" : "ASPECT")  << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.Transparency() << "</td>\n";
+      *aHtmlFile << "<td>" << formatSvgColoredRect (aMat.PBRMaterial().Color().GetRGB()) << (Graphic3d_Vec3 )aMat.PBRMaterial().Color().GetRGB() << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.PBRMaterial().Metallic() << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.PBRMaterial().NormalizedRoughness() << "</td>\n";
+      *aHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (aMat.PBRMaterial().Emission())) << aMat.PBRMaterial().Emission() << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.PBRMaterial().IOR() << "</td>\n";
+      *aHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (anAmbient))  << anAmbient  << "</td>\n";
+      *aHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (aDiffuse))   << aDiffuse   << "</td>\n";
+      *aHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (aSpecular))  << aSpecular  << "</td>\n";
+      *aHtmlFile << "<td>" << formatSvgColoredRect (Quantity_Color (anEmission)) << anEmission << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.Shininess() << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.BSDF().Kc << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.BSDF().Kd << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.BSDF().Ks << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.BSDF().Kt << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.BSDF().Le << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.BSDF().Absorption << "</td>\n";
+      *aHtmlFile << "<td>" << fresnelModelString (aMat.BSDF().FresnelCoat.FresnelType()) << "</td>\n";
+      *aHtmlFile << "<td>" << fresnelModelString (aMat.BSDF().FresnelBase.FresnelType()) << "</td>\n";
+      *aHtmlFile << "<td>" << aMat.RefractionIndex() << "</td>\n";
+      *aHtmlFile << "</tr>\n";
     }
     else
     {
@@ -808,20 +809,20 @@ static Standard_Integer VListMaterials (Draw_Interpretor& theDI,
       theDI << "  RefractionIndex:        " << aMat.RefractionIndex() << "\n";
     }
 
-    if (anObjFile.is_open())
+    if (anObjFile.get() != NULL)
     {
-      anObjFile << "g " << aMatName << "\n";
-      anObjFile << "usemtl " << aMatName << "\n";
+      *anObjFile << "g " << aMatName << "\n";
+      *anObjFile << "usemtl " << aMatName << "\n";
       for (Standard_Integer aVertIter = 0; aVertIter < 8; ++aVertIter)
       {
-        anObjFile << "v " << (aBoxVerts[aVertIter] + Graphic3d_Vec3 (3.0f * anX, -3.0f * anY, 0.0f)) << "\n";
+        *anObjFile << "v " << (aBoxVerts[aVertIter] + Graphic3d_Vec3 (3.0f * anX, -3.0f * anY, 0.0f)) << "\n";
       }
-      anObjFile << "s off\n";
+      *anObjFile << "s off\n";
       for (Standard_Integer aFaceIter = 0; aFaceIter < 6; ++aFaceIter)
       {
-        anObjFile << "f " << (aBoxQuads[aFaceIter] + Graphic3d_Vec4i (8 * aMatIndex)) << "\n";
+        *anObjFile << "f " << (aBoxQuads[aFaceIter] + Graphic3d_Vec4i (8 * aMatIndex)) << "\n";
       }
-      anObjFile << "\n";
+      *anObjFile << "\n";
       if (++anX > 5)
       {
         anX = 0;
@@ -830,9 +831,9 @@ static Standard_Integer VListMaterials (Draw_Interpretor& theDI,
     }
   }
 
-  if (anHtmlFile.is_open())
+  if (aHtmlFile.get() != NULL)
   {
-    anHtmlFile << "</tbody></table>\n</body>\n</html>\n";
+    *aHtmlFile << "</tbody></table>\n</body>\n</html>\n";
   }
   return 0;
 }
@@ -892,7 +893,8 @@ static Standard_Integer VListColors (Draw_Interpretor& theDI,
     }
   }
 
-  std::ofstream anHtmlFile;
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aHtmlFile;
   TCollection_AsciiString aFileNameBase, aFolder;
   if (aDumpFile.EndsWith (".htm")
    || aDumpFile.EndsWith (".html"))
@@ -929,13 +931,13 @@ static Standard_Integer VListColors (Draw_Interpretor& theDI,
 
   if (!aDumpFile.IsEmpty())
   {
-    OSD_OpenStream (anHtmlFile, aDumpFile.ToCString(), std::ios::out | std::ios::binary);
-    if (!anHtmlFile.is_open())
+    aHtmlFile = aFileSystem->OpenOStream (aDumpFile, std::ios::out | std::ios::binary);
+    if (aHtmlFile.get() == NULL)
     {
       Message::SendFail ("Error: unable creating HTML file");
       return 0;
     }
-    anHtmlFile << "<html>\n"
+    *aHtmlFile << "<html>\n"
                << "<head><title>OCCT Color table</title></head>\n"
                << "<body>\n"
                << "<table border='1'><tbody>\n"
@@ -957,7 +959,7 @@ static Standard_Integer VListColors (Draw_Interpretor& theDI,
     const TCollection_AsciiString aColName  = Quantity_Color::StringName (aColIter.Value());
     const TCollection_AsciiString anSRgbHex = Quantity_Color::ColorToHex (aCol);
     const Graphic3d_Vec3i anSRgbInt ((Graphic3d_Vec3 )aCol * 255.0f);
-    if (anHtmlFile.is_open())
+    if (aHtmlFile.get() != NULL)
     {
       const TCollection_AsciiString anImgPath = aFileNameBase + "_" + aColName + ".png";
       if (!aView.IsNull())
@@ -972,14 +974,14 @@ static Standard_Integer VListColors (Draw_Interpretor& theDI,
         }
       }
 
-      anHtmlFile << "<tr>\n";
-      anHtmlFile << "<td style='background-color:" << anSRgbHex << "'><pre>       </pre></td>\n";
-      anHtmlFile << "<td><img src='" << (!aView.IsNull() ? anImgPath : "") << "'></img></td>\n";
-      anHtmlFile << "<td style='text-align:left'>" << aColName << "</td>\n";
-      anHtmlFile << "<td style='text-align:left'><pre>" << anSRgbHex << "</pre></td>\n";
-      anHtmlFile << "<td style='text-align:left'>(" << anSRgbInt.r() << " " << anSRgbInt.g() << " " << anSRgbInt.b() << ")</td>\n";
-      anHtmlFile << "<td style='text-align:left'>(" << aCol.Red() << " " << aCol.Green() << " " << aCol.Blue() << ")</td>\n";
-      anHtmlFile << "</tr>\n";
+      *aHtmlFile << "<tr>\n";
+      *aHtmlFile << "<td style='background-color:" << anSRgbHex << "'><pre>       </pre></td>\n";
+      *aHtmlFile << "<td><img src='" << (!aView.IsNull() ? anImgPath : "") << "'></img></td>\n";
+      *aHtmlFile << "<td style='text-align:left'>" << aColName << "</td>\n";
+      *aHtmlFile << "<td style='text-align:left'><pre>" << anSRgbHex << "</pre></td>\n";
+      *aHtmlFile << "<td style='text-align:left'>(" << anSRgbInt.r() << " " << anSRgbInt.g() << " " << anSRgbInt.b() << ")</td>\n";
+      *aHtmlFile << "<td style='text-align:left'>(" << aCol.Red() << " " << aCol.Green() << " " << aCol.Blue() << ")</td>\n";
+      *aHtmlFile << "</tr>\n";
     }
     else
     {
@@ -994,9 +996,9 @@ static Standard_Integer VListColors (Draw_Interpretor& theDI,
     ViewerTest::RemoveView (aView);
   }
 
-  if (anHtmlFile.is_open())
+  if (aHtmlFile.get() != NULL)
   {
-    anHtmlFile << "</tbody></table>\n</body>\n</html>\n";
+    *aHtmlFile << "</tbody></table>\n</body>\n</html>\n";
   }
   return 0;
 }
@@ -1085,20 +1087,19 @@ static Standard_Integer VGenEnvLUT (Draw_Interpretor&,
     aNbSamples = 1024;
   }
 
-  std::ofstream aFile;
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aFile = aFileSystem->OpenOStream (aFilePath, std::ios::out | std::ios::trunc);
 
-  OSD_OpenStream (aFile, aFilePath, std::ios::out | std::ios::binary);
-
-  if (!aFile.good())
+  if (aFile.get() == NULL || !aFile->good())
   {
     Message::SendFail() << "Error: unable to write to " << aFilePath;
     return 1;
   }
 
-  aFile << "//this file has been generated by vgenenvlut draw command\n";
-  aFile << "static unsigned int Textures_EnvLUTSize = " << aTableSize << ";\n\n";
-  aFile << "static float Textures_EnvLUT[] =\n";
-  aFile << "{\n";
+  *aFile << "//this file has been generated by vgenenvlut draw command\n";
+  *aFile << "static unsigned int Textures_EnvLUTSize = " << aTableSize << ";\n\n";
+  *aFile << "static float Textures_EnvLUT[] =\n";
+  *aFile << "{\n";
 
   Handle(Image_PixMap) aPixMap = new Image_PixMap();
   aPixMap->InitZero (Image_Format_RGF, aTableSize, aTableSize);
@@ -1112,44 +1113,43 @@ static Standard_Integer VGenEnvLUT (Draw_Interpretor&,
     aCounter = 0;
     for (int x = 0; x < aTableSize; ++x)
     {
-      aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(aTableSize - 1 - y, x).x()) << ",";
-      aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(aTableSize - 1 - y, x).y()) << ",";
+      *aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(aTableSize - 1 - y, x).x()) << ",";
+      *aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(aTableSize - 1 - y, x).y()) << ",";
       if (++aCounter % aNumbersInRow == 0)
       {
-        aFile << "\n";
+        *aFile << "\n";
       }
       else if (x != aTableSize - 1)
       {
-        aFile << " ";
+        *aFile << " ";
       }
     }
-    aFile << "\n";
+    *aFile << "\n";
     if (aTableSize % aNumbersInRow != 0)
     {
-      aFile << "\n";
+      *aFile << "\n";
     }
   }
 
   aCounter = 0;
   for (int x = 0; x < aTableSize - 1; ++x)
   {
-    aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(0, x).x()) << ",";
-    aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(0, x).y()) << ",";
+    *aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(0, x).x()) << ",";
+    *aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(0, x).y()) << ",";
     if (++aCounter % aNumbersInRow == 0)
     {
-      aFile << "\n";
+      *aFile << "\n";
     }
     else
     {
-      aFile << " ";
+      *aFile << " ";
     }
   }
 
-  aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(0, aTableSize - 1).x()) << ",";
-  aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(0, aTableSize - 1).y()) << "\n";
+  *aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(0, aTableSize - 1).x()) << ",";
+  *aFile << envLutWriteToFile (aPixMap->Value<Graphic3d_Vec3>(0, aTableSize - 1).y()) << "\n";
 
-  aFile << "};";
-  aFile.close();
+  *aFile << "};";
 
   return 0;
 }
index c4964b5..9b884a0 100644 (file)
@@ -13,7 +13,7 @@
 
 
 #include <BRep_Tool.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_Path.hxx>
 #include <Poly_Triangulation.hxx>
 #include <Quantity_HArray1OfColor.hxx>
@@ -225,9 +225,9 @@ Standard_Boolean VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Stand
 {
   OSD_Path thePath(aFile);
   TCollection_AsciiString theFile;thePath.SystemName(theFile);
-  std::ofstream outfile;
-  OSD_OpenStream(outfile, theFile.ToCString(), std::ios::out);
-  if (!outfile)
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> anOutFile = aFileSystem->OpenOStream (theFile, std::ios::out);
+  if (anOutFile.get() == NULL)
   {
     return Standard_False;
   }
@@ -308,16 +308,16 @@ Standard_Boolean VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Stand
                                                                           XUp, YUp, ZUp,
                                                                           Camera,
                                                                           Light);
-  Vrml::VrmlHeaderWriter(outfile);
+  Vrml::VrmlHeaderWriter (*anOutFile);
   if (myRepresentation == VrmlAPI_BothRepresentation)
-    Vrml::CommentWriter(" This file contents both Shaded and Wire Frame representation of selected Shape ",outfile);   
+    Vrml::CommentWriter(" This file contents both Shaded and Wire Frame representation of selected Shape ", *anOutFile);
   if (myRepresentation == VrmlAPI_ShadedRepresentation)
-    Vrml::CommentWriter(" This file contents only Shaded representation of selected Shape ",outfile);   
+    Vrml::CommentWriter(" This file contents only Shaded representation of selected Shape ", *anOutFile);
   if (myRepresentation == VrmlAPI_WireFrameRepresentation)
-    Vrml::CommentWriter(" This file contents only Wire Frame representation of selected Shape ",outfile);   
+    Vrml::CommentWriter(" This file contents only Wire Frame representation of selected Shape ", *anOutFile);
   Vrml_Separator S1;
-  S1.Print(outfile); 
-  projector->Add(outfile);
+  S1.Print (*anOutFile); 
+  projector->Add (*anOutFile);
   Light = VrmlConverter_DirectionLight;
   Camera = VrmlConverter_OrthographicCamera;
   Handle(VrmlConverter_Projector) projector1 = new VrmlConverter_Projector (Shapes, 
@@ -326,32 +326,32 @@ Standard_Boolean VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Stand
                                                                           XUp, YUp, ZUp,
                                                                           Camera,
                                                                           Light);
-  projector1->Add(outfile);
+  projector1->Add (*anOutFile);
   Vrml_Separator S2;
-  S2.Print(outfile); 
+  S2.Print (*anOutFile);
   if ( (myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation) && hasTriangles)
     {
       Vrml_Group Group1;
-      Group1.Print(outfile);
+      Group1.Print (*anOutFile);
       Vrml_Instancing I2 ("Shaded representation of shape");
-      I2.DEF(outfile);
-      VrmlConverter_ShadedShape::Add(outfile,aShape,myDrawer);
-      Group1.Print(outfile);
+      I2.DEF (*anOutFile);
+      VrmlConverter_ShadedShape::Add (*anOutFile,aShape,myDrawer);
+      Group1.Print (*anOutFile);
     }
   if (myRepresentation == VrmlAPI_WireFrameRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
     {
       Vrml_Group Group2;
-      Group2.Print(outfile);
+      Group2.Print (*anOutFile);
       Vrml_Instancing I3 ("Wire Frame representation of shape");
-      I3.DEF(outfile);
-      VrmlConverter_WFDeflectionShape::Add(outfile,aShape,myDrawer);
-      Group2.Print(outfile);
+      I3.DEF (*anOutFile);
+      VrmlConverter_WFDeflectionShape::Add (*anOutFile,aShape,myDrawer);
+      Group2.Print (*anOutFile);
     }
-  S2.Print(outfile);
-  S1.Print(outfile);
+  S2.Print (*anOutFile);
+  S1.Print (*anOutFile);
 
-  outfile.close();
-  return outfile.good();
+  anOutFile->flush();
+  return anOutFile->good();
 }
 
 Standard_Boolean VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Standard_CString aFile) const
@@ -369,15 +369,15 @@ Standard_Boolean VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Stand
   aConv.AddShape(aShape);
   aConv.Convert(anExtFace, anExtEdge);
 
-  std::ofstream anOutStream;
-  OSD_OpenStream(anOutStream, aFile, std::ios::out);
-  if (anOutStream)
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> anOutStream = aFileSystem->OpenOStream (aFile, std::ios::out);
+  if (anOutStream.get() != NULL)
   {
-    anOutStream << aScene;
-    anOutStream.close();
-    return anOutStream.good();
+    *anOutStream << aScene;
+    anOutStream->flush();
+    return anOutStream->good();
   }
-
+  anOutStream.reset();
   return Standard_False;
 }
 
@@ -394,15 +394,15 @@ Standard_Boolean VrmlAPI_Writer::WriteDoc(
   VrmlData_ShapeConvert aConv(aScene, theScale);
   aConv.ConvertDocument(theDoc);
 
-  std::ofstream anOutStream;
-  OSD_OpenStream(anOutStream, theFile, std::ios::out);
-  if (anOutStream)
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> anOutStream = aFileSystem->OpenOStream (theFile, std::ios::out);
+  if (anOutStream.get() != NULL)
   {
-    anOutStream << aScene;
-    anOutStream.close();
-    return anOutStream.good();
+    *anOutStream << aScene;
+    anOutStream->flush();
+    return anOutStream->good();
   }
-
+  anOutStream.reset();
   return Standard_False;
 }
 
index 2c7215b..f1176e6 100644 (file)
@@ -24,7 +24,7 @@
 #include <LDOM_XmlWriter.hxx>
 #include <OSD_Environment.hxx>
 #include <OSD_File.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <PCDM.hxx>
 #include <PCDM_ReadWriter.hxx>
 #include <Standard_ErrorHandler.hxx>
@@ -98,12 +98,12 @@ void XmlLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)&
 {
   myFileName = theFileName;
 
-  std::ofstream aFileStream;
-  OSD_OpenStream (aFileStream, theFileName, std::ios::out);
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aFileStream = aFileSystem->OpenOStream (theFileName, std::ios::out);
 
-  if (aFileStream.is_open() && aFileStream.good())
+  if (aFileStream.get() != NULL && aFileStream->good())
   {
-    Write (theDocument, aFileStream, theRange);
+    Write (theDocument, *aFileStream, theRange);
   }
   else
   {