1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_Gen_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_Gen_i.hh"
28 #include "VISU_Result_i.hh"
29 #include "VISU_PrsObject_i.hh"
30 #include "VISU_ViewManager_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Mesh_i.hh"
34 #include "VISU_ScalarMap_i.hh"
35 #include "VISU_IsoSurfaces_i.hh"
36 #include "VISU_DeformedShape_i.hh"
37 #include "VISU_CutPlanes_i.hh"
38 #include "VISU_CutLines_i.hh"
39 #include "VISU_Vectors_i.hh"
40 #include "VISU_StreamLines_i.hh"
41 #include "VISU_Table_i.hh"
42 #include "VISU_TimeAnimation.h"
44 #include "HDFascii.hxx"
45 #include "SALOMEDS_Tool.hxx"
47 #include "SALOMEDSClient_AttributeName.hxx"
48 #include "SALOMEDSClient_AttributePixMap.hxx"
50 #include "utilities.h"
53 #include <TCollection_AsciiString.hxx>
54 #include <TColStd_SequenceOfAsciiString.hxx>
56 #include <omnithread.h>
57 #include CORBA_SERVER_HEADER(SALOME_Session)
58 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
61 #include <qfileinfo.h>
62 #include "Utils_ExceptHandlers.hxx"
66 static QFileInfo aFileInfo;
69 static int MYDEBUG = 1;
71 static int MYDEBUG = 0;
74 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
76 extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB,
77 PortableServer::POA_ptr thePOA,
78 SALOME_NamingService* theNamingService,
81 if(MYDEBUG) MESSAGE("extern \"C\" GetImpl");
82 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
83 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
84 return aVISU_Gen->_this();
88 static string VisuTmpDir;
90 static CORBA::Boolean myIsMultiFile;
91 const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
93 //===========================================================================
94 _PTR(SComponent) ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument)
96 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU");
98 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
99 aStudyBuilder->NewCommand();
100 int aLocked = theStudyDocument->GetProperties()->IsLocked();
101 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
102 aSComponent = aStudyBuilder->NewComponent("VISU");
103 _PTR(GenericAttribute) anAttr =
104 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
105 _PTR(AttributeName) aName (anAttr);
107 CORBA::ORB_var anORB = Base_i::GetORB();
108 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
109 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
110 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
111 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
112 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
113 if (!Comp->_is_nil()) {
114 aName->SetValue(Comp->componentusername());
117 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
118 _PTR(AttributePixMap) aPixmap (anAttr);
119 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
121 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
122 aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID());
123 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
124 aStudyBuilder->CommitCommand();
129 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
130 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
131 if (aSComponent->_is_nil()) {
132 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
133 aStudyBuilder->NewCommand();
134 int aLocked = theStudyDocument->GetProperties()->IsLocked();
135 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
136 aSComponent = aStudyBuilder->NewComponent("VISU");
137 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
138 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
140 //NRI aName->SetValue("Visu");
141 CORBA::ORB_var anORB = Base_i::GetORB();
142 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
143 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
144 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
145 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
146 if ( !Comp->_is_nil() ) {
147 aName->SetValue( Comp->componentusername() );
150 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
151 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
152 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
154 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
155 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
156 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
157 aStudyBuilder->CommitCommand();
162 void RegistryStorable() {
163 Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore));
164 Storable::Registry(Mesh_i::myComment.c_str(),&(Restore<Mesh_i>));
165 Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore<ScalarMap_i>));
166 Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore<DeformedShape_i>));
167 Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore<CutPlanes_i>));
168 Storable::Registry(CutLines_i::myComment.c_str(),&(Restore<CutLines_i>));
169 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore<IsoSurfaces_i>));
170 Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore<StreamLines_i>));
171 Storable::Registry(Vectors_i::myComment.c_str(),&(Restore<Vectors_i>));
172 Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore));
173 Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore));
174 Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore));
178 //===========================================================================
179 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
180 SALOME_NamingService* theNamingService, QMutex* theMutex) :
181 Engines_Component_i()
183 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
184 Base_i::myMutex = theMutex; //apo
185 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
186 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
187 Base_i::myNamingService = theNamingService;
188 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
189 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
190 Base_i::myVisuGenImpl = this;
193 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
194 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
195 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
196 if(aListOfOpenStudies->length() > 0) {
197 CORBA::String_var aStudyName = aListOfOpenStudies[0];
198 //aFileInfo.setFile(aStudyName.in());
199 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
201 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
204 VISU_Gen_i::~VISU_Gen_i(){
205 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
207 //===========================================================================
208 CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
209 const SALOMEDS::TMPFile & theStream,
214 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
215 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
216 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
217 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
218 VisuTmpDir = aTmpDir.ToCString();
219 SALOMEDS::ListOfFileNames_var aSeq =
220 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
221 myIsMultiFile = isMultiFile;
225 CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
226 const SALOMEDS::TMPFile & theStream,
230 return Load(theComponent, theStream, theURL, isMultiFile);
233 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
234 const char* aLocalPersistentID,
235 CORBA::Boolean isMultiFile,
236 CORBA::Boolean isASCII)
238 CORBA::String_var aString("");
239 if(strcmp(aLocalPersistentID,"") != 0) {
241 Storable* aStorable =
242 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
243 if(aStorable != NULL) aString = aStorable->GetID();
245 return aString._retn();
247 //===========================================================================
248 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
253 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
254 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
255 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
257 TColStd_SequenceOfAsciiString aFileNames;
258 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
260 //CORBA::Boolean anIsValidScript;
261 //Engines::TMPFile_var aDump = DumpPython(aStudy,false,anIsValidScript);
263 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
264 for (; itBig->More(); itBig->Next()) {
265 SALOMEDS::SObject_var gotBranch = itBig->Value();
266 CORBA::Object_var anObj = SObjectToObject(gotBranch);
267 if(CORBA::is_nil(anObj)) continue;
268 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
269 switch(pResult->GetCreationId()){
270 case Result_i::eImportFile:
271 case Result_i::eCopyAndImportFile: {
272 const QFileInfo& aFileInfo = pResult->GetFileInfo();
274 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
275 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
276 static QString aCommand;
277 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
279 int aRes = system(aCommand);
281 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
284 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aCommand = "<<aCommand);
286 TCollection_AsciiString aString(strdup(aFileName.latin1()));
287 aFileNames.Append(aString);
291 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
292 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
293 if(aFileNames.Length() > 0){
294 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
295 aSeq->length(aFileNames.Length());
296 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
297 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
298 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
300 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
302 return aStreamFile._retn();
305 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
310 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
311 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
312 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
314 TColStd_SequenceOfAsciiString aFileNames;
315 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
316 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
317 for (; itBig->More(); itBig->Next()) {
318 SALOMEDS::SObject_var gotBranch = itBig->Value();
319 CORBA::Object_var anObj = SObjectToObject(gotBranch);
320 if(CORBA::is_nil(anObj)) continue;
321 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
322 switch(pResult->GetCreationId()){
323 case Result_i::eImportFile:
324 case Result_i::eCopyAndImportFile: {
325 const QFileInfo& aFileInfo = pResult->GetFileInfo();
327 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
328 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
329 static QString aCommand;
330 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
332 int aRes = system(aCommand);
334 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Can't execute the command :"<<aCommand);
337 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
339 TCollection_AsciiString aString(strdup(aFileName.latin1()));
341 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
343 aFileNames.Append(aString);
347 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
348 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
349 if(aFileNames.Length() > 0){
350 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
351 aSeq->length(aFileNames.Length());
352 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
353 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
354 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
356 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
358 return aStreamFile._retn();
361 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
362 const char* IORString,
363 CORBA::Boolean isMultiFile,
364 CORBA::Boolean isASCII)
366 CORBA::String_var aString(IORString);
367 if(strcmp(IORString,"") != 0){
368 CORBA::ORB_ptr anORB = GetORB();
369 CORBA::Object_var anObj = anORB->string_to_object(aString);
370 if(!CORBA::is_nil(anObj)){
371 if(Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
373 aString = pStorable->ToString().c_str();
374 return aString._retn();
378 return aString._retn();
381 char* VISU_Gen_i::GetID(){
382 return Base_i::GetID();
385 void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
386 if(!CORBA::is_nil(theStudy)){
387 CORBA::String_var aName = theStudy->Name();
388 MESSAGE("VISU_Gen_i::SetCurrentStudy - StudyId = "<<theStudy->StudyId()<<"; Name = '"<<aName.in()<<"'");
389 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
391 MESSAGE("VISU_Gen_i::SetCurrentStudy : CORBA::is_nil(theStudy)");
395 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
396 return SALOMEDS::Study::_duplicate(myStudyDocument);
399 ViewManager_ptr VISU_Gen_i::GetViewManager(){
401 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
402 return ViewManager::_duplicate(aViewManager->_this());
405 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
406 if(myStudyDocument->GetProperties()->IsLocked())
407 return SALOMEDS::SObject::_nil();
409 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
413 CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
414 const char* theFileName)
416 return VISU::ExportTableToFile(theTable, theFileName);
419 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
420 if(myStudyDocument->GetProperties()->IsLocked())
421 return Result::_nil();
423 aFileInfo.setFile(theFileName);
424 Result_i* pResult = new Result_i(myStudyDocument,
426 Result_i::eImportFile);
427 if(pResult->Create(theFileName) != NULL)
428 return pResult->_this();
430 pResult->_remove_ref();
431 return VISU::Result::_nil();
435 Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){
436 if(myStudyDocument->GetProperties()->IsLocked())
437 return Result::_nil();
439 VISU::Result_var aResult;
440 aFileInfo.setFile(theFileName);
441 Result_i* pResult = new Result_i(myStudyDocument,
442 Result_i::eRestoredFile,
443 Result_i::eCopyAndImportFile);
444 if(pResult->Create(theFileName) != NULL)
445 aResult = pResult->_this();
446 return aResult._retn();
449 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject){
450 if(myStudyDocument->GetProperties()->IsLocked())
451 return Result::_nil();
453 Result_i* pResult = new Result_i(myStudyDocument,
454 Result_i::eComponent,
455 Result_i::eImportMed);
456 if(pResult->Create(theMedSObject) != NULL)
457 return pResult->_this();
459 pResult->_remove_ref();
460 return VISU::Result::_nil();
464 Result_ptr VISU_Gen_i::ImportMedField(SALOME_MED::FIELD_ptr theField){
465 if(myStudyDocument->GetProperties()->IsLocked())
466 return Result::_nil();
468 Result_i* pResult = new Result_i(myStudyDocument,
469 Result_i::eComponent,
470 Result_i::eImportMedField);
471 if(pResult->Create(theField) != NULL)
472 return pResult->_this();
474 pResult->_remove_ref();
475 return VISU::Result::_nil();
479 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult,
480 const char* theMeshName,
481 VISU::Entity theEntity)
483 if(myStudyDocument->GetProperties()->IsLocked())
486 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
487 Mesh_i* aPresent = new Mesh_i(pResult);
488 if(aPresent->Create(theMeshName,theEntity) != NULL)
489 return aPresent->_this();
491 aPresent->_remove_ref();
494 return VISU::Mesh::_nil();
497 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult,
498 const char* theMeshName,
499 VISU::Entity theEntity,
500 const char* theFamilyName)
502 if(myStudyDocument->GetProperties()->IsLocked())
505 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
506 Mesh_i* aPresent = new Mesh_i(pResult);
507 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
508 return aPresent->_this();
510 aPresent->_remove_ref();
513 return VISU::Mesh::_nil();
516 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult,
517 const char* theMeshName,
518 const char* theGroupName)
520 if(myStudyDocument->GetProperties()->IsLocked())
523 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
524 Mesh_i* aPresent = new Mesh_i(pResult);
525 if(aPresent->Create(theMeshName,theGroupName) != NULL)
526 return aPresent->_this();
528 aPresent->_remove_ref();
531 return VISU::Mesh::_nil();
534 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult,
535 const char* theMeshName,
536 VISU::Entity theEntity,
537 const char* theFieldName,
538 CORBA::Double theIteration)
540 return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
543 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult,
544 const char* theMeshName,
545 VISU::Entity theEntity,
546 const char* theFieldName,
547 CORBA::Double theIteration)
549 return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
552 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult,
553 const char* theMeshName,
554 VISU::Entity theEntity,
555 const char* theFieldName,
556 CORBA::Double theIteration)
558 return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
561 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult,
562 const char* theMeshName,
563 VISU::Entity theEntity,
564 const char* theFieldName,
565 CORBA::Double theIteration)
567 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
570 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult,
571 const char* theMeshName,
572 VISU::Entity theEntity,
573 const char* theFieldName,
574 CORBA::Double theIteration)
576 return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
579 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult,
580 const char* theMeshName,
581 VISU::Entity theEntity,
582 const char* theFieldName,
583 CORBA::Double theIteration)
585 return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
588 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult,
589 const char* theMeshName,
590 VISU::Entity theEntity,
591 const char* theFieldName,
592 CORBA::Double theIteration)
594 return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
597 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
598 if(myStudyDocument->GetProperties()->IsLocked())
599 return Table::_nil();
601 Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry);
602 if(pPresent->Create() != NULL)
603 return pPresent->_this();
605 pPresent->_remove_ref();
606 return VISU::Table::_nil();
610 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable,
614 if(myStudyDocument->GetProperties()->IsLocked())
615 return Curve::_nil();
617 PortableServer::POA_ptr aPOA = GetPOA();
618 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
619 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
620 if(pPresent->Create() != NULL)
621 return pPresent->_this();
623 pPresent->_remove_ref();
624 return VISU::Curve::_nil();
628 Container_ptr VISU_Gen_i::CreateContainer(){
629 if(myStudyDocument->GetProperties()->IsLocked())
630 return Container::_nil();
632 Container_i* pPresent = new Container_i(myStudyDocument);
633 if(pPresent->Create() != NULL)
634 return pPresent->_this();
636 pPresent->_remove_ref();
637 return VISU::Container::_nil();
641 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
642 if(myStudyDocument->GetProperties()->IsLocked())
643 return Animation::_nil();
645 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
646 return anAnim->_this();
648 return VISU::Animation::_nil();
651 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
654 char* VISU_Gen_i::ComponentDataType(){
655 return CORBA::string_dup("VISU");
658 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
659 Result_var aResultObj = Result::_narrow(theIOR);
660 return !(aResultObj->_is_nil());
663 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
664 SALOMEDS::SObject_ptr theSObject,
665 CORBA::Object_ptr theObject,
667 throw (SALOME::SALOME_Exception)
669 Unexpect aCatch(SalomeException);
670 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
672 SALOMEDS::SObject_var aResultSO;
673 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
674 if (!aResultObj) return aResultSO._retn();
675 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
676 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
677 aResultSO = theStudy->FindObjectID(anEntry);
678 return aResultSO._retn();
681 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
683 SALOMEDS::GenericAttribute_var anAttr;
684 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
686 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
687 CORBA::String_var aValue = anIOR->Value();
688 if(strcmp(aValue,"") != 0){
689 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
690 if (!CORBA::is_nil(anObj)){
691 Result_var aResultObj = Result::_narrow(anObj);
692 if(!aResultObj->_is_nil()){
693 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj).in())){
694 switch(pResult->GetCreationId()){
695 case Result_i::eImportFile:
696 case Result_i::eCopyAndImportFile:
703 }catch(std::exception& exc){
704 INFOS("Follow exception was occured :\n"<<exc.what());
706 INFOS("Unknown exception was occured!");
711 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
714 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
715 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
717 PortableServer::POA_ptr aPOA = GetPOA();
719 SALOMEDS::GenericAttribute_var anAttr;
720 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
721 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
722 CORBA::Object_var aCorbaObj;
724 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
726 aStreamFile->length(1);
727 aStreamFile[0] = strdup("E")[0];
728 return aStreamFile._retn();
730 if (CORBA::is_nil(aCorbaObj)) {
734 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj).in());
739 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
740 string aCopyPersist = aTmpDir + "copy_persistent";
742 ofstream stmOut2(aCopyPersist.c_str(),ios::out);
743 string aStr = pStorable->ToString().c_str();
747 if (Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj))) {
748 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
749 if(strlen(aFileName.c_str()) == 1) aFileName="";
750 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
751 aFileName += aFileInfo.fileName().latin1();
752 static QString aCommand;
753 string aFullFileName = aTmpDir + aFileName;
754 aCommand.sprintf("cp %s %s",
755 aFileInfo.filePath().latin1(),
756 aFullFileName.c_str());
757 if(system(aCommand) == -1) {
758 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
762 aSeq[0] = "copy_persistent";
763 aSeq[1] = aFileName.c_str();
766 aSeq[0] = "copy_persistent";
769 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false);
770 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
772 // Assign an ID = 1 the the type VISU::Result
776 SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
777 return aStreamFile._retn();
780 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
781 // The VISU component can paste only objects copied by VISU component
782 // and with the object type = 1
783 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1)
788 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
789 CORBA::Long theObjectID,
790 SALOMEDS::SObject_ptr theObject)
793 SALOMEDS::SObject_var aResultSO;
794 if (theObjectID != 1)
795 return aResultSO._retn();
797 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
798 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false);
800 ifstream stmIn((aTmpDir + string("copy_persistent")).c_str());
801 stmIn.seekg(0, ios::end);
802 int aLength = stmIn.tellg();
803 stmIn.seekg(0, ios::beg);
804 char* aString = new char[aLength+1];
805 stmIn.read(aString, aLength);
806 aString[aLength] = 0;
807 myIsMultiFile = false;
809 string aFileName(aTmpDir);
810 string aBasicFileName;
811 if(aSeq->length() > 1) {
812 aBasicFileName = aSeq[1].in();
813 aFileName += aBasicFileName;
816 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
817 SALOMEDS::Study_var aStudy = theObject->GetStudy();
818 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
819 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
821 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
822 aResultSO = aStudyBuilder->NewObject(aComponent);
824 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
826 //Just for Result::Restore to find the Comment attribute :(
827 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
829 Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
831 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
833 aSeqToRm[0] = "copy_persistent";
835 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true);
837 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
838 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
839 CORBA::String_var anIORValue(aStorable->GetID());
840 anIOR->SetValue(anIORValue);
841 return aResultSO._retn();