1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_Gen_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_Gen_i.hh"
28 #include "VISU_Result_i.hh"
29 #include "VISU_PrsObject_i.hh"
30 #include "VISU_ViewManager_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Mesh_i.hh"
34 #include "VISU_ScalarMap_i.hh"
35 #include "VISU_IsoSurfaces_i.hh"
36 #include "VISU_DeformedShape_i.hh"
37 #include "VISU_CutPlanes_i.hh"
38 #include "VISU_CutLines_i.hh"
39 #include "VISU_Vectors_i.hh"
40 #include "VISU_StreamLines_i.hh"
41 #include "VISU_Table_i.hh"
42 #include "VISU_TimeAnimation.h"
44 #include "HDFascii.hxx"
45 #include "SALOMEDS_Tool.hxx"
47 #include "utilities.h"
50 #include <TCollection_AsciiString.hxx>
51 #include <TColStd_SequenceOfAsciiString.hxx>
53 #include <omnithread.h>
54 #include CORBA_SERVER_HEADER(SALOME_Session)
55 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
58 #include <qfileinfo.h>
62 static QFileInfo aFileInfo;
65 static int MYDEBUG = 0;
67 static int MYDEBUG = 0;
71 PortableServer::ObjectId *
72 VISUEngine_factory(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId * contId,
73 const char *instanceName, const char *interfaceName)
75 if(MYDEBUG) MESSAGE("VisuEngine_factory : "<<interfaceName);
76 VISU::VISU_Gen_i * pVISU_Gen = new VISU::VISU_Gen_i(orb, poa, contId, instanceName, interfaceName);
77 return pVISU_Gen->getId() ;
80 GetVisuGen(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
81 SALOME_NamingService* theNamingService, QMutex* theMutex)
83 if(MYDEBUG) MESSAGE("extern \"C\" GetVisuGen");
84 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
85 return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
86 //return aVISU_Gen->_this();
91 static string VisuTmpDir;
93 static CORBA::Boolean myIsMultiFile;
94 const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
96 //===========================================================================
97 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
98 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
99 if (aSComponent->_is_nil()) {
100 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
101 aStudyBuilder->NewCommand();
102 int aLocked = theStudyDocument->GetProperties()->IsLocked();
103 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
104 aSComponent = aStudyBuilder->NewComponent("VISU");
105 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
106 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
108 //NRI aName->SetValue("Visu");
109 CORBA::ORB_var anORB = Base_i::GetORB();
110 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
111 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
112 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
113 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
114 if ( !Comp->_is_nil() ) {
115 aName->SetValue( Comp->componentusername() );
118 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
119 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
120 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
122 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
123 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
124 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
125 aStudyBuilder->CommitCommand();
131 void RegistryStorable() throw(std::logic_error&) {
132 Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore));
133 Storable::Registry(Mesh_i::myComment.c_str(),&(Restore<Mesh_i>));
134 Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore<ScalarMap_i>));
135 Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore<DeformedShape_i>));
136 Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore<CutPlanes_i>));
137 Storable::Registry(CutLines_i::myComment.c_str(),&(Restore<CutLines_i>));
138 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore<IsoSurfaces_i>));
139 Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore<StreamLines_i>));
140 Storable::Registry(Vectors_i::myComment.c_str(),&(Restore<Vectors_i>));
141 Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore));
142 Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore));
143 Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore));
147 //===========================================================================
148 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr orb,
149 PortableServer::POA_ptr poa,
150 PortableServer::ObjectId * contId,
151 const char *instanceName,
152 const char *interfaceName) :
153 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
155 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<myMutex);
157 _id = _poa->activate_object(_thisObj);
158 SALOME_NamingService aNamingService(orb);
159 CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session");
160 SALOME::Session_var aSession = SALOME::Session::_narrow(anObject);
161 //aSession->GetInterface();
162 Engines::Component_var aComponent = aSession->GetVisuComponent();
163 myVisuGen = VISU::VISU_Gen::_narrow(aComponent);
166 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
167 SALOME_NamingService* theNamingService, QMutex* theMutex) :
168 Engines_Component_i()
170 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
171 Mutex mt(theMutex,qApp);
172 Base_i::myMutex = theMutex; //apo
173 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
174 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
175 Base_i::myNamingService = theNamingService;
176 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
177 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
178 Base_i::myVisuGenImpl = this;
181 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
182 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
183 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
184 if(aListOfOpenStudies->length() > 0) {
185 CORBA::String_var aStudyName = aListOfOpenStudies[0];
186 //aFileInfo.setFile(aStudyName.in());
187 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
189 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
192 VISU_Gen_i::~VISU_Gen_i(){
193 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
195 //===========================================================================
196 bool VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
197 const SALOMEDS::TMPFile & theStream,
201 if(MYDEBUG) MESSAGE("VISU_Gen_i::Load - myMutex = "<<myMutex);
203 Mutex mt(myMutex,qApp);
204 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
205 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
206 TCollection_AsciiString aTmpDir =
207 isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
208 VisuTmpDir = aTmpDir.ToCString();
209 SALOMEDS::ListOfFileNames_var aSeq =
210 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
211 myIsMultiFile = isMultiFile;
214 return myVisuGen->Load(theComponent,theStream,theURL,isMultiFile);
217 bool VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
218 const SALOMEDS::TMPFile & theStream,
222 return Load(theComponent, theStream, theURL, isMultiFile);
225 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
226 const char* aLocalPersistentID,
227 CORBA::Boolean isMultiFile,
228 CORBA::Boolean isASCII)
231 CORBA::String_var aString("");
232 if(strcmp(aLocalPersistentID,"") != 0) {
233 Mutex mt(myMutex,qApp);
234 Storable* aStorable =
235 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
236 if(aStorable != NULL) aString = aStorable->GetID();
238 return aString._retn();
240 return myVisuGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile, isASCII);
242 //===========================================================================
243 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
247 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
249 Mutex mt(myMutex,qApp);
250 TCollection_AsciiString aTmpDir = isMultiFile? strdup(theURL): SALOMEDS_Tool::GetTmpDir();
251 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
253 TColStd_SequenceOfAsciiString aFileNames;
254 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
255 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
256 for (; itBig->More(); itBig->Next()) {
257 SALOMEDS::SObject_var gotBranch = itBig->Value();
258 CORBA::Object_var anObj = SObjectToObject(gotBranch);
259 if(CORBA::is_nil(anObj)) continue;
260 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in());
262 const Result_i::TSourceId& aSourceId = pResult->GetSourceId();
263 if(aSourceId == Result_i::eFile || aSourceId == Result_i::eRestoredFile){
264 const QFileInfo& aFileInfo = pResult->GetFileInfo();
266 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
267 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
268 static QString aCommand;
269 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
270 if(system(aCommand) == -1){
271 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
274 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aCommand = "<<aCommand);
275 TCollection_AsciiString aString(strdup(aFileName.latin1()));
276 aFileNames.Append(aString);
280 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
281 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
282 if(aFileNames.Length() > 0){
283 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
284 aSeq->length(aFileNames.Length());
285 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
286 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
287 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
289 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
291 return aStreamFile._retn();
293 return myVisuGen->Save(theComponent,theURL,isMultiFile);
296 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
299 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
301 Mutex mt(myMutex,qApp);
302 CORBA::String_var aString = SALOMEDS_Tool::GetTmpDir();
303 TCollection_AsciiString aTmpDir = isMultiFile? (const Standard_CString)theURL: (const Standard_CString)aString.in();
304 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
306 TColStd_SequenceOfAsciiString aFileNames;
307 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
308 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
309 for (; itBig->More(); itBig->Next()) {
310 SALOMEDS::SObject_var gotBranch = itBig->Value();
311 CORBA::Object_var anObj = SObjectToObject(gotBranch);
312 if(CORBA::is_nil(anObj)) continue;
313 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in());
315 const Result_i::TSourceId& aSourceId = pResult->GetSourceId();
316 if(aSourceId == Result_i::eFile || aSourceId == Result_i::eRestoredFile){
317 const QFileInfo& aFileInfo = pResult->GetFileInfo();
319 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
320 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
321 static QString aCommand;
322 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
324 if(system(aCommand) == -1){
325 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
328 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
329 TCollection_AsciiString aString(strdup(aFileName.latin1()));
331 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
333 aFileNames.Append(aString);
337 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
338 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
339 if(aFileNames.Length() > 0){
340 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
341 aSeq->length(aFileNames.Length());
342 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
343 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
344 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
346 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
348 return aStreamFile._retn();
350 return myVisuGen->Save(theComponent,theURL,isMultiFile);
353 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
354 const char* IORString,
355 CORBA::Boolean isMultiFile,
356 CORBA::Boolean isASCII) {
357 if(MYDEBUG) MESSAGE("VISU_Gen_i::IORToLocalPersistentID - myMutex = "<<myMutex);
359 CORBA::String_var aString(IORString);
360 if(strcmp(IORString,"") != 0){
361 CORBA::ORB_ptr anORB = GetORB();
362 CORBA::Object_var anObj = anORB->string_to_object(aString);
363 if(!CORBA::is_nil(anObj)){
364 Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj).in());
365 if(pStorable != NULL){
366 Mutex mt(myMutex,qApp);
367 aString = pStorable->ToString().c_str();
368 return aString._retn();
372 return aString._retn();
374 return myVisuGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile, isASCII);
377 char* VISU_Gen_i::GetID(){
379 return Base_i::GetID();
380 return myVisuGen->GetID();
383 void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
385 if(CORBA::is_nil(theStudy))
386 INFOS("VISU_Gen_i::SetCurrentStudy : CORBA::is_nil(theStudy)");
387 if(!CORBA::is_nil(theStudy)){
388 CORBA::String_var aName = theStudy->Name();
389 INFOS("VISU_Gen_i::SetCurrentStudy - StudyId = "<<theStudy->StudyId()<<"; Name = '"<<aName.in()<<"'");
390 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
393 myVisuGen->SetCurrentStudy(theStudy);
395 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
397 return SALOMEDS::Study::_duplicate(myStudyDocument);
398 return myVisuGen->GetCurrentStudy();
400 ViewManager_ptr VISU_Gen_i::GetViewManager(){
402 //omni_mutex_lock aMutexLock(aMutex);
403 if(MYDEBUG) MESSAGE("VISU_Gen_i::GetViewManager : "<<myMutex);
405 Mutex mt(myMutex,qApp);
406 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
407 return ViewManager::_duplicate(aViewManager->_this());
409 return myVisuGen->GetViewManager();
412 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
414 if(myStudyDocument->GetProperties()->IsLocked()) return SALOMEDS::SObject::_nil();
415 Mutex mt(myMutex,qApp);
416 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
419 return myVisuGen->ImportTables(theFileName);
422 CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
423 const char* theFileName)
425 return VISU::ExportTableToFile(theTable, theFileName);
428 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
430 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
431 Mutex mt(myMutex,qApp);
432 aFileInfo.setFile(theFileName);
433 Result_i* pResult = new Result_i(myStudyDocument);
434 if(pResult->Create(theFileName) != NULL)
435 return pResult->_this();
437 pResult->_remove_ref();
438 return VISU::Result::_nil();
441 return myVisuGen->ImportFile(theFileName);
444 Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){
446 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
447 Mutex mt(myMutex,qApp);
448 VISU::Result_var aResult;
449 aFileInfo.setFile(theFileName);
450 Result_i* pResult = new Result_i(myStudyDocument,Result_i::eRestoredFile);
451 if(pResult->Create(theFileName) != NULL)
452 aResult = pResult->_this();
453 return aResult._retn();
455 return myVisuGen->CopyAndImportFile(theFileName);
458 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject){
459 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMed : "<<myMutex);
461 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
462 Mutex mt(myMutex,qApp);
463 Result_i* pResult = new Result_i(myStudyDocument);
464 if(pResult->Create(theMedSObject) != NULL)
465 return pResult->_this();
467 pResult->_remove_ref();
468 return VISU::Result::_nil();
471 return myVisuGen->ImportMed(theMedSObject);
474 Result_ptr VISU_Gen_i::ImportMedField(SALOME_MED::FIELD_ptr theField){
475 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedField : "<<myMutex);
477 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
478 Mutex mt(myMutex,qApp);
479 Result_i* pResult = new Result_i(myStudyDocument);
480 if(pResult->Create(theField) != NULL)
481 return pResult->_this();
483 pResult->_remove_ref();
484 return VISU::Result::_nil();
487 return myVisuGen->ImportMedField(theField);
490 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity){
491 if(MYDEBUG) MESSAGE("VISU_Gen_i::MeshOnEntity : "<<myMutex);
493 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
494 Mutex mt(myMutex,qApp);
495 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
496 Mesh_i* aPresent = new Mesh_i(pResult);
497 if(aPresent->Create(theMeshName,theEntity) != NULL)
498 return aPresent->_this();
500 aPresent->_remove_ref();
501 return VISU::Mesh::_nil();
504 return myVisuGen->MeshOnEntity(theResult,theMeshName,theEntity);
507 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName,
508 VISU::Entity theEntity,
509 const char* theFamilyName){
510 if(MYDEBUG) MESSAGE("VISU_Gen_i::FamilyMeshOnEntity : "<<myMutex);
512 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
513 Mutex mt(myMutex,qApp);
514 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
515 Mesh_i* aPresent = new Mesh_i(pResult);
516 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
517 return aPresent->_this();
519 aPresent->_remove_ref();
520 return VISU::Mesh::_nil();
523 return myVisuGen->FamilyMeshOnEntity(theResult,theMeshName,theEntity,theFamilyName);
526 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, const char* theMeshName,
527 const char* theGroupName){
528 if(MYDEBUG) MESSAGE("VISU_Gen_i::GroupMesh : "<<myMutex);
530 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
531 Mutex mt(myMutex,qApp);
532 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
533 Mesh_i* aPresent = new Mesh_i(pResult);
534 if(aPresent->Create(theMeshName,theGroupName) != NULL)
535 return aPresent->_this();
537 aPresent->_remove_ref();
538 return VISU::Mesh::_nil();
541 return myVisuGen->GroupMesh(theResult,theMeshName,theGroupName);
544 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
545 const char* theFieldName, CORBA::Double theIteration)
547 if(myMutex) return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
548 return myVisuGen->ScalarMapOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
551 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
552 const char* theFieldName, CORBA::Double theIteration)
554 if(myMutex) return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
555 return myVisuGen->DeformedShapeOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
558 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
559 const char* theFieldName, CORBA::Double theIteration)
561 if(myMutex) return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
562 return myVisuGen->VectorsOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
565 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
566 const char* theFieldName, CORBA::Double theIteration)
568 if(myMutex) return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
569 return myVisuGen->IsoSurfacesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
572 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
573 const char* theFieldName, CORBA::Double theIteration)
575 if(myMutex) return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
576 return myVisuGen->StreamLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
579 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
580 const char* theFieldName, CORBA::Double theIteration)
582 if(myMutex) return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
583 return myVisuGen->CutPlanesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
586 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
587 const char* theFieldName, CORBA::Double theIteration)
589 if(myMutex) return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
590 return myVisuGen->CutLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
593 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
594 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateTable : "<<myMutex);
596 if(myStudyDocument->GetProperties()->IsLocked()) return Table::_nil();
597 Mutex mt(myMutex,qApp);
598 Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry);
599 if(pPresent->Create() != NULL)
600 return pPresent->_this();
602 pPresent->_remove_ref();
603 return VISU::Table::_nil();
606 return myVisuGen->CreateTable(theTableEntry);
609 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow){
610 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateCurve : "<<myMutex);
612 if(myStudyDocument->GetProperties()->IsLocked()) return Curve::_nil();
613 Mutex mt(myMutex,qApp);
614 PortableServer::POA_ptr aPOA = GetPOA();
615 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
616 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
617 if(pPresent->Create() != NULL)
618 return pPresent->_this();
620 pPresent->_remove_ref();
621 return VISU::Curve::_nil();
624 return myVisuGen->CreateCurve(theTable,theHRow,theVRow);
626 Container_ptr VISU_Gen_i::CreateContainer(){
627 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateContainer : "<<myMutex);
629 if(myStudyDocument->GetProperties()->IsLocked()) return Container::_nil();
630 Mutex mt(myMutex,qApp);
631 Container_i* pPresent = new Container_i(myStudyDocument);
632 if(pPresent->Create() != NULL)
633 return pPresent->_this();
635 pPresent->_remove_ref();
636 return VISU::Container::_nil();
639 return myVisuGen->CreateContainer();
642 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
644 if(myStudyDocument->GetProperties()->IsLocked()) return Animation::_nil();
645 Mutex mt(myMutex,qApp);
646 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateAnimation : "<<myMutex);
647 if(VISU_TimeAnimation* anAnim = new VISU_TimeAnimation(myStudyDocument,theView3D)){
648 return anAnim->_this();
650 return VISU::Animation::_nil();
653 return myVisuGen->CreateAnimation(theView3D);
656 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
657 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : "<<myMutex);
659 //Mutex mt(myMutex,qApp);
660 //SALOMEDS::Study_var aStudy = theComponent->GetStudy();
661 //if(!aStudy->_is_nil()){
662 // SALOMEDS::ChildIterator_var aChildIter = aStudy->NewChildIterator(theComponent);
663 // aChildIter->InitEx(true);
664 // for (int i = 0; aChildIter->More(); aChildIter->Next(),i++) {
665 // SALOMEDS::SObject_var aSObject = aChildIter->Value();
666 // if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : aChildIter->Next() = "<<i);
667 // CORBA::Object_var anObj = SObjectToObject(aSObject);
668 // if(CORBA::is_nil(anObj)) continue;
669 // PortableServer::ServantBase_var aServant = GetServant(anObj);
670 // if(aServant.in() == NULL) continue;
671 // if(VISU::Base_i* pBase = dynamic_cast<VISU::Base_i*>(aServant.in())){
672 // VISU::VISUType aType = pBase->GetType();
674 // case VISU::TRESULT:
675 // if(VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(pBase)){
676 // //Try remove its file and directory
677 // if(pResult->GetSourceId() == Result_i::eRestoredFile){
678 // const QFileInfo& aFileInfo = pResult->GetFileInfo();
679 // static QString aCommand;
680 // aCommand.sprintf("rm %s",aFileInfo.filePath().latin1());
681 // if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
682 // aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",aFileInfo.dirPath().latin1());
683 // if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
695 myVisuGen->Close(theComponent);
698 char* VISU_Gen_i::ComponentDataType(){
699 return CORBA::string_dup("VISU");
702 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
703 Result_var aResultObj = Result::_narrow(theIOR);
704 return !(aResultObj->_is_nil());
707 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
708 SALOMEDS::SObject_ptr theSObject,
709 CORBA::Object_ptr theObject,
711 throw (SALOME::SALOME_Exception)
713 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
715 Mutex mt(myMutex,qApp);
716 SALOMEDS::SObject_var aResultSO;
717 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
718 if (!aResultObj) return aResultSO._retn();
719 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
720 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
721 aResultSO = theStudy->FindObjectID(anEntry);
722 return aResultSO._retn();
724 return myVisuGen->PublishInStudy(theStudy, theSObject, theObject, theName);
727 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
728 if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanCopy : "<<myMutex);
730 //Mutex mt(myMutex,qApp);
731 SALOMEDS::GenericAttribute_var anAttr;
732 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
734 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
735 CORBA::String_var aValue = anIOR->Value();
736 if(strcmp(aValue,"") != 0){
737 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
738 if (!CORBA::is_nil(anObj)){
739 Result_var aResultObj = Result::_narrow(anObj);
740 if(!aResultObj->_is_nil()){
741 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj).in())){
742 const Result_i::TSourceId& aSourceId = pResult->GetSourceId();
743 if(aSourceId == Result_i::eComponent || aSourceId == Result_i::eRestoredComponent)
744 if((pResult->GetFileInfo()).filePath() == "MED")
752 INFOS("Unknown exception was accured!");
756 return myVisuGen->CanCopy(theObject);
759 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
761 Mutex mt(myMutex,qApp);
764 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
765 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
767 PortableServer::POA_ptr aPOA = GetPOA();
769 SALOMEDS::GenericAttribute_var anAttr;
770 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
771 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
772 CORBA::Object_var aCorbaObj;
774 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
776 aStreamFile->length(1);
777 aStreamFile[0] = strdup("E")[0];
778 return aStreamFile._retn();
780 if (CORBA::is_nil(aCorbaObj)) {
784 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj).in());
788 CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
790 string aStr = pStorable->ToString().c_str();
791 ofstream stmOut2((string(aTmpDir) + string("copy_persistent")).c_str(),ios::out);
795 Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj));
797 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
798 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
799 aFileName += aFileInfo.fileName().latin1();
800 static QString aCommand;
801 aCommand.sprintf("cp %s %s",
802 aFileInfo.filePath().latin1(),
803 (string(aTmpDir) + aFileName).c_str());
804 if(system(aCommand) == -1) {
805 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
810 aSeq[0] = "copy_persistent";
811 aSeq[1] = aFileName.c_str();
814 aSeq[0] = "copy_persistent";
816 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
817 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
819 // Assign an ID = 1 the the type VISU::Result
823 SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
824 return aStreamFile._retn();
826 return myVisuGen->CopyFrom(theObject, theObjectID);
829 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
830 // The VISU component can paste only objects copied by VISU component
831 // and with the object type = 1
832 if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanPaste : "<<myMutex);
833 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
837 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
838 CORBA::Long theObjectID,
839 SALOMEDS::SObject_ptr theObject) {
840 if(MYDEBUG) MESSAGE("VISU_Gen_i::PasteInto : "<<myMutex);
842 Mutex mt(myMutex,qApp);
843 SALOMEDS::SObject_var aResultSO;
844 if (theObjectID != 1) return aResultSO._retn();
846 CORBA::String_var aTmpDir = (const char*)SALOMEDS_Tool::GetTmpDir();
847 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
849 ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str());
850 stmIn.seekg(0, ios::end);
851 int aLength = stmIn.tellg();
852 stmIn.seekg(0, ios::beg);
853 char* aString = new char[aLength+1];
854 stmIn.read(aString, aLength);
855 aString[aLength] = 0;
856 myIsMultiFile = false;
858 string aFileName(aTmpDir.in());
859 if(aSeq->length() > 1) aFileName += aSeq[1].in();
861 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
862 SALOMEDS::Study_var aStudy = theObject->GetStudy();
863 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
864 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
866 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
867 aResultSO = aStudyBuilder->NewObject(aComponent);
869 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
871 //Just for Result::Restore to find the Comment attribute :(
872 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
874 Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
876 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
878 aSeqToRm[0] = "copy_persistent";
879 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeqToRm.in(), true);
881 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
882 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
883 CORBA::String_var anIORValue(aStorable->GetID());
884 anIOR->SetValue(anIORValue);
885 return aResultSO._retn();
887 return myVisuGen->PasteInto(theStream,theObjectID,theObject);