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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_Gen_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_Gen_i.hh"
28 #include "VISU_Result_i.hh"
29 #include "VISU_PrsObject_i.hh"
30 #include "VISU_ViewManager_i.hh"
31 #include "VISU_ResultUtils.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::EngineComponent_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() );
845 ProcessVoidEvent(new TUpdateObjBrowser(aStudy->StudyId(),&isDone));
851 //----------------------------------------------------------------------------
854 ::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
855 const char* theFileName)
857 return VISU::ExportTableToFile(theTable, theFileName);
861 //----------------------------------------------------------------------------
864 ::ImportFile(const char* theFileName)
866 if(myStudyDocument->GetProperties()->IsLocked())
867 return Result::_nil();
869 Result_i* aResult = Result_i::New(myStudyDocument,
871 Result_i::eImportFile,
877 if(aResult->Create(theFileName) != NULL)
878 return aResult->_this();
880 aResult->_remove_ref();
882 return VISU::Result::_nil();
886 //----------------------------------------------------------------------------
889 ::CreateResult(const char* theFileName)
891 if(myStudyDocument->GetProperties()->IsLocked())
892 return Result::_nil();
894 Result_i* aResult = Result_i::New(myStudyDocument,
896 Result_i::eImportFile,
902 if(aResult->Create(theFileName) != NULL)
903 return aResult->_this();
905 aResult->_remove_ref();
907 return VISU::Result::_nil();
911 //----------------------------------------------------------------------------
914 ::CopyAndImportFile(const char* theFileName)
916 if(myStudyDocument->GetProperties()->IsLocked())
917 return Result::_nil();
919 Result_i* aResult = Result_i::New(myStudyDocument,
920 Result_i::eRestoredFile,
921 Result_i::eCopyAndImportFile,
926 if(aResult->Create(theFileName) != NULL)
927 return aResult->_this();
929 aResult->_remove_ref();
931 return VISU::Result::_nil();
935 //----------------------------------------------------------------------------
936 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject)
938 if (myStudyDocument->GetProperties()->IsLocked())
939 return Result::_nil();
941 Result_i* aResult = Result_i::New(myStudyDocument,
942 Result_i::eComponent,
943 Result_i::eImportMed,
948 if (aResult->Create(theMedSObject) != NULL)
950 return aResult->_this();
953 aResult->_remove_ref();
955 return VISU::Result::_nil();
959 //----------------------------------------------------------------------------
962 ::ImportMedField (SALOME_MED::FIELD_ptr theField)
964 if (myStudyDocument->GetProperties()->IsLocked())
965 return Result::_nil();
967 Result_i* aResult = Result_i::New(myStudyDocument,
968 Result_i::eComponent,
969 Result_i::eImportMedField,
975 if (aResult->Create(theField) != NULL)
976 return aResult->_this();
978 aResult->_remove_ref();
980 return VISU::Result::_nil();
985 ::RenameMeshInStudy(Result_ptr theResult,
986 const std::string& theMeshName,
987 int theEntity, // -1 for group indication
988 const std::string& theSubMeshName, // Family or Group name
989 const std::string& theNewName)
991 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
995 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
996 if (aStudyDocument->GetProperties()->IsLocked())
1001 VISU::VISUType aType;
1003 if (theSubMeshName == "")
1004 aType = VISU::TENTITY;
1006 aType = VISU::TFAMILY;
1008 aType = VISU::TGROUP;
1010 VISU::Storable::TRestoringMap aRestoringMap;
1011 aRestoringMap["myMeshName"] = theMeshName.c_str();
1015 aRestoringMap["myComment"] = "ENTITY";
1016 aRestoringMap["myId"] = QString::number(theEntity);
1019 aRestoringMap["myComment"] = "FAMILY";
1020 aRestoringMap["myEntityId"] = QString::number(theEntity);
1021 aRestoringMap["myName"] = theSubMeshName.c_str();
1024 aRestoringMap["myComment"] = "GROUP";
1025 aRestoringMap["myName"] = theSubMeshName.c_str();
1029 string anEntry = aResult->GetEntry(aRestoringMap);
1033 SALOMEDS::SObject_ptr aSObject = aStudyDocument->FindObjectID(anEntry.c_str());
1035 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
1036 aStudyBuilder->NewCommand(); // There is a transaction
1038 SALOMEDS::GenericAttribute_var anAttr =
1039 aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
1040 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
1041 aNameAttr->SetValue(theNewName.c_str());
1043 aStudyBuilder->CommitCommand();
1047 //----------------------------------------------------------------------------
1050 ::RenameEntityInStudy(Result_ptr theResult,
1051 const char* theMeshName,
1052 VISU::Entity theEntity,
1053 const char* theNewName)
1055 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, "", theNewName);
1059 //----------------------------------------------------------------------------
1062 ::RenameFamilyInStudy(Result_ptr theResult,
1063 const char* theMeshName,
1064 VISU::Entity theEntity,
1065 const char* theFamilyName,
1066 const char* theNewName)
1068 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, theFamilyName, theNewName);
1072 //----------------------------------------------------------------------------
1075 ::RenameGroupInStudy(Result_ptr theResult,
1076 const char* theMeshName,
1077 const char* theGroupName,
1078 const char* theNewName)
1080 RenameMeshInStudy(theResult, theMeshName, -1, theGroupName, theNewName);
1084 //----------------------------------------------------------------------------
1087 ::MeshOnEntity(Result_ptr theResult,
1088 const char* theMeshName,
1089 VISU::Entity theEntity)
1091 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1093 return VISU::Mesh::_nil();
1095 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1096 if (aStudyDocument->GetProperties()->IsLocked())
1097 return VISU::Mesh::_nil();
1099 Mesh_i* aPresent = new Mesh_i();
1100 if(aPresent->Create(aResult, theMeshName, theEntity))
1101 return aPresent->_this();
1103 aPresent->_remove_ref();
1105 return VISU::Mesh::_nil();
1109 //----------------------------------------------------------------------------
1112 ::FamilyMeshOnEntity(Result_ptr theResult,
1113 const char* theMeshName,
1114 VISU::Entity theEntity,
1115 const char* theFamilyName)
1117 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1119 return VISU::Mesh::_nil();
1121 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1122 if (aStudyDocument->GetProperties()->IsLocked())
1123 return VISU::Mesh::_nil();
1125 Mesh_i* aPresent = new Mesh_i();
1126 if(aPresent->Create(aResult, theMeshName, theEntity, theFamilyName))
1127 return aPresent->_this();
1129 aPresent->_remove_ref();
1131 return VISU::Mesh::_nil();
1135 //----------------------------------------------------------------------------
1138 ::GroupMesh(Result_ptr theResult,
1139 const char* theMeshName,
1140 const char* theGroupName)
1142 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1144 return VISU::Mesh::_nil();
1146 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1147 if (aStudyDocument->GetProperties()->IsLocked())
1148 return VISU::Mesh::_nil();
1150 Mesh_i* aPresent = new Mesh_i();
1151 if(aPresent->Create(aResult, theMeshName, theGroupName))
1152 return aPresent->_this();
1154 aPresent->_remove_ref();
1156 return VISU::Mesh::_nil();
1160 //----------------------------------------------------------------------------
1163 ::ScalarMapOnField(Result_ptr theResult,
1164 const char* theMeshName,
1165 VISU::Entity theEntity,
1166 const char* theFieldName,
1167 CORBA::Long theIteration)
1169 return Prs3dOnField<VISU::ScalarMap_i>(theResult,
1173 theIteration)._retn();
1177 //----------------------------------------------------------------------------
1180 ::GaussPointsOnField(Result_ptr theResult,
1181 const char* theMeshName,
1182 VISU::Entity theEntity,
1183 const char* theFieldName,
1184 CORBA::Long theIteration)
1186 return Prs3dOnField<VISU::GaussPoints_i>(theResult,
1190 theIteration)._retn();
1194 //---------------------------------------------------------------
1197 ::DeformedShapeOnField(Result_ptr theResult,
1198 const char* theMeshName,
1199 VISU::Entity theEntity,
1200 const char* theFieldName,
1201 CORBA::Long theIteration)
1203 return Prs3dOnField<VISU::DeformedShape_i>(theResult,
1207 theIteration)._retn();
1211 //---------------------------------------------------------------
1212 DeformedShapeAndScalarMap_ptr
1214 ::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
1215 const char* theMeshName,
1216 VISU::Entity theEntity,
1217 const char* theFieldName,
1218 CORBA::Long theIteration)
1220 return DeformedShapeAndScalarMapOnField(theResult,
1228 //---------------------------------------------------------------
1229 DeformedShapeAndScalarMap_ptr
1231 ::DeformedShapeAndScalarMapOnField(Result_ptr theResult,
1232 const char* theMeshName,
1233 VISU::Entity theEntity,
1234 const char* theFieldName,
1235 CORBA::Long theIteration)
1237 return Prs3dOnField<VISU::DeformedShapeAndScalarMap_i>(theResult,
1241 theIteration)._retn();
1245 //---------------------------------------------------------------
1248 ::VectorsOnField(Result_ptr theResult,
1249 const char* theMeshName,
1250 VISU::Entity theEntity,
1251 const char* theFieldName,
1252 CORBA::Long theIteration)
1254 return Prs3dOnField<VISU::Vectors_i>(theResult,
1258 theIteration)._retn();
1262 //---------------------------------------------------------------
1265 ::IsoSurfacesOnField(Result_ptr theResult,
1266 const char* theMeshName,
1267 VISU::Entity theEntity,
1268 const char* theFieldName,
1269 CORBA::Long theIteration)
1271 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,
1275 theIteration)._retn();
1279 //---------------------------------------------------------------
1282 ::StreamLinesOnField(Result_ptr theResult,
1283 const char* theMeshName,
1284 VISU::Entity theEntity,
1285 const char* theFieldName,
1286 CORBA::Long theIteration)
1288 return Prs3dOnField<VISU::StreamLines_i>(theResult,
1292 theIteration)._retn();
1296 //---------------------------------------------------------------
1299 ::Plot3DOnField(Result_ptr theResult,
1300 const char* theMeshName,
1301 VISU::Entity theEntity,
1302 const char* theFieldName,
1303 CORBA::Long theIteration)
1305 return Prs3dOnField<VISU::Plot3D_i>(theResult,
1309 theIteration)._retn();
1313 //---------------------------------------------------------------
1316 ::CutPlanesOnField(Result_ptr theResult,
1317 const char* theMeshName,
1318 VISU::Entity theEntity,
1319 const char* theFieldName,
1320 CORBA::Long theIteration)
1322 return Prs3dOnField<VISU::CutPlanes_i>(theResult,
1326 theIteration)._retn();
1330 //---------------------------------------------------------------
1333 ::CutLinesOnField(Result_ptr theResult,
1334 const char* theMeshName,
1335 VISU::Entity theEntity,
1336 const char* theFieldName,
1337 CORBA::Long theIteration)
1339 return Prs3dOnField<VISU::CutLines_i>(theResult,
1343 theIteration)._retn();
1346 //---------------------------------------------------------------
1349 ::CutSegmentOnField(Result_ptr theResult,
1350 const char* theMeshName,
1351 VISU::Entity theEntity,
1352 const char* theFieldName,
1353 CORBA::Long theIteration)
1355 return Prs3dOnField<VISU::CutSegment_i>(theResult,
1359 theIteration)._retn();
1362 //---------------------------------------------------------------
1363 struct CreateTableEvent: public SALOME_Event
1365 SALOMEDS::Study_var myStudyDocument;
1366 const char* myTableEntry;
1367 typedef Table_ptr TResult;
1370 CreateTableEvent(SALOMEDS::Study_var theStudy, const char* theTableEntry)
1372 myStudyDocument = theStudy;
1373 myTableEntry = theTableEntry;
1374 myResult = Table::_nil();
1381 SALOMEDS::SObject_var SO = myStudyDocument->FindObjectID(myTableEntry);
1382 SALOMEDS::GenericAttribute_var anAttr;
1383 if ( SO->FindAttribute(anAttr, "AttributeTableOfReal") ) {
1384 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1385 if ( isSparseMatrix( aTableOfReal ) ) {
1386 PointMap3d_i* pPresent = new PointMap3d_i(myStudyDocument,myTableEntry);
1387 if(pPresent->Create() != NULL)
1388 myResult = pPresent->_this();
1390 pPresent->_remove_ref();
1391 myResult = VISU::Table::_nil();
1396 Table_i* pPresent = new Table_i(myStudyDocument,myTableEntry);
1397 if(pPresent->Create() != NULL)
1398 myResult = pPresent->_this();
1400 pPresent->_remove_ref();
1401 myResult = VISU::Table::_nil();
1407 isSparseMatrix(SALOMEDS::AttributeTableOfReal_var theTableOfReal)
1409 int aCols = theTableOfReal->GetNbColumns();
1410 int aRows = theTableOfReal->GetNbRows();
1412 for (int i=1; i<=aCols; i++) {
1413 for (int j=1; j<=aRows; j++) {
1414 if ( !(theTableOfReal->HasValue(j, i)) )
1422 //---------------------------------------------------------------
1425 ::CreateTable(const char* theTableEntry)
1427 TCollection_AsciiString tmp( (char*)theTableEntry ); // 11.06.2008 IPAL18844
1428 if( myStudyDocument->GetProperties()->IsLocked() ||
1430 return Table::_nil();
1432 return ProcessEvent(new CreateTableEvent(myStudyDocument, theTableEntry));
1435 //---------------------------------------------------------------
1438 ::CreateCurve(Table_ptr theTable,
1439 CORBA::Long theHRow,
1440 CORBA::Long theVRow)
1442 return CreateCurveWithZExt( theTable, theHRow, theVRow, 0, false );
1446 //---------------------------------------------------------------
1449 ::CreateCurveWithZ(Table_ptr theTable,
1450 CORBA::Long theHRow,
1451 CORBA::Long theVRow,
1452 CORBA::Long theZRow)
1454 return CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, false );
1458 //---------------------------------------------------------------
1461 ::CreateCurveWithZExt(Table_ptr theTable,
1462 CORBA::Long theHRow,
1463 CORBA::Long theVRow,
1464 CORBA::Long theZRow,
1465 CORBA::Boolean theIsV2)
1467 if(myStudyDocument->GetProperties()->IsLocked())
1468 return Curve::_nil();
1470 PortableServer::POA_ptr aPOA = GetPOA();
1471 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
1472 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow,theZRow,theIsV2);
1473 if(pPresent->Create() != NULL)
1474 return pPresent->_this();
1476 pPresent->_remove_ref();
1477 return VISU::Curve::_nil();
1482 //---------------------------------------------------------------
1487 if(myStudyDocument->GetProperties()->IsLocked())
1488 return Container::_nil();
1490 Container_i* pPresent = new Container_i(myStudyDocument);
1491 if(pPresent->Create() != NULL)
1492 return pPresent->_this();
1494 pPresent->_remove_ref();
1495 return VISU::Container::_nil();
1500 //---------------------------------------------------------------
1503 ::CreateAnimation(View3D_ptr theView3D)
1505 if(myStudyDocument->GetProperties()->IsLocked())
1506 return Animation::_nil();
1508 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
1509 return anAnim->_this();
1511 return VISU::Animation::_nil();
1515 //---------------------------------------------------------------
1518 ::CreateEvolution(XYPlot_ptr theXYPlot)
1520 if(myStudyDocument->GetProperties()->IsLocked())
1521 return Evolution::_nil();
1523 if(VISU_Evolution_i* anEvolution = new VISU_Evolution_i(myStudyDocument,theXYPlot)){
1524 return anEvolution->_this();
1526 return VISU::Evolution::_nil();
1530 //---------------------------------------------------------------
1533 ::DeleteResult (Result_ptr theResult)
1535 theResult->RemoveFromStudy();
1539 //---------------------------------------------------------------
1542 ::DeletePrs3d(Prs3d_ptr thePrs3d)
1544 thePrs3d->RemoveFromStudy();
1548 //---------------------------------------------------------------
1551 ::Close(SALOMEDS::SComponent_ptr theComponent)
1553 if ( !CORBA::is_nil( myStudyDocument ) && !CORBA::is_nil( theComponent ) &&
1554 myStudyDocument->StudyId() == theComponent->GetStudy()->StudyId())
1555 myStudyDocument = SALOMEDS::Study::_nil();
1559 //---------------------------------------------------------------
1562 ::ComponentDataType()
1564 return CORBA::string_dup("VISU");
1568 //---------------------------------------------------------------
1571 ::CanPublishInStudy(CORBA::Object_ptr theIOR)
1573 Result_var aResultObj = Result::_narrow(theIOR);
1574 return !(aResultObj->_is_nil());
1578 //---------------------------------------------------------------
1579 SALOMEDS::SObject_ptr
1581 ::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1582 SALOMEDS::SObject_ptr theSObject,
1583 CORBA::Object_ptr theObject,
1584 const char* theName)
1585 throw (SALOME::SALOME_Exception)
1587 Unexpect aCatch(SalomeException);
1588 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
1590 SALOMEDS::SObject_var aResultSO;
1591 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
1593 return aResultSO._retn();
1594 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1595 CORBA::String_var anEntry = aResultObj->Create((const char*)aFileInfo.absoluteFilePath().toLatin1())->GetID();
1596 aResultSO = theStudy->FindObjectID(anEntry);
1597 return aResultSO._retn();
1601 //---------------------------------------------------------------
1604 ::CanCopy(SALOMEDS::SObject_ptr theObject)
1606 CORBA::Object_var anObj = SObjectToObject(theObject);
1607 if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in()))
1608 return aStorable->CanCopy(theObject);
1614 //---------------------------------------------------------------
1617 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
1618 CORBA::Long& theObjectID)
1621 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
1623 CORBA::Object_var anObj = SObjectToObject(theObject);
1624 if (CORBA::is_nil(anObj)) {
1625 aStreamFile->length(1);
1626 aStreamFile[0] = CORBA::string_dup("E")[0];
1627 } else if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())) {
1628 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1629 Storable::TFileNames aFileNames;
1630 bool anIsDone = aStorable->CopyFrom(theObject, theObjectID, aTmpDir, aFileNames);
1632 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
1633 aListOfFileNames->length(aFileNames.size());
1634 for(size_t anId = 0; anId < aFileNames.size(); anId++)
1635 aListOfFileNames[anId] = aFileNames[anId].c_str();
1638 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFileNames.in(), false);
1640 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aListOfFileNames.in(), true);
1642 return aStreamFile._retn();
1646 //---------------------------------------------------------------
1649 ::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1650 // The VISU component can paste only objects copied by VISU component
1651 CORBA::String_var aString = ComponentDataType();
1652 if (strcmp(theComponentName, aString.in()) == 0 && theObjectID == 1)
1658 //---------------------------------------------------------------
1659 SALOMEDS::SObject_ptr
1661 ::PasteInto(const SALOMEDS::TMPFile& theStream,
1662 CORBA::Long theObjectID,
1663 SALOMEDS::SObject_ptr theSObject)
1665 if (theObjectID != 1)
1666 return SALOMEDS::SObject::_nil();
1668 SALOMEDS::SComponent_var aComponent = theSObject->GetFatherComponent();
1669 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1670 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1671 CORBA::String_var aComponentID(aComponent->GetID());
1672 CORBA::String_var aSObjectID(theSObject->GetID());
1674 SALOMEDS::SObject_var aSObject;
1675 if (strcmp(aComponentID, aSObjectID) == 0) //create the new result SObject
1676 aSObject = aStudyBuilder->NewObject(aComponent);
1678 aSObject = SALOMEDS::SObject::_duplicate(theSObject);
1680 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1681 SALOMEDS::ListOfFileNames_var aListOfFileNames =
1682 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1683 if(MYDEBUG) MESSAGE("Result_i::PasteInto - aListOfFileNames->length() = "<<aListOfFileNames->length());
1685 std::ostringstream aLocalPersistentID;
1687 std::string aCopyPersist = aTmpDir + "copy_persistent";
1688 std::ifstream anInputFileStream( aCopyPersist.c_str() );
1689 anInputFileStream >> aLocalPersistentID.rdbuf();
1692 //Just for Result::Restore to find the Comment attribute :(
1693 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
1695 std::string aFileName(aTmpDir);
1696 if(aListOfFileNames->length() > 1)
1697 aFileName += aListOfFileNames[1].in();
1698 Storable* aStorable = Storable::Create(aSObject, aLocalPersistentID.str(), aFileName, false);
1700 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
1701 aFilesToRemove->length(1);
1702 aFilesToRemove[0] = aListOfFileNames[0];
1703 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aFilesToRemove.in(), true);
1705 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
1706 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1707 CORBA::String_var anIORValue(aStorable->GetID());
1708 anIOR->SetValue(anIORValue);
1710 return aSObject._retn();
1714 //---------------------------------------------------------------
1715 VISU::ColoredPrs3dCache_ptr
1717 ::GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy)
1719 return ColoredPrs3dCache_i::GetInstance(theStudy);
1723 CORBA::Long VISU_Gen_i::CreateClippingPlane(CORBA::Double X,CORBA::Double Y, CORBA::Double Z,
1724 CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1725 CORBA::Boolean isAuto, const char* name)
1727 return myClippingPlaneMgr.CreateClippingPlane(X, Y, Z, dX, dY, dZ, isAuto, name);
1731 void VISU_Gen_i::EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double Y, CORBA::Double Z,
1732 CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1733 CORBA::Boolean isAuto, const char* name)
1735 myClippingPlaneMgr.EditClippingPlane(id, X, Y, Z, dX, dY, dZ, isAuto, name);
1738 /* Returns clipping plane by its Id */
1739 VISU::ClippingPlane* VISU_Gen_i::GetClippingPlane(CORBA::Long id)
1741 VISU_CutPlaneFunction* aPlane = myClippingPlaneMgr.GetClippingPlane(id);
1743 if (aPlane != NULL) {
1746 aPlane->GetOrigin(aOrigin);
1747 aPlane->GetNormal(aDir);
1749 VISU::ClippingPlane* aRetPlane = new VISU::ClippingPlane;
1750 aRetPlane->X = aOrigin[0];
1751 aRetPlane->Y = aOrigin[1];
1752 aRetPlane->Z = aOrigin[2];
1753 aRetPlane->dX = aDir[0];
1754 aRetPlane->dY = aDir[1];
1755 aRetPlane->dZ = aDir[2];
1756 aRetPlane->isAuto = aPlane->isAuto();
1758 aRetPlane->name = aPlane->getName().c_str();
1764 /* Deletes clipping plane by its Id */
1765 CORBA::Boolean VISU_Gen_i::DeleteClippingPlane(CORBA::Long id)
1767 return myClippingPlaneMgr.DeleteClippingPlane(id);
1770 /* Applyes a clipping plane with Id to presentation thePrs */
1771 CORBA::Boolean VISU_Gen_i::ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1773 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1774 return myClippingPlaneMgr.ApplyClippingPlane(aPrs, id);
1777 /* Detaches a clipping plane with Id from presentation thePrs */
1778 CORBA::Boolean VISU_Gen_i::DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1780 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1781 return myClippingPlaneMgr.DetachClippingPlane(aPrs, id);
1784 /* Get number of clipping planes */
1785 CORBA::Long VISU_Gen_i::GetClippingPlanesNb()
1787 return myClippingPlaneMgr.GetClippingPlanesNb();
1791 \brief Converts set of VTK files to the one MED-file
1792 \param theVTKFiles sequence of VTK files
1793 \param theMEDFile MED-file
1794 \param theMeshName mesh name. This parameter can be empty. In this case name
1795 of mesh is equal vtk2med
1796 \param theTStamps values of time stamps. This array can be empty, in
1797 this case values of time stamps will be generated automatically ( 0, 1, 2 ... )
1798 \return TRUE if operation has been completed successfully, FALSE otherwise
1802 ::VTK2MED( const VISU::string_array& theVTKFiles,
1803 const char* theMEDFile,
1804 const char* theMeshName,
1805 const VISU::double_array& theTStamps )
1807 if ( !theMEDFile || !theVTKFiles.length() )
1810 VISU_Vtk2MedConvertor aConvertor;
1811 aConvertor.setMEDFileName( theMEDFile );
1812 // std::string aFirstFile = theVTKFiles[ 0 ];
1813 char* aFirstFile = CORBA::string_dup( theVTKFiles[ 0 ] );
1814 aConvertor.setFirstVTKFileName( aFirstFile );
1815 if ( theVTKFiles.length() > 1 )
1817 VISU_Vtk2MedConvertor::TVectorString aFiles( theVTKFiles.length() - 1 );
1818 for ( int i = 1, n = theVTKFiles.length(); i < n; i++ )
1819 aFiles[ i - 1 ] = theVTKFiles[ i ];
1820 aConvertor.setDataVTKFileNames( aFiles );
1822 if ( theTStamps.length() > 0 )
1824 VISU_Vtk2MedConvertor::TVectorDouble aTStamps( theTStamps.length() );
1825 for ( int i = 0, n = theTStamps.length(); i < n; i++ )
1826 aTStamps[ i ] = theTStamps[ i ];
1827 aConvertor.setTimeStamps( aTStamps );
1830 if ( theMeshName && strlen( theMeshName ) > 0 )
1831 aConvertor.setMeshName( theMeshName );
1833 aConvertor.addToIgnoringFieldList("cellID");
1834 aConvertor.setCellDataFieldNameIDS("cellID");
1836 int res = aConvertor.Execute();
1843 ::LoadTexture(const char* theTextureFile)
1845 if( CORBA::is_nil( myStudyDocument ) )
1848 int aStudyId = myStudyDocument->StudyId();
1850 VTK::MarkerTexture aMarkerTexture;
1851 if( !VTK::LoadTextureData( theTextureFile, VTK::MS_NONE, aMarkerTexture ) )
1854 VTK::MarkerMap& aMarkerMap = myMarkerMap[ aStudyId ];
1855 int aMarkerId = VTK::GetUniqueId( aMarkerMap );
1857 VTK::MarkerData& aMarkerData = aMarkerMap[ aMarkerId ];
1858 aMarkerData.first = theTextureFile;
1859 aMarkerData.second = aMarkerTexture;