]> OCCT Git - occt-copy.git/commitdiff
STEPCAFControl_Reader::ReadStream() - added stream reading method (similar to STEPCon...
authorkgv <kgv@opencascade.com>
Thu, 27 May 2021 08:54:41 +0000 (11:54 +0300)
committerkgv <kgv@opencascade.com>
Thu, 27 May 2021 08:54:41 +0000 (11:54 +0300)
Added option -stream to ReadStep command (similar to testreadstep command).

src/STEPCAFControl/STEPCAFControl_Reader.cxx
src/STEPCAFControl/STEPCAFControl_Reader.hxx
src/XDEDRAW/XDEDRAW_Common.cxx
src/XSDRAWSTEP/XSDRAWSTEP.cxx

index ed31a819e4673687c3560e1c8269c0bf312ef8a8..115f67de3c2be32b9c233d6066012c6ba877ee18 100644 (file)
@@ -389,14 +389,22 @@ TCollection_ExtendedString STEPCAFControl_Reader::convertName (const TCollection
 
 //=======================================================================
 //function : ReadFile
-//purpose  : 
+//purpose  :
 //=======================================================================
-
-IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile(const Standard_CString filename)
+IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString theFileName)
 {
-  return myReader.ReadFile(filename);
+  return myReader.ReadFile (theFileName);
 }
 
+//=======================================================================
+//function : ReadStream
+//purpose  :
+//=======================================================================
+IFSelect_ReturnStatus STEPCAFControl_Reader::ReadStream (const Standard_CString theName,
+                                                         std::istream& theIStream)
+{
+  return myReader.ReadStream (theName, theIStream);
+}
 
 //=======================================================================
 //function : NbRootsForTransfer
index 2aa4d23f38a30e7e21e418b50b2e527e44e58b5a..647311804dde82d4031a4c3d7d08af5e8f40187c 100644 (file)
@@ -77,11 +77,20 @@ public:
   //! Clears the internal data structures and attaches to a new session
   //! Clears the session if it was not yet set for STEP
   Standard_EXPORT void Init (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
-  
+
   //! Loads a file and returns the read status
-  //! Provided for use like single-file reader
-  Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename);
-  
+  //! Provided for use like single-file reader.
+  //! @param theFileName [in] file to open
+  //! @return read status
+  Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString theFileName);
+
+  //! Loads a file from stream and returns the read status.
+  //! @param theName [in] auxiliary stream name
+  //! @param theIStream [in] stream to read from
+  //! @return read status
+  Standard_EXPORT IFSelect_ReturnStatus ReadStream (const Standard_CString theName,
+                                                    std::istream& theIStream);
+
   //! Returns number of roots recognized for transfer
   //! Shortcut for Reader().NbRootsForTransfer()
   Standard_EXPORT Standard_Integer NbRootsForTransfer();
index 45cb4b1e0c741971bab5a7f670554a6869414cab..44cc378ba4eb6b40f39341c0305050c3a9d8637c 100644 (file)
@@ -25,6 +25,8 @@
 #include <IGESCAFControl_Writer.hxx>
 #include <IGESControl_Controller.hxx>
 #include <Interface_Macros.hxx>
+#include <OSD_OpenFile.hxx>
+#include <OSD_Path.hxx>
 #include <STEPCAFControl_ExternFile.hxx>
 #include <STEPCAFControl_Reader.hxx>
 #include <STEPCAFControl_Writer.hxx>
@@ -346,11 +348,16 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c
 
   Standard_CString aDocName = NULL;
   TCollection_AsciiString aFilePath, aModeStr;
+  bool toTestStream = false;
   for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
   {
     TCollection_AsciiString anArgCase (argv[anArgIter]);
     anArgCase.LowerCase();
-    if (aDocName == NULL)
+    if (anArgCase == "-stream")
+    {
+      toTestStream = true;
+    }
+    else if (aDocName == NULL)
     {
       aDocName = argv[anArgIter];
     }
@@ -406,7 +413,18 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c
   {
     Message_ProgressScope aReadScope (aRootScope.Next(), "File reading", 1);
     aReadScope.Show();
-    readstat = reader.ReadFile (fnom.ToCString());
+    if (toTestStream)
+    {
+      std::ifstream aStream;
+      OSD_OpenStream (aStream, fnom.ToCString(), std::ios::in | std::ios::binary);
+      TCollection_AsciiString aFolder, aFileName;
+      OSD_Path::FolderAndFileFromPath (fnom, aFolder, aFileName);
+      readstat = reader.ReadStream (aFileName.ToCString(), aStream);
+    }
+    else
+    {
+      readstat = reader.ReadFile (fnom.ToCString());
+    }
   }
   else if (XSDRAW::Session()->NbStartingEntities() > 0)
   {
@@ -679,8 +697,9 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di)
   di.Add("ReadIges" , "Doc filename: Read IGES file to DECAF document" ,__FILE__, ReadIges, g);
   di.Add("WriteIges" , "Doc filename: Write DECAF document to IGES file" ,__FILE__, WriteIges, g);
   di.Add("ReadStep" ,
-         "Doc filename [mode]"
-         "\n\t\t: Read STEP file to a document.",
+         "Doc filename [mode] [-stream]"
+         "\n\t\t: Read STEP file to a document."
+         "\n\t\t:  -stream read using istream reading interface (testing)",
          __FILE__, ReadStep, g);
   di.Add("WriteStep" , "Doc filename [mode=a [multifile_prefix] [label]]: Write DECAF document to STEP file" ,__FILE__, WriteStep, g);  
   
index ab7cf79a1d8ca888400fb2b4275e4cda887a7588..5b20f2dfe44e0a9266836e639f6387e04fff222f 100644 (file)
@@ -24,6 +24,8 @@
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
 #include <Message_ProgressScope.hxx>
+#include <OSD_OpenFile.hxx>
+#include <OSD_Path.hxx>
 #include <STEPControl_ActorWrite.hxx>
 #include <STEPControl_Controller.hxx>
 #include <STEPControl_Reader.hxx>
@@ -285,8 +287,11 @@ static Standard_Integer testreadstep (Draw_Interpretor& di, Standard_Integer arg
   IFSelect_ReturnStatus readstat;
   if (useStream)
   {
-    std::ifstream aStream (filename);
-    readstat = Reader.ReadStream(filename, aStream);
+    std::ifstream aStream;
+    OSD_OpenStream (aStream, filename, std::ios::in | std::ios::binary);
+    TCollection_AsciiString aFolder, aFileNameShort;
+    OSD_Path::FolderAndFileFromPath (filename, aFolder, aFileNameShort);
+    readstat = Reader.ReadStream (aFileNameShort.ToCString(), aStream);
   }
   else
   {