1 // Copyright (C) 2007-2012 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 "SALOMEDS_Driver_i.hxx"
24 #include "SALOMEDS_TMPFile_i.hxx"
25 #include "utilities.h"
26 #include "SALOMEDS_SObject_i.hxx"
27 #include "SALOMEDS_SComponent_i.hxx"
28 #include "SALOMEDS_Study_i.hxx"
29 #include "SALOMEDS.hxx"
32 SALOMEDS_Driver_i::SALOMEDS_Driver_i(Engines::EngineComponent_ptr theEngine, CORBA::ORB_ptr theORB)
34 // engine should not be null - component is supposed to be inherited from Engines::EngineComponent
35 _engine = Engines::EngineComponent::_duplicate(theEngine);
36 // driver can be null - if component interface does not inherit SALOMEDS::Driver
37 _driver = SALOMEDS::Driver::_narrow(theEngine);
38 _orb = CORBA::ORB::_duplicate(theORB);
41 SALOMEDS_Driver_i::SALOMEDS_Driver_i(SALOMEDS::Driver_ptr theDriver, CORBA::ORB_ptr theORB)
43 // driver can be null - if component interface does not inherit SALOMEDS::Driver
44 _driver = SALOMEDS::Driver::_duplicate(theDriver);
45 // engine can be null - since it is narrowed from SALOMEDS::Driver ptr which can be null
46 _engine = Engines::EngineComponent::_narrow(theDriver);
47 _orb = CORBA::ORB::_duplicate(theORB);
50 SALOMEDS_Driver_i::~SALOMEDS_Driver_i()
54 std::string SALOMEDS_Driver_i::GetIOR()
57 if ( !CORBA::is_nil(_engine) ) {
58 CORBA::String_var cior = _orb->object_to_string(_engine);
64 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::Save(const SALOMEDSImpl_SComponent& theComponent,
65 const std::string& theURL,
66 long& theStreamLength,
69 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
70 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
73 SALOMEDS::TMPFile_var aStream;
75 if ( !CORBA::is_nil(_driver) )
76 aStream = _driver->Save(sco.in(), url, isMultiFile);
78 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
79 theStreamLength = aTMPFile->Size();
85 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::SaveASCII(const SALOMEDSImpl_SComponent& theComponent,
86 const std::string& theURL,
87 long& theStreamLength,
90 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
91 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
94 SALOMEDS::TMPFile_var aStream;
96 if ( !CORBA::is_nil(_driver) )
97 aStream = _driver->SaveASCII(sco.in(), url, isMultiFile);
99 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
100 theStreamLength = aTMPFile->Size();
106 bool SALOMEDS_Driver_i::Load(const SALOMEDSImpl_SComponent& theComponent,
107 const unsigned char* theStream,
108 const long theStreamLength,
109 const std::string& theURL,
112 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
113 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
114 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
116 SALOMEDS::TMPFile_var aStream;
117 if (theStreamLength > 0)
118 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
120 aStream = new SALOMEDS::TMPFile(0);
125 if ( !CORBA::is_nil(_driver) )
126 isOk = _driver->Load(sco.in(), aStream.in(), url, isMultiFile);
132 bool SALOMEDS_Driver_i::LoadASCII(const SALOMEDSImpl_SComponent& theComponent,
133 const unsigned char* theStream,
134 const long theStreamLength,
135 const std::string& theURL,
138 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
139 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
140 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
142 SALOMEDS::TMPFile_var aStream;
143 if(theStreamLength > 0)
144 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
146 aStream = new SALOMEDS::TMPFile(0);
151 if ( !CORBA::is_nil(_driver) )
152 isOk = _driver->LoadASCII(sco.in(), aStream.in(), url, isMultiFile);
158 void SALOMEDS_Driver_i::Close(const SALOMEDSImpl_SComponent& theComponent)
160 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
163 if ( !CORBA::is_nil(_driver) )
164 _driver->Close(sco.in());
168 std::string SALOMEDS_Driver_i::ComponentDataType()
170 std::string dtype = "";
171 if ( !CORBA::is_nil(_driver) ) {
172 CORBA::String_var type = _driver->ComponentDataType();
178 std::string SALOMEDS_Driver_i::Version()
180 return !CORBA::is_nil( _engine ) ? _engine->getVersion() : std::string("");
183 std::string SALOMEDS_Driver_i::IORToLocalPersistentID(const SALOMEDSImpl_SObject& theSObject,
184 const std::string& IORString,
188 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theSObject, _orb);
189 CORBA::String_var ior = CORBA::string_dup(IORString.c_str());
193 std::string pstr = "";
195 if ( !CORBA::is_nil(_driver) ) {
196 CORBA::String_var pers_string =_driver->IORToLocalPersistentID(so.in(), ior.in(), isMultiFile, isASCII);
206 std::string SALOMEDS_Driver_i::LocalPersistentIDToIOR(const SALOMEDSImpl_SObject& theObject,
207 const std::string& aLocalPersistentID,
211 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
212 CORBA::String_var pers_string = CORBA::string_dup(aLocalPersistentID.c_str());
215 std::string ior = "";
217 if ( !CORBA::is_nil(_driver) ) {
218 CORBA::String_var IOR = _driver->LocalPersistentIDToIOR(so.in(), pers_string.in(), isMultiFile, isASCII);
226 bool SALOMEDS_Driver_i::CanCopy(const SALOMEDSImpl_SObject& theObject)
228 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
233 if ( !CORBA::is_nil(_driver) )
234 isOk = _driver->CanCopy(so.in());
243 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::CopyFrom(const SALOMEDSImpl_SObject& theObject,
245 long& theStreamLength)
247 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
250 CORBA::Long anObjectID;
251 SALOMEDS::TMPFile_var aStream;
253 if ( !CORBA::is_nil(_driver) )
254 aStream = _driver->CopyFrom(so.in(), anObjectID);
256 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
257 theStreamLength = aTMPFile->Size();
258 theObjectID = anObjectID;
264 bool SALOMEDS_Driver_i::CanPaste(const std::string& theComponentName, int theObjectID)
267 bool canPaste = false;
269 if ( !CORBA::is_nil(_driver) )
270 canPaste = _driver->CanPaste(theComponentName.c_str(), theObjectID);
276 std::string SALOMEDS_Driver_i::PasteInto(const unsigned char* theStream,
277 const long theStreamLength,
279 const SALOMEDSImpl_SObject& theObject)
281 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
282 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
284 SALOMEDS::TMPFile_var aStream;
285 if(theStreamLength > 0)
286 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
288 aStream = new SALOMEDS::TMPFile(0);
292 std::string entry = "";
294 if ( !CORBA::is_nil(_driver) ) {
295 SALOMEDS::SObject_var ret_so = _driver->PasteInto(aStream.in(), theObjectID, so.in());
296 entry = ret_so->GetID();
304 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy,
308 long& theStreamLength)
310 SALOMEDS_Study_i * st_servant = SALOMEDS_Study_i::GetStudyServant(theStudy, _orb);//new SALOMEDS_Study_i (theStudy, _orb);
311 SALOMEDS::Study_var st = SALOMEDS::Study::_narrow(st_servant->_this());
315 Engines::TMPFile_var aStream;
316 CORBA::Boolean aValidScript = true; // VSR: maybe should be false by default ???
318 if ( !CORBA::is_nil( _engine ) )
319 aStream = _engine->DumpPython(st.in(), isPublished, isMultiFile, aValidScript);
321 SALOMEDSImpl_TMPFile* aTMPFile = new Engines_TMPFile_i(aStream._retn());
322 theStreamLength = aTMPFile->Size();
323 isValidScript = aValidScript;
330 //###############################################################################################################
331 // SALOMEDS_DriverFactory
332 //###############################################################################################################
334 SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB)
336 _orb = CORBA::ORB::_duplicate(theORB);
337 _name_service = new SALOME_NamingService(_orb);
341 SALOMEDS_DriverFactory_i::~SALOMEDS_DriverFactory_i()
343 delete _name_service;
346 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByType(const std::string& theComponentType)
348 CORBA::Object_var obj;
350 std::string aFactoryType;
351 if (theComponentType == "SUPERV") aFactoryType = "SuperVisionContainer";
352 else aFactoryType = "FactoryServer";
355 obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component(aFactoryType.c_str(), theComponentType.c_str());
358 if (CORBA::is_nil(obj)) {
359 obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component("FactoryServer", theComponentType.c_str());
362 if (!CORBA::is_nil(obj)) {
363 Engines::EngineComponent_var anEngine = Engines::EngineComponent::_narrow(obj);
364 return new SALOMEDS_Driver_i(anEngine, _orb);
370 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByIOR(const std::string& theIOR)
372 CORBA::Object_var obj;
373 obj = _orb->string_to_object(theIOR.c_str());
375 if (!CORBA::is_nil(obj)) {
376 Engines::EngineComponent_var anEngine = Engines::EngineComponent::_narrow(obj);
377 return new SALOMEDS_Driver_i(anEngine, _orb);