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();
87 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::SaveASCII(const SALOMEDSImpl_SComponent& theComponent,
88 const std::string& theURL,
89 long& theStreamLength,
92 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
93 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
96 SALOMEDS::TMPFile_var aStream;
98 if ( !CORBA::is_nil(_driver) )
99 aStream = _driver->SaveASCII(sco.in(), url, isMultiFile);
101 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
102 theStreamLength = aTMPFile->Size();
110 bool SALOMEDS_Driver_i::Load(const SALOMEDSImpl_SComponent& theComponent,
111 const unsigned char* theStream,
112 const long theStreamLength,
113 const std::string& theURL,
116 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
117 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
118 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
120 SALOMEDS::TMPFile_var aStream;
121 if (theStreamLength > 0)
122 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
124 aStream = new SALOMEDS::TMPFile(0);
129 if ( !CORBA::is_nil(_driver) )
130 isOk = _driver->Load(sco.in(), aStream.in(), url, isMultiFile);
137 bool SALOMEDS_Driver_i::LoadASCII(const SALOMEDSImpl_SComponent& theComponent,
138 const unsigned char* theStream,
139 const long theStreamLength,
140 const std::string& theURL,
143 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
144 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
145 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
147 SALOMEDS::TMPFile_var aStream;
148 if(theStreamLength > 0)
149 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
151 aStream = new SALOMEDS::TMPFile(0);
156 if ( !CORBA::is_nil(_driver) )
157 isOk = _driver->LoadASCII(sco.in(), aStream.in(), url, isMultiFile);
164 void SALOMEDS_Driver_i::Close(const SALOMEDSImpl_SComponent& theComponent)
166 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
169 if ( !CORBA::is_nil(_driver) )
170 _driver->Close(sco.in());
175 std::string SALOMEDS_Driver_i::ComponentDataType()
177 std::string dtype = "";
178 if ( !CORBA::is_nil(_driver) ) {
179 CORBA::String_var type = _driver->ComponentDataType();
185 std::string SALOMEDS_Driver_i::Version()
187 return !CORBA::is_nil( _engine ) ? _engine->getVersion() : std::string("");
190 std::string SALOMEDS_Driver_i::IORToLocalPersistentID(const SALOMEDSImpl_SObject& theSObject,
191 const std::string& IORString,
195 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theSObject, _orb);
198 std::string pstr = "";
200 if ( !CORBA::is_nil(_driver) ) {
201 CORBA::String_var pers_string =_driver->IORToLocalPersistentID(so.in(), IORString.c_str(),
202 isMultiFile, isASCII);
213 std::string SALOMEDS_Driver_i::LocalPersistentIDToIOR(const SALOMEDSImpl_SObject& theObject,
214 const std::string& aLocalPersistentID,
218 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
219 CORBA::String_var pers_string = CORBA::string_dup(aLocalPersistentID.c_str());
222 std::string ior = "";
224 if ( !CORBA::is_nil(_driver) ) {
225 CORBA::String_var IOR = _driver->LocalPersistentIDToIOR(so.in(), pers_string.in(), isMultiFile, isASCII);
233 bool SALOMEDS_Driver_i::CanCopy(const SALOMEDSImpl_SObject& theObject)
235 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
240 if ( !CORBA::is_nil(_driver) )
241 isOk = _driver->CanCopy(so.in());
250 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::CopyFrom(const SALOMEDSImpl_SObject& theObject,
252 long& theStreamLength)
254 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
257 CORBA::Long anObjectID;
258 SALOMEDS::TMPFile_var aStream;
260 if ( !CORBA::is_nil(_driver) )
261 aStream = _driver->CopyFrom(so.in(), anObjectID);
263 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
264 theStreamLength = aTMPFile->Size();
265 theObjectID = anObjectID;
273 bool SALOMEDS_Driver_i::CanPaste(const std::string& theComponentName, int theObjectID)
276 bool canPaste = false;
278 if ( !CORBA::is_nil(_driver) )
279 canPaste = _driver->CanPaste(theComponentName.c_str(), theObjectID);
285 std::string SALOMEDS_Driver_i::PasteInto(const unsigned char* theStream,
286 const long theStreamLength,
288 const SALOMEDSImpl_SObject& theObject)
290 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
291 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
293 SALOMEDS::TMPFile_var aStream;
294 if(theStreamLength > 0)
295 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
297 aStream = new SALOMEDS::TMPFile(0);
301 std::string entry = "";
303 if ( !CORBA::is_nil(_driver) ) {
304 SALOMEDS::SObject_var ret_so = _driver->PasteInto(aStream.in(), theObjectID, so.in());
305 entry = ret_so->GetID();
314 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy,
318 long& theStreamLength)
320 SALOMEDS_Study_i * st_servant = SALOMEDS_Study_i::GetStudyServant(theStudy, _orb);//new SALOMEDS_Study_i (theStudy, _orb);
321 SALOMEDS::Study_var st = SALOMEDS::Study::_narrow(st_servant->_this());
325 Engines::TMPFile_var aStream;
326 CORBA::Boolean aValidScript = true; // VSR: maybe should be false by default ???
328 if ( !CORBA::is_nil( _engine ) )
329 aStream = _engine->DumpPython(st.in(), isPublished, isMultiFile, aValidScript);
331 SALOMEDSImpl_TMPFile* aTMPFile = new Engines_TMPFile_i(aStream._retn());
332 theStreamLength = aTMPFile->Size();
333 isValidScript = aValidScript;
340 //###############################################################################################################
341 // SALOMEDS_DriverFactory
342 //###############################################################################################################
344 SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB)
346 _orb = CORBA::ORB::_duplicate(theORB);
347 _name_service = new SALOME_NamingService(_orb);
351 SALOMEDS_DriverFactory_i::~SALOMEDS_DriverFactory_i()
353 delete _name_service;
356 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByType(const std::string& theComponentType)
358 CORBA::Object_var obj;
360 std::string aFactoryType;
361 if (theComponentType == "SUPERV") aFactoryType = "SuperVisionContainer";
362 else aFactoryType = "FactoryServer";
365 obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component(aFactoryType.c_str(), theComponentType.c_str());
368 if (CORBA::is_nil(obj)) {
369 obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component("FactoryServerPy", theComponentType.c_str());
372 if (!CORBA::is_nil(obj)) {
373 Engines::EngineComponent_var anEngine = Engines::EngineComponent::_narrow(obj);
374 return new SALOMEDS_Driver_i(anEngine, _orb);
380 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByIOR(const std::string& theIOR)
382 CORBA::Object_var obj;
383 obj = _orb->string_to_object(theIOR.c_str());
385 if (!CORBA::is_nil(obj)) {
386 Engines::EngineComponent_var anEngine = Engines::EngineComponent::_narrow(obj);
387 return new SALOMEDS_Driver_i(anEngine, _orb);