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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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_ScalarMap_i.hh"
35 #include "VISU_IsoSurfaces_i.hh"
36 #include "VISU_DeformedShape_i.hh"
37 #include "VISU_CutPlanes_i.hh"
38 #include "VISU_CutLines_i.hh"
39 #include "VISU_Vectors_i.hh"
40 #include "VISU_StreamLines_i.hh"
41 #include "VISU_Table_i.hh"
42 #include "VISU_TimeAnimation.h"
44 #include "VISU_Actor.h"
46 #include "HDFascii.hxx"
47 #include "SALOMEDS_Tool.hxx"
49 #include "SALOMEDSClient_AttributeName.hxx"
50 #include "SALOMEDSClient_AttributePixMap.hxx"
52 #include "SUIT_Session.h"
53 #include "SalomeApp_Study.h"
54 #include "SalomeApp_Application.h"
55 #include "SalomeApp_SelectionMgr.h"
56 #include "SVTK_ViewModel.h"
57 #include "SVTK_ViewWindow.h"
58 #include "SALOME_Event.hxx"
59 #include "SALOME_ListIO.hxx"
60 #include "SALOME_ListIteratorOfListIO.hxx"
62 #include "utilities.h"
65 #include <omnithread.h>
66 #include CORBA_SERVER_HEADER(SALOME_Session)
67 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
71 #include <qfileinfo.h>
74 #include <vtkRenderer.h>
75 #include <vtkActorCollection.h>
78 #include <TCollection_AsciiString.hxx>
79 #include <TColStd_SequenceOfAsciiString.hxx>
84 #include "Utils_ExceptHandlers.hxx"
88 static QFileInfo aFileInfo;
91 static int MYDEBUG = 1;
93 static int MYDEBUG = 0;
96 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
98 extern "C" VISU::VISU_Gen_ptr 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();
110 static string VisuTmpDir;
112 static CORBA::Boolean myIsMultiFile;
113 const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
115 //===========================================================================
116 _PTR(SComponent) ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
118 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
120 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
121 aStudyBuilder->NewCommand();
122 int aLocked = theStudyDocument->GetProperties()->IsLocked();
123 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
124 aSComponent = aStudyBuilder->NewComponent("VISU");
125 _PTR(GenericAttribute) anAttr =
126 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
127 _PTR(AttributeName) aName (anAttr);
129 CORBA::ORB_var anORB = Base_i::GetORB();
130 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
131 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
132 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
133 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
134 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
135 if (!Comp->_is_nil()) {
136 aName->SetValue(Comp->componentusername());
139 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
140 _PTR(AttributePixMap) aPixmap (anAttr);
141 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
143 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
144 aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
145 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
146 aStudyBuilder->CommitCommand();
151 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
152 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
153 if (aSComponent->_is_nil()) {
154 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
155 aStudyBuilder->NewCommand();
156 int aLocked = theStudyDocument->GetProperties()->IsLocked();
157 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
158 aSComponent = aStudyBuilder->NewComponent("VISU");
159 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
160 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
162 //NRI aName->SetValue("Visu");
163 CORBA::ORB_var anORB = Base_i::GetORB();
164 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
165 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
166 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
167 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
168 if ( !Comp->_is_nil() ) {
169 aName->SetValue( Comp->componentusername() );
172 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
173 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
174 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
176 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
177 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
178 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
179 aStudyBuilder->CommitCommand();
184 void RegistryStorable() {
185 Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore));
186 Storable::Registry(Mesh_i::myComment.c_str(),&(Restore<Mesh_i>));
187 Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore<ScalarMap_i>));
188 Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore<DeformedShape_i>));
189 Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore<CutPlanes_i>));
190 Storable::Registry(CutLines_i::myComment.c_str(),&(Restore<CutLines_i>));
191 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore<IsoSurfaces_i>));
192 Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore<StreamLines_i>));
193 Storable::Registry(Vectors_i::myComment.c_str(),&(Restore<Vectors_i>));
194 Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore));
195 Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore));
196 Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore));
200 //===========================================================================
201 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
202 SALOME_NamingService* theNamingService, QMutex* theMutex) :
203 Engines_Component_i()
205 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
206 Base_i::myMutex = theMutex; //apo
207 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
208 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
209 Base_i::myNamingService = theNamingService;
210 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
211 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
212 Base_i::myVisuGenImpl = this;
215 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
216 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
217 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
218 if(aListOfOpenStudies->length() > 0) {
219 CORBA::String_var aStudyName = aListOfOpenStudies[0];
220 //aFileInfo.setFile(aStudyName.in());
221 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
223 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
226 VISU_Gen_i::~VISU_Gen_i(){
227 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
229 //===========================================================================
230 CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
231 const SALOMEDS::TMPFile & theStream,
236 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
237 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
238 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
239 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
240 VisuTmpDir = aTmpDir.ToCString();
241 SALOMEDS::ListOfFileNames_var aSeq =
242 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
243 myIsMultiFile = isMultiFile;
247 CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
248 const SALOMEDS::TMPFile & theStream,
252 return Load(theComponent, theStream, theURL, isMultiFile);
255 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
256 const char* aLocalPersistentID,
257 CORBA::Boolean isMultiFile,
258 CORBA::Boolean isASCII)
260 CORBA::String_var aString("");
261 if(strcmp(aLocalPersistentID,"") != 0) {
263 Storable* aStorable =
264 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
265 if(aStorable != NULL) aString = aStorable->GetID();
267 return aString._retn();
269 //===========================================================================
270 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
275 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
276 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
277 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
279 TColStd_SequenceOfAsciiString aFileNames;
280 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
282 //CORBA::Boolean anIsValidScript;
283 //Engines::TMPFile_var aDump = DumpPython(aStudy,false,anIsValidScript);
285 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
286 for (; itBig->More(); itBig->Next()) {
287 SALOMEDS::SObject_var gotBranch = itBig->Value();
288 CORBA::Object_var anObj = SObjectToObject(gotBranch);
289 if(CORBA::is_nil(anObj)) continue;
290 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
291 switch(pResult->GetCreationId()){
292 case Result_i::eImportFile:
293 case Result_i::eCopyAndImportFile: {
294 const QFileInfo& aFileInfo = pResult->GetFileInfo();
296 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
297 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
298 static QString aCommand;
299 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
301 int aRes = system(aCommand);
303 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
306 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aCommand = "<<aCommand);
308 TCollection_AsciiString aString(strdup(aFileName.latin1()));
309 aFileNames.Append(aString);
313 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
314 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
315 if(aFileNames.Length() > 0){
316 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
317 aSeq->length(aFileNames.Length());
318 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
319 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
320 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
322 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
324 return aStreamFile._retn();
327 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
332 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
333 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
334 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
336 TColStd_SequenceOfAsciiString aFileNames;
337 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
338 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
339 for (; itBig->More(); itBig->Next()) {
340 SALOMEDS::SObject_var gotBranch = itBig->Value();
341 CORBA::Object_var anObj = SObjectToObject(gotBranch);
342 if(CORBA::is_nil(anObj)) continue;
343 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
344 switch(pResult->GetCreationId()){
345 case Result_i::eImportFile:
346 case Result_i::eCopyAndImportFile: {
347 const QFileInfo& aFileInfo = pResult->GetFileInfo();
349 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
350 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
351 static QString aCommand;
352 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
354 int aRes = system(aCommand);
356 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Can't execute the command :"<<aCommand);
359 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
361 TCollection_AsciiString aString(strdup(aFileName.latin1()));
363 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
365 aFileNames.Append(aString);
369 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
370 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
371 if(aFileNames.Length() > 0){
372 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
373 aSeq->length(aFileNames.Length());
374 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
375 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
376 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
378 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
380 return aStreamFile._retn();
383 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
384 const char* IORString,
385 CORBA::Boolean isMultiFile,
386 CORBA::Boolean isASCII)
388 CORBA::String_var aString(IORString);
389 if(strcmp(IORString,"") != 0){
390 CORBA::ORB_ptr anORB = GetORB();
391 CORBA::Object_var anObj = anORB->string_to_object(aString);
392 if(!CORBA::is_nil(anObj)){
393 if(Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
395 aString = pStorable->ToString().c_str();
396 return aString._retn();
400 return aString._retn();
403 char* VISU_Gen_i::GetID(){
404 return Base_i::GetID();
407 void VISU_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy)
409 if (!CORBA::is_nil(theStudy))
411 CORBA::String_var aName = theStudy->Name();
412 QString aStudyName (aName.in());
413 MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
414 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
416 bool isActive = false;
417 SUIT_Session* aSession = SUIT_Session::session();
418 QPtrList<SUIT_Application> anApplications = aSession->applications();
419 QPtrListIterator<SUIT_Application> anIter (anApplications);
420 SUIT_Application* aFirstApp = anIter.current();
421 while (SUIT_Application* anApp = anIter.current()) {
423 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
424 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
425 MESSAGE("There is an application with active study : " << aStudy->studyName());
426 if (aStudyName == aStudy->studyName()) {
434 MESSAGE("!!! anApp->onLoadDoc(aName.in()) !!!");
435 // Has to be loaded in an empty or in a new application
436 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
437 anApp->onLoadDoc(aName.in());
440 MESSAGE("CORBA::is_nil(theStudy)");
444 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
445 return SALOMEDS::Study::_duplicate(myStudyDocument);
448 ViewManager_ptr VISU_Gen_i::GetViewManager(){
450 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
451 return ViewManager::_duplicate(aViewManager->_this());
454 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
455 if(myStudyDocument->GetProperties()->IsLocked())
456 return SALOMEDS::SObject::_nil();
458 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
462 CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
463 const char* theFileName)
465 return VISU::ExportTableToFile(theTable, theFileName);
468 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
469 if(myStudyDocument->GetProperties()->IsLocked())
470 return Result::_nil();
472 aFileInfo.setFile(theFileName);
473 Result_i* pResult = new Result_i(myStudyDocument,
475 Result_i::eImportFile);
476 if(pResult->Create(theFileName) != NULL)
477 return pResult->_this();
479 pResult->_remove_ref();
480 return VISU::Result::_nil();
484 Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){
485 if(myStudyDocument->GetProperties()->IsLocked())
486 return Result::_nil();
488 VISU::Result_var aResult;
489 aFileInfo.setFile(theFileName);
490 Result_i* pResult = new Result_i(myStudyDocument,
491 Result_i::eRestoredFile,
492 Result_i::eCopyAndImportFile);
493 if(pResult->Create(theFileName) != NULL)
494 aResult = pResult->_this();
495 return aResult._retn();
498 Result_ptr VISU_Gen_i::ClientImportMed (_PTR(SObject) theMedSObject)
500 SALOMEDS::SObject_ptr aMedSObject = GetSObject(theMedSObject);
501 return ImportMed(aMedSObject);
504 Result_ptr VISU_Gen_i::ImportMed (SALOMEDS::SObject_ptr theMedSObject)
506 if (myStudyDocument->GetProperties()->IsLocked())
507 return Result::_nil();
509 Result_i* pResult = new Result_i(myStudyDocument,
510 Result_i::eComponent,
511 Result_i::eImportMed);
512 if (pResult->Create(theMedSObject) != NULL) {
513 return pResult->_this();
515 pResult->_remove_ref();
516 return VISU::Result::_nil();
520 Result_ptr VISU_Gen_i::ImportMedField (SALOME_MED::FIELD_ptr theField)
522 if (myStudyDocument->GetProperties()->IsLocked())
523 return Result::_nil();
525 Result_i* pResult = new Result_i(myStudyDocument,
526 Result_i::eComponent,
527 Result_i::eImportMedField);
528 if (pResult->Create(theField) != NULL) {
529 return pResult->_this();
531 pResult->_remove_ref();
532 return VISU::Result::_nil();
536 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult,
537 const char* theMeshName,
538 VISU::Entity theEntity)
540 if(myStudyDocument->GetProperties()->IsLocked())
543 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
544 Mesh_i* aPresent = new Mesh_i(pResult);
545 if(aPresent->Create(theMeshName,theEntity) != NULL)
546 return aPresent->_this();
548 aPresent->_remove_ref();
551 return VISU::Mesh::_nil();
554 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult,
555 const char* theMeshName,
556 VISU::Entity theEntity,
557 const char* theFamilyName)
559 if(myStudyDocument->GetProperties()->IsLocked())
562 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
563 Mesh_i* aPresent = new Mesh_i(pResult);
564 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
565 return aPresent->_this();
567 aPresent->_remove_ref();
570 return VISU::Mesh::_nil();
573 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult,
574 const char* theMeshName,
575 const char* theGroupName)
577 if(myStudyDocument->GetProperties()->IsLocked())
580 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
581 Mesh_i* aPresent = new Mesh_i(pResult);
582 if(aPresent->Create(theMeshName,theGroupName) != NULL)
583 return aPresent->_this();
585 aPresent->_remove_ref();
588 return VISU::Mesh::_nil();
591 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult,
592 const char* theMeshName,
593 VISU::Entity theEntity,
594 const char* theFieldName,
595 CORBA::Double theIteration)
597 return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
600 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult,
601 const char* theMeshName,
602 VISU::Entity theEntity,
603 const char* theFieldName,
604 CORBA::Double theIteration)
606 return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
609 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult,
610 const char* theMeshName,
611 VISU::Entity theEntity,
612 const char* theFieldName,
613 CORBA::Double theIteration)
615 return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
618 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult,
619 const char* theMeshName,
620 VISU::Entity theEntity,
621 const char* theFieldName,
622 CORBA::Double theIteration)
624 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
627 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult,
628 const char* theMeshName,
629 VISU::Entity theEntity,
630 const char* theFieldName,
631 CORBA::Double theIteration)
633 return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
636 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult,
637 const char* theMeshName,
638 VISU::Entity theEntity,
639 const char* theFieldName,
640 CORBA::Double theIteration)
642 return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
645 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult,
646 const char* theMeshName,
647 VISU::Entity theEntity,
648 const char* theFieldName,
649 CORBA::Double theIteration)
651 return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
654 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
655 if(myStudyDocument->GetProperties()->IsLocked())
656 return Table::_nil();
658 Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry);
659 if(pPresent->Create() != NULL)
660 return pPresent->_this();
662 pPresent->_remove_ref();
663 return VISU::Table::_nil();
667 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable,
671 if(myStudyDocument->GetProperties()->IsLocked())
672 return Curve::_nil();
674 PortableServer::POA_ptr aPOA = GetPOA();
675 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
676 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
677 if(pPresent->Create() != NULL)
678 return pPresent->_this();
680 pPresent->_remove_ref();
681 return VISU::Curve::_nil();
685 Container_ptr VISU_Gen_i::CreateContainer(){
686 if(myStudyDocument->GetProperties()->IsLocked())
687 return Container::_nil();
689 Container_i* pPresent = new Container_i(myStudyDocument);
690 if(pPresent->Create() != NULL)
691 return pPresent->_this();
693 pPresent->_remove_ref();
694 return VISU::Container::_nil();
698 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
699 if(myStudyDocument->GetProperties()->IsLocked())
700 return Animation::_nil();
702 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
703 return anAnim->_this();
705 return VISU::Animation::_nil();
708 void DeletePrs3d (Prs3d_ptr thePrs3d)
710 Prs3d_i* aPrs3d = dynamic_cast<Prs3d_i*>(GetServant(thePrs3d).in());
714 // 1. Find appropriate application (code like in VISU_ViewManager_i.cxx)
715 SALOMEDS::Study_var myStudyDocument = aPrs3d->GetStudyDocument();
716 SalomeApp_Application* anApp = NULL;
717 CORBA::String_var studyName = myStudyDocument->Name();
718 std::string aStudyName = studyName.in();
719 SUIT_Session* aSession = SUIT_Session::session();
720 QPtrList<SUIT_Application> anApplications = aSession->applications();
721 QPtrListIterator<SUIT_Application> anIter (anApplications);
722 while (SUIT_Application* aSUITApp = anIter.current()) {
724 if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) {
725 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
726 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
727 if (aStudyName == aCStudy->Name()) {
728 anApp = dynamic_cast<SalomeApp_Application*>(aSUITApp);
738 // 2. Remove corresponding IO from selection
739 SALOMEDS::SObject_var aSObject = aPrs3d->GetSObject();
740 CORBA::String_var anEntry = aSObject->GetID();
742 SalomeApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
743 SALOME_ListIO aListIO, aNewListIO;
744 aSelectionMgr->selectedObjects(aListIO);
746 for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) {
747 if (it.Value()->hasEntry()) {
748 std::string aCurEntry (it.Value()->getEntry());
749 if (aCurEntry != anEntry) {
750 aNewListIO.Append(it.Value());
755 aSelectionMgr->setSelectedObjects(aNewListIO);
758 ViewManagerList aViewManagerList;
759 anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList);
760 QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
761 for (; anVMIter.current(); ++anVMIter) {
762 SUIT_ViewManager* aViewManager = anVMIter.current();
763 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
764 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
765 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
766 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
767 //VISU_Actor* anActor = aVISUViewManager->GetActor(aPrs3d, vw);
768 VISU_Actor* anActor = NULL;
769 vtkActorCollection *anActColl = vw->getRenderer()->GetActors();
770 anActColl->InitTraversal();
771 vtkActor *aVTKActor = anActColl->GetNextActor();
772 for (; !anActor && aVTKActor; aVTKActor = anActColl->GetNextActor()) {
773 if (VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(aVTKActor)) {
774 if (aPrs3d == anVISUActor->GetPrs3d()) {
775 anActor = anVISUActor->GetParent();
780 vw->RemoveActor(anActor);
788 aPrs3d->RemoveFromStudy();
791 //jfa tmp:theModule->updateObjBrowser(); //update Object browser
794 void VISU_Gen_i::DeleteResult (Result_ptr theResult)
796 class TEvent: public SALOME_Event {
799 TEvent(Result_ptr theResult): myResult(theResult) {}
800 virtual void Execute(){
801 if (Result_i* aResult = dynamic_cast<Result_i*>(GetServant(myResult).in())) {
802 SALOMEDS::SObject_var aSObject = aResult->GetSObject();
803 SALOMEDS::Study_var aStudyDocument = aSObject->GetStudy();
804 SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(aSObject);
805 for(aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()){
806 SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
807 CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
808 if(CORBA::is_nil(aChildObj)) continue;
809 VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aChildObj);
810 if(CORBA::is_nil(aPrs3d)) continue;
811 VISU::DeletePrs3d(aPrs3d);
814 aResult->RemoveFromStudy();
817 //jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop())
818 //jfa tmp: if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument))
819 //jfa tmp: aStudy->updateObjBrowser(); //update Object browser
824 if (myStudyDocument->GetProperties()->IsLocked())
826 Mutex mt(myMutex); // jfa ???
828 ProcessVoidEvent(new TEvent(theResult));
831 void VISU_Gen_i::DeletePrs3d (Prs3d_ptr thePrs3d)
833 class TEvent: public SALOME_Event {
836 TEvent(Prs3d_ptr thePrs3d): myPrs3d(thePrs3d) {}
837 virtual void Execute() {
838 VISU::DeletePrs3d(myPrs3d);
842 if (myStudyDocument->GetProperties()->IsLocked())
844 Mutex mt(myMutex); // jfa ???
846 ProcessVoidEvent(new TEvent(thePrs3d));
849 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
852 char* VISU_Gen_i::ComponentDataType(){
853 return CORBA::string_dup("VISU");
856 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
857 Result_var aResultObj = Result::_narrow(theIOR);
858 return !(aResultObj->_is_nil());
861 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
862 SALOMEDS::SObject_ptr theSObject,
863 CORBA::Object_ptr theObject,
865 throw (SALOME::SALOME_Exception)
867 Unexpect aCatch(SalomeException);
868 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
870 SALOMEDS::SObject_var aResultSO;
871 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
872 if (!aResultObj) return aResultSO._retn();
873 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
874 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
875 aResultSO = theStudy->FindObjectID(anEntry);
876 return aResultSO._retn();
879 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
881 SALOMEDS::GenericAttribute_var anAttr;
882 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
884 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
885 CORBA::String_var aValue = anIOR->Value();
886 if(strcmp(aValue,"") != 0){
887 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
888 if (!CORBA::is_nil(anObj)){
889 Result_var aResultObj = Result::_narrow(anObj);
890 if(!aResultObj->_is_nil()){
891 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj).in())){
892 switch(pResult->GetCreationId()){
893 case Result_i::eImportFile:
894 case Result_i::eCopyAndImportFile:
901 }catch(std::exception& exc){
902 INFOS("Follow exception was occured :\n"<<exc.what());
904 INFOS("Unknown exception was occured!");
909 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
912 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
913 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
915 PortableServer::POA_ptr aPOA = GetPOA();
917 SALOMEDS::GenericAttribute_var anAttr;
918 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
919 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
920 CORBA::Object_var aCorbaObj;
922 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
924 aStreamFile->length(1);
925 aStreamFile[0] = strdup("E")[0];
926 return aStreamFile._retn();
928 if (CORBA::is_nil(aCorbaObj)) {
932 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj).in());
937 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
938 string aCopyPersist = aTmpDir + "copy_persistent";
940 ofstream stmOut2(aCopyPersist.c_str(),ios::out);
941 string aStr = pStorable->ToString().c_str();
945 if (Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj))) {
946 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
947 if(strlen(aFileName.c_str()) == 1) aFileName="";
948 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
949 aFileName += aFileInfo.fileName().latin1();
950 static QString aCommand;
951 string aFullFileName = aTmpDir + aFileName;
952 aCommand.sprintf("cp %s %s",
953 aFileInfo.filePath().latin1(),
954 aFullFileName.c_str());
955 if(system(aCommand) == -1) {
956 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
960 aSeq[0] = "copy_persistent";
961 aSeq[1] = aFileName.c_str();
964 aSeq[0] = "copy_persistent";
967 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false);
968 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
970 // Assign an ID = 1 the the type VISU::Result
974 SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
975 return aStreamFile._retn();
978 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
979 // The VISU component can paste only objects copied by VISU component
980 // and with the object type = 1
981 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1)
986 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
987 CORBA::Long theObjectID,
988 SALOMEDS::SObject_ptr theObject)
991 SALOMEDS::SObject_var aResultSO;
992 if (theObjectID != 1)
993 return aResultSO._retn();
995 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
996 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false);
998 ifstream stmIn((aTmpDir + string("copy_persistent")).c_str());
999 stmIn.seekg(0, ios::end);
1000 int aLength = stmIn.tellg();
1001 stmIn.seekg(0, ios::beg);
1002 char* aString = new char[aLength+1];
1003 stmIn.read(aString, aLength);
1004 aString[aLength] = 0;
1005 myIsMultiFile = false;
1007 string aFileName(aTmpDir);
1008 string aBasicFileName;
1009 if(aSeq->length() > 1) {
1010 aBasicFileName = aSeq[1].in();
1011 aFileName += aBasicFileName;
1014 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
1015 SALOMEDS::Study_var aStudy = theObject->GetStudy();
1016 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1017 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
1019 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
1020 aResultSO = aStudyBuilder->NewObject(aComponent);
1022 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
1024 //Just for Result::Restore to find the Comment attribute :(
1025 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
1027 Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
1029 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
1030 aSeqToRm->length(1);
1031 aSeqToRm[0] = "copy_persistent";
1033 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true);
1035 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1036 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1037 CORBA::String_var anIORValue(aStorable->GetID());
1038 anIOR->SetValue(anIORValue);
1039 return aResultSO._retn();