3 #include "GEOMImpl_ExportDriver.hxx"
4 #include "GEOMImpl_IImportExport.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <TopoDS_Shape.hxx>
9 #include <TCollection_AsciiString.hxx>
11 #include <Standard_ConstructionError.hxx>
20 #define LibHandle HMODULE
21 #define LoadLib( name ) LoadLibrary( name )
22 #define GetProc GetProcAddress
23 #define UnLoadLib( handle ) FreeLibrary( handle );
25 #define LibHandle void*
26 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
28 #define UnLoadLib( handle ) dlclose( handle );
31 typedef int (*funcPoint)(const TopoDS_Shape&, const TCollection_AsciiString&);
33 //=======================================================================
36 //=======================================================================
37 const Standard_GUID& GEOMImpl_ExportDriver::GetID()
39 static Standard_GUID aExportDriver("FF1BBB58-5D14-4df2-980B-3A668264EA16");
44 //=======================================================================
45 //function : GEOMImpl_ExportDriver
47 //=======================================================================
48 GEOMImpl_ExportDriver::GEOMImpl_ExportDriver()
52 //=======================================================================
55 //=======================================================================
56 Standard_Integer GEOMImpl_ExportDriver::Execute(TFunction_Logbook& log) const
58 if (Label().IsNull()) return 0;
59 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
61 GEOMImpl_IImportExport aCI (aFunction);
63 // retrieve the being exported shape
65 Handle(GEOM_Function) aRefFunction = aCI.GetOriginal();
66 if (aRefFunction.IsNull()) return 0;
67 aShape = aRefFunction->GetValue();
68 if (aShape.IsNull()) return 0;
69 // !!! set the result of function to be used by next operations
70 aFunction->SetValue(aShape);
72 // retrieve the file and format names
73 TCollection_AsciiString aFileName = aCI.GetFileName();
74 TCollection_AsciiString aLibName = aCI.GetPluginName();
75 if (aFileName.IsEmpty() || aLibName.IsEmpty())
78 // load plugin library
79 LibHandle anExportLib = LoadLib( aLibName.ToCString() );
82 fp = (funcPoint)GetProc( anExportLib, "Export" );
88 int res = fp( aShape, aFileName );
90 // unload plugin library
91 UnLoadLib( anExportLib );
93 log.SetTouched(Label());
99 //=======================================================================
100 //function : GEOMImpl_ExportDriver_Type_
102 //=======================================================================
103 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ExportDriver_Type_()
106 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
107 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
108 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
109 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
110 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
111 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
114 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
115 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ExportDriver",
116 sizeof(GEOMImpl_ExportDriver),
118 (Standard_Address)_Ancestors,
119 (Standard_Address)NULL);
124 //=======================================================================
125 //function : DownCast
127 //=======================================================================
128 const Handle(GEOMImpl_ExportDriver) Handle(GEOMImpl_ExportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
130 Handle(GEOMImpl_ExportDriver) _anOtherObject;
132 if (!AnObject.IsNull()) {
133 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ExportDriver))) {
134 _anOtherObject = Handle(GEOMImpl_ExportDriver)((Handle(GEOMImpl_ExportDriver)&)AnObject);
138 return _anOtherObject ;