3 #include "GEOMImpl_ImportDriver.hxx"
4 #include "GEOMImpl_IImportExport.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
10 #include <TopoDS_Shape.hxx>
12 #include <Standard_ConstructionError.hxx>
13 #include <StdFail_NotDone.hxx>
22 #define LibHandle HMODULE
23 #define LoadLib( name ) LoadLibrary( name )
24 #define GetProc GetProcAddress
25 #define UnLoadLib( handle ) FreeLibrary( handle );
27 #define LibHandle void*
28 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
30 #define UnLoadLib( handle ) dlclose( handle );
33 typedef TopoDS_Shape (*funcPoint)(const TCollection_AsciiString&, TCollection_AsciiString&);
35 //=======================================================================
38 //=======================================================================
39 const Standard_GUID& GEOMImpl_ImportDriver::GetID()
41 static Standard_GUID aImportDriver("FF1BBB60-5D14-4df2-980B-3A668264EA16");
46 //=======================================================================
47 //function : GEOMImpl_ImportDriver
49 //=======================================================================
50 GEOMImpl_ImportDriver::GEOMImpl_ImportDriver()
54 //=======================================================================
57 //=======================================================================
58 Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const
60 if (Label().IsNull()) return 0;
61 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
63 GEOMImpl_IImportExport aCI (aFunction);
64 //Standard_Integer aType = aFunction->GetType();
66 // retrieve the file and plugin library names
67 TCollection_AsciiString aFileName = aCI.GetFileName();
68 TCollection_AsciiString aLibName = aCI.GetPluginName();
69 if (aFileName.IsEmpty() || aLibName.IsEmpty())
72 // load plugin library
73 LibHandle anImportLib = LoadLib( aLibName.ToCString() );
76 fp = (funcPoint)GetProc( anImportLib, "Import" );
82 TCollection_AsciiString anError;
83 TopoDS_Shape aShape = fp( aFileName, anError );
85 // unload plugin library
86 UnLoadLib( anImportLib );
88 if ( aShape.IsNull() ) {
89 StdFail_NotDone::Raise(anError.ToCString());
93 // set the function result
94 aFunction->SetValue(aShape);
96 log.SetTouched(Label());
102 //=======================================================================
103 //function : GEOMImpl_ImportDriver_Type_
105 //=======================================================================
106 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ImportDriver_Type_()
109 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
110 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
111 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
112 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
113 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
114 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
117 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
118 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ImportDriver",
119 sizeof(GEOMImpl_ImportDriver),
121 (Standard_Address)_Ancestors,
122 (Standard_Address)NULL);
127 //=======================================================================
128 //function : DownCast
130 //=======================================================================
131 const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
133 Handle(GEOMImpl_ImportDriver) _anOtherObject;
135 if (!AnObject.IsNull()) {
136 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ImportDriver))) {
137 _anOtherObject = Handle(GEOMImpl_ImportDriver)((Handle(GEOMImpl_ImportDriver)&)AnObject);
141 return _anOtherObject ;