]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_ImportDriver.cxx
Salome HOME
if a shape to be rotated is a vertex, and it is located ON the Revolution Axis, then...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ImportDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_ImportDriver.hxx"
4 #include "GEOMImpl_IImportExport.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include "utilities.h"
9
10 #include <TopoDS_Shape.hxx>
11
12 #include <Standard_ConstructionError.hxx>
13 #include <StdFail_NotDone.hxx>
14
15 #ifdef WNT
16 #include <windows.h>
17 #else
18 #include <dlfcn.h>
19 #endif
20
21 #ifdef WNT
22 #define LibHandle HMODULE
23 #define LoadLib( name ) LoadLibrary( name )
24 #define GetProc GetProcAddress
25 #define UnLoadLib( handle ) FreeLibrary( handle );
26 #else
27 #define LibHandle void*
28 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
29 #define GetProc dlsym
30 #define UnLoadLib( handle ) dlclose( handle );
31 #endif
32
33 typedef TopoDS_Shape (*funcPoint)(const TCollection_AsciiString&, TCollection_AsciiString&);
34
35 //=======================================================================
36 //function : GetID
37 //purpose  :
38 //=======================================================================
39 const Standard_GUID& GEOMImpl_ImportDriver::GetID()
40 {
41   static Standard_GUID aImportDriver("FF1BBB60-5D14-4df2-980B-3A668264EA16");
42   return aImportDriver;
43 }
44
45
46 //=======================================================================
47 //function : GEOMImpl_ImportDriver
48 //purpose  :
49 //=======================================================================
50 GEOMImpl_ImportDriver::GEOMImpl_ImportDriver()
51 {
52 }
53
54 //=======================================================================
55 //function : Execute
56 //purpose  :
57 //=======================================================================
58 Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const
59 {
60   if (Label().IsNull()) return 0;
61   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
62
63   GEOMImpl_IImportExport aCI (aFunction);
64   //Standard_Integer aType = aFunction->GetType();
65
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())
70     return 0;
71
72   // load plugin library
73   LibHandle anImportLib = LoadLib( aLibName.ToCString() );
74   funcPoint fp = 0;
75   if ( anImportLib )
76     fp = (funcPoint)GetProc( anImportLib, "Import" );
77
78   if ( !fp )
79     return 0;
80
81   // perform the import
82   TCollection_AsciiString anError;
83   TopoDS_Shape aShape = fp( aFileName, anError );
84
85   // unload plugin library
86   UnLoadLib( anImportLib );
87
88   if ( aShape.IsNull() ) {
89     StdFail_NotDone::Raise(anError.ToCString());
90     return 0;
91   }
92
93   // set the function result
94   aFunction->SetValue(aShape);
95
96   log.SetTouched(Label());
97
98   return 1;
99 }
100
101
102 //=======================================================================
103 //function :  GEOMImpl_ImportDriver_Type_
104 //purpose  :
105 //=======================================================================
106 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ImportDriver_Type_()
107 {
108
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);
115
116
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),
120                                                          1,
121                                                          (Standard_Address)_Ancestors,
122                                                          (Standard_Address)NULL);
123
124   return _aType;
125 }
126
127 //=======================================================================
128 //function : DownCast
129 //purpose  :
130 //=======================================================================
131 const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
132 {
133   Handle(GEOMImpl_ImportDriver) _anOtherObject;
134
135   if (!AnObject.IsNull()) {
136      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ImportDriver))) {
137        _anOtherObject = Handle(GEOMImpl_ImportDriver)((Handle(GEOMImpl_ImportDriver)&)AnObject);
138      }
139   }
140
141   return _anOtherObject ;
142 }