0030180: Data Exchange - VrmlAPI_Writer is expected to return export state
authormzernova <mzernova@opencascade.com>
Mon, 16 Sep 2019 10:44:02 +0000 (13:44 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 20 Sep 2019 16:39:27 +0000 (19:39 +0300)
The VrmlAPI_Writer::WriteDoc() and VrmlAPI_Writer::Write() methods now return the export state.

src/VrmlAPI/VrmlAPI.cxx
src/VrmlAPI/VrmlAPI.hxx
src/VrmlAPI/VrmlAPI_Writer.cxx
src/VrmlAPI/VrmlAPI_Writer.hxx
src/XDEDRAW/XDEDRAW_Common.cxx
src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx

index 2cd2158..03f378f 100644 (file)
@@ -18,7 +18,7 @@
 #include <VrmlAPI.hxx>
 #include <VrmlAPI_Writer.hxx>
 
 #include <VrmlAPI.hxx>
 #include <VrmlAPI_Writer.hxx>
 
-void VrmlAPI::Write(const TopoDS_Shape& aShape, const Standard_CString aFileName, const Standard_Integer aVersion)  {
+Standard_Boolean VrmlAPI::Write(const TopoDS_Shape& aShape, const Standard_CString aFileName, const Standard_Integer aVersion)  {
   VrmlAPI_Writer writer;
   VrmlAPI_Writer writer;
-  writer.Write(aShape, aFileName, aVersion);
+  return writer.Write(aShape, aFileName, aVersion);
 }
 }
index d362acd..ec12058 100644 (file)
@@ -37,7 +37,7 @@ public:
   //! With help of this class user can change parameters of writing.
   //! Converts the shape aShape to VRML format of the passed version and writes it
   //! to the file identified by aFileName using default parameters.
   //! With help of this class user can change parameters of writing.
   //! Converts the shape aShape to VRML format of the passed version and writes it
   //! to the file identified by aFileName using default parameters.
-  Standard_EXPORT static void Write (const TopoDS_Shape& aShape, const Standard_CString aFileName, const Standard_Integer aVersion = 2);
+  Standard_EXPORT static Standard_Boolean Write (const TopoDS_Shape& aShape, const Standard_CString aFileName, const Standard_Integer aVersion = 2);
 
 
 
 
 
 
index a61110f..523168c 100644 (file)
@@ -222,20 +222,26 @@ Handle(Vrml_Material) VrmlAPI_Writer::GetUnfreeBoundsMaterial() const
   return myUnfreeBoundsMaterial;
 }
 
   return myUnfreeBoundsMaterial;
 }
 
-void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFile, const Standard_Integer aVersion) const
+Standard_Boolean VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFile, const Standard_Integer aVersion) const
 {
   if (aVersion == 1)
 {
   if (aVersion == 1)
-    write_v1(aShape, aFile);
+    return write_v1 (aShape, aFile);
   else if (aVersion == 2)
   else if (aVersion == 2)
-    write_v2(aShape, aFile);
+    return write_v2 (aShape, aFile);
+
+  return Standard_False;
 }
 
 }
 
-void VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Standard_CString aFile) const
+Standard_Boolean VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Standard_CString aFile) const
 {
   OSD_Path thePath(aFile);
   TCollection_AsciiString theFile;thePath.SystemName(theFile);
   std::ofstream outfile;
   OSD_OpenStream(outfile, theFile.ToCString(), std::ios::out);
 {
   OSD_Path thePath(aFile);
   TCollection_AsciiString theFile;thePath.SystemName(theFile);
   std::ofstream outfile;
   OSD_OpenStream(outfile, theFile.ToCString(), std::ios::out);
+  if (!outfile)
+  {
+    return Standard_False;
+  }
   Handle(VrmlConverter_IsoAspect) ia = new VrmlConverter_IsoAspect;  // UIso
   Handle(VrmlConverter_IsoAspect) ia1 = new VrmlConverter_IsoAspect; //VIso
   ia->SetMaterial(myUisoMaterial);
   Handle(VrmlConverter_IsoAspect) ia = new VrmlConverter_IsoAspect;  // UIso
   Handle(VrmlConverter_IsoAspect) ia1 = new VrmlConverter_IsoAspect; //VIso
   ia->SetMaterial(myUisoMaterial);
@@ -352,18 +358,21 @@ void VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Standard_CString
       VrmlConverter_WFDeflectionShape::Add(outfile,aShape,myDrawer);
       Group2.Print(outfile);
     }
       VrmlConverter_WFDeflectionShape::Add(outfile,aShape,myDrawer);
       Group2.Print(outfile);
     }
-  S2.Print(outfile); 
-  S1.Print(outfile); 
+  S2.Print(outfile);
+  S1.Print(outfile);
+
+  outfile.close();
+  return outfile.good();
 }
 
 }
 
