2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_ExportDriver.hxx>
5 #include <GEOMImpl_IImportExport.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <TopoDS_Shape.hxx>
10 #include <TCollection_AsciiString.hxx>
12 #include <Standard_ConstructionError.hxx>
21 #define LibHandle HMODULE
22 #define LoadLib( name ) LoadLibrary( name )
23 #define GetProc GetProcAddress
24 #define UnLoadLib( handle ) FreeLibrary( handle );
26 #define LibHandle void*
27 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
29 #define UnLoadLib( handle ) dlclose( handle );
32 typedef int (*funcPoint)(const TopoDS_Shape&, const TCollection_AsciiString&);
34 //=======================================================================
37 //=======================================================================
38 const Standard_GUID& GEOMImpl_ExportDriver::GetID()
40 static Standard_GUID aExportDriver("FF1BBB58-5D14-4df2-980B-3A668264EA16");
45 //=======================================================================
46 //function : GEOMImpl_ExportDriver
48 //=======================================================================
49 GEOMImpl_ExportDriver::GEOMImpl_ExportDriver()
53 //=======================================================================
56 //=======================================================================
57 Standard_Integer GEOMImpl_ExportDriver::Execute(TFunction_Logbook& log) const
59 if (Label().IsNull()) return 0;
60 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
62 GEOMImpl_IImportExport aCI (aFunction);
64 // retrieve the being exported shape
66 Handle(GEOM_Function) aRefFunction = aCI.GetOriginal();
67 if (aRefFunction.IsNull()) return 0;
68 aShape = aRefFunction->GetValue();
69 if (aShape.IsNull()) return 0;
70 // !!! set the result of function to be used by next operations
71 aFunction->SetValue(aShape);
73 // retrieve the file and format names
74 TCollection_AsciiString aFileName = aCI.GetFileName();
75 TCollection_AsciiString aLibName = aCI.GetPluginName();
76 if (aFileName.IsEmpty() || aLibName.IsEmpty())
79 // load plugin library
80 LibHandle anExportLib = LoadLib( aLibName.ToCString() );
83 fp = (funcPoint)GetProc( anExportLib, "Export" );
89 int res = fp( aShape, aFileName );
91 // unload plugin library
92 UnLoadLib( anExportLib );
94 log.SetTouched(Label());
100 //=======================================================================
101 //function : GEOMImpl_ExportDriver_Type_
103 //=======================================================================
104 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ExportDriver_Type_()
107 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
108 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
109 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
110 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
111 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
112 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
115 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
116 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ExportDriver",
117 sizeof(GEOMImpl_ExportDriver),
119 (Standard_Address)_Ancestors,
120 (Standard_Address)NULL);
125 //=======================================================================
126 //function : DownCast
128 //=======================================================================
129 const Handle(GEOMImpl_ExportDriver) Handle(GEOMImpl_ExportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
131 Handle(GEOMImpl_ExportDriver) _anOtherObject;
133 if (!AnObject.IsNull()) {
134 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ExportDriver))) {
135 _anOtherObject = Handle(GEOMImpl_ExportDriver)((Handle(GEOMImpl_ExportDriver)&)AnObject);
139 return _anOtherObject ;