From: kgv Date: Thu, 27 May 2021 08:54:41 +0000 (+0300) Subject: STEPCAFControl_Reader::ReadStream() - added stream reading method (similar to STEPCon... X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=bf352805bbdf3465b20ca3b1b632e73dbaf6b2a9;p=occt-copy.git STEPCAFControl_Reader::ReadStream() - added stream reading method (similar to STEPControl_Reader::ReadStream()). Added option -stream to ReadStep command (similar to testreadstep command). --- diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.cxx b/src/STEPCAFControl/STEPCAFControl_Reader.cxx index ed31a819e4..115f67de3c 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.cxx @@ -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 diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.hxx b/src/STEPCAFControl/STEPCAFControl_Reader.hxx index 2aa4d23f38..647311804d 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.hxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.hxx @@ -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(); diff --git a/src/XDEDRAW/XDEDRAW_Common.cxx b/src/XDEDRAW/XDEDRAW_Common.cxx index 45cb4b1e0c..44cc378ba4 100644 --- a/src/XDEDRAW/XDEDRAW_Common.cxx +++ b/src/XDEDRAW/XDEDRAW_Common.cxx @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -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); diff --git a/src/XSDRAWSTEP/XSDRAWSTEP.cxx b/src/XSDRAWSTEP/XSDRAWSTEP.cxx index ab7cf79a1d..5b20f2dfe4 100644 --- a/src/XSDRAWSTEP/XSDRAWSTEP.cxx +++ b/src/XSDRAWSTEP/XSDRAWSTEP.cxx @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -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 {