Salome HOME
PAL17233: Projection 2D doesn't work (bis)
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ExportDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_ExportDriver.hxx>
24 #include <GEOMImpl_IImportExport.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <TopoDS_Shape.hxx>
29 #include <TCollection_AsciiString.hxx>
30
31 #include <Standard_ConstructionError.hxx>
32
33 #include <NCollection_DataMap.hxx>
34
35 #ifdef WNT
36 #include <windows.h>
37 #else
38 #include <dlfcn.h>
39 #endif
40
41 #ifdef WNT
42 #define LibHandle HMODULE
43 #define LoadLib( name ) LoadLibrary( name )
44 #define GetProc GetProcAddress
45 #define UnLoadLib( handle ) FreeLibrary( handle );
46 #else
47 #define LibHandle void*
48 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
49 #define GetProc dlsym
50 #define UnLoadLib( handle ) dlclose( handle );
51 #endif
52
53 typedef int (*funcPoint)(const TopoDS_Shape&,
54                          const TCollection_AsciiString&,
55                          const TCollection_AsciiString&);
56
57 //=======================================================================
58 //function : GetID
59 //purpose  :
60 //======================================================================= 
61 const Standard_GUID& GEOMImpl_ExportDriver::GetID()
62 {
63   static Standard_GUID aExportDriver("FF1BBB58-5D14-4df2-980B-3A668264EA16");
64   return aExportDriver; 
65 }
66
67
68 //=======================================================================
69 //function : GEOMImpl_ExportDriver
70 //purpose  : 
71 //=======================================================================
72 GEOMImpl_ExportDriver::GEOMImpl_ExportDriver() 
73 {
74 }
75
76 //=======================================================================
77 //function : Execute
78 //purpose  :
79 //======================================================================= 
80 Standard_Integer GEOMImpl_ExportDriver::Execute(TFunction_Logbook& log) const
81 {
82   if (Label().IsNull()) return 0;    
83   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
84
85   GEOMImpl_IImportExport aCI (aFunction);
86
87   // retrieve the being exported shape
88   TopoDS_Shape aShape;
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);
95
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())
101     return 0;
102
103   // load plugin library
104   LibHandle anExportLib = LoadLib( aLibName.ToCString() ); //This is workaround of BUG OCC13051
105   funcPoint fp = 0;
106   if ( anExportLib )
107     fp = (funcPoint)GetProc( anExportLib, "Export" );
108
109   if ( !fp )
110     return 0;
111
112   // perform the export
113   int res = fp( aShape, aFileName, aFormatName );
114
115   // unload plugin library
116   // commented by enk:
117   // the bug was occured: using ACIS Import/Export plugin
118   // UnLoadLib( anExportLib );
119
120   if ( res )
121     log.SetTouched(Label()); 
122
123   return res;
124 }
125
126
127 //=======================================================================
128 //function :  GEOMImpl_ExportDriver_Type_
129 //purpose  :
130 //======================================================================= 
131 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ExportDriver_Type_()
132 {
133
134   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
135   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
136   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
137   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
138   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
139   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
140  
141
142   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
143   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ExportDriver",
144                                                          sizeof(GEOMImpl_ExportDriver),
145                                                          1,
146                                                          (Standard_Address)_Ancestors,
147                                                          (Standard_Address)NULL);
148
149   return _aType;
150 }
151
152 //=======================================================================
153 //function : DownCast
154 //purpose  :
155 //======================================================================= 
156 const Handle(GEOMImpl_ExportDriver) Handle(GEOMImpl_ExportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
157 {
158   Handle(GEOMImpl_ExportDriver) _anOtherObject;
159
160   if (!AnObject.IsNull()) {
161      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ExportDriver))) {
162        _anOtherObject = Handle(GEOMImpl_ExportDriver)((Handle(GEOMImpl_ExportDriver)&)AnObject);
163      }
164   }
165
166   return _anOtherObject ;
167 }