]> OCCT Git - occt.git/commitdiff
0032826: Data Exchange - use OSD_FileSystem within RWStl::ReadAscii() and StepFile_Read()
authorkgv <kgv@opencascade.com>
Wed, 9 Feb 2022 18:16:26 +0000 (21:16 +0300)
committersmoskvin <smoskvin@opencascade.com>
Thu, 10 Feb 2022 17:39:28 +0000 (20:39 +0300)
src/RWStl/RWStl.cxx
src/StepFile/StepFile_Read.cxx
src/StepFile/StepFile_Read.hxx

index 8b703f443eb0a1594f7c994b8eb027c62d60f4f1..86eaeb601e83a1468461097f9f7880352f59d6cc 100644 (file)
@@ -147,12 +147,6 @@ Handle(Poly_Triangulation) RWStl::ReadFile (const OSD_Path& theFile,
 Handle(Poly_Triangulation) RWStl::ReadBinary (const OSD_Path& theFile,
                                               const Message_ProgressRange& theProgress)
 {
-  OSD_File aFile(theFile);
-  if (!aFile.Exists())
-  {
-    return Handle(Poly_Triangulation)();
-  }
-
   TCollection_AsciiString aPath;
   theFile.SystemName (aPath);
 
@@ -179,31 +173,24 @@ Handle(Poly_Triangulation) RWStl::ReadBinary (const OSD_Path& theFile,
 Handle(Poly_Triangulation) RWStl::ReadAscii (const OSD_Path& theFile,
                                              const Message_ProgressRange& theProgress)
 {
-  OSD_File aFile (theFile);
-  if (!aFile.Exists())
-  {
-    return Handle(Poly_Triangulation)();
-  }
-
   TCollection_AsciiString aPath;
   theFile.SystemName (aPath);
 
-  std::filebuf aBuf;
-  OSD_OpenStream (aBuf, aPath, std::ios::in | std::ios::binary);
-  if (!aBuf.is_open())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (aPath, std::ios::in | std::ios::binary);
+  if (aStream.get() == NULL)
   {
     return Handle(Poly_Triangulation)();
   }
-  Standard_IStream aStream (&aBuf);
 
   // get length of file to feed progress indicator
-  aStream.seekg (0, aStream.end);
-  std::streampos theEnd = aStream.tellg();
-  aStream.seekg (0, aStream.beg);
+  aStream->seekg (0, aStream->end);
+  std::streampos theEnd = aStream->tellg();
+  aStream->seekg (0, aStream->beg);
 
   Reader aReader;
   Standard_ReadLineBuffer aBuffer (THE_BUFFER_SIZE);
-  if (!aReader.ReadAscii (aStream, aBuffer, theEnd, theProgress))
+  if (!aReader.ReadAscii (*aStream, aBuffer, theEnd, theProgress))
   {
     return Handle(Poly_Triangulation)();
   }
@@ -351,7 +338,7 @@ Standard_Boolean RWStl::writeBinary (const Handle(Poly_Triangulation)& theMesh,
                                      FILE* theFile,
                                      const Message_ProgressRange& theProgress)
 {
-  char aHeader[80] = "STL Exported by OpenCASCADE [www.opencascade.com]";
+  char aHeader[80] = "STL Exported by Open CASCADE Technology [dev.opencascade.org]";
   if (fwrite (aHeader, 1, 80, theFile) != 80)
   {
     return Standard_False;
index b2e2a877b7f8cddb28624a0433075650ba3551b1..26319a7c43e364d9ee7f302cb7dd17121aec78af 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-//   StepFile_Read
-
-//   routine assurant l enchainement des operations de lecture d un fichier
-//   STEP dans un StepModel, en fonction d une cle de reconnaissance
-//   Retour de la fonction :
-//     0 si OK  (le StepModel a ete charge)
-//    -1 si abandon car fichier pas pu etre ouvert
-//     1 si erreur en cours de lecture
-
-//   Compilation conditionnelle : concerne les mesures de performances
-
-#include <stdio.h>
-#include <iostream> 
-
-#include <step.tab.hxx>
 #include <StepFile_Read.hxx>
+
 #include <StepFile_ReadData.hxx>
 
 #include <Interface_Check.hxx>
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
 
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_Timer.hxx>
 
+#include "step.tab.hxx"
+
+#include <stdio.h>
+
 #ifdef OCCT_DEBUG
 #define CHRONOMESURE
 #endif
@@ -73,14 +63,15 @@ static Standard_Integer StepFile_Read (const char* theName,
                                        const Handle(StepData_FileRecognizer)& theRecogData)
 {
   // if stream is not provided, open file stream here
-  std::istream *aStreamPtr = theIStream;
-  std::ifstream aFileStream;
-  if (!aStreamPtr) {
-    OSD_OpenStream(aFileStream, theName, std::ios_base::in | std::ios_base::binary);
-    aStreamPtr = &aFileStream;
+  std::istream* aStreamPtr = theIStream;
+  std::shared_ptr<std::istream> aFileStream;
+  if (aStreamPtr == nullptr)
+  {
+    const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+    aFileStream = aFileSystem->OpenIStream (theName, std::ios::in | std::ios::binary);
+    aStreamPtr = aFileStream.get();
   }
-
-  if (aStreamPtr->fail())
+  if (aStreamPtr == nullptr || aStreamPtr->fail())
   {
     return -1;
   }
index 3f51411c5fc987b0f79fc264e40e2d371e43efdf..56921cbe6e351462a4e0ebcf9584932f9be7573f 100644 (file)
@@ -17,6 +17,9 @@
 #ifndef StepFile_Read_HeaderFile
 #define StepFile_Read_HeaderFile
 
+#include <Standard_CString.hxx>
+#include <Standard_Type.hxx>
+
 #include <iostream>
 
 class StepData_StepModel;