#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>
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;
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;
}
#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>
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
{
#include <BinTools_ShapeSet.hxx>
#include <FSD_FileHeader.hxx>
#include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
#include <Storage_StreamTypeMismatchError.hxx>
//=======================================================================
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();
}
//=======================================================================
#include <OSD_FileSystem.hxx>
#include <OSD_Path.hxx>
-#include <OSD_OpenFile.hxx>
#include <TDocStd_PathParser.hxx>
#include <XmlLDrivers.hxx>
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
{
}
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;
{
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";
#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>
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;
}
#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>
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;
}
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;
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Image_Texture, Standard_Transient)
// ================================================================
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;
}
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 :
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 :
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;
//! 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,
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,
}
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;
+}
//! 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
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
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 :
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
//! 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,
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,
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 :
//! 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,
#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>
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;
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())
{
}
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;
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;
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())
{
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;
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())
{
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;
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())
{
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)
continue;
}
- myMaterialMap->AddGlbImages (aBinFile, aFaceIter.FaceStyle());
+ myMaterialMap->AddGlbImages (*aBinFile, aFaceIter.FaceStyle());
}
}
}
}
// 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;
}
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;
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.
}
}
- rapidjson::OStreamWrapper aFileStream (aGltfContentFile);
+ rapidjson::OStreamWrapper aFileStream (*aGltfContentFile);
myWriter.reset (new RWGltf_GltfOStreamWriter (aFileStream));
myWriter->StartObject();
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())
{
{
break;
}
- aGltfContentFile.write (aBuffer, aReadLen);
+ aGltfContentFile->write (aBuffer, aReadLen);
}
}
OSD_Path aBinFilePath (myBinFileNameFull);
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
#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>
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;
}
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;
#include <BinTObjDrivers.hxx>
#include <XmlTObjDrivers.hxx>
#include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
#include <stdio.h>
}
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) );
#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>
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;
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"
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
{
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;
}
}
- 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;
}
}
}
- 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"))
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"
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())
}
}
- 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
{
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;
}
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);
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;
}
#include <BRep_Tool.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
#include <OSD_Path.hxx>
#include <Poly_Triangulation.hxx>
#include <Quantity_HArray1OfColor.hxx>
{
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;
}
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,
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
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;
}
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;
}
#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>
{
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
{