1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_Gen_i.cc
25 // Author : Alexey PETROV
28 #include "VISU_Gen_i.hh"
29 #include "VISU_Result_i.hh"
30 #include "VISU_PrsObject_i.hh"
31 #include "VISU_ViewManager_i.hh"
33 #include "VISU_Prs3d_i.hh"
34 #include "VISU_Mesh_i.hh"
35 #include "VISU_Table_i.hh"
36 #include "VISU_PointMap3d_i.hh"
37 #include "VISU_TimeAnimation.h"
38 #include "VISU_Evolution.h"
40 #include "VISU_ColoredPrs3dFactory.hh"
41 #include "VISU_ColoredPrs3dCache_i.hh"
42 #include "VISU_ColoredPrs3dHolder_i.hh"
44 #include <VISU_Vtk2MedConvertor.hxx>
46 #include "VISU_Actor.h"
49 #include "HDFascii.hxx"
50 #include "SALOMEDS_Tool.hxx"
52 #include "SALOMEDSClient_AttributeName.hxx"
53 #include "SALOMEDSClient_AttributePixMap.hxx"
55 #include "SUIT_Session.h"
56 #include "SalomeApp_Study.h"
57 #include "SalomeApp_Application.h"
58 #include "LightApp_SelectionMgr.h"
59 #include "VTKViewer_MarkerUtils.h"
60 #include "SVTK_ViewModel.h"
61 #include "SVTK_ViewWindow.h"
62 #include "SALOME_Event.h"
63 #include "SALOME_ListIO.hxx"
64 #include "SALOME_ListIteratorOfListIO.hxx"
66 #include "utilities.h"
69 #include <omnithread.h>
70 #include CORBA_SERVER_HEADER(SALOME_Session)
71 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
72 #include CORBA_SERVER_HEADER(MED_Gen)
79 #include <vtkRenderer.h>
80 #include <vtkActorCollection.h>
83 #include <TCollection_AsciiString.hxx>
84 #include <TColStd_SequenceOfAsciiString.hxx>
86 #include "Utils_ExceptHandlers.hxx"
87 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
92 #include <boost/filesystem/path.hpp>
93 #include <boost/filesystem/operations.hpp>
94 namespace filesystem = boost::filesystem;
98 static int MYDEBUG = 0;
100 static int MYDEBUG = 0;
106 VISU_I_EXPORT VISU::VISU_Gen_ptr
107 GetImpl(CORBA::ORB_ptr theORB,
108 PortableServer::POA_ptr thePOA,
109 SALOME_NamingService* theNamingService,
112 if(MYDEBUG) MESSAGE("extern 'C' GetImpl");
113 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
114 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
115 return aVISU_Gen->_this();
120 //----------------------------------------------------------------------------
121 static std::string VISU_TMP_DIR;
123 static CORBA::Boolean myIsMultiFile;
124 const CORBA::Boolean IsMultiFile()
126 return myIsMultiFile;
129 //----------------------------------------------------------------------------
131 ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
133 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
135 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
136 aStudyBuilder->NewCommand();
137 int aLocked = theStudyDocument->GetProperties()->IsLocked();
138 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
139 aSComponent = aStudyBuilder->NewComponent("VISU");
140 _PTR(GenericAttribute) anAttr =
141 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
142 _PTR(AttributeName) aName (anAttr);
144 CORBA::ORB_var anORB = Base_i::GetORB();
145 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
146 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
147 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
148 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
149 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
150 if (!Comp->_is_nil()) {
151 aName->SetValue(Comp->componentusername());
154 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
155 _PTR(AttributePixMap) aPixmap (anAttr);
156 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
158 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
159 aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
160 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
161 aStudyBuilder->CommitCommand();
167 //----------------------------------------------------------------------------
168 SALOMEDS::SComponent_var
169 FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument)
171 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
172 if (aSComponent->_is_nil()) {
173 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
174 aStudyBuilder->NewCommand();
175 int aLocked = theStudyDocument->GetProperties()->IsLocked();
176 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
177 aSComponent = aStudyBuilder->NewComponent("VISU");
178 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
179 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
181 //NRI aName->SetValue("Visu");
182 CORBA::ORB_var anORB = Base_i::GetORB();
183 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
184 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
185 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
186 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
187 if ( !Comp->_is_nil() ) {
188 aName->SetValue( Comp->componentusername() );
191 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
192 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
193 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
195 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
196 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
197 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
198 aStudyBuilder->CommitCommand();
204 //----------------------------------------------------------------------------
208 Storable::RegistryStorableEngine(Result_i::myComment.c_str(),&(Result_i::StorableEngine));
210 Storable::RegistryStorableEngine(Mesh_i::myComment.c_str(),&(Mesh_i::StorableEngine));
212 Storable::RegistryStorableEngine(ScalarMap_i::myComment.c_str(),&(StorableEngine<ScalarMap_i>));
213 Storable::RegistryStorableEngine(GaussPoints_i::myComment.c_str(),&(StorableEngine<GaussPoints_i>));
214 Storable::RegistryStorableEngine(DeformedShape_i::myComment.c_str(),&(StorableEngine<DeformedShape_i>));
215 Storable::RegistryStorableEngine(CutPlanes_i::myComment.c_str(),&(StorableEngine<CutPlanes_i>));
216 Storable::RegistryStorableEngine(CutLines_i::myComment.c_str(),&(StorableEngine<CutLines_i>));
217 Storable::RegistryStorableEngine(CutSegment_i::myComment.c_str(),&(StorableEngine<CutSegment_i>));
218 Storable::RegistryStorableEngine(IsoSurfaces_i::myComment.c_str(),&(StorableEngine<IsoSurfaces_i>));
219 Storable::RegistryStorableEngine(StreamLines_i::myComment.c_str(),&(StorableEngine<StreamLines_i>));
220 Storable::RegistryStorableEngine(Plot3D_i::myComment.c_str(),&(StorableEngine<Plot3D_i>));
221 Storable::RegistryStorableEngine(Vectors_i::myComment.c_str(),&(StorableEngine<Vectors_i>));
222 Storable::RegistryStorableEngine(DeformedShapeAndScalarMap_i::myComment.c_str(),&(StorableEngine<DeformedShapeAndScalarMap_i>));
224 Storable::RegistryStorableEngine(ColoredPrs3dHolder_i::myComment.c_str(),&(ColoredPrs3dHolder_i::StorableEngine));
225 Storable::RegistryStorableEngine(ColoredPrs3dCache_i::myComment.c_str(),&(ColoredPrs3dCache_i::StorableEngine));
227 Storable::RegistryStorableEngine(PointMap3d_i::myComment.c_str(),&(PointMap3d_i::StorableEngine));
228 Storable::RegistryStorableEngine(Table_i::myComment.c_str(),&(Table_i::StorableEngine));
229 Storable::RegistryStorableEngine(Curve_i::myComment.c_str(),&(Curve_i::StorableEngine));
230 Storable::RegistryStorableEngine(Container_i::myComment.c_str(),&(Container_i::StorableEngine));
234 //----------------------------------------------------------------------------
235 SALOMEDS::ListOfFileNames*
236 GetListOfFileNames(const Result_i::TFileNames& theFileNames)
238 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
239 if(!theFileNames.empty()){
240 aListOfFileNames->length(theFileNames.size());
241 for(int aCounter = theFileNames.size(); aCounter > 0; aCounter--)
242 aListOfFileNames[aCounter-1] = theFileNames[aCounter-1].c_str();
244 return aListOfFileNames._retn();
248 //----------------------------------------------------------------------------
250 LoadMarkerMap(SALOMEDS::Study_ptr theStudy,
254 StudyId2MarkerMap& theStudyId2MarkerMap,
255 std::string& theMarkerMapFileName,
256 std::string& theMarkerMapFile)
259 if( theIsMultiFile ) {
260 CORBA::String_var anURL = theStudy->URL();
261 aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
264 theMarkerMapFileName = aPrefix + "_textures";
265 theMarkerMapFile = VISU_TMP_DIR + theMarkerMapFileName;
267 if( theIsASCII && !HDFascii::ConvertFromASCIIToHDF( const_cast<char*>( theMarkerMapFile.c_str() ), true ) )
271 HDFdataset* aDataset;
275 HDFgroup* aSubSubGroup;
278 aFile = new HDFfile( (char*)theMarkerMapFile.c_str() );
280 aFile->OpenOnDisk( HDF_RDONLY );
282 catch ( HDFexception ) {
283 INFOS( "Load(): " << theMarkerMapFile << " not found!" );
287 VTK::MarkerMap& aMarkerMap = theStudyId2MarkerMap[ theStudy->StudyId() ];
289 for( int i = 0, n = aFile->nInternalObjects(); i < n; i++ ) {
290 char markerGrpName[ HDF_NAME_MAX_LEN+1 ];
291 aFile->InternalObjectIndentify( i, markerGrpName );
294 std::string aMarkerFile;
295 VTK::MarkerTexture aMarkerTexture;
297 if( string( markerGrpName ).substr( 0, 6 ) == string( "Marker" ) ) {
298 aTopGroup = new HDFgroup( markerGrpName, aFile );
299 aTopGroup->OpenOnDisk();
301 aMarkerId = atoi( string( markerGrpName ).substr( 6 ).c_str() );
305 if( aTopGroup->ExistInternalObject( "File" ) ) {
306 aDataset = new HDFdataset( "File", aTopGroup );
307 aDataset->OpenOnDisk();
308 aSize = aDataset->GetSize();
309 char* aFileName = new char[ aSize ];
310 aDataset->ReadFromDisk( aFileName );
311 aMarkerFile = aFileName;
313 aDataset->CloseOnDisk();
316 if( aTopGroup->ExistInternalObject( "Texture" ) ) {
317 aDataset = new HDFdataset( "Texture", aTopGroup );
318 aDataset->OpenOnDisk();
319 aSize = aDataset->GetSize();
320 int* aTextureData = new int[ aSize ];
321 aDataset->ReadFromDisk( aTextureData );
322 for( int j = 0; j < aSize; j++ )
323 aMarkerTexture.push_back( aTextureData[j] );
324 delete [] aTextureData;
325 aDataset->CloseOnDisk();
328 aTopGroup->CloseOnDisk();
332 aMarkerMap[ aMarkerId ] = VTK::MarkerData( aMarkerFile, aMarkerTexture );
335 aFile->CloseOnDisk();
341 //----------------------------------------------------------------------------
343 SaveMarkerMap(SALOMEDS::Study_ptr theStudy,
347 const StudyId2MarkerMap& theStudyId2MarkerMap,
348 std::string& theMarkerMapFileName,
349 std::string& theMarkerMapFile)
351 VISU::StudyId2MarkerMap::const_iterator aMainIter = theStudyId2MarkerMap.find( theStudy->StudyId() );
352 if( aMainIter == theStudyId2MarkerMap.end() )
355 const VTK::MarkerMap& aMarkerMap = aMainIter->second;
356 if( aMarkerMap.empty() )
360 if( theIsMultiFile ) {
361 CORBA::String_var anURL = theStudy->URL();
362 aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
365 theMarkerMapFileName = aPrefix + "_textures";
366 theMarkerMapFile = string( theURL ) + theMarkerMapFileName;
369 HDFdataset* aDataset;
373 HDFgroup* aSubSubGroup;
376 aFile = new HDFfile( (char*)theMarkerMapFile.c_str() );
377 aFile->CreateOnDisk();
379 VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
380 for( ; aMarkerIter != aMarkerMap.end(); aMarkerIter++ ) {
381 int aMarkerId = aMarkerIter->first;
382 const VTK::MarkerData& aMarkerData = aMarkerIter->second;
383 std::string aMarkerFile = aMarkerData.first;
384 VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
386 char markerGrpName[30];
387 sprintf( markerGrpName, "Marker %d", aMarkerId );
388 aTopGroup = new HDFgroup( markerGrpName, aFile );
390 aTopGroup->CreateOnDisk();
392 aSize[ 0 ] = aMarkerFile.length() + 1;
393 aDataset = new HDFdataset( "File", aTopGroup, HDF_STRING, aSize, 1 );
394 aDataset->CreateOnDisk();
395 aDataset->WriteOnDisk( ( char* )( aMarkerFile.c_str() ) );
396 aDataset->CloseOnDisk();
398 int* aTextureData = new int[ aMarkerTexture.size() ];
399 VTK::MarkerTexture::const_iterator anIter = aMarkerTexture.begin();
400 for( int i = 0; anIter != aMarkerTexture.end(); anIter++, i++ )
401 aTextureData[i] = *anIter;
403 aSize[0] = aMarkerTexture.size();
404 aDataset = new HDFdataset( "Texture", aTopGroup, HDF_INT32, aSize, 1 );
405 aDataset->CreateOnDisk();
406 aDataset->WriteOnDisk( aTextureData );
407 aDataset->CloseOnDisk();
408 delete [] aTextureData;
410 aTopGroup->CloseOnDisk();
413 aFile->CloseOnDisk();
416 if( theIsASCII && !HDFascii::ConvertFromHDFToASCII( const_cast<char*>( theMarkerMapFile.c_str() ), true ) )
423 //----------------------------------------------------------------------------
425 ::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
426 SALOME_NamingService* theNamingService, QMutex* theMutex) :
427 Engines_Component_i()
429 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
430 Base_i::myMutex = theMutex; //apo
431 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
432 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
433 Base_i::myNamingService = theNamingService;
434 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
435 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
436 Base_i::myVisuGenImpl = this;
439 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
440 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
441 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
442 if(aListOfOpenStudies->length() > 0) {
443 CORBA::String_var aStudyName = aListOfOpenStudies[0];
444 //aFileInfo.setFile(aStudyName.in());
445 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
446 myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument));
448 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
452 //----------------------------------------------------------------------------
455 ::CreatePrs3d(VISUType theType,
456 SALOMEDS::Study_ptr theStudy)
458 if(ColoredPrs3d_i* aPrs3d = CreatePrs3d_i(theType, theStudy, ColoredPrs3d_i::EPublishIndependently))
459 return aPrs3d->_this();
460 return Prs3d::_nil();
464 //----------------------------------------------------------------------------
468 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
472 //----------------------------------------------------------------------------
474 CorrectSObjectType(SALOMEDS::SObject_ptr theSObject,
475 SALOMEDS::StudyBuilder_ptr theBuilder)
477 SALOMEDS::GenericAttribute_var anAttr;
478 bool isAttrStringFound = false;
480 if( theSObject->FindAttribute(anAttr, "AttributeComment") ) {
481 //SRN: Replace an AttributeComment with AttributeString
482 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
483 string aValue = aComment->Value();
484 theBuilder->RemoveAttribute(theSObject, "AttributeComment");
485 anAttr = theBuilder->FindOrCreateAttribute(theSObject, "AttributeString");
486 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
487 aStringAttr->SetValue(aValue.c_str());
488 isAttrStringFound = true;
491 if ( isAttrStringFound || theSObject->FindAttribute(anAttr, "AttributeString") ) {
492 SALOMEDS::AttributeString_var aAttComment = SALOMEDS::AttributeString::_narrow(anAttr);
494 CORBA::String_var aValue = aAttComment->Value();
495 std::string aString = Storable::CorrectPersistentString(aValue.in());
496 aAttComment->SetValue( aString.c_str() );
502 //----------------------------------------------------------------------------
504 LoadWithMarkerMap(SALOMEDS::SComponent_ptr theComponent,
505 const SALOMEDS::TMPFile & theStream,
507 CORBA::Boolean theIsMultiFile,
508 CORBA::Boolean theIsASCII,
509 StudyId2MarkerMap& theStudyId2MarkerMap)
511 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
513 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
514 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
516 for (anIter->InitEx(true); anIter->More(); anIter->Next()) {
517 SALOMEDS::SObject_var aSObject = anIter->Value();
518 CorrectSObjectType(aSObject, aStudyBuilder);
521 VISU_TMP_DIR = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
522 SALOMEDS::ListOfFileNames_var aSeq =
523 SALOMEDS_Tool::PutStreamToFiles(theStream, VISU_TMP_DIR, theIsMultiFile);
524 myIsMultiFile = theIsMultiFile;
526 // load textures of custom point markers
527 Result_i::TFileNames aTMPFileNames;
528 std::string aMarkerMapFileName, aMarkerMapFile;
529 if( LoadMarkerMap( aStudy, theURL, theIsMultiFile, theIsASCII,
530 theStudyId2MarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
531 aTMPFileNames.push_back( aMarkerMapFileName );
534 if(!theIsMultiFile && !aTMPFileNames.empty()) {
535 SALOMEDS::ListOfFileNames_var aListOfTMPFileNames = GetListOfFileNames(aTMPFileNames);
536 SALOMEDS_Tool::RemoveTemporaryFiles(VISU_TMP_DIR, aListOfTMPFileNames, true );
543 //----------------------------------------------------------------------------
546 ::Load(SALOMEDS::SComponent_ptr theComponent,
547 const SALOMEDS::TMPFile & theStream,
549 CORBA::Boolean theIsMultiFile)
552 return LoadWithMarkerMap(theComponent, theStream, theURL, theIsMultiFile, false, myMarkerMap);
556 //----------------------------------------------------------------------------
559 ::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
560 const SALOMEDS::TMPFile & theStream,
565 return LoadWithMarkerMap(theComponent, theStream, theURL, theIsMultiFile, true, myMarkerMap);
569 //----------------------------------------------------------------------------
572 ::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
573 const char* theLocalPersistentID,
574 CORBA::Boolean theIsMultiFile,
575 CORBA::Boolean theIsASCII)
577 CORBA::String_var aString("");
578 if(strcmp(theLocalPersistentID,"") != 0) {
579 Storable* aStorable = Storable::Create(theSObject,
580 theLocalPersistentID,
583 if(aStorable != NULL)
584 aString = aStorable->GetID();
586 return aString._retn();
590 //----------------------------------------------------------------------------
593 ::Save(SALOMEDS::SComponent_ptr theComponent,
597 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - theURL = '"<<theURL<<"'");
599 Result_i::TFileNames aFileNames;
600 Result_i::TFileNames aFiles;
602 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
603 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
604 for (; anIter->More(); anIter->Next()) {
605 SALOMEDS::SObject_var aSObject = anIter->Value();
606 CORBA::Object_var anObj = SObjectToObject(aSObject);
607 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
608 aResult->Save(theComponent,
616 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<<aFileNames.size());
618 // save textures of custom point markers
619 Result_i::TFileNames aTMPFileNames;
620 std::string aMarkerMapFileName, aMarkerMapFile;
621 if( SaveMarkerMap( aStudy, theURL, theIsMultiFile, false,
622 myMarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
623 aTMPFileNames.push_back( aMarkerMapFileName );
624 aFileNames.push_back( aMarkerMapFileName );
625 aFiles.push_back( aMarkerMapFile );
628 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
629 if(aFileNames.empty())
630 return aStreamFile._retn();
632 SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
633 SALOMEDS::ListOfFileNames_var aListOfFiles = GetListOfFileNames(aFiles);
636 aStreamFile = SALOMEDS_Tool::PutFilesToStream(theURL, aListOfFiles.in(), theIsMultiFile);
638 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in());
640 if(!theIsMultiFile && !aTMPFileNames.empty()) {
641 SALOMEDS::ListOfFileNames_var aListOfTMPFileNames = GetListOfFileNames(aTMPFileNames);
642 SALOMEDS_Tool::RemoveTemporaryFiles(theURL, aListOfTMPFileNames, true);
645 return aStreamFile._retn();
649 //----------------------------------------------------------------------------
652 ::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
656 std::string anURL = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
657 if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - "<<anURL);
659 Result_i::TFileNames aFileNames;
660 Result_i::TFileNames aFiles;
662 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
663 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
664 for (; anIter->More(); anIter->Next()) {
665 SALOMEDS::SObject_var aSObject = anIter->Value();
666 CORBA::Object_var anObj = SObjectToObject(aSObject);
667 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
668 aResult->Save(theComponent,
676 if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - aFileNames.size() - "<<aFileNames.size());
678 // save textures of custom point markers
679 std::string aMarkerMapFileName, aMarkerMapFile;
680 if( SaveMarkerMap( aStudy, anURL.c_str(), theIsMultiFile, true,
681 myMarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
682 aFileNames.push_back( aMarkerMapFileName );
683 aFiles.push_back( aMarkerMapFile );
686 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
687 if(aFileNames.empty())
688 return aStreamFile._retn();
690 SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
691 aStreamFile = SALOMEDS_Tool::PutFilesToStream(anURL, aListOfFileNames.in(), theIsMultiFile);
694 SALOMEDS_Tool::RemoveTemporaryFiles(anURL, aListOfFileNames, true);
696 return aStreamFile._retn();
700 //----------------------------------------------------------------------------
703 ::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
704 const char* theIORString,
705 CORBA::Boolean theIsMultiFile,
706 CORBA::Boolean theIsASCII)
708 CORBA::String_var aString("");
709 if(strcmp(theIORString, "") != 0){
710 CORBA::Object_var anObj = GetORB()->string_to_object(theIORString);
711 if(Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
712 aString = aStorable->ToString().c_str();
713 return aString._retn();
716 return aString._retn();
720 //----------------------------------------------------------------------------
725 return Base_i::GetID();
729 //----------------------------------------------------------------------------
732 ::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
734 class TEvent: public SALOME_Event {
735 std::string myStudyName;
737 TEvent(const std::string theStudyName):myStudyName(theStudyName)
739 virtual void Execute()
741 bool isActive = false;
742 SUIT_Session* aSession = SUIT_Session::session();
743 QList<SUIT_Application*> anApplications = aSession->applications();
744 QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
745 SUIT_Application* aFirstApp = *anIter;
746 while (anIter != anApplications.end()) {
747 SUIT_Application* anApp = *anIter;
748 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
749 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
750 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
751 if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = "
752 << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
753 if (myStudyName == aCStudy->Name()) {
763 MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
764 // Has to be loaded in an empty or in a new application
765 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
766 anApp->onLoadDoc(myStudyName.c_str());
771 if (!CORBA::is_nil(theStudy))
773 CORBA::String_var aName = theStudy->Name();
774 std::string aStudyName (aName.in());
775 if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
776 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
777 myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument));
779 ProcessVoidEvent(new TEvent(aStudyName));
781 // Load MED component if necessary
782 if(!myStudyDocument->FindComponent("MED")->_is_nil())
784 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
785 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
786 SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow(aComponent);
788 if(!CORBA::is_nil(aMedEngine))
790 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
792 aStudyBuilder->LoadWith( myStudyDocument->FindComponent( "MED" ), aMedEngine );
794 catch( const SALOME::SALOME_Exception& ) {
795 // Oops, something went wrong while loading
796 // See also SalomeApp_Study::openDataModel()
801 INFOS("CORBA::is_nil(theStudy)");
806 //----------------------------------------------------------------------------
811 return SALOMEDS::Study::_duplicate(myStudyDocument);
815 //----------------------------------------------------------------------------
821 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
822 return ViewManager::_duplicate(aViewManager->_this());
826 //----------------------------------------------------------------------------
827 SALOMEDS::SObject_ptr
829 ::ImportTables(const char* theFileName, bool theFirstStrAsTitle)
831 if(myStudyDocument->GetProperties()->IsLocked())
832 return SALOMEDS::SObject::_nil();
834 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument,
837 SALOMEDS::Study_var aStudy = aRes->GetStudy();
838 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aRes);
839 for (; anIter->More(); anIter->Next()) {
840 SALOMEDS::SObject_var SO = anIter->Value();
841 CreateTable( SO->GetID() );
848 //----------------------------------------------------------------------------
851 ::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
852 const char* theFileName)
854 return VISU::ExportTableToFile(theTable, theFileName);
858 //----------------------------------------------------------------------------
861 ::ImportFile(const char* theFileName)
863 if(myStudyDocument->GetProperties()->IsLocked())
864 return Result::_nil();
866 Result_i* aResult = Result_i::New(myStudyDocument,
868 Result_i::eImportFile,
874 if(aResult->Create(theFileName) != NULL)
875 return aResult->_this();
877 aResult->_remove_ref();
879 return VISU::Result::_nil();
883 //----------------------------------------------------------------------------
886 ::CreateResult(const char* theFileName)
888 if(myStudyDocument->GetProperties()->IsLocked())
889 return Result::_nil();
891 Result_i* aResult = Result_i::New(myStudyDocument,
893 Result_i::eImportFile,
899 if(aResult->Create(theFileName) != NULL)
900 return aResult->_this();
902 aResult->_remove_ref();
904 return VISU::Result::_nil();
908 //----------------------------------------------------------------------------
911 ::CopyAndImportFile(const char* theFileName)
913 if(myStudyDocument->GetProperties()->IsLocked())
914 return Result::_nil();
916 Result_i* aResult = Result_i::New(myStudyDocument,
917 Result_i::eRestoredFile,
918 Result_i::eCopyAndImportFile,
923 if(aResult->Create(theFileName) != NULL)
924 return aResult->_this();
926 aResult->_remove_ref();
928 return VISU::Result::_nil();
932 //----------------------------------------------------------------------------
933 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject)
935 if (myStudyDocument->GetProperties()->IsLocked())
936 return Result::_nil();
938 Result_i* aResult = Result_i::New(myStudyDocument,
939 Result_i::eComponent,
940 Result_i::eImportMed,
945 if (aResult->Create(theMedSObject) != NULL)
947 return aResult->_this();
950 aResult->_remove_ref();
952 return VISU::Result::_nil();
956 //----------------------------------------------------------------------------
959 ::ImportMedField (SALOME_MED::FIELD_ptr theField)
961 if (myStudyDocument->GetProperties()->IsLocked())
962 return Result::_nil();
964 Result_i* aResult = Result_i::New(myStudyDocument,
965 Result_i::eComponent,
966 Result_i::eImportMedField,
972 if (aResult->Create(theField) != NULL)
973 return aResult->_this();
975 aResult->_remove_ref();
977 return VISU::Result::_nil();
982 ::RenameMeshInStudy(Result_ptr theResult,
983 const std::string& theMeshName,
984 int theEntity, // -1 for group indication
985 const std::string& theSubMeshName, // Family or Group name
986 const std::string& theNewName)
988 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
992 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
993 if (aStudyDocument->GetProperties()->IsLocked())
998 VISU::VISUType aType;
1000 if (theSubMeshName == "")
1001 aType = VISU::TENTITY;
1003 aType = VISU::TFAMILY;
1005 aType = VISU::TGROUP;
1007 VISU::Storable::TRestoringMap aRestoringMap;
1008 aRestoringMap["myMeshName"] = theMeshName.c_str();
1012 aRestoringMap["myComment"] = "ENTITY";
1013 aRestoringMap["myId"] = QString::number(theEntity);
1016 aRestoringMap["myComment"] = "FAMILY";
1017 aRestoringMap["myEntityId"] = QString::number(theEntity);
1018 aRestoringMap["myName"] = theSubMeshName.c_str();
1021 aRestoringMap["myComment"] = "GROUP";
1022 aRestoringMap["myName"] = theSubMeshName.c_str();
1026 string anEntry = aResult->GetEntry(aRestoringMap);
1030 SALOMEDS::SObject_ptr aSObject = aStudyDocument->FindObjectID(anEntry.c_str());
1032 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
1033 aStudyBuilder->NewCommand(); // There is a transaction
1035 SALOMEDS::GenericAttribute_var anAttr =
1036 aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
1037 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
1038 aNameAttr->SetValue(theNewName.c_str());
1040 aStudyBuilder->CommitCommand();
1044 //----------------------------------------------------------------------------
1047 ::RenameEntityInStudy(Result_ptr theResult,
1048 const char* theMeshName,
1049 VISU::Entity theEntity,
1050 const char* theNewName)
1052 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, "", theNewName);
1056 //----------------------------------------------------------------------------
1059 ::RenameFamilyInStudy(Result_ptr theResult,
1060 const char* theMeshName,
1061 VISU::Entity theEntity,
1062 const char* theFamilyName,
1063 const char* theNewName)
1065 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, theFamilyName, theNewName);
1069 //----------------------------------------------------------------------------
1072 ::RenameGroupInStudy(Result_ptr theResult,
1073 const char* theMeshName,
1074 const char* theGroupName,
1075 const char* theNewName)
1077 RenameMeshInStudy(theResult, theMeshName, -1, theGroupName, theNewName);
1081 //----------------------------------------------------------------------------
1084 ::MeshOnEntity(Result_ptr theResult,
1085 const char* theMeshName,
1086 VISU::Entity theEntity)
1088 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1090 return VISU::Mesh::_nil();
1092 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1093 if (aStudyDocument->GetProperties()->IsLocked())
1094 return VISU::Mesh::_nil();
1096 Mesh_i* aPresent = new Mesh_i();
1097 if(aPresent->Create(aResult, theMeshName, theEntity))
1098 return aPresent->_this();
1100 aPresent->_remove_ref();
1102 return VISU::Mesh::_nil();
1106 //----------------------------------------------------------------------------
1109 ::FamilyMeshOnEntity(Result_ptr theResult,
1110 const char* theMeshName,
1111 VISU::Entity theEntity,
1112 const char* theFamilyName)
1114 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1116 return VISU::Mesh::_nil();
1118 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1119 if (aStudyDocument->GetProperties()->IsLocked())
1120 return VISU::Mesh::_nil();
1122 Mesh_i* aPresent = new Mesh_i();
1123 if(aPresent->Create(aResult, theMeshName, theEntity, theFamilyName))
1124 return aPresent->_this();
1126 aPresent->_remove_ref();
1128 return VISU::Mesh::_nil();
1132 //----------------------------------------------------------------------------
1135 ::GroupMesh(Result_ptr theResult,
1136 const char* theMeshName,
1137 const char* theGroupName)
1139 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1141 return VISU::Mesh::_nil();
1143 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1144 if (aStudyDocument->GetProperties()->IsLocked())
1145 return VISU::Mesh::_nil();
1147 Mesh_i* aPresent = new Mesh_i();
1148 if(aPresent->Create(aResult, theMeshName, theGroupName))
1149 return aPresent->_this();
1151 aPresent->_remove_ref();
1153 return VISU::Mesh::_nil();
1157 //----------------------------------------------------------------------------
1160 ::ScalarMapOnField(Result_ptr theResult,
1161 const char* theMeshName,
1162 VISU::Entity theEntity,
1163 const char* theFieldName,
1164 CORBA::Long theIteration)
1166 return Prs3dOnField<VISU::ScalarMap_i>(theResult,
1170 theIteration)._retn();
1174 //----------------------------------------------------------------------------
1177 ::GaussPointsOnField(Result_ptr theResult,
1178 const char* theMeshName,
1179 VISU::Entity theEntity,
1180 const char* theFieldName,
1181 CORBA::Long theIteration)
1183 return Prs3dOnField<VISU::GaussPoints_i>(theResult,
1187 theIteration)._retn();
1191 //---------------------------------------------------------------
1194 ::DeformedShapeOnField(Result_ptr theResult,
1195 const char* theMeshName,
1196 VISU::Entity theEntity,
1197 const char* theFieldName,
1198 CORBA::Long theIteration)
1200 return Prs3dOnField<VISU::DeformedShape_i>(theResult,
1204 theIteration)._retn();
1208 //---------------------------------------------------------------
1209 DeformedShapeAndScalarMap_ptr
1211 ::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
1212 const char* theMeshName,
1213 VISU::Entity theEntity,
1214 const char* theFieldName,
1215 CORBA::Long theIteration)
1217 return DeformedShapeAndScalarMapOnField(theResult,
1225 //---------------------------------------------------------------
1226 DeformedShapeAndScalarMap_ptr
1228 ::DeformedShapeAndScalarMapOnField(Result_ptr theResult,
1229 const char* theMeshName,
1230 VISU::Entity theEntity,
1231 const char* theFieldName,
1232 CORBA::Long theIteration)
1234 return Prs3dOnField<VISU::DeformedShapeAndScalarMap_i>(theResult,
1238 theIteration)._retn();
1242 //---------------------------------------------------------------
1245 ::VectorsOnField(Result_ptr theResult,
1246 const char* theMeshName,
1247 VISU::Entity theEntity,
1248 const char* theFieldName,
1249 CORBA::Long theIteration)
1251 return Prs3dOnField<VISU::Vectors_i>(theResult,
1255 theIteration)._retn();
1259 //---------------------------------------------------------------
1262 ::IsoSurfacesOnField(Result_ptr theResult,
1263 const char* theMeshName,
1264 VISU::Entity theEntity,
1265 const char* theFieldName,
1266 CORBA::Long theIteration)
1268 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,
1272 theIteration)._retn();
1276 //---------------------------------------------------------------
1279 ::StreamLinesOnField(Result_ptr theResult,
1280 const char* theMeshName,
1281 VISU::Entity theEntity,
1282 const char* theFieldName,
1283 CORBA::Long theIteration)
1285 return Prs3dOnField<VISU::StreamLines_i>(theResult,
1289 theIteration)._retn();
1293 //---------------------------------------------------------------
1296 ::Plot3DOnField(Result_ptr theResult,
1297 const char* theMeshName,
1298 VISU::Entity theEntity,
1299 const char* theFieldName,
1300 CORBA::Long theIteration)
1302 return Prs3dOnField<VISU::Plot3D_i>(theResult,
1306 theIteration)._retn();
1310 //---------------------------------------------------------------
1313 ::CutPlanesOnField(Result_ptr theResult,
1314 const char* theMeshName,
1315 VISU::Entity theEntity,
1316 const char* theFieldName,
1317 CORBA::Long theIteration)
1319 return Prs3dOnField<VISU::CutPlanes_i>(theResult,
1323 theIteration)._retn();
1327 //---------------------------------------------------------------
1330 ::CutLinesOnField(Result_ptr theResult,
1331 const char* theMeshName,
1332 VISU::Entity theEntity,
1333 const char* theFieldName,
1334 CORBA::Long theIteration)
1336 return Prs3dOnField<VISU::CutLines_i>(theResult,
1340 theIteration)._retn();
1343 //---------------------------------------------------------------
1346 ::CutSegmentOnField(Result_ptr theResult,
1347 const char* theMeshName,
1348 VISU::Entity theEntity,
1349 const char* theFieldName,
1350 CORBA::Long theIteration)
1352 return Prs3dOnField<VISU::CutSegment_i>(theResult,
1356 theIteration)._retn();
1359 //---------------------------------------------------------------
1360 struct CreateTableEvent: public SALOME_Event
1362 SALOMEDS::Study_var myStudyDocument;
1363 const char* myTableEntry;
1364 typedef Table_ptr TResult;
1367 CreateTableEvent(SALOMEDS::Study_var theStudy, const char* theTableEntry)
1369 myStudyDocument = theStudy;
1370 myTableEntry = theTableEntry;
1371 myResult = Table::_nil();
1378 SALOMEDS::SObject_var SO = myStudyDocument->FindObjectID(myTableEntry);
1379 SALOMEDS::GenericAttribute_var anAttr;
1380 if ( SO->FindAttribute(anAttr, "AttributeTableOfReal") ) {
1381 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1382 if ( isSparseMatrix( aTableOfReal ) ) {
1383 PointMap3d_i* pPresent = new PointMap3d_i(myStudyDocument,myTableEntry);
1384 if(pPresent->Create() != NULL)
1385 myResult = pPresent->_this();
1387 pPresent->_remove_ref();
1388 myResult = VISU::Table::_nil();
1393 Table_i* pPresent = new Table_i(myStudyDocument,myTableEntry);
1394 if(pPresent->Create() != NULL)
1395 myResult = pPresent->_this();
1397 pPresent->_remove_ref();
1398 myResult = VISU::Table::_nil();
1404 isSparseMatrix(SALOMEDS::AttributeTableOfReal_var theTableOfReal)
1406 int aCols = theTableOfReal->GetNbColumns();
1407 int aRows = theTableOfReal->GetNbRows();
1409 for (int i=1; i<=aCols; i++) {
1410 for (int j=1; j<=aRows; j++) {
1411 if ( !(theTableOfReal->HasValue(j, i)) )
1419 //---------------------------------------------------------------
1422 ::CreateTable(const char* theTableEntry)
1424 TCollection_AsciiString tmp( (char*)theTableEntry ); // 11.06.2008 IPAL18844
1425 if( myStudyDocument->GetProperties()->IsLocked() ||
1427 return Table::_nil();
1429 return ProcessEvent(new CreateTableEvent(myStudyDocument, theTableEntry));
1432 //---------------------------------------------------------------
1435 ::CreateCurve(Table_ptr theTable,
1436 CORBA::Long theHRow,
1437 CORBA::Long theVRow)
1439 return CreateCurveWithZExt( theTable, theHRow, theVRow, 0, false );
1443 //---------------------------------------------------------------
1446 ::CreateCurveWithZ(Table_ptr theTable,
1447 CORBA::Long theHRow,
1448 CORBA::Long theVRow,
1449 CORBA::Long theZRow)
1451 return CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, false );
1455 //---------------------------------------------------------------
1458 ::CreateCurveWithZExt(Table_ptr theTable,
1459 CORBA::Long theHRow,
1460 CORBA::Long theVRow,
1461 CORBA::Long theZRow,
1462 CORBA::Boolean theIsV2)
1464 if(myStudyDocument->GetProperties()->IsLocked())
1465 return Curve::_nil();
1467 PortableServer::POA_ptr aPOA = GetPOA();
1468 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
1469 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow,theZRow,theIsV2);
1470 if(pPresent->Create() != NULL)
1471 return pPresent->_this();
1473 pPresent->_remove_ref();
1474 return VISU::Curve::_nil();
1479 //---------------------------------------------------------------
1484 if(myStudyDocument->GetProperties()->IsLocked())
1485 return Container::_nil();
1487 Container_i* pPresent = new Container_i(myStudyDocument);
1488 if(pPresent->Create() != NULL)
1489 return pPresent->_this();
1491 pPresent->_remove_ref();
1492 return VISU::Container::_nil();
1497 //---------------------------------------------------------------
1500 ::CreateAnimation(View3D_ptr theView3D)
1502 if(myStudyDocument->GetProperties()->IsLocked())
1503 return Animation::_nil();
1505 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
1506 return anAnim->_this();
1508 return VISU::Animation::_nil();
1512 //---------------------------------------------------------------
1515 ::CreateEvolution(XYPlot_ptr theXYPlot)
1517 if(myStudyDocument->GetProperties()->IsLocked())
1518 return Evolution::_nil();
1520 if(VISU_Evolution_i* anEvolution = new VISU_Evolution_i(myStudyDocument,theXYPlot)){
1521 return anEvolution->_this();
1523 return VISU::Evolution::_nil();
1527 //---------------------------------------------------------------
1530 ::DeleteResult (Result_ptr theResult)
1532 theResult->RemoveFromStudy();
1536 //---------------------------------------------------------------
1539 ::DeletePrs3d(Prs3d_ptr thePrs3d)
1541 thePrs3d->RemoveFromStudy();
1545 //---------------------------------------------------------------
1548 ::Close(SALOMEDS::SComponent_ptr theComponent)
1550 if ( !CORBA::is_nil( myStudyDocument ) && !CORBA::is_nil( theComponent ) &&
1551 myStudyDocument->StudyId() == theComponent->GetStudy()->StudyId())
1552 myStudyDocument = SALOMEDS::Study::_nil();
1556 //---------------------------------------------------------------
1559 ::ComponentDataType()
1561 return CORBA::string_dup("VISU");
1565 //---------------------------------------------------------------
1568 ::CanPublishInStudy(CORBA::Object_ptr theIOR)
1570 Result_var aResultObj = Result::_narrow(theIOR);
1571 return !(aResultObj->_is_nil());
1575 //---------------------------------------------------------------
1576 SALOMEDS::SObject_ptr
1578 ::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1579 SALOMEDS::SObject_ptr theSObject,
1580 CORBA::Object_ptr theObject,
1581 const char* theName)
1582 throw (SALOME::SALOME_Exception)
1584 Unexpect aCatch(SalomeException);
1585 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
1587 SALOMEDS::SObject_var aResultSO;
1588 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
1590 return aResultSO._retn();
1591 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1592 CORBA::String_var anEntry = aResultObj->Create((const char*)aFileInfo.absoluteFilePath().toLatin1())->GetID();
1593 aResultSO = theStudy->FindObjectID(anEntry);
1594 return aResultSO._retn();
1598 //---------------------------------------------------------------
1601 ::CanCopy(SALOMEDS::SObject_ptr theObject)
1603 CORBA::Object_var anObj = SObjectToObject(theObject);
1604 if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in()))
1605 return aStorable->CanCopy(theObject);
1611 //---------------------------------------------------------------
1614 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
1615 CORBA::Long& theObjectID)
1618 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
1620 CORBA::Object_var anObj = SObjectToObject(theObject);
1621 if (CORBA::is_nil(anObj)) {
1622 aStreamFile->length(1);
1623 aStreamFile[0] = CORBA::string_dup("E")[0];
1624 } else if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())) {
1625 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1626 Storable::TFileNames aFileNames;
1627 bool anIsDone = aStorable->CopyFrom(theObject, theObjectID, aTmpDir, aFileNames);
1629 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
1630 aListOfFileNames->length(aFileNames.size());
1631 for(size_t anId = 0; anId < aFileNames.size(); anId++)
1632 aListOfFileNames[anId] = aFileNames[anId].c_str();
1635 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFileNames.in(), false);
1637 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aListOfFileNames.in(), true);
1639 return aStreamFile._retn();
1643 //---------------------------------------------------------------
1646 ::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1647 // The VISU component can paste only objects copied by VISU component
1648 CORBA::String_var aString = ComponentDataType();
1649 if (strcmp(theComponentName, aString.in()) == 0 && theObjectID == 1)
1655 //---------------------------------------------------------------
1656 SALOMEDS::SObject_ptr
1658 ::PasteInto(const SALOMEDS::TMPFile& theStream,
1659 CORBA::Long theObjectID,
1660 SALOMEDS::SObject_ptr theSObject)
1662 if (theObjectID != 1)
1663 return SALOMEDS::SObject::_nil();
1665 SALOMEDS::SComponent_var aComponent = theSObject->GetFatherComponent();
1666 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1667 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1668 CORBA::String_var aComponentID(aComponent->GetID());
1669 CORBA::String_var aSObjectID(theSObject->GetID());
1671 SALOMEDS::SObject_var aSObject;
1672 if (strcmp(aComponentID, aSObjectID) == 0) //create the new result SObject
1673 aSObject = aStudyBuilder->NewObject(aComponent);
1675 aSObject = SALOMEDS::SObject::_duplicate(theSObject);
1677 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1678 SALOMEDS::ListOfFileNames_var aListOfFileNames =
1679 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1680 if(MYDEBUG) MESSAGE("Result_i::PasteInto - aListOfFileNames->length() = "<<aListOfFileNames->length());
1682 std::ostringstream aLocalPersistentID;
1684 std::string aCopyPersist = aTmpDir + "copy_persistent";
1685 std::ifstream anInputFileStream( aCopyPersist.c_str() );
1686 anInputFileStream >> aLocalPersistentID.rdbuf();
1689 //Just for Result::Restore to find the Comment attribute :(
1690 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
1692 std::string aFileName(aTmpDir);
1693 if(aListOfFileNames->length() > 1)
1694 aFileName += aListOfFileNames[1].in();
1695 Storable* aStorable = Storable::Create(aSObject, aLocalPersistentID.str(), aFileName, false);
1697 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
1698 aFilesToRemove->length(1);
1699 aFilesToRemove[0] = aListOfFileNames[0];
1700 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aFilesToRemove.in(), true);
1702 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
1703 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1704 CORBA::String_var anIORValue(aStorable->GetID());
1705 anIOR->SetValue(anIORValue);
1707 return aSObject._retn();
1711 //---------------------------------------------------------------
1712 VISU::ColoredPrs3dCache_ptr
1714 ::GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy)
1716 return ColoredPrs3dCache_i::GetInstance(theStudy);
1720 CORBA::Long VISU_Gen_i::CreateClippingPlane(CORBA::Double X,CORBA::Double Y, CORBA::Double Z,
1721 CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1722 CORBA::Boolean isAuto, const char* name)
1724 return myClippingPlaneMgr.CreateClippingPlane(X, Y, Z, dX, dY, dZ, isAuto, name);
1728 void VISU_Gen_i::EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double Y, CORBA::Double Z,
1729 CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1730 CORBA::Boolean isAuto, const char* name)
1732 myClippingPlaneMgr.EditClippingPlane(id, X, Y, Z, dX, dY, dZ, isAuto, name);
1735 /* Returns clipping plane by its Id */
1736 VISU::ClippingPlane* VISU_Gen_i::GetClippingPlane(CORBA::Long id)
1738 VISU_CutPlaneFunction* aPlane = myClippingPlaneMgr.GetClippingPlane(id);
1740 if (aPlane != NULL) {
1743 aPlane->GetOrigin(aOrigin);
1744 aPlane->GetNormal(aDir);
1746 VISU::ClippingPlane* aRetPlane = new VISU::ClippingPlane;
1747 aRetPlane->X = aOrigin[0];
1748 aRetPlane->Y = aOrigin[1];
1749 aRetPlane->Z = aOrigin[2];
1750 aRetPlane->dX = aDir[0];
1751 aRetPlane->dY = aDir[1];
1752 aRetPlane->dZ = aDir[2];
1753 aRetPlane->isAuto = aPlane->isAuto();
1755 aRetPlane->name = aPlane->getName().c_str();
1761 /* Deletes clipping plane by its Id */
1762 CORBA::Boolean VISU_Gen_i::DeleteClippingPlane(CORBA::Long id)
1764 return myClippingPlaneMgr.DeleteClippingPlane(id);
1767 /* Applyes a clipping plane with Id to presentation thePrs */
1768 CORBA::Boolean VISU_Gen_i::ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1770 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1771 return myClippingPlaneMgr.ApplyClippingPlane(aPrs, id);
1774 /* Detaches a clipping plane with Id from presentation thePrs */
1775 CORBA::Boolean VISU_Gen_i::DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1777 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1778 return myClippingPlaneMgr.DetachClippingPlane(aPrs, id);
1781 /* Get number of clipping planes */
1782 CORBA::Long VISU_Gen_i::GetClippingPlanesNb()
1784 return myClippingPlaneMgr.GetClippingPlanesNb();
1788 \brief Converts set of VTK files to the one MED-file
1789 \param theVTKFiles sequence of VTK files
1790 \param theMEDFile MED-file
1791 \param theMeshName mesh name. This parameter can be empty. In this case name
1792 of mesh is equal vtk2med
1793 \param theTStamps values of time stamps. This array can be empty, in
1794 this case values of time stamps will be generated automatically ( 0, 1, 2 ... )
1795 \return TRUE if operation has been completed successfully, FALSE otherwise
1799 ::VTK2MED( const VISU::string_array& theVTKFiles,
1800 const char* theMEDFile,
1801 const char* theMeshName,
1802 const VISU::double_array& theTStamps )
1804 if ( !theMEDFile || !theVTKFiles.length() )
1807 VISU_Vtk2MedConvertor aConvertor;
1808 aConvertor.setMEDFileName( theMEDFile );
1809 // std::string aFirstFile = theVTKFiles[ 0 ];
1810 char* aFirstFile = CORBA::string_dup( theVTKFiles[ 0 ] );
1811 aConvertor.setFirstVTKFileName( aFirstFile );
1812 if ( theVTKFiles.length() > 1 )
1814 VISU_Vtk2MedConvertor::TVectorString aFiles( theVTKFiles.length() - 1 );
1815 for ( int i = 1, n = theVTKFiles.length(); i < n; i++ )
1816 aFiles[ i - 1 ] = theVTKFiles[ i ];
1817 aConvertor.setDataVTKFileNames( aFiles );
1819 if ( theTStamps.length() > 0 )
1821 VISU_Vtk2MedConvertor::TVectorDouble aTStamps( theTStamps.length() );
1822 for ( int i = 0, n = theTStamps.length(); i < n; i++ )
1823 aTStamps[ i ] = theTStamps[ i ];
1824 aConvertor.setTimeStamps( aTStamps );
1827 if ( theMeshName && strlen( theMeshName ) > 0 )
1828 aConvertor.setMeshName( theMeshName );
1830 aConvertor.addToIgnoringFieldList("cellID");
1831 aConvertor.setCellDataFieldNameIDS("cellID");
1833 int res = aConvertor.Execute();
1840 ::LoadTexture(const char* theTextureFile)
1842 if( CORBA::is_nil( myStudyDocument ) )
1845 int aStudyId = myStudyDocument->StudyId();
1847 VTK::MarkerTexture aMarkerTexture;
1848 if( !VTK::LoadTextureData( theTextureFile, VTK::MS_NONE, aMarkerTexture ) )
1851 VTK::MarkerMap& aMarkerMap = myMarkerMap[ aStudyId ];
1852 int aMarkerId = VTK::GetUniqueId( aMarkerMap );
1854 VTK::MarkerData& aMarkerData = aMarkerMap[ aMarkerId ];
1855 aMarkerData.first = theTextureFile;
1856 aMarkerData.second = aMarkerTexture;