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_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"
88 #include "CASCatch.hxx"
92 static QFileInfo aFileInfo;
95 static int MYDEBUG = 0;
98 static int MYDEBUG = 0;
101 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
103 extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB,
104 PortableServer::POA_ptr thePOA,
105 SALOME_NamingService* theNamingService,
108 if(MYDEBUG) MESSAGE("extern \"C\" GetImpl");
109 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
110 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
111 return aVISU_Gen->_this();
116 static string VisuTmpDir;
118 static CORBA::Boolean myIsMultiFile;
119 const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
121 //===========================================================================
122 _PTR(SComponent) 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();
157 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
158 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
159 if (aSComponent->_is_nil()) {
160 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
161 aStudyBuilder->NewCommand();
162 int aLocked = theStudyDocument->GetProperties()->IsLocked();
163 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
164 aSComponent = aStudyBuilder->NewComponent("VISU");
165 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
166 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
168 //NRI aName->SetValue("Visu");
169 CORBA::ORB_var anORB = Base_i::GetORB();
170 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
171 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
172 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
173 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
174 if ( !Comp->_is_nil() ) {
175 aName->SetValue( Comp->componentusername() );
178 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
179 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
180 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
182 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
183 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
184 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
185 aStudyBuilder->CommitCommand();
190 void RegistryStorable() {
191 Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore));
192 Storable::Registry(Mesh_i::myComment.c_str(),&(Restore<Mesh_i>));
193 Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore<ScalarMap_i>));
194 Storable::Registry(GaussPoints_i::myComment.c_str(),&(Restore<GaussPoints_i>));
195 Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore<DeformedShape_i>));
196 Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore<CutPlanes_i>));
197 Storable::Registry(CutLines_i::myComment.c_str(),&(Restore<CutLines_i>));
198 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore<IsoSurfaces_i>));
199 Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore<StreamLines_i>));
200 Storable::Registry(Plot3D_i::myComment.c_str(),&(Restore<Plot3D_i>));
201 Storable::Registry(Vectors_i::myComment.c_str(),&(Restore<Vectors_i>));
202 Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore));
203 Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore));
204 Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore));
205 Storable::Registry(ScalarMapOnDeformedShape_i::myComment.c_str(),&(Restore<ScalarMapOnDeformedShape_i>));
209 //===========================================================================
210 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
211 SALOME_NamingService* theNamingService, QMutex* theMutex) :
212 Engines_Component_i()
214 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
215 Base_i::myMutex = theMutex; //apo
216 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
217 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
218 Base_i::myNamingService = theNamingService;
219 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
220 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
221 Base_i::myVisuGenImpl = this;
224 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
225 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
226 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
227 if(aListOfOpenStudies->length() > 0) {
228 CORBA::String_var aStudyName = aListOfOpenStudies[0];
229 //aFileInfo.setFile(aStudyName.in());
230 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
232 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
236 CreatColoredPrs3d(ColoredPrs3d_i* theColoredPrs3d,
237 const char* theMeshName,
238 VISU::Entity theEntity,
239 const char* theFieldName,
240 CORBA::Double theIteration)
246 if(theColoredPrs3d->Create(theMeshName,theEntity,theFieldName,int(theIteration)))
249 }catch(std::exception& exc){
250 INFOS("Follow exception was occured :\n"<<exc.what());
252 INFOS("Unknown exception was occured!");
255 }CASCatch_CATCH(Standard_Failure) {
256 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
257 INFOS("Follow signal was occured :\n"<<aFail->GetMessageString());
262 VISU_Gen_i::~VISU_Gen_i(){
263 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
265 //===========================================================================
266 CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
267 const SALOMEDS::TMPFile & theStream,
272 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
273 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
274 string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
275 TCollection_AsciiString aTmpDir (const_cast<char*>(aDir.c_str()));
276 VisuTmpDir = aTmpDir.ToCString();
277 SALOMEDS::ListOfFileNames_var aSeq =
278 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
279 myIsMultiFile = isMultiFile;
283 CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
284 const SALOMEDS::TMPFile & theStream,
288 return Load(theComponent, theStream, theURL, isMultiFile);
291 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
292 const char* aLocalPersistentID,
293 CORBA::Boolean isMultiFile,
294 CORBA::Boolean isASCII)
296 CORBA::String_var aString("");
297 if(strcmp(aLocalPersistentID,"") != 0) {
299 Storable* aStorable =
300 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
301 if(aStorable != NULL) aString = aStorable->GetID();
303 return aString._retn();
305 //===========================================================================
306 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
311 string aTmpDir = theURL;
312 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
314 typedef std::vector<std::string> TFileNames;
315 TFileNames aFileNames;
318 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
319 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
320 for (; anIter->More(); anIter->Next()) {
321 SALOMEDS::SObject_var gotBranch = anIter->Value();
322 CORBA::Object_var anObj = SObjectToObject(gotBranch);
323 if(CORBA::is_nil(anObj)) continue;
324 if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
325 switch(aResult->GetCreationId()){
326 case Result_i::eImportFile:
327 case Result_i::eCopyAndImportFile: {
328 const QFileInfo& aFileInfo = aResult->GetFileInfo();
329 const std::string& aName = aResult->GetName();
330 std::string aFileName = std::string("_") + aName;
331 std::string aFile = aFileInfo.filePath().latin1();
333 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()) + aFileName;
335 std::ostringstream aStream;
336 aStream<<"cp "<<aFile<<" "<<aTmpDir<<aFileName;
337 std::string aCommand = aStream.str();
338 if(system(aCommand.c_str()) != 0){
339 INFOS("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
343 aFileNames.push_back(aFileName);
344 aFiles.push_back(aFile);
349 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<<aFileNames.size());
351 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
352 if(!aFileNames.empty()){
353 aListOfFileNames->length(aFileNames.size());
354 for(int aCounter = aFileNames.size(); aCounter > 0; aCounter--)
355 aListOfFileNames[aCounter-1] = aFileNames[aCounter-1].c_str();
358 SALOMEDS::ListOfFileNames_var aListOfFiles = new SALOMEDS::ListOfFileNames;
359 aListOfFiles->length(aFiles.size());
361 for(int aCounter = aFileNames.size(); aCounter > 0; aCounter--)
362 aListOfFiles[aCounter-1] = aFiles[aCounter-1].c_str();
365 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
367 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFiles.in(), theIsMultiFile);
369 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in());
371 return aStreamFile._retn();
374 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
379 string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
380 TCollection_AsciiString aTmpDir (const_cast<char*>(aDir.c_str()));
381 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
383 TColStd_SequenceOfAsciiString aFileNames;
384 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
385 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
386 for (; itBig->More(); itBig->Next()) {
387 SALOMEDS::SObject_var gotBranch = itBig->Value();
388 CORBA::Object_var anObj = SObjectToObject(gotBranch);
389 if(CORBA::is_nil(anObj)) continue;
390 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
391 switch(pResult->GetCreationId()){
392 case Result_i::eImportFile:
393 case Result_i::eCopyAndImportFile: {
394 const QFileInfo& aFileInfo = pResult->GetFileInfo();
396 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
397 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
398 static QString aCommand;
399 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
401 int aRes = system(aCommand);
403 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Can't execute the command :"<<aCommand);
406 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
408 TCollection_AsciiString aString(strdup(aFileName.latin1()));
410 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
412 aFileNames.Append(aString);
416 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
417 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
418 if(aFileNames.Length() > 0){
419 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
420 aSeq->length(aFileNames.Length());
421 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
422 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
423 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
425 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
427 return aStreamFile._retn();
430 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
431 const char* IORString,
432 CORBA::Boolean isMultiFile,
433 CORBA::Boolean isASCII)
435 CORBA::String_var aString(IORString);
436 if(strcmp(IORString,"") != 0){
437 CORBA::ORB_ptr anORB = GetORB();
438 CORBA::Object_var anObj = anORB->string_to_object(aString);
439 if(!CORBA::is_nil(anObj)){
440 if(Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
442 aString = pStorable->ToString().c_str();
443 return aString._retn();
447 return aString._retn();
450 char* VISU_Gen_i::GetID(){
451 return Base_i::GetID();
454 void VISU_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy)
456 class TEvent: public SALOME_Event {
457 std::string myStudyName;
459 TEvent(const std::string theStudyName):myStudyName(theStudyName)
461 virtual void Execute()
463 bool isActive = false;
464 SUIT_Session* aSession = SUIT_Session::session();
465 QPtrList<SUIT_Application> anApplications = aSession->applications();
466 QPtrListIterator<SUIT_Application> anIter (anApplications);
467 SUIT_Application* aFirstApp = anIter.current();
468 while (SUIT_Application* anApp = anIter.current()) {
470 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
471 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
472 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
473 if(MYDEBUG) MESSAGE("There is an application with active study : StudyId = "
474 << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
475 if (myStudyName == aCStudy->Name()) {
484 MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
485 // Has to be loaded in an empty or in a new application
486 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
487 anApp->onLoadDoc(myStudyName.c_str());
492 if (!CORBA::is_nil(theStudy))
494 CORBA::String_var aName = theStudy->Name();
495 std::string aStudyName (aName.in());
496 if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
497 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
499 ProcessVoidEvent(new TEvent(aStudyName));
501 INFOS("CORBA::is_nil(theStudy)");
505 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
506 return SALOMEDS::Study::_duplicate(myStudyDocument);
509 ViewManager_ptr VISU_Gen_i::GetViewManager(){
511 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
512 return ViewManager::_duplicate(aViewManager->_this());
515 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
516 if(myStudyDocument->GetProperties()->IsLocked())
517 return SALOMEDS::SObject::_nil();
519 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
523 CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
524 const char* theFileName)
526 return VISU::ExportTableToFile(theTable, theFileName);
529 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
530 if(myStudyDocument->GetProperties()->IsLocked())
531 return Result::_nil();
533 aFileInfo.setFile(theFileName);
534 Result_i* pResult = new Result_i(myStudyDocument,
536 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::CreateResult(const char* theFileName){
546 if(myStudyDocument->GetProperties()->IsLocked())
547 return Result::_nil();
549 aFileInfo.setFile(theFileName);
550 Result_i* pResult = new Result_i(myStudyDocument,
552 Result_i::eImportFile,
554 if(pResult->Create(theFileName) != NULL)
555 return pResult->_this();
557 pResult->_remove_ref();
558 return VISU::Result::_nil();
562 Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){
563 if(myStudyDocument->GetProperties()->IsLocked())
564 return Result::_nil();
566 VISU::Result_var aResult;
567 aFileInfo.setFile(theFileName);
568 Result_i* pResult = new Result_i(myStudyDocument,
569 Result_i::eRestoredFile,
570 Result_i::eCopyAndImportFile);
571 if(pResult->Create(theFileName) != NULL)
572 aResult = pResult->_this();
573 return aResult._retn();
576 Result_ptr VISU_Gen_i::ImportMed (SALOMEDS::SObject_ptr theMedSObject)
578 if (myStudyDocument->GetProperties()->IsLocked())
579 return Result::_nil();
581 Result_i* pResult = new Result_i(myStudyDocument,
582 Result_i::eComponent,
583 Result_i::eImportMed);
584 if (pResult->Create(theMedSObject) != NULL) {
585 return pResult->_this();
587 pResult->_remove_ref();
588 return VISU::Result::_nil();
592 Result_ptr VISU_Gen_i::ImportMedField (SALOME_MED::FIELD_ptr theField)
594 if (myStudyDocument->GetProperties()->IsLocked())
595 return Result::_nil();
597 Result_i* pResult = new Result_i(myStudyDocument,
598 Result_i::eComponent,
599 Result_i::eImportMedField);
600 if (pResult->Create(theField) != NULL) {
601 return pResult->_this();
603 pResult->_remove_ref();
604 return VISU::Result::_nil();
608 void VISU_Gen_i::RenameMeshInStudy(Result_ptr theResult,
610 int theEntity, // -1 for group indication
611 string theSubMeshName, // Family or Group name
614 if (myStudyDocument->GetProperties()->IsLocked()) return;
617 Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in());
618 if (!pResult) return;
621 VISU::VISUType aType;
623 if (theSubMeshName == "")
624 aType = VISU::TENTITY;
626 aType = VISU::TFAMILY;
628 aType = VISU::TGROUP;
632 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
633 VISU::TENTITY, theMeshName.c_str(), theEntity);
636 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
637 VISU::TFAMILY, theMeshName.c_str(), theEntity, theSubMeshName.c_str());
640 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
641 VISU::TGROUP, theMeshName.c_str(), theSubMeshName.c_str());
645 string aResultEntry = pResult->GetEntry();
646 string anEntry = pResult->GetEntry(aComment.latin1());
647 if (anEntry == "") return;
649 SALOMEDS::SObject_ptr aSObject = myStudyDocument->FindObjectID(anEntry.c_str());
651 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
652 aStudyBuilder->NewCommand(); // There is a transaction
654 SALOMEDS::GenericAttribute_var anAttr =
655 aStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
656 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
657 aNameAttr->SetValue(theNewName.c_str());
659 aStudyBuilder->CommitCommand();
662 void VISU_Gen_i::RenameEntityInStudy(Result_ptr theResult,
663 const char* theMeshName,
664 VISU::Entity theEntity,
665 const char* theNewName)
667 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, "", theNewName);
670 void VISU_Gen_i::RenameFamilyInStudy(Result_ptr theResult,
671 const char* theMeshName,
672 VISU::Entity theEntity,
673 const char* theFamilyName,
674 const char* theNewName)
676 RenameMeshInStudy(theResult, theMeshName, (int)theEntity, theFamilyName, theNewName);
679 void VISU_Gen_i::RenameGroupInStudy(Result_ptr theResult,
680 const char* theMeshName,
681 const char* theGroupName,
682 const char* theNewName)
684 RenameMeshInStudy(theResult, theMeshName, -1, theGroupName, theNewName);
687 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult,
688 const char* theMeshName,
689 VISU::Entity theEntity)
691 if(myStudyDocument->GetProperties()->IsLocked())
694 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
695 Mesh_i* aPresent = new Mesh_i(pResult);
696 if(aPresent->Create(theMeshName,theEntity) != NULL)
697 return aPresent->_this();
699 aPresent->_remove_ref();
702 return VISU::Mesh::_nil();
705 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult,
706 const char* theMeshName,
707 VISU::Entity theEntity,
708 const char* theFamilyName)
710 if(myStudyDocument->GetProperties()->IsLocked())
713 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
714 Mesh_i* aPresent = new Mesh_i(pResult);
715 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
716 return aPresent->_this();
718 aPresent->_remove_ref();
721 return VISU::Mesh::_nil();
724 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult,
725 const char* theMeshName,
726 const char* theGroupName)
728 if(myStudyDocument->GetProperties()->IsLocked())
731 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
732 Mesh_i* aPresent = new Mesh_i(pResult);
733 if(aPresent->Create(theMeshName,theGroupName) != NULL)
734 return aPresent->_this();
736 aPresent->_remove_ref();
739 return VISU::Mesh::_nil();
742 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult,
743 const char* theMeshName,
744 VISU::Entity theEntity,
745 const char* theFieldName,
746 CORBA::Double theIteration)
748 return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
751 GaussPoints_ptr VISU_Gen_i::GaussPointsOnField(Result_ptr theResult,
752 const char* theMeshName,
753 VISU::Entity theEntity,
754 const char* theFieldName,
755 CORBA::Double theIteration)
757 return Prs3dOnField<VISU::GaussPoints_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
760 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult,
761 const char* theMeshName,
762 VISU::Entity theEntity,
763 const char* theFieldName,
764 CORBA::Double theIteration)
766 return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
769 ScalarMapOnDeformedShape_ptr VISU_Gen_i::ScalarMapOnDeformedShapeOnField(Result_ptr theResult,
770 const char* theMeshName,
771 VISU::Entity theEntity,
772 const char* theFieldName,
773 CORBA::Double theIteration)
775 return Prs3dOnField<VISU::ScalarMapOnDeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
778 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult,
779 const char* theMeshName,
780 VISU::Entity theEntity,
781 const char* theFieldName,
782 CORBA::Double theIteration)
784 return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
787 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult,
788 const char* theMeshName,
789 VISU::Entity theEntity,
790 const char* theFieldName,
791 CORBA::Double theIteration)
793 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
796 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult,
797 const char* theMeshName,
798 VISU::Entity theEntity,
799 const char* theFieldName,
800 CORBA::Double theIteration)
802 return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
805 Plot3D_ptr VISU_Gen_i::Plot3DOnField(Result_ptr theResult,
806 const char* theMeshName,
807 VISU::Entity theEntity,
808 const char* theFieldName,
809 CORBA::Double theIteration)
811 return Prs3dOnField<VISU::Plot3D_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
814 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult,
815 const char* theMeshName,
816 VISU::Entity theEntity,
817 const char* theFieldName,
818 CORBA::Double theIteration)
820 return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
823 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult,
824 const char* theMeshName,
825 VISU::Entity theEntity,
826 const char* theFieldName,
827 CORBA::Double theIteration)
829 return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
832 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
833 if(myStudyDocument->GetProperties()->IsLocked())
834 return Table::_nil();
836 Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry);
837 if(pPresent->Create() != NULL)
838 return pPresent->_this();
840 pPresent->_remove_ref();
841 return VISU::Table::_nil();
845 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable,
849 if(myStudyDocument->GetProperties()->IsLocked())
850 return Curve::_nil();
852 PortableServer::POA_ptr aPOA = GetPOA();
853 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
854 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
855 if(pPresent->Create() != NULL)
856 return pPresent->_this();
858 pPresent->_remove_ref();
859 return VISU::Curve::_nil();
863 Container_ptr VISU_Gen_i::CreateContainer(){
864 if(myStudyDocument->GetProperties()->IsLocked())
865 return Container::_nil();
867 Container_i* pPresent = new Container_i(myStudyDocument);
868 if(pPresent->Create() != NULL)
869 return pPresent->_this();
871 pPresent->_remove_ref();
872 return VISU::Container::_nil();
876 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
877 if(myStudyDocument->GetProperties()->IsLocked())
878 return Animation::_nil();
880 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
881 return anAnim->_this();
883 return VISU::Animation::_nil();
886 void VISU_Gen_i::DeleteResult (Result_ptr theResult)
888 theResult->RemoveFromStudy();
891 void VISU_Gen_i::DeletePrs3d (Prs3d_ptr thePrs3d)
893 thePrs3d->RemoveFromStudy();
896 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
899 char* VISU_Gen_i::ComponentDataType(){
900 return CORBA::string_dup("VISU");
903 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
904 Result_var aResultObj = Result::_narrow(theIOR);
905 return !(aResultObj->_is_nil());
908 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
909 SALOMEDS::SObject_ptr theSObject,
910 CORBA::Object_ptr theObject,
912 throw (SALOME::SALOME_Exception)
914 Unexpect aCatch(SalomeException);
915 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
917 SALOMEDS::SObject_var aResultSO;
918 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
919 if (!aResultObj) return aResultSO._retn();
920 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
921 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
922 aResultSO = theStudy->FindObjectID(anEntry);
923 return aResultSO._retn();
926 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
928 SALOMEDS::GenericAttribute_var anAttr;
929 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
931 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
932 CORBA::String_var aValue = anIOR->Value();
933 if(strcmp(aValue,"") != 0){
934 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
935 if (!CORBA::is_nil(anObj)){
936 Result_var aResultObj = Result::_narrow(anObj);
937 if(!aResultObj->_is_nil()){
938 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj).in())){
939 switch(pResult->GetCreationId()){
940 case Result_i::eImportFile:
941 case Result_i::eCopyAndImportFile:
948 }catch(std::exception& exc){
949 INFOS("Follow exception was occured :\n"<<exc.what());
951 INFOS("Unknown exception was occured!");
956 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
959 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
960 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
962 PortableServer::POA_ptr aPOA = GetPOA();
964 SALOMEDS::GenericAttribute_var anAttr;
965 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
966 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
967 CORBA::Object_var aCorbaObj;
969 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
971 aStreamFile->length(1);
972 aStreamFile[0] = strdup("E")[0];
973 return aStreamFile._retn();
975 if (CORBA::is_nil(aCorbaObj)) {
979 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj).in());
984 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
985 string aCopyPersist = aTmpDir + "copy_persistent";
987 ofstream stmOut2(aCopyPersist.c_str(),ios::out);
988 string aStr = pStorable->ToString().c_str();
992 if (Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj))) {
993 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
994 if(strlen(aFileName.c_str()) == 1) aFileName="";
995 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
996 aFileName += aFileInfo.fileName().latin1();
997 static QString aCommand;
998 string aFullFileName = aTmpDir + aFileName;
999 aCommand.sprintf("cp %s %s",
1000 aFileInfo.filePath().latin1(),
1001 aFullFileName.c_str());
1002 if(system(aCommand) == -1) {
1003 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
1007 aSeq[0] = "copy_persistent";
1008 aSeq[1] = aFileName.c_str();
1011 aSeq[0] = "copy_persistent";
1014 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false);
1015 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
1017 // Assign an ID = 1 the the type VISU::Result
1021 SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
1022 return aStreamFile._retn();
1025 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
1026 // The VISU component can paste only objects copied by VISU component
1027 // and with the object type = 1
1028 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1)
1033 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
1034 CORBA::Long theObjectID,
1035 SALOMEDS::SObject_ptr theObject)
1038 SALOMEDS::SObject_var aResultSO;
1039 if (theObjectID != 1)
1040 return aResultSO._retn();
1042 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1043 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false);
1045 ifstream stmIn((aTmpDir + string("copy_persistent")).c_str());
1046 stmIn.seekg(0, ios::end);
1047 int aLength = stmIn.tellg();
1048 stmIn.seekg(0, ios::beg);
1049 char* aString = new char[aLength+1];
1050 stmIn.read(aString, aLength);
1051 aString[aLength] = 0;
1052 myIsMultiFile = false;
1054 string aFileName(aTmpDir);
1055 string aBasicFileName;
1056 if(aSeq->length() > 1) {
1057 aBasicFileName = aSeq[1].in();
1058 aFileName += aBasicFileName;
1061 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
1062 SALOMEDS::Study_var aStudy = theObject->GetStudy();
1063 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1064 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
1066 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
1067 aResultSO = aStudyBuilder->NewObject(aComponent);
1069 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
1071 //Just for Result::Restore to find the Comment attribute :(
1072 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
1074 Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
1076 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
1077 aSeqToRm->length(1);
1078 aSeqToRm[0] = "copy_persistent";
1080 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true);
1082 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1083 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1084 CORBA::String_var anIORValue(aStorable->GetID());
1085 anIOR->SetValue(anIORValue);
1086 return aResultSO._retn();