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)
31 #include <qfileinfo.h>
32 static QFileInfo aFileInfo;
35 static int MYDEBUG = 0;
37 static int MYDEBUG = 0;
40 #include <utilities.h>
42 //static int IS_LOADED = (cout<<"\n----------------- VisuEngine_factory is loaded -----------------\n", 1);
44 PortableServer::ObjectId *
45 VisuEngine_factory(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId * contId,
46 const char *instanceName, const char *interfaceName)
48 if(MYDEBUG) MESSAGE("VisuEngine_factory : "<<interfaceName);
49 VISU::VISU_Gen_i * pVISU_Gen = new VISU::VISU_Gen_i(orb, poa, contId, instanceName, interfaceName);
50 return pVISU_Gen->getId() ;
53 GetVisuGen(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
54 SALOME_NamingService* theNamingService, QMutex* theMutex)
56 if(MYDEBUG) MESSAGE("extern \"C\" GetVisuGen");
57 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
58 return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
59 //return aVISU_Gen->_this();
64 //===========================================================================
65 //apo - static QMutex VISUMutex;
66 QMutex* Base_i::myMutex = NULL; //apo - &VISUMutex;
67 CORBA::ORB_var Base_i::myOrb;
68 PortableServer::POA_var Base_i::myPOA;
70 char* Base_i::GetID(){
71 //CORBA::Object_var anObject = _this();
72 //return CORBA::string_dup(myOrb->object_to_string(anObject));
73 return CORBA::string_dup(myOrb->object_to_string(_this()));
75 //===========================================================================
76 static int mySCnt = 0;
77 static int myQCnt = 0;
78 static int myIsBatchMode = 0;
80 static int QApp_Counter = 0;
81 static int Session_Counter = 0;
82 static int COUNTER = 0;
84 Mutex::Mutex(QMutex* theMutex, QApplication* theQApp, int theDelay) :
85 myQApp(theQApp), isQAppLocked(theQApp->locked()), myDelay(theDelay),
86 myMutex(theMutex), isSessionLocked(theMutex->locked())
88 if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<(!isQAppLocked && !myQCnt)<<" "<<(!isSessionLocked && !mySCnt));
89 if(!myIsBatchMode && isQAppLocked) myIsBatchMode++;
90 if(!isSessionLocked && !mySCnt) { myMutex->lock();}; mySCnt++;
91 if(!isQAppLocked && !myQCnt) {
99 if(!isQAppLocked && !myQCnt) {
102 myQApp->processEvents(myDelay+3);
105 mySCnt--; if(!isSessionLocked && !mySCnt) { myMutex->unlock();}
106 if(MYDEBUG) MESSAGE("Mutex::~Mutex : "<<(!isQAppLocked && !myQCnt)<<" "<<(!isSessionLocked && !mySCnt));
108 //===========================================================================
109 static Storable::TCallbackMap VisuStoreMap;
110 string Storable::ToString(){
111 ostringstream strOut;
112 Storable::DataToStream( strOut, "myComment", GetComment() );
115 if(MYDEBUG) MESSAGE("Storable::ToString - "<<strOut.str());
116 //apo - auto_ptr<char> aRet(strOut.str());
119 void Storable::Registry(const char* theComment, TStorableEngine theEngine)
120 throw(std::logic_error&)
122 if(!VisuStoreMap.insert(TCallbackMap::value_type(theComment,theEngine)).second){
123 if(MYDEBUG) MESSAGE("Storable::Registry >> dupliacte registring !!!");
124 throw std::logic_error("Storable::Registry >> dupliacte registring !!!");
127 void RegistryStorable() throw(std::logic_error&) {
128 //Storable::Registry(View3D_i::myComment.c_str(),&View3DRestore);
129 Storable::Registry(Result_i::myComment.c_str(),&ResultRestore);
130 Storable::Registry(Mesh_i::myComment.c_str(),&MeshRestore);
131 Storable::Registry(ScalarMap_i::myComment.c_str(),&ScalarMapRestore);
132 Storable::Registry(DeformedShape_i::myComment.c_str(),&DeformedShapeRestore);
133 Storable::Registry(CutPlanes_i::myComment.c_str(),&CutPlanesRestore);
134 Storable::Registry(CutLines_i::myComment.c_str(),&CutLinesRestore);
135 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&IsoSurfacesRestore);
136 Storable::Registry(StreamLines_i::myComment.c_str(),&StreamLinesRestore);
137 Storable::Registry(Vectors_i::myComment.c_str(),&VectorsRestore);
138 Storable::Registry(Table_i::myComment.c_str(),&TableRestore);
139 Storable::Registry(Curve_i::myComment.c_str(),&CurveRestore);
140 Storable::Registry(Container_i::myComment.c_str(),&ContainerRestore);
143 SALOMEDS::SObject_ptr Storable::GetResultSO(SALOMEDS::SObject_ptr theSObject) {
144 CORBA::String_var aComponentID(theSObject->GetFatherComponent()->GetID());
145 SALOMEDS::SObject_var aResult = SALOMEDS::SObject::_duplicate(theSObject);
146 CORBA::String_var aFatherID(aResult->GetFather()->GetID());
147 while(strcmp(aComponentID, aFatherID)) {
148 aResult = aResult->GetFather();
149 aFatherID = aResult->GetFather()->GetID();
150 if (strlen(aFatherID) < 3) break;
152 return aResult._retn();
155 void Storable::StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap){
156 if(MYDEBUG) MESSAGE("Storable::StrToMap : string="<<theStr);
157 QStringList strList = QStringList::split( ";", theStr, false );
158 for ( int i = 0; i < strList.count(); i++ ) {
159 QString next = strList[ i ];
160 int pos = next.find("=");
161 QString aName, aValue;
163 aName = next.stripWhiteSpace();
167 aName = next.left( pos ).stripWhiteSpace();
168 aValue = next.mid( pos+1 );
169 if ( aValue.isNull() )
172 if ( !aName.isEmpty() )
173 theMap.insert( TRestoringMap::value_type( aName.latin1(), aValue ) );
176 void Storable::DataToStream(ostringstream& theStr, const QString& theName, const QString& theVal) {
177 QString output = ( !theName.isNull() ? theName : QString("") )
179 + ( !theVal.isNull() ? theVal : QString("") );
180 theStr<<output.latin1()<<";";
182 void Storable::DataToStream(ostringstream& theStr, const QString& theName, const int theVal) {
183 QString output = ( !theName.isNull() ? theName : QString("") )
185 + QString::number( theVal );
186 theStr<<output.latin1()<<";";
188 void Storable::DataToStream(ostringstream& theStr, const QString& theName, const double theVal) {
189 QString output = ( !theName.isNull() ? theName : QString("") )
191 + QString::number( theVal );
192 theStr<<output.latin1()<<";";
194 Storable* Storable::Create(SALOMEDS::SObject_ptr theSObject,
195 const string& thePrefix, const string& theLocalPersistentID)
196 throw (std::runtime_error&)
199 QString strIn( theLocalPersistentID.c_str() );
201 StrToMap(strIn,aMap);
202 //CORBA::String_var aResultID(GetResultSO(theSObject)->GetID());
203 //aMap.insert(TRestoringMap::value_type("ResultID", strdup(aResultID)));
205 QString aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist);
207 TCallbackMap::const_iterator i = VisuStoreMap.find(aComment.latin1());
208 if(MYDEBUG) MESSAGE("Storable::Create - "<<aComment.latin1()<<" "<<(i != VisuStoreMap.end()));
209 if(i == VisuStoreMap.end()) return NULL;
210 return (i->second)(theSObject,thePrefix,aMap);
212 }catch(std::logic_error& exc){
213 MESSAGE("Follow exception was accured :\n"<<exc.what());
215 MESSAGE("Unknown exception was accured!");
219 const QString& Storable::FindValue(const TRestoringMap& theMap, const string& theArg, bool* isFind)
220 throw(std::logic_error&)
222 TRestoringMap::const_iterator i = theMap.find(theArg);
223 if(i == theMap.end()) {
224 if(MYDEBUG) MESSAGE("Storable::Init >> there is no value for "<<theArg);
225 if(isFind != NULL) *isFind = false;
226 //throw std::logic_error(string("Storable::Init >> there is no value for ") + theArg);
227 static QString BAD_VALUE("NULL");
230 if(isFind != NULL) *isFind = true;
234 //===========================================================================
235 PortableServer::Servant GetServant(CORBA::Object_ptr theObject){
236 PortableServer::POA_var aPOA = GetPOA();
237 if(CORBA::is_nil(theObject))
238 if(MYDEBUG) MESSAGE("GetServant - CORBA::is_nil(theObject)");
239 return aPOA->reference_to_servant(theObject);
241 //===========================================================================
242 CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr theSObject){
243 SALOMEDS::GenericAttribute_var anAttr;
244 CORBA::Object_var anObj;
245 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
246 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
247 CORBA::String_var aValue = anIOR->Value();
248 CORBA::ORB_var anORB = GetORB();
249 if(strcmp(aValue,"") != 0)
250 anObj = anORB->string_to_object(aValue);
254 //===========================================================================
255 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
256 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
257 if (aSComponent->_is_nil()) {
258 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
259 aStudyBuilder->NewCommand();
260 int aLocked = theStudyDocument->GetProperties()->IsLocked();
261 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
262 aSComponent = aStudyBuilder->NewComponent("VISU");
263 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
264 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
265 //NRI aName->SetValue("Visu");
267 CORBA::ORB_var anORB = GetORB();
268 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
269 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
270 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
271 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
272 if ( !Comp->_is_nil() ) {
273 aName->SetValue( Comp->componentusername() );
276 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
277 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
278 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
280 VISU_Gen_var aVisuGen = GetVisu();
281 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
282 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
283 aStudyBuilder->CommitCommand();
287 //===========================================================================
288 string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry,
289 const char* theComment, int IsAllLevels)
291 if(MYDEBUG) MESSAGE("FindEntryWithComment - '"<<theComment<<"'");
292 SALOMEDS::ChildIterator_var anIter =
293 theStudyDocument->NewChildIterator(theStudyDocument->FindObjectID(theStartEntry));
294 anIter->InitEx(IsAllLevels);
295 SALOMEDS::SObject_var aFieldSO;
296 for(;anIter->More();anIter->Next()) {
297 SALOMEDS::GenericAttribute_var anAttr;
298 if (anIter->Value()->FindAttribute(anAttr,"AttributeComment")) {
299 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
300 CORBA::String_var aString = aCmnt->Value();
301 string aValue(aString);
302 if (aValue == theComment) {
303 aFieldSO = anIter->Value();
304 aString = aFieldSO->GetID();
312 //===========================================================================
313 string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
314 const char* theFatherEntry, const char* theRefFatherEntry,
315 const char* theIOR, const char* theName,
316 const char* thePersistentRef, const char* theComment,
317 CORBA::Boolean theCreateNew)
320 MESSAGE("CreateAttributes - theName = "<<theName<<"; theComment = '"<<theComment<<
321 "'; theFatherEntry = "<<theFatherEntry);
322 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
323 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry);
324 SALOMEDS::SObject_var newObj;
325 if (theCreateNew) newObj = aStudyBuilder->NewObject(aFather);
326 else newObj = aFather;
327 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
328 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
329 anIOR->SetValue(theIOR);
330 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
331 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
332 aName->SetValue(theName);
333 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef");
334 SALOMEDS::AttributePersistentRef_var aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
335 aPRef->SetValue(thePersistentRef);
336 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
337 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
338 aCmnt->SetValue(theComment);
339 if(strcmp(theRefFatherEntry,"") != 0){
340 SALOMEDS::SObject_var aRefFather = theStudyDocument->FindObjectID(theRefFatherEntry);
341 SALOMEDS::SObject_var anObj = aStudyBuilder->NewObject(aRefFather);
342 aStudyBuilder->Addreference(anObj,newObj);
344 CORBA::String_var anEntry = newObj->GetID();
345 string aRet(anEntry);
346 if(MYDEBUG) MESSAGE("CreateAttributes - anEntry = "<<aRet<<"; IOR = "<<theIOR);
349 //===========================================================================
350 static CORBA::ORB_var VisuORB;
351 static PortableServer::POA_var VisuPOA;
352 static SALOMEDS::SComponent_var VisuSComponent;
353 static string VisuTmpDir;
354 static VISU_Gen_i* VisuGen;
355 static CORBA::Boolean myIsMultiFile;
356 const CORBA::Boolean IsMultifile() {
357 return myIsMultiFile;
359 //===========================================================================
360 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr orb,
361 PortableServer::POA_ptr poa,
362 PortableServer::ObjectId * contId,
363 const char *instanceName,
364 const char *interfaceName) :
365 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
367 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<myMutex);
369 _id = _poa->activate_object(_thisObj);
370 SALOME_NamingService aNamingService(orb);
371 CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session");
372 SALOME::Session_var aSession = SALOME::Session::_narrow(anObject);
373 //aSession->GetInterface();
374 Engines::Component_var aComponent = aSession->GetVisuGen();
375 myVisuGen = VISU::VISU_Gen::_narrow(aComponent);
378 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
379 SALOME_NamingService* theNamingService, QMutex* theMutex) :
380 Engines_Component_i()
382 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
383 Mutex mt(theMutex,qApp);
384 Base_i::myMutex = theMutex; //apo
385 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
386 Base_i::myPOA = PortableServer::POA::_duplicate(thePOA);
387 Base_i::myNamingService = theNamingService;
388 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
389 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
390 Base_i::myVisuGenImpl = this;
393 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
394 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
395 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
396 if(aListOfOpenStudies->length() > 0) {
397 CORBA::String_var aStudyName = aListOfOpenStudies[0];
398 aFileInfo.setFile(aStudyName.in());
399 myStudyDocument = aStudyManager->GetStudyByName(aFileInfo.baseName());
401 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
404 Base_i::myPOA->activate_object(this);
407 VISU_Gen_i::~VISU_Gen_i(){
408 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
410 const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
411 //===========================================================================
412 bool VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
413 const SALOMEDS::TMPFile & theStream,
417 if(MYDEBUG) MESSAGE("VISU_Gen_i::Load - myMutex = "<<myMutex);
419 Mutex mt(myMutex,qApp);
420 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
421 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
422 TCollection_AsciiString aTmpDir =
423 isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
424 VisuSComponent = SALOMEDS::SComponent::_duplicate(theComponent);
425 VisuTmpDir = aTmpDir.ToCString();
426 SALOMEDS::ListOfFileNames_var aSeq =
427 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
428 myIsMultiFile = isMultiFile;
431 return myVisuGen->Load(theComponent,theStream,theURL,isMultiFile);
434 bool VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
435 const SALOMEDS::TMPFile & theStream,
438 return Load(theComponent, theStream, theURL, isMultiFile);
441 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
442 const char* aLocalPersistentID,
443 CORBA::Boolean isMultiFile,
444 CORBA::Boolean isASCII) {
446 Mutex mt(myMutex,qApp);
447 CORBA::String_var aString("");
448 if(strcmp(aLocalPersistentID,"") != 0) {
449 Storable* aStorable =
450 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
451 if(aStorable != NULL) aString = aStorable->GetID();
453 return aString._retn();
455 return myVisuGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile, isASCII);
457 //===========================================================================
458 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
462 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
464 Mutex mt(myMutex,qApp);
465 TCollection_AsciiString aTmpDir =
466 (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
467 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
469 TColStd_SequenceOfAsciiString aFileNames;
470 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
471 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
472 for (; itBig->More(); itBig->Next()) {
473 SALOMEDS::SObject_var gotBranch = itBig->Value();
474 CORBA::Object_var anObj = SObjectToObject(gotBranch);
475 if(CORBA::is_nil(anObj)) continue;
476 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
478 const QFileInfo& aFileInfo = pResult->GetFileInfo();
479 QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
480 QString aFileName = aPrefix + "_" + pResult->GetName();
481 static QString aCommand;
482 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
483 if(system(aCommand) == -1){
484 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
487 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
488 TCollection_AsciiString aString(strdup(aFileName.latin1()));
489 aFileNames.Append(aString);
492 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
493 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
494 if(aFileNames.Length() > 0){
495 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
496 aSeq->length(aFileNames.Length());
497 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
498 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
499 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
501 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
503 return aStreamFile._retn();
505 return myVisuGen->Save(theComponent,theURL,isMultiFile);
508 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
511 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
513 Mutex mt(myMutex,qApp);
514 CORBA::String_var aString = SALOMEDS_Tool::GetTmpDir();
515 TCollection_AsciiString aTmpDir = isMultiFile? (const Standard_CString)theURL: (const Standard_CString)aString.in();
516 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
518 TColStd_SequenceOfAsciiString aFileNames;
519 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
520 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
521 for (; itBig->More(); itBig->Next()) {
522 SALOMEDS::SObject_var gotBranch = itBig->Value();
523 CORBA::Object_var anObj = SObjectToObject(gotBranch);
524 if(CORBA::is_nil(anObj)) continue;
525 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
526 if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){
527 const QFileInfo& aFileInfo = pResult->GetFileInfo();
528 QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
529 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
530 static QString aCommand;
531 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
533 if(system(aCommand) == -1){
534 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
537 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
538 TCollection_AsciiString aString(strdup(aFileName.latin1()));
540 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
542 aFileNames.Append(aString);
545 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
546 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
547 if(aFileNames.Length() > 0){
548 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
549 aSeq->length(aFileNames.Length());
550 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
551 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
552 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
554 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
556 return aStreamFile._retn();
558 return myVisuGen->Save(theComponent,theURL,isMultiFile);
561 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
562 const char* IORString,
563 CORBA::Boolean isMultiFile,
564 CORBA::Boolean isASCII) {
565 if(MYDEBUG) MESSAGE("VISU_Gen_i::IORToLocalPersistentID - myMutex = "<<myMutex);
567 Mutex mt(myMutex,qApp);
568 CORBA::ORB_var anORB = GetORB();
569 CORBA::String_var aString(IORString);
570 if(strcmp(IORString,"") != 0){
571 CORBA::Object_var anObj = anORB->string_to_object(aString);
572 if(!CORBA::is_nil(anObj)){
573 Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj));
574 if(pStorable != NULL){
575 aString = pStorable->ToString();
576 return aString._retn();
580 return aString._retn();
582 return myVisuGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile, isASCII);
585 //===========================================================================
586 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr orb,
587 PortableServer::POA_ptr poa,
588 PortableServer::ObjectId * contId,
589 const char *instanceName,
590 const char *interfaceName) :
591 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
593 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<myMutex);
595 _id = _poa->activate_object(_thisObj);
596 SALOME_NamingService aNamingService(orb);
597 CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session");
598 SALOME::Session_var aSession = SALOME::Session::_narrow(anObject);
599 //aSession->GetInterface();
600 //myVisuGen = aSession->GetVisuGen();
601 myVisuGen = VISU::VISU_Gen::_narrow( aSession->GetVisuComponent() );
603 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA, QMutex* theMutex) :
604 Engines_Component_i()
606 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
607 Base_i::myMutex = theMutex;
608 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
609 Base_i::myPOA = PortableServer::POA::_duplicate(thePOA);
610 Mutex mt(myMutex,qApp);
614 VisuPOA->activate_object(this);
616 if(!QAD_Application::getDesktop()->getActiveStudy())
617 QAD_Application::getDesktop()->createStudy();
619 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
621 VISU_Gen_i::~VISU_Gen_i(){
622 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
624 void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
625 //if(MYDEBUG) MESSAGE("VISU_Gen_i::SetCurrentStudy : "<<(!theStudy->_is_nil()));
627 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
629 myVisuGen->SetCurrentStudy(theStudy);
631 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
632 if(MYDEBUG) MESSAGE("VISU_Gen_i::GetCurrentStudy : "<<myMutex);
634 return SALOMEDS::Study::_duplicate(myStudyDocument);
635 return myVisuGen->GetCurrentStudy();
637 ViewManager_ptr VISU_Gen_i::GetViewManager(){
639 //omni_mutex_lock aMutexLock(aMutex);
640 if(MYDEBUG) MESSAGE("VISU_Gen_i::GetViewManager : "<<myMutex);
642 Mutex mt(myMutex,qApp);
643 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
644 return ViewManager::_duplicate(aViewManager->_this());
646 return myVisuGen->GetViewManager();
649 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
651 if(myStudyDocument->GetProperties()->IsLocked()) return SALOMEDS::SObject::_nil();
652 Mutex mt(myMutex,qApp);
653 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
656 return myVisuGen->ImportTables(theFileName);
659 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
661 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
662 Mutex mt(myMutex,qApp);
663 aFileInfo.setFile(theFileName);
664 Result_i* pResult = new Result_i(myStudyDocument);
665 if(pResult->Create(theFileName) != NULL)
666 return Result::_duplicate(pResult->_this());
667 return Result::_nil();
669 return myVisuGen->ImportFile(theFileName);
671 Result_ptr VISU_Gen_i::ImportMed(SALOME_MED::FIELD_ptr theField){
672 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMed : "<<myMutex);
674 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
675 Mutex mt(myMutex,qApp);
676 Result_i* pResult = new Result_i(myStudyDocument);
677 if(pResult->Create(theField) != NULL)
678 return Result::_duplicate(pResult->_this());
679 return Result::_nil();
681 return myVisuGen->ImportMed(theField);
683 Result_ptr VISU_Gen_i::ImportMedMesh(SALOME_MED::MESH_ptr theMesh){
684 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedMesh : "<<myMutex);
686 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
687 Mutex mt(myMutex,qApp);
688 Result_i* pResult = new Result_i(myStudyDocument);
689 if(pResult->Create(theMesh) != NULL)
690 return Result::_duplicate(pResult->_this());
691 return Result::_nil();
693 return myVisuGen->ImportMedMesh(theMesh);
696 Result_ptr VISU_Gen_i::ImportMedSupport(SALOME_MED::SUPPORT_ptr theSupport){
697 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedSupport : "<<myMutex);
699 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
700 Mutex mt(myMutex,qApp);
701 Result_i* pResult = new Result_i(myStudyDocument);
702 if(pResult->Create(theSupport) != NULL)
703 return Result::_duplicate(pResult->_this());
704 return Result::_nil();
706 return myVisuGen->ImportMedSupport(theSupport);
709 Result_ptr VISU_Gen_i::ImportMedField(SALOME_MED::FIELD_ptr theField){
710 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedField : "<<myMutex);
712 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
713 Mutex mt(myMutex,qApp);
714 Result_i* pResult = new Result_i(myStudyDocument);
715 if(pResult->Create(theField) != NULL)
716 return Result::_duplicate(pResult->_this());
717 return Result::_nil();
719 return myVisuGen->ImportMedField(theField);
722 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity){
723 if(MYDEBUG) MESSAGE("VISU_Gen_i::MeshOnEntity : "<<myMutex);
725 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
726 Mutex mt(myMutex,qApp);
727 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
728 Mesh_i* aPresent = new Mesh_i(pResult);
729 if(aPresent->Create(theMeshName,theEntity) != NULL)
730 return Mesh::_duplicate(aPresent->_this());
733 return myVisuGen->MeshOnEntity(theResult,theMeshName,theEntity);
736 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName,
737 VISU::Entity theEntity,
738 const char* theFamilyName){
739 if(MYDEBUG) MESSAGE("VISU_Gen_i::FamilyMeshOnEntity : "<<myMutex);
741 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
742 Mutex mt(myMutex,qApp);
743 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
744 Mesh_i* aPresent = new Mesh_i(pResult);
745 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
746 return Mesh::_duplicate(aPresent->_this());
749 return myVisuGen->FamilyMeshOnEntity(theResult,theMeshName,theEntity,theFamilyName);
752 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, const char* theMeshName,
753 const char* theGroupName){
754 if(MYDEBUG) MESSAGE("VISU_Gen_i::GroupMesh : "<<myMutex);
756 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
757 Mutex mt(myMutex,qApp);
758 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
759 Mesh_i* aPresent = new Mesh_i(pResult);
760 if(aPresent->Create(theMeshName,theGroupName) != NULL)
761 return Mesh::_duplicate(aPresent->_this());
764 return myVisuGen->GroupMesh(theResult,theMeshName,theGroupName);
767 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
768 const char* theFieldName, CORBA::Double theIteration){
769 if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<<myMutex);
771 if(myStudyDocument->GetProperties()->IsLocked()) return ScalarMap::_nil();
772 Mutex mt(myMutex,qApp);
773 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
774 if(ScalarMap_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
775 ScalarMap_i* aPresent = new ScalarMap_i(pResult);
776 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL){
777 //Base_i::myPOA->activate_object(aPresent);
778 //aPresent->_remove_ref();
779 return aPresent->_this();
782 return ScalarMap::_nil();
784 return myVisuGen->ScalarMapOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
787 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
788 const char* theFieldName, CORBA::Double theIteration){
789 if(MYDEBUG) MESSAGE("VISU_Gen_i::DeformedShapeOnField : "<<myMutex);
791 if(myStudyDocument->GetProperties()->IsLocked()) return DeformedShape::_nil();
792 Mutex mt(myMutex,qApp);
793 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
794 if(DeformedShape_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
795 DeformedShape_i* aPresent = new DeformedShape_i(pResult);
796 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
797 return DeformedShape::_duplicate(aPresent->_this());
799 return DeformedShape::_nil();
801 return myVisuGen->DeformedShapeOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
804 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
805 const char* theFieldName, CORBA::Double theIteration){
806 if(MYDEBUG) MESSAGE("VISU_Gen_i::VectorsOnField : "<<myMutex);
808 if(myStudyDocument->GetProperties()->IsLocked()) return Vectors::_nil();
809 Mutex mt(myMutex,qApp);
810 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
811 if(Vectors_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
812 Vectors_i* aPresent = new Vectors_i(pResult);
813 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
814 return Vectors::_duplicate(aPresent->_this());
816 return Vectors::_nil();
818 return myVisuGen->VectorsOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
821 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
822 const char* theFieldName, CORBA::Double theIteration){
823 if(MYDEBUG) MESSAGE("VISU_Gen_i::IsoSurfacesOnField : "<<myMutex);
825 if(myStudyDocument->GetProperties()->IsLocked()) return IsoSurfaces::_nil();
826 Mutex mt(myMutex,qApp);
827 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
828 if(IsoSurfaces_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
829 IsoSurfaces_i* aPresent = new IsoSurfaces_i(pResult);
830 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
831 return IsoSurfaces::_duplicate(aPresent->_this());
833 return IsoSurfaces::_nil();
835 return myVisuGen->IsoSurfacesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
838 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
839 const char* theFieldName, CORBA::Double theIteration){
840 if(MYDEBUG) MESSAGE("VISU_Gen_i::StreamLinesOnField : "<<myMutex);
842 if(myStudyDocument->GetProperties()->IsLocked()) return StreamLines::_nil();
843 Mutex mt(myMutex,qApp);
844 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
845 if(StreamLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
846 StreamLines_i* aPresent = new StreamLines_i(pResult);
847 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
848 return StreamLines::_duplicate(aPresent->_this());
850 return StreamLines::_nil();
852 return myVisuGen->StreamLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
855 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
856 const char* theFieldName, CORBA::Double theIteration){
857 if(MYDEBUG) MESSAGE("VISU_Gen_i::CutPlanesOnField : "<<myMutex);
859 if(myStudyDocument->GetProperties()->IsLocked()) return CutPlanes::_nil();
860 Mutex mt(myMutex,qApp);
861 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
862 if(CutPlanes_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
863 CutPlanes_i* aPresent = new CutPlanes_i(pResult);
864 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
865 return CutPlanes::_duplicate(aPresent->_this());
867 return CutPlanes::_nil();
869 return myVisuGen->CutPlanesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
872 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
873 const char* theFieldName, CORBA::Double theIteration){
874 if(MYDEBUG) MESSAGE("VISU_Gen_i::CutLinesOnField : "<<myMutex);
876 if(myStudyDocument->GetProperties()->IsLocked()) return CutLines::_nil();
877 Mutex mt(myMutex,qApp);
878 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
879 if(CutLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){
880 CutLines_i* aPresent = new CutLines_i(pResult);
881 if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL)
882 return CutLines::_duplicate(aPresent->_this());
884 return CutLines::_nil();
886 return myVisuGen->CutLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
889 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
890 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateTable : "<<myMutex);
892 if(myStudyDocument->GetProperties()->IsLocked()) return Table::_nil();
893 Mutex mt(myMutex,qApp);
894 Table_i* aPresent = new Table_i(myStudyDocument,theTableEntry);
895 if(aPresent->Create() != NULL)
896 return Table::_duplicate(aPresent->_this());
897 return Table::_nil();
899 return myVisuGen->CreateTable(theTableEntry);
902 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow){
903 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateCurve : "<<myMutex);
905 if(myStudyDocument->GetProperties()->IsLocked()) return Curve::_nil();
906 Mutex mt(myMutex,qApp);
907 PortableServer::POA_var aPOA = GetPOA();
908 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
909 Curve_i* aPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
910 if(aPresent->Create() != NULL) {
911 return Curve::_duplicate(aPresent->_this());
913 return Curve::_nil();
915 return myVisuGen->CreateCurve(theTable,theHRow,theVRow);
917 Container_ptr VISU_Gen_i::CreateContainer(){
918 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateContainer : "<<myMutex);
920 if(myStudyDocument->GetProperties()->IsLocked()) return Container::_nil();
921 Mutex mt(myMutex,qApp);
922 Container_i* aPresent = new Container_i(myStudyDocument);
923 if(aPresent->Create() != NULL) {
924 return Container::_duplicate(aPresent->_this());
926 return Container::_nil();
928 return myVisuGen->CreateContainer();
931 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
933 if(myStudyDocument->GetProperties()->IsLocked()) return Animation::_nil();
934 Mutex mt(myMutex,qApp);
935 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateAnimation : "<<myMutex);
936 VISU_TimeAnimation* anAnim = new VISU_TimeAnimation(myStudyDocument,theView3D);
937 return Animation::_duplicate(anAnim->_this());
939 return myVisuGen->CreateAnimation(theView3D);
942 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
943 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : "<<myMutex);
945 Mutex mt(myMutex,qApp);
946 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
947 if(!aStudy->_is_nil()){
948 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
949 for (int i = 0; itBig->More(); itBig->Next(),i++) {
950 SALOMEDS::SObject_var gotBranch = itBig->Value();
951 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : itBig->Next() = "<<i);
952 CORBA::Object_var anObj = SObjectToObject(gotBranch);
953 if(CORBA::is_nil(anObj)) continue;
954 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
955 if(!pResult) continue;
956 if(pResult->GetSourceId() == Result_i::eRestoredFile){ //Try remove its file and directory
957 const QFileInfo& aFileInfo = pResult->GetFileInfo();
958 static QString aCommand;
959 aCommand.sprintf("rm %s",aFileInfo.filePath().latin1());
960 if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
961 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",aFileInfo.dirPath().latin1());
962 if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
968 myVisuGen->Close(theComponent);
971 char* VISU_Gen_i::ComponentDataType(){
972 return CORBA::string_dup("VISU");
975 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
976 Result_var aResultObj = Result::_narrow(theIOR);
977 return !(aResultObj->_is_nil());
980 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
981 SALOMEDS::SObject_ptr theSObject,
982 CORBA::Object_ptr theObject,
984 throw (SALOME::SALOME_Exception)
986 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
988 Mutex mt(myMutex,qApp);
989 SALOMEDS::SObject_var aResultSO;
990 PortableServer::POA_var aPOA = GetPOA();
991 Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(theObject));
992 if (!aResultObj) return aResultSO._retn();
994 CORBA::String_var anEntry;
995 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
996 anEntry = strdup(aResultObj->Create(aFileInfo.filePath().latin1())->GetID());
997 // if (CORBA::is_nil(theSObject)) {
998 // anEntry = strdup(aResultObj->Create(SALOMEDS::SObject::_nil(), theName));
1000 // if (!theSObject->ReferencedObject(aResultSO))
1001 // THROW_SALOME_CORBA_EXCEPTION("Publish error: bad referenced SObject",SALOME::BAD_PARAM);
1002 // anEntry = strdup(aResultObj->Create(aResultSO, (const char *)theName));
1004 aResultSO = theStudy->FindObjectID(anEntry);
1005 return aResultSO._retn();
1007 return myVisuGen->PublishInStudy(theStudy, theSObject, theObject, theName);
1010 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
1011 if(MYDEBUG) MESSAGE("VISU_Gen_i::CanCopy : "<<myMutex);
1013 //Mutex mt(myMutex,qApp);
1014 SALOMEDS::GenericAttribute_var anAttr;
1015 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
1017 CORBA::Object_var anObj = GetORB()->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
1018 if (CORBA::is_nil(anObj)) return false;
1020 Result_var aResultObj = Result::_narrow(anObj);
1021 if (aResultObj->_is_nil()) return false;
1028 return myVisuGen->CanCopy(theObject);
1031 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
1032 if(MYDEBUG) MESSAGE("VISU_Gen_i::CopyFrom : "<<myMutex);
1034 Mutex mt(myMutex,qApp);
1037 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
1038 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
1040 PortableServer::POA_var aPOA = GetPOA();
1042 SALOMEDS::GenericAttribute_var anAttr;
1043 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
1044 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
1045 CORBA::Object_var aCorbaObj;
1047 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
1049 aStreamFile->length(1);
1050 aStreamFile[0] = strdup("E")[0];
1051 return aStreamFile._retn();
1053 if (CORBA::is_nil(aCorbaObj)) {
1057 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj));
1061 CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
1063 char* aStr = strdup(pStorable->ToString());
1064 ofstream stmOut2((string(aTmpDir) + string("copy_persistent")).c_str(),ios::out);
1065 stmOut2<<aStr<<endl;
1068 Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj));
1070 string aStudyPrefix = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + string("_");
1072 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1073 static QString aCommand;
1074 aCommand.sprintf("cp %s %s",
1075 aFileInfo.filePath().latin1(),
1076 (string(aTmpDir)+aStudyPrefix + string(aResultObj->GetName())).c_str());
1077 if(system(aCommand) == -1) {
1078 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
1083 aSeq[0] = "copy_persistent";
1084 aSeq[1] = (aStudyPrefix + string(aResultObj->GetName())).c_str();
1087 aSeq[0] = "copy_persistent";
1089 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
1090 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
1092 // Assign an ID = 1 the the type VISU::Result
1094 return aStreamFile._retn();
1096 return myVisuGen->CopyFrom(theObject, theObjectID);
1099 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1100 // The VISU component can paste only objects copied by VISU component
1101 // and with the object type = 1
1102 if(MYDEBUG) MESSAGE("VISU_Gen_i::CanPaste : "<<myMutex);
1103 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
1107 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
1108 CORBA::Long theObjectID,
1109 SALOMEDS::SObject_ptr theObject) {
1110 if(MYDEBUG) MESSAGE("VISU_Gen_i::PasteInto : "<<myMutex);
1112 Mutex mt(myMutex,qApp);
1113 SALOMEDS::SObject_var aResultSO;
1114 if (theObjectID != 1) return aResultSO._retn();
1116 CORBA::String_var aTmpDir = strdup(SALOMEDS_Tool::GetTmpDir());
1117 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1119 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
1120 SALOMEDS::Study_var aStudy = theObject->GetStudy();
1121 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1122 CORBA::ORB_var anORB = GetORB();
1124 ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str());
1125 // ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str(),ios::in);
1126 stmIn.seekg(0, ios::end);
1127 int aLength = stmIn.tellg();
1128 stmIn.seekg(0, ios::beg);
1129 char* aString = new char[aLength+1];
1130 stmIn.read(aString, aLength);
1131 aString[aLength] = 0;
1132 myIsMultiFile = true;
1133 Storable* aStorable = Storable::Create(theObject,aTmpDir.in(),aString);
1135 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
1136 aSeqToRm->length(1);
1137 aSeqToRm[0] = "copy_persistent";
1138 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeqToRm.in(), true);
1140 CORBA::String_var aComponentIDString(aComponent->GetID());
1141 if (strcmp(aComponentIDString, theObject->GetID()) == 0) {
1142 // create the new result SObject
1143 aResultSO = aStudyBuilder->NewObject(aComponent);
1145 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
1147 SALOMEDS::AttributeIOR_var anIOR =
1148 SALOMEDS::AttributeIOR::_narrow(aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
1149 anIOR->SetValue(aStorable->GetID());
1150 return aResultSO._retn();
1152 return myVisuGen->PasteInto(theStream,theObjectID,theObject);