Salome HOME
Merge from BR_PARAVIS_LOT1_2 24/02/2010
[modules/paravis.git] / src / ENGINE / PARAVIS_Engine_i.cc
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "PARAVIS_Engine_i.hh"
23 #include "utilities.h"
24
25
26 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
27
28 #include "SALOME_NamingService.hxx"
29 #include "Utils_ExceptHandlers.hxx"
30
31 using namespace std;
32
33 #ifdef _DEBUG_
34 static int MYDEBUG = 1;
35 #else
36 static int MYDEBUG = 0;
37 #endif
38
39 #ifdef WNT
40 #if defined PARAVIS_ENGINE_EXPORTS || defined PARAVISEngine_EXPORTS
41 #define PARAVIS_ENGINE_EXPORT __declspec(dllexport)
42 #else
43 #define PARAVIS_ENGINE_EXPORT __declspec(dllimport)
44 #endif
45 #else
46 #define PARAVIS_ENGINE_EXPORT
47 #endif
48
49 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
50
51 extern "C" {
52 PARAVIS_ENGINE_EXPORT PortableServer::ObjectId* PARAVISEngine_factory(CORBA::ORB_ptr orb, 
53                                                                       PortableServer::POA_ptr poa, 
54                                                                       PortableServer::ObjectId * contId,
55                                                                       const char *instanceName, 
56                                                                       const char *interfaceName) 
57 {
58   MESSAGE("PARAVISEngine_factory : "<<interfaceName);
59   SALOME_NamingService aNamingService(orb);
60   CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session");
61   SALOME::Session_var aSession = SALOME::Session::_narrow(anObject);
62   if (CORBA::is_nil(aSession))
63     return NULL;
64   
65   PARAVIS::PARAVIS_Gen_i* pPARAVIS_Gen = new PARAVIS::PARAVIS_Gen_i(aSession, 
66                                                                     orb, 
67                                                                     poa, 
68                                                                     contId, 
69                                                                     instanceName, 
70                                                                     interfaceName);
71   return pPARAVIS_Gen->getId() ;
72 }
73 }
74
75 namespace PARAVIS {
76   //===========================================================================
77   PARAVIS_Gen_i::PARAVIS_Gen_i(SALOME::Session_ptr session,
78                                CORBA::ORB_ptr orb,
79                                PortableServer::POA_ptr poa,
80                                PortableServer::ObjectId * contId, 
81                                const char *instanceName, 
82                                const char *interfaceName) :
83     Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
84   {
85     _thisObj = this ;
86     _id = _poa->activate_object(_thisObj);
87 #ifndef WIN32
88     Engines::Component_var aComponent = session->GetComponent("libPARAVIS.so");
89 #else
90     Engines::Component_var aComponent = session->GetComponent("PARAVIS.dll");
91 #endif
92     if (CORBA::is_nil(aComponent)) {
93       MESSAGE("Component PARAVIS is null");
94       return;
95     }
96     myParaVisGen = PARAVIS::PARAVIS_Gen::_narrow(aComponent);
97   } 
98   
99   //===========================================================================
100   PARAVIS_Gen_i::~PARAVIS_Gen_i()
101   {
102     if(MYDEBUG) MESSAGE("PARAVIS_Gen_i::~PARAVIS_Gen_i");
103   }
104
105
106   //===========================================================================
107   char* PARAVIS_Gen_i::GetIOR(){
108     return myParaVisGen->GetIOR();
109   }
110
111   //===========================================================================
112   bool PARAVIS_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
113                         const SALOMEDS::TMPFile & theStream,
114                         const char* theURL,
115                         bool isMultiFile)
116   {
117     return myParaVisGen->Load(theComponent,theStream,theURL,isMultiFile);
118   }
119
120   //===========================================================================
121   bool PARAVIS_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
122                              const SALOMEDS::TMPFile & theStream,
123                              const char* theURL,
124                              bool isMultiFile) 
125   {
126     return Load(theComponent, theStream, theURL, isMultiFile);
127   }
128
129
130   //===========================================================================
131   char* PARAVIS_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
132                                            const char* aLocalPersistentID,
133                                            CORBA::Boolean isMultiFile,
134                                            CORBA::Boolean isASCII) 
135   {
136     return myParaVisGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile, isASCII);
137   }
138
139   //===========================================================================
140   SALOMEDS::TMPFile* PARAVIS_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
141                                       const char* theURL,
142                                       bool isMultiFile)
143   {
144     return myParaVisGen->Save(theComponent,theURL,isMultiFile);
145   }
146
147   //===========================================================================
148   SALOMEDS::TMPFile* PARAVIS_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
149                                            const char* theURL,
150                                            bool isMultiFile) 
151   {
152     return myParaVisGen->Save(theComponent,theURL,isMultiFile);
153   }
154
155
156   //===========================================================================
157   char* PARAVIS_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
158                                            const char* IORString,
159                                            CORBA::Boolean isMultiFile,
160                                            CORBA::Boolean isASCII) 
161   {
162     return myParaVisGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile, isASCII);
163   }
164
165   //===========================================================================
166   void PARAVIS_Gen_i::ImportFile(const char* theFileName)
167   {
168     if (CORBA::is_nil(myParaVisGen)) {
169       MESSAGE("PARAVIS_Gen_i is null");
170       return;
171     }
172     myParaVisGen->ImportFile(theFileName);
173   }
174
175   //===========================================================================
176   char* PARAVIS_Gen_i::GetTrace()
177   {
178     if (CORBA::is_nil(myParaVisGen)) {
179       MESSAGE("PARAVIS_Gen_i is null");
180       return CORBA::string_dup("");
181     }
182     return CORBA::string_dup(myParaVisGen->GetTrace());
183   }
184
185   //===========================================================================
186   void PARAVIS_Gen_i::SaveTrace(const char* theFileName)
187   {
188     if (CORBA::is_nil(myParaVisGen)) {
189       MESSAGE("PARAVIS_Gen_i is null");
190       return ;
191     }
192     myParaVisGen->SaveTrace(theFileName);
193   }
194
195   //===========================================================================
196   void PARAVIS_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
197   {
198     myParaVisGen->Close(theComponent);
199   }
200
201
202   //===========================================================================
203   char* PARAVIS_Gen_i::ComponentDataType()
204   {
205     return CORBA::string_dup("PARAVIS");
206   }
207
208   //===========================================================================
209   CORBA::Boolean PARAVIS_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) 
210   {
211     return myParaVisGen->CanPublishInStudy(theIOR);
212   }
213
214
215   //===========================================================================
216   SALOMEDS::SObject_ptr PARAVIS_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
217                                                    SALOMEDS::SObject_ptr theSObject,
218                                                    CORBA::Object_ptr theObject,
219                                                    const char* theName) 
220     throw (SALOME::SALOME_Exception) 
221   {
222     return myParaVisGen->PublishInStudy(theStudy, theSObject, theObject, theName);
223   }
224
225   //===========================================================================
226   CORBA::Boolean PARAVIS_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) 
227   {
228     return myParaVisGen->CanCopy(theObject);
229   }
230   
231
232   //===========================================================================
233   SALOMEDS::TMPFile* PARAVIS_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) 
234   {
235     return myParaVisGen->CopyFrom(theObject, theObjectID);
236   }
237   
238
239   //===========================================================================
240   CORBA::Boolean PARAVIS_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) 
241   {
242     return myParaVisGen->CanPaste(theComponentName, theObjectID);
243   }
244
245   //===========================================================================
246   SALOMEDS::SObject_ptr PARAVIS_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
247                                               CORBA::Long theObjectID,
248                                               SALOMEDS::SObject_ptr theObject) 
249   {
250     return myParaVisGen->PasteInto(theStream,theObjectID,theObject);
251   }
252
253   //===========================================================================
254   PARAVIS::string_array* PARAVIS_Gen_i::GetClassesList()
255   {
256     return myParaVisGen->GetClassesList();
257   }
258
259   //===========================================================================
260   PARAVIS_Base_ptr PARAVIS_Gen_i::CreateClass(const char* theClassName)
261   {
262     return myParaVisGen->CreateClass(theClassName);
263   }
264
265   //===========================================================================
266   void PARAVIS_Gen_i::GetConnectionParameters(CORBA::Long& theId, 
267                                               CORBA::String_out theDHost, CORBA::Long& theDPort,
268                                               CORBA::String_out theRHost, CORBA::Long& theRPort,
269                                               CORBA::Long& theReversed)
270   {
271     myParaVisGen->GetConnectionParameters(theId, theDHost, theDPort, theRHost, theRPort, theReversed);
272   }
273     
274   //===========================================================================
275   void PARAVIS_Gen_i::ActivateModule()
276   {
277     myParaVisGen->ActivateModule();
278   }
279 }