1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VISU_Gen_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_Gen_i.hh"
28 #include "VISU_Result_i.hh"
29 #include "VISU_PrsObject_i.hh"
30 #include "VISU_ViewManager_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Mesh_i.hh"
34 #include "VISU_Table_i.hh"
35 #include "VISU_TimeAnimation.h"
37 #include "VISU_ColoredPrs3dFactory.hh"
38 #include "VISU_ColoredPrs3dCache_i.hh"
39 #include "VISU_ColoredPrs3dHolder_i.hh"
41 #include "VISU_Actor.h"
43 #include "HDFascii.hxx"
44 #include "SALOMEDS_Tool.hxx"
46 #include "SALOMEDSClient_AttributeName.hxx"
47 #include "SALOMEDSClient_AttributePixMap.hxx"
49 #include "SUIT_Session.h"
50 #include "SalomeApp_Study.h"
51 #include "SalomeApp_Application.h"
52 #include "LightApp_SelectionMgr.h"
53 #include "SVTK_ViewModel.h"
54 #include "SVTK_ViewWindow.h"
55 #include "SALOME_Event.hxx"
56 #include "SALOME_ListIO.hxx"
57 #include "SALOME_ListIteratorOfListIO.hxx"
59 #include "utilities.h"
62 #include <omnithread.h>
63 #include CORBA_SERVER_HEADER(SALOME_Session)
64 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
65 #include CORBA_SERVER_HEADER(MED_Gen)
69 #include <qfileinfo.h>
72 #include <vtkRenderer.h>
73 #include <vtkActorCollection.h>
76 #include <TCollection_AsciiString.hxx>
77 #include <TColStd_SequenceOfAsciiString.hxx>
79 #include "Utils_ExceptHandlers.hxx"
80 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
85 #include <boost/filesystem/path.hpp>
86 #include <boost/filesystem/operations.hpp>
87 namespace filesystem = boost::filesystem;
91 static int MYDEBUG = 0;
93 static int MYDEBUG = 0;
97 VISU_I_EXPORT VISU::VISU_Gen_ptr
98 GetImpl(CORBA::ORB_ptr theORB,
99 PortableServer::POA_ptr thePOA,
100 SALOME_NamingService* theNamingService,
103 if(MYDEBUG) MESSAGE("extern 'C' GetImpl");
104 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
105 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
106 return aVISU_Gen->_this();
111 //----------------------------------------------------------------------------
112 static std::string VISU_TMP_DIR;
114 static CORBA::Boolean myIsMultiFile;
115 const CORBA::Boolean IsMultiFile()
117 return myIsMultiFile;
120 //----------------------------------------------------------------------------
122 ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
124 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
126 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
127 aStudyBuilder->NewCommand();
128 int aLocked = theStudyDocument->GetProperties()->IsLocked();
129 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
130 aSComponent = aStudyBuilder->NewComponent("VISU");
131 _PTR(GenericAttribute) anAttr =
132 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
133 _PTR(AttributeName) aName (anAttr);
135 CORBA::ORB_var anORB = Base_i::GetORB();
136 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
137 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
138 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
139 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
140 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
141 if (!Comp->_is_nil()) {
142 aName->SetValue(Comp->componentusername());
145 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
146 _PTR(AttributePixMap) aPixmap (anAttr);
147 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
149 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
150 aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
151 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
152 aStudyBuilder->CommitCommand();
158 //----------------------------------------------------------------------------
159 SALOMEDS::SComponent_var
160 FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument)
162 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
163 if (aSComponent->_is_nil()) {
164 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
165 aStudyBuilder->NewCommand();
166 int aLocked = theStudyDocument->GetProperties()->IsLocked();
167 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
168 aSComponent = aStudyBuilder->NewComponent("VISU");
169 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
170 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
172 //NRI aName->SetValue("Visu");
173 CORBA::ORB_var anORB = Base_i::GetORB();
174 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
175 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
176 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
177 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
178 if ( !Comp->_is_nil() ) {
179 aName->SetValue( Comp->componentusername() );
182 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
183 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
184 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
186 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
187 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
188 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
189 aStudyBuilder->CommitCommand();
195 //----------------------------------------------------------------------------
199 Storable::RegistryStorableEngine(Result_i::myComment.c_str(),&(Result_i::StorableEngine));
201 Storable::RegistryStorableEngine(Mesh_i::myComment.c_str(),&(Mesh_i::StorableEngine));
203 Storable::RegistryStorableEngine(ScalarMap_i::myComment.c_str(),&(StorableEngine<ScalarMap_i>));
204 Storable::RegistryStorableEngine(GaussPoints_i::myComment.c_str(),&(StorableEngine<GaussPoints_i>));
205 Storable::RegistryStorableEngine(DeformedShape_i::myComment.c_str(),&(StorableEngine<DeformedShape_i>));
206 Storable::RegistryStorableEngine(CutPlanes_i::myComment.c_str(),&(StorableEngine<CutPlanes_i>));
207 Storable::RegistryStorableEngine(CutLines_i::myComment.c_str(),&(StorableEngine<CutLines_i>));
208 Storable::RegistryStorableEngine(IsoSurfaces_i::myComment.c_str(),&(StorableEngine<IsoSurfaces_i>));
209 Storable::RegistryStorableEngine(StreamLines_i::myComment.c_str(),&(StorableEngine<StreamLines_i>));
210 Storable::RegistryStorableEngine(Plot3D_i::myComment.c_str(),&(StorableEngine<Plot3D_i>));
211 Storable::RegistryStorableEngine(Vectors_i::myComment.c_str(),&(StorableEngine<Vectors_i>));
212 Storable::RegistryStorableEngine(ScalarMapOnDeformedShape_i::myComment.c_str(),&(StorableEngine<ScalarMapOnDeformedShape_i>));
214 Storable::RegistryStorableEngine(ColoredPrs3dHolder_i::myComment.c_str(),&(ColoredPrs3dHolder_i::StorableEngine));
215 Storable::RegistryStorableEngine(ColoredPrs3dCache_i::myComment.c_str(),&(ColoredPrs3dCache_i::StorableEngine));
217 Storable::RegistryStorableEngine(Table_i::myComment.c_str(),&(Table_i::StorableEngine));
218 Storable::RegistryStorableEngine(Curve_i::myComment.c_str(),&(Curve_i::StorableEngine));
219 Storable::RegistryStorableEngine(Container_i::myComment.c_str(),&(Container_i::StorableEngine));
223 //----------------------------------------------------------------------------
224 SALOMEDS::ListOfFileNames*
225 GetListOfFileNames(const Result_i::TFileNames& theFileNames)
227 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
228 if(!theFileNames.empty()){
229 aListOfFileNames->length(theFileNames.size());
230 for(int aCounter = theFileNames.size(); aCounter > 0; aCounter--)
231 aListOfFileNames[aCounter-1] = theFileNames[aCounter-1].c_str();
233 return aListOfFileNames._retn();
237 //----------------------------------------------------------------------------
239 ::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
240 SALOME_NamingService* theNamingService, QMutex* theMutex) :
241 Engines_Component_i()
243 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
244 Base_i::myMutex = theMutex; //apo
245 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
246 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
247 Base_i::myNamingService = theNamingService;
248 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
249 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
250 Base_i::myVisuGenImpl = this;
253 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
254 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
255 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
256 if(aListOfOpenStudies->length() > 0) {
257 CORBA::String_var aStudyName = aListOfOpenStudies[0];
258 //aFileInfo.setFile(aStudyName.in());
259 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
261 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
265 //----------------------------------------------------------------------------
268 ::CreatePrs3d(VISUType theType,
269 SALOMEDS::Study_ptr theStudy)
271 if(ColoredPrs3d_i* aPrs3d = CreatePrs3d_i(theType, theStudy, ColoredPrs3d_i::EPublishIndependently))
272 return aPrs3d->_this();
273 return Prs3d::_nil();
277 //----------------------------------------------------------------------------
281 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
285 //----------------------------------------------------------------------------
287 CorrectSObjectType(SALOMEDS::SObject_ptr theSObject,
288 SALOMEDS::StudyBuilder_ptr theBuilder)
290 SALOMEDS::GenericAttribute_var anAttr;
291 bool isAttrStringFound = false;
293 if( theSObject->FindAttribute(anAttr, "AttributeComment") ) {
294 //SRN: Replace an AttributeComment with AttributeString
295 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
296 string aValue = aComment->Value();
297 theBuilder->RemoveAttribute(theSObject, "AttributeComment");
298 anAttr = theBuilder->FindOrCreateAttribute(theSObject, "AttributeString");
299 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
300 aStringAttr->SetValue(aValue.c_str());
301 isAttrStringFound = true;
304 if ( isAttrStringFound || theSObject->FindAttribute(anAttr, "AttributeString") ) {
305 SALOMEDS::AttributeString_var aAttComment = SALOMEDS::AttributeString::_narrow(anAttr);
307 CORBA::String_var aValue = aAttComment->Value();
308 std::string aString = Storable::CorrectPersistentString(aValue.in());
309 aAttComment->SetValue( aString.c_str() );
315 //----------------------------------------------------------------------------
318 ::Load(SALOMEDS::SComponent_ptr theComponent,
319 const SALOMEDS::TMPFile & theStream,
321 CORBA::Boolean theIsMultiFile)
324 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
326 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
327 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
329 for (anIter->InitEx(true); anIter->More(); anIter->Next()) {
330 SALOMEDS::SObject_var aSObject = anIter->Value();
331 CorrectSObjectType(aSObject, aStudyBuilder);
335 VISU_TMP_DIR = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
336 SALOMEDS::ListOfFileNames_var aSeq =
337 SALOMEDS_Tool::PutStreamToFiles(theStream, VISU_TMP_DIR, theIsMultiFile);
338 myIsMultiFile = theIsMultiFile;
343 //----------------------------------------------------------------------------
346 ::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
347 const SALOMEDS::TMPFile & theStream,
351 return Load(theComponent, theStream, theURL, theIsMultiFile);
355 //----------------------------------------------------------------------------
358 ::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
359 const char* theLocalPersistentID,
360 CORBA::Boolean theIsMultiFile,
361 CORBA::Boolean theIsASCII)
363 CORBA::String_var aString("");
364 if(strcmp(theLocalPersistentID,"") != 0) {
365 Storable* aStorable = Storable::Create(theSObject,
366 theLocalPersistentID,
369 if(aStorable != NULL)
370 aString = aStorable->GetID();
372 return aString._retn();
376 //----------------------------------------------------------------------------
379 ::Save(SALOMEDS::SComponent_ptr theComponent,
383 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - theURL = '"<<theURL<<"'");
385 Result_i::TFileNames aFileNames;
386 Result_i::TFileNames aFiles;
388 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
389 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
390 for (; anIter->More(); anIter->Next()) {
391 SALOMEDS::SObject_var aSObject = anIter->Value();
392 CORBA::Object_var anObj = SObjectToObject(aSObject);
393 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
394 aResult->Save(theComponent,
402 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<<aFileNames.size());
404 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
405 if(aFileNames.empty())
406 return aStreamFile._retn();
408 SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
409 SALOMEDS::ListOfFileNames_var aListOfFiles = GetListOfFileNames(aFiles);
412 aStreamFile = SALOMEDS_Tool::PutFilesToStream(theURL, aListOfFiles.in(), theIsMultiFile);
414 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in());
416 return aStreamFile._retn();
420 //----------------------------------------------------------------------------
423 ::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
427 std::string anURL = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
428 if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - "<<anURL);
430 Result_i::TFileNames aFileNames;
431 Result_i::TFileNames aFiles;
433 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
434 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
435 for (; anIter->More(); anIter->Next()) {
436 SALOMEDS::SObject_var aSObject = anIter->Value();
437 CORBA::Object_var anObj = SObjectToObject(aSObject);
438 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
439 aResult->Save(theComponent,
447 if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - aFileNames.size() - "<<aFileNames.size());
449 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
450 if(aFileNames.empty())
451 return aStreamFile._retn();
453 SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
454 aStreamFile = SALOMEDS_Tool::PutFilesToStream(anURL, aListOfFileNames.in(), theIsMultiFile);
457 SALOMEDS_Tool::RemoveTemporaryFiles(anURL, aListOfFileNames, true);
459 return aStreamFile._retn();
463 //----------------------------------------------------------------------------
466 ::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
467 const char* theIORString,
468 CORBA::Boolean theIsMultiFile,
469 CORBA::Boolean theIsASCII)
471 CORBA::String_var aString("");
472 if(strcmp(theIORString, "") != 0){
473 CORBA::Object_var anObj = GetORB()->string_to_object(theIORString);
474 if(Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
475 aString = aStorable->ToString().c_str();
476 return aString._retn();
479 return aString._retn();
483 //----------------------------------------------------------------------------
488 return Base_i::GetID();
492 //----------------------------------------------------------------------------
495 ::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
497 class TEvent: public SALOME_Event {
498 std::string myStudyName;
500 TEvent(const std::string theStudyName):myStudyName(theStudyName)
502 virtual void Execute()
504 bool isActive = false;
505 SUIT_Session* aSession = SUIT_Session::session();
506 QPtrList<SUIT_Application> anApplications = aSession->applications();
507 QPtrListIterator<SUIT_Application> anIter (anApplications);
508 SUIT_Application* aFirstApp = anIter.current();
509 while (SUIT_Application* anApp = anIter.current()) {
511 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
512 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
513 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
514 if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = "
515 << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
516 if (myStudyName == aCStudy->Name()) {
525 MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
526 // Has to be loaded in an empty or in a new application
527 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
528 anApp->onLoadDoc(myStudyName.c_str());
533 if (!CORBA::is_nil(theStudy))
535 CORBA::String_var aName = theStudy->Name();
536 std::string aStudyName (aName.in());
537 if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
538 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
540 ProcessVoidEvent(new TEvent(aStudyName));
542 // Load MED component if necessary
543 if(!myStudyDocument->FindComponent("MED")->_is_nil())
545 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
546 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
547 SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow(aComponent);
549 if(!CORBA::is_nil(aMedEngine))
551 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
553 aStudyBuilder->LoadWith( myStudyDocument->FindComponent( "MED" ), aMedEngine );
555 catch( const SALOME::SALOME_Exception& ) {
556 // Oops, something went wrong while loading
557 // See also SalomeApp_Study::openDataModel()
562 INFOS("CORBA::is_nil(theStudy)");
567 //----------------------------------------------------------------------------
572 return SALOMEDS::Study::_duplicate(myStudyDocument);
576 //----------------------------------------------------------------------------
582 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
583 return ViewManager::_duplicate(aViewManager->_this());
587 //----------------------------------------------------------------------------
588 SALOMEDS::SObject_ptr
590 ::ImportTables(const char* theFileName)
592 if(myStudyDocument->GetProperties()->IsLocked())
593 return SALOMEDS::SObject::_nil();
594 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
599 //----------------------------------------------------------------------------
602 ::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
603 const char* theFileName)
605 return VISU::ExportTableToFile(theTable, theFileName);
609 //----------------------------------------------------------------------------
612 ::ImportFile(const char* theFileName)
614 if(myStudyDocument->GetProperties()->IsLocked())
615 return Result::_nil();
617 Result_i* aResult = Result_i::New(myStudyDocument,
619 Result_i::eImportFile,
625 if(aResult->Create(theFileName) != NULL)
626 return aResult->_this();
628 aResult->_remove_ref();
630 return VISU::Result::_nil();
634 //----------------------------------------------------------------------------
637 ::CreateResult(const char* theFileName)
639 if(myStudyDocument->GetProperties()->IsLocked())
640 return Result::_nil();
642 Result_i* aResult = Result_i::New(myStudyDocument,
644 Result_i::eImportFile,
650 if(aResult->Create(theFileName) != NULL)
651 return aResult->_this();
653 aResult->_remove_ref();
655 return VISU::Result::_nil();
659 //----------------------------------------------------------------------------
662 ::CopyAndImportFile(const char* theFileName)
664 if(myStudyDocument->GetProperties()->IsLocked())
665 return Result::_nil();
667 Result_i* aResult = Result_i::New(myStudyDocument,
668 Result_i::eRestoredFile,
669 Result_i::eCopyAndImportFile,
674 if(aResult->Create(theFileName) != NULL)
675 return aResult->_this();
677 aResult->_remove_ref();
679 return VISU::Result::_nil();
683 //----------------------------------------------------------------------------
684 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject)
686 if (myStudyDocument->GetProperties()->IsLocked())
687 return Result::_nil();
689 Result_i* aResult = Result_i::New(myStudyDocument,
690 Result_i::eComponent,
691 Result_i::eImportMed,
696 if (aResult->Create(theMedSObject) != NULL)
698 return aResult->_this();
701 aResult->_remove_ref();
703 return VISU::Result::_nil();
707 //----------------------------------------------------------------------------
710 ::ImportMedField (SALOME_MED::FIELD_ptr theField)
712 if (myStudyDocument->GetProperties()->IsLocked())
713 return Result::_nil();
715 Result_i* aResult = Result_i::New(myStudyDocument,
716 Result_i::eComponent,
717 Result_i::eImportMedField,
723 if (aResult->Create(theField) != NULL)
724 return aResult->_this();
726 aResult->_remove_ref();
728 return VISU::Result::_nil();
733 ::RenameMeshInStudy(Result_ptr theResult,
734 const std::string& theMeshName,
735 int theEntity, // -1 for group indication
736 const std::string& theSubMeshName, // Family or Group name
737 const std::string& theNewName)
739 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
743 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
744 if (aStudyDocument->GetProperties()->IsLocked())
749 VISU::VISUType aType;
751 if (theSubMeshName == "")
752 aType = VISU::TENTITY;
754 aType = VISU::TFAMILY;
756 aType = VISU::TGROUP;
758 VISU::Storable::TRestoringMap aRestoringMap;
759 aRestoringMap["myMeshName"] = theMeshName;
763 aRestoringMap["myComment"] = "ENTITY";
764 aRestoringMap["myId"] = QString::number(theEntity);
767 aRestoringMap["myComment"] = "FAMILY";
768 aRestoringMap["myEntityId"] = QString::number(theEntity);
769 aRestoringMap["myName"] = theSubMeshName;
772 aRestoringMap["myComment"] = "GROUP";
773 aRestoringMap["myName"] = theSubMeshName;
777 string anEntry = aResult->GetEntry(aRestoringMap);
781 SALOMEDS::SObject_ptr aSObject = aStudyDocument->FindObjectID(anEntry.c_str());
783 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
784 aStudyBuilder->NewCommand(); // There is a transaction
786 SALOMEDS::GenericAttribute_var anAttr =
787 aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
788 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
789 aNameAttr->SetValue(theNewName.c_str());
791 aStudyBuilder->CommitCommand();
795 //----------------------------------------------------------------------------
798 ::RenameEntityInStudy(Result_ptr theResult,
799 const char* theMeshName,
800 VISU::Entity theEntity,
801 const char* theNewName)
803 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, "", theNewName);
807 //----------------------------------------------------------------------------
810 ::RenameFamilyInStudy(Result_ptr theResult,
811 const char* theMeshName,
812 VISU::Entity theEntity,
813 const char* theFamilyName,
814 const char* theNewName)
816 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, theFamilyName, theNewName);
820 //----------------------------------------------------------------------------
823 ::RenameGroupInStudy(Result_ptr theResult,
824 const char* theMeshName,
825 const char* theGroupName,
826 const char* theNewName)
828 RenameMeshInStudy(theResult, theMeshName, -1, theGroupName, theNewName);
832 //----------------------------------------------------------------------------
835 ::MeshOnEntity(Result_ptr theResult,
836 const char* theMeshName,
837 VISU::Entity theEntity)
839 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
841 return VISU::Mesh::_nil();
843 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
844 if (aStudyDocument->GetProperties()->IsLocked())
845 return VISU::Mesh::_nil();
847 Mesh_i* aPresent = new Mesh_i();
848 if(aPresent->Create(aResult, theMeshName, theEntity))
849 return aPresent->_this();
851 aPresent->_remove_ref();
853 return VISU::Mesh::_nil();
857 //----------------------------------------------------------------------------
860 ::FamilyMeshOnEntity(Result_ptr theResult,
861 const char* theMeshName,
862 VISU::Entity theEntity,
863 const char* theFamilyName)
865 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
867 return VISU::Mesh::_nil();
869 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
870 if (aStudyDocument->GetProperties()->IsLocked())
871 return VISU::Mesh::_nil();
873 Mesh_i* aPresent = new Mesh_i();
874 if(aPresent->Create(aResult, theMeshName, theEntity, theFamilyName))
875 return aPresent->_this();
877 aPresent->_remove_ref();
879 return VISU::Mesh::_nil();
883 //----------------------------------------------------------------------------
886 ::GroupMesh(Result_ptr theResult,
887 const char* theMeshName,
888 const char* theGroupName)
890 Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
892 return VISU::Mesh::_nil();
894 SALOMEDS::Study_var aStudyDocument = aResult->GetStudyDocument();
895 if (aStudyDocument->GetProperties()->IsLocked())
896 return VISU::Mesh::_nil();
898 Mesh_i* aPresent = new Mesh_i();
899 if(aPresent->Create(aResult, theMeshName, theGroupName))
900 return aPresent->_this();
902 aPresent->_remove_ref();
904 return VISU::Mesh::_nil();
908 //----------------------------------------------------------------------------
911 ::ScalarMapOnField(Result_ptr theResult,
912 const char* theMeshName,
913 VISU::Entity theEntity,
914 const char* theFieldName,
915 CORBA::Long theIteration)
917 return Prs3dOnField<VISU::ScalarMap_i>(theResult,
921 theIteration)._retn();
925 //----------------------------------------------------------------------------
928 ::GaussPointsOnField(Result_ptr theResult,
929 const char* theMeshName,
930 VISU::Entity theEntity,
931 const char* theFieldName,
932 CORBA::Long theIteration)
934 return Prs3dOnField<VISU::GaussPoints_i>(theResult,
938 theIteration)._retn();
942 //---------------------------------------------------------------
945 ::DeformedShapeOnField(Result_ptr theResult,
946 const char* theMeshName,
947 VISU::Entity theEntity,
948 const char* theFieldName,
949 CORBA::Long theIteration)
951 return Prs3dOnField<VISU::DeformedShape_i>(theResult,
955 theIteration)._retn();
959 //---------------------------------------------------------------
960 ScalarMapOnDeformedShape_ptr
962 ::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
963 const char* theMeshName,
964 VISU::Entity theEntity,
965 const char* theFieldName,
966 CORBA::Long theIteration)
968 return Prs3dOnField<VISU::ScalarMapOnDeformedShape_i>(theResult,
972 theIteration)._retn();
976 //---------------------------------------------------------------
979 ::VectorsOnField(Result_ptr theResult,
980 const char* theMeshName,
981 VISU::Entity theEntity,
982 const char* theFieldName,
983 CORBA::Long theIteration)
985 return Prs3dOnField<VISU::Vectors_i>(theResult,
989 theIteration)._retn();
993 //---------------------------------------------------------------
996 ::IsoSurfacesOnField(Result_ptr theResult,
997 const char* theMeshName,
998 VISU::Entity theEntity,
999 const char* theFieldName,
1000 CORBA::Long theIteration)
1002 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,
1006 theIteration)._retn();
1010 //---------------------------------------------------------------
1013 ::StreamLinesOnField(Result_ptr theResult,
1014 const char* theMeshName,
1015 VISU::Entity theEntity,
1016 const char* theFieldName,
1017 CORBA::Long theIteration)
1019 return Prs3dOnField<VISU::StreamLines_i>(theResult,
1023 theIteration)._retn();
1027 //---------------------------------------------------------------
1030 ::Plot3DOnField(Result_ptr theResult,
1031 const char* theMeshName,
1032 VISU::Entity theEntity,
1033 const char* theFieldName,
1034 CORBA::Long theIteration)
1036 return Prs3dOnField<VISU::Plot3D_i>(theResult,
1040 theIteration)._retn();
1044 //---------------------------------------------------------------
1047 ::CutPlanesOnField(Result_ptr theResult,
1048 const char* theMeshName,
1049 VISU::Entity theEntity,
1050 const char* theFieldName,
1051 CORBA::Long theIteration)
1053 return Prs3dOnField<VISU::CutPlanes_i>(theResult,
1057 theIteration)._retn();
1061 //---------------------------------------------------------------
1064 ::CutLinesOnField(Result_ptr theResult,
1065 const char* theMeshName,
1066 VISU::Entity theEntity,
1067 const char* theFieldName,
1068 CORBA::Long theIteration)
1070 return Prs3dOnField<VISU::CutLines_i>(theResult,
1074 theIteration)._retn();
1078 //---------------------------------------------------------------
1079 struct CreateTableEvent: public SALOME_Event
1081 SALOMEDS::Study_var myStudyDocument;
1082 const char* myTableEntry;
1083 typedef Table_ptr TResult;
1086 CreateTableEvent(const SALOMEDS::Study_var& theStudy, const char* theTableEntry)
1088 myStudyDocument = theStudy;
1089 myTableEntry = theTableEntry;
1090 myResult = Table::_nil();
1097 Table_i* pPresent = new Table_i(myStudyDocument,myTableEntry);
1098 if(pPresent->Create() != NULL)
1099 myResult = pPresent->_this();
1101 pPresent->_remove_ref();
1102 myResult = VISU::Table::_nil();
1108 //---------------------------------------------------------------
1111 ::CreateTable(const char* theTableEntry)
1113 if(myStudyDocument->GetProperties()->IsLocked())
1114 return Table::_nil();
1116 return ProcessEvent(new CreateTableEvent(myStudyDocument, theTableEntry));
1120 //---------------------------------------------------------------
1123 ::CreateCurve(Table_ptr theTable,
1124 CORBA::Long theHRow,
1125 CORBA::Long theVRow)
1127 return CreateCurveWithZ( theTable, theHRow, theVRow, 0 );
1131 //---------------------------------------------------------------
1134 ::CreateCurveWithZ(Table_ptr theTable,
1135 CORBA::Long theHRow,
1136 CORBA::Long theVRow,
1137 CORBA::Long theZRow)
1139 if(myStudyDocument->GetProperties()->IsLocked())
1140 return Curve::_nil();
1142 PortableServer::POA_ptr aPOA = GetPOA();
1143 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
1144 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow,theZRow);
1145 if(pPresent->Create() != NULL)
1146 return pPresent->_this();
1148 pPresent->_remove_ref();
1149 return VISU::Curve::_nil();
1155 //---------------------------------------------------------------
1160 if(myStudyDocument->GetProperties()->IsLocked())
1161 return Container::_nil();
1163 Container_i* pPresent = new Container_i(myStudyDocument);
1164 if(pPresent->Create() != NULL)
1165 return pPresent->_this();
1167 pPresent->_remove_ref();
1168 return VISU::Container::_nil();
1173 //---------------------------------------------------------------
1176 ::CreateAnimation(View3D_ptr theView3D)
1178 if(myStudyDocument->GetProperties()->IsLocked())
1179 return Animation::_nil();
1181 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
1182 return anAnim->_this();
1184 return VISU::Animation::_nil();
1188 //---------------------------------------------------------------
1191 ::DeleteResult (Result_ptr theResult)
1193 theResult->RemoveFromStudy();
1197 //---------------------------------------------------------------
1200 ::DeletePrs3d(Prs3d_ptr thePrs3d)
1202 thePrs3d->RemoveFromStudy();
1206 //---------------------------------------------------------------
1209 ::Close(SALOMEDS::SComponent_ptr theComponent)
1213 //---------------------------------------------------------------
1216 ::ComponentDataType()
1218 return CORBA::string_dup("VISU");
1222 //---------------------------------------------------------------
1225 ::CanPublishInStudy(CORBA::Object_ptr theIOR)
1227 Result_var aResultObj = Result::_narrow(theIOR);
1228 return !(aResultObj->_is_nil());
1232 //---------------------------------------------------------------
1233 SALOMEDS::SObject_ptr
1235 ::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1236 SALOMEDS::SObject_ptr theSObject,
1237 CORBA::Object_ptr theObject,
1238 const char* theName)
1239 throw (SALOME::SALOME_Exception)
1241 Unexpect aCatch(SalomeException);
1242 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
1244 SALOMEDS::SObject_var aResultSO;
1245 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
1247 return aResultSO._retn();
1248 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
1249 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
1250 aResultSO = theStudy->FindObjectID(anEntry);
1251 return aResultSO._retn();
1255 //---------------------------------------------------------------
1258 ::CanCopy(SALOMEDS::SObject_ptr theObject)
1260 CORBA::Object_var anObj = SObjectToObject(theObject);
1261 if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in()))
1262 return aStorable->CanCopy(theObject);
1268 //---------------------------------------------------------------
1271 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
1272 CORBA::Long& theObjectID)
1275 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
1277 CORBA::Object_var anObj = SObjectToObject(theObject);
1278 if (CORBA::is_nil(anObj)) {
1279 aStreamFile->length(1);
1280 aStreamFile[0] = CORBA::string_dup("E")[0];
1281 } else if (Storable* aStorable = dynamic_cast<Storable*>(GetServant(anObj).in())) {
1282 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1283 Storable::TFileNames aFileNames;
1284 bool anIsDone = aStorable->CopyFrom(theObject, theObjectID, aTmpDir, aFileNames);
1286 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
1287 aListOfFileNames->length(aFileNames.size());
1288 for(size_t anId = 0; anId < aFileNames.size(); anId++)
1289 aListOfFileNames[anId] = aFileNames[anId].c_str();
1292 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFileNames.in(), false);
1294 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aListOfFileNames.in(), true);
1296 return aStreamFile._retn();
1300 //---------------------------------------------------------------
1303 ::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1304 // The VISU component can paste only objects copied by VISU component
1305 CORBA::String_var aString = ComponentDataType();
1306 if (strcmp(theComponentName, aString.in()) == 0 && theObjectID == 1)
1312 //---------------------------------------------------------------
1313 SALOMEDS::SObject_ptr
1315 ::PasteInto(const SALOMEDS::TMPFile& theStream,
1316 CORBA::Long theObjectID,
1317 SALOMEDS::SObject_ptr theSObject)
1319 if (theObjectID != 1)
1320 return SALOMEDS::SObject::_nil();
1322 SALOMEDS::SComponent_var aComponent = theSObject->GetFatherComponent();
1323 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1324 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1325 CORBA::String_var aComponentID(aComponent->GetID());
1326 CORBA::String_var aSObjectID(theSObject->GetID());
1328 SALOMEDS::SObject_var aSObject;
1329 if (strcmp(aComponentID, aSObjectID) == 0) //create the new result SObject
1330 aSObject = aStudyBuilder->NewObject(aComponent);
1332 aSObject = SALOMEDS::SObject::_duplicate(theSObject);
1334 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1335 SALOMEDS::ListOfFileNames_var aListOfFileNames =
1336 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
1337 if(MYDEBUG) MESSAGE("Result_i::PasteInto - aListOfFileNames->length() = "<<aListOfFileNames->length());
1339 std::string aLocalPersistentID;
1341 std::string aCopyPersist = aTmpDir + "copy_persistent";
1342 std::ifstream anInputFileStream(aCopyPersist.c_str());
1343 anInputFileStream>>aLocalPersistentID;
1344 anInputFileStream.close();
1347 //Just for Result::Restore to find the Comment attribute :(
1348 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeString");
1350 std::string aFileName(aTmpDir);
1351 if(aListOfFileNames->length() > 1)
1352 aFileName += aListOfFileNames[1].in();
1353 Storable* aStorable = Storable::Create(aSObject, aLocalPersistentID, aFileName, false);
1355 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
1356 aFilesToRemove->length(1);
1357 aFilesToRemove[0] = aListOfFileNames[0];
1358 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aFilesToRemove.in(), true);
1360 anAttr = aStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
1361 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1362 CORBA::String_var anIORValue(aStorable->GetID());
1363 anIOR->SetValue(anIORValue);
1365 return aSObject._retn();
1369 //---------------------------------------------------------------
1370 VISU::ColoredPrs3dCache_ptr
1372 ::GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy)
1374 return ColoredPrs3dCache_i::GetInstance(theStudy);