1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_ImportDriver.hxx>
24 #include <GEOMImpl_IImportExport.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include "utilities.h"
30 #include <TopoDS_Shape.hxx>
32 #include <Standard_ConstructionError.hxx>
33 #include <StdFail_NotDone.hxx>
42 #define LibHandle HMODULE
43 #define LoadLib( name ) LoadLibrary( name )
44 #define GetProc GetProcAddress
45 #define UnLoadLib( handle ) FreeLibrary( handle );
47 #define LibHandle void*
48 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
50 #define UnLoadLib( handle ) dlclose( handle );
53 typedef TopoDS_Shape (*funcPoint)(const TCollection_AsciiString&, TCollection_AsciiString&);
55 //=======================================================================
58 //=======================================================================
59 const Standard_GUID& GEOMImpl_ImportDriver::GetID()
61 static Standard_GUID aImportDriver("FF1BBB60-5D14-4df2-980B-3A668264EA16");
66 //=======================================================================
67 //function : GEOMImpl_ImportDriver
69 //=======================================================================
70 GEOMImpl_ImportDriver::GEOMImpl_ImportDriver()
74 //=======================================================================
77 //=======================================================================
78 Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const
80 if (Label().IsNull()) return 0;
81 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
83 GEOMImpl_IImportExport aCI (aFunction);
84 //Standard_Integer aType = aFunction->GetType();
86 // retrieve the file and plugin library names
87 TCollection_AsciiString aFileName = aCI.GetFileName();
88 TCollection_AsciiString aLibName = aCI.GetPluginName();
89 if (aFileName.IsEmpty() || aLibName.IsEmpty())
92 // load plugin library
93 LibHandle anImportLib = LoadLib( aLibName.ToCString() );
96 fp = (funcPoint)GetProc( anImportLib, "Import" );
101 // perform the import
102 TCollection_AsciiString anError;
103 TopoDS_Shape aShape = fp( aFileName, anError );
105 // unload plugin library
106 UnLoadLib( anImportLib );
108 if ( aShape.IsNull() ) {
109 StdFail_NotDone::Raise(anError.ToCString());
113 // set the function result
114 aFunction->SetValue(aShape);
116 log.SetTouched(Label());
122 //=======================================================================
123 //function : GEOMImpl_ImportDriver_Type_
125 //=======================================================================
126 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ImportDriver_Type_()
129 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
130 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
131 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
132 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
133 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
134 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
137 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
138 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ImportDriver",
139 sizeof(GEOMImpl_ImportDriver),
141 (Standard_Address)_Ancestors,
142 (Standard_Address)NULL);
147 //=======================================================================
148 //function : DownCast
150 //=======================================================================
151 const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
153 Handle(GEOMImpl_ImportDriver) _anOtherObject;
155 if (!AnObject.IsNull()) {
156 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ImportDriver))) {
157 _anOtherObject = Handle(GEOMImpl_ImportDriver)((Handle(GEOMImpl_ImportDriver)&)AnObject);
161 return _anOtherObject ;