Back to index

salome-geom  6.5.0
IGESExport.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:        IGESExport.cxx
00024 // Created:     Wed May 19 14:49:45 2004
00025 // Author:      Pavel TELKOV
00026 
00027 #include "utilities.h"
00028 
00029 #include <Basics_Utils.hxx>
00030 
00031 #include <IGESControl_Controller.hxx>
00032 #include <IGESControl_Writer.hxx>
00033 #include <Interface_Static.hxx>
00034 
00035 #include <TopoDS_Shape.hxx>
00036 #include <TopoDS_Iterator.hxx>
00037 
00038 #include <TCollection_AsciiString.hxx>
00039 
00040 #include <Standard_Failure.hxx>
00041 
00042 #ifdef WNT
00043  #if defined IGESEXPORT_EXPORTS || defined IGESExport_EXPORTS
00044   #if defined WIN32
00045    #define IGESEXPORT_EXPORT __declspec( dllexport )
00046   #else
00047    #define IGESEXPORT_EXPORT
00048   #endif
00049  #else
00050   #if defined WIN32
00051    #define IGESEXPORT_EXPORT __declspec( dllimport )
00052   #else
00053    #define IGESEXPORT_EXPORT
00054   #endif
00055  #endif
00056 #else
00057  #define IGESEXPORT_EXPORT
00058 #endif
00059 
00060 //=============================================================================
00069 //=============================================================================
00070 int KindOfBRep (const TopoDS_Shape& theShape)
00071 {
00072   int aKind = 2;
00073 
00074   switch (theShape.ShapeType())
00075   {
00076   case TopAbs_COMPOUND:
00077     {
00078       bool isSimple = false;
00079       bool isComplex = false;
00080       TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
00081       for (; anIt.More(); anIt.Next()) {
00082         TopoDS_Shape aS = anIt.Value();
00083         int aKindSub = KindOfBRep(aS);
00084         if (aKindSub == 0)
00085           isSimple = true;
00086         else if (aKindSub == 1)
00087           isComplex = true;
00088         else if (aKindSub == -1) {
00089           return -1; // heterogeneous
00090         }
00091       }
00092       if (isSimple && isComplex)
00093         aKind = -1; // heterogeneous
00094       else if (isSimple)
00095         aKind = 0;
00096       else if (isComplex)
00097         aKind = 1;
00098     }
00099     break;
00100   case TopAbs_COMPSOLID:
00101   case TopAbs_SOLID:
00102   case TopAbs_SHELL:
00103     aKind = 1;
00104     break;
00105   case TopAbs_WIRE:
00106   case TopAbs_EDGE:
00107   case TopAbs_VERTEX:
00108     aKind = 0;
00109     break;
00110   default:
00111     aKind = 2;
00112   }
00113 
00114   return aKind;
00115 }
00116 
00117 //=============================================================================
00121 //=============================================================================
00122 
00123 extern "C"
00124 {
00125 IGESEXPORT_EXPORT
00126   int Export( const TopoDS_Shape& theShape,
00127               const TCollection_AsciiString& theFileName,
00128               const TCollection_AsciiString& theFormatName )
00129   {
00130     bool ok = false;
00131 
00132     // define, whether to write only faces (5.1 IGES format)
00133     // or shells and solids also (5.3 IGES format)
00134     int aBrepMode = 0;
00135     if (theFormatName.IsEqual("IGES_5_3"))
00136       aBrepMode = 1;
00137 
00138     MESSAGE("Export IGES into file " << theFileName.ToCString());
00139 
00140     // Mantis issue 0021350: check being exported shape, as some standalone
00141     // entities (edges, wires and vertices) cannot be saved in BRepMode
00142     if (aBrepMode == 1) {
00143       int aKind = KindOfBRep(theShape);
00144       if (aKind == -1)
00145         Standard_Failure::Raise("EXPORT_IGES_HETEROGENEOUS_COMPOUND");
00146       else if (aKind == 2)
00147         aBrepMode = 1;
00148       else
00149         aBrepMode = aKind;
00150     }
00151 
00152     // commented for 0021350: Please don't catch exceptions silently and send an
00153     // inappropriate error message instead, it is disturbing for the user and for us
00154     //try
00155     {
00156       // Set "C" numeric locale to save numbers correctly
00157       Kernel_Utils::Localizer loc;
00158 
00159       // initialize writer
00160       IGESControl_Controller::Init();
00161       //IGESControl_Writer ICW (Interface_Static::CVal("write.iges.unit"),
00162       //                        Interface_Static::IVal("write.iges.brep.mode"));
00163       IGESControl_Writer ICW ("M", aBrepMode); // "write.iges.unit" ->> VSR 15.09.09: export explicitly in meters
00164       Interface_Static::SetCVal("xstep.cascade.unit","M");
00165 
00166       // 09.03.2010 skl for bug 0020726
00167       // change default value "Average" to "Max"
00168       Interface_Static::SetCVal("write.precision.mode","Max");
00169 
00170       // perform shape writing
00171       if (ICW.AddShape( theShape )) {
00172         ICW.ComputeModel();
00173         ok = ICW.Write( theFileName.ToCString() );
00174       }
00175     }
00176     //catch(Standard_Failure)
00177     //{
00178     //}
00179     return ok;
00180   }
00181 }