Salome HOME
Copyrights update 2015.
[modules/paravis.git] / src / ENGINE / PARAVIS_Engine_i.cc
1 // Copyright (C) 2010-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "PARAVIS_Engine_i.hh"
21 #include "utilities.h"
22
23
24 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
25
26 #include "SALOME_NamingService.hxx"
27 #include "Utils_ExceptHandlers.hxx"
28
29 using namespace std;
30
31 #ifdef _DEBUG_
32 static int MYDEBUG = 1;
33 #else
34 static int MYDEBUG = 0;
35 #endif
36
37 #ifdef WNT
38 #if defined PARAVIS_ENGINE_EXPORTS || defined PARAVISEngine_EXPORTS
39 #define PARAVIS_ENGINE_EXPORT __declspec(dllexport)
40 #else
41 #define PARAVIS_ENGINE_EXPORT __declspec(dllimport)
42 #endif
43 #else
44 #define PARAVIS_ENGINE_EXPORT
45 #endif
46
47 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
48
49 extern "C" {
50 PARAVIS_ENGINE_EXPORT PortableServer::ObjectId* PARAVISEngine_factory(CORBA::ORB_ptr orb, 
51                                                                       PortableServer::POA_ptr poa, 
52                                                                       PortableServer::ObjectId * contId,
53                                                                       const char *instanceName, 
54                                                                       const char *interfaceName) 
55 {
56   MESSAGE("PARAVISEngine_factory : "<<interfaceName);
57   SALOME_NamingService aNamingService(orb);
58   CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session");
59   SALOME::Session_var aSession = SALOME::Session::_narrow(anObject);
60   if (CORBA::is_nil(aSession))
61     return NULL;
62   
63   PARAVIS::PARAVIS_Gen_i* pPARAVIS_Gen = new PARAVIS::PARAVIS_Gen_i(aSession, 
64                                                                     orb, 
65                                                                     poa, 
66                                                                     contId, 
67                                                                     instanceName, 
68                                                                     interfaceName);
69   return pPARAVIS_Gen->getId() ;
70 }
71 }
72
73 namespace PARAVIS {
74   //===========================================================================
75   PARAVIS_Gen_i::PARAVIS_Gen_i(SALOME::Session_ptr session,
76                                CORBA::ORB_ptr orb,
77                                PortableServer::POA_ptr poa,
78                                PortableServer::ObjectId * contId, 
79                                const char *instanceName, 
80                                const char *interfaceName) :
81     Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
82   {
83     _thisObj = this ;
84     _id = _poa->activate_object(_thisObj);
85 #ifndef WIN32
86     Engines::EngineComponent_var aComponent = session->GetComponent("libPARAVIS.so");
87 #else
88     Engines::EngineComponent_var aComponent = session->GetComponent("PARAVIS.dll");
89 #endif
90     if (CORBA::is_nil(aComponent)) {
91       MESSAGE("Component PARAVIS is null");
92       return;
93     }
94     myParaVisGen = PARAVIS::PARAVIS_Gen::_narrow(aComponent);
95   } 
96   
97   //===========================================================================
98   PARAVIS_Gen_i::~PARAVIS_Gen_i()
99   {
100     if(MYDEBUG) MESSAGE("PARAVIS_Gen_i::~PARAVIS_Gen_i");
101   }
102
103
104   //===========================================================================
105   char* PARAVIS_Gen_i::GetIOR(){
106     return myParaVisGen->GetIOR();
107   }
108
109   //===========================================================================
110   bool PARAVIS_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
111                         const SALOMEDS::TMPFile & theStream,
112                         const char* theURL,
113                         bool isMultiFile)
114   {
115     return myParaVisGen->Load(theComponent,theStream,theURL,isMultiFile);
116   }
117
118   //===========================================================================
119   bool PARAVIS_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
120                              const SALOMEDS::TMPFile & theStream,
121                              const char* theURL,
122                              bool isMultiFile) 
123   {
124     return Load(theComponent, theStream, theURL, isMultiFile);
125   }
126
127
128   //===========================================================================
129   char* PARAVIS_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
130                                            const char* aLocalPersistentID,
131                                            CORBA::Boolean isMultiFile,
132                                            CORBA::Boolean isASCII) 
133   {
134     return myParaVisGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile, isASCII);
135   }
136
137   //===========================================================================
138   SALOMEDS::TMPFile* PARAVIS_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
139                                       const char* theURL,
140                                       bool isMultiFile)
141   {
142     return myParaVisGen->Save(theComponent,theURL,isMultiFile);
143   }
144
145   //===========================================================================
146   SALOMEDS::TMPFile* PARAVIS_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
147                                            const char* theURL,
148                                            bool isMultiFile) 
149   {
150     return myParaVisGen->Save(theComponent,theURL,isMultiFile);
151   }
152
153
154   //===========================================================================
155   char* PARAVIS_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
156                                            const char* IORString,
157                                            CORBA::Boolean isMultiFile,
158                                            CORBA::Boolean isASCII) 
159   {
160     return myParaVisGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile, isASCII);
161   }
162
163   //===========================================================================
164   void PARAVIS_Gen_i::ImportFile(const char* theFileName)
165   {
166     if (CORBA::is_nil(myParaVisGen)) {
167       MESSAGE("PARAVIS_Gen_i is null");
168       return;
169     }
170     myParaVisGen->ImportFile(theFileName);
171   }
172
173   void PARAVIS_Gen_i::ExecuteScript(const char* script)
174   {
175     if (CORBA::is_nil(myParaVisGen)) {
176       MESSAGE("PARAVIS_Gen_i is null");
177       return;
178     }
179     myParaVisGen->ExecuteScript(script);
180   }
181
182   //===========================================================================
183   char* PARAVIS_Gen_i::GetTrace()
184   {
185     if (CORBA::is_nil(myParaVisGen)) {
186       MESSAGE("PARAVIS_Gen_i is null");
187       return CORBA::string_dup("");
188     }
189     return CORBA::string_dup(myParaVisGen->GetTrace());
190   }
191
192   //===========================================================================
193   void PARAVIS_Gen_i::SaveTrace(const char* theFileName)
194   {
195     if (CORBA::is_nil(myParaVisGen)) {
196       MESSAGE("PARAVIS_Gen_i is null");
197       return ;
198     }
199     myParaVisGen->SaveTrace(theFileName);
200   }
201
202   //===========================================================================
203   void PARAVIS_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
204   {
205     myParaVisGen->Close(theComponent);
206   }
207
208
209   //===========================================================================
210   char* PARAVIS_Gen_i::ComponentDataType()
211   {
212     return CORBA::string_dup("PARAVIS");
213   }
214
215   //===========================================================================
216   CORBA::Boolean PARAVIS_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) 
217   {
218     return myParaVisGen->CanPublishInStudy(theIOR);
219   }
220
221
222   //===========================================================================
223   SALOMEDS::SObject_ptr PARAVIS_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
224                                                    SALOMEDS::SObject_ptr theSObject,
225                                                    CORBA::Object_ptr theObject,
226                                                    const char* theName) 
227     throw (SALOME::SALOME_Exception) 
228   {
229     return myParaVisGen->PublishInStudy(theStudy, theSObject, theObject, theName);
230   }
231
232   //===========================================================================
233   CORBA::Boolean PARAVIS_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) 
234   {
235     return myParaVisGen->CanCopy(theObject);
236   }
237   
238
239   //===========================================================================
240   SALOMEDS::TMPFile* PARAVIS_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) 
241   {
242     return myParaVisGen->CopyFrom(theObject, theObjectID);
243   }
244   
245
246   //===========================================================================
247   CORBA::Boolean PARAVIS_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) 
248   {
249     return myParaVisGen->CanPaste(theComponentName, theObjectID);
250   }
251
252   //===========================================================================
253   SALOMEDS::SObject_ptr PARAVIS_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
254                                               CORBA::Long theObjectID,
255                                               SALOMEDS::SObject_ptr theObject) 
256   {
257     return myParaVisGen->PasteInto(theStream,theObjectID,theObject);
258   }
259
260 #ifdef PARAVIS_WITH_FULL_CORBA
261   //===========================================================================
262   PARAVIS::string_array* PARAVIS_Gen_i::GetClassesList()
263   {
264     return myParaVisGen->GetClassesList();
265   }
266
267   //===========================================================================
268   PARAVIS_Base_ptr PARAVIS_Gen_i::CreateClass(const char* theClassName)
269   {
270     return myParaVisGen->CreateClass(theClassName);
271   }
272 #endif
273
274   //===========================================================================
275   void PARAVIS_Gen_i::GetConnectionParameters(CORBA::Long& theId, 
276                                               CORBA::String_out theDHost, CORBA::Long& theDPort,
277                                               CORBA::String_out theRHost, CORBA::Long& theRPort,
278                                               CORBA::Long& theReversed)
279   {
280     myParaVisGen->GetConnectionParameters(theId, theDHost, theDPort, theRHost, theRPort, theReversed);
281   }
282     
283   //===========================================================================
284   void PARAVIS_Gen_i::ActivateModule()
285   {
286     myParaVisGen->ActivateModule();
287   }
288
289   //===========================================================================
290   void PARAVIS_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
291     myParaVisGen->SetCurrentStudy(theStudy);
292   }
293
294
295   //===========================================================================
296   SALOMEDS::Study_ptr PARAVIS_Gen_i::GetCurrentStudy(){
297     return myParaVisGen->GetCurrentStudy();
298   }
299   char* PARAVIS_Gen_i::getVersion()
300   {
301     return myParaVisGen->getVersion();
302   }
303 }