1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : VISU_Gen_i.cc file
6 // Author : Alexey Petrov
11 #include "VISU_Gen_i.hh"
12 #include "VISU_Result_i.hh"
13 #include "VISU_Convertor.hxx"
14 #include "VISU_PrsObject_i.hh"
15 #include "VISU_ViewManager_i.hh"
16 #include "VISU_TimeAnimation.h"
17 #include "VISU_Table_i.hh"
19 #include "HDFascii.hxx"
20 #include "SALOMEDS_Tool.hxx"
22 #include <TCollection_AsciiString.hxx>
23 #include <TColStd_SequenceOfAsciiString.hxx>
24 #include <vtkUnstructuredGridReader.h>
25 #include <vtkUnstructuredGridWriter.h>
27 #include <omnithread.h>
28 #include CORBA_SERVER_HEADER(SALOME_Session)
29 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
32 #include <qfileinfo.h>
33 static QFileInfo aFileInfo;
36 static int MYDEBUG = 0;
38 static int MYDEBUG = 0;
41 #include <utilities.h>
43 //static int IS_LOADED = (cout<<"\n----------------- VisuEngine_factory is loaded -----------------\n", 1);
45 PortableServer::ObjectId *
46 VISUEngine_factory(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId * contId,
47 const char *instanceName, const char *interfaceName)
49 if(MYDEBUG) MESSAGE("VisuEngine_factory : "<<interfaceName);
50 VISU::VISU_Gen_i * pVISU_Gen = new VISU::VISU_Gen_i(orb, poa, contId, instanceName, interfaceName);
51 return pVISU_Gen->getId() ;
54 GetVisuGen(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
55 SALOME_NamingService* theNamingService, QMutex* theMutex)
57 if(MYDEBUG) MESSAGE("extern \"C\" GetVisuGen");
58 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
59 return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
60 //return aVISU_Gen->_this();
65 //===========================================================================
66 //apo - static QMutex VISUMutex;
67 QMutex* Base_i::myMutex = NULL; //apo - &VISUMutex;
68 CORBA::ORB_var Base_i::myOrb;
69 PortableServer::POA_var Base_i::myPOA;
70 SALOME_NamingService* Base_i::myNamingService;
71 SALOME_LifeCycleCORBA* Base_i::myEnginesLifeCycle;
72 VISU_Gen_i* Base_i::myVisuGenImpl;
73 VISU_Gen_var Base_i::GetVisuGenInter() { return myVisuGenImpl->_this();}
75 char* Base_i::GetID(){
76 //CORBA::Object_var anObject = _this();
77 //return CORBA::string_dup(myOrb->object_to_string(anObject));
78 return CORBA::string_dup(myOrb->object_to_string(_this()));
80 //===========================================================================
81 static int mySCnt = 0;
82 static int myQCnt = 0;
83 static int myIsBatchMode = 0;
85 static int QApp_Counter = 0;
86 static int Session_Counter = 0;
87 static int COUNTER = 0;
89 Mutex::Mutex(QMutex* theMutex, QApplication* theQApp, int theDelay) :
90 myQApp(theQApp), isQAppLocked(theQApp->locked()), myDelay(theDelay),
91 myMutex(theMutex), isSessionLocked(theMutex->locked())
93 if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<(!isQAppLocked && !myQCnt)<<" "<<(!isSessionLocked && !mySCnt));
94 if(!myIsBatchMode && isQAppLocked) myIsBatchMode++;
95 if(!isSessionLocked && !mySCnt) { myMutex->lock();}; mySCnt++;
96 if(!isQAppLocked && !myQCnt) {
104 if(!isQAppLocked && !myQCnt) {
107 myQApp->processEvents(myDelay+3);
110 mySCnt--; if(!isSessionLocked && !mySCnt) { myMutex->unlock();}
111 if(MYDEBUG) MESSAGE("Mutex::~Mutex : "<<(!isQAppLocked && !myQCnt)<<" "<<(!isSessionLocked && !mySCnt));
113 //===========================================================================
114 static Storable::TCallbackMap VisuStoreMap;
115 string Storable::ToString(){
116 ostringstream strOut;
117 Storable::DataToStream( strOut, "myComment", GetComment() );
120 if(MYDEBUG) MESSAGE("Storable::ToString - "<<strOut.str());
121 //apo - auto_ptr<char> aRet(strOut.str());
125 void Storable::Registry(const char* theComment, TStorableEngine theEngine)
126 throw(std::logic_error&)
128 if(!VisuStoreMap.insert(TCallbackMap::value_type(theComment,theEngine)).second){
129 if(MYDEBUG) MESSAGE("Storable::Registry >> dupliacte registring !!!");
130 throw std::logic_error("Storable::Registry >> dupliacte registring !!!");
134 void RegistryStorable() throw(std::logic_error&) {
135 //Storable::Registry(View3D_i::myComment.c_str(),&View3DRestore);
136 Storable::Registry(Result_i::myComment.c_str(),&ResultRestore);
137 Storable::Registry(Mesh_i::myComment.c_str(),&MeshRestore);
138 Storable::Registry(ScalarMap_i::myComment.c_str(),&ScalarMapRestore);
139 Storable::Registry(DeformedShape_i::myComment.c_str(),&DeformedShapeRestore);
140 Storable::Registry(CutPlanes_i::myComment.c_str(),&CutPlanesRestore);
141 Storable::Registry(CutLines_i::myComment.c_str(),&CutLinesRestore);
142 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&IsoSurfacesRestore);
143 Storable::Registry(StreamLines_i::myComment.c_str(),&StreamLinesRestore);
144 Storable::Registry(Vectors_i::myComment.c_str(),&VectorsRestore);
145 Storable::Registry(Table_i::myComment.c_str(),&TableRestore);
146 Storable::Registry(Curve_i::myComment.c_str(),&CurveRestore);
147 Storable::Registry(Container_i::myComment.c_str(),&ContainerRestore);
150 void Storable::StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap){
151 if(0 && MYDEBUG) MESSAGE("Storable::StrToMap : string="<<theStr);
152 QStringList strList = QStringList::split( ";", theStr, false );
153 for ( int i = 0; i < strList.count(); i++ ) {
154 QString next = strList[ i ];
155 int pos = next.find("=");
156 QString aName, aValue;
158 aName = next.stripWhiteSpace();
162 aName = next.left( pos ).stripWhiteSpace();
163 aValue = next.mid( pos+1 );
164 if ( aValue.isNull() )
167 if ( !aName.isEmpty() )
168 theMap.insert( TRestoringMap::value_type( aName.latin1(), aValue ) );
171 void Storable::DataToStream(ostringstream& theStr, const QString& theName, const QString& theVal) {
172 QString output = ( !theName.isNull() ? theName : QString("") )
174 + ( !theVal.isNull() ? theVal : QString("") );
175 theStr<<output.latin1()<<";";
177 void Storable::DataToStream(ostringstream& theStr, const QString& theName, const int theVal) {
178 QString output = ( !theName.isNull() ? theName : QString("") )
180 + QString::number( theVal );
181 theStr<<output.latin1()<<";";
183 void Storable::DataToStream(ostringstream& theStr, const QString& theName, const double theVal) {
184 QString output = ( !theName.isNull() ? theName : QString("") )
186 + QString::number( theVal );
187 theStr<<output.latin1()<<";";
189 Storable* Storable::Create(SALOMEDS::SObject_ptr theSObject,
190 const string& thePrefix, const string& theLocalPersistentID)
191 throw (std::runtime_error&)
194 QString strIn( theLocalPersistentID.c_str() );
196 StrToMap(strIn,aMap);
197 //CORBA::String_var aResultID(GetResultSO(theSObject)->GetID());
198 //aMap.insert(TRestoringMap::value_type("ResultID", strdup(aResultID)));
200 QString aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist);
202 TCallbackMap::const_iterator i = VisuStoreMap.find(aComment.latin1());
203 if(MYDEBUG) MESSAGE("Storable::Create - "<<aComment.latin1()<<" "<<(i != VisuStoreMap.end()));
204 if(i == VisuStoreMap.end()) return NULL;
205 return (i->second)(theSObject,thePrefix,aMap);
207 }catch(std::logic_error& exc){
208 MESSAGE("Follow exception was accured :\n"<<exc.what());
210 MESSAGE("Unknown exception was accured!");
214 const QString& Storable::FindValue(const TRestoringMap& theMap, const string& theArg, bool* isFind)
215 throw(std::logic_error&)
217 TRestoringMap::const_iterator i = theMap.find(theArg);
218 if(i == theMap.end()) {
219 if(MYDEBUG) MESSAGE("Storable::Init >> there is no value for "<<theArg);
220 if(isFind != NULL) *isFind = false;
221 //throw std::logic_error(string("Storable::Init >> there is no value for ") + theArg);
222 static QString BAD_VALUE("NULL");
225 if(isFind != NULL) *isFind = true;
229 //===========================================================================
230 PortableServer::Servant GetServant(CORBA::Object_ptr theObject){
231 PortableServer::POA_ptr aPOA = Base_i::GetPOA();
232 if(CORBA::is_nil(theObject))
233 if(MYDEBUG) MESSAGE("GetServant - CORBA::is_nil(theObject)");
234 return aPOA->reference_to_servant(theObject);
236 //===========================================================================
237 CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr theSObject){
238 SALOMEDS::GenericAttribute_var anAttr;
239 CORBA::Object_var anObj;
241 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
242 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
243 CORBA::String_var aValue = anIOR->Value();
244 CORBA::ORB_ptr anORB = Base_i::GetORB();
245 if(strcmp(aValue,"") != 0)
246 anObj = anORB->string_to_object(aValue);
249 MESSAGE("SObjectToObject - Unknown exception was accured!");
253 //===========================================================================
254 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
255 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
256 if (aSComponent->_is_nil()) {
257 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
258 aStudyBuilder->NewCommand();
259 int aLocked = theStudyDocument->GetProperties()->IsLocked();
260 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
261 aSComponent = aStudyBuilder->NewComponent("VISU");
262 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
263 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
264 //NRI aName->SetValue("Visu");
266 CORBA::ORB_var anORB = Base_i::GetORB();
267 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
268 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
269 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
270 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
271 if ( !Comp->_is_nil() ) {
272 aName->SetValue( Comp->componentusername() );
275 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
276 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
277 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
279 VISU_Gen_var aVisuGen = Base_i::GetVisuGenInter();
280 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
281 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
282 aStudyBuilder->CommitCommand();
286 //===========================================================================
287 string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry,
288 const char* theComment, int IsAllLevels)
290 if(0 && MYDEBUG) MESSAGE("FindEntryWithComment - '"<<theComment<<"'");
291 SALOMEDS::ChildIterator_var anIter =
292 theStudyDocument->NewChildIterator(theStudyDocument->FindObjectID(theStartEntry));
293 anIter->InitEx(IsAllLevels);
294 SALOMEDS::SObject_var aFieldSO;
295 for(;anIter->More();anIter->Next()) {
296 SALOMEDS::GenericAttribute_var anAttr;
297 if (anIter->Value()->FindAttribute(anAttr,"AttributeComment")) {
298 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
299 CORBA::String_var aString = aCmnt->Value();
300 string aValue(aString);
301 if (aValue == theComment) {
302 aFieldSO = anIter->Value();
303 aString = aFieldSO->GetID();
311 //===========================================================================
312 string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
313 const char* theFatherEntry, const char* theRefFatherEntry,
314 const char* theIOR, const char* theName,
315 const char* thePersistentRef, const char* theComment,
316 CORBA::Boolean theCreateNew)
319 MESSAGE("CreateAttributes - theName = "<<theName<<"; theComment = '"<<theComment<<
320 "'; theFatherEntry = "<<theFatherEntry);
321 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
322 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry);
323 SALOMEDS::SObject_var newObj;
324 if (theCreateNew) newObj = aStudyBuilder->NewObject(aFather);
325 else newObj = aFather;
326 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
327 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
328 anIOR->SetValue(theIOR);
329 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
330 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
331 aName->SetValue(theName);
332 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef");
333 SALOMEDS::AttributePersistentRef_var aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
334 aPRef->SetValue(thePersistentRef);
335 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
336 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
337 aCmnt->SetValue(theComment);
338 if(strcmp(theRefFatherEntry,"") != 0){
339 SALOMEDS::SObject_var aRefFather = theStudyDocument->FindObjectID(theRefFatherEntry);
340 SALOMEDS::SObject_var anObj = aStudyBuilder->NewObject(aRefFather);
341 aStudyBuilder->Addreference(anObj,newObj);
343 CORBA::String_var anEntry = newObj->GetID();
344 string aRet(anEntry);
345 if(0 && MYDEBUG) MESSAGE("CreateAttributes - anEntry = "<<aRet<<"; IOR = "<<theIOR);
348 //===========================================================================
349 static SALOMEDS::SComponent_var VisuSComponent;
350 static string VisuTmpDir;
351 static CORBA::Boolean myIsMultiFile;
352 const CORBA::Boolean IsMultifile() {
353 return myIsMultiFile;
355 //===========================================================================
356 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr orb,
357 PortableServer::POA_ptr poa,
358 PortableServer::ObjectId * contId,
359 const char *instanceName,
360 const char *interfaceName) :
361 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
363 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<myMutex);
365 _id = _poa->activate_object(_thisObj);
366 SALOME_NamingService aNamingService(orb);
367 CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session");
368 SALOME::Session_var aSession = SALOME::Session::_narrow(anObject);
369 //aSession->GetInterface();
370 Engines::Component_var aComponent = aSession->GetVisuComponent();
371 myVisuGen = VISU::VISU_Gen::_narrow(aComponent);
374 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
375 SALOME_NamingService* theNamingService, QMutex* theMutex) :
376 Engines_Component_i()
378 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
379 Mutex mt(theMutex,qApp);
380 Base_i::myMutex = theMutex; //apo
381 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
382 Base_i::myPOA = PortableServer::POA::_duplicate(thePOA);
383 Base_i::myNamingService = theNamingService;
384 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
385 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
386 Base_i::myVisuGenImpl = this;
389 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
390 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
391 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
392 if(aListOfOpenStudies->length() > 0) {
393 CORBA::String_var aStudyName = aListOfOpenStudies[0];
394 aFileInfo.setFile(aStudyName.in());
395 myStudyDocument = aStudyManager->GetStudyByName(aFileInfo.baseName());
397 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
400 Base_i::myPOA->activate_object(this);
403 VISU_Gen_i::~VISU_Gen_i(){
404 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
406 //===========================================================================
407 bool VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
408 const SALOMEDS::TMPFile & theStream,
412 if(MYDEBUG) MESSAGE("VISU_Gen_i::Load - myMutex = "<<myMutex);
414 Mutex mt(myMutex,qApp);
415 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
416 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
417 TCollection_AsciiString aTmpDir =
418 isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
419 VisuSComponent = SALOMEDS::SComponent::_duplicate(theComponent);
420 VisuTmpDir = aTmpDir.ToCString();
421 SALOMEDS::ListOfFileNames_var aSeq =
422 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
423 myIsMultiFile = isMultiFile;
426 return myVisuGen->Load(theComponent,theStream,theURL,isMultiFile);
429 bool VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
430 const SALOMEDS::TMPFile & theStream,
433 return Load(theComponent, theStream, theURL, isMultiFile);
436 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
437 const char* aLocalPersistentID,
438 CORBA::Boolean isMultiFile,
439 CORBA::Boolean isASCII) {
441 CORBA::String_var aString("");
442 if(strcmp(aLocalPersistentID,"") != 0) {
443 Mutex mt(myMutex,qApp);
444 Storable* aStorable =
445 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
446 if(aStorable != NULL) aString = aStorable->GetID();
448 return aString._retn();
450 return myVisuGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile, isASCII);
452 //===========================================================================
453 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
457 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
459 Mutex mt(myMutex,qApp);
460 CORBA::String_var aString = SALOMEDS_Tool::GetTmpDir();
461 TCollection_AsciiString aTmpDir = isMultiFile? (const Standard_CString)theURL: (const Standard_CString)aString.in();
462 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
464 TColStd_SequenceOfAsciiString aFileNames;
465 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
466 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
467 for (; itBig->More(); itBig->Next()) {
468 SALOMEDS::SObject_var gotBranch = itBig->Value();
469 CORBA::Object_var anObj = SObjectToObject(gotBranch);
470 if(CORBA::is_nil(anObj)) continue;
471 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
472 if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){
473 const QFileInfo& aFileInfo = pResult->GetFileInfo();
474 QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
475 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
476 static QString aCommand;
477 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
478 if(system(aCommand) == -1){
479 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
482 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
483 TCollection_AsciiString aString(strdup(aFileName.latin1()));
484 aFileNames.Append(aString);
487 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
488 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
489 if(aFileNames.Length() > 0){
490 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
491 aSeq->length(aFileNames.Length());
492 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
493 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
494 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
496 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
498 return aStreamFile._retn();
500 return myVisuGen->Save(theComponent,theURL,isMultiFile);
503 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
506 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
508 Mutex mt(myMutex,qApp);
509 CORBA::String_var aString = SALOMEDS_Tool::GetTmpDir();
510 TCollection_AsciiString aTmpDir = isMultiFile? (const Standard_CString)theURL: (const Standard_CString)aString.in();
511 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
513 TColStd_SequenceOfAsciiString aFileNames;
514 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
515 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
516 for (; itBig->More(); itBig->Next()) {
517 SALOMEDS::SObject_var gotBranch = itBig->Value();
518 CORBA::Object_var anObj = SObjectToObject(gotBranch);
519 if(CORBA::is_nil(anObj)) continue;
520 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
521 if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){
522 const QFileInfo& aFileInfo = pResult->GetFileInfo();
523 QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
524 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
525 static QString aCommand;
526 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
528 if(system(aCommand) == -1){
529 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
532 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
533 TCollection_AsciiString aString(strdup(aFileName.latin1()));
535 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
537 aFileNames.Append(aString);
540 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
541 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
542 if(aFileNames.Length() > 0){
543 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
544 aSeq->length(aFileNames.Length());
545 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
546 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
547 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
549 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
551 return aStreamFile._retn();
553 return myVisuGen->Save(theComponent,theURL,isMultiFile);
556 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
557 const char* IORString,
558 CORBA::Boolean isMultiFile,
559 CORBA::Boolean isASCII) {
560 if(MYDEBUG) MESSAGE("VISU_Gen_i::IORToLocalPersistentID - myMutex = "<<myMutex);
562 CORBA::String_var aString(IORString);
563 if(strcmp(IORString,"") != 0){
564 CORBA::ORB_ptr anORB = GetORB();
565 CORBA::Object_var anObj = anORB->string_to_object(aString);
566 if(!CORBA::is_nil(anObj)){
567 Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj));
568 if(pStorable != NULL){
569 Mutex mt(myMutex,qApp);
570 aString = pStorable->ToString().c_str();
571 return aString._retn();
575 return aString._retn();
577 return myVisuGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile, isASCII);
580 void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
581 //if(MYDEBUG) MESSAGE("VISU_Gen_i::SetCurrentStudy : "<<(!theStudy->_is_nil()));
583 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
585 myVisuGen->SetCurrentStudy(theStudy);
587 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
588 if(MYDEBUG) MESSAGE("VISU_Gen_i::GetCurrentStudy : "<<myMutex);
590 return SALOMEDS::Study::_duplicate(myStudyDocument);
591 return myVisuGen->GetCurrentStudy();
593 ViewManager_ptr VISU_Gen_i::GetViewManager(){
595 //omni_mutex_lock aMutexLock(aMutex);
596 if(MYDEBUG) MESSAGE("VISU_Gen_i::GetViewManager : "<<myMutex);
598 Mutex mt(myMutex,qApp);
599 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
600 return ViewManager::_duplicate(aViewManager->_this());
602 return myVisuGen->GetViewManager();
605 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
607 if(myStudyDocument->GetProperties()->IsLocked()) return SALOMEDS::SObject::_nil();
608 Mutex mt(myMutex,qApp);
609 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
612 return myVisuGen->ImportTables(theFileName);
615 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
617 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
618 Mutex mt(myMutex,qApp);
619 aFileInfo.setFile(theFileName);
620 Result_i* pResult = new Result_i(myStudyDocument);
621 if(pResult->Create(theFileName) != NULL)
622 return Result::_duplicate(pResult->_this());
623 return Result::_nil();
625 return myVisuGen->ImportFile(theFileName);
628 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject){
629 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMed : "<<myMutex);
631 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
632 Mutex mt(myMutex,qApp);
633 Result_i* pResult = new Result_i(myStudyDocument);
634 if(pResult->Create(theMedSObject) != NULL)
635 return Result::_duplicate(pResult->_this());
636 return Result::_nil();
638 return myVisuGen->ImportMed(theMedSObject);
641 Result_ptr VISU_Gen_i::ImportMedField(SALOME_MED::FIELD_ptr theField){
642 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedField : "<<myMutex);
644 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
645 Mutex mt(myMutex,qApp);
646 Result_i* pResult = new Result_i(myStudyDocument);
647 if(pResult->Create(theField) != NULL)
648 return Result::_duplicate(pResult->_this());
649 return Result::_nil();
651 return myVisuGen->ImportMedField(theField);
654 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity){
655 if(MYDEBUG) MESSAGE("VISU_Gen_i::MeshOnEntity : "<<myMutex);
657 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
658 Mutex mt(myMutex,qApp);
659 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
660 Mesh_i* aPresent = new Mesh_i(pResult);
661 if(aPresent->Create(theMeshName,theEntity) != NULL)
662 return Mesh::_duplicate(aPresent->_this());
665 return myVisuGen->MeshOnEntity(theResult,theMeshName,theEntity);
668 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName,
669 VISU::Entity theEntity,
670 const char* theFamilyName){
671 if(MYDEBUG) MESSAGE("VISU_Gen_i::FamilyMeshOnEntity : "<<myMutex);
673 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
674 Mutex mt(myMutex,qApp);
675 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
676 Mesh_i* aPresent = new Mesh_i(pResult);
677 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
678 return Mesh::_duplicate(aPresent->_this());
681 return myVisuGen->FamilyMeshOnEntity(theResult,theMeshName,theEntity,theFamilyName);
684 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, const char* theMeshName,
685 const char* theGroupName){
686 if(MYDEBUG) MESSAGE("VISU_Gen_i::GroupMesh : "<<myMutex);
688 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
689 Mutex mt(myMutex,qApp);
690 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
691 Mesh_i* aPresent = new Mesh_i(pResult);
692 if(aPresent->Create(theMeshName,theGroupName) != NULL)
693 return Mesh::_duplicate(aPresent->_this());
696 return myVisuGen->GroupMesh(theResult,theMeshName,theGroupName);
699 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
700 const char* theFieldName, CORBA::Double theIteration){
701 if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
703 if(myStudyDocument->GetProperties()->IsLocked()) return ScalarMap::_nil();
704 Mutex mt(myMutex,qApp);
705 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
706 if(ScalarMap_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
707 ScalarMap_i* aPresent = new ScalarMap_i(pResult);
708 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL){
709 //Base_i::myPOA->activate_object(aPresent);
710 //aPresent->_remove_ref();
711 return aPresent->_this();
714 return ScalarMap::_nil();
716 return myVisuGen->ScalarMapOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
719 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
720 const char* theFieldName, CORBA::Double theIteration){
721 if(MYDEBUG) MESSAGE("VISU_Gen_i::DeformedShapeOnField : "<<myMutex);
723 if(myStudyDocument->GetProperties()->IsLocked()) return DeformedShape::_nil();
724 Mutex mt(myMutex,qApp);
725 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
726 if(DeformedShape_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
727 DeformedShape_i* aPresent = new DeformedShape_i(pResult);
728 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
729 return DeformedShape::_duplicate(aPresent->_this());
731 return DeformedShape::_nil();
733 return myVisuGen->DeformedShapeOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
736 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
737 const char* theFieldName, CORBA::Double theIteration){
738 if(MYDEBUG) MESSAGE("VISU_Gen_i::VectorsOnField : "<<myMutex);
740 if(myStudyDocument->GetProperties()->IsLocked()) return Vectors::_nil();
741 Mutex mt(myMutex,qApp);
742 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
743 if(Vectors_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
744 Vectors_i* aPresent = new Vectors_i(pResult);
745 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
746 return Vectors::_duplicate(aPresent->_this());
748 return Vectors::_nil();
750 return myVisuGen->VectorsOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
753 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
754 const char* theFieldName, CORBA::Double theIteration){
755 if(MYDEBUG) MESSAGE("VISU_Gen_i::IsoSurfacesOnField : "<<myMutex);
757 if(myStudyDocument->GetProperties()->IsLocked()) return IsoSurfaces::_nil();
758 Mutex mt(myMutex,qApp);
759 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
760 if(IsoSurfaces_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
761 IsoSurfaces_i* aPresent = new IsoSurfaces_i(pResult);
762 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
763 return IsoSurfaces::_duplicate(aPresent->_this());
765 return IsoSurfaces::_nil();
767 return myVisuGen->IsoSurfacesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
770 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
771 const char* theFieldName, CORBA::Double theIteration){
772 if(MYDEBUG) MESSAGE("VISU_Gen_i::StreamLinesOnField : "<<myMutex);
774 if(myStudyDocument->GetProperties()->IsLocked()) return StreamLines::_nil();
775 Mutex mt(myMutex,qApp);
776 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
777 if(StreamLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
778 StreamLines_i* aPresent = new StreamLines_i(pResult);
779 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
780 return StreamLines::_duplicate(aPresent->_this());
782 return StreamLines::_nil();
784 return myVisuGen->StreamLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
787 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
788 const char* theFieldName, CORBA::Double theIteration){
789 if(MYDEBUG) MESSAGE("VISU_Gen_i::CutPlanesOnField : "<<myMutex);
791 if(myStudyDocument->GetProperties()->IsLocked()) return CutPlanes::_nil();
792 Mutex mt(myMutex,qApp);
793 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
794 if(CutPlanes_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
795 CutPlanes_i* aPresent = new CutPlanes_i(pResult);
796 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
797 return CutPlanes::_duplicate(aPresent->_this());
799 return CutPlanes::_nil();
801 return myVisuGen->CutPlanesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
804 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
805 const char* theFieldName, CORBA::Double theIteration){
806 if(MYDEBUG) MESSAGE("VISU_Gen_i::CutLinesOnField : "<<myMutex);
808 if(myStudyDocument->GetProperties()->IsLocked()) return CutLines::_nil();
809 Mutex mt(myMutex,qApp);
810 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
811 if(CutLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
812 CutLines_i* aPresent = new CutLines_i(pResult);
813 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
814 return CutLines::_duplicate(aPresent->_this());
816 return CutLines::_nil();
818 return myVisuGen->CutLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
821 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
822 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateTable : "<<myMutex);
824 if(myStudyDocument->GetProperties()->IsLocked()) return Table::_nil();
825 Mutex mt(myMutex,qApp);
826 Table_i* aPresent = new Table_i(myStudyDocument,theTableEntry);
827 if(aPresent->Create() != NULL)
828 return Table::_duplicate(aPresent->_this());
829 return Table::_nil();
831 return myVisuGen->CreateTable(theTableEntry);
834 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow){
835 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateCurve : "<<myMutex);
837 if(myStudyDocument->GetProperties()->IsLocked()) return Curve::_nil();
838 Mutex mt(myMutex,qApp);
839 PortableServer::POA_ptr aPOA = GetPOA();
840 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
841 Curve_i* aPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
842 if(aPresent->Create() != NULL) {
843 return Curve::_duplicate(aPresent->_this());
845 return Curve::_nil();
847 return myVisuGen->CreateCurve(theTable,theHRow,theVRow);
849 Container_ptr VISU_Gen_i::CreateContainer(){
850 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateContainer : "<<myMutex);
852 if(myStudyDocument->GetProperties()->IsLocked()) return Container::_nil();
853 Mutex mt(myMutex,qApp);
854 Container_i* aPresent = new Container_i(myStudyDocument);
855 if(aPresent->Create() != NULL) {
856 return Container::_duplicate(aPresent->_this());
858 return Container::_nil();
860 return myVisuGen->CreateContainer();
863 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
865 if(myStudyDocument->GetProperties()->IsLocked()) return Animation::_nil();
866 Mutex mt(myMutex,qApp);
867 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateAnimation : "<<myMutex);
868 VISU_TimeAnimation* anAnim = new VISU_TimeAnimation(myStudyDocument,theView3D);
869 return Animation::_duplicate(anAnim->_this());
871 return myVisuGen->CreateAnimation(theView3D);
874 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
875 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : "<<myMutex);
877 Mutex mt(myMutex,qApp);
878 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
879 if(!aStudy->_is_nil()){
880 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
881 for (int i = 0; itBig->More(); itBig->Next(),i++) {
882 SALOMEDS::SObject_var gotBranch = itBig->Value();
883 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : itBig->Next() = "<<i);
884 CORBA::Object_var anObj = SObjectToObject(gotBranch);
885 if(CORBA::is_nil(anObj)) continue;
886 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
887 if(!pResult) continue;
888 if(pResult->GetSourceId() == Result_i::eRestoredFile){ //Try remove its file and directory
889 const QFileInfo& aFileInfo = pResult->GetFileInfo();
890 static QString aCommand;
891 aCommand.sprintf("rm %s",aFileInfo.filePath().latin1());
892 if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
893 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",aFileInfo.dirPath().latin1());
894 if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
900 myVisuGen->Close(theComponent);
903 char* VISU_Gen_i::ComponentDataType(){
904 return CORBA::string_dup("VISU");
907 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
908 Result_var aResultObj = Result::_narrow(theIOR);
909 return !(aResultObj->_is_nil());
912 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
913 SALOMEDS::SObject_ptr theSObject,
914 CORBA::Object_ptr theObject,
916 throw (SALOME::SALOME_Exception)
918 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
920 Mutex mt(myMutex,qApp);
921 SALOMEDS::SObject_var aResultSO;
922 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject));
923 if (!aResultObj) return aResultSO._retn();
924 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
925 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
926 aResultSO = theStudy->FindObjectID(anEntry);
927 return aResultSO._retn();
929 return myVisuGen->PublishInStudy(theStudy, theSObject, theObject, theName);
932 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
933 if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanCopy : "<<myMutex);
935 //Mutex mt(myMutex,qApp);
936 SALOMEDS::GenericAttribute_var anAttr;
937 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
939 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
940 CORBA::String_var aValue = anIOR->Value();
941 if(strcmp(aValue,"") != 0){
942 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
943 if (!CORBA::is_nil(anObj)){
944 Result_var aResultObj = Result::_narrow(anObj);
945 if(!aResultObj->_is_nil()){
946 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj));
948 if(abs(pResult->GetSourceId()) > Result_i::eFile)
949 if((pResult->GetFileInfo()).filePath() == "Med") return false;
956 MESSAGE("Unknown exception was accured!");
960 return myVisuGen->CanCopy(theObject);
963 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
964 if(MYDEBUG) MESSAGE("VISU_Gen_i::CopyFrom : "<<myMutex);
966 Mutex mt(myMutex,qApp);
969 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
970 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
972 PortableServer::POA_ptr aPOA = GetPOA();
974 SALOMEDS::GenericAttribute_var anAttr;
975 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
976 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
977 CORBA::Object_var aCorbaObj;
979 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
981 aStreamFile->length(1);
982 aStreamFile[0] = strdup("E")[0];
983 return aStreamFile._retn();
985 if (CORBA::is_nil(aCorbaObj)) {
989 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj));
993 CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
995 string aStr = pStorable->ToString().c_str();
996 ofstream stmOut2((string(aTmpDir) + string("copy_persistent")).c_str(),ios::out);
1000 Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj));
1002 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
1003 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1004 aFileName += aFileInfo.fileName().latin1();
1005 static QString aCommand;
1006 aCommand.sprintf("cp %s %s",
1007 aFileInfo.filePath().latin1(),
1008 (string(aTmpDir) + aFileName).c_str());
1009 if(system(aCommand) == -1) {
1010 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
1015 aSeq[0] = "copy_persistent";
1016 aSeq[1] = aFileName.c_str();
1019 aSeq[0] = "copy_persistent";
1021 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
1022 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
1024 // Assign an ID = 1 the the type VISU::Result
1026 return aStreamFile._retn();
1028 return myVisuGen->CopyFrom(theObject, theObjectID);
1031 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1032 // The VISU component can paste only objects copied by VISU component
1033 // and with the object type = 1
1034 if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanPaste : "<<myMutex);
1035 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
1039 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
1040 CORBA::Long theObjectID,
1041 SALOMEDS::SObject_ptr theObject) {
1042 if(MYDEBUG) MESSAGE("VISU_Gen_i::PasteInto : "<<myMutex);
1044 Mutex mt(myMutex,qApp);
1045 SALOMEDS::SObject_var aResultSO;
1046 if (theObjectID != 1) return aResultSO._retn();
1048 CORBA::String_var aTmpDir = (const char*)SALOMEDS_Tool::GetTmpDir();
1049 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1051 ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str());
1052 // ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str(),ios::in);
1053 stmIn.seekg(0, ios::end);
1054 int aLength = stmIn.tellg();
1055 stmIn.seekg(0, ios::beg);
1056 char* aString = new char[aLength+1];
1057 stmIn.read(aString, aLength);
1058 aString[aLength] = 0;
1059 myIsMultiFile = true;
1061 string aFileName(aTmpDir.in());
1062 if(aSeq->length() > 1) aFileName += aSeq[1].in();
1063 Storable* aStorable = Storable::Create(theObject,aFileName,aString);
1065 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
1066 aSeqToRm->length(1);
1067 aSeqToRm[0] = "copy_persistent";
1068 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeqToRm.in(), true);
1070 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
1071 SALOMEDS::Study_var aStudy = theObject->GetStudy();
1072 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1073 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
1074 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
1075 aResultSO = aStudyBuilder->NewObject(aComponent);
1077 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
1078 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1079 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1080 CORBA::String_var anIORValue(aStorable->GetID());
1081 anIOR->SetValue(anIORValue);
1082 return aResultSO._retn();
1084 return myVisuGen->PasteInto(theStream,theObjectID,theObject);