Back to index

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