1 // Copyright (C) 2007-2011 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(SALOMEDS::Driver_ptr theDriver, CORBA::ORB_ptr theORB)
34 _driver = SALOMEDS::Driver::_duplicate(theDriver);
35 _orb = CORBA::ORB::_duplicate(theORB);
38 SALOMEDS_Driver_i::~SALOMEDS_Driver_i()
42 std::string SALOMEDS_Driver_i::GetIOR()
45 if ( !CORBA::is_nil(_driver) ) {
46 CORBA::String_var cior = _orb->object_to_string(_driver);
52 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::Save(const SALOMEDSImpl_SComponent& theComponent,
53 const std::string& theURL,
54 long& theStreamLength,
57 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
58 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
61 SALOMEDS::TMPFile_var aStream;
63 if ( !CORBA::is_nil(_driver) )
64 aStream = _driver->Save(sco.in(), url, isMultiFile);
66 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
67 theStreamLength = aTMPFile->Size();
73 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::SaveASCII(const SALOMEDSImpl_SComponent& theComponent,
74 const std::string& theURL,
75 long& theStreamLength,
78 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
79 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
82 SALOMEDS::TMPFile_var aStream;
84 if ( !CORBA::is_nil(_driver) )
85 aStream = _driver->SaveASCII(sco.in(), url, isMultiFile);
87 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
88 theStreamLength = aTMPFile->Size();
94 bool SALOMEDS_Driver_i::Load(const SALOMEDSImpl_SComponent& theComponent,
95 const unsigned char* theStream,
96 const long theStreamLength,
97 const std::string& theURL,
100 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
101 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
102 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
104 SALOMEDS::TMPFile_var aStream;
105 if (theStreamLength > 0)
106 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
108 aStream = new SALOMEDS::TMPFile(0);
113 if ( !CORBA::is_nil(_driver) )
114 isOk = _driver->Load(sco.in(), aStream.in(), url, isMultiFile);
120 bool SALOMEDS_Driver_i::LoadASCII(const SALOMEDSImpl_SComponent& theComponent,
121 const unsigned char* theStream,
122 const long theStreamLength,
123 const std::string& theURL,
126 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
127 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
128 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
130 SALOMEDS::TMPFile_var aStream;
131 if(theStreamLength > 0)
132 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
134 aStream = new SALOMEDS::TMPFile(0);
139 if ( !CORBA::is_nil(_driver) )
140 isOk = _driver->LoadASCII(sco.in(), aStream.in(), url, isMultiFile);
146 void SALOMEDS_Driver_i::Close(const SALOMEDSImpl_SComponent& theComponent)
148 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
151 if ( !CORBA::is_nil(_driver) )
152 _driver->Close(sco.in());
156 std::string SALOMEDS_Driver_i::ComponentDataType()
158 std::string dtype = "";
159 if ( !CORBA::is_nil(_driver) ) {
160 CORBA::String_var type = _driver->ComponentDataType();
166 std::string SALOMEDS_Driver_i::IORToLocalPersistentID(const SALOMEDSImpl_SObject& theSObject,
167 const std::string& IORString,
171 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theSObject, _orb);
172 CORBA::String_var ior = CORBA::string_dup(IORString.c_str());
176 std::string pstr = "";
178 if ( !CORBA::is_nil(_driver) ) {
179 CORBA::String_var pers_string =_driver->IORToLocalPersistentID(so.in(), ior.in(), isMultiFile, isASCII);
189 std::string SALOMEDS_Driver_i::LocalPersistentIDToIOR(const SALOMEDSImpl_SObject& theObject,
190 const std::string& aLocalPersistentID,
194 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
195 CORBA::String_var pers_string = CORBA::string_dup(aLocalPersistentID.c_str());
198 std::string ior = "";
200 if ( !CORBA::is_nil(_driver) ) {
201 CORBA::String_var IOR = _driver->LocalPersistentIDToIOR(so.in(), pers_string.in(), isMultiFile, isASCII);
209 bool SALOMEDS_Driver_i::CanCopy(const SALOMEDSImpl_SObject& theObject)
211 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
216 if ( !CORBA::is_nil(_driver) )
217 isOk = _driver->CanCopy(so.in());
226 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::CopyFrom(const SALOMEDSImpl_SObject& theObject,
228 long& theStreamLength)
230 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
233 CORBA::Long anObjectID;
234 SALOMEDS::TMPFile_var aStream;
236 if ( !CORBA::is_nil(_driver) )
237 aStream = _driver->CopyFrom(so.in(), anObjectID);
239 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
240 theStreamLength = aTMPFile->Size();
241 theObjectID = anObjectID;
247 bool SALOMEDS_Driver_i::CanPaste(const std::string& theComponentName, int theObjectID)
250 bool canPaste = false;
252 if ( !CORBA::is_nil(_driver) )
253 canPaste = _driver->CanPaste(theComponentName.c_str(), theObjectID);
259 std::string SALOMEDS_Driver_i::PasteInto(const unsigned char* theStream,
260 const long theStreamLength,
262 const SALOMEDSImpl_SObject& theObject)
264 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
265 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
267 SALOMEDS::TMPFile_var aStream;
268 if(theStreamLength > 0)
269 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
271 aStream = new SALOMEDS::TMPFile(0);
275 std::string entry = "";
277 if ( !CORBA::is_nil(_driver) ) {
278 SALOMEDS::SObject_var ret_so = _driver->PasteInto(aStream.in(), theObjectID, so.in());
279 entry = ret_so->GetID();
287 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy,
291 long& theStreamLength)
293 SALOMEDS_Study_i * st_servant = SALOMEDS_Study_i::GetStudyServant(theStudy, _orb);//new SALOMEDS_Study_i (theStudy, _orb);
294 SALOMEDS::Study_var st = SALOMEDS::Study::_narrow(st_servant->_this());
295 Engines::EngineComponent_ptr aComponent = Engines::EngineComponent::_narrow(_driver);
298 CORBA::Boolean aValidScript, aPublished = isPublished;
299 Engines::TMPFile_var aStream = aComponent->DumpPython(st.in(), aPublished, isMultiFile, aValidScript);
300 SALOMEDSImpl_TMPFile* aTMPFile = new Engines_TMPFile_i(aStream._retn());
301 theStreamLength = aTMPFile->Size();
302 isValidScript = aValidScript;
308 //###############################################################################################################
309 // SALOMEDS_DriverFactory
310 //###############################################################################################################
312 SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB)
314 _orb = CORBA::ORB::_duplicate(theORB);
315 _name_service = new SALOME_NamingService(_orb);
319 SALOMEDS_DriverFactory_i::~SALOMEDS_DriverFactory_i()
321 delete _name_service;
324 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByType(const std::string& theComponentType)
326 CORBA::Object_var obj;
328 std::string aFactoryType;
329 if (theComponentType == "SUPERV") aFactoryType = "SuperVisionContainer";
330 else aFactoryType = "FactoryServer";
333 obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component(aFactoryType.c_str(), theComponentType.c_str());
336 if (CORBA::is_nil(obj)) {
337 obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component("FactoryServerPy", theComponentType.c_str());
340 if (!CORBA::is_nil(obj)) {
341 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(obj);
342 return new SALOMEDS_Driver_i(aDriver, _orb);
348 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByIOR(const std::string& theIOR)
350 CORBA::Object_var obj;
351 obj = _orb->string_to_object(theIOR.c_str());
353 if (!CORBA::is_nil(obj)) {
354 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(obj);
355 return new SALOMEDS_Driver_i(aDriver, _orb);