1 // Copyright (C) 2007-2013 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)
75 #include CORBA_SERVER_HEADER(MED_Gen)
83 #include <vtkRenderer.h>
84 #include <vtkActorCollection.h>
87 #include <TCollection_AsciiString.hxx>
88 #include <TColStd_SequenceOfAsciiString.hxx>
90 #include "Utils_ExceptHandlers.hxx"
91 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
96 #include <boost/filesystem/path.hpp>
97 #include <boost/filesystem/operations.hpp>
98 namespace filesystem = boost::filesystem;
102 static int MYDEBUG = 0;
104 static int MYDEBUG = 0;
110 VISU_I_EXPORT VISU::VISU_Gen_ptr
111 GetImpl(CORBA::ORB_ptr theORB,
112 PortableServer::POA_ptr thePOA,
113 SALOME_NamingService* theNamingService,
116 if(MYDEBUG) MESSAGE("extern 'C' GetImpl");
117 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
118 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
119 return aVISU_Gen->_this();
124 //----------------------------------------------------------------------------
125 static std::string VISU_TMP_DIR;
127 static CORBA::Boolean myIsMultiFile;
128 const CORBA::Boolean IsMultiFile()
130 return myIsMultiFile;
133 //----------------------------------------------------------------------------
135 ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
137 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
139 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
140 aStudyBuilder->NewCommand();
141 int aLocked = theStudyDocument->GetProperties()->IsLocked();
142 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
143 aSComponent = aStudyBuilder->NewComponent("VISU");
144 _PTR(GenericAttribute) anAttr =
145 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
146 _PTR(AttributeName) aName (anAttr);
148 CORBA::ORB_var anORB = Base_i::GetORB();
149 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
150 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
151 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
152 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
153 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
154 if (!Comp->_is_nil()) {
155 aName->SetValue(Comp->componentusername());
158 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
159 _PTR(AttributePixMap) aPixmap (anAttr);
160 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
162 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
163 aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
164 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
165 aStudyBuilder->CommitCommand();
171 //----------------------------------------------------------------------------
172 SALOMEDS::SComponent_var
173 FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument)
175 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
176 if (aSComponent->_is_nil()) {
177 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
178 aStudyBuilder->NewCommand();
179 int aLocked = theStudyDocument->GetProperties()->IsLocked();
180 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
181 aSComponent = aStudyBuilder->NewComponent("VISU");
182 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
183 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
185 //NRI aName->SetValue("Visu");
186 CORBA::ORB_var anORB = Base_i::GetORB();
187 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
188 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
189 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
190 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
191 if ( !Comp->_is_nil() ) {
192 aName->SetValue( Comp->componentusername() );
195 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
196 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
197 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
199 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
200 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
201 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
202 aStudyBuilder->CommitCommand();
208 //----------------------------------------------------------------------------
212 Storable::RegistryStorableEngine(Result_i::myComment.c_str(),&(Result_i::StorableEngine));
214 Storable::RegistryStorableEngine(Mesh_i::myComment.c_str(),&(Mesh_i::StorableEngine));
216 Storable::RegistryStorableEngine(ScalarMap_i::myComment.c_str(),&(StorableEngine<ScalarMap_i>));
217 Storable::RegistryStorableEngine(GaussPoints_i::myComment.c_str(),&(StorableEngine<GaussPoints_i>));
218 Storable::RegistryStorableEngine(DeformedShape_i::myComment.c_str(),&(StorableEngine<DeformedShape_i>));
219 Storable::RegistryStorableEngine(CutPlanes_i::myComment.c_str(),&(StorableEngine<CutPlanes_i>));
220 Storable::RegistryStorableEngine(CutLines_i::myComment.c_str(),&(StorableEngine<CutLines_i>));
221 Storable::RegistryStorableEngine(CutSegment_i::myComment.c_str(),&(StorableEngine<CutSegment_i>));
222 Storable::RegistryStorableEngine(IsoSurfaces_i::myComment.c_str(),&(StorableEngine<IsoSurfaces_i>));
223 Storable::RegistryStorableEngine(StreamLines_i::myComment.c_str(),&(StorableEngine<StreamLines_i>));
224 Storable::RegistryStorableEngine(Plot3D_i::myComment.c_str(),&(StorableEngine<Plot3D_i>));
225 Storable::RegistryStorableEngine(Vectors_i::myComment.c_str(),&(StorableEngine<Vectors_i>));
226 Storable::RegistryStorableEngine(DeformedShapeAndScalarMap_i::myComment.c_str(),&(StorableEngine<DeformedShapeAndScalarMap_i>));
228 Storable::RegistryStorableEngine(ColoredPrs3dHolder_i::myComment.c_str(),&(ColoredPrs3dHolder_i::StorableEngine));
229 Storable::RegistryStorableEngine(ColoredPrs3dCache_i::myComment.c_str(),&(ColoredPrs3dCache_i::StorableEngine));
231 Storable::RegistryStorableEngine(PointMap3d_i::myComment.c_str(),&(PointMap3d_i::StorableEngine));
232 Storable::RegistryStorableEngine(Table_i::myComment.c_str(),&(Table_i::StorableEngine));
233 Storable::RegistryStorableEngine(Curve_i::myComment.c_str(),&(Curve_i::StorableEngine));
234 Storable::RegistryStorableEngine(Container_i::myComment.c_str(),&(Container_i::StorableEngine));
238 //----------------------------------------------------------------------------
239 SALOMEDS::ListOfFileNames*
240 GetListOfFileNames(const Result_i::TFileNames& theFileNames)
242 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
243 if(!theFileNames.empty()){
244 aListOfFileNames->length(theFileNames.size());
245 for(int aCounter = theFileNames.size(); aCounter > 0; aCounter--)
246 aListOfFileNames[aCounter-1] = theFileNames[aCounter-1].c_str();
248 return aListOfFileNames._retn();
252 //----------------------------------------------------------------------------
254 LoadMarkerMap(SALOMEDS::Study_ptr theStudy,
258 StudyId2MarkerMap& theStudyId2MarkerMap,
259 std::string& theMarkerMapFileName,
260 std::string& theMarkerMapFile)
263 if( theIsMultiFile ) {
264 CORBA::String_var anURL = theStudy->URL();
265 aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
268 theMarkerMapFileName = aPrefix + "_textures";
269 theMarkerMapFile = VISU_TMP_DIR + theMarkerMapFileName;
271 if( theIsASCII && !HDFascii::ConvertFromASCIIToHDF( const_cast<char*>( theMarkerMapFile.c_str() ), true ) )
275 HDFdataset* aDataset;
279 HDFgroup* aSubSubGroup;
282 aFile = new HDFfile( (char*)theMarkerMapFile.c_str() );
284 aFile->OpenOnDisk( HDF_RDONLY );
286 catch ( HDFexception ) {
287 INFOS( "Load(): " << theMarkerMapFile << " not found!" );
291 VTK::MarkerMap& aMarkerMap = theStudyId2MarkerMap[ theStudy->StudyId() ];
293 for( int i = 0, n = aFile->nInternalObjects(); i < n; i++ ) {
294 char markerGrpName[ HDF_NAME_MAX_LEN+1 ];
295 aFile->InternalObjectIndentify( i, markerGrpName );
298 std::string aMarkerFile;
299 VTK::MarkerTexture aMarkerTexture;
301 if( string( markerGrpName ).substr( 0, 6 ) == string( "Marker" ) ) {
302 aTopGroup = new HDFgroup( markerGrpName, aFile );
303 aTopGroup->OpenOnDisk();
305 aMarkerId = atoi( string( markerGrpName ).substr( 6 ).c_str() );
309 if( aTopGroup->ExistInternalObject( "File" ) ) {
310 aDataset = new HDFdataset( "File", aTopGroup );
311 aDataset->OpenOnDisk();
312 aSize = aDataset->GetSize();
313 char* aFileName = new char[ aSize ];
314 aDataset->ReadFromDisk( aFileName );
315 aMarkerFile = aFileName;
317 aDataset->CloseOnDisk();
320 if( aTopGroup->ExistInternalObject( "Texture" ) ) {
321 aDataset = new HDFdataset( "Texture", aTopGroup );
322 aDataset->OpenOnDisk();
323 aSize = aDataset->GetSize();
324 int* aTextureData = new int[ aSize ];
325 aDataset->ReadFromDisk( aTextureData );
326 for( int j = 0; j < aSize; j++ )
327 aMarkerTexture.push_back( aTextureData[j] );
328 delete [] aTextureData;
329 aDataset->CloseOnDisk();
332 aTopGroup->CloseOnDisk();
336 aMarkerMap[ aMarkerId ] = VTK::MarkerData( aMarkerFile, aMarkerTexture );
339 aFile->CloseOnDisk();
345 //----------------------------------------------------------------------------
347 SaveMarkerMap(SALOMEDS::Study_ptr theStudy,
351 const StudyId2MarkerMap& theStudyId2MarkerMap,
352 std::string& theMarkerMapFileName,
353 std::string& theMarkerMapFile)
355 VISU::StudyId2MarkerMap::const_iterator aMainIter = theStudyId2MarkerMap.find( theStudy->StudyId() );
356 if( aMainIter == theStudyId2MarkerMap.end() )
359 const VTK::MarkerMap& aMarkerMap = aMainIter->second;
360 if( aMarkerMap.empty() )
364 if( theIsMultiFile ) {
365 CORBA::String_var anURL = theStudy->URL();
366 aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
369 theMarkerMapFileName = aPrefix + "_textures";
370 theMarkerMapFile = string( theURL ) + theMarkerMapFileName;
373 HDFdataset* aDataset;
377 HDFgroup* aSubSubGroup;
380 aFile = new HDFfile( (char*)theMarkerMapFile.c_str() );
381 aFile->CreateOnDisk();
383 VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
384 for( ; aMarkerIter != aMarkerMap.end(); aMarkerIter++ ) {
385 int aMarkerId = aMarkerIter->first;
386 const VTK::MarkerData& aMarkerData = aMarkerIter->second;
387 std::string aMarkerFile = aMarkerData.first;
388 VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
390 char markerGrpName[30];
391 sprintf( markerGrpName, "Marker %d", aMarkerId );
392 aTopGroup = new HDFgroup( markerGrpName, aFile );
394 aTopGroup->CreateOnDisk();
396 aSize[ 0 ] = aMarkerFile.length() + 1;
397 aDataset = new HDFdataset( "File", aTopGroup, HDF_STRING, aSize, 1 );
398 aDataset->CreateOnDisk();
399 aDataset->WriteOnDisk( ( char* )( aMarkerFile.c_str() ) );
400 aDataset->CloseOnDisk();
402 int* aTextureData = new int[ aMarkerTexture.size() ];
403 VTK::MarkerTexture::const_iterator anIter = aMarkerTexture.begin();
404 for( int i = 0; anIter != aMarkerTexture.end(); anIter++, i++ )
405 aTextureData[i] = *anIter;
407 aSize[0] = aMarkerTexture.size();
408 aDataset = new HDFdataset( "Texture", aTopGroup, HDF_INT32, aSize, 1 );
409 aDataset->CreateOnDisk();
410 aDataset->WriteOnDisk( aTextureData );
411 aDataset->CloseOnDisk();
412 delete [] aTextureData;
414 aTopGroup->CloseOnDisk();
417 aFile->CloseOnDisk();
420 if( theIsASCII && !HDFascii::ConvertFromHDFToASCII( const_cast<char*>( theMarkerMapFile.c_str() ), true ) )
427 //----------------------------------------------------------------------------
429 ::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
430 SALOME_NamingService* theNamingService, QMutex* theMutex) :
431 Engines_Component_i()
433 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
434 Base_i::myMutex = theMutex; //apo
435 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
436 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
437 Base_i::myNamingService = theNamingService;
438 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
439 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
440 Base_i::myVisuGenImpl = this;
443 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
444 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
445 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
446 if(aListOfOpenStudies->length() > 0) {
447 CORBA::String_var aStudyName = aListOfOpenStudies[0];
448 //aFileInfo.setFile(aStudyName.in());
449 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
450 myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument));
452 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
456 //----------------------------------------------------------------------------
459 ::CreatePrs3d(VISUType theType,
460 SALOMEDS::Study_ptr theStudy)
462 if(ColoredPrs3d_i* aPrs3d = CreatePrs3d_i(theType, theStudy, ColoredPrs3d_i::EPublishIndependently))
463 return aPrs3d->_this();
464 return Prs3d::_nil();
468 //----------------------------------------------------------------------------
472 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
476 //----------------------------------------------------------------------------
478 CorrectSObjectType(SALOMEDS::SObject_ptr theSObject,
479 SALOMEDS::StudyBuilder_ptr theBuilder)
481 SALOMEDS::GenericAttribute_var anAttr;
482 bool isAttrStringFound = false;
484 if( theSObject->FindAttribute(anAttr, "AttributeComment") ) {
485 //SRN: Replace an AttributeComment with AttributeString
486 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
487 string aValue = aComment->Value();
488 theBuilder->RemoveAttribute(theSObject, "AttributeComment");
489 anAttr = theBuilder->FindOrCreateAttribute(theSObject, "AttributeString");
490 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
491 aStringAttr->SetValue(aValue.c_str());
492 isAttrStringFound = true;
495 if ( isAttrStringFound || theSObject->FindAttribute(anAttr, "AttributeString") ) {
496 SALOMEDS::AttributeString_var aAttComment = SALOMEDS::AttributeString::_narrow(anAttr);
498 CORBA::String_var aValue = aAttComment->Value();
499 std::string aString = Storable::CorrectPersistentString(aValue.in());
500 aAttComment->SetValue( aString.c_str() );
506 //----------------------------------------------------------------------------
508 LoadWithMarkerMap(SALOMEDS::SComponent_ptr theComponent,
509 const SALOMEDS::TMPFile & theStream,
511 CORBA::Boolean theIsMultiFile,
512 CORBA::Boolean theIsASCII,
513 StudyId2MarkerMap& theStudyId2MarkerMap)
515 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
517 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
518 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
520 for (anIter->InitEx(true); anIter->More(); anIter->Next()) {
521 SALOMEDS::SObject_var aSObject = anIter->Value();
522 CorrectSObjectType(aSObject, aStudyBuilder);
525 VISU_TMP_DIR = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
526 SALOMEDS::ListOfFileNames_var aSeq =
527 SALOMEDS_Tool::PutStreamToFiles(theStream, VISU_TMP_DIR, theIsMultiFile);
528 myIsMultiFile = theIsMultiFile;
530 // load textures of custom point markers
531 Result_i::TFileNames aTMPFileNames;
532 std::string aMarkerMapFileName, aMarkerMapFile;
533 if( LoadMarkerMap( aStudy, theURL, theIsMultiFile, theIsASCII,
534 theStudyId2MarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
535 aTMPFileNames.push_back( aMarkerMapFileName );
538 if(!theIsMultiFile && !aTMPFileNames.empty()) {
539 SALOMEDS::ListOfFileNames_var aListOfTMPFileNames = GetListOfFileNames(aTMPFileNames);
540 SALOMEDS_Tool::RemoveTemporaryFiles(VISU_TMP_DIR, aListOfTMPFileNames, true );
547 //----------------------------------------------------------------------------
550 ::Load(SALOMEDS::SComponent_ptr theComponent,
551 const SALOMEDS::TMPFile & theStream,
553 CORBA::Boolean theIsMultiFile)
556 return LoadWithMarkerMap(theComponent, theStream, theURL, theIsMultiFile, false, myMarkerMap);
560 //----------------------------------------------------------------------------
563 ::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
564 const SALOMEDS::TMPFile & theStream,
569 return LoadWithMarkerMap(theComponent, theStream, theURL, theIsMultiFile, true, myMarkerMap);
573 //----------------------------------------------------------------------------
576 ::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
577 const char* theLocalPersistentID,
578 CORBA::Boolean theIsMultiFile,
579 CORBA::Boolean theIsASCII)
581 CORBA::String_var aString("");
582 if(strcmp(theLocalPersistentID,"") != 0) {
583 Storable* aStorable = Storable::Create(theSObject,
584 theLocalPersistentID,
587 if(aStorable != NULL)
588 aString = aStorable->GetID();
590 return aString._retn();
594 //----------------------------------------------------------------------------
597 ::Save(SALOMEDS::SComponent_ptr theComponent,
601 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - theURL = '"<<theURL<<"'");
603 Result_i::TFileNames aFileNames;
604 Result_i::TFileNames aFiles;
606 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
607 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
608 for (; anIter->More(); anIter->Next()) {
609 SALOMEDS::SObject_var aSObject = anIter->Value();
610 CORBA::Object_var anObj = SObjectToObject(aSObject);
611 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
612 aResult->Save(theComponent,
620 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<<aFileNames.size());
622 // save textures of custom point markers
623 Result_i::TFileNames aTMPFileNames;
624 std::string aMarkerMapFileName, aMarkerMapFile;
625 if( SaveMarkerMap( aStudy, theURL, theIsMultiFile, false,
626 myMarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
627 aTMPFileNames.push_back( aMarkerMapFileName );
628 aFileNames.push_back( aMarkerMapFileName );
629 aFiles.push_back( aMarkerMapFile );
632 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
633 if(aFileNames.empty())
634 return aStreamFile._retn();
636 SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
637 SALOMEDS::ListOfFileNames_var aListOfFiles = GetListOfFileNames(aFiles);
640 aStreamFile = SALOMEDS_Tool::PutFilesToStream(theURL, aListOfFiles.in(), theIsMultiFile);
642 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in());
644 if(!theIsMultiFile && !aTMPFileNames.empty()) {
645 SALOMEDS::ListOfFileNames_var aListOfTMPFileNames = GetListOfFileNames(aTMPFileNames);
646 SALOMEDS_Tool::RemoveTemporaryFiles(theURL, aListOfTMPFileNames, true);
649 return aStreamFile._retn();
653 //----------------------------------------------------------------------------
656 ::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
660 std::string anURL = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
661 if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - "<<anURL);
663 Result_i::TFileNames aFileNames;
664 Result_i::TFileNames aFiles;
666 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
667 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
668 for (; anIter->More(); anIter->Next()) {
669 SALOMEDS::SObject_var aSObject = anIter->Value();
670 CORBA::Object_var anObj = SObjectToObject(aSObject);
671 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
672 aResult->Save(theComponent,
680 if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - aFileNames.size() - "<<aFileNames.size());
682 // save textures of custom point markers
683 std::string aMarkerMapFileName, aMarkerMapFile;
684 if( SaveMarkerMap( aStudy, anURL.c_str(), theIsMultiFile, true,
685 myMarkerMap, aMarkerMapFileName, aMarkerMapFile ) ) {
686 aFileNames.push_back( aMarkerMapFileName );
687 aFiles.push_back( aMarkerMapFile );
690 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
691 if(aFileNames.empty())
692 return aStreamFile._retn();
694 SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
695 aStreamFile = SALOMEDS_Tool::PutFilesToStream(anURL, aListOfFileNames.in(), theIsMultiFile);
698 SALOMEDS_Tool::RemoveTemporaryFiles(anURL, aListOfFileNames, true);
700 return aStreamFile._retn();
704 //----------------------------------------------------------------------------
707 ::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
708 const char* theIORString,
709 CORBA::Boolean theIsMultiFile,
710 CORBA::Boolean theIsASCII)
712 CORBA::String_var aString("");
713 if(strcmp(theIORString, "") != 0){
714 CORBA::Object_var anObj = GetORB()->string_to_object(theIORString);
715 if(Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
716 aString = aStorable->ToString().c_str();
717 return aString._retn();
720 return aString._retn();
724 //----------------------------------------------------------------------------
729 return Base_i::GetID();
733 //----------------------------------------------------------------------------
736 ::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
738 class TEvent: public SALOME_Event {
739 std::string myStudyName;
741 TEvent(const std::string theStudyName):myStudyName(theStudyName)
743 virtual void Execute()
745 bool isActive = false;
746 SUIT_Session* aSession = SUIT_Session::session();
747 QList<SUIT_Application*> anApplications = aSession->applications();
748 QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
749 SUIT_Application* aFirstApp = *anIter;
750 while (anIter != anApplications.end()) {
751 SUIT_Application* anApp = *anIter;
752 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
753 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
754 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
755 if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = "
756 << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
757 if (myStudyName == aCStudy->Name()) {
767 MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
768 // Has to be loaded in an empty or in a new application
769 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
770 anApp->onLoadDoc(myStudyName.c_str());
775 if (!CORBA::is_nil(theStudy))
777 CORBA::String_var aName = theStudy->Name();
778 std::string aStudyName (aName.in());
779 if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
780 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
781 myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument));
783 ProcessVoidEvent(new TEvent(aStudyName));
786 // Load MED component if necessary
787 if (!myStudyDocument->FindComponent("MED")->_is_nil())
789 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
790 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
791 SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow(aComponent);
793 if(!CORBA::is_nil(aMedEngine))
795 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
797 aStudyBuilder->LoadWith( myStudyDocument->FindComponent( "MED" ), aMedEngine );
799 catch( const SALOME::SALOME_Exception& ) {
800 // Oops, something went wrong while loading
801 // See also SalomeApp_Study::openDataModel()
805 #endif // WITH_MEDGEN
807 INFOS("CORBA::is_nil(theStudy)");
812 //----------------------------------------------------------------------------
817 return SALOMEDS::Study::_duplicate(myStudyDocument);
821 //----------------------------------------------------------------------------
827 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
828 return ViewManager::_duplicate(aViewManager->_this());
832 //----------------------------------------------------------------------------
833 SALOMEDS::SObject_ptr
835 ::ImportTables(const char* theFileName, bool theFirstStrAsTitle)
837 if(myStudyDocument->GetProperties()->IsLocked())
838 return SALOMEDS::SObject::_nil();
840 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument,
843 SALOMEDS::Study_var aStudy = aRes->GetStudy();
844 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aRes);
845 for (; anIter->More(); anIter->Next()) {
846 SALOMEDS::SObject_var SO = anIter->Value();
847 CreateTable( SO->GetID() );
851 ProcessVoidEvent(new TUpdateObjBrowser(aStudy->StudyId(),&isDone));
857 //----------------------------------------------------------------------------
860 ::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
861 const char* theFileName)
863 return VISU::ExportTableToFile(theTable, theFileName);
867 //----------------------------------------------------------------------------
870 ::ImportFile(const char* theFileName)
872 if(myStudyDocument->GetProperties()->IsLocked())
873 return Result::_nil();
875 Result_i* aResult = Result_i::New(myStudyDocument,
877 Result_i::eImportFile,
883 if(aResult->Create(theFileName) != NULL)
884 return aResult->_this();
886 aResult->_remove_ref();
888 return VISU::Result::_nil();
892 //----------------------------------------------------------------------------
895 ::CreateResult(const char* theFileName)
897 if(myStudyDocument->GetProperties()->IsLocked())
898 return Result::_nil();
900 Result_i* aResult = Result_i::New(myStudyDocument,
902 Result_i::eImportFile,
908 if(aResult->Create(theFileName) != NULL)
909 return aResult->_this();
911 aResult->_remove_ref();
913 return VISU::Result::_nil();
917 //----------------------------------------------------------------------------
920 ::CopyAndImportFile(const char* theFileName)
922 if(myStudyDocument->GetProperties()->IsLocked())
923 return Result::_nil();
925 Result_i* aResult = Result_i::New(myStudyDocument,
926 Result_i::eRestoredFile,
927 Result_i::eCopyAndImportFile,
932 if(aResult->Create(theFileName) != NULL)
933 return aResult->_this();
935 aResult->_remove_ref();
937 return VISU::Result::_nil();
941 //----------------------------------------------------------------------------
942 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject)
944 if (myStudyDocument->GetProperties()->IsLocked())
945 return Result::_nil();
947 Result_i* aResult = Result_i::New(myStudyDocument,
948 Result_i::eComponent,
949 Result_i::eImportMed,
954 if (aResult->Create(theMedSObject) != NULL)
956 return aResult->_this();
959 aResult->_remove_ref();
961 return VISU::Result::_nil();
965 //----------------------------------------------------------------------------
968 ::ImportMedField (SALOME_MED::FIELD_ptr theField)
970 if (myStudyDocument->GetProperties()->IsLocked())
971 return Result::_nil();
973 Result_i* aResult = Result_i::New(myStudyDocument,
974 Result_i::eComponent,
975 Result_i::eImportMedField,
981 if (aResult->Create(theField) != NULL)
982 return aResult->_this();
984 aResult->_remove_ref();
986 return VISU::Result::_nil();
991 ::RenameMeshInStudy(Result_ptr theResult,
992 const std::string& theMeshName,
993 int theEntity, // -1 for group indication
994 const std::string& theSubMeshName, // Family or Group name
995 const std::string& theNewName)
997 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1001 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1002 if (aStudyDocument->GetProperties()->IsLocked())
1007 VISU::VISUType aType;
1009 if (theSubMeshName == "")
1010 aType = VISU::TENTITY;
1012 aType = VISU::TFAMILY;
1014 aType = VISU::TGROUP;
1016 VISU::Storable::TRestoringMap aRestoringMap;
1017 aRestoringMap["myMeshName"] = theMeshName.c_str();
1021 aRestoringMap["myComment"] = "ENTITY";
1022 aRestoringMap["myId"] = QString::number(theEntity);
1025 aRestoringMap["myComment"] = "FAMILY";
1026 aRestoringMap["myEntityId"] = QString::number(theEntity);
1027 aRestoringMap["myName"] = theSubMeshName.c_str();
1030 aRestoringMap["myComment"] = "GROUP";
1031 aRestoringMap["myName"] = theSubMeshName.c_str();
1035 string anEntry = aResult->GetEntry(aRestoringMap);
1039 SALOMEDS::SObject_ptr aSObject = aStudyDocument->FindObjectID(anEntry.c_str());
1041 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
1042 aStudyBuilder->NewCommand(); // There is a transaction
1044 SALOMEDS::GenericAttribute_var anAttr =
1045 aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
1046 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
1047 aNameAttr->SetValue(theNewName.c_str());
1049 aStudyBuilder->CommitCommand();
1053 //----------------------------------------------------------------------------
1056 ::RenameEntityInStudy(Result_ptr theResult,
1057 const char* theMeshName,
1058 VISU::Entity theEntity,
1059 const char* theNewName)
1061 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, "", theNewName);
1065 //----------------------------------------------------------------------------
1068 ::RenameFamilyInStudy(Result_ptr theResult,
1069 const char* theMeshName,
1070 VISU::Entity theEntity,
1071 const char* theFamilyName,
1072 const char* theNewName)
1074 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, theFamilyName, theNewName);
1078 //----------------------------------------------------------------------------
1081 ::RenameGroupInStudy(Result_ptr theResult,
1082 const char* theMeshName,
1083 const char* theGroupName,
1084 const char* theNewName)
1086 RenameMeshInStudy(theResult, theMeshName, -1, theGroupName, theNewName);
1090 //----------------------------------------------------------------------------
1093 ::MeshOnEntity(Result_ptr theResult,
1094 const char* theMeshName,
1095 VISU::Entity theEntity)
1097 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1099 return VISU::Mesh::_nil();
1101 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1102 if (aStudyDocument->GetProperties()->IsLocked())
1103 return VISU::Mesh::_nil();
1105 Mesh_i* aPresent = new Mesh_i();
1106 if(aPresent->Create(aResult, theMeshName, theEntity))
1107 return aPresent->_this();
1109 aPresent->_remove_ref();
1111 return VISU::Mesh::_nil();
1115 //----------------------------------------------------------------------------
1118 ::FamilyMeshOnEntity(Result_ptr theResult,
1119 const char* theMeshName,
1120 VISU::Entity theEntity,
1121 const char* theFamilyName)
1123 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1125 return VISU::Mesh::_nil();
1127 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1128 if (aStudyDocument->GetProperties()->IsLocked())
1129 return VISU::Mesh::_nil();
1131 Mesh_i* aPresent = new Mesh_i();
1132 if(aPresent->Create(aResult, theMeshName, theEntity, theFamilyName))
1133 return aPresent->_this();
1135 aPresent->_remove_ref();
1137 return VISU::Mesh::_nil();
1141 //----------------------------------------------------------------------------
1144 ::GroupMesh(Result_ptr theResult,
1145 const char* theMeshName,
1146 const char* theGroupName)
1148 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
1150 return VISU::Mesh::_nil();
1152 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
1153 if (aStudyDocument->GetProperties()->IsLocked())
1154 return VISU::Mesh::_nil();
1156 Mesh_i* aPresent = new Mesh_i();
1157 if(aPresent->Create(aResult, theMeshName, theGroupName))
1158 return aPresent->_this();
1160 aPresent->_remove_ref();
1162 return VISU::Mesh::_nil();
1166 //----------------------------------------------------------------------------
1169 ::ScalarMapOnField(Result_ptr theResult,
1170 const char* theMeshName,
1171 VISU::Entity theEntity,
1172 const char* theFieldName,
1173 CORBA::Long theIteration)
1175 return Prs3dOnField<VISU::ScalarMap_i>(theResult,
1179 theIteration)._retn();
1183 //----------------------------------------------------------------------------
1186 ::GaussPointsOnField(Result_ptr theResult,
1187 const char* theMeshName,
1188 VISU::Entity theEntity,
1189 const char* theFieldName,
1190 CORBA::Long theIteration)
1192 return Prs3dOnField<VISU::GaussPoints_i>(theResult,
1196 theIteration)._retn();
1200 //---------------------------------------------------------------
1203 ::DeformedShapeOnField(Result_ptr theResult,
1204 const char* theMeshName,
1205 VISU::Entity theEntity,
1206 const char* theFieldName,
1207 CORBA::Long theIteration)
1209 return Prs3dOnField<VISU::DeformedShape_i>(theResult,
1213 theIteration)._retn();
1217 //---------------------------------------------------------------
1218 DeformedShapeAndScalarMap_ptr
1220 ::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
1221 const char* theMeshName,
1222 VISU::Entity theEntity,
1223 const char* theFieldName,
1224 CORBA::Long theIteration)
1226 return DeformedShapeAndScalarMapOnField(theResult,
1234 //---------------------------------------------------------------
1235 DeformedShapeAndScalarMap_ptr
1237 ::DeformedShapeAndScalarMapOnField(Result_ptr theResult,
1238 const char* theMeshName,
1239 VISU::Entity theEntity,
1240 const char* theFieldName,
1241 CORBA::Long theIteration)
1243 return Prs3dOnField<VISU::DeformedShapeAndScalarMap_i>(theResult,
1247 theIteration)._retn();
1251 //---------------------------------------------------------------
1254 ::VectorsOnField(Result_ptr theResult,
1255 const char* theMeshName,
1256 VISU::Entity theEntity,
1257 const char* theFieldName,
1258 CORBA::Long theIteration)
1260 return Prs3dOnField<VISU::Vectors_i>(theResult,
1264 theIteration)._retn();
1268 //---------------------------------------------------------------
1271 ::IsoSurfacesOnField(Result_ptr theResult,
1272 const char* theMeshName,
1273 VISU::Entity theEntity,
1274 const char* theFieldName,
1275 CORBA::Long theIteration)
1277 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,
1281 theIteration)._retn();
1285 //---------------------------------------------------------------
1288 ::StreamLinesOnField(Result_ptr theResult,
1289 const char* theMeshName,
1290 VISU::Entity theEntity,
1291 const char* theFieldName,
1292 CORBA::Long theIteration)
1294 return Prs3dOnField<VISU::StreamLines_i>(theResult,
1298 theIteration)._retn();
1302 //---------------------------------------------------------------
1305 ::Plot3DOnField(Result_ptr theResult,
1306 const char* theMeshName,
1307 VISU::Entity theEntity,
1308 const char* theFieldName,
1309 CORBA::Long theIteration)
1311 return Prs3dOnField<VISU::Plot3D_i>(theResult,
1315 theIteration)._retn();
1319 //---------------------------------------------------------------
1322 ::CutPlanesOnField(Result_ptr theResult,
1323 const char* theMeshName,
1324 VISU::Entity theEntity,
1325 const char* theFieldName,
1326 CORBA::Long theIteration)
1328 return Prs3dOnField<VISU::CutPlanes_i>(theResult,
1332 theIteration)._retn();
1336 //---------------------------------------------------------------
1339 ::CutLinesOnField(Result_ptr theResult,
1340 const char* theMeshName,
1341 VISU::Entity theEntity,
1342 const char* theFieldName,
1343 CORBA::Long theIteration)
1345 return Prs3dOnField<VISU::CutLines_i>(theResult,
1349 theIteration)._retn();
1352 //---------------------------------------------------------------
1355 ::CutSegmentOnField(Result_ptr theResult,
1356 const char* theMeshName,
1357 VISU::Entity theEntity,
1358 const char* theFieldName,
1359 CORBA::Long theIteration)
1361 return Prs3dOnField<VISU::CutSegment_i>(theResult,
1365 theIteration)._retn();
1368 //---------------------------------------------------------------
1369 struct CreateTableEvent: public SALOME_Event
1371 SALOMEDS::Study_var myStudyDocument;
1372 const char* myTableEntry;
1373 typedef Table_ptr TResult;
1376 CreateTableEvent(SALOMEDS::Study_var theStudy, const char* theTableEntry)
1378 myStudyDocument = theStudy;
1379 myTableEntry = theTableEntry;
1380 myResult = Table::_nil();
1387 SALOMEDS::SObject_var SO = myStudyDocument->FindObjectID(myTableEntry);
1388 SALOMEDS::GenericAttribute_var anAttr;
1389 if ( SO->FindAttribute(anAttr, "AttributeTableOfReal") ) {
1390 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1391 if ( isSparseMatrix( aTableOfReal ) ) {
1392 PointMap3d_i* pPresent = new PointMap3d_i(myStudyDocument,myTableEntry);
1393 if(pPresent->Create() != NULL)
1394 myResult = pPresent->_this();
1396 pPresent->_remove_ref();
1397 myResult = VISU::Table::_nil();
1402 Table_i* pPresent = new Table_i(myStudyDocument,myTableEntry);
1403 if(pPresent->Create() != NULL)
1404 myResult = pPresent->_this();
1406 pPresent->_remove_ref();
1407 myResult = VISU::Table::_nil();
1413 isSparseMatrix(SALOMEDS::AttributeTableOfReal_var theTableOfReal)
1415 int aCols = theTableOfReal->GetNbColumns();
1416 int aRows = theTableOfReal->GetNbRows();
1418 for (int i=1; i<=aCols; i++) {
1419 for (int j=1; j<=aRows; j++) {
1420 if ( !(theTableOfReal->HasValue(j, i)) )
1428 //---------------------------------------------------------------
1431 ::CreateTable(const char* theTableEntry)
1433 TCollection_AsciiString tmp( (char*)theTableEntry ); // 11.06.2008 IPAL18844
1434 if( myStudyDocument->GetProperties()->IsLocked() ||
1436 return Table::_nil();
1438 return ProcessEvent(new CreateTableEvent(myStudyDocument, theTableEntry));
1441 //---------------------------------------------------------------
1444 ::CreateCurve(Table_ptr theTable,
1445 CORBA::Long theHRow,
1446 CORBA::Long theVRow)
1448 return CreateCurveWithZExt( theTable, theHRow, theVRow, 0, false );
1452 //---------------------------------------------------------------
1455 ::CreateCurveWithZ(Table_ptr theTable,
1456 CORBA::Long theHRow,
1457 CORBA::Long theVRow,
1458 CORBA::Long theZRow)
1460 return CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, false );
1464 //---------------------------------------------------------------
1467 ::CreateCurveWithZExt(Table_ptr theTable,
1468 CORBA::Long theHRow,
1469 CORBA::Long theVRow,
1470 CORBA::Long theZRow,
1471 CORBA::Boolean theIsV2)
1473 if(myStudyDocument->GetProperties()->IsLocked())
1474 return Curve::_nil();
1476 PortableServer::POA_ptr aPOA = GetPOA();
1477 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
1478 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow,theZRow,theIsV2);
1479 if(pPresent->Create() != NULL)
1480 return pPresent->_this();
1482 pPresent->_remove_ref();
1483 return VISU::Curve::_nil();
1488 //---------------------------------------------------------------
1493 if(myStudyDocument->GetProperties()->IsLocked())
1494 return Container::_nil();
1496 Container_i* pPresent = new Container_i(myStudyDocument);
1497 if(pPresent->Create() != NULL)
1498 return pPresent->_this();
1500 pPresent->_remove_ref();
1501 return VISU::Container::_nil();
1506 //---------------------------------------------------------------
1509 ::CreateAnimation(View3D_ptr theView3D)
1511 if(myStudyDocument->GetProperties()->IsLocked())
1512 return Animation::_nil();
1514 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
1515 return anAnim->_this();
1517 return VISU::Animation::_nil();
1521 //---------------------------------------------------------------
1524 ::CreateEvolution(XYPlot_ptr theXYPlot)
1526 if(myStudyDocument->GetProperties()->IsLocked())
1527 return Evolution::_nil();
1529 if(VISU_Evolution_i* anEvolution = new VISU_Evolution_i(myStudyDocument,theXYPlot)){
1530 return anEvolution->_this();
1532 return VISU::Evolution::_nil();
1536 //---------------------------------------------------------------
1539 ::DeleteResult (Result_ptr theResult)
1541 theResult->RemoveFromStudy();
1545 //---------------------------------------------------------------
1548 ::DeletePrs3d(Prs3d_ptr thePrs3d)
1550 thePrs3d->RemoveFromStudy();
1554 //---------------------------------------------------------------
1557 ::Close(SALOMEDS::SComponent_ptr theComponent)
1559 if ( !CORBA::is_nil( theComponent ) ) {
1560 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
1561 // 1. Decrement reference counter for published GenericObj-based servants
1562 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theComponent );
1563 anIter->InitEx( true );
1564 for ( ; anIter->More(); anIter->Next() ) {
1565 SALOMEDS::SObject_var aSObject = anIter->Value();
1566 if ( CORBA::is_nil( aSObject ) ) continue;
1567 CORBA::Object_var anObject = aSObject->GetObject();
1568 if ( CORBA::is_nil( anObject ) ) continue;
1569 SALOME::GenericObj_var aGenericObj = SALOME::GenericObj::_narrow( anObject );
1570 if ( !CORBA::is_nil( aGenericObj ) ) aGenericObj->UnRegister();
1573 if ( !CORBA::is_nil( myStudyDocument ) && !CORBA::is_nil( aStudy ) &&
1574 myStudyDocument->StudyId() == aStudy->StudyId() )
1575 myStudyDocument = SALOMEDS::Study::_nil();
1580 //---------------------------------------------------------------
1583 ::ComponentDataType()
1585 return CORBA::string_dup("VISU");
1589 //---------------------------------------------------------------
1592 ::CanPublishInStudy(CORBA::Object_ptr theIOR)
1594 Result_var aResultObj = Result::_narrow(theIOR);
1595 return !(aResultObj->_is_nil());
1599 //---------------------------------------------------------------
1600 SALOMEDS::SObject_ptr
1602 ::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1603 SALOMEDS::SObject_ptr theSObject,
1604 CORBA::Object_ptr theObject,
1605 const char* theName)
1606 throw (SALOME::SALOME_Exception)
1608 Unexpect aCatch(SalomeException);
1609 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
1611 SALOMEDS::SObject_var aResultSO;
1612 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
1614 return aResultSO._retn();
1615 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1616 CORBA::String_var anEntry = aResultObj->Create((const char*)aFileInfo.absoluteFilePath().toLatin1())->GetID();
1617 aResultSO = theStudy->FindObjectID(anEntry);
1618 return aResultSO._retn();
1622 //---------------------------------------------------------------
1625 ::CanCopy(SALOMEDS::SObject_ptr theObject)
1627 CORBA::Object_var anObj = SObjectToObject(theObject);
1628 if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in()))
1629 return aStorable->CanCopy(theObject);
1635 //---------------------------------------------------------------
1638 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
1639 CORBA::Long& theObjectID)
1642 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
1644 CORBA::Object_var anObj = SObjectToObject(theObject);
1645 if (CORBA::is_nil(anObj)) {
1646 aStreamFile->length(1);
1647 aStreamFile[0] = CORBA::string_dup("E")[0];
1648 } else if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())) {
1649 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1650 Storable::TFileNames aFileNames;
1651 bool anIsDone = aStorable->CopyFrom(theObject, theObjectID, aTmpDir, aFileNames);
1653 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
1654 aListOfFileNames->length(aFileNames.size());
1655 for(size_t anId = 0; anId < aFileNames.size(); anId++)
1656 aListOfFileNames[anId] = aFileNames[anId].c_str();
1659 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFileNames.in(), false);
1661 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aListOfFileNames.in(), true);
1663 return aStreamFile._retn();
1667 //---------------------------------------------------------------
1670 ::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1671 // The VISU component can paste only objects copied by VISU component
1672 CORBA::String_var aString = ComponentDataType();
1673 if (strcmp(theComponentName, aString.in()) == 0 && theObjectID == 1)
1679 //---------------------------------------------------------------
1680 SALOMEDS::SObject_ptr
1682 ::PasteInto(const SALOMEDS::TMPFile& theStream,
1683 CORBA::Long theObjectID,
1684 SALOMEDS::SObject_ptr theSObject)
1686 if (theObjectID != 1)
1687 return SALOMEDS::SObject::_nil();
1689 SALOMEDS::SComponent_var aComponent = theSObject->GetFatherComponent();
1690 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1691 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1692 CORBA::String_var aComponentID(aComponent->GetID());
1693 CORBA::String_var aSObjectID(theSObject->GetID());
1695 SALOMEDS::SObject_var aSObject;
1696 if (strcmp(aComponentID, aSObjectID) == 0) //create the new result SObject
1697 aSObject = aStudyBuilder->NewObject(aComponent);
1699 aSObject = SALOMEDS::SObject::_duplicate(theSObject);
1701 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1702 SALOMEDS::ListOfFileNames_var aListOfFileNames =
1703 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1704 if(MYDEBUG) MESSAGE("Result_i::PasteInto - aListOfFileNames->length() = "<<aListOfFileNames->length());
1706 std::ostringstream aLocalPersistentID;
1708 std::string aCopyPersist = aTmpDir + "copy_persistent";
1709 std::ifstream anInputFileStream( aCopyPersist.c_str() );
1710 anInputFileStream >> aLocalPersistentID.rdbuf();
1713 //Just for Result::Restore to find the Comment attribute :(
1714 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
1716 std::string aFileName(aTmpDir);
1717 if(aListOfFileNames->length() > 1)
1718 aFileName += aListOfFileNames[1].in();
1719 Storable* aStorable = Storable::Create(aSObject, aLocalPersistentID.str(), aFileName, false);
1721 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
1722 aFilesToRemove->length(1);
1723 aFilesToRemove[0] = aListOfFileNames[0];
1724 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aFilesToRemove.in(), true);
1726 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
1727 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1728 CORBA::String_var anIORValue(aStorable->GetID());
1729 anIOR->SetValue(anIORValue);
1731 return aSObject._retn();
1735 //---------------------------------------------------------------
1736 VISU::ColoredPrs3dCache_ptr
1738 ::GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy)
1740 return ColoredPrs3dCache_i::GetInstance(theStudy);
1744 CORBA::Long VISU_Gen_i::CreateClippingPlane(CORBA::Double X,CORBA::Double Y, CORBA::Double Z,
1745 CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1746 CORBA::Boolean isAuto, const char* name)
1748 return myClippingPlaneMgr.CreateClippingPlane(X, Y, Z, dX, dY, dZ, isAuto, name);
1752 void VISU_Gen_i::EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double Y, CORBA::Double Z,
1753 CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ,
1754 CORBA::Boolean isAuto, const char* name)
1756 myClippingPlaneMgr.EditClippingPlane(id, X, Y, Z, dX, dY, dZ, isAuto, name);
1759 /* Returns clipping plane by its Id */
1760 VISU::ClippingPlane* VISU_Gen_i::GetClippingPlane(CORBA::Long id)
1762 VISU_CutPlaneFunction* aPlane = myClippingPlaneMgr.GetClippingPlane(id);
1764 if (aPlane != NULL) {
1767 aPlane->GetOrigin(aOrigin);
1768 aPlane->GetNormal(aDir);
1770 VISU::ClippingPlane* aRetPlane = new VISU::ClippingPlane;
1771 aRetPlane->X = aOrigin[0];
1772 aRetPlane->Y = aOrigin[1];
1773 aRetPlane->Z = aOrigin[2];
1774 aRetPlane->dX = aDir[0];
1775 aRetPlane->dY = aDir[1];
1776 aRetPlane->dZ = aDir[2];
1777 aRetPlane->isAuto = aPlane->isAuto();
1779 aRetPlane->name = aPlane->getName().c_str();
1785 /* Deletes clipping plane by its Id */
1786 CORBA::Boolean VISU_Gen_i::DeleteClippingPlane(CORBA::Long id)
1788 return myClippingPlaneMgr.DeleteClippingPlane(id);
1791 /* Applyes a clipping plane with Id to presentation thePrs */
1792 CORBA::Boolean VISU_Gen_i::ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1794 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1795 return myClippingPlaneMgr.ApplyClippingPlane(aPrs, id);
1798 /* Detaches a clipping plane with Id from presentation thePrs */
1799 CORBA::Boolean VISU_Gen_i::DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id)
1801 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(thePrs).in());
1802 return myClippingPlaneMgr.DetachClippingPlane(aPrs, id);
1805 /* Get number of clipping planes */
1806 CORBA::Long VISU_Gen_i::GetClippingPlanesNb()
1808 return myClippingPlaneMgr.GetClippingPlanesNb();
1812 \brief Converts set of VTK files to the one MED-file
1813 \param theVTKFiles sequence of VTK files
1814 \param theMEDFile MED-file
1815 \param theMeshName mesh name. This parameter can be empty. In this case name
1816 of mesh is equal vtk2med
1817 \param theTStamps values of time stamps. This array can be empty, in
1818 this case values of time stamps will be generated automatically ( 0, 1, 2 ... )
1819 \return TRUE if operation has been completed successfully, FALSE otherwise
1823 ::VTK2MED( const VISU::string_array& theVTKFiles,
1824 const char* theMEDFile,
1825 const char* theMeshName,
1826 const VISU::double_array& theTStamps )
1828 if ( !theMEDFile || !theVTKFiles.length() )
1831 VISU_Vtk2MedConvertor aConvertor;
1832 aConvertor.setMEDFileName( theMEDFile );
1833 // std::string aFirstFile = theVTKFiles[ 0 ];
1834 char* aFirstFile = CORBA::string_dup( theVTKFiles[ 0 ] );
1835 aConvertor.setFirstVTKFileName( aFirstFile );
1836 if ( theVTKFiles.length() > 1 )
1838 VISU_Vtk2MedConvertor::TVectorString aFiles( theVTKFiles.length() - 1 );
1839 for ( int i = 1, n = theVTKFiles.length(); i < n; i++ )
1840 aFiles[ i - 1 ] = theVTKFiles[ i ];
1841 aConvertor.setDataVTKFileNames( aFiles );
1843 if ( theTStamps.length() > 0 )
1845 VISU_Vtk2MedConvertor::TVectorDouble aTStamps( theTStamps.length() );
1846 for ( int i = 0, n = theTStamps.length(); i < n; i++ )
1847 aTStamps[ i ] = theTStamps[ i ];
1848 aConvertor.setTimeStamps( aTStamps );
1851 if ( theMeshName && strlen( theMeshName ) > 0 )
1852 aConvertor.setMeshName( theMeshName );
1854 aConvertor.addToIgnoringFieldList("cellID");
1855 aConvertor.setCellDataFieldNameIDS("cellID");
1857 int res = aConvertor.Execute();
1864 ::LoadTexture(const char* theTextureFile)
1866 if( CORBA::is_nil( myStudyDocument ) )
1869 int aStudyId = myStudyDocument->StudyId();
1871 VTK::MarkerTexture aMarkerTexture;
1872 if( !VTK::LoadTextureData( theTextureFile, VTK::MS_NONE, aMarkerTexture ) )
1875 VTK::MarkerMap& aMarkerMap = myMarkerMap[ aStudyId ];
1876 int aMarkerId = VTK::GetUniqueId( aMarkerMap );
1878 VTK::MarkerData& aMarkerData = aMarkerMap[ aMarkerId ];
1879 aMarkerData.first = theTextureFile;
1880 aMarkerData.second = aMarkerTexture;
1885 // Version information
1886 char* VISU_Gen_i::getVersion()
1888 #if VISU_DEVELOPMENT
1889 return CORBA::string_dup( VISU_VERSION_STR"dev" );
1891 return CORBA::string_dup( VISU_VERSION_STR );