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);
107 //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(),&(Mesh_i::Restore));
134 Storable::Registry(ScalarMap_i::myComment.c_str(),&(ScalarMap_i::Restore));
135 Storable::Registry(DeformedShape_i::myComment.c_str(),&(DeformedShape_i::Restore));
136 Storable::Registry(CutPlanes_i::myComment.c_str(),&(CutPlanes_i::Restore));
137 Storable::Registry(CutLines_i::myComment.c_str(),&(CutLines_i::Restore));
138 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(IsoSurfaces_i::Restore));
139 Storable::Registry(StreamLines_i::myComment.c_str(),&(StreamLines_i::Restore));
140 Storable::Registry(Vectors_i::myComment.c_str(),&(Vectors_i::Restore));
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(aFileInfo.baseName());
189 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
192 Base_i::myPOA->activate_object(this);
195 VISU_Gen_i::~VISU_Gen_i(){
196 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
198 //===========================================================================
199 bool VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
200 const SALOMEDS::TMPFile & theStream,
204 if(MYDEBUG) MESSAGE("VISU_Gen_i::Load - myMutex = "<<myMutex);
206 Mutex mt(myMutex,qApp);
207 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
208 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
209 TCollection_AsciiString aTmpDir =
210 isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
211 VisuTmpDir = aTmpDir.ToCString();
212 SALOMEDS::ListOfFileNames_var aSeq =
213 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
214 myIsMultiFile = isMultiFile;
217 return myVisuGen->Load(theComponent,theStream,theURL,isMultiFile);
220 bool VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
221 const SALOMEDS::TMPFile & theStream,
225 return Load(theComponent, theStream, theURL, isMultiFile);
228 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
229 const char* aLocalPersistentID,
230 CORBA::Boolean isMultiFile,
231 CORBA::Boolean isASCII)
234 CORBA::String_var aString("");
235 if(strcmp(aLocalPersistentID,"") != 0) {
236 Mutex mt(myMutex,qApp);
237 Storable* aStorable =
238 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
239 if(aStorable != NULL) aString = aStorable->GetID();
241 return aString._retn();
243 return myVisuGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile, isASCII);
245 //===========================================================================
246 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
250 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<<myMutex);
252 Mutex mt(myMutex,qApp);
253 CORBA::String_var aString = SALOMEDS_Tool::GetTmpDir();
254 TCollection_AsciiString aTmpDir = isMultiFile? (const Standard_CString)theURL: (const Standard_CString)aString.in();
255 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
257 TColStd_SequenceOfAsciiString aFileNames;
258 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
259 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
260 for (; itBig->More(); itBig->Next()) {
261 SALOMEDS::SObject_var gotBranch = itBig->Value();
262 CORBA::Object_var anObj = SObjectToObject(gotBranch);
263 if(CORBA::is_nil(anObj)) continue;
264 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
265 if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){
266 const QFileInfo& aFileInfo = pResult->GetFileInfo();
267 QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
268 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
269 static QString aCommand;
270 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
271 if(system(aCommand) == -1){
272 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
275 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
276 TCollection_AsciiString aString(strdup(aFileName.latin1()));
277 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));
314 if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){
315 const QFileInfo& aFileInfo = pResult->GetFileInfo();
316 QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
317 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
318 static QString aCommand;
319 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
321 if(system(aCommand) == -1){
322 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
325 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
326 TCollection_AsciiString aString(strdup(aFileName.latin1()));
328 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
330 aFileNames.Append(aString);
333 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
334 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
335 if(aFileNames.Length() > 0){
336 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
337 aSeq->length(aFileNames.Length());
338 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
339 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
340 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
342 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
344 return aStreamFile._retn();
346 return myVisuGen->Save(theComponent,theURL,isMultiFile);
349 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
350 const char* IORString,
351 CORBA::Boolean isMultiFile,
352 CORBA::Boolean isASCII) {
353 if(MYDEBUG) MESSAGE("VISU_Gen_i::IORToLocalPersistentID - myMutex = "<<myMutex);
355 CORBA::String_var aString(IORString);
356 if(strcmp(IORString,"") != 0){
357 CORBA::ORB_ptr anORB = GetORB();
358 CORBA::Object_var anObj = anORB->string_to_object(aString);
359 if(!CORBA::is_nil(anObj)){
360 Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj));
361 if(pStorable != NULL){
362 Mutex mt(myMutex,qApp);
363 aString = pStorable->ToString().c_str();
364 return aString._retn();
368 return aString._retn();
370 return myVisuGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile, isASCII);
373 char* VISU_Gen_i::GetID(){
375 return Base_i::GetID();
376 return myVisuGen->GetID();
379 void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
381 if(!CORBA::is_nil(theStudy))
382 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
384 myVisuGen->SetCurrentStudy(SALOMEDS::Study::_duplicate(theStudy));
386 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
388 return SALOMEDS::Study::_duplicate(myStudyDocument);
389 return myVisuGen->GetCurrentStudy();
391 ViewManager_ptr VISU_Gen_i::GetViewManager(){
393 //omni_mutex_lock aMutexLock(aMutex);
394 if(MYDEBUG) MESSAGE("VISU_Gen_i::GetViewManager : "<<myMutex);
396 Mutex mt(myMutex,qApp);
397 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
398 return ViewManager::_duplicate(aViewManager->_this());
400 return myVisuGen->GetViewManager();
403 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
405 if(myStudyDocument->GetProperties()->IsLocked()) return SALOMEDS::SObject::_nil();
406 Mutex mt(myMutex,qApp);
407 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
410 return myVisuGen->ImportTables(theFileName);
413 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
415 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
416 Mutex mt(myMutex,qApp);
417 VISU::Result_var aResult;
418 aFileInfo.setFile(theFileName);
419 Result_i* pResult = new Result_i(myStudyDocument);
420 if(pResult->Create(theFileName) != NULL)
421 aResult = pResult->_this();
422 return aResult._retn();
424 return myVisuGen->ImportFile(theFileName);
427 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject){
428 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMed : "<<myMutex);
430 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
431 Mutex mt(myMutex,qApp);
432 Result_i* pResult = new Result_i(myStudyDocument);
433 if(pResult->Create(theMedSObject) != NULL)
434 return Result::_duplicate(pResult->_this());
435 return Result::_nil();
437 return myVisuGen->ImportMed(theMedSObject);
440 Result_ptr VISU_Gen_i::ImportMedField(SALOME_MED::FIELD_ptr theField){
441 if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedField : "<<myMutex);
443 if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil();
444 Mutex mt(myMutex,qApp);
445 Result_i* pResult = new Result_i(myStudyDocument);
446 if(pResult->Create(theField) != NULL)
447 return Result::_duplicate(pResult->_this());
448 return Result::_nil();
450 return myVisuGen->ImportMedField(theField);
453 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity){
454 if(MYDEBUG) MESSAGE("VISU_Gen_i::MeshOnEntity : "<<myMutex);
456 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
457 Mutex mt(myMutex,qApp);
458 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
459 Mesh_i* aPresent = new Mesh_i(pResult);
460 if(aPresent->Create(theMeshName,theEntity) != NULL)
461 return Mesh::_duplicate(aPresent->_this());
464 return myVisuGen->MeshOnEntity(theResult,theMeshName,theEntity);
467 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName,
468 VISU::Entity theEntity,
469 const char* theFamilyName){
470 if(MYDEBUG) MESSAGE("VISU_Gen_i::FamilyMeshOnEntity : "<<myMutex);
472 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
473 Mutex mt(myMutex,qApp);
474 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
475 Mesh_i* aPresent = new Mesh_i(pResult);
476 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
477 return Mesh::_duplicate(aPresent->_this());
480 return myVisuGen->FamilyMeshOnEntity(theResult,theMeshName,theEntity,theFamilyName);
483 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, const char* theMeshName,
484 const char* theGroupName){
485 if(MYDEBUG) MESSAGE("VISU_Gen_i::GroupMesh : "<<myMutex);
487 if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil();
488 Mutex mt(myMutex,qApp);
489 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult));
490 Mesh_i* aPresent = new Mesh_i(pResult);
491 if(aPresent->Create(theMeshName,theGroupName) != NULL)
492 return Mesh::_duplicate(aPresent->_this());
495 return myVisuGen->GroupMesh(theResult,theMeshName,theGroupName);
498 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
499 const char* theFieldName, CORBA::Double theIteration)
501 if(myMutex) return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration);
502 return myVisuGen->ScalarMapOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
505 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
506 const char* theFieldName, CORBA::Double theIteration)
508 if(myMutex) return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration);
509 return myVisuGen->DeformedShapeOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
512 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
513 const char* theFieldName, CORBA::Double theIteration)
515 if(myMutex) return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration);
516 return myVisuGen->VectorsOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
519 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
520 const char* theFieldName, CORBA::Double theIteration)
522 if(myMutex) return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration);
523 return myVisuGen->IsoSurfacesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
526 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
527 const char* theFieldName, CORBA::Double theIteration)
529 if(myMutex) return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration);
530 return myVisuGen->StreamLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
533 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
534 const char* theFieldName, CORBA::Double theIteration)
536 if(myMutex) return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration);
537 return myVisuGen->CutPlanesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
540 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity,
541 const char* theFieldName, CORBA::Double theIteration)
543 if(myMutex) return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration);
544 return myVisuGen->CutLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration);
547 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
548 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateTable : "<<myMutex);
550 if(myStudyDocument->GetProperties()->IsLocked()) return Table::_nil();
551 Mutex mt(myMutex,qApp);
552 Table_i* aPresent = new Table_i(myStudyDocument,theTableEntry);
553 if(aPresent->Create() != NULL)
554 return Table::_duplicate(aPresent->_this());
555 return Table::_nil();
557 return myVisuGen->CreateTable(theTableEntry);
560 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow){
561 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateCurve : "<<myMutex);
563 if(myStudyDocument->GetProperties()->IsLocked()) return Curve::_nil();
564 Mutex mt(myMutex,qApp);
565 PortableServer::POA_ptr aPOA = GetPOA();
566 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
567 Curve_i* aPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
568 if(aPresent->Create() != NULL) {
569 return Curve::_duplicate(aPresent->_this());
571 return Curve::_nil();
573 return myVisuGen->CreateCurve(theTable,theHRow,theVRow);
575 Container_ptr VISU_Gen_i::CreateContainer(){
576 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateContainer : "<<myMutex);
578 if(myStudyDocument->GetProperties()->IsLocked()) return Container::_nil();
579 Mutex mt(myMutex,qApp);
580 Container_i* aPresent = new Container_i(myStudyDocument);
581 if(aPresent->Create() != NULL) {
582 return Container::_duplicate(aPresent->_this());
584 return Container::_nil();
586 return myVisuGen->CreateContainer();
589 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
591 if(myStudyDocument->GetProperties()->IsLocked()) return Animation::_nil();
592 Mutex mt(myMutex,qApp);
593 if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateAnimation : "<<myMutex);
594 VISU_TimeAnimation* anAnim = new VISU_TimeAnimation(myStudyDocument,theView3D);
595 return Animation::_duplicate(anAnim->_this());
597 return myVisuGen->CreateAnimation(theView3D);
600 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
601 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : "<<myMutex);
603 Mutex mt(myMutex,qApp);
604 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
605 if(!aStudy->_is_nil()){
606 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
607 for (int i = 0; itBig->More(); itBig->Next(),i++) {
608 SALOMEDS::SObject_var gotBranch = itBig->Value();
609 if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : itBig->Next() = "<<i);
610 CORBA::Object_var anObj = SObjectToObject(gotBranch);
611 if(CORBA::is_nil(anObj)) continue;
612 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj));
613 if(!pResult) continue;
614 if(pResult->GetSourceId() == Result_i::eRestoredFile){ //Try remove its file and directory
615 const QFileInfo& aFileInfo = pResult->GetFileInfo();
616 static QString aCommand;
617 aCommand.sprintf("rm %s",aFileInfo.filePath().latin1());
618 if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
619 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",aFileInfo.dirPath().latin1());
620 if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<<aCommand);
626 myVisuGen->Close(theComponent);
629 char* VISU_Gen_i::ComponentDataType(){
630 return CORBA::string_dup("VISU");
633 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
634 Result_var aResultObj = Result::_narrow(theIOR);
635 return !(aResultObj->_is_nil());
638 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
639 SALOMEDS::SObject_ptr theSObject,
640 CORBA::Object_ptr theObject,
642 throw (SALOME::SALOME_Exception)
644 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
646 Mutex mt(myMutex,qApp);
647 SALOMEDS::SObject_var aResultSO;
648 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject));
649 if (!aResultObj) return aResultSO._retn();
650 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
651 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
652 aResultSO = theStudy->FindObjectID(anEntry);
653 return aResultSO._retn();
655 return myVisuGen->PublishInStudy(theStudy, theSObject, theObject, theName);
658 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
659 if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanCopy : "<<myMutex);
661 //Mutex mt(myMutex,qApp);
662 SALOMEDS::GenericAttribute_var anAttr;
663 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
665 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
666 CORBA::String_var aValue = anIOR->Value();
667 if(strcmp(aValue,"") != 0){
668 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
669 if (!CORBA::is_nil(anObj)){
670 Result_var aResultObj = Result::_narrow(anObj);
671 if(!aResultObj->_is_nil()){
672 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj));
674 if(abs(pResult->GetSourceId()) > Result_i::eFile)
675 if((pResult->GetFileInfo()).filePath() == "MED") return false;
682 INFOS("Unknown exception was accured!");
686 return myVisuGen->CanCopy(theObject);
689 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
690 if(MYDEBUG) MESSAGE("VISU_Gen_i::CopyFrom : "<<myMutex);
692 Mutex mt(myMutex,qApp);
695 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
696 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
698 PortableServer::POA_ptr aPOA = GetPOA();
700 SALOMEDS::GenericAttribute_var anAttr;
701 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
702 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
703 CORBA::Object_var aCorbaObj;
705 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
707 aStreamFile->length(1);
708 aStreamFile[0] = strdup("E")[0];
709 return aStreamFile._retn();
711 if (CORBA::is_nil(aCorbaObj)) {
715 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj));
719 CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
721 string aStr = pStorable->ToString().c_str();
722 ofstream stmOut2((string(aTmpDir) + string("copy_persistent")).c_str(),ios::out);
726 Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj));
728 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
729 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
730 aFileName += aFileInfo.fileName().latin1();
731 static QString aCommand;
732 aCommand.sprintf("cp %s %s",
733 aFileInfo.filePath().latin1(),
734 (string(aTmpDir) + aFileName).c_str());
735 if(system(aCommand) == -1) {
736 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
741 aSeq[0] = "copy_persistent";
742 aSeq[1] = aFileName.c_str();
745 aSeq[0] = "copy_persistent";
747 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
748 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
750 // Assign an ID = 1 the the type VISU::Result
754 SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
755 return aStreamFile._retn();
757 return myVisuGen->CopyFrom(theObject, theObjectID);
760 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
761 // The VISU component can paste only objects copied by VISU component
762 // and with the object type = 1
763 if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanPaste : "<<myMutex);
764 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
768 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
769 CORBA::Long theObjectID,
770 SALOMEDS::SObject_ptr theObject) {
771 if(MYDEBUG) MESSAGE("VISU_Gen_i::PasteInto : "<<myMutex);
773 Mutex mt(myMutex,qApp);
774 SALOMEDS::SObject_var aResultSO;
775 if (theObjectID != 1) return aResultSO._retn();
777 CORBA::String_var aTmpDir = (const char*)SALOMEDS_Tool::GetTmpDir();
778 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
780 ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str());
781 // ifstream stmIn((string(aTmpDir) + string("copy_persistent")).c_str(),ios::in);
782 stmIn.seekg(0, ios::end);
783 int aLength = stmIn.tellg();
784 stmIn.seekg(0, ios::beg);
785 char* aString = new char[aLength+1];
786 stmIn.read(aString, aLength);
787 aString[aLength] = 0;
788 myIsMultiFile = true;
790 string aFileName(aTmpDir.in());
791 if(aSeq->length() > 1) aFileName += aSeq[1].in();
793 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
794 SALOMEDS::Study_var aStudy = theObject->GetStudy();
795 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
796 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
798 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
799 aResultSO = aStudyBuilder->NewObject(aComponent);
801 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
803 //Just for Result::Restore to find the Comment attribute :(
804 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
806 Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
808 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
810 aSeqToRm[0] = "copy_persistent";
811 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeqToRm.in(), true);
813 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
814 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
815 CORBA::String_var anIORValue(aStorable->GetID());
816 anIOR->SetValue(anIORValue);
817 return aResultSO._retn();
819 return myVisuGen->PasteInto(theStream,theObjectID,theObject);