1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SALOMEDS_Driver_i.hxx"
23 #include <SALOMEDS_TMPFile_i.hxx>
24 #include "utilities.h"
25 #include "SALOMEDS_SObject_i.hxx"
26 #include "SALOMEDS_SComponent_i.hxx"
27 #include "SALOMEDS_Study_i.hxx"
28 #include "SALOMEDS.hxx"
33 SALOMEDS_Driver_i::~SALOMEDS_Driver_i()
37 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::Save(const SALOMEDSImpl_SComponent& theComponent,
39 long& theStreamLength,
42 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
43 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
46 SALOMEDS::TMPFile_var aStream = _driver->Save(sco.in(), url, isMultiFile);
47 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
48 theStreamLength = aTMPFile->Size();
54 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::SaveASCII(const SALOMEDSImpl_SComponent& theComponent,
56 long& theStreamLength,
59 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
60 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
63 SALOMEDS::TMPFile_var aStream = _driver->SaveASCII(sco.in(), url, isMultiFile);
64 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
65 theStreamLength = aTMPFile->Size();
71 bool SALOMEDS_Driver_i::Load(const SALOMEDSImpl_SComponent& theComponent,
72 const unsigned char* theStream,
73 const long theStreamLength,
77 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
78 CORBA::String_var url = CORBA::string_dup(theURL.c_str());
79 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
81 SALOMEDS::TMPFile_var aStream;
82 if (theStreamLength > 0)
83 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
85 aStream = new SALOMEDS::TMPFile(0);
88 bool isOk = _driver->Load(sco.in(), aStream.in(), url, isMultiFile);
94 bool SALOMEDS_Driver_i::LoadASCII(const SALOMEDSImpl_SComponent& theComponent,
95 const unsigned char* theStream,
96 const long theStreamLength,
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);
111 bool isOk = _driver->LoadASCII(sco.in(), aStream.in(), url, isMultiFile);
117 void SALOMEDS_Driver_i::Close(const SALOMEDSImpl_SComponent& theComponent)
119 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
122 _driver->Close(sco.in());
128 string SALOMEDS_Driver_i::IORToLocalPersistentID(const SALOMEDSImpl_SObject& theSObject,
129 const string& IORString,
133 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theSObject, _orb);
134 CORBA::String_var ior = CORBA::string_dup(IORString.c_str());
137 CORBA::String_var pers_string =_driver->IORToLocalPersistentID(so.in(), ior.in(), isMultiFile, isASCII);
140 return string(pers_string);
144 string SALOMEDS_Driver_i::LocalPersistentIDToIOR(const SALOMEDSImpl_SObject& theObject,
145 const string& aLocalPersistentID,
149 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
150 CORBA::String_var pers_string = CORBA::string_dup(aLocalPersistentID.c_str());
152 CORBA::String_var IOR = _driver->LocalPersistentIDToIOR(so.in(), pers_string.in(), isMultiFile, isASCII);
157 bool SALOMEDS_Driver_i::CanCopy(const SALOMEDSImpl_SObject& theObject)
159 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
162 bool isOk = _driver->CanCopy(so.in());
169 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::CopyFrom(const SALOMEDSImpl_SObject& theObject,
171 long& theStreamLength)
173 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
176 CORBA::Long anObjectID;
177 SALOMEDS::TMPFile_var aStream = _driver->CopyFrom(so.in(), anObjectID);
178 SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
179 theStreamLength = aTMPFile->Size();
180 theObjectID = anObjectID;
186 bool SALOMEDS_Driver_i::CanPaste(const string& theComponentName, int theObjectID)
189 bool canPaste = _driver->CanPaste(theComponentName.c_str(), theObjectID);
194 string SALOMEDS_Driver_i::PasteInto(const unsigned char* theStream,
195 const long theStreamLength,
197 const SALOMEDSImpl_SObject& theObject)
199 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
200 CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
202 SALOMEDS::TMPFile_var aStream;
203 if(theStreamLength > 0)
204 aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);
206 aStream = new SALOMEDS::TMPFile(0);
209 SALOMEDS::SObject_var ret_so = _driver->PasteInto(aStream.in(), theObjectID, so.in());
212 return string(ret_so->GetID());
215 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy,
218 long& theStreamLength)
220 SALOMEDS_Study_i * st_servant = new SALOMEDS_Study_i (theStudy, _orb);
221 SALOMEDS::Study_var st = SALOMEDS::Study::_narrow(st_servant->_this());
222 Engines::Component_ptr aComponent = Engines::Component::_narrow(_driver);
225 CORBA::Boolean aValidScript, aPublished = isPublished;
226 Engines::TMPFile_var aStream = aComponent->DumpPython(st.in(), aPublished, aValidScript);
227 SALOMEDSImpl_TMPFile* aTMPFile = new Engines_TMPFile_i(aStream._retn());
228 theStreamLength = aTMPFile->Size();
229 isValidScript = aValidScript;
235 //###############################################################################################################
236 // SALOMEDS_DriverFactory
237 //###############################################################################################################
239 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByType(const string& theComponentType)
241 CORBA::Object_var obj;
244 if (theComponentType == "SUPERV") aFactoryType = "SuperVisionContainer";
245 else aFactoryType = "FactoryServer";
248 obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component(aFactoryType.c_str(), theComponentType.c_str());
251 if (CORBA::is_nil(obj)) {
252 obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component("FactoryServerPy", theComponentType.c_str());
255 if (!CORBA::is_nil(obj)) {
256 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(obj);
257 return new SALOMEDS_Driver_i(aDriver, _orb);
263 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByIOR(const string& theIOR)
265 CORBA::Object_var obj;
266 obj = _orb->string_to_object(theIOR.c_str());
268 if (!CORBA::is_nil(obj)) {
269 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(obj);
270 return new SALOMEDS_Driver_i(aDriver, _orb);