1 // Copyright (C) 2007-2012 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_version.h"
29 #include "VISU_Gen_i.hh"
30 #include "VISU_Result_i.hh"
31 #include "VISU_PrsObject_i.hh"
32 #include "VISU_ViewManager_i.hh"
33 #include "VISU_ResultUtils.hh"
35 #include "VISU_Prs3d_i.hh"
36 #include "VISU_Mesh_i.hh"
37 #include "VISU_Table_i.hh"
38 #include "VISU_PointMap3d_i.hh"
39 #include "VISU_TimeAnimation.h"
40 #include "VISU_Evolution.h"
42 #include "VISU_ColoredPrs3dFactory.hh"
43 #include "VISU_ColoredPrs3dCache_i.hh"
44 #include "VISU_ColoredPrs3dHolder_i.hh"
46 #include <VISU_Vtk2MedConvertor.hxx>
48 #include "VISU_Actor.h"
51 #include "HDFascii.hxx"
52 #include "SALOMEDS_Tool.hxx"
54 #include "SALOMEDSClient_AttributeName.hxx"
55 #include "SALOMEDSClient_AttributePixMap.hxx"
57 #include "SUIT_Session.h"
58 #include "SalomeApp_Study.h"
59 #include "SalomeApp_Application.h"
60 #include "LightApp_SelectionMgr.h"
61 #include "VTKViewer_MarkerUtils.h"
62 #include "SVTK_ViewModel.h"
63 #include "SVTK_ViewWindow.h"
64 #include "SALOME_Event.h"
65 #include "SALOME_ListIO.hxx"
66 #include "SALOME_ListIteratorOfListIO.hxx"
68 #include "utilities.h"
71 #include <omnithread.h>
72 #include CORBA_SERVER_HEADER(SALOME_Session)
73 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
74 #include CORBA_SERVER_HEADER(MED_Gen)
81 #include <vtkRenderer.h>
82 #include <vtkActorCollection.h>
85 #include <TCollection_AsciiString.hxx>
86 #include <TColStd_SequenceOfAsciiString.hxx>
88 #include "Utils_ExceptHandlers.hxx"
89 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
94 #include <boost/filesystem/path.hpp>
95 #include <boost/filesystem/operations.hpp>
96 namespace filesystem = boost::filesystem;
100 static int MYDEBUG = 0;
102 static int MYDEBUG = 0;
108 VISU_I_EXPORT VISU::VISU_Gen_ptr
109 GetImpl(CORBA::ORB_ptr theORB,
110 PortableServer::POA_ptr thePOA,
111 SALOME_NamingService* theNamingService,
114 if(MYDEBUG) MESSAGE("extern 'C' GetImpl");
115 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
116 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
117 return aVISU_Gen->_this();
122 //----------------------------------------------------------------------------
123 static std::string VISU_TMP_DIR;
125 static CORBA::Boolean myIsMultiFile;
126 const CORBA::Boolean IsMultiFile()
128 return myIsMultiFile;
131 //----------------------------------------------------------------------------
133 ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
135 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
137 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
138 aStudyBuilder->NewCommand();
139 int aLocked = theStudyDocument->GetProperties()->IsLocked();
140 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
141 aSComponent = aStudyBuilder->NewComponent("VISU");
142 _PTR(GenericAttribute) anAttr =
143 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
144 _PTR(AttributeName) aName (anAttr);
146 CORBA::ORB_var anORB = Base_i::GetORB();
147 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
148 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
149 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
150 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
151 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
152 if (!Comp->_is_nil()) {
153 aName->SetValue(Comp->componentusername());
156 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
157 _PTR(AttributePixMap) aPixmap (anAttr);
158 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
160 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
161 aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
162 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
163 aStudyBuilder->CommitCommand();
169 //----------------------------------------------------------------------------
170 SALOMEDS::SComponent_var
171 FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument)
173 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
174 if (aSComponent->_is_nil()) {
175 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
176 aStudyBuilder->NewCommand();
177 int aLocked = theStudyDocument->GetProperties()->IsLocked();
178 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
179 aSComponent = aStudyBuilder->NewComponent("VISU");
180 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
181 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
183 //NRI aName->SetValue("Visu");
184 CORBA::ORB_var anORB = Base_i::GetORB();
185 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
186 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
187 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
188 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
189 if ( !Comp->_is_nil() ) {
190 aName->SetValue( Comp->componentusername() );
193 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
194 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
195 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
197 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
198 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
199 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
200 aStudyBuilder->CommitCommand();
206 //----------------------------------------------------------------------------
210 Storable::RegistryStorableEngine(Result_i::myComment.c_str(),&(Result_i::StorableEngine));
212 Storable::RegistryStorableEngine(Mesh_i::myComment.c_str(),&(Mesh_i::StorableEngine));
214 Storable::RegistryStorableEngine(ScalarMap_i::myComment.c_str(),&(StorableEngine<ScalarMap_i>));
215 Storable::RegistryStorableEngine(GaussPoints_i::myComment.c_str(),&(StorableEngine<GaussPoints_i>));
216 Storable::RegistryStorableEngine(DeformedShape_i::myComment.c_str(),&(StorableEngine<DeformedShape_i>));
217 Storable::RegistryStorableEngine(CutPlanes_i::myComment.c_str(),&(StorableEngine<CutPlanes_i>));
218 Storable::RegistryStorableEngine(CutLines_i::myComment.c_str(),&(StorableEngine<CutLines_i>));
219 Storable::RegistryStorableEngine(CutSegment_i::myComment.c_str(),&(StorableEngine<CutSegment_i>));
220 Storable::RegistryStorableEngine(IsoSurfaces_i::myComment.c_str(),&(StorableEngine<IsoSurfaces_i>));
221 Storable::RegistryStorableEngine(StreamLines_i::myComment.c_str(),&(StorableEngine<StreamLines_i>));
222 Storable::RegistryStorableEngine(Plot3D_i::myComment.c_str(),&(StorableEngine<Plot3D_i>));
223 Storable::RegistryStorableEngine(Vectors_i::myComment.c_str(),&(StorableEngine<Vectors_i>));
224 Storable::RegistryStorableEngine(DeformedShapeAndScalarMap_i::myComment.c_str(),&(StorableEngine<DeformedShapeAndScalarMap_i>));
226 Storable::RegistryStorableEngine(ColoredPrs3dHolder_i::myComment.c_str(),&(ColoredPrs3dHolder_i::StorableEngine));
227 Storable::RegistryStorableEngine(ColoredPrs3dCache_i::myComment.c_str(),&(ColoredPrs3dCache_i::StorableEngine));
229 Storable::RegistryStorableEngine(PointMap3d_i::myComment.c_str(),&(PointMap3d_i::StorableEngine));
230 Storable::RegistryStorableEngine(Table_i::myComment.c_str(),&(Table_i::StorableEngine));
231 Storable::RegistryStorableEngine(Curve_i::myComment.c_str(),&(Curve_i::StorableEngine));
232 Storable::RegistryStorableEngine(Container_i::myComment.c_str(),&(Container_i::StorableEngine));
236 //----------------------------------------------------------------------------
237 SALOMEDS::ListOfFileNames*
238 GetListOfFileNames(const Result_i::TFileNames& theFileNames)
240 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
241 if(!theFileNames.empty()){
242 aListOfFileNames->length(theFileNames.size());
243 for(int aCounter = theFileNames.size(); aCounter > 0; aCounter--)
244 aListOfFileNames[aCounter-1] = theFileNames[aCounter-1].c_str();
246 return aListOfFileNames._retn();
250 //----------------------------------------------------------------------------
252 LoadMarkerMap(SALOMEDS::Study_ptr theStudy,
256 StudyId2MarkerMap& theStudyId2MarkerMap,
257 std::string& theMarkerMapFileName,
258 std::string& theMarkerMapFile)
261 if( theIsMultiFile ) {
262 CORBA::String_var anURL = theStudy->URL();
263 aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
266 theMarkerMapFileName = aPrefix + "_textures";
267 theMarkerMapFile = VISU_TMP_DIR + theMarkerMapFileName;
269 if( theIsASCII && !HDFascii::ConvertFromASCIIToHDF( const_cast<char*>( theMarkerMapFile.c_str() ), true ) )
273 HDFdataset* aDataset;
277 HDFgroup* aSubSubGroup;
280 aFile = new HDFfile( (char*)theMarkerMapFile.c_str() );
282 aFile->OpenOnDisk( HDF_RDONLY );
284 catch ( HDFexception ) {
285 INFOS( "Load(): " << theMarkerMapFile << " not found!" );
289 VTK::MarkerMap& aMarkerMap = theStudyId2MarkerMap[ theStudy->StudyId() ];
291 for( int i = 0, n = aFile->nInternalObjects(); i < n; i++ ) {
292 char markerGrpName[ HDF_NAME_MAX_LEN+1 ];
293 aFile->InternalObjectIndentify( i, markerGrpName );
296 std::string aMarkerFile;
297 VTK::MarkerTexture aMarkerTexture;
299 if( string( markerGrpName ).substr( 0, 6 ) == string( "Marker" ) ) {
300 aTopGroup = new HDFgroup( markerGrpName, aFile );
301 aTopGroup->OpenOnDisk();
303 aMarkerId = atoi( string( markerGrpName ).substr( 6 ).c_str() );
307 if( aTopGroup->ExistInternalObject( "File" ) ) {
308 aDataset = new HDFdataset( "File", aTopGroup );
309 aDataset->OpenOnDisk();
310 aSize = aDataset->GetSize();
311 char* aFileName = new char[ aSize ];
312 aDataset->ReadFromDisk( aFileName );
313 aMarkerFile = aFileName;
315 aDataset->CloseOnDisk();
318 if( aTopGroup->ExistInternalObject( "Texture" ) ) {
319 aDataset = new HDFdataset( "Texture", aTopGroup );
320 aDataset->OpenOnDisk();
321 aSize = aDataset->GetSize();
322 int* aTextureData = new int[ aSize ];
323 aDataset->ReadFromDisk( aTextureData );
324 for( int j = 0; j < aSize; j++ )
325 aMarkerTexture.push_back( aTextureData[j] );
326 delete [] aTextureData;
327 aDataset->CloseOnDisk();
330 aTopGroup->CloseOnDisk();
334 aMarkerMap[ aMarkerId ] = VTK::MarkerData( aMarkerFile, aMarkerTexture );
337 aFile->CloseOnDisk();
343 //----------------------------------------------------------------------------
345 SaveMarkerMap(SALOMEDS::Study_ptr theStudy,
349 const StudyId2MarkerMap& theStudyId2MarkerMap,
350 std::string& theMarkerMapFileName,
351 std::string& theMarkerMapFile)
353 VISU::StudyId2MarkerMap::const_iterator aMainIter = theStudyId2MarkerMap.find( theStudy->StudyId() );
354 if( aMainIter == theStudyId2MarkerMap.end() )
357 const VTK::MarkerMap& aMarkerMap = aMainIter->second;
358 if( aMarkerMap.empty() )
362 if( theIsMultiFile ) {
363 CORBA::String_var anURL = theStudy->URL();
364 aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
367 theMarkerMapFileName = aPrefix + "_textures";
368 theMarkerMapFile = string( theURL ) + theMarkerMapFileName;
371 HDFdataset* aDataset;
375 HDFgroup* aSubSubGroup;
378 aFile = new HDFfile( (char*)theMarkerMapFile.c_str() );
379 aFile->CreateOnDisk();
381 VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
382 for( ; aMarkerIter != aMarkerMap.end(); aMarkerIter++ ) {
383 int aMarkerId = aMarkerIter->first;
384 const VTK::MarkerData& aMarkerData = aMarkerIter->second;
385 std::string aMarkerFile = aMarkerData.first;
386 VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
388 char markerGrpName[30];
389 sprintf( markerGrpName, "Marker %d", aMarkerId );
390 aTopGroup = new HDFgroup( markerGrpName, aFile );
392 aTopGroup->CreateOnDisk();
394 aSize[ 0 ] = aMarkerFile.length() + 1;
395 aDataset = new HDFdataset( "File", aTopGroup, HDF_STRING, aSize, 1 );
396 aDataset->CreateOnDisk();
397 aDataset->WriteOnDisk( ( char* )( aMarkerFile.c_str() ) );
398 aDataset->CloseOnDisk();
400 int* aTextureData = new int[ aMarkerTexture.size() ];
401 VTK::MarkerTexture::const_iterator anIter = aMarkerTexture.begin();
402 for( int i = 0; anIter != aMarkerTexture.end(); anIter++, i++ )
403 aTextureData[i] = *anIter;
405 aSize[0] = aMarkerTexture.size();
406 aDataset = new HDFdataset( "Texture", aTopGroup, HDF_INT32, aSize, 1 );
407 aDataset->CreateOnDisk();
408 aDataset->WriteOnDisk( aTextureData );
409 aDataset->CloseOnDisk();
410 delete [] aTextureData;
412 aTopGroup->CloseOnDisk();
415 aFile->CloseOnDisk();
418 if( theIsASCII && !HDFascii::ConvertFromHDFToASCII( const_cast<char*>( theMarkerMapFile.c_str() ), true ) )
425 //----------------------------------------------------------------------------
427 ::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
428 SALOME_NamingService* theNamingService, QMutex* theMutex) :
429 Engines_Component_i()
431 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
432 Base_i::myMutex = theMutex; //apo
433 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
434 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
435 Base_i::myNamingService = theNamingService;
436 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
437 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
438 Base_i::myVisuGenImpl = this;
441 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
442 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
443 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
444 if(aListOfOpenStudies->length() > 0) {
445 CORBA::String_var aStudyName = aListOfOpenStudies[0];
446 //aFileInfo.setFile(aStudyName.in());
447 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
448 myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument));
450 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
454 //----------------------------------------------------------------------------
457 ::CreatePrs3d(VISUType theType,
458 SALOMEDS::Study_ptr theStudy)
460 if(ColoredPrs3d_i* aPrs3d = CreatePrs3d_i(theType, theStudy, ColoredPrs3d_i::EPublishIndependently))
461 return aPrs3d->_this();
462 return Prs3d::_nil();
466 //----------------------------------------------------------------------------
470 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
474 //----------------------------------------------------------------------------
476 CorrectSObjectType(SALOMEDS::SObject_ptr theSObject,
477 SALOMEDS::StudyBuilder_ptr theBuilder)
479 SALOMEDS::GenericAttribute_var anAttr;
480 bool isAttrStringFound = false;
482 if( theSObject->FindAttribute(anAttr, "AttributeComment") ) {
483 //SRN: Replace an AttributeComment with AttributeString
484 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
485 string aValue = aComment->Value();
486 theBuilder->RemoveAttribute(theSObject, "AttributeComment");
487 anAttr = theBuilder->FindOrCreateAttribute(theSObject, "AttributeString");
488 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
489 aStringAttr->SetValue(aValue.c_str());
490 isAttrStringFound = true;
493 if ( isAttrStringFound || theSObject->FindAttribute(anAttr, "AttributeString") ) {
494 SALOMEDS::AttributeString_var aAttComment = SALOMEDS::AttributeString::_narrow(anAttr);
496 CORBA::String_var aValue = aAttComment->Value();
497 std::string aString = Storable::CorrectPersistentString(aValue.in());
498 aAttComment->SetValue( aString.c_str() );
504 //----------------------------------------------------------------------------
506 LoadWithMarkerMap(SALOMEDS::SComponent_ptr theComponent,
507 const SALOMEDS::TMPFile & theStream,
509 CORBA::Boolean theIsMultiFile,
510 CORBA::Boolean theIsASCII,
511 StudyId2MarkerMap& theStudyId2MarkerMap)
513 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
515 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
516 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
518 for (anIter->InitEx(true); anIter->More(); anIter->Next()) {
519 SALOMEDS::SObject_var aSObject = anIter->Value();
520 CorrectSObjectType(aSObject, aStudyBuilder);
523 VISU_TMP_DIR = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
524 SALOMEDS::ListOfFileNames_var aSeq =
525 SALOMEDS_Tool::PutStreamToFiles(theStream, VISU_TMP_DIR, theIsMultiFile);
526 myIsMultiFile = theIsMultiFile;
528 // load textures of custom point markers
529 Result_i::TFileNames aTMPFileNames;
530 std::string aMarkerMapFileName, aMarkerMapFile;
531 if( LoadMarkerMap( aStudy, theURL, theIsMultiFile, theIsASCII,
532 theStudyId2MarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
533 aTMPFileNames.push_back( aMarkerMapFileName );
536 if(!theIsMultiFile && !aTMPFileNames.empty()) {
537 SALOMEDS::ListOfFileNames_var aListOfTMPFileNames = GetListOfFileNames(aTMPFileNames);
538 SALOMEDS_Tool::RemoveTemporaryFiles(VISU_TMP_DIR, aListOfTMPFileNames, true );
545 //----------------------------------------------------------------------------
548 ::Load(SALOMEDS::SComponent_ptr theComponent,
549 const SALOMEDS::TMPFile & theStream,
551 CORBA::Boolean theIsMultiFile)
554 return LoadWithMarkerMap(theComponent, theStream, theURL, theIsMultiFile, false, myMarkerMap);
558 //----------------------------------------------------------------------------
561 ::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
562 const SALOMEDS::TMPFile & theStream,
567 return LoadWithMarkerMap(theComponent, theStream, theURL, theIsMultiFile, true, myMarkerMap);
571 //----------------------------------------------------------------------------
574 ::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
575 const char* theLocalPersistentID,
576 CORBA::Boolean theIsMultiFile,
577 CORBA::Boolean theIsASCII)
579 CORBA::String_var aString("");
580 if(strcmp(theLocalPersistentID,"") != 0) {
581 Storable* aStorable = Storable::Create(theSObject,
582 theLocalPersistentID,
585 if(aStorable != NULL)
586 aString = aStorable->GetID();
588 return aString._retn();
592 //----------------------------------------------------------------------------
595 ::Save(SALOMEDS::SComponent_ptr theComponent,
599 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - theURL = '"<<theURL<<"'");
601 Result_i::TFileNames aFileNames;
602 Result_i::TFileNames aFiles;
604 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
605 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
606 for (; anIter->More(); anIter->Next()) {
607 SALOMEDS::SObject_var aSObject = anIter->Value();
608 CORBA::Object_var anObj = SObjectToObject(aSObject);
609 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
610 aResult->Save(theComponent,
618 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<<aFileNames.size());
620 // save textures of custom point markers
621 Result_i::TFileNames aTMPFileNames;
622 std::string aMarkerMapFileName, aMarkerMapFile;
623 if( SaveMarkerMap( aStudy, theURL, theIsMultiFile, false,
624 myMarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
625 aTMPFileNames.push_back( aMarkerMapFileName );
626 aFileNames.push_back( aMarkerMapFileName );
627 aFiles.push_back( aMarkerMapFile );
630 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
631 if(aFileNames.empty())
632 return aStreamFile._retn();
634 SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
635 SALOMEDS::ListOfFileNames_var aListOfFiles = GetListOfFileNames(aFiles);
638 aStreamFile = SALOMEDS_Tool::PutFilesToStream(theURL, aListOfFiles.in(), theIsMultiFile);
640 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in());
642 if(!theIsMultiFile && !aTMPFileNames.empty()) {
643 SALOMEDS::ListOfFileNames_var aListOfTMPFileNames = GetListOfFileNames(aTMPFileNames);
644 SALOMEDS_Tool::RemoveTemporaryFiles(theURL, aListOfTMPFileNames, true);
647 return aStreamFile._retn();
651 //----------------------------------------------------------------------------
654 ::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
658 std::string anURL = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
659 if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - "<<anURL);
661 Result_i::TFileNames aFileNames;
662 Result_i::TFileNames aFiles;
664 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
665 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
666 for (; anIter->More(); anIter->Next()) {
667 SALOMEDS::SObject_var aSObject = anIter->Value();
668 CORBA::Object_var anObj = SObjectToObject(aSObject);
669 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
670 aResult->Save(theComponent,
678 if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - aFileNames.size() - "<<aFileNames.size());
680 // save textures of custom point markers
681 std::string aMarkerMapFileName, aMarkerMapFile;
682 if( SaveMarkerMap( aStudy, anURL.c_str(), theIsMultiFile, true,
683 myMarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
684 aFileNames.push_back( aMarkerMapFileName );
685 aFiles.push_back( aMarkerMapFile );
688 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
689 if(aFileNames.empty())
690 return aStreamFile._retn();
692 SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
693 aStreamFile = SALOMEDS_Tool::PutFilesToStream(anURL, aListOfFileNames.in(), theIsMultiFile);
696 SALOMEDS_Tool::RemoveTemporaryFiles(anURL, aListOfFileNames, true);
698 return aStreamFile._retn();
702 //----------------------------------------------------------------------------
705 ::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
706 const char* theIORString,
707 CORBA::Boolean theIsMultiFile,
708 CORBA::Boolean theIsASCII)
710 CORBA::String_var aString("");
711 if(strcmp(theIORString, "") != 0){
712 CORBA::Object_var anObj = GetORB()->string_to_object(theIORString);
713 if(Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
714 aString = aStorable->ToString().c_str();
715 return aString._retn();
718 return aString._retn();
722 //----------------------------------------------------------------------------
727 return Base_i::GetID();
731 //----------------------------------------------------------------------------
734 ::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
736 class TEvent: public SALOME_Event {
737 std::string myStudyName;
739 TEvent(const std::string theStudyName):myStudyName(theStudyName)
741 virtual void Execute()
743 bool isActive = false;
744 SUIT_Session* aSession = SUIT_Session::session();
745 QList<SUIT_Application*> anApplications = aSession->applications();
746 QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
747 SUIT_Application* aFirstApp = *anIter;
748 while (anIter != anApplications.end()) {
749 SUIT_Application* anApp = *anIter;
750 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
751 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
752 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
753 if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = "
754 << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
755 if (myStudyName == aCStudy->Name()) {
765 MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
766 // Has to be loaded in an empty or in a new application
767 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
768 anApp->onLoadDoc(myStudyName.c_str());
773 if (!CORBA::is_nil(theStudy))
775 CORBA::String_var aName = theStudy->Name();
776 std::string aStudyName (aName.in());
777 if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
778 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
779 myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument));
781 ProcessVoidEvent(new TEvent(aStudyName));
783 // Load MED component if necessary
784 if(!myStudyDocument->FindComponent("MED")->_is_nil())
786 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
787 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
788 SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow(aComponent);
790 if(!CORBA::is_nil(aMedEngine))
792 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
794 aStudyBuilder->LoadWith( myStudyDocument->FindComponent( "MED" ), aMedEngine );
796 catch( const SALOME::SALOME_Exception& ) {
797 // Oops, something went wrong while loading
798 // See also SalomeApp_Study::openDataModel()
803 INFOS("CORBA::is_nil(theStudy)");
808 //----------------------------------------------------------------------------
813 return SALOMEDS::Study::_duplicate(myStudyDocument);
817 //----------------------------------------------------------------------------
823 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
824 return ViewManager::_duplicate(aViewManager->_this());
828 //----------------------------------------------------------------------------
829 SALOMEDS::SObject_ptr
831 ::ImportTables(const char* theFileName, bool theFirstStrAsTitle)
833 if(myStudyDocument->GetProperties()->IsLocked())
834 return SALOMEDS::SObject::_nil();
836 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument,
839 SALOMEDS::Study_var aStudy = aRes->GetStudy();
840 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aRes);
841 for (; anIter->More(); anIter->Next()) {
842 SALOMEDS::SObject_var SO = anIter->Value();
843 CreateTable( SO->GetID() );
847 ProcessVoidEvent(new TUpdateObjBrowser(aStudy->StudyId(),&isDone));
853 //----------------------------------------------------------------------------
856 ::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
857 const char* theFileName)
859 return VISU::ExportTableToFile(theTable, theFileName);
863 //----------------------------------------------------------------------------
866 ::ImportFile(const char* theFileName)
868 if(myStudyDocument->GetProperties()->IsLocked())
869 return Result::_nil();
871 Result_i* aResult = Result_i::New(myStudyDocument,
873 Result_i::eImportFile,
879 if(aResult->Create(theFileName) != NULL)
880 return aResult->_this();
882 aResult->_remove_ref();
884 return VISU::Result::_nil();
888 //----------------------------------------------------------------------------
891 ::CreateResult(const char* theFileName)
893 if(myStudyDocument->GetProperties()->IsLocked())
894 return Result::_nil();
896 Result_i* aResult = Result_i::New(myStudyDocument,
898 Result_i::eImportFile,
904 if(aResult->Create(theFileName) != NULL)
905 return aResult->_this();
907 aResult->_remove_ref();
909 return VISU::Result::_nil();
913 //----------------------------------------------------------------------------
916 ::CopyAndImportFile(const char* theFileName)
918 if(myStudyDocument->GetProperties()->IsLocked())
919 return Result::_nil();
921 Result_i* aResult = Result_i::New(myStudyDocument,
922 Result_i::eRestoredFile,
923 Result_i::eCopyAndImportFile,
928 if(aResult->Create(theFileName) != NULL)
929 return aResult->_this();
931 aResult->_remove_ref();
933 return VISU::Result::_nil();
937 //----------------------------------------------------------------------------
938 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject)
940 if (myStudyDocument->GetProperties()->IsLocked())
941 return Result::_nil();
943 Result_i* aResult = Result_i::New(myStudyDocument,
944 Result_i::eComponent,
945 Result_i::eImportMed,
950 if (aResult->Create(theMedSObject) != NULL)
952 return aResult->_this();
955 aResult->_remove_ref();
957 return VISU::Result::_nil();
961 //----------------------------------------------------------------------------
964 ::ImportMedField (SALOME_MED::FIELD_ptr theField)
966 if (myStudyDocument->GetProperties()->IsLocked())
967 return Result::_nil();
969 Result_i* aResult = Result_i::New(myStudyDocument,
970 Result_i::eComponent,
971 Result_i::eImportMedField,
977 if (aResult->Create(theField) != NULL)
978 return aResult->_this();
980 aResult->_remove_ref();
982 return VISU::Result::_nil();
987 ::RenameMeshInStudy(Result_ptr theResult,
988 const std::string& theMeshName,
989 int theEntity, // -1 for group indication
990 const std::string& theSubMeshName, // Family or Group name
991 const std::string& theNewName)
993 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
997 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
998 if (aStudyDocument->GetProperties()->IsLocked())
1003 VISU::VISUType aType;
1005 if (theSubMeshName == "")
1006 aType = VISU::TENTITY;
1008 aType = VISU::TFAMILY;
1010 aType = VISU::TGROUP;
1012 VISU::Storable::TRestoringMap aRestoringMap;
1013 aRestoringMap["myMeshName"] = theMeshName.c_str();
1017 aRestoringMap["myComment"] = "ENTITY";
1018 aRestoringMap["myId"] = QString::number(theEntity);
1021 aRestoringMap["myComment"] = "FAMILY";
1022 aRestoringMap["myEntityId"] = QString::number(theEntity);
1023 aRestoringMap["myName"] = theSubMeshName.c_str();
1026 aRestoringMap["myComment"] = "GROUP";
1027 aRestoringMap["myName"] = theSubMeshName.c_str();
1031 string anEntry = aResult->GetEntry(aRestoringMap);
1035 SALOMEDS::SObject_ptr aSObject = aStudyDocument->FindObjectID(anEntry.c_str());
1037 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
1038 aStudyBuilder->NewCommand(); // There is a transaction
1040 SALOMEDS::GenericAttribute_var anAttr =
1041 aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
1042 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
1043 aNameAttr->SetValue(theNewName.c_str());
1045 aStudyBuilder->CommitCommand();
1049 //----------------------------------------------------------------------------
1052 ::RenameEntityInStudy(Result_ptr theResult,
1053 const char* theMeshName,
1054 VISU::Entity theEntity,
1055 const char* theNewName)
1057 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, "", theNewName);
1061 //----------------------------------------------------------------------------
1064 ::RenameFamilyInStudy(Result_ptr theResult,
1065 const char* theMeshName,
1066 VISU::Entity theEntity,
1067 const char* theFamilyName,
1068 const char* theNewName)
1070 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, theFamilyName, theNewName);
1074 //----------------------------------------------------------------------------
1077 ::RenameGroupInStudy(Result_ptr theResult,
1078 const char* theMeshName,
1079 const char* theGroupName,
1080 const char* theNewName)
1082 RenameMeshInStudy(theResult, theMeshName, -1, theGroupName, theNewName);
1086 //----------------------------------------------------------------------------
1089 ::MeshOnEntity(Result_ptr theResult,
1090 const char* theMeshName,
1091 VISU::Entity theEntity)
1093 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1095 return VISU::Mesh::_nil();
1097 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1098 if (aStudyDocument->GetProperties()->IsLocked())
1099 return VISU::Mesh::_nil();
1101 Mesh_i* aPresent = new Mesh_i();
1102 if(aPresent->Create(aResult, theMeshName, theEntity))
1103 return aPresent->_this();
1105 aPresent->_remove_ref();
1107 return VISU::Mesh::_nil();
1111 //----------------------------------------------------------------------------
1114 ::FamilyMeshOnEntity(Result_ptr theResult,
1115 const char* theMeshName,
1116 VISU::Entity theEntity,
1117 const char* theFamilyName)
1119 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1121 return VISU::Mesh::_nil();
1123 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1124 if (aStudyDocument->GetProperties()->IsLocked())
1125 return VISU::Mesh::_nil();
1127 Mesh_i* aPresent = new Mesh_i();
1128 if(aPresent->Create(aResult, theMeshName, theEntity, theFamilyName))
1129 return aPresent->_this();
1131 aPresent->_remove_ref();
1133 return VISU::Mesh::_nil();
1137 //----------------------------------------------------------------------------
1140 ::GroupMesh(Result_ptr theResult,
1141 const char* theMeshName,
1142 const char* theGroupName)
1144 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1146 return VISU::Mesh::_nil();
1148 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1149 if (aStudyDocument->GetProperties()->IsLocked())
1150 return VISU::Mesh::_nil();
1152 Mesh_i* aPresent = new Mesh_i();
1153 if(aPresent->Create(aResult, theMeshName, theGroupName))
1154 return aPresent->_this();
1156 aPresent->_remove_ref();
1158 return VISU::Mesh::_nil();
1162 //----------------------------------------------------------------------------
1165 ::ScalarMapOnField(Result_ptr theResult,
1166 const char* theMeshName,
1167 VISU::Entity theEntity,
1168 const char* theFieldName,
1169 CORBA::Long theIteration)
1171 return Prs3dOnField<VISU::ScalarMap_i>(theResult,
1175 theIteration)._retn();
1179 //----------------------------------------------------------------------------
1182 ::GaussPointsOnField(Result_ptr theResult,
1183 const char* theMeshName,
1184 VISU::Entity theEntity,
1185 const char* theFieldName,
1186 CORBA::Long theIteration)
1188 return Prs3dOnField<VISU::GaussPoints_i>(theResult,
1192 theIteration)._retn();
1196 //---------------------------------------------------------------
1199 ::DeformedShapeOnField(Result_ptr theResult,
1200 const char* theMeshName,
1201 VISU::Entity theEntity,
1202 const char* theFieldName,
1203 CORBA::Long theIteration)
1205 return Prs3dOnField<VISU::DeformedShape_i>(theResult,
1209 theIteration)._retn();
1213 //---------------------------------------------------------------
1214 DeformedShapeAndScalarMap_ptr
1216 ::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
1217 const char* theMeshName,
1218 VISU::Entity theEntity,
1219 const char* theFieldName,
1220 CORBA::Long theIteration)
1222 return DeformedShapeAndScalarMapOnField(theResult,
1230 //---------------------------------------------------------------
1231 DeformedShapeAndScalarMap_ptr
1233 ::DeformedShapeAndScalarMapOnField(Result_ptr theResult,
1234 const char* theMeshName,
1235 VISU::Entity theEntity,
1236 const char* theFieldName,
1237 CORBA::Long theIteration)
1239 return Prs3dOnField<VISU::DeformedShapeAndScalarMap_i>(theResult,
1243 theIteration)._retn();
1247 //---------------------------------------------------------------
1250 ::VectorsOnField(Result_ptr theResult,
1251 const char* theMeshName,
1252 VISU::Entity theEntity,
1253 const char* theFieldName,
1254 CORBA::Long theIteration)
1256 return Prs3dOnField<VISU::Vectors_i>(theResult,
1260 theIteration)._retn();
1264 //---------------------------------------------------------------
1267 ::IsoSurfacesOnField(Result_ptr theResult,
1268 const char* theMeshName,
1269 VISU::Entity theEntity,
1270 const char* theFieldName,
1271 CORBA::Long theIteration)
1273 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,
1277 theIteration)._retn();
1281 //---------------------------------------------------------------
1284 ::StreamLinesOnField(Result_ptr theResult,
1285 const char* theMeshName,
1286 VISU::Entity theEntity,
1287 const char* theFieldName,
1288 CORBA::Long theIteration)
1290 return Prs3dOnField<VISU::StreamLines_i>(theResult,
1294 theIteration)._retn();
1298 //---------------------------------------------------------------
1301 ::Plot3DOnField(Result_ptr theResult,
1302 const char* theMeshName,
1303 VISU::Entity theEntity,
1304 const char* theFieldName,
1305 CORBA::Long theIteration)
1307 return Prs3dOnField<VISU::Plot3D_i>(theResult,
1311 theIteration)._retn();
1315 //---------------------------------------------------------------
1318 ::CutPlanesOnField(Result_ptr theResult,
1319 const char* theMeshName,
1320 VISU::Entity theEntity,
1321 const char* theFieldName,
1322 CORBA::Long theIteration)
1324 return Prs3dOnField<VISU::CutPlanes_i>(theResult,
1328 theIteration)._retn();
1332 //---------------------------------------------------------------
1335 ::CutLinesOnField(Result_ptr theResult,
1336 const char* theMeshName,
1337 VISU::Entity theEntity,
1338 const char* theFieldName,
1339 CORBA::Long theIteration)
1341 return Prs3dOnField<VISU::CutLines_i>(theResult,
1345 theIteration)._retn();
1348 //---------------------------------------------------------------
1351 ::CutSegmentOnField(Result_ptr theResult,
1352 const char* theMeshName,
1353 VISU::Entity theEntity,
1354 const char* theFieldName,
1355 CORBA::Long theIteration)
1357 return Prs3dOnField<VISU::CutSegment_i>(theResult,
1361 theIteration)._retn();
1364 //---------------------------------------------------------------
1365 struct CreateTableEvent: public SALOME_Event
1367 SALOMEDS::Study_var myStudyDocument;
1368 const char* myTableEntry;
1369 typedef Table_ptr TResult;
1372 CreateTableEvent(SALOMEDS::Study_var theStudy, const char* theTableEntry)
1374 myStudyDocument = theStudy;
1375 myTableEntry = theTableEntry;
1376 myResult = Table::_nil();
1383 SALOMEDS::SObject_var SO = myStudyDocument->FindObjectID(myTableEntry);
1384 SALOMEDS::GenericAttribute_var anAttr;
1385 if ( SO->FindAttribute(anAttr, "AttributeTableOfReal") ) {
1386 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1387 if ( isSparseMatrix( aTableOfReal ) ) {
1388 PointMap3d_i* pPresent = new PointMap3d_i(myStudyDocument,myTableEntry);
1389 if(pPresent->Create() != NULL)
1390 myResult = pPresent->_this();
1392 pPresent->_remove_ref();
1393 myResult = VISU::Table::_nil();
1398 Table_i* pPresent = new Table_i(myStudyDocument,myTableEntry);
1399 if(pPresent->Create() != NULL)
1400 myResult = pPresent->_this();
1402 pPresent->_remove_ref();
1403 myResult = VISU::Table::_nil();
1409 isSparseMatrix(SALOMEDS::AttributeTableOfReal_var theTableOfReal)
1411 int aCols = theTableOfReal->GetNbColumns();
1412 int aRows = theTableOfReal->GetNbRows();
1414 for (int i=1; i<=aCols; i++) {
1415 for (int j=1; j<=aRows; j++) {
1416 if ( !(theTableOfReal->HasValue(j, i)) )
1424 //---------------------------------------------------------------
1427 ::CreateTable(const char* theTableEntry)
1429 TCollection_AsciiString tmp( (char*)theTableEntry ); // 11.06.2008 IPAL18844
1430 if( myStudyDocument->GetProperties()->IsLocked() ||
1432 return Table::_nil();
1434 return ProcessEvent(new CreateTableEvent(myStudyDocument, theTableEntry));
1437 //---------------------------------------------------------------
1440 ::CreateCurve(Table_ptr theTable,
1441 CORBA::Long theHRow,
1442 CORBA::Long theVRow)
1444 return CreateCurveWithZExt( theTable, theHRow, theVRow, 0, false );
1448 //---------------------------------------------------------------
1451 ::CreateCurveWithZ(Table_ptr theTable,
1452 CORBA::Long theHRow,
1453 CORBA::Long theVRow,
1454 CORBA::Long theZRow)
1456 return CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, false );
1460 //---------------------------------------------------------------
1463 ::CreateCurveWithZExt(Table_ptr theTable,
1464 CORBA::Long theHRow,
1465 CORBA::Long theVRow,
1466 CORBA::Long theZRow,
1467 CORBA::Boolean theIsV2)
1469 if(myStudyDocument->GetProperties()->IsLocked())
1470 return Curve::_nil();
1472 PortableServer::POA_ptr aPOA = GetPOA();
1473 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
1474 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow,theZRow,theIsV2);
1475 if(pPresent->Create() != NULL)
1476 return pPresent->_this();
1478 pPresent->_remove_ref();
1479 return VISU::Curve::_nil();
1484 //---------------------------------------------------------------
1489 if(myStudyDocument->GetProperties()->IsLocked())
1490 return Container::_nil();
1492 Container_i* pPresent = new Container_i(myStudyDocument);
1493 if(pPresent->Create() != NULL)
1494 return pPresent->_this();
1496 pPresent->_remove_ref();
1497 return VISU::Container::_nil();
1502 //---------------------------------------------------------------
1505 ::CreateAnimation(View3D_ptr theView3D)
1507 if(myStudyDocument->GetProperties()->IsLocked())
1508 return Animation::_nil();
1510 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
1511 return anAnim->_this();
1513 return VISU::Animation::_nil();
1517 //---------------------------------------------------------------
1520 ::CreateEvolution(XYPlot_ptr theXYPlot)
1522 if(myStudyDocument->GetProperties()->IsLocked())
1523 return Evolution::_nil();
1525 if(VISU_Evolution_i* anEvolution = new VISU_Evolution_i(myStudyDocument,theXYPlot)){
1526 return anEvolution->_this();
1528 return VISU::Evolution::_nil();
1532 //---------------------------------------------------------------
1535 ::DeleteResult (Result_ptr theResult)
1537 theResult->RemoveFromStudy();
1541 //---------------------------------------------------------------
1544 ::DeletePrs3d(Prs3d_ptr thePrs3d)
1546 thePrs3d->RemoveFromStudy();
1550 //---------------------------------------------------------------
1553 ::Close(SALOMEDS::SComponent_ptr theComponent)
1555 if ( !CORBA::is_nil( theComponent ) ) {
1556 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1557 // 1. Decrement reference counter for published GenericObj-based servants
1558 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theComponent );
1559 anIter->InitEx( true );
1560 for ( ; anIter->More(); anIter->Next() ) {
1561 SALOMEDS::SObject_var aSObject = anIter->Value();
1562 if ( CORBA::is_nil( aSObject ) ) continue;
1563 CORBA::Object_var anObject = aSObject->GetObject();
1564 if ( CORBA::is_nil( anObject ) ) continue;
1565 SALOME::GenericObj_var aGenericObj = SALOME::GenericObj::_narrow( anObject );
1566 if ( !CORBA::is_nil( aGenericObj ) ) aGenericObj->UnRegister();
1569 if ( !CORBA::is_nil( myStudyDocument ) && !CORBA::is_nil( aStudy ) &&
1570 myStudyDocument->StudyId() == aStudy->StudyId() )
1571 myStudyDocument = SALOMEDS::Study::_nil();
1576 //---------------------------------------------------------------
1579 ::ComponentDataType()
1581 return CORBA::string_dup("VISU");
1585 //---------------------------------------------------------------
1588 ::CanPublishInStudy(CORBA::Object_ptr theIOR)
1590 Result_var aResultObj = Result::_narrow(theIOR);
1591 return !(aResultObj->_is_nil());
1595 //---------------------------------------------------------------
1596 SALOMEDS::SObject_ptr
1598 ::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1599 SALOMEDS::SObject_ptr theSObject,
1600 CORBA::Object_ptr theObject,
1601 const char* theName)
1602 throw (SALOME::SALOME_Exception)
1604 Unexpect aCatch(SalomeException);
1605 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
1607 SALOMEDS::SObject_var aResultSO;
1608 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
1610 return aResultSO._retn();
1611 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1612 CORBA::String_var anEntry = aResultObj->Create((const char*)aFileInfo.absoluteFilePath().toLatin1())->GetID();
1613 aResultSO = theStudy->FindObjectID(anEntry);
1614 return aResultSO._retn();
1618 //---------------------------------------------------------------
1621 ::CanCopy(SALOMEDS::SObject_ptr theObject)
1623 CORBA::Object_var anObj = SObjectToObject(theObject);
1624 if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in()))
1625 return aStorable->CanCopy(theObject);
1631 //---------------------------------------------------------------
1634 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
1635 CORBA::Long& theObjectID)
1638 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
1640 CORBA::Object_var anObj = SObjectToObject(theObject);
1641 if (CORBA::is_nil(anObj)) {
1642 aStreamFile->length(1);
1643 aStreamFile[0] = CORBA::string_dup("E")[0];
1644 } else if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())) {
1645 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1646 Storable::TFileNames aFileNames;
1647 bool anIsDone = aStorable->CopyFrom(theObject, theObjectID, aTmpDir, aFileNames);
1649 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
1650 aListOfFileNames->length(aFileNames.size());
1651 for(size_t anId = 0; anId < aFileNames.size(); anId++)
1652 aListOfFileNames[anId] = aFileNames[anId].c_str();
1655 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFileNames.in(), false);
1657 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aListOfFileNames.in(), true);
1659 return aStreamFile._retn();
1663 //---------------------------------------------------------------
1666 ::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1667 // The VISU component can paste only objects copied by VISU component
1668 CORBA::String_var aString = ComponentDataType();
1669 if (strcmp(theComponentName, aString.in()) == 0 && theObjectID == 1)
1675 //---------------------------------------------------------------
1676 SALOMEDS::SObject_ptr
1678 ::PasteInto(const SALOMEDS::TMPFile& theStream,
1679 CORBA::Long theObjectID,
1680 SALOMEDS::SObject_ptr theSObject)
1682 if (theObjectID != 1)
1683 return SALOMEDS::SObject::_nil();
1685 SALOMEDS::SComponent_var aComponent = theSObject->GetFatherComponent();
1686 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1687 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1688 CORBA::String_var aComponentID(aComponent->GetID());
1689 CORBA::String_var aSObjectID(theSObject->GetID());
1691 SALOMEDS::SObject_var aSObject;
1692 if (strcmp(aComponentID, aSObjectID) == 0) //create the new result SObject
1693 aSObject = aStudyBuilder->NewObject(aComponent);
1695 aSObject = SALOMEDS::SObject::_duplicate(theSObject);
1697 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1698 SALOMEDS::ListOfFileNames_var aListOfFileNames =
1699 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1700 if(MYDEBUG) MESSAGE("Result_i::PasteInto - aListOfFileNames->length() = "<<aListOfFileNames->length());
1702 std::ostringstream aLocalPersistentID;
1704 std::string aCopyPersist = aTmpDir + "copy_persistent";
1705 std::ifstream anInputFileStream( aCopyPersist.c_str() );
1706 anInputFileStream >> aLocalPersistentID.rdbuf();
1709 //Just for Result::Restore to find the Comment attribute :(
1710 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
1712 std::string aFileName(aTmpDir);
1713 if(aListOfFileNames->length() > 1)
1714 aFileName += aListOfFileNames[1].in();
1715 Storable* aStorable = Storable::Create(aSObject, aLocalPersistentID.str(), aFileName, false);
1717 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
1718 aFilesToRemove->length(1);
1719 aFilesToRemove[0] = aListOfFileNames[0];
1720 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aFilesToRemove.in(), true);
1722 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
1723 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1724 CORBA::String_var anIORValue(aStorable->GetID());
1725 anIOR->SetValue(anIORValue);
1727 return aSObject._retn();
1731 //---------------------------------------------------------------
1732 VISU::ColoredPrs3dCache_ptr
1734 ::GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy)
1736 return ColoredPrs3dCache_i::GetInstance(theStudy);
1740 CORBA::Long VISU_Gen_i::CreateClippingPlane(CORBA::Double X,CORBA::Double Y, CORBA::Double Z,
1741 CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1742 CORBA::Boolean isAuto, const char* name)
1744 return myClippingPlaneMgr.CreateClippingPlane(X, Y, Z, dX, dY, dZ, isAuto, name);
1748 void VISU_Gen_i::EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double Y, CORBA::Double Z,
1749 CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1750 CORBA::Boolean isAuto, const char* name)
1752 myClippingPlaneMgr.EditClippingPlane(id, X, Y, Z, dX, dY, dZ, isAuto, name);
1755 /* Returns clipping plane by its Id */
1756 VISU::ClippingPlane* VISU_Gen_i::GetClippingPlane(CORBA::Long id)
1758 VISU_CutPlaneFunction* aPlane = myClippingPlaneMgr.GetClippingPlane(id);
1760 if (aPlane != NULL) {
1763 aPlane->GetOrigin(aOrigin);
1764 aPlane->GetNormal(aDir);
1766 VISU::ClippingPlane* aRetPlane = new VISU::ClippingPlane;
1767 aRetPlane->X = aOrigin[0];
1768 aRetPlane->Y = aOrigin[1];
1769 aRetPlane->Z = aOrigin[2];
1770 aRetPlane->dX = aDir[0];
1771 aRetPlane->dY = aDir[1];
1772 aRetPlane->dZ = aDir[2];
1773 aRetPlane->isAuto = aPlane->isAuto();
1775 aRetPlane->name = aPlane->getName().c_str();
1781 /* Deletes clipping plane by its Id */
1782 CORBA::Boolean VISU_Gen_i::DeleteClippingPlane(CORBA::Long id)
1784 return myClippingPlaneMgr.DeleteClippingPlane(id);
1787 /* Applyes a clipping plane with Id to presentation thePrs */
1788 CORBA::Boolean VISU_Gen_i::ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1790 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1791 return myClippingPlaneMgr.ApplyClippingPlane(aPrs, id);
1794 /* Detaches a clipping plane with Id from presentation thePrs */
1795 CORBA::Boolean VISU_Gen_i::DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1797 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1798 return myClippingPlaneMgr.DetachClippingPlane(aPrs, id);
1801 /* Get number of clipping planes */
1802 CORBA::Long VISU_Gen_i::GetClippingPlanesNb()
1804 return myClippingPlaneMgr.GetClippingPlanesNb();
1808 \brief Converts set of VTK files to the one MED-file
1809 \param theVTKFiles sequence of VTK files
1810 \param theMEDFile MED-file
1811 \param theMeshName mesh name. This parameter can be empty. In this case name
1812 of mesh is equal vtk2med
1813 \param theTStamps values of time stamps. This array can be empty, in
1814 this case values of time stamps will be generated automatically ( 0, 1, 2 ... )
1815 \return TRUE if operation has been completed successfully, FALSE otherwise
1819 ::VTK2MED( const VISU::string_array& theVTKFiles,
1820 const char* theMEDFile,
1821 const char* theMeshName,
1822 const VISU::double_array& theTStamps )
1824 if ( !theMEDFile || !theVTKFiles.length() )
1827 VISU_Vtk2MedConvertor aConvertor;
1828 aConvertor.setMEDFileName( theMEDFile );
1829 // std::string aFirstFile = theVTKFiles[ 0 ];
1830 char* aFirstFile = CORBA::string_dup( theVTKFiles[ 0 ] );
1831 aConvertor.setFirstVTKFileName( aFirstFile );
1832 if ( theVTKFiles.length() > 1 )
1834 VISU_Vtk2MedConvertor::TVectorString aFiles( theVTKFiles.length() - 1 );
1835 for ( int i = 1, n = theVTKFiles.length(); i < n; i++ )
1836 aFiles[ i - 1 ] = theVTKFiles[ i ];
1837 aConvertor.setDataVTKFileNames( aFiles );
1839 if ( theTStamps.length() > 0 )
1841 VISU_Vtk2MedConvertor::TVectorDouble aTStamps( theTStamps.length() );
1842 for ( int i = 0, n = theTStamps.length(); i < n; i++ )
1843 aTStamps[ i ] = theTStamps[ i ];
1844 aConvertor.setTimeStamps( aTStamps );
1847 if ( theMeshName && strlen( theMeshName ) > 0 )
1848 aConvertor.setMeshName( theMeshName );
1850 aConvertor.addToIgnoringFieldList("cellID");
1851 aConvertor.setCellDataFieldNameIDS("cellID");
1853 int res = aConvertor.Execute();
1860 ::LoadTexture(const char* theTextureFile)
1862 if( CORBA::is_nil( myStudyDocument ) )
1865 int aStudyId = myStudyDocument->StudyId();
1867 VTK::MarkerTexture aMarkerTexture;
1868 if( !VTK::LoadTextureData( theTextureFile, VTK::MS_NONE, aMarkerTexture ) )
1871 VTK::MarkerMap& aMarkerMap = myMarkerMap[ aStudyId ];
1872 int aMarkerId = VTK::GetUniqueId( aMarkerMap );
1874 VTK::MarkerData& aMarkerData = aMarkerMap[ aMarkerId ];
1875 aMarkerData.first = theTextureFile;
1876 aMarkerData.second = aMarkerTexture;
1881 // Version information
1882 char* VISU_Gen_i::getVersion()
1884 #if VISU_DEVELOPMENT
1885 return CORBA::string_dup( VISU_VERSION_STR"dev" );
1887 return CORBA::string_dup( VISU_VERSION_STR );