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 "utilities.h"
50 #include <TCollection_AsciiString.hxx>
51 #include <TColStd_SequenceOfAsciiString.hxx>
53 #include <omnithread.h>
54 #include CORBA_SERVER_HEADER(SALOME_Session)
55 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
58 #include <qfileinfo.h>
59 #include "Utils_ExceptHandlers.hxx"
63 static QFileInfo aFileInfo;
66 static int MYDEBUG = 1;
68 static int MYDEBUG = 0;
71 UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception);
73 extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB,
74 PortableServer::POA_ptr thePOA,
75 SALOME_NamingService* theNamingService,
78 if(MYDEBUG) MESSAGE("extern \"C\" GetImpl");
79 VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex);
80 //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this());
81 return aVISU_Gen->_this();
85 static string VisuTmpDir;
87 static CORBA::Boolean myIsMultiFile;
88 const CORBA::Boolean IsMultifile() { return myIsMultiFile;}
90 //===========================================================================
91 SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){
92 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU");
93 if (aSComponent->_is_nil()) {
94 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
95 aStudyBuilder->NewCommand();
96 int aLocked = theStudyDocument->GetProperties()->IsLocked();
97 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
98 aSComponent = aStudyBuilder->NewComponent("VISU");
99 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
100 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
102 //NRI aName->SetValue("Visu");
103 CORBA::ORB_var anORB = Base_i::GetORB();
104 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
105 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
106 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
107 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" );
108 if ( !Comp->_is_nil() ) {
109 aName->SetValue( Comp->componentusername() );
112 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
113 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
114 aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" );
116 VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this();
117 aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen);
118 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
119 aStudyBuilder->CommitCommand();
124 void RegistryStorable() {
125 Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore));
126 Storable::Registry(Mesh_i::myComment.c_str(),&(Restore<Mesh_i>));
127 Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore<ScalarMap_i>));
128 Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore<DeformedShape_i>));
129 Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore<CutPlanes_i>));
130 Storable::Registry(CutLines_i::myComment.c_str(),&(Restore<CutLines_i>));
131 Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore<IsoSurfaces_i>));
132 Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore<StreamLines_i>));
133 Storable::Registry(Vectors_i::myComment.c_str(),&(Restore<Vectors_i>));
134 Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore));
135 Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore));
136 Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore));
140 //===========================================================================
141 VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
142 SALOME_NamingService* theNamingService, QMutex* theMutex) :
143 Engines_Component_i()
145 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<<theMutex);
146 Base_i::myMutex = theMutex; //apo
147 Base_i::myOrb = CORBA::ORB::_duplicate(theORB);
148 Base_i::myPoa = PortableServer::POA::_duplicate(thePOA);
149 Base_i::myNamingService = theNamingService;
150 static SALOME_LifeCycleCORBA aEnginesLifeCycle(theNamingService);
151 Base_i::myEnginesLifeCycle = &aEnginesLifeCycle;
152 Base_i::myVisuGenImpl = this;
155 CORBA::Object_var anObj = myNamingService->Resolve("/myStudyManager");
156 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObj);
157 SALOMEDS::ListOfOpenStudies_var aListOfOpenStudies = aStudyManager->GetOpenStudies();
158 if(aListOfOpenStudies->length() > 0) {
159 CORBA::String_var aStudyName = aListOfOpenStudies[0];
160 //aFileInfo.setFile(aStudyName.in());
161 myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/);
163 if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!");
166 VISU_Gen_i::~VISU_Gen_i(){
167 if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i");
169 //===========================================================================
170 CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
171 const SALOMEDS::TMPFile & theStream,
176 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
177 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
178 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
179 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
180 VisuTmpDir = aTmpDir.ToCString();
181 SALOMEDS::ListOfFileNames_var aSeq =
182 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile);
183 myIsMultiFile = isMultiFile;
187 CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
188 const SALOMEDS::TMPFile & theStream,
192 return Load(theComponent, theStream, theURL, isMultiFile);
195 char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
196 const char* aLocalPersistentID,
197 CORBA::Boolean isMultiFile,
198 CORBA::Boolean isASCII)
200 CORBA::String_var aString("");
201 if(strcmp(aLocalPersistentID,"") != 0) {
203 Storable* aStorable =
204 Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID);
205 if(aStorable != NULL) aString = aStorable->GetID();
207 return aString._retn();
209 //===========================================================================
210 SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
215 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
216 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
217 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
219 TColStd_SequenceOfAsciiString aFileNames;
220 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
221 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
222 for (; itBig->More(); itBig->Next()) {
223 SALOMEDS::SObject_var gotBranch = itBig->Value();
224 CORBA::Object_var anObj = SObjectToObject(gotBranch);
225 if(CORBA::is_nil(anObj)) continue;
226 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
227 const Result_i::TSourceId& aSourceId = pResult->GetSourceId();
228 if(aSourceId == Result_i::eFile || aSourceId == Result_i::eRestoredFile){
229 const QFileInfo& aFileInfo = pResult->GetFileInfo();
231 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
232 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
233 static QString aCommand;
234 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
236 int aRes = system(aCommand);
238 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
241 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aCommand = "<<aCommand);
243 TCollection_AsciiString aString(strdup(aFileName.latin1()));
244 aFileNames.Append(aString);
248 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
249 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
250 if(aFileNames.Length() > 0){
251 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
252 aSeq->length(aFileNames.Length());
253 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
254 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
255 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
257 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
259 return aStreamFile._retn();
262 SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
267 const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str();
268 TCollection_AsciiString aTmpDir(const_cast<char*>(aDir));
269 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
271 TColStd_SequenceOfAsciiString aFileNames;
272 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
273 SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
274 for (; itBig->More(); itBig->Next()) {
275 SALOMEDS::SObject_var gotBranch = itBig->Value();
276 CORBA::Object_var anObj = SObjectToObject(gotBranch);
277 if(CORBA::is_nil(anObj)) continue;
278 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
279 const Result_i::TSourceId& aSourceId = pResult->GetSourceId();
280 if(aSourceId == Result_i::eFile || aSourceId == Result_i::eRestoredFile){
281 const QFileInfo& aFileInfo = pResult->GetFileInfo();
283 if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
284 QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
285 static QString aCommand;
286 aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
288 int aRes = system(aCommand);
290 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Can't execute the command :"<<aCommand);
293 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aCommand);
295 TCollection_AsciiString aString(strdup(aFileName.latin1()));
297 HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true);
299 aFileNames.Append(aString);
303 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
304 if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
305 if(aFileNames.Length() > 0){
306 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
307 aSeq->length(aFileNames.Length());
308 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
309 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
310 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
312 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
314 return aStreamFile._retn();
317 char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
318 const char* IORString,
319 CORBA::Boolean isMultiFile,
320 CORBA::Boolean isASCII)
322 CORBA::String_var aString(IORString);
323 if(strcmp(IORString,"") != 0){
324 CORBA::ORB_ptr anORB = GetORB();
325 CORBA::Object_var anObj = anORB->string_to_object(aString);
326 if(!CORBA::is_nil(anObj)){
327 if(Storable* pStorable = dynamic_cast<Storable*>(GetServant(anObj).in())){
329 aString = pStorable->ToString().c_str();
330 return aString._retn();
334 return aString._retn();
337 char* VISU_Gen_i::GetID(){
338 return Base_i::GetID();
341 void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){
342 if(!CORBA::is_nil(theStudy)){
343 CORBA::String_var aName = theStudy->Name();
344 MESSAGE("VISU_Gen_i::SetCurrentStudy - StudyId = "<<theStudy->StudyId()<<"; Name = '"<<aName.in()<<"'");
345 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
347 MESSAGE("VISU_Gen_i::SetCurrentStudy : CORBA::is_nil(theStudy)");
351 SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){
352 return SALOMEDS::Study::_duplicate(myStudyDocument);
355 ViewManager_ptr VISU_Gen_i::GetViewManager(){
357 ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument);
358 return ViewManager::_duplicate(aViewManager->_this());
361 SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){
362 if(myStudyDocument->GetProperties()->IsLocked())
363 return SALOMEDS::SObject::_nil();
365 SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument);
369 CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable,
370 const char* theFileName)
372 return VISU::ExportTableToFile(theTable, theFileName);
375 Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){
376 if(myStudyDocument->GetProperties()->IsLocked())
377 return Result::_nil();
379 aFileInfo.setFile(theFileName);
380 Result_i* pResult = new Result_i(myStudyDocument);
381 if(pResult->Create(theFileName) != NULL)
382 return pResult->_this();
384 pResult->_remove_ref();
385 return VISU::Result::_nil();
389 Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){
390 if(myStudyDocument->GetProperties()->IsLocked())
391 return Result::_nil();
393 VISU::Result_var aResult;
394 aFileInfo.setFile(theFileName);
395 Result_i* pResult = new Result_i(myStudyDocument,Result_i::eRestoredFile);
396 if(pResult->Create(theFileName) != NULL)
397 aResult = pResult->_this();
398 return aResult._retn();
401 Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject){
402 if(myStudyDocument->GetProperties()->IsLocked())
403 return Result::_nil();
405 Result_i* pResult = new Result_i(myStudyDocument);
406 if(pResult->Create(theMedSObject) != NULL)
407 return pResult->_this();
409 pResult->_remove_ref();
410 return VISU::Result::_nil();
414 Result_ptr VISU_Gen_i::ImportMedField(SALOME_MED::FIELD_ptr theField){
415 if(myStudyDocument->GetProperties()->IsLocked())
416 return Result::_nil();
418 Result_i* pResult = new Result_i(myStudyDocument);
419 if(pResult->Create(theField) != NULL)
420 return pResult->_this();
422 pResult->_remove_ref();
423 return VISU::Result::_nil();
427 Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult,
428 const char* theMeshName,
429 VISU::Entity theEntity)
431 if(myStudyDocument->GetProperties()->IsLocked())
434 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
435 Mesh_i* aPresent = new Mesh_i(pResult);
436 if(aPresent->Create(theMeshName,theEntity) != NULL)
437 return aPresent->_this();
439 aPresent->_remove_ref();
442 return VISU::Mesh::_nil();
445 Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult,
446 const char* theMeshName,
447 VISU::Entity theEntity,
448 const char* theFamilyName)
450 if(myStudyDocument->GetProperties()->IsLocked())
453 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
454 Mesh_i* aPresent = new Mesh_i(pResult);
455 if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL)
456 return aPresent->_this();
458 aPresent->_remove_ref();
461 return VISU::Mesh::_nil();
464 Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult,
465 const char* theMeshName,
466 const char* theGroupName)
468 if(myStudyDocument->GetProperties()->IsLocked())
471 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
472 Mesh_i* aPresent = new Mesh_i(pResult);
473 if(aPresent->Create(theMeshName,theGroupName) != NULL)
474 return aPresent->_this();
476 aPresent->_remove_ref();
479 return VISU::Mesh::_nil();
482 ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult,
483 const char* theMeshName,
484 VISU::Entity theEntity,
485 const char* theFieldName,
486 CORBA::Double theIteration)
488 return Prs3dOnField<VISU::ScalarMap_i>(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn();
491 DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult,
492 const char* theMeshName,
493 VISU::Entity theEntity,
494 const char* theFieldName,
495 CORBA::Double theIteration)
497 return Prs3dOnField<VISU::DeformedShape_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
500 Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult,
501 const char* theMeshName,
502 VISU::Entity theEntity,
503 const char* theFieldName,
504 CORBA::Double theIteration)
506 return Prs3dOnField<VISU::Vectors_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
509 IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult,
510 const char* theMeshName,
511 VISU::Entity theEntity,
512 const char* theFieldName,
513 CORBA::Double theIteration)
515 return Prs3dOnField<VISU::IsoSurfaces_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
518 StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult,
519 const char* theMeshName,
520 VISU::Entity theEntity,
521 const char* theFieldName,
522 CORBA::Double theIteration)
524 return Prs3dOnField<VISU::StreamLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
527 CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult,
528 const char* theMeshName,
529 VISU::Entity theEntity,
530 const char* theFieldName,
531 CORBA::Double theIteration)
533 return Prs3dOnField<VISU::CutPlanes_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
536 CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult,
537 const char* theMeshName,
538 VISU::Entity theEntity,
539 const char* theFieldName,
540 CORBA::Double theIteration)
542 return Prs3dOnField<VISU::CutLines_i>(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn();
545 Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){
546 if(myStudyDocument->GetProperties()->IsLocked())
547 return Table::_nil();
549 Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry);
550 if(pPresent->Create() != NULL)
551 return pPresent->_this();
553 pPresent->_remove_ref();
554 return VISU::Table::_nil();
558 Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable,
562 if(myStudyDocument->GetProperties()->IsLocked())
563 return Curve::_nil();
565 PortableServer::POA_ptr aPOA = GetPOA();
566 Table_i* pTable = dynamic_cast<Table_i*>(aPOA->reference_to_servant(theTable));
567 Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow);
568 if(pPresent->Create() != NULL)
569 return pPresent->_this();
571 pPresent->_remove_ref();
572 return VISU::Curve::_nil();
576 Container_ptr VISU_Gen_i::CreateContainer(){
577 if(myStudyDocument->GetProperties()->IsLocked())
578 return Container::_nil();
580 Container_i* pPresent = new Container_i(myStudyDocument);
581 if(pPresent->Create() != NULL)
582 return pPresent->_this();
584 pPresent->_remove_ref();
585 return VISU::Container::_nil();
589 Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){
590 if(myStudyDocument->GetProperties()->IsLocked())
591 return Animation::_nil();
593 if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){
594 return anAnim->_this();
596 return VISU::Animation::_nil();
599 void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){
602 char* VISU_Gen_i::ComponentDataType(){
603 return CORBA::string_dup("VISU");
606 bool VISU_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) {
607 Result_var aResultObj = Result::_narrow(theIOR);
608 return !(aResultObj->_is_nil());
611 SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
612 SALOMEDS::SObject_ptr theSObject,
613 CORBA::Object_ptr theObject,
615 throw (SALOME::SALOME_Exception)
617 Unexpect aCatch(SalomeException);
618 if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<<myMutex);
620 SALOMEDS::SObject_var aResultSO;
621 Result_i* aResultObj = dynamic_cast<Result_i*>(GetServant(theObject).in());
622 if (!aResultObj) return aResultSO._retn();
623 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
624 CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID();
625 aResultSO = theStudy->FindObjectID(anEntry);
626 return aResultSO._retn();
629 CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
631 SALOMEDS::GenericAttribute_var anAttr;
632 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
634 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
635 CORBA::String_var aValue = anIOR->Value();
636 if(strcmp(aValue,"") != 0){
637 CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue);
638 if (!CORBA::is_nil(anObj)){
639 Result_var aResultObj = Result::_narrow(anObj);
640 if(!aResultObj->_is_nil()){
641 if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(aResultObj).in())){
642 const Result_i::TSourceId& aSourceId = pResult->GetSourceId();
643 if(aSourceId == Result_i::eComponent || aSourceId == Result_i::eRestoredComponent)
644 if((pResult->GetFileInfo()).filePath() == "MED")
651 }catch(std::exception& exc){
652 INFOS("Follow exception was occured :\n"<<exc.what());
654 INFOS("Unknown exception was occured!");
659 SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
662 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
663 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
665 PortableServer::POA_ptr aPOA = GetPOA();
667 SALOMEDS::GenericAttribute_var anAttr;
668 if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL;
669 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
670 CORBA::Object_var aCorbaObj;
672 aCorbaObj = GetORB()->string_to_object(anIORAttr->Value());
674 aStreamFile->length(1);
675 aStreamFile[0] = strdup("E")[0];
676 return aStreamFile._retn();
678 if (CORBA::is_nil(aCorbaObj)) {
682 Storable* pStorable = dynamic_cast<Storable*>(GetServant(aCorbaObj).in());
687 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
688 string aCopyPersist = aTmpDir + "copy_persistent";
690 ofstream stmOut2(aCopyPersist.c_str(),ios::out);
691 string aStr = pStorable->ToString().c_str();
695 if (Result_i* aResultObj = dynamic_cast<Result_i*>(aPOA->reference_to_servant(aCorbaObj))) {
696 string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_";
697 if(strlen(aFileName.c_str()) == 1) aFileName="";
698 const QFileInfo& aFileInfo = aResultObj->GetFileInfo();
699 aFileName += aFileInfo.fileName().latin1();
700 static QString aCommand;
701 string aFullFileName = aTmpDir + aFileName;
702 aCommand.sprintf("cp %s %s",
703 aFileInfo.filePath().latin1(),
704 aFullFileName.c_str());
705 if(system(aCommand) == -1) {
706 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand);
710 aSeq[0] = "copy_persistent";
711 aSeq[1] = aFileName.c_str();
714 aSeq[0] = "copy_persistent";
717 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false);
718 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
720 // Assign an ID = 1 the the type VISU::Result
724 SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU");
725 return aStreamFile._retn();
728 CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
729 // The VISU component can paste only objects copied by VISU component
730 // and with the object type = 1
731 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1)
736 SALOMEDS::SObject_ptr VISU_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
737 CORBA::Long theObjectID,
738 SALOMEDS::SObject_ptr theObject)
741 SALOMEDS::SObject_var aResultSO;
742 if (theObjectID != 1)
743 return aResultSO._retn();
745 string aTmpDir = SALOMEDS_Tool::GetTmpDir();
746 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false);
748 ifstream stmIn((aTmpDir + string("copy_persistent")).c_str());
749 stmIn.seekg(0, ios::end);
750 int aLength = stmIn.tellg();
751 stmIn.seekg(0, ios::beg);
752 char* aString = new char[aLength+1];
753 stmIn.read(aString, aLength);
754 aString[aLength] = 0;
755 myIsMultiFile = false;
757 string aFileName(aTmpDir);
758 string aBasicFileName;
759 if(aSeq->length() > 1) {
760 aBasicFileName = aSeq[1].in();
761 aFileName += aBasicFileName;
764 SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent();
765 SALOMEDS::Study_var aStudy = theObject->GetStudy();
766 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
767 CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID());
769 if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject
770 aResultSO = aStudyBuilder->NewObject(aComponent);
772 aResultSO = SALOMEDS::SObject::_duplicate(theObject);
774 //Just for Result::Restore to find the Comment attribute :(
775 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
777 Storable* aStorable = Storable::Create(aResultSO,aFileName,aString);
779 SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames;
781 aSeqToRm[0] = "copy_persistent";
783 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true);
785 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
786 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
787 CORBA::String_var anIORValue(aStorable->GetID());
788 anIOR->SetValue(anIORValue);
789 return aResultSO._retn();