0025689: IGESCAFControl_Writer crash in constructor.
[occt.git] / src / IGESControl / IGESControl_Writer.cxx
index 300d435..dcaca3a 100644 (file)
@@ -2,8 +2,8 @@
 //
 // This file is part of Open CASCADE Technology software library.
 //
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
 // by the Free Software Foundation, with special exception defined in the file
 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
 // distribution for complete text of the license and disclaimer of any warranty.
 #include <TopExp_Explorer.hxx>
 #include <Message_ProgressIndicator.hxx>
 #include <errno.h>
+#include <OSD_OpenFile.hxx>
 
 IGESControl_Writer::IGESControl_Writer ()
     :  theTP (new Transfer_FinderProcess(10000)) ,
-       thedit (IGESSelect_WorkLibrary::DefineProtocol()) ,
        thest (Standard_False)
 {
 //  faudrait aussi (?) prendre les parametres par defaut ... ?
   IGESControl_Controller::Init();
+  thedit.Init(IGESSelect_WorkLibrary::DefineProtocol());
   thedit.SetUnitName(Interface_Static::CVal ("write.iges.unit"));
   thedit.ApplyUnit(); 
   thecr = Interface_Static::IVal ("write.iges.brep.mode");
@@ -61,11 +62,11 @@ IGESControl_Writer::IGESControl_Writer ()
 IGESControl_Writer::IGESControl_Writer
   (const Standard_CString unit, const Standard_Integer modecr)
     :  theTP (new Transfer_FinderProcess(10000)) ,
-       thedit (IGESSelect_WorkLibrary::DefineProtocol()) ,
        thecr (modecr) , thest (Standard_False)
 {
 //  faudrait aussi (?) prendre les parametres par defaut ... ?
   IGESControl_Controller::Init();
+  thedit.Init(IGESSelect_WorkLibrary::DefineProtocol());
   thedit.SetUnitName(unit);
   thedit.ApplyUnit();
   themod = thedit.Model();
@@ -245,7 +246,7 @@ Standard_Boolean IGESControl_Writer::Write
   if (!S) return Standard_False;
   ComputeModel();
   Standard_Integer nbEnt = themod->NbEntities();
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
   cout<<" IGES Write : "<<nbEnt<<" ent.s"<< flush;
 #endif
   if(!nbEnt)
@@ -253,12 +254,12 @@ Standard_Boolean IGESControl_Writer::Write
   IGESData_IGESWriter IW (themod);
 //  ne pas oublier le mode fnes ... a transmettre a IW
   IW.SendModel (IGESSelect_WorkLibrary::DefineProtocol());
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
   cout<<" ...  ecriture  ..."<<flush;
 #endif
   if (fnes) IW.WriteMode() = 10;
   Standard_Boolean status = IW.Print(S);
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
   cout<<" ...  fichier ecrit  ..."<<endl;
 #endif
   return status;
@@ -267,9 +268,10 @@ Standard_Boolean IGESControl_Writer::Write
 Standard_Boolean IGESControl_Writer::Write
   (const Standard_CString file, const Standard_Boolean fnes)
 {
-  ofstream fout(file,ios::out);
+  ofstream fout;
+  OSD_OpenStream(fout,file,ios::out);
   if (!fout) return Standard_False;
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
   cout<<" Ecriture fichier ("<< (fnes ? "fnes" : "IGES") <<"): "<<file<<endl;
 #endif
   Standard_Boolean res = Write (fout,fnes);