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"
23 #include <TCollection_AsciiString.hxx>
24 #include <TColStd_SequenceOfAsciiString.hxx>
25 #include <vtkUnstructuredGridReader.h>
26 #include <vtkUnstructuredGridWriter.h>
28 #include <omnithread.h>
29 #include CORBA_SERVER_HEADER(SALOME_Session)
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 aName->SetValue("Visu");
266 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
267 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
268 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
270 VISU_Gen_var aVisuGen = Base_i::GetVisuGenInter();
271 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
272 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
273 aStudyBuilder->CommitCommand();
277 //===========================================================================
278 string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry,
279 const char* theComment, int IsAllLevels)
281 if(0 && MYDEBUG) MESSAGE("FindEntryWithComment - '"<<theComment<<"'");
282 SALOMEDS::ChildIterator_var anIter =
283 theStudyDocument->NewChildIterator(theStudyDocument->FindObjectID(theStartEntry));
284 anIter->InitEx(IsAllLevels);
285 SALOMEDS::SObject_var aFieldSO;
286 for(;anIter->More();anIter->Next()) {
287 SALOMEDS::GenericAttribute_var anAttr;
288 if (anIter->Value()->FindAttribute(anAttr,"AttributeComment")) {
289 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
290 CORBA::String_var aString = aCmnt->Value();
291 string aValue(aString);
292 if (aValue == theComment) {
293 aFieldSO = anIter->Value();
294 aString = aFieldSO->GetID();
302 //===========================================================================
303 string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
304 const char* theFatherEntry, const char* theRefFatherEntry,
305 const char* theIOR, const char* theName,
306 const char* thePersistentRef, const char* theComment,
307 CORBA::Boolean theCreateNew)
310 MESSAGE("CreateAttributes - theName = "<<theName<<"; theComment = '"<<theComment<<
311 "'; theFatherEntry = "<<theFatherEntry);
312 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
313 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry);
314 SALOMEDS::SObject_var newObj;
315 if (theCreateNew) newObj = aStudyBuilder->NewObject(aFather);
316 else newObj = aFather;
317 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
318 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
319 anIOR->SetValue(theIOR);
320 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
321 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
322 aName->SetValue(theName);
323 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef");
324 SALOMEDS::AttributePersistentRef_var aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
325 aPRef->SetValue(thePersistentRef);
326 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
327 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
328 aCmnt->SetValue(theComment);
329 if(strcmp(theRefFatherEntry,"") != 0){
330 SALOMEDS::SObject_var aRefFather = theStudyDocument->FindObjectID(theRefFatherEntry);
331 SALOMEDS::SObject_var anObj = aStudyBuilder->NewObject(aRefFather);
332 aStudyBuilder->Addreference(anObj,newObj);
334 CORBA::String_var anEntry = newObj->GetID();
335 string aRet(anEntry);
336 if(0 && MYDEBUG) MESSAGE("CreateAttributes - anEntry = "<<aRet<<"; IOR = "<<theIOR);
339 //===========================================================================
340 static SALOMEDS::SComponent_var VisuSComponent;
341 static string VisuTmpDir;
342 static CORBA::Boolean myIsMultiFile;
343 const CORBA::Boolean IsMultifile() {
344 return myIsMultiFile;
346 //===========================================================================
347 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr orb,
348 PortableServer::POA_ptr poa,
349 PortableServer::ObjectId * contId,
350 const char *instanceName,
351 const char *interfaceName) :
352 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
354 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<myMutex);
356 _id = _poa->activate_object(_thisObj);
357 SALOME_NamingService aNamingService(orb);
358 CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session");
359 SALOME::Session_var aSession = SALOME::Session::_narrow(anObject);
360 //aSession->GetInterface();
361 Engines::Component_var aComponent = aSession->GetVisuGen();
362 myVisuGen = VISU::VISU_Gen::_narrow(aComponent);
365 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
366 SALOME_NamingService* theNamingService, QMutex* theMutex) :
367 Engines_Component_i()
369 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
370 Mutex mt(theMutex,qApp);
371 Base_i::myMutex = theMutex; //apo
372 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
373 Base_i::myPOA = PortableServer::POA::_duplicate(thePOA);
374 Base_i::myNamingService = theNamingService;
375 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
376 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
377 Base_i::myVisuGenImpl = this;
380 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
381 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
382 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
383 if(aListOfOpenStudies->length() > 0) {
384 CORBA::String_var aStudyName = aListOfOpenStudies[0];
385 aFileInfo.setFile(aStudyName.in());
386 myStudyDocument = aStudyManager->GetStudyByName(aFileInfo.baseName());
388 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
391 Base_i::myPOA->activate_object(this);
394 VISU_Gen_i::~VISU_Gen_i(){
395 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
397 //===========================================================================
398 bool VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
399 const SALOMEDS::TMPFile & theStream,
403 if(MYDEBUG) MESSAGE("VISU_Gen_i::Load - myMutex = "<<myMutex);
405 Mutex mt(myMutex,qApp);
406 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
407 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
408 TCollection_AsciiString aTmpDir =
409 isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
410 VisuSComponent = SALOMEDS::SComponent::_duplicate(theComponent);
411 VisuTmpDir = aTmpDir.ToCString();
412 SALOMEDS::ListOfFileNames_var aSeq =
413 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
414 myIsMultiFile = isMultiFile;
417 return myVisuGen->Load(theComponent,theStream,theURL,isMultiFile);
420 bool VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
421 const SALOMEDS::TMPFile & theStream,
424 return Load(theComponent, theStream, theURL, isMultiFile);
427 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
428 const char* aLocalPersistentID,
429 CORBA::Boolean isMultiFile,
430 CORBA::Boolean isASCII) {
432 CORBA::String_var aString("");
433 if(strcmp(aLocalPersistentID,"") != 0) {
434 Mutex mt(myMutex,qApp);
435 Storable* aStorable =
436 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
437 if(aStorable != NULL) aString = aStorable->GetID();
439 return aString._retn();
441 return myVisuGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile, isASCII);
443 //===========================================================================
444 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
448 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
450 Mutex mt(myMutex,qApp);
451 CORBA::String_var aString = SALOMEDS_Tool::GetTmpDir();
452 TCollection_AsciiString aTmpDir = isMultiFile? (const Standard_CString)theURL: (const Standard_CString)aString.in();
453 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
455 TColStd_SequenceOfAsciiString aFileNames;
456 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
457 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
458 for (; itBig->More(); itBig->Next()) {
459 SALOMEDS::SObject_var gotBranch = itBig->Value();
460 CORBA::Object_var anObj = SObjectToObject(gotBranch);
461 if(CORBA::is_nil(anObj)) continue;
462 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
463 if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){
464 const QFileInfo& aFileInfo = pResult->GetFileInfo();
465 QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
466 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
467 static QString aCommand;
468 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
469 if(system(aCommand) == -1){
470 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
473 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
474 TCollection_AsciiString aString(strdup(aFileName.latin1()));
475 aFileNames.Append(aString);
478 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
479 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
480 if(aFileNames.Length() > 0){
481 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
482 aSeq->length(aFileNames.Length());
483 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
484 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
485 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
487 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
489 return aStreamFile._retn();
491 return myVisuGen->Save(theComponent,theURL,isMultiFile);
494 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
497 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
499 Mutex mt(myMutex,qApp);
500 CORBA::String_var aString = SALOMEDS_Tool::GetTmpDir();
501 TCollection_AsciiString aTmpDir = isMultiFile? (const Standard_CString)theURL: (const Standard_CString)aString.in();
502 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
504 TColStd_SequenceOfAsciiString aFileNames;
505 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
506 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
507 for (; itBig->More(); itBig->Next()) {
508 SALOMEDS::SObject_var gotBranch = itBig->Value();
509 CORBA::Object_var anObj = SObjectToObject(gotBranch);
510 if(CORBA::is_nil(anObj)) continue;
511 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
512 if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){
513 const QFileInfo& aFileInfo = pResult->GetFileInfo();
514 QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
515 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
516 static QString aCommand;
517 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
519 if(system(aCommand) == -1){
520 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
523 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
524 TCollection_AsciiString aString(strdup(aFileName.latin1()));
526 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
528 aFileNames.Append(aString);
531 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
532 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
533 if(aFileNames.Length() > 0){
534 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
535 aSeq->length(aFileNames.Length());
536 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
537 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
538 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
540 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
542 return aStreamFile._retn();
544 return myVisuGen->Save(theComponent,theURL,isMultiFile);
547 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
548 const char* IORString,
549 CORBA::Boolean isMultiFile,
550 CORBA::Boolean isASCII) {
551 if(MYDEBUG) MESSAGE("VISU_Gen_i::IORToLocalPersistentID - myMutex = "<<myMutex);
553 CORBA::String_var aString(IORString);
554 if(strcmp(IORString,"") != 0){
555 CORBA::ORB_ptr anORB = GetORB();
556 CORBA::Object_var anObj = anORB->string_to_object(aString);
557 if(!CORBA::is_nil(anObj)){
558 Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj));
559 if(pStorable != NULL){
560 Mutex mt(myMutex,qApp);
561 aString = pStorable->ToString().c_str();
562 return aString._retn();
566 return aString._retn();
568 return myVisuGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile, isASCII);
571 void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
572 //if(MYDEBUG) MESSAGE("VISU_Gen_i::SetCurrentStudy : "<<(!theStudy->_is_nil()));
574 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
576 myVisuGen->SetCurrentStudy(theStudy);
578 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
579 if(MYDEBUG) MESSAGE("VISU_Gen_i::GetCurrentStudy : "<<myMutex);
581 return SALOMEDS::Study::_duplicate(myStudyDocument);
582 return myVisuGen->GetCurrentStudy();
584 ViewManager_ptr VISU_Gen_i::GetViewManager(){
586 //omni_mutex_lock aMutexLock(aMutex);
587 if(MYDEBUG) MESSAGE("VISU_Gen_i::GetViewManager : "<<myMutex);
589 Mutex mt(myMutex,qApp);
590 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
591 return ViewManager::_duplicate(aViewManager->_this());
593 return myVisuGen->GetViewManager();
596 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
598 if(myStudyDocument->GetProperties()->IsLocked()) return SALOMEDS::SObject::_nil();
599 Mutex mt(myMutex,qApp);
600 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
603 return myVisuGen->ImportTables(theFileName);
606 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
608 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
609 Mutex mt(myMutex,qApp);
610 aFileInfo.setFile(theFileName);
611 Result_i* pResult = new Result_i(myStudyDocument);
612 if(pResult->Create(theFileName) != NULL)
613 return Result::_duplicate(pResult->_this());
614 return Result::_nil();
616 return myVisuGen->ImportFile(theFileName);
619 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject){
620 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMed : "<<myMutex);
622 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
623 Mutex mt(myMutex,qApp);
624 Result_i* pResult = new Result_i(myStudyDocument);
625 if(pResult->Create(theMedSObject) != NULL)
626 return Result::_duplicate(pResult->_this());
627 return Result::_nil();
629 return myVisuGen->ImportMed(theMedSObject);
632 Result_ptr VISU_Gen_i::ImportMedField(SALOME_MED::FIELD_ptr theField){
633 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedField : "<<myMutex);
635 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
636 Mutex mt(myMutex,qApp);
637 Result_i* pResult = new Result_i(myStudyDocument);
638 if(pResult->Create(theField) != NULL)
639 return Result::_duplicate(pResult->_this());
640 return Result::_nil();
642 return myVisuGen->ImportMedField(theField);
645 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity){
646 if(MYDEBUG) MESSAGE("VISU_Gen_i::MeshOnEntity : "<<myMutex);
648 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
649 Mutex mt(myMutex,qApp);
650 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
651 Mesh_i* aPresent = new Mesh_i(pResult);
652 if(aPresent->Create(theMeshName,theEntity) != NULL)
653 return Mesh::_duplicate(aPresent->_this());
656 return myVisuGen->MeshOnEntity(theResult,theMeshName,theEntity);
659 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName,
660 VISU::Entity theEntity,
661 const char* theFamilyName){
662 if(MYDEBUG) MESSAGE("VISU_Gen_i::FamilyMeshOnEntity : "<<myMutex);
664 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
665 Mutex mt(myMutex,qApp);
666 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
667 Mesh_i* aPresent = new Mesh_i(pResult);
668 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
669 return Mesh::_duplicate(aPresent->_this());
672 return myVisuGen->FamilyMeshOnEntity(theResult,theMeshName,theEntity,theFamilyName);
675 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, const char* theMeshName,
676 const char* theGroupName){
677 if(MYDEBUG) MESSAGE("VISU_Gen_i::GroupMesh : "<<myMutex);
679 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
680 Mutex mt(myMutex,qApp);
681 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
682 Mesh_i* aPresent = new Mesh_i(pResult);
683 if(aPresent->Create(theMeshName,theGroupName) != NULL)
684 return Mesh::_duplicate(aPresent->_this());
687 return myVisuGen->GroupMesh(theResult,theMeshName,theGroupName);
690 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
691 const char* theFieldName, CORBA::Double theIteration){
692 if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
694 if(myStudyDocument->GetProperties()->IsLocked()) return ScalarMap::_nil();
695 Mutex mt(myMutex,qApp);
696 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
697 if(ScalarMap_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
698 ScalarMap_i* aPresent = new ScalarMap_i(pResult);
699 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL){
700 //Base_i::myPOA->activate_object(aPresent);
701 //aPresent->_remove_ref();
702 return aPresent->_this();
705 return ScalarMap::_nil();
707 return myVisuGen->ScalarMapOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
710 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
711 const char* theFieldName, CORBA::Double theIteration){
712 if(MYDEBUG) MESSAGE("VISU_Gen_i::DeformedShapeOnField : "<<myMutex);
714 if(myStudyDocument->GetProperties()->IsLocked()) return DeformedShape::_nil();
715 Mutex mt(myMutex,qApp);
716 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
717 if(DeformedShape_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
718 DeformedShape_i* aPresent = new DeformedShape_i(pResult);
719 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
720 return DeformedShape::_duplicate(aPresent->_this());
722 return DeformedShape::_nil();
724 return myVisuGen->DeformedShapeOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
727 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
728 const char* theFieldName, CORBA::Double theIteration){
729 if(MYDEBUG) MESSAGE("VISU_Gen_i::VectorsOnField : "<<myMutex);
731 if(myStudyDocument->GetProperties()->IsLocked()) return Vectors::_nil();
732 Mutex mt(myMutex,qApp);
733 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
734 if(Vectors_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
735 Vectors_i* aPresent = new Vectors_i(pResult);
736 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
737 return Vectors::_duplicate(aPresent->_this());
739 return Vectors::_nil();
741 return myVisuGen->VectorsOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
744 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
745 const char* theFieldName, CORBA::Double theIteration){
746 if(MYDEBUG) MESSAGE("VISU_Gen_i::IsoSurfacesOnField : "<<myMutex);
748 if(myStudyDocument->GetProperties()->IsLocked()) return IsoSurfaces::_nil();
749 Mutex mt(myMutex,qApp);
750 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
751 if(IsoSurfaces_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
752 IsoSurfaces_i* aPresent = new IsoSurfaces_i(pResult);
753 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
754 return IsoSurfaces::_duplicate(aPresent->_this());
756 return IsoSurfaces::_nil();
758 return myVisuGen->IsoSurfacesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
761 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
762 const char* theFieldName, CORBA::Double theIteration){
763 if(MYDEBUG) MESSAGE("VISU_Gen_i::StreamLinesOnField : "<<myMutex);
765 if(myStudyDocument->GetProperties()->IsLocked()) return StreamLines::_nil();
766 Mutex mt(myMutex,qApp);
767 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
768 if(StreamLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
769 StreamLines_i* aPresent = new StreamLines_i(pResult);
770 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
771 return StreamLines::_duplicate(aPresent->_this());
773 return StreamLines::_nil();
775 return myVisuGen->StreamLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
778 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
779 const char* theFieldName, CORBA::Double theIteration){
780 if(MYDEBUG) MESSAGE("VISU_Gen_i::CutPlanesOnField : "<<myMutex);
782 if(myStudyDocument->GetProperties()->IsLocked()) return CutPlanes::_nil();
783 Mutex mt(myMutex,qApp);
784 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
785 if(CutPlanes_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
786 CutPlanes_i* aPresent = new CutPlanes_i(pResult);
787 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
788 return CutPlanes::_duplicate(aPresent->_this());
790 return CutPlanes::_nil();
792 return myVisuGen->CutPlanesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
795 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
796 const char* theFieldName, CORBA::Double theIteration){
797 if(MYDEBUG) MESSAGE("VISU_Gen_i::CutLinesOnField : "<<myMutex);
799 if(myStudyDocument->GetProperties()->IsLocked()) return CutLines::_nil();
800 Mutex mt(myMutex,qApp);
801 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
802 if(CutLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
803 CutLines_i* aPresent = new CutLines_i(pResult);
804 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
805 return CutLines::_duplicate(aPresent->_this());
807 return CutLines::_nil();
809 return myVisuGen->CutLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
812 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
813 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateTable : "<<myMutex);
815 if(myStudyDocument->GetProperties()->IsLocked()) return Table::_nil();
816 Mutex mt(myMutex,qApp);
817 Table_i* aPresent = new Table_i(myStudyDocument,theTableEntry);
818 if(aPresent->Create() != NULL)
819 return Table::_duplicate(aPresent->_this());
820 return Table::_nil();
822 return myVisuGen->CreateTable(theTableEntry);
825 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow){
826 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateCurve : "<<myMutex);
828 if(myStudyDocument->GetProperties()->IsLocked()) return Curve::_nil();
829 Mutex mt(myMutex,qApp);
830 PortableServer::POA_ptr aPOA = GetPOA();
831 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
832 Curve_i* aPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
833 if(aPresent->Create() != NULL) {
834 return Curve::_duplicate(aPresent->_this());
836 return Curve::_nil();
838 return myVisuGen->CreateCurve(theTable,theHRow,theVRow);
840 Container_ptr VISU_Gen_i::CreateContainer(){
841 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateContainer : "<<myMutex);
843 if(myStudyDocument->GetProperties()->IsLocked()) return Container::_nil();
844 Mutex mt(myMutex,qApp);
845 Container_i* aPresent = new Container_i(myStudyDocument);
846 if(aPresent->Create() != NULL) {
847 return Container::_duplicate(aPresent->_this());
849 return Container::_nil();
851 return myVisuGen->CreateContainer();
854 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
856 if(myStudyDocument->GetProperties()->IsLocked()) return Animation::_nil();
857 Mutex mt(myMutex,qApp);
858 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateAnimation : "<<myMutex);
859 VISU_TimeAnimation* anAnim = new VISU_TimeAnimation(myStudyDocument,theView3D);
860 return Animation::_duplicate(anAnim->_this());
862 return myVisuGen->CreateAnimation(theView3D);
865 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
866 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : "<<myMutex);
868 Mutex mt(myMutex,qApp);
869 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
870 if(!aStudy->_is_nil()){
871 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
872 for (int i = 0; itBig->More(); itBig->Next(),i++) {
873 SALOMEDS::SObject_var gotBranch = itBig->Value();
874 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : itBig->Next() = "<<i);
875 CORBA::Object_var anObj = SObjectToObject(gotBranch);
876 if(CORBA::is_nil(anObj)) continue;
877 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
878 if(!pResult) continue;
879 if(pResult->GetSourceId() == Result_i::eRestoredFile){ //Try remove its file and directory
880 const QFileInfo& aFileInfo = pResult->GetFileInfo();
881 static QString aCommand;
882 aCommand.sprintf("rm %s",aFileInfo.filePath().latin1());
883 if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
884 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",aFileInfo.dirPath().latin1());
885 if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
891 myVisuGen->Close(theComponent);
894 char* VISU_Gen_i::ComponentDataType(){
895 return CORBA::string_dup("VISU");
898 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
899 Result_var aResultObj = Result::_narrow(theIOR);
900 return !(aResultObj->_is_nil());
903 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
904 SALOMEDS::SObject_ptr theSObject,
905 CORBA::Object_ptr theObject,
907 throw (SALOME::SALOME_Exception)
909 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
911 Mutex mt(myMutex,qApp);
912 SALOMEDS::SObject_var aResultSO;
913 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject));
914 if (!aResultObj) return aResultSO._retn();
915 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
916 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
917 aResultSO = theStudy->FindObjectID(anEntry);
918 return aResultSO._retn();
920 return myVisuGen->PublishInStudy(theStudy, theSObject, theObject, theName);
923 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
924 if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanCopy : "<<myMutex);
926 //Mutex mt(myMutex,qApp);
927 SALOMEDS::GenericAttribute_var anAttr;
928 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
930 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
931 CORBA::String_var aValue = anIOR->Value();
932 if(strcmp(aValue,"") != 0){
933 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
934 if (!CORBA::is_nil(anObj)){
935 Result_var aResultObj = Result::_narrow(anObj);
936 if(!aResultObj->_is_nil()){
937 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj));
939 if(abs(pResult->GetSourceId()) > Result_i::eFile)
940 if((pResult->GetFileInfo()).filePath() == "Med") return false;
947 MESSAGE("Unknown exception was accured!");
951 return myVisuGen->CanCopy(theObject);
954 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
955 if(MYDEBUG) MESSAGE("VISU_Gen_i::CopyFrom : "<<myMutex);
957 Mutex mt(myMutex,qApp);
960 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
961 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
963 PortableServer::POA_ptr aPOA = GetPOA();
965 SALOMEDS::GenericAttribute_var anAttr;
966 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
967 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
968 CORBA::Object_var aCorbaObj;
970 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
972 aStreamFile->length(1);
973 aStreamFile[0] = strdup("E")[0];
974 return aStreamFile._retn();
976 if (CORBA::is_nil(aCorbaObj)) {
980 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj));
984 CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
986 string aStr = pStorable->ToString().c_str();
987 ofstream stmOut2((string(aTmpDir) + string("copy_persistent")).c_str(),ios::out);
991 Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj));
993 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
994 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
995 aFileName += aFileInfo.fileName().latin1();
996 static QString aCommand;
997 aCommand.sprintf("cp %s %s",
998 aFileInfo.filePath().latin1(),
999 (string(aTmpDir) + aFileName).c_str());
1000 if(system(aCommand) == -1) {
1001 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
1006 aSeq[0] = "copy_persistent";
1007 aSeq[1] = aFileName.c_str();
1010 aSeq[0] = "copy_persistent";
1012 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
1013 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
1015 // Assign an ID = 1 the the type VISU::Result
1017 return aStreamFile._retn();
1019 return myVisuGen->CopyFrom(theObject, theObjectID);
1022 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1023 // The VISU component can paste only objects copied by VISU component
1024 // and with the object type = 1
1025 if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanPaste : "<<myMutex);
1026 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
1030 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
1031 CORBA::Long theObjectID,
1032 SALOMEDS::SObject_ptr theObject) {
1033 if(MYDEBUG) MESSAGE("VISU_Gen_i::PasteInto : "<<myMutex);
1035 Mutex mt(myMutex,qApp);
1036 SALOMEDS::SObject_var aResultSO;
1037 if (theObjectID != 1) return aResultSO._retn();
1039 CORBA::String_var aTmpDir = (const char*)SALOMEDS_Tool::GetTmpDir();
1040 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1042 ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str());
1043 // ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str(),ios::in);
1044 stmIn.seekg(0, ios::end);
1045 int aLength = stmIn.tellg();
1046 stmIn.seekg(0, ios::beg);
1047 char* aString = new char[aLength+1];
1048 stmIn.read(aString, aLength);
1049 aString[aLength] = 0;
1050 myIsMultiFile = true;
1052 string aFileName(aTmpDir.in());
1053 if(aSeq->length() > 1) aFileName += aSeq[1].in();
1054 Storable* aStorable = Storable::Create(theObject,aFileName,aString);
1056 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
1057 aSeqToRm->length(1);
1058 aSeqToRm[0] = "copy_persistent";
1059 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeqToRm.in(), true);
1061 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
1062 SALOMEDS::Study_var aStudy = theObject->GetStudy();
1063 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1064 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
1065 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
1066 aResultSO = aStudyBuilder->NewObject(aComponent);
1068 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
1069 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1070 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1071 CORBA::String_var anIORValue(aStorable->GetID());
1072 anIOR->SetValue(anIORValue);
1073 return aResultSO._retn();
1075 return myVisuGen->PasteInto(theStream,theObjectID,theObject);