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_Plot3D_i.hh"
42 #include "VISU_Table_i.hh"
43 #include "VISU_TimeAnimation.h"
45 #include "VISU_Actor.h"
47 #include "HDFascii.hxx"
48 #include "SALOMEDS_Tool.hxx"
50 #include "SALOMEDSClient_AttributeName.hxx"
51 #include "SALOMEDSClient_AttributePixMap.hxx"
53 #include "SUIT_Session.h"
54 #include "SalomeApp_Study.h"
55 #include "SalomeApp_Application.h"
56 #include "SalomeApp_SelectionMgr.h"
57 #include "SVTK_ViewModel.h"
58 #include "SVTK_ViewWindow.h"
59 #include "SALOME_Event.hxx"
60 #include "SALOME_ListIO.hxx"
61 #include "SALOME_ListIteratorOfListIO.hxx"
63 #include "utilities.h"
66 #include <omnithread.h>
67 #include CORBA_SERVER_HEADER(SALOME_Session)
68 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
72 #include <qfileinfo.h>
75 #include <vtkRenderer.h>
76 #include <vtkActorCollection.h>
79 #include <TCollection_AsciiString.hxx>
80 #include <TColStd_SequenceOfAsciiString.hxx>
85 #include "Utils_ExceptHandlers.hxx"
89 static QFileInfo aFileInfo;
92 static int MYDEBUG = 1;
94 static int MYDEBUG = 0;
97 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
99 extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB,
100 PortableServer::POA_ptr thePOA,
101 SALOME_NamingService* theNamingService,
104 if(MYDEBUG) MESSAGE("extern \"C\" GetImpl");
105 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
106 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
107 return aVISU_Gen->_this();
111 static string VisuTmpDir;
113 static CORBA::Boolean myIsMultiFile;
114 const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
116 //===========================================================================
117 _PTR(SComponent) ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
119 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
121 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
122 aStudyBuilder->NewCommand();
123 int aLocked = theStudyDocument->GetProperties()->IsLocked();
124 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
125 aSComponent = aStudyBuilder->NewComponent("VISU");
126 _PTR(GenericAttribute) anAttr =
127 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
128 _PTR(AttributeName) aName (anAttr);
130 CORBA::ORB_var anORB = Base_i::GetORB();
131 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
132 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
133 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
134 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
135 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
136 if (!Comp->_is_nil()) {
137 aName->SetValue(Comp->componentusername());
140 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
141 _PTR(AttributePixMap) aPixmap (anAttr);
142 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
144 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
145 aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
146 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
147 aStudyBuilder->CommitCommand();
152 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
153 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
154 if (aSComponent->_is_nil()) {
155 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
156 aStudyBuilder->NewCommand();
157 int aLocked = theStudyDocument->GetProperties()->IsLocked();
158 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
159 aSComponent = aStudyBuilder->NewComponent("VISU");
160 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
161 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
163 //NRI aName->SetValue("Visu");
164 CORBA::ORB_var anORB = Base_i::GetORB();
165 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
166 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
167 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
168 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
169 if ( !Comp->_is_nil() ) {
170 aName->SetValue( Comp->componentusername() );
173 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
174 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
175 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
177 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
178 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
179 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
180 aStudyBuilder->CommitCommand();
185 void RegistryStorable() {
186 Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore));
187 Storable::Registry(Mesh_i::myComment.c_str(),&(Restore<Mesh_i>));
188 Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore<ScalarMap_i>));
189 Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore<DeformedShape_i>));
190 Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore<CutPlanes_i>));
191 Storable::Registry(CutLines_i::myComment.c_str(),&(Restore<CutLines_i>));
192 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore<IsoSurfaces_i>));
193 Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore<StreamLines_i>));
194 Storable::Registry(Plot3D_i::myComment.c_str(),&(Restore<Plot3D_i>));
195 Storable::Registry(Vectors_i::myComment.c_str(),&(Restore<Vectors_i>));
196 Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore));
197 Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore));
198 Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore));
202 //===========================================================================
203 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
204 SALOME_NamingService* theNamingService, QMutex* theMutex) :
205 Engines_Component_i()
207 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
208 Base_i::myMutex = theMutex; //apo
209 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
210 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
211 Base_i::myNamingService = theNamingService;
212 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
213 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
214 Base_i::myVisuGenImpl = this;
217 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
218 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
219 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
220 if(aListOfOpenStudies->length() > 0) {
221 CORBA::String_var aStudyName = aListOfOpenStudies[0];
222 //aFileInfo.setFile(aStudyName.in());
223 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
225 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
228 VISU_Gen_i::~VISU_Gen_i(){
229 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
231 //===========================================================================
232 CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
233 const SALOMEDS::TMPFile & theStream,
238 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
239 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
240 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
241 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
242 VisuTmpDir = aTmpDir.ToCString();
243 SALOMEDS::ListOfFileNames_var aSeq =
244 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
245 myIsMultiFile = isMultiFile;
249 CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
250 const SALOMEDS::TMPFile & theStream,
254 return Load(theComponent, theStream, theURL, isMultiFile);
257 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
258 const char* aLocalPersistentID,
259 CORBA::Boolean isMultiFile,
260 CORBA::Boolean isASCII)
262 CORBA::String_var aString("");
263 if(strcmp(aLocalPersistentID,"") != 0) {
265 Storable* aStorable =
266 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
267 if(aStorable != NULL) aString = aStorable->GetID();
269 return aString._retn();
271 //===========================================================================
272 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
277 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
278 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
279 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
281 TColStd_SequenceOfAsciiString aFileNames;
282 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
284 //CORBA::Boolean anIsValidScript;
285 //Engines::TMPFile_var aDump = DumpPython(aStudy,false,anIsValidScript);
287 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
288 for (; itBig->More(); itBig->Next()) {
289 SALOMEDS::SObject_var gotBranch = itBig->Value();
290 CORBA::Object_var anObj = SObjectToObject(gotBranch);
291 if(CORBA::is_nil(anObj)) continue;
292 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
293 switch(pResult->GetCreationId()){
294 case Result_i::eImportFile:
295 case Result_i::eCopyAndImportFile: {
296 const QFileInfo& aFileInfo = pResult->GetFileInfo();
298 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
299 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
300 static QString aCommand;
301 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
303 int aRes = system(aCommand);
305 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
308 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aCommand = "<<aCommand);
310 TCollection_AsciiString aString(strdup(aFileName.latin1()));
311 aFileNames.Append(aString);
315 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
316 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
317 if(aFileNames.Length() > 0){
318 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
319 aSeq->length(aFileNames.Length());
320 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
321 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
322 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
324 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
326 return aStreamFile._retn();
329 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
334 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
335 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
336 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
338 TColStd_SequenceOfAsciiString aFileNames;
339 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
340 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
341 for (; itBig->More(); itBig->Next()) {
342 SALOMEDS::SObject_var gotBranch = itBig->Value();
343 CORBA::Object_var anObj = SObjectToObject(gotBranch);
344 if(CORBA::is_nil(anObj)) continue;
345 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
346 switch(pResult->GetCreationId()){
347 case Result_i::eImportFile:
348 case Result_i::eCopyAndImportFile: {
349 const QFileInfo& aFileInfo = pResult->GetFileInfo();
351 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
352 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
353 static QString aCommand;
354 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
356 int aRes = system(aCommand);
358 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Can't execute the command :"<<aCommand);
361 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
363 TCollection_AsciiString aString(strdup(aFileName.latin1()));
365 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
367 aFileNames.Append(aString);
371 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
372 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
373 if(aFileNames.Length() > 0){
374 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
375 aSeq->length(aFileNames.Length());
376 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
377 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
378 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
380 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
382 return aStreamFile._retn();
385 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
386 const char* IORString,
387 CORBA::Boolean isMultiFile,
388 CORBA::Boolean isASCII)
390 CORBA::String_var aString(IORString);
391 if(strcmp(IORString,"") != 0){
392 CORBA::ORB_ptr anORB = GetORB();
393 CORBA::Object_var anObj = anORB->string_to_object(aString);
394 if(!CORBA::is_nil(anObj)){
395 if(Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
397 aString = pStorable->ToString().c_str();
398 return aString._retn();
402 return aString._retn();
405 char* VISU_Gen_i::GetID(){
406 return Base_i::GetID();
409 void VISU_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy)
411 class TEvent: public SALOME_Event {
412 std::string myStudyName;
414 TEvent(const std::string theStudyName):myStudyName(theStudyName)
416 virtual void Execute()
418 bool isActive = false;
419 SUIT_Session* aSession = SUIT_Session::session();
420 QPtrList<SUIT_Application> anApplications = aSession->applications();
421 QPtrListIterator<SUIT_Application> anIter (anApplications);
422 SUIT_Application* aFirstApp = anIter.current();
423 while (SUIT_Application* anApp = anIter.current()) {
425 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
426 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
427 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
428 MESSAGE("There is an application with active study : StudyId = "
429 << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'");
430 if (myStudyName == aCStudy->Name()) {
439 MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!");
440 // Has to be loaded in an empty or in a new application
441 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aFirstApp);
442 anApp->onLoadDoc(myStudyName.c_str());
447 if (!CORBA::is_nil(theStudy))
449 CORBA::String_var aName = theStudy->Name();
450 std::string aStudyName (aName.in());
451 MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'");
452 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
454 ProcessVoidEvent(new TEvent(aStudyName));
456 MESSAGE("CORBA::is_nil(theStudy)");
460 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
461 return SALOMEDS::Study::_duplicate(myStudyDocument);
464 ViewManager_ptr VISU_Gen_i::GetViewManager(){
466 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
467 return ViewManager::_duplicate(aViewManager->_this());
470 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
471 if(myStudyDocument->GetProperties()->IsLocked())
472 return SALOMEDS::SObject::_nil();
474 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
478 CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
479 const char* theFileName)
481 return VISU::ExportTableToFile(theTable, theFileName);
484 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
485 if(myStudyDocument->GetProperties()->IsLocked())
486 return Result::_nil();
488 aFileInfo.setFile(theFileName);
489 Result_i* pResult = new Result_i(myStudyDocument,
491 Result_i::eImportFile);
492 if(pResult->Create(theFileName) != NULL)
493 return pResult->_this();
495 pResult->_remove_ref();
496 return VISU::Result::_nil();
500 Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){
501 if(myStudyDocument->GetProperties()->IsLocked())
502 return Result::_nil();
504 VISU::Result_var aResult;
505 aFileInfo.setFile(theFileName);
506 Result_i* pResult = new Result_i(myStudyDocument,
507 Result_i::eRestoredFile,
508 Result_i::eCopyAndImportFile);
509 if(pResult->Create(theFileName) != NULL)
510 aResult = pResult->_this();
511 return aResult._retn();
514 Result_ptr VISU_Gen_i::ImportMed (SALOMEDS::SObject_ptr theMedSObject)
516 if (myStudyDocument->GetProperties()->IsLocked())
517 return Result::_nil();
519 Result_i* pResult = new Result_i(myStudyDocument,
520 Result_i::eComponent,
521 Result_i::eImportMed);
522 if (pResult->Create(theMedSObject) != NULL) {
523 return pResult->_this();
525 pResult->_remove_ref();
526 return VISU::Result::_nil();
530 Result_ptr VISU_Gen_i::ImportMedField (SALOME_MED::FIELD_ptr theField)
532 if (myStudyDocument->GetProperties()->IsLocked())
533 return Result::_nil();
535 Result_i* pResult = new Result_i(myStudyDocument,
536 Result_i::eComponent,
537 Result_i::eImportMedField);
538 if (pResult->Create(theField) != NULL) {
539 return pResult->_this();
541 pResult->_remove_ref();
542 return VISU::Result::_nil();
546 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult,
547 const char* theMeshName,
548 VISU::Entity theEntity)
550 if(myStudyDocument->GetProperties()->IsLocked())
553 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
554 Mesh_i* aPresent = new Mesh_i(pResult);
555 if(aPresent->Create(theMeshName,theEntity) != NULL)
556 return aPresent->_this();
558 aPresent->_remove_ref();
561 return VISU::Mesh::_nil();
564 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult,
565 const char* theMeshName,
566 VISU::Entity theEntity,
567 const char* theFamilyName)
569 if(myStudyDocument->GetProperties()->IsLocked())
572 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
573 Mesh_i* aPresent = new Mesh_i(pResult);
574 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
575 return aPresent->_this();
577 aPresent->_remove_ref();
580 return VISU::Mesh::_nil();
583 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult,
584 const char* theMeshName,
585 const char* theGroupName)
587 if(myStudyDocument->GetProperties()->IsLocked())
590 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
591 Mesh_i* aPresent = new Mesh_i(pResult);
592 if(aPresent->Create(theMeshName,theGroupName) != NULL)
593 return aPresent->_this();
595 aPresent->_remove_ref();
598 return VISU::Mesh::_nil();
601 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult,
602 const char* theMeshName,
603 VISU::Entity theEntity,
604 const char* theFieldName,
605 CORBA::Double theIteration)
607 return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
610 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult,
611 const char* theMeshName,
612 VISU::Entity theEntity,
613 const char* theFieldName,
614 CORBA::Double theIteration)
616 return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
619 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult,
620 const char* theMeshName,
621 VISU::Entity theEntity,
622 const char* theFieldName,
623 CORBA::Double theIteration)
625 return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
628 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult,
629 const char* theMeshName,
630 VISU::Entity theEntity,
631 const char* theFieldName,
632 CORBA::Double theIteration)
634 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
637 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult,
638 const char* theMeshName,
639 VISU::Entity theEntity,
640 const char* theFieldName,
641 CORBA::Double theIteration)
643 return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
646 Plot3D_ptr VISU_Gen_i::Plot3DOnField(Result_ptr theResult,
647 const char* theMeshName,
648 VISU::Entity theEntity,
649 const char* theFieldName,
650 CORBA::Double theIteration)
652 return Prs3dOnField<VISU::Plot3D_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
655 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult,
656 const char* theMeshName,
657 VISU::Entity theEntity,
658 const char* theFieldName,
659 CORBA::Double theIteration)
661 return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
664 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult,
665 const char* theMeshName,
666 VISU::Entity theEntity,
667 const char* theFieldName,
668 CORBA::Double theIteration)
670 return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
673 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
674 if(myStudyDocument->GetProperties()->IsLocked())
675 return Table::_nil();
677 Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry);
678 if(pPresent->Create() != NULL)
679 return pPresent->_this();
681 pPresent->_remove_ref();
682 return VISU::Table::_nil();
686 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable,
690 if(myStudyDocument->GetProperties()->IsLocked())
691 return Curve::_nil();
693 PortableServer::POA_ptr aPOA = GetPOA();
694 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
695 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
696 if(pPresent->Create() != NULL)
697 return pPresent->_this();
699 pPresent->_remove_ref();
700 return VISU::Curve::_nil();
704 Container_ptr VISU_Gen_i::CreateContainer(){
705 if(myStudyDocument->GetProperties()->IsLocked())
706 return Container::_nil();
708 Container_i* pPresent = new Container_i(myStudyDocument);
709 if(pPresent->Create() != NULL)
710 return pPresent->_this();
712 pPresent->_remove_ref();
713 return VISU::Container::_nil();
717 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
718 if(myStudyDocument->GetProperties()->IsLocked())
719 return Animation::_nil();
721 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
722 return anAnim->_this();
724 return VISU::Animation::_nil();
727 void VISU_Gen_i::DeleteResult (Result_ptr theResult)
729 class TEvent: public SALOME_Event {
732 TEvent(Result_ptr theResult): myResult(theResult) {}
733 virtual void Execute()
735 if (Result_i* aResult = dynamic_cast<Result_i*>(GetServant(myResult).in())) {
736 SALOMEDS::SObject_var aSObject = aResult->GetSObject();
737 VISU::RemoveFromStudy(aSObject,
738 false, // not only attribute
739 true); // destroy sub-objects
741 //jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop())
742 //jfa tmp: if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument))
743 //jfa tmp: aStudy->updateObjBrowser(); //update Object browser
750 if (myStudyDocument->GetProperties()->IsLocked())
752 Mutex mt(myMutex); // jfa ???
754 ProcessVoidEvent(new TEvent(theResult));
757 void VISU_Gen_i::DeletePrs3d (Prs3d_ptr thePrs3d)
759 class TEvent: public SALOME_Event {
762 TEvent(Prs3d_ptr thePrs3d): myPrs3d(thePrs3d) {}
763 virtual void Execute() {
764 myPrs3d->RemoveFromStudy();
766 //update Object browser
767 /*jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop()) {
768 if (Prs3d_i* aPrs3d = dynamic_cast<Prs3d_i*>(GetServant(myPrs3d).in())) {
769 SALOMEDS::SObject_var aSObject = aPrs3d->GetSObject();
770 SALOMEDS::Study_var aStudyDocument = aSObject->GetStudy();
771 if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument))
772 aStudy->updateObjBrowser();
780 if (myStudyDocument->GetProperties()->IsLocked())
782 Mutex mt(myMutex); // jfa ???
784 ProcessVoidEvent(new TEvent(thePrs3d));
787 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
790 char* VISU_Gen_i::ComponentDataType(){
791 return CORBA::string_dup("VISU");
794 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
795 Result_var aResultObj = Result::_narrow(theIOR);
796 return !(aResultObj->_is_nil());
799 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
800 SALOMEDS::SObject_ptr theSObject,
801 CORBA::Object_ptr theObject,
803 throw (SALOME::SALOME_Exception)
805 Unexpect aCatch(SalomeException);
806 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
808 SALOMEDS::SObject_var aResultSO;
809 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
810 if (!aResultObj) return aResultSO._retn();
811 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
812 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
813 aResultSO = theStudy->FindObjectID(anEntry);
814 return aResultSO._retn();
817 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
819 SALOMEDS::GenericAttribute_var anAttr;
820 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
822 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
823 CORBA::String_var aValue = anIOR->Value();
824 if(strcmp(aValue,"") != 0){
825 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
826 if (!CORBA::is_nil(anObj)){
827 Result_var aResultObj = Result::_narrow(anObj);
828 if(!aResultObj->_is_nil()){
829 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj).in())){
830 switch(pResult->GetCreationId()){
831 case Result_i::eImportFile:
832 case Result_i::eCopyAndImportFile:
839 }catch(std::exception& exc){
840 INFOS("Follow exception was occured :\n"<<exc.what());
842 INFOS("Unknown exception was occured!");
847 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
850 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
851 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
853 PortableServer::POA_ptr aPOA = GetPOA();
855 SALOMEDS::GenericAttribute_var anAttr;
856 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
857 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
858 CORBA::Object_var aCorbaObj;
860 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
862 aStreamFile->length(1);
863 aStreamFile[0] = strdup("E")[0];
864 return aStreamFile._retn();
866 if (CORBA::is_nil(aCorbaObj)) {
870 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj).in());
875 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
876 string aCopyPersist = aTmpDir + "copy_persistent";
878 ofstream stmOut2(aCopyPersist.c_str(),ios::out);
879 string aStr = pStorable->ToString().c_str();
883 if (Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj))) {
884 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
885 if(strlen(aFileName.c_str()) == 1) aFileName="";
886 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
887 aFileName += aFileInfo.fileName().latin1();
888 static QString aCommand;
889 string aFullFileName = aTmpDir + aFileName;
890 aCommand.sprintf("cp %s %s",
891 aFileInfo.filePath().latin1(),
892 aFullFileName.c_str());
893 if(system(aCommand) == -1) {
894 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
898 aSeq[0] = "copy_persistent";
899 aSeq[1] = aFileName.c_str();
902 aSeq[0] = "copy_persistent";
905 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false);
906 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
908 // Assign an ID = 1 the the type VISU::Result
912 SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
913 return aStreamFile._retn();
916 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
917 // The VISU component can paste only objects copied by VISU component
918 // and with the object type = 1
919 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1)
924 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
925 CORBA::Long theObjectID,
926 SALOMEDS::SObject_ptr theObject)
929 SALOMEDS::SObject_var aResultSO;
930 if (theObjectID != 1)
931 return aResultSO._retn();
933 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
934 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false);
936 ifstream stmIn((aTmpDir + string("copy_persistent")).c_str());
937 stmIn.seekg(0, ios::end);
938 int aLength = stmIn.tellg();
939 stmIn.seekg(0, ios::beg);
940 char* aString = new char[aLength+1];
941 stmIn.read(aString, aLength);
942 aString[aLength] = 0;
943 myIsMultiFile = false;
945 string aFileName(aTmpDir);
946 string aBasicFileName;
947 if(aSeq->length() > 1) {
948 aBasicFileName = aSeq[1].in();
949 aFileName += aBasicFileName;
952 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
953 SALOMEDS::Study_var aStudy = theObject->GetStudy();
954 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
955 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
957 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
958 aResultSO = aStudyBuilder->NewObject(aComponent);
960 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
962 //Just for Result::Restore to find the Comment attribute :(
963 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
965 Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
967 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
969 aSeqToRm[0] = "copy_persistent";
971 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true);
973 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
974 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
975 CORBA::String_var anIORValue(aStorable->GetID());
976 anIOR->SetValue(anIORValue);
977 return aResultSO._retn();