Back to index

salome-geom  6.5.0
GEOMImpl_ExportDriver.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 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_ExportDriver.hxx>
00026 #include <GEOMImpl_IImportExport.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <TopoDS_Shape.hxx>
00031 #include <TCollection_AsciiString.hxx>
00032 
00033 #include <Standard_Failure.hxx>
00034 
00035 #ifdef WNT
00036 #include <windows.h>
00037 #else
00038 #include <dlfcn.h>
00039 #endif
00040 
00041 #ifdef WNT
00042 #define LibHandle HMODULE
00043 #define LoadLib( name ) LoadLibrary( name )
00044 #define GetProc GetProcAddress
00045 #define UnLoadLib( handle ) FreeLibrary( handle );
00046 #else
00047 #define LibHandle void*
00048 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
00049 #define GetProc dlsym
00050 #define UnLoadLib( handle ) dlclose( handle );
00051 #endif
00052 
00053 typedef int (*funcPoint)(const TopoDS_Shape&,
00054                          const TCollection_AsciiString&,
00055                          const TCollection_AsciiString&);
00056 
00057 //=======================================================================
00058 //function : GetID
00059 //purpose  :
00060 //======================================================================= 
00061 const Standard_GUID& GEOMImpl_ExportDriver::GetID()
00062 {
00063   static Standard_GUID aExportDriver("FF1BBB58-5D14-4df2-980B-3A668264EA16");
00064   return aExportDriver; 
00065 }
00066 
00067 
00068 //=======================================================================
00069 //function : GEOMImpl_ExportDriver
00070 //purpose  : 
00071 //=======================================================================
00072 GEOMImpl_ExportDriver::GEOMImpl_ExportDriver() 
00073 {
00074 }
00075 
00076 //=======================================================================
00077 //function : Execute
00078 //purpose  :
00079 //======================================================================= 
00080 Standard_Integer GEOMImpl_ExportDriver::Execute(TFunction_Logbook& log) const
00081 {
00082   if (Label().IsNull()) return 0;    
00083   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00084 
00085   GEOMImpl_IImportExport aCI (aFunction);
00086 
00087   // retrieve the being exported shape
00088   TopoDS_Shape aShape;
00089   Handle(GEOM_Function) aRefFunction = aCI.GetOriginal();
00090   if (aRefFunction.IsNull()) return 0;
00091   aShape = aRefFunction->GetValue();
00092   if (aShape.IsNull()) return 0;
00093   // !!! set the result of function to be used by next operations
00094   aFunction->SetValue(aShape);
00095 
00096   // retrieve the file and format names
00097   TCollection_AsciiString aFileName   = aCI.GetFileName();
00098   TCollection_AsciiString aFormatName = aCI.GetFormatName();
00099   TCollection_AsciiString aLibName    = aCI.GetPluginName();
00100   if (aFileName.IsEmpty() || aFormatName.IsEmpty() || aLibName.IsEmpty())
00101     return 0;
00102 
00103   // load plugin library
00104   LibHandle anExportLib = LoadLib( aLibName.ToCString() ); //This is workaround of BUG OCC13051
00105   funcPoint fp = 0;
00106   if ( anExportLib )
00107     fp = (funcPoint)GetProc( anExportLib, "Export" );
00108 
00109   if ( !fp ) {
00110     TCollection_AsciiString aMsg = aFormatName;
00111     aMsg += " plugin was not installed";
00112     Standard_Failure::Raise(aMsg.ToCString());
00113   }
00114 
00115   // perform the export
00116   int res = fp( aShape, aFileName, aFormatName );
00117 
00118   // unload plugin library
00119   // commented by enk:
00120   // the bug was occured: using ACIS Import/Export plugin
00121   // UnLoadLib( anExportLib );
00122 
00123   if ( res )
00124     log.SetTouched(Label()); 
00125 
00126   return res;
00127 }
00128 
00129 
00130 //=======================================================================
00131 //function :  GEOMImpl_ExportDriver_Type_
00132 //purpose  :
00133 //======================================================================= 
00134 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ExportDriver_Type_()
00135 {
00136 
00137   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00138   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00139   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00140   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
00141   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00142   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00143  
00144 
00145   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00146   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ExportDriver",
00147                                                          sizeof(GEOMImpl_ExportDriver),
00148                                                          1,
00149                                                          (Standard_Address)_Ancestors,
00150                                                          (Standard_Address)NULL);
00151 
00152   return _aType;
00153 }
00154 
00155 //=======================================================================
00156 //function : DownCast
00157 //purpose  :
00158 //======================================================================= 
00159 const Handle(GEOMImpl_ExportDriver) Handle(GEOMImpl_ExportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00160 {
00161   Handle(GEOMImpl_ExportDriver) _anOtherObject;
00162 
00163   if (!AnObject.IsNull()) {
00164      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ExportDriver))) {
00165        _anOtherObject = Handle(GEOMImpl_ExportDriver)((Handle(GEOMImpl_ExportDriver)&)AnObject);
00166      }
00167   }
00168 
00169   return _anOtherObject ;
00170 }