-void VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Standard_CString aFile) const
+Standard_Boolean VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Standard_CString aFile) const
 {
   Standard_Boolean anExtFace = Standard_False;
   if(myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation) 
     anExtFace = Standard_True;
 
   Standard_Boolean anExtEdge = Standard_False;
 {
   Standard_Boolean anExtFace = Standard_False;
   if(myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation) 
     anExtFace = Standard_True;
 
   Standard_Boolean anExtEdge = Standard_False;
-  if(myRepresentation == VrmlAPI_WireFrameRepresentation|| myRepresentation == VrmlAPI_BothRepresentation)
+  if(myRepresentation == VrmlAPI_WireFrameRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
     anExtEdge = Standard_True;
 
   VrmlData_Scene aScene;
     anExtEdge = Standard_True;
 
   VrmlData_Scene aScene;
@@ -373,17 +382,21 @@ void VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Standard_CString
 
   std::ofstream anOutStream;
   OSD_OpenStream(anOutStream, aFile, std::ios::out);
 
   std::ofstream anOutStream;
   OSD_OpenStream(anOutStream, aFile, std::ios::out);
-  if (!anOutStream.fail())
+  if (anOutStream)
   {
   {
-      anOutStream << aScene;
+    anOutStream << aScene;
+    anOutStream.close();
+    return anOutStream.good();
   }
   }
+
+  return Standard_False;
 }
 
 //=======================================================================
 //function : WriteDoc
 //purpose  : 
 //=======================================================================
 }
 
 //=======================================================================
 //function : WriteDoc
 //purpose  : 
 //=======================================================================
-void VrmlAPI_Writer::WriteDoc(
+Standard_Boolean VrmlAPI_Writer::WriteDoc(
   const Handle(TDocStd_Document) &theDoc,
   const Standard_CString theFile,
   const Standard_Real theScale) const
   const Handle(TDocStd_Document) &theDoc,
   const Standard_CString theFile,
   const Standard_Real theScale) const
@@ -394,9 +407,13 @@ void VrmlAPI_Writer::WriteDoc(
 
   std::ofstream anOutStream;
   OSD_OpenStream(anOutStream, theFile, std::ios::out);
 
   std::ofstream anOutStream;
   OSD_OpenStream(anOutStream, theFile, std::ios::out);
-  if (!anOutStream.fail())
+  if (anOutStream)
   {
   {
-      anOutStream << aScene;
+    anOutStream << aScene;
+    anOutStream.close();
+    return anOutStream.good();
   }
   }
+
+  return Standard_False;
 }
 
 }
 
index 4d77a86..46a23cf 100644 (file)
@@ -105,12 +105,12 @@ public:
   
   //! Converts the shape aShape to
   //! VRML format of the passed version and writes it to the file identified by aFile.
   
   //! Converts the shape aShape to
   //! VRML format of the passed version and writes it to the file identified by aFile.
-  Standard_EXPORT void Write (const TopoDS_Shape& aShape, const Standard_CString aFile,
+  Standard_EXPORT Standard_Boolean Write (const TopoDS_Shape& aShape, const Standard_CString aFile,
       const Standard_Integer aVersion = 2) const;
 
   //! Converts the document to VRML format of the passed version
   //! and writes it to the file identified by aFile.
       const Standard_Integer aVersion = 2) const;
 
   //! Converts the document to VRML format of the passed version
   //! and writes it to the file identified by aFile.
-  Standard_EXPORT void WriteDoc(
+  Standard_EXPORT Standard_Boolean WriteDoc(
     const Handle(TDocStd_Document) &theDoc,
     const Standard_CString theFile,
     const Standard_Real theScale) const;
     const Handle(TDocStd_Document) &theDoc,
     const Standard_CString theFile,
     const Standard_Real theScale) const;
@@ -119,11 +119,11 @@ protected:
 
   //! Converts the shape aShape to VRML format of version 1.0 and writes it
   //! to the file identified by aFileName using default parameters.
 
   //! Converts the shape aShape to VRML format of version 1.0 and writes it
   //! to the file identified by aFileName using default parameters.
-  Standard_EXPORT void write_v1 (const TopoDS_Shape& aShape, const Standard_CString aFileName) const;
+  Standard_EXPORT Standard_Boolean write_v1 (const TopoDS_Shape& aShape, const Standard_CString aFileName) const;
   
   //! Converts the shape aShape to VRML format of version 2.0 and writes it
   //! to the file identified by aFileName using default parameters.
   
   //! Converts the shape aShape to VRML format of version 2.0 and writes it
   //! to the file identified by aFileName using default parameters.
-  Standard_EXPORT void write_v2 (const TopoDS_Shape& aShape, const Standard_CString aFileName) const;
+  Standard_EXPORT Standard_Boolean write_v2 (const TopoDS_Shape& aShape, const Standard_CString aFileName) const;
 
 private:
 
 
 private:
 
index 98eaa4d..07d71d1 100644 (file)
@@ -597,7 +597,10 @@ static Standard_Integer WriteVrml(Draw_Interpretor& di, Standard_Integer argc, c
   Standard_Real anOCCLengthUnit =
       UnitsMethods::GetLengthFactorValue(Interface_Static::IVal("xstep.cascade.unit"));
   Standard_Real aScale = 0.001*anOCCLengthUnit;
   Standard_Real anOCCLengthUnit =
       UnitsMethods::GetLengthFactorValue(Interface_Static::IVal("xstep.cascade.unit"));
   Standard_Real aScale = 0.001*anOCCLengthUnit;
-  writer.WriteDoc(aDoc, argv[2], aScale);
+  if (!writer.WriteDoc(aDoc, argv[2], aScale))
+  {
+    di << "Error: File " << argv[2] << " was not written\n";
+  }
 
   return 0;
 }
 
   return 0;
 }
index eee2583..cf86dc0 100644 (file)
@@ -532,7 +532,10 @@ static Standard_Integer writevrml
   case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break;
   }
 
   case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break;
   }
 
-  writer.Write(aShape, argv[2], aVersion);
+  if (!writer.Write(aShape, argv[2], aVersion))
+  {
+    di << "Error: File " << argv[2] << " was not written\n";
+  }
 
   return 0;
 }
 
   return 0;
 }