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_GaussPoints_i.hh"
42 #include "VISU_Plot3D_i.hh"
43 #include "VISU_Table_i.hh"
44 #include "VISU_TimeAnimation.h"
45 #include "VISU_ScalarMapOnDeformedShape_i.hh"
47 #include "VISU_Actor.h"
49 #include "HDFascii.hxx"
50 #include "SALOMEDS_Tool.hxx"
52 #include "SALOMEDSClient_AttributeName.hxx"
53 #include "SALOMEDSClient_AttributePixMap.hxx"
55 #include "SUIT_Session.h"
56 #include "SalomeApp_Study.h"
57 #include "SalomeApp_Application.h"
58 #include "LightApp_SelectionMgr.h"
59 #include "SVTK_ViewModel.h"
60 #include "SVTK_ViewWindow.h"
61 #include "SALOME_Event.hxx"
62 #include "SALOME_ListIO.hxx"
63 #include "SALOME_ListIteratorOfListIO.hxx"
65 #include "utilities.h"
68 #include <omnithread.h>
69 #include CORBA_SERVER_HEADER(SALOME_Session)
70 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
74 #include <qfileinfo.h>
77 #include <vtkRenderer.h>
78 #include <vtkActorCollection.h>
81 #include <TCollection_AsciiString.hxx>
82 #include <TColStd_SequenceOfAsciiString.hxx>
87 #include "Utils_ExceptHandlers.hxx"
91 static QFileInfo aFileInfo;
94 static int MYDEBUG = 0;
97 static int MYDEBUG = 0;
100 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
102 extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB,
103 PortableServer::POA_ptr thePOA,
104 SALOME_NamingService* theNamingService,
107 if(MYDEBUG) MESSAGE("extern \"C\" GetImpl");
108 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
109 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
110 return aVISU_Gen->_this();
115 static string VisuTmpDir;
117 static CORBA::Boolean myIsMultiFile;
118 const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
120 //===========================================================================
121 _PTR(SComponent) ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
123 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
125 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
126 aStudyBuilder->NewCommand();
127 int aLocked = theStudyDocument->GetProperties()->IsLocked();
128 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
129 aSComponent = aStudyBuilder->NewComponent("VISU");
130 _PTR(GenericAttribute) anAttr =
131 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
132 _PTR(AttributeName) aName (anAttr);
134 CORBA::ORB_var anORB = Base_i::GetORB();
135 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
136 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
137 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
138 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
139 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
140 if (!Comp->_is_nil()) {
141 aName->SetValue(Comp->componentusername());
144 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
145 _PTR(AttributePixMap) aPixmap (anAttr);
146 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
148 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
149 aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
150 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
151 aStudyBuilder->CommitCommand();
156 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
157 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
158 if (aSComponent->_is_nil()) {
159 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
160 aStudyBuilder->NewCommand();
161 int aLocked = theStudyDocument->GetProperties()->IsLocked();
162 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
163 aSComponent = aStudyBuilder->NewComponent("VISU");
164 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
165 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
167 //NRI aName->SetValue("Visu");
168 CORBA::ORB_var anORB = Base_i::GetORB();
169 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
170 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
171 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
172 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
173 if ( !Comp->_is_nil() ) {
174 aName->SetValue( Comp->componentusername() );
177 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
178 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
179 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
181 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
182 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
183 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
184 aStudyBuilder->CommitCommand();
189 void RegistryStorable() {
190 Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore));
191 Storable::Registry(Mesh_i::myComment.c_str(),&(Restore<Mesh_i>));
192 Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore<ScalarMap_i>));
193 Storable::Registry(GaussPoints_i::myComment.c_str(),&(Restore<GaussPoints_i>));
194 Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore<DeformedShape_i>));
195 Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore<CutPlanes_i>));
196 Storable::Registry(CutLines_i::myComment.c_str(),&(Restore<CutLines_i>));
197 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore<IsoSurfaces_i>));
198 Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore<StreamLines_i>));
199 Storable::Registry(Plot3D_i::myComment.c_str(),&(Restore<Plot3D_i>));
200 Storable::Registry(Vectors_i::myComment.c_str(),&(Restore<Vectors_i>));
201 Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore));
202 Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore));
203 Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore));
204 Storable::Registry(ScalarMapOnDeformedShape_i::myComment.c_str(),&(Restore<ScalarMapOnDeformedShape_i>));
208 //===========================================================================
209 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
210 SALOME_NamingService* theNamingService, QMutex* theMutex) :
211 Engines_Component_i()
213 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
214 Base_i::myMutex = theMutex; //apo
215 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
216 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
217 Base_i::myNamingService = theNamingService;
218 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
219 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
220 Base_i::myVisuGenImpl = this;
223 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
224 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
225 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
226 if(aListOfOpenStudies->length() > 0) {
227 CORBA::String_var aStudyName = aListOfOpenStudies[0];
228 //aFileInfo.setFile(aStudyName.in());
229 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
231 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
235 CreatColoredPrs3d(ColoredPrs3d_i* theColoredPrs3d,
236 const char* theMeshName,
237 VISU::Entity theEntity,
238 const char* theFieldName,
239 CORBA::Double theIteration)
244 if(theColoredPrs3d->Create(theMeshName,theEntity,theFieldName,int(theIteration)))
247 }catch(std::exception& exc){
248 INFOS("Follow exception was occured :\n"<<exc.what());
250 INFOS("Unknown exception was occured!");
256 VISU_Gen_i::~VISU_Gen_i(){
257 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
259 //===========================================================================
260 CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
261 const SALOMEDS::TMPFile & theStream,
266 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
267 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
268 string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
269 TCollection_AsciiString aTmpDir (const_cast<char*>(aDir.c_str()));
270 VisuTmpDir = aTmpDir.ToCString();
271 SALOMEDS::ListOfFileNames_var aSeq =
272 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
273 myIsMultiFile = isMultiFile;
277 CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
278 const SALOMEDS::TMPFile & theStream,
282 return Load(theComponent, theStream, theURL, isMultiFile);
285 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
286 const char* aLocalPersistentID,
287 CORBA::Boolean isMultiFile,
288 CORBA::Boolean isASCII)
290 CORBA::String_var aString("");
291 if(strcmp(aLocalPersistentID,"") != 0) {
293 Storable* aStorable =
294 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
295 if(aStorable != NULL) aString = aStorable->GetID();
297 return aString._retn();
299 //===========================================================================
300 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
305 string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
306 TCollection_AsciiString aTmpDir (const_cast<char*>(aDir.c_str()));
307 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
309 TColStd_SequenceOfAsciiString aFileNames;
310 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
312 //CORBA::Boolean anIsValidScript;
313 //Engines::TMPFile_var aDump = DumpPython(aStudy,false,anIsValidScript);
315 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
316 for (; itBig->More(); itBig->Next()) {
317 SALOMEDS::SObject_var gotBranch = itBig->Value();
318 CORBA::Object_var anObj = SObjectToObject(gotBranch);
319 if(CORBA::is_nil(anObj)) continue;
320 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
321 switch(pResult->GetCreationId()){
322 case Result_i::eImportFile:
323 case Result_i::eCopyAndImportFile: {
324 const QFileInfo& aFileInfo = pResult->GetFileInfo();
326 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
327 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
328 static QString aCommand;
329 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
331 int aRes = system(aCommand);
333 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
336 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aCommand = "<<aCommand);
338 TCollection_AsciiString aString(strdup(aFileName.latin1()));
339 aFileNames.Append(aString);
343 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
344 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
345 if(aFileNames.Length() > 0){
346 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
347 aSeq->length(aFileNames.Length());
348 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
349 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
350 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
352 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
354 return aStreamFile._retn();
357 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
362 string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
363 TCollection_AsciiString aTmpDir (const_cast<char*>(aDir.c_str()));
364 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
366 TColStd_SequenceOfAsciiString aFileNames;
367 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
368 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
369 for (; itBig->More(); itBig->Next()) {
370 SALOMEDS::SObject_var gotBranch = itBig->Value();
371 CORBA::Object_var anObj = SObjectToObject(gotBranch);
372 if(CORBA::is_nil(anObj)) continue;
373 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
374 switch(pResult->GetCreationId()){
375 case Result_i::eImportFile:
376 case Result_i::eCopyAndImportFile: {
377 const QFileInfo& aFileInfo = pResult->GetFileInfo();
379 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
380 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
381 static QString aCommand;
382 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
384 int aRes = system(aCommand);
386 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Can't execute the command :"<<aCommand);
389 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
391 TCollection_AsciiString aString(strdup(aFileName.latin1()));
393 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
395 aFileNames.Append(aString);
399 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
400 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
401 if(aFileNames.Length() > 0){
402 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
403 aSeq->length(aFileNames.Length());
404 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
405 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
406 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
408 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
410 return aStreamFile._retn();
413 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
414 const char* IORString,
415 CORBA::Boolean isMultiFile,
416 CORBA::Boolean isASCII)
418 CORBA::String_var aString(IORString);
419 if(strcmp(IORString,"") != 0){
420 CORBA::ORB_ptr anORB = GetORB();
421 CORBA::Object_var anObj = anORB->string_to_object(aString);
422 if(!CORBA::is_nil(anObj)){
423 if(Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
425 aString = pStorable->ToString().c_str();
426 return aString._retn();
430 return aString._retn();
433 char* VISU_Gen_i::GetID(){
434 return Base_i::GetID();
437 void VISU_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy)
439 class TEvent: public SALOME_Event {
440 std::string myStudyName;
442 TEvent(const std::string theStudyName):myStudyName(theStudyName)
444 virtual void Execute()
446 bool isActive = false;
447 SUIT_Session* aSession = SUIT_Session::session();
448 QPtrList<SUIT_Application> anApplications = aSession->applications();
449 QPtrListIterator<SUIT_Application> anIter (anApplications);
450 SUIT_Application* aFirstApp = anIter.current();
451 while (SUIT_Application* anApp = anIter.current()) {
453 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
454 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
455 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
456 if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = "
457 << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
458 if (myStudyName == aCStudy->Name()) {
467 MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
468 // Has to be loaded in an empty or in a new application
469 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
470 anApp->onLoadDoc(myStudyName.c_str());
475 if (!CORBA::is_nil(theStudy))
477 CORBA::String_var aName = theStudy->Name();
478 std::string aStudyName (aName.in());
479 if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
480 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
482 ProcessVoidEvent(new TEvent(aStudyName));
484 INFOS("CORBA::is_nil(theStudy)");
488 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
489 return SALOMEDS::Study::_duplicate(myStudyDocument);
492 ViewManager_ptr VISU_Gen_i::GetViewManager(){
494 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
495 return ViewManager::_duplicate(aViewManager->_this());
498 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
499 if(myStudyDocument->GetProperties()->IsLocked())
500 return SALOMEDS::SObject::_nil();
502 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
506 CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
507 const char* theFileName)
509 return VISU::ExportTableToFile(theTable, theFileName);
512 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
513 if(myStudyDocument->GetProperties()->IsLocked())
514 return Result::_nil();
516 aFileInfo.setFile(theFileName);
517 Result_i* pResult = new Result_i(myStudyDocument,
519 Result_i::eImportFile);
520 if(pResult->Create(theFileName) != NULL)
521 return pResult->_this();
523 pResult->_remove_ref();
524 return VISU::Result::_nil();
528 Result_ptr VISU_Gen_i::CreateResult(const char* theFileName){
529 if(myStudyDocument->GetProperties()->IsLocked())
530 return Result::_nil();
532 aFileInfo.setFile(theFileName);
533 Result_i* pResult = new Result_i(myStudyDocument,
535 Result_i::eImportFile,
537 if(pResult->Create(theFileName) != NULL)
538 return pResult->_this();
540 pResult->_remove_ref();
541 return VISU::Result::_nil();
545 Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){
546 if(myStudyDocument->GetProperties()->IsLocked())
547 return Result::_nil();
549 VISU::Result_var aResult;
550 aFileInfo.setFile(theFileName);
551 Result_i* pResult = new Result_i(myStudyDocument,
552 Result_i::eRestoredFile,
553 Result_i::eCopyAndImportFile);
554 if(pResult->Create(theFileName) != NULL)
555 aResult = pResult->_this();
556 return aResult._retn();
559 Result_ptr VISU_Gen_i::ImportMed (SALOMEDS::SObject_ptr theMedSObject)
561 if (myStudyDocument->GetProperties()->IsLocked())
562 return Result::_nil();
564 Result_i* pResult = new Result_i(myStudyDocument,
565 Result_i::eComponent,
566 Result_i::eImportMed);
567 if (pResult->Create(theMedSObject) != NULL) {
568 return pResult->_this();
570 pResult->_remove_ref();
571 return VISU::Result::_nil();
575 Result_ptr VISU_Gen_i::ImportMedField (SALOME_MED::FIELD_ptr theField)
577 if (myStudyDocument->GetProperties()->IsLocked())
578 return Result::_nil();
580 Result_i* pResult = new Result_i(myStudyDocument,
581 Result_i::eComponent,
582 Result_i::eImportMedField);
583 if (pResult->Create(theField) != NULL) {
584 return pResult->_this();
586 pResult->_remove_ref();
587 return VISU::Result::_nil();
591 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult,
592 const char* theMeshName,
593 VISU::Entity theEntity)
595 if(myStudyDocument->GetProperties()->IsLocked())
598 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
599 Mesh_i* aPresent = new Mesh_i(pResult);
600 if(aPresent->Create(theMeshName,theEntity) != NULL)
601 return aPresent->_this();
603 aPresent->_remove_ref();
606 return VISU::Mesh::_nil();
609 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult,
610 const char* theMeshName,
611 VISU::Entity theEntity,
612 const char* theFamilyName)
614 if(myStudyDocument->GetProperties()->IsLocked())
617 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
618 Mesh_i* aPresent = new Mesh_i(pResult);
619 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
620 return aPresent->_this();
622 aPresent->_remove_ref();
625 return VISU::Mesh::_nil();
628 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult,
629 const char* theMeshName,
630 const char* theGroupName)
632 if(myStudyDocument->GetProperties()->IsLocked())
635 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
636 Mesh_i* aPresent = new Mesh_i(pResult);
637 if(aPresent->Create(theMeshName,theGroupName) != NULL)
638 return aPresent->_this();
640 aPresent->_remove_ref();
643 return VISU::Mesh::_nil();
646 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult,
647 const char* theMeshName,
648 VISU::Entity theEntity,
649 const char* theFieldName,
650 CORBA::Double theIteration)
652 return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
655 GaussPoints_ptr VISU_Gen_i::GaussPointsOnField(Result_ptr theResult,
656 const char* theMeshName,
657 VISU::Entity theEntity,
658 const char* theFieldName,
659 CORBA::Double theIteration)
661 return Prs3dOnField<VISU::GaussPoints_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
664 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult,
665 const char* theMeshName,
666 VISU::Entity theEntity,
667 const char* theFieldName,
668 CORBA::Double theIteration)
670 return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
673 ScalarMapOnDeformedShape_ptr VISU_Gen_i::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
674 const char* theMeshName,
675 VISU::Entity theEntity,
676 const char* theFieldName,
677 CORBA::Double theIteration)
679 return Prs3dOnField<VISU::ScalarMapOnDeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
682 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult,
683 const char* theMeshName,
684 VISU::Entity theEntity,
685 const char* theFieldName,
686 CORBA::Double theIteration)
688 return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
691 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult,
692 const char* theMeshName,
693 VISU::Entity theEntity,
694 const char* theFieldName,
695 CORBA::Double theIteration)
697 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
700 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult,
701 const char* theMeshName,
702 VISU::Entity theEntity,
703 const char* theFieldName,
704 CORBA::Double theIteration)
706 return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
709 Plot3D_ptr VISU_Gen_i::Plot3DOnField(Result_ptr theResult,
710 const char* theMeshName,
711 VISU::Entity theEntity,
712 const char* theFieldName,
713 CORBA::Double theIteration)
715 return Prs3dOnField<VISU::Plot3D_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
718 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult,
719 const char* theMeshName,
720 VISU::Entity theEntity,
721 const char* theFieldName,
722 CORBA::Double theIteration)
724 return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
727 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult,
728 const char* theMeshName,
729 VISU::Entity theEntity,
730 const char* theFieldName,
731 CORBA::Double theIteration)
733 return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
736 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
737 if(myStudyDocument->GetProperties()->IsLocked())
738 return Table::_nil();
740 Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry);
741 if(pPresent->Create() != NULL)
742 return pPresent->_this();
744 pPresent->_remove_ref();
745 return VISU::Table::_nil();
749 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable,
753 if(myStudyDocument->GetProperties()->IsLocked())
754 return Curve::_nil();
756 PortableServer::POA_ptr aPOA = GetPOA();
757 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
758 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
759 if(pPresent->Create() != NULL)
760 return pPresent->_this();
762 pPresent->_remove_ref();
763 return VISU::Curve::_nil();
767 Container_ptr VISU_Gen_i::CreateContainer(){
768 if(myStudyDocument->GetProperties()->IsLocked())
769 return Container::_nil();
771 Container_i* pPresent = new Container_i(myStudyDocument);
772 if(pPresent->Create() != NULL)
773 return pPresent->_this();
775 pPresent->_remove_ref();
776 return VISU::Container::_nil();
780 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
781 if(myStudyDocument->GetProperties()->IsLocked())
782 return Animation::_nil();
784 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
785 return anAnim->_this();
787 return VISU::Animation::_nil();
790 void VISU_Gen_i::DeleteResult (Result_ptr theResult)
792 theResult->RemoveFromStudy();
795 void VISU_Gen_i::DeletePrs3d (Prs3d_ptr thePrs3d)
797 thePrs3d->RemoveFromStudy();
800 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
803 char* VISU_Gen_i::ComponentDataType(){
804 return CORBA::string_dup("VISU");
807 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
808 Result_var aResultObj = Result::_narrow(theIOR);
809 return !(aResultObj->_is_nil());
812 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
813 SALOMEDS::SObject_ptr theSObject,
814 CORBA::Object_ptr theObject,
816 throw (SALOME::SALOME_Exception)
818 Unexpect aCatch(SalomeException);
819 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
821 SALOMEDS::SObject_var aResultSO;
822 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
823 if (!aResultObj) return aResultSO._retn();
824 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
825 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
826 aResultSO = theStudy->FindObjectID(anEntry);
827 return aResultSO._retn();
830 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
832 SALOMEDS::GenericAttribute_var anAttr;
833 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
835 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
836 CORBA::String_var aValue = anIOR->Value();
837 if(strcmp(aValue,"") != 0){
838 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
839 if (!CORBA::is_nil(anObj)){
840 Result_var aResultObj = Result::_narrow(anObj);
841 if(!aResultObj->_is_nil()){
842 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj).in())){
843 switch(pResult->GetCreationId()){
844 case Result_i::eImportFile:
845 case Result_i::eCopyAndImportFile:
852 }catch(std::exception& exc){
853 INFOS("Follow exception was occured :\n"<<exc.what());
855 INFOS("Unknown exception was occured!");
860 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
863 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
864 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
866 PortableServer::POA_ptr aPOA = GetPOA();
868 SALOMEDS::GenericAttribute_var anAttr;
869 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
870 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
871 CORBA::Object_var aCorbaObj;
873 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
875 aStreamFile->length(1);
876 aStreamFile[0] = strdup("E")[0];
877 return aStreamFile._retn();
879 if (CORBA::is_nil(aCorbaObj)) {
883 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj).in());
888 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
889 string aCopyPersist = aTmpDir + "copy_persistent";
891 ofstream stmOut2(aCopyPersist.c_str(),ios::out);
892 string aStr = pStorable->ToString().c_str();
896 if (Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj))) {
897 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
898 if(strlen(aFileName.c_str()) == 1) aFileName="";
899 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
900 aFileName += aFileInfo.fileName().latin1();
901 static QString aCommand;
902 string aFullFileName = aTmpDir + aFileName;
903 aCommand.sprintf("cp %s %s",
904 aFileInfo.filePath().latin1(),
905 aFullFileName.c_str());
906 if(system(aCommand) == -1) {
907 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
911 aSeq[0] = "copy_persistent";
912 aSeq[1] = aFileName.c_str();
915 aSeq[0] = "copy_persistent";
918 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false);
919 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
921 // Assign an ID = 1 the the type VISU::Result
925 SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
926 return aStreamFile._retn();
929 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
930 // The VISU component can paste only objects copied by VISU component
931 // and with the object type = 1
932 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1)
937 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
938 CORBA::Long theObjectID,
939 SALOMEDS::SObject_ptr theObject)
942 SALOMEDS::SObject_var aResultSO;
943 if (theObjectID != 1)
944 return aResultSO._retn();
946 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
947 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false);
949 ifstream stmIn((aTmpDir + string("copy_persistent")).c_str());
950 stmIn.seekg(0, ios::end);
951 int aLength = stmIn.tellg();
952 stmIn.seekg(0, ios::beg);
953 char* aString = new char[aLength+1];
954 stmIn.read(aString, aLength);
955 aString[aLength] = 0;
956 myIsMultiFile = false;
958 string aFileName(aTmpDir);
959 string aBasicFileName;
960 if(aSeq->length() > 1) {
961 aBasicFileName = aSeq[1].in();
962 aFileName += aBasicFileName;
965 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
966 SALOMEDS::Study_var aStudy = theObject->GetStudy();
967 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
968 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
970 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
971 aResultSO = aStudyBuilder->NewObject(aComponent);
973 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
975 //Just for Result::Restore to find the Comment attribute :(
976 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
978 Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
980 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
982 aSeqToRm[0] = "copy_persistent";
984 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true);
986 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
987 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
988 CORBA::String_var anIORValue(aStorable->GetID());
989 anIOR->SetValue(anIORValue);
990 return aResultSO._retn();