1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0032350: Data Exchange - STEPControl_Writer.writeStream(std::ostream)

STEPCAFControl_Writer::WriteStream(), STEPControl_Writer::WriteStream() - added interface for writing into stream.
STEPCAFControl_Reader::ReadStream() - added stream reading method (similar to STEPControl_Reader::ReadStream()).

Added option -stream to commands ReadStep, WriteStep, and testwritestep.
This commit is contained in:
mahaidong
2021-05-14 14:35:28 +08:00
committed by smoskvin
parent b77de43fb0
commit 3e06b70623
9 changed files with 465 additions and 209 deletions

View File

@@ -336,14 +336,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

View File

@@ -73,11 +73,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();

View File

@@ -302,34 +302,51 @@ void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS,
//function : Write
//purpose :
//=======================================================================
IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename)
IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString theFileName)
{
IFSelect_ReturnStatus status = myWriter.Write ( filename );
// get directory name of the main file
OSD_Path mainfile ( filename );
mainfile.SetName ( "" );
mainfile.SetExtension ( "" );
TCollection_AsciiString dpath;
mainfile.SystemName ( dpath );
NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator it(myFiles);
for ( ; it.More(); it.Next() ) {
Handle(STEPCAFControl_ExternFile) EF = it.Value();
if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
// construct extern file name
TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() );
if ( fname.Length() <= 0 ) fname = EF->GetName()->String();
#ifdef OCCT_DEBUG
std::cout << "Writing external file: " << fname.ToCString() << std::endl;
#endif
EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) );
IFSelect_ReturnStatus aStatus = myWriter.Write (theFileName);
if (aStatus != IFSelect_RetDone)
{
return aStatus;
}
return status;
// get directory name of the main file
TCollection_AsciiString aDirPath;
{
OSD_Path aMainFile (theFileName);
aMainFile.SetName ("");
aMainFile.SetExtension ("");
aMainFile.SystemName (aDirPath);
}
for (NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator anExtFileIter (myFiles);
anExtFileIter.More(); anExtFileIter.Next())
{
Handle(STEPCAFControl_ExternFile) anExtFile = anExtFileIter.Value();
if (anExtFile->GetWriteStatus() != IFSelect_RetVoid)
{
continue;
}
// construct extern file name
TCollection_AsciiString aFileName = OSD_Path::AbsolutePath (aDirPath, anExtFile->GetName()->String());
if (aFileName.Length() <= 0)
{
aFileName = anExtFile->GetName()->String();
}
#ifdef OCCT_DEBUG
std::cout << "Writing external file: " << aFileName << std::endl;
#endif
const IFSelect_ReturnStatus anExtStatus = anExtFile->GetWS()->SendAll (aFileName.ToCString());
anExtFile->SetWriteStatus (anExtStatus);
if (anExtStatus != IFSelect_RetDone)
{
aStatus = anExtStatus;
}
}
return aStatus;
}
//=======================================================================
@@ -352,6 +369,21 @@ void STEPCAFControl_Writer::prepareUnit(const TDF_Label& theLabel,
}
}
//=======================================================================
//function : WriteStream
//purpose :
//=======================================================================
IFSelect_ReturnStatus STEPCAFControl_Writer::WriteStream (std::ostream& theStream)
{
if (!myFiles.IsEmpty())
{
// writing external files is unsupported via stream interface
return IFSelect_RetError;
}
return myWriter.WriteStream (theStream);
}
//=======================================================================
//function : Transfer
//purpose :

View File

@@ -70,7 +70,11 @@ public:
//! filename will be a name of root file, all other files
//! have names of corresponding parts
//! Provided for use like single-file writer
Standard_EXPORT IFSelect_ReturnStatus Write (const Standard_CString filename);
Standard_EXPORT IFSelect_ReturnStatus Write (const Standard_CString theFileName);
//! Writes all the produced models into the stream.
//! Provided for use like single-file writer
Standard_EXPORT IFSelect_ReturnStatus WriteStream (std::ostream& theStream);
//! Transfers a document (or single label) to a STEP model
//! The mode of translation of shape is AsIs