1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_ExportDriver.hxx>
26 #include <GEOMImpl_IImportExport.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TCollection_AsciiString.hxx>
33 #include <Standard_Failure.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 int (*funcPoint)(const TopoDS_Shape&,
54 const TCollection_AsciiString&,
55 const TCollection_AsciiString&);
57 //=======================================================================
60 //=======================================================================
61 const Standard_GUID& GEOMImpl_ExportDriver::GetID()
63 static Standard_GUID aExportDriver("FF1BBB58-5D14-4df2-980B-3A668264EA16");
68 //=======================================================================
69 //function : GEOMImpl_ExportDriver
71 //=======================================================================
72 GEOMImpl_ExportDriver::GEOMImpl_ExportDriver()
76 //=======================================================================
79 //=======================================================================
80 Standard_Integer GEOMImpl_ExportDriver::Execute(TFunction_Logbook& log) const
82 if (Label().IsNull()) return 0;
83 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
85 GEOMImpl_IImportExport aCI (aFunction);
87 // retrieve the being exported shape
89 Handle(GEOM_Function) aRefFunction = aCI.GetOriginal();
90 if (aRefFunction.IsNull()) return 0;
91 aShape = aRefFunction->GetValue();
92 if (aShape.IsNull()) return 0;
93 // !!! set the result of function to be used by next operations
94 aFunction->SetValue(aShape);
96 // retrieve the file and format names
97 TCollection_AsciiString aFileName = aCI.GetFileName();
98 TCollection_AsciiString aFormatName = aCI.GetFormatName();
99 TCollection_AsciiString aLibName = aCI.GetPluginName();
100 if (aFileName.IsEmpty() || aFormatName.IsEmpty() || aLibName.IsEmpty())
103 // load plugin library
104 LibHandle anExportLib = LoadLib( aLibName.ToCString() ); //This is workaround of BUG OCC13051
107 fp = (funcPoint)GetProc( anExportLib, "Export" );
110 TCollection_AsciiString aMsg = aFormatName;
111 aMsg += " plugin was not installed";
112 Standard_Failure::Raise(aMsg.ToCString());
115 // perform the export
116 int res = fp( aShape, aFileName, aFormatName );
118 // unload plugin library
120 // the bug was occured: using ACIS Import/Export plugin
121 // UnLoadLib( anExportLib );
124 log.SetTouched(Label());
130 //=======================================================================
131 //function : GEOMImpl_ExportDriver_Type_
133 //=======================================================================
134 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ExportDriver_Type_()
137 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
138 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
139 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
140 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
141 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
142 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
145 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
146 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ExportDriver",
147 sizeof(GEOMImpl_ExportDriver),
149 (Standard_Address)_Ancestors,
150 (Standard_Address)NULL);
155 //=======================================================================
156 //function : DownCast
158 //=======================================================================
159 const Handle(GEOMImpl_ExportDriver) Handle(GEOMImpl_ExportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
161 Handle(GEOMImpl_ExportDriver) _anOtherObject;
163 if (!AnObject.IsNull()) {
164 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ExportDriver))) {
165 _anOtherObject = Handle(GEOMImpl_ExportDriver)((Handle(GEOMImpl_ExportDriver)&)AnObject);
169 return _anOtherObject ;