]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_Result_i.cc
Salome HOME
IPAL21489 Filter by Scalars... does not show visible elements for some presentations.
[modules/visu.git] / src / VISU_I / VISU_Result_i.cc
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_Result_i.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26 //
27 #include "VISU_MultiResult_i.hh"
28 #include "VISU_ResultUtils.hh"
29 #include "VISU_Prs3d_i.hh"
30
31 #include "VISU_Convertor_impl.hxx"
32 #include "VISU_CorbaMedConvertor.hxx"
33 #include "VISU_ConvertorUtils.hxx"
34 #include "VISU_PipeLine.hxx"
35
36 #include "SUIT_ResourceMgr.h"
37
38 #include "SALOMEDS_Tool.hxx"
39 #include "HDFascii.hxx"
40
41 #include "SUIT_Session.h"
42 #include "SALOME_Event.h"
43 #include "SalomeApp_Study.h"
44 #include "SalomeApp_Application.h"
45
46 #include "MED_Factory.hxx"
47
48 #include <boost/thread/thread.hpp>
49 #include <boost/bind.hpp>
50
51 // QT Includes
52 #include <QString>
53 #include <QFileInfo>
54 #include <QSemaphore>
55 #include <QThread>
56 #include <QDir>
57 #include <QList>
58
59 // VTK Includes
60 #include <vtkCell.h>
61 #include <vtkUnstructuredGrid.h>
62
63 // OCCT Includes
64 #include <Bnd_Box.hxx>
65
66 #ifdef _DEBUG_
67 static int MYDEBUG = 1;
68 #else
69 static int MYDEBUG = 0;
70 #endif
71
72 using namespace std;
73
74 namespace VISU
75 {
76   //---------------------------------------------------------------
77   Result_var 
78   FindResult(SALOMEDS::SObject_ptr theSObject)
79   {
80     SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent();
81     SALOMEDS::SObject_var aFather = theSObject->GetFather();
82     CORBA::String_var aComponentID (aSComponent->GetID());
83     CORBA::String_var aFatherID    (aFather->GetID());
84     Result_var aResult;
85     while (strcmp(aComponentID, aFatherID) != 0) {
86       CORBA::Object_var anObject = SObjectToObject(aFather);
87       if (!CORBA::is_nil(anObject)) {
88         aResult = Result::_narrow(anObject);
89         if (!aResult->_is_nil()) return aResult;
90       }
91       aFather = aFather->GetFather();
92       aFatherID = aFather->GetID();
93     }
94     return aResult;
95   }
96
97
98   //---------------------------------------------------------------
99   Result_i* 
100   GetResult(SALOMEDS::Study_ptr theStudy,
101             const std::string& theResultEntry)
102   {
103     if(CORBA::is_nil(theStudy))
104       return NULL;
105
106     SALOMEDS::SObject_var aSObject = theStudy->FindObjectID(theResultEntry.c_str());
107     CORBA::Object_var anObject = SObjectToObject(aSObject);
108     return dynamic_cast<VISU::Result_i*>(GetServant(anObject).in());
109   }
110
111
112   //---------------------------------------------------------------
113   std::string
114   GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
115   {
116     SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
117     CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
118     return aDataType.in();
119   }
120
121
122   //---------------------------------------------------------------
123   void
124   CreateReference (SALOMEDS::Study_ptr theStudyDocument,
125                    const string& theFatherEntry, 
126                    const string& theRefEntry)
127   {
128     SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
129     SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
130     SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather);
131     SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str());
132     aStudyBuilder->Addreference(newObj,aRefSObj);
133   }
134
135
136 //---------------------------------------------------------------
137 }
138
139
140 //---------------------------------------------------------------
141 const string VISU::Result_i::myComment = "RESULT";
142 const char* VISU::Result_i::GetComment() const { return myComment.c_str();}
143
144 //---------------------------------------------------------------
145 VISU::Result_i
146 ::Result_i(SALOMEDS::Study_ptr theStudy,
147            const ESourceId& theSourceId,
148            const ECreationId& theCreationId,
149            CORBA::Boolean theIsBuildImmediately,
150            CORBA::Boolean theIsBuildFields,
151            CORBA::Boolean theIsBuildMinMax,
152            CORBA::Boolean theIsBuildGroups):
153   myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
154   myCreationId(theCreationId),
155   mySourceId(theSourceId),
156   myIsBuildImmediately(theIsBuildImmediately),
157   myIsBuildFields(theIsBuildFields),
158   myIsBuildMinMax(theIsBuildMinMax),
159   myIsBuildGroups(theIsBuildGroups),
160   myIsEntitiesDone(false),
161   myIsFieldsDone(false),
162   myIsGroupsDone(false),
163   myIsMinMaxDone(false),
164   myIsAllDone(false),
165   myIsBuildParts(false),
166   myIsPartsDone(false)
167 {
168   if(MYDEBUG) MESSAGE("Result_i::Result_i - this = "<<this);
169   myStudy = VISU::GetStudy(myStudyDocument);
170 }
171
172
173 //---------------------------------------------------------------
174 VISU::Result_i
175 ::Result_i():
176   myIsEntitiesDone(false),
177   myIsFieldsDone(false),
178   myIsGroupsDone(false),
179   myIsMinMaxDone(false),
180   myIsAllDone(false),
181   myIsBuildParts(false),
182   myIsPartsDone(false)
183 {
184   if(MYDEBUG) MESSAGE("Result_i::Result_i - this = "<<this);
185 }
186
187
188 //---------------------------------------------------------------
189 VISU::Result_i
190 ::~Result_i()
191 {
192   MESSAGE("Result_i::~Result_i() - this = "<<this);
193   if (GetSourceId() == eRestoredFile) 
194     VISU::RemoveFile(myFileInfo.filePath().toLatin1().data());
195 }
196
197
198 //---------------------------------------------------------------
199 void
200 VISU::Result_i
201 ::RemoveFromStudy()
202 {
203   struct TRemoveFromStudy: public SALOME_Event
204   {
205     VISU::Result_i* myRemovable;
206     TRemoveFromStudy(VISU::Result_i* theRemovable):
207       myRemovable(theRemovable)
208     {}
209     
210     virtual
211     void
212     Execute()
213     {
214       VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
215       myRemovable->Destroy();
216     }
217   };
218
219   // Remove the result with all presentations and other possible sub-objects
220   ProcessVoidEvent(new TRemoveFromStudy(this));
221 }
222
223
224 //---------------------------------------------------------------
225 void 
226 VISU::Result_i
227 ::ConnectObserver(TResultObserver* theObserver,
228                   boost::signalslib::connection& theConnection)
229 {
230   if(theConnection.connected())
231     theConnection.disconnect();
232
233   theConnection = 
234     myUpdateObserverSignal.connect(boost::bind(boost::bind(&TResultObserver::UpdateFromResult, 
235                                                            theObserver, 
236                                                            _1),
237                                                this));
238 }
239
240
241 //---------------------------------------------------------------
242 void 
243 VISU::Result_i
244 ::UpdateObservers()
245 {
246   struct TEvent: public SALOME_Event
247   {
248     VISU::Result_i::TUpdateObserverSignal& myUpdateObserverSignal;
249
250     TEvent(VISU::Result_i::TUpdateObserverSignal& theUpdateObserverSignal):
251       myUpdateObserverSignal(theUpdateObserverSignal)
252     {}
253     
254     virtual
255     void
256     Execute()
257     {
258       myUpdateObserverSignal();
259     }
260   };
261
262   ProcessVoidEvent(new TEvent(myUpdateObserverSignal));
263 }
264
265
266 //---------------------------------------------------------------
267 size_t
268 VISU::Result_i
269 ::IsPossible()
270 {
271   try{
272     size_t aSize = myInput->GetSize();
273     size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
274     MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
275     return aResult;
276   }catch(std::exception& exc){
277     INFOS("Follow exception was occured :\n"<<exc.what());
278   }catch(...){
279     INFOS("Unknown exception was occured!");
280   }
281   return 0;
282 }
283
284
285 //---------------------------------------------------------------
286 CORBA::Boolean
287 VISU::Result_i
288 ::BuildAll()
289 {
290   if(MYDEBUG) MESSAGE("Result_i::Build - myIsAllDone = "<<myIsAllDone);
291   if(myIsAllDone) 
292     return 1;
293   if(!IsPossible()) 
294     return 0;
295   try{
296     const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
297     VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
298     for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
299       const string& aMeshName = aMeshMapIter->first;
300       const VISU::PMesh aMesh = aMeshMapIter->second;
301       const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
302       VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
303       //Import fields
304       aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
305       for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
306         const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
307         const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
308         const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
309         VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
310         for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
311           const string& aFieldName = aFieldMapIter->first;
312           const VISU::PField aField = aFieldMapIter->second;
313           const VISU::TValField& aValField = aField->myValField;
314           VISU::TValField::const_iterator aValFieldIter = aValField.begin();
315           for(; aValFieldIter != aValField.end(); aValFieldIter++){
316             int aTimeStamp = aValFieldIter->first;
317             try{
318               myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
319             }catch(std::exception& exc){
320               INFOS("Follow exception was occured :\n"<<exc.what());
321             }catch(...){
322               INFOS("Unknown exception was occured!!!");
323             }
324           }
325         }
326         //Importing groups
327         const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
328         VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
329         for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
330           const string& aGroupName = aGroupMapIter->first;
331           try{
332             myInput->GetMeshOnGroup(aMeshName,aGroupName);
333           }catch(std::exception& exc){
334             INFOS("Follow exception was occured :\n"<<exc.what());
335           }catch(...){
336             INFOS("Unknown exception was occured!!!");
337           }
338         }
339         //Import families
340         const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
341         VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
342         for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
343           const string& aFamilyName = aFamilyMapIter->first;
344           try{
345             myInput->GetFamilyOnEntity(aMeshName,anEntity,aFamilyName);
346           }catch(std::exception& exc){
347             INFOS("Follow exception was occured :\n"<<exc.what());
348           }catch(...){
349             INFOS("Unknown exception was occured!!!");
350           }
351         }
352         //Import mesh on entity
353         try{
354           myInput->GetMeshOnEntity(aMeshName,anEntity);
355         }catch(std::exception& exc){
356           INFOS("Follow exception was occured :\n"<<exc.what());
357         }catch(...){
358           INFOS("Unknown exception was occured!!!");
359         }
360       }
361     }
362     myIsAllDone = 1;
363   }catch(std::exception& exc){
364     INFOS("Follow exception was occured :\n"<<exc.what());
365   }catch(...){
366     INFOS("Unknown exception was occured!!!");
367   }
368   return myIsAllDone;
369 }
370
371
372 //---------------------------------------------------------------
373 CORBA::Boolean
374 VISU::Result_i
375 ::Build(CORBA::Boolean theIsBuildAll,
376         CORBA::Boolean theIsAtOnce)
377 {
378   if(theIsBuildAll)
379     theIsAtOnce = true;
380
381   if(Build(SALOMEDS::SObject::_nil(), theIsAtOnce)){
382     
383     // Set icon
384     SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
385
386     SALOMEDS::GenericAttribute_var anAttr;
387     SALOMEDS::AttributePixMap_var  aPixmap;
388     
389     anAttr  = aStudyBuilder->FindOrCreateAttribute( mySObject, "AttributePixMap" );
390     aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
391     aPixmap ->SetPixMap("ICON_TREE_RESULT");
392
393     if(theIsBuildAll)
394       return BuildAll();
395     return true;
396   }
397   
398   return false;
399 }
400
401
402 //---------------------------------------------------------------
403 VISU::Storable* VISU::Result_i::Build(SALOMEDS::SObject_ptr theSObject,
404                                       CORBA::Boolean theIsAtOnce)
405 {
406   if(!myInput)
407     return NULL;
408
409   if(IsDone())
410     return this;
411
412   mySComponent = FindOrCreateVisuComponent(myStudyDocument);
413   CORBA::String_var aSComponentEntry = mySComponent->GetID();
414   CORBA::String_var anIOR(GetID());
415   QString aComment;
416   aComment.sprintf("myComment=%s;myFileName=%s;myInitFileName=%s",
417                    GetComment(),
418                    myFileInfo.filePath().toLatin1().data(),
419                    GetInitFileName().c_str()); // Restoring of Python dump
420   std::string aResultEntry = 
421     CreateAttributes(myStudy,
422                      aSComponentEntry.in(),
423                      NO_ICON,
424                      anIOR.in(),
425                      GetName(),
426                      NO_PERFSITENT_REF,
427                      aComment.toLatin1().data(),
428                      true);
429   mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
430   if(!CORBA::is_nil(theSObject)){
431     CORBA::String_var aString = theSObject->GetID();
432     CreateReference(myStudyDocument, aResultEntry, aString.in());
433   }
434
435   if(theIsAtOnce){
436     BuildEntities(this,
437                   myInput,
438                   &myIsEntitiesDone,
439                   aResultEntry,
440                   theIsAtOnce,
441                   myIsBuildGroups,
442                   myIsBuildFields,
443                   myIsBuildParts,
444                   myStudy);
445     
446     BuildGroups(this,
447                 myInput,
448                 &myIsGroupsDone,
449                 myIsBuildGroups,
450                 theIsAtOnce,
451                 myStudy);
452
453     BuildFieldDataTree(this,
454                        myInput,
455                        &myIsFieldsDone,
456                        myIsBuildFields,
457                        &myIsMinMaxDone,
458                        myIsBuildMinMax,
459                        myStudy);
460   } else {
461     boost::thread aThread(boost::bind(boost::bind(&Result_i::BuildDataTree, this, _1),
462                                       aResultEntry));
463   }
464
465   return this;
466 }
467
468
469 //---------------------------------------------------------------
470 void
471 VISU::Result_i
472 ::BuildDataTree(const std::string& theResultEntry)
473 {
474   BuildEntities(this,
475                 myInput,
476                 &myIsEntitiesDone,
477                 theResultEntry,
478                 false,
479                 myIsBuildGroups,
480                 myIsBuildFields,
481                 myIsBuildParts,
482                 myStudy);
483
484   {
485     boost::thread aThread(boost::bind(&BuildGroups,
486                                       this,
487                                       myInput,
488                                       &myIsGroupsDone,
489                                       myIsBuildGroups,
490                                       false,
491                                       myStudy));
492   }
493   {
494     boost::thread aThread(boost::bind(&BuildFieldDataTree,
495                                       this,
496                                       myInput,
497                                       &myIsFieldsDone,
498                                       myIsBuildFields,
499                                       &myIsMinMaxDone,
500                                       myIsBuildMinMax,
501                                       myStudy));
502   }
503 }
504
505 //---------------------------------------------------------------
506 VISU::Storable*
507 VISU::Result_i
508 ::BuildAll(SALOMEDS::SObject_ptr theSObject)
509 {
510   if(MYDEBUG) MESSAGE("Result_i::Build");
511   try{
512     Build(theSObject);
513     BuildAll();
514   }catch(std::exception& exc){
515     INFOS("Follow exception was occured :\n"<<exc.what());
516     return NULL;
517   }catch(...){
518     INFOS("Unknown exception was occured!!!");
519     return NULL;
520   }
521
522   return this;
523 }
524
525
526 //---------------------------------------------------------------
527 VISU::Storable*
528 VISU::Result_i
529 ::Create(const char* theFileName)
530 {       
531   try {
532     myFileInfo.setFile(theFileName);
533     myFileName = myFileInfo.fileName().toLatin1().data();
534
535     if(!myIsBuildParts){
536       SetInitFileName(myFileInfo.filePath().toLatin1().data());
537       SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
538     }
539
540     if(mySourceId == eRestoredFile){
541       QString aTmpDir(SALOMEDS_Tool::GetTmpDir().c_str());
542       std::string aFileName = VISU::MakeFileName(myFileInfo.fileName().toLatin1().data(), this);
543       QString aPathToCopy(aTmpDir + aFileName.c_str());
544       if(!VISU::CopyFile(myFileInfo.absoluteFilePath().toLatin1().data(), aPathToCopy.toLatin1().data()))
545         return NULL;
546
547       myFileInfo.setFile(aPathToCopy);
548       myFileName = myFileInfo.fileName().toLatin1().data();
549     }
550
551     myInput.reset(CreateConvertor(myFileInfo.absoluteFilePath().toLatin1().data()));
552
553     if(myInput){
554       if(myIsBuildImmediately)
555         Build(SALOMEDS::SObject::_nil());
556       return this;
557     }
558   }catch(std::exception& exc){
559     MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
560   }catch(...){
561     MSG(MYDEBUG,"Unknown exception !!!");
562   }
563   return NULL;
564 }
565
566
567 //---------------------------------------------------------------
568 VISU::Storable*
569 VISU::Result_i
570 ::Create(SALOMEDS::SObject_ptr theMedSObject)
571 {
572   if(MYDEBUG)  MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
573   try{
574     myInput.reset(CreateMEDConvertor(theMedSObject));
575     if(!myInput)
576       return NULL;
577
578     myInput->Build();
579
580     string aCompDataType = GetComponentDataType(theMedSObject);
581     myFileInfo.setFile(aCompDataType.c_str());
582     myFileName = VISU::GenerateName("aResult").toLatin1().data();
583
584     SetInitFileName(aCompDataType);
585     SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
586
587     return Build(theMedSObject);
588   }catch(std::exception& exc){
589     INFOS("Follow exception was occured :\n"<<exc.what());
590   }catch(...){
591     INFOS("Unknown exception was occured!!!");
592   }
593   return NULL;
594 }
595
596
597 //---------------------------------------------------------------
598 VISU::Storable*
599 VISU::Result_i
600 ::Create(SALOME_MED::FIELD_ptr theField)
601 {
602   if(MYDEBUG)  MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
603   try{
604     myInput.reset(CreateMEDFieldConvertor(theField));
605     if(!myInput)
606       return NULL;
607
608     myInput->Build();
609
610     string aCompDataType = "MED";
611     myFileInfo.setFile(aCompDataType.c_str());
612
613     myFileName = VISU::GenerateName("aResult").toLatin1().data();
614     SetInitFileName(aCompDataType);
615     SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
616
617     CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
618     SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
619
620     return Build(aFieldSObject);
621   }catch(std::exception& exc){
622     INFOS("Follow exception was occured :\n"<<exc.what());
623   }catch(...){
624     INFOS("Unknown exception was occured!!!");
625   }
626   return NULL;
627 }
628
629
630 //---------------------------------------------------------------
631 bool
632 VISU::Result_i
633 ::Save(SALOMEDS::SComponent_ptr theComponent,
634        const std::string& theURL,
635        bool theIsMultiFile,
636        bool theIsASCII,
637        TFileNames& theFileNames,
638        TFileNames& theFiles)
639 {
640   switch(GetCreationId()){
641   case Result_i::eImportFile:
642   case Result_i::eCopyAndImportFile: {
643     INITMSG(MYDEBUG, "Result::Save - this = "<<this<<"\n");
644     INITMSGA(MYDEBUG, 0, "theIsMultiFile = "<<theIsMultiFile<<"; theIsASCII = "<<theIsASCII<<"\n");
645
646     std::string aPrefix;
647     if (theIsMultiFile) {
648       CORBA::String_var anURL = GetStudyDocument()->URL();
649       aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
650     }
651
652     std::string aFileName = aPrefix + "_" + GetFileName().c_str();
653     BEGMSG(MYDEBUG, "aFileName = '"<<aFileName<<"'\n");
654
655     std::string aFile = GetFileInfo().filePath().toLatin1().data();
656     BEGMSG(MYDEBUG, "aFile = '"<<aFile<<"'\n");
657
658     if(theIsMultiFile || theIsASCII){
659       std::string aPathToCopy(theURL + aFileName);
660       BEGMSG(MYDEBUG, "aPathToCopy = '"<<aPathToCopy<<"'\n");
661       
662       if(!VISU::CopyFile(aFile, aPathToCopy))
663         return false;
664
665       if(theIsASCII)
666         HDFascii::ConvertFromHDFToASCII(const_cast<char*>(aPathToCopy.c_str()), true);
667     }
668
669     theFileNames.push_back(aFileName);
670     theFiles.push_back(aFile);
671
672     return true;
673   }}
674
675   return false;
676 }
677
678
679 //---------------------------------------------------------------
680 CORBA::Boolean 
681 VISU::Result_i
682 ::CanCopy(SALOMEDS::SObject_ptr theObject) 
683 {
684   switch(GetCreationId()){
685   case Result_i::eImportFile:
686   case Result_i::eCopyAndImportFile: 
687     return true;
688   }
689   
690   return false;
691 }
692
693
694 //---------------------------------------------------------------
695 bool
696 VISU::Result_i
697 ::CopyFrom(SALOMEDS::SObject_ptr theObject, 
698            CORBA::Long& theObjectID,
699            const std::string& theTmpDir,
700            TFileNames& theFileNames) 
701 {
702   if(!Storable::CopyFrom(theObject, theObjectID, theTmpDir, theFileNames))
703     return false;
704   
705   SALOMEDS::Study_var aStudy = theObject->GetStudy();
706   CORBA::String_var anURL = aStudy->URL();
707   std::string aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
708   std::string aFileName = aPrefix + GetFileInfo().fileName().toLatin1().data();
709
710   static QString aCommand;
711   std::string aFilePath =  theTmpDir + aFileName;
712   aCommand.sprintf(" %s %s", GetFileInfo().filePath().toLatin1().data(), aFilePath.c_str());
713   aCommand = QDir::convertSeparators( aCommand );
714   aCommand.prepend( COPY_COMMAND );
715
716   if(system(aCommand.toLatin1().data()) != 0) {
717     if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand.toLatin1().data());
718     return false;
719   }
720
721   SALOMEDS::SComponent_var aSComponent = aStudy->FindComponent("VISU");
722
723   theFileNames.push_back(aFileName);
724
725   return true;
726 }
727
728
729 //---------------------------------------------------------------
730 VISU::Storable*
731 VISU::Result_i
732 ::Restore(SALOMEDS::SObject_ptr theSObject,
733           const Storable::TRestoringMap& theMap,
734           const string& thePrefix,
735           CORBA::Boolean theIsMultiFile)
736 {
737   if(MYDEBUG) MESSAGE("Result_i::Restore - " << thePrefix);
738   mySObject = SALOMEDS::SObject::_duplicate(theSObject);
739   mySComponent = mySObject->GetFatherComponent();
740   myStudyDocument = theSObject->GetStudy();
741   myStudy = VISU::GetStudy(myStudyDocument);
742
743   myCreationId = ECreationId(Storable::FindValue(theMap, "myCreationId").toInt());
744   mySourceId = eRestoredFile;
745   if(myCreationId == eImportMed || myCreationId == eImportMedField)
746     mySourceId = eRestoredComponent;
747
748   myIsBuildFields = Storable::FindValue(theMap, "myIsBuildFields", "1").toInt();
749   myIsBuildMinMax = Storable::FindValue(theMap, "myIsBuildMinMax", "1").toInt();
750   myIsBuildGroups = Storable::FindValue(theMap, "myIsBuildGroups", "1").toInt();
751
752   myIsBuildImmediately = true;
753
754   try {
755     myFileName = VISU::Storable::FindValue(theMap, "myName").toLatin1().data();
756     SetInitFileName(VISU::Storable::FindValue(theMap, "myInitFileName").toLatin1().data());
757     
758     SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
759     if (theSObject->FindSubObject(1, aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)) {
760       if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
761       SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
762       CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
763       myFileInfo.setFile(aDataType.in());
764       if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType);
765       Engines::Component_var aEngComp =
766         Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
767       if (CORBA::is_nil(aEngComp))
768         throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
769       SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
770       SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
771       aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
772       // create field or MED converter
773       CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj);
774       SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject);
775       if (!CORBA::is_nil(aField)) {
776         // create field converter
777         myInput.reset(CreateMEDFieldConvertor(aField));
778         myInput->Build();
779       }
780       else if (strcmp(aDataType, "MED") == 0) {
781         // create MED converter
782         myInput.reset(CreateMEDConvertor(aTargetRefSObj));
783         myInput->Build();
784       }
785       else {
786         throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
787       }
788     } else {
789       myFileInfo.setFile(thePrefix.c_str());
790
791       std::string aStudyPrefix ("");
792       if (theIsMultiFile) {
793         CORBA::String_var anURL(GetStudyDocument()->URL());
794         aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
795       }
796       if (!myFileInfo.isFile()) {
797         std::string aFileName = thePrefix + aStudyPrefix + "_" + myFileName;
798         myFileInfo.setFile(aFileName.c_str());
799       }
800       if(MYDEBUG)
801         MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath().toLatin1().data() << "; " << myFileInfo.isFile());
802       
803       if (HDFascii::isASCII(myFileInfo.filePath().toLatin1().data())) {
804         MESSAGE("ConvertFromASCIIToHDF(" << myFileInfo.filePath().toLatin1().data() << ")");
805         char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().toLatin1().data());
806         MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath);
807         char* aHDFFileName = new char[strlen(aResultPath) + 19];
808         sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
809         
810         if (theIsMultiFile) { // set this file as new - temporary
811           static QString aCommand;
812           aCommand.sprintf(" %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().toLatin1().data());
813           aCommand = QDir::convertSeparators( aCommand );
814           aCommand.prepend( MOVE_COMMAND );
815           
816           if (system(aCommand.toLatin1().data()) == -1) {
817             if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand.toLatin1().data());
818             return NULL;
819           } else {
820             if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand.toLatin1().data());
821           }
822           myFileInfo.setFile(QString(aResultPath) + myFileInfo.baseName());
823         } else { // change current temporary file to the new: with hdf-format
824           static QString aCommand;
825           aCommand.sprintf(" %s %s\0",aHDFFileName, myFileInfo.filePath().toLatin1().data());
826           aCommand = QDir::convertSeparators( aCommand );
827           aCommand.prepend( MOVE_COMMAND );
828           
829           if (system(aCommand.toLatin1().data()) == -1) {
830             if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand.toLatin1().data());
831             return NULL;
832           } else {
833             if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand.toLatin1().data());
834           }
835           SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
836           SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
837         }
838         mySourceId = eRestoredFile;
839         delete(aResultPath);
840         delete(aHDFFileName);
841       } else if (!theIsMultiFile) {
842         mySourceId = eRestoredFile;
843       } else {
844         mySourceId = eSavedFile;
845       }
846       if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId);
847       myInput.reset(CreateConvertor(myFileInfo.filePath().toLatin1().data()));
848
849       myInput->BuildEntities();
850       if(myIsBuildFields){
851         myInput->BuildFields();
852         myIsFieldsDone = true;
853         if(myIsBuildMinMax){
854           myInput->BuildMinMax();
855           myIsMinMaxDone = true;
856         }
857       }
858       if(myIsBuildGroups){
859         myInput->BuildGroups();
860         myIsGroupsDone = true;
861       }
862
863       QString aComment;
864       aComment.sprintf("myComment=%s;myFileName=%s;myInitFileName=%s",
865                        GetComment(), 
866                        myFileInfo.filePath().toLatin1().data(),
867                        GetInitFileName().c_str()); // Restoring of Python dump
868       SALOMEDS::GenericAttribute_var anAttr;
869       if (!theSObject->FindAttribute(anAttr, "AttributeString"))
870         throw std::runtime_error("Build - There is no AttributeString for the SObject !!!");
871       SALOMEDS::AttributeString_var aCmnt = SALOMEDS::AttributeString::_narrow(anAttr);
872       aCmnt->SetValue(aComment.toLatin1().data());
873     }
874     bool anIsBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
875     if(anIsBuildAll)
876       BuildAll();
877     return this;
878   } catch(std::exception& exc) {
879     INFOS("Follow exception was occured :\n"<<exc.what());
880   } catch(...) {
881     INFOS("Unknown exception was occured!!!");
882   }
883   return NULL;
884 }
885
886
887 //---------------------------------------------------------------
888 VISU::Result_i::PInput
889 VISU::Result_i
890 ::GetInput(const std::string& theMeshName, 
891            VISU::Entity theEntity,
892            const std::string& theFieldName, 
893            CORBA::Long theTimeStampNumber) 
894 {
895   return myInput;
896 }
897
898
899 //---------------------------------------------------------------
900 CORBA::Boolean 
901 VISU::Result_i
902 ::IsDone() 
903 {
904   return 
905     myIsEntitiesDone && 
906     (myIsBuildFields? myIsFieldsDone: true) &&
907     (myIsBuildMinMax? myIsMinMaxDone: true) &&
908     (myIsBuildGroups? myIsGroupsDone: true);
909 }
910
911 CORBA::Boolean 
912 VISU::Result_i
913 ::IsEntitiesDone() 
914 {
915   return myIsEntitiesDone;
916 }
917
918 void
919 VISU::Result_i
920 ::SetBuildFields(CORBA::Boolean theIsBuildFields, 
921                  CORBA::Boolean theIsCalculateMinMax)
922 {
923   myIsBuildFields = theIsBuildFields;
924   if(theIsBuildFields)
925     myIsBuildMinMax = theIsCalculateMinMax;
926   else
927     myIsBuildMinMax = false;
928 }
929
930 void
931 VISU::Result_i
932 ::SetBuildGroups(CORBA::Boolean theIsBuildGroups)
933 {
934   myIsBuildGroups = theIsBuildGroups;
935 }
936
937 CORBA::Boolean 
938 VISU::Result_i
939 ::IsFieldsDone() 
940 {
941   return myIsFieldsDone;
942 }
943
944 CORBA::Boolean 
945 VISU::Result_i
946 ::IsGroupsDone() 
947 {
948   return myIsGroupsDone;
949 }
950
951 CORBA::Boolean 
952 VISU::Result_i
953 ::IsMinMaxDone() 
954 {
955   return myIsMinMaxDone;
956 }
957
958 CORBA::Boolean 
959 VISU::Result_i
960 ::IsPartsDone()
961 {
962   return myIsPartsDone;
963 }
964
965
966 //---------------------------------------------------------------
967 VISU::Result::EntityNames* 
968 VISU::Result_i
969 ::GetMeshNames()
970 {
971   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
972   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
973   if(aMeshMap.empty())
974     return aResult._retn();
975
976   aResult->length(aMeshMap.size());
977   VISU::TMeshMap::const_iterator anIter = aMeshMap.begin();
978   for(size_t anId = 0; anIter != aMeshMap.end(); anIter++, anId++){
979     const std::string& aName = anIter->first;
980     aResult[anId] = aName.c_str();
981   }
982  
983   return aResult._retn();
984 }
985
986
987 //---------------------------------------------------------------
988 VISU::Result::Entities* 
989 VISU::Result_i
990 ::GetEntities(const char* theMeshName)
991 {
992   VISU::Result::Entities_var anEntities = new VISU::Result::Entities();
993   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
994   if(aMeshMap.empty())
995     return anEntities._retn();
996
997   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
998   if(anIter == aMeshMap.end())
999     return anEntities._retn();
1000   
1001   const VISU::PMesh& aMesh = anIter->second;
1002   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1003   if(aMeshOnEntityMap.empty())
1004     return anEntities._retn();
1005
1006   {
1007     anEntities->length(aMeshOnEntityMap.size());
1008     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.begin();
1009     for(size_t anId = 0; anIter != aMeshOnEntityMap.end(); anIter++, anId++){
1010       const VISU::TEntity& anEntity = anIter->first;
1011       anEntities[anId] = VISU::Entity(anEntity);
1012     }
1013   }
1014
1015   return anEntities._retn();
1016 }
1017
1018
1019 //---------------------------------------------------------------
1020 VISU::Result::EntityNames* 
1021 VISU::Result_i
1022 ::GetFamilies(const char* theMeshName, 
1023               VISU::Entity theEntity)
1024 {
1025   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1026   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1027   if(aMeshMap.empty())
1028     return aResult._retn();
1029
1030   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1031   if(anIter == aMeshMap.end())
1032     return aResult._retn();
1033   
1034   const VISU::PMesh& aMesh = anIter->second;
1035   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1036   if(aMeshOnEntityMap.empty())
1037     return aResult._retn();
1038
1039   {
1040     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1041     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1042     if(anIter == aMeshOnEntityMap.end())
1043       return aResult._retn();
1044
1045     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1046     const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
1047     if(aFamilyMap.empty())
1048       return aResult._retn();
1049     
1050     {
1051       aResult->length(aFamilyMap.size());
1052       VISU::TFamilyMap::const_iterator anIter = aFamilyMap.begin();
1053       for(size_t anId = 0; anIter != aFamilyMap.end(); anIter++, anId++){
1054         const std::string& aName = anIter->first;
1055         aResult[anId] = aName.c_str();
1056       }
1057     }
1058   }
1059
1060   return aResult._retn();
1061 }
1062
1063
1064 //---------------------------------------------------------------
1065 VISU::Result::EntityNames* 
1066 VISU::Result_i
1067 ::GetGroups(const char* theMeshName)
1068 {
1069   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1070   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1071   if(aMeshMap.empty())
1072     return aResult._retn();
1073
1074   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1075   if(anIter == aMeshMap.end())
1076     return aResult._retn();
1077   
1078   const VISU::PMesh& aMesh = anIter->second;
1079   const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
1080   if(aGroupMap.empty())
1081     return aResult._retn();
1082
1083   {
1084     aResult->length(aGroupMap.size());
1085     VISU::TGroupMap::const_iterator anIter = aGroupMap.begin();
1086     for(size_t anId = 0; anIter != aGroupMap.end(); anIter++, anId++){
1087       const std::string& aName = anIter->first;
1088       aResult[anId] = aName.c_str();
1089     }
1090   }
1091
1092   return aResult._retn();
1093 }
1094
1095
1096 //---------------------------------------------------------------
1097 VISU::Result::EntityNames*
1098 VISU::Result_i
1099 ::GetFields(const char* theMeshName, 
1100             VISU::Entity theEntity)
1101 {
1102   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1103   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1104   if(aMeshMap.empty())
1105     return aResult._retn();
1106
1107   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1108   if(anIter == aMeshMap.end())
1109     return aResult._retn();
1110   
1111   const VISU::PMesh& aMesh = anIter->second;
1112   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1113   if(aMeshOnEntityMap.empty())
1114     return aResult._retn();
1115
1116   {
1117     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1118     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1119     if(anIter == aMeshOnEntityMap.end())
1120       return aResult._retn();
1121
1122     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1123     const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1124     if(aFieldMap.empty())
1125       return aResult._retn();
1126     
1127     {
1128       aResult->length(aFieldMap.size());
1129       VISU::TFieldMap::const_iterator anIter = aFieldMap.begin();
1130       for(size_t anId = 0; anIter != aFieldMap.end(); anIter++, anId++){
1131         const std::string& aName = anIter->first;
1132         aResult[anId] = aName.c_str();
1133       }
1134     }
1135   }
1136
1137   return aResult._retn();
1138 }
1139
1140
1141 //---------------------------------------------------------------
1142 VISU::Result::TimeStampNumbers* 
1143 VISU::Result_i
1144 ::GetTimeStampNumbers(const char* theMeshName, 
1145                       VISU::Entity theEntity, 
1146                       const char* theFieldName)
1147 {
1148   VISU::Result::TimeStampNumbers_var aResult = new VISU::Result::TimeStampNumbers();
1149   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1150   if(aMeshMap.empty())
1151     return aResult._retn();
1152
1153   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1154   if(anIter == aMeshMap.end())
1155     return aResult._retn();
1156   
1157   const VISU::PMesh& aMesh = anIter->second;
1158   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1159   if(aMeshOnEntityMap.empty())
1160     return aResult._retn();
1161
1162   {
1163     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1164     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1165     if(anIter == aMeshOnEntityMap.end())
1166       return aResult._retn();
1167
1168     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1169     const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1170     if(aFieldMap.empty())
1171       return aResult._retn();
1172
1173     {
1174       VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1175       if(anIter == aFieldMap.end())
1176         return aResult._retn();
1177
1178       {
1179         const VISU::PField& aField = anIter->second;
1180         const VISU::TValField& aValField = aField->myValField;
1181         if(aValField.empty())
1182           return aResult._retn();
1183
1184         {
1185           aResult->length(aValField.size());
1186           VISU::TValField::const_iterator anIter = aValField.begin();
1187           for(size_t anId = 0; anIter != aValField.end(); anIter++, anId++){
1188             const vtkIdType& aTimeStampNumber = anIter->first;
1189             aResult[anId] = aTimeStampNumber;
1190           }
1191         }
1192       }
1193     }
1194   }
1195
1196   return aResult._retn();
1197 }
1198
1199
1200 //---------------------------------------------------------------
1201 CORBA::Long 
1202 VISU::Result_i
1203 ::GetNumberOfComponents(const char* theMeshName, 
1204                         VISU::Entity theEntity, 
1205                         const char* theFieldName)
1206 {
1207   CORBA::Long aResult = 0;
1208   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1209   if(aMeshMap.empty())
1210     return aResult;
1211
1212   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1213   if(anIter == aMeshMap.end())
1214     return aResult;
1215   
1216   const VISU::PMesh& aMesh = anIter->second;
1217   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1218   if(aMeshOnEntityMap.empty())
1219     return aResult;
1220
1221   {
1222     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1223     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1224     if(anIter == aMeshOnEntityMap.end())
1225       return aResult;
1226
1227     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1228     const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1229     if(aFieldMap.empty())
1230       return aResult;
1231
1232     {
1233       VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1234       if(anIter == aFieldMap.end())
1235         return aResult;
1236
1237       {
1238         const VISU::PField& aField = anIter->second;
1239         aResult = aField->myNbComp;
1240       }
1241     }
1242   }
1243
1244   return aResult;
1245 }
1246
1247
1248 //---------------------------------------------------------------
1249 VISU::Result::EntityNames* 
1250 VISU::Result_i
1251 ::GetPartNames(const char* theMeshName)
1252 {
1253   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1254   return aResult._retn();
1255 }
1256
1257
1258 //---------------------------------------------------------------
1259 VISU::Result::Resolutions* 
1260 VISU::Result_i
1261 ::GetResolutions(const char* theMeshName, 
1262                  const char* thePartName)
1263 {
1264   VISU::Result::Resolutions_var aResult = new VISU::Result::Resolutions();
1265   return aResult._retn();
1266 }
1267
1268
1269 //---------------------------------------------------------------
1270 VISU::Result::Resolution
1271 VISU::Result_i
1272 ::GetResolution(const char* theMeshName, 
1273                 const char* thePartName)
1274 {
1275   return VISU::Result::HIDDEN;
1276 }
1277
1278
1279 //---------------------------------------------------------------
1280 void 
1281 VISU::Result_i
1282 ::SetResolution(const char* theMeshName, 
1283                 const char* thePartName, 
1284                 VISU::Result::Resolution theResolution)
1285 {}
1286
1287
1288 //---------------------------------------------------------------
1289 VISU::Result_i*
1290 VISU::Result_i
1291 ::New(SALOMEDS::Study_ptr theStudy,
1292       const ESourceId& theSourceId,
1293       const ECreationId& theCreationId,
1294       CORBA::Boolean theIsBuildImmediately,
1295       CORBA::Boolean theIsBuildFields,
1296       CORBA::Boolean theIsBuildMinMax,
1297       CORBA::Boolean theIsBuildGroups)
1298 {
1299   return new RESULT_CLASS_NAME(theStudy,
1300                                theSourceId,
1301                                theCreationId,
1302                                theIsBuildImmediately,
1303                                theIsBuildFields,
1304                                theIsBuildMinMax,
1305                                theIsBuildGroups);
1306 }
1307
1308
1309 //---------------------------------------------------------------
1310 VISU::Storable*
1311 VISU::Result_i
1312 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
1313                  const Storable::TRestoringMap& theMap,
1314                  const std::string& thePrefix,
1315                  CORBA::Boolean theIsMultiFile)
1316 {
1317   VISU::Result_i* aResult = new RESULT_CLASS_NAME();
1318   return aResult->Restore(theSObject, theMap, thePrefix, theIsMultiFile);
1319 }
1320
1321
1322 //---------------------------------------------------------------
1323 void 
1324 VISU::Result_i
1325 ::ToStream(std::ostringstream& theStr)
1326 {
1327   Storable::DataToStream(theStr,"myName", GetFileName().c_str());
1328   Storable::DataToStream(theStr,"myInitFileName", GetInitFileName().c_str());
1329   Storable::DataToStream(theStr,"myCreationId", myCreationId);
1330   Storable::DataToStream(theStr,"myIsBuildFields", myIsFieldsDone);
1331   Storable::DataToStream(theStr,"myIsBuildMinMax", myIsMinMaxDone);
1332   Storable::DataToStream(theStr,"myIsBuildGroups", myIsGroupsDone);
1333 }
1334
1335 //---------------------------------------------------------------
1336
1337 bool
1338 VISU::Result_i
1339 ::ExportMED(const char* theTargetFileName)
1340 {
1341   static QString aCommand;
1342   const char* aTempFileName = myFileInfo.absoluteFilePath().toLatin1();
1343   aCommand.sprintf(" %s %s", aTempFileName, theTargetFileName);
1344   aCommand = QDir::convertSeparators( aCommand );
1345   aCommand.prepend( COPY_COMMAND );
1346   
1347   if(system(aCommand.toLatin1().data()) != 0) {
1348     if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand.toLatin1().data());
1349     return false;
1350   }
1351   return true;
1352 }
1353
1354
1355 //---------------------------------------------------------------
1356 std::string
1357 VISU::Result_i
1358 ::GetInitFileName() const
1359 {
1360   return myInitFileName;
1361 }
1362
1363
1364 void 
1365 VISU::Result_i
1366 ::SetInitFileName(const std::string& theFileName)
1367 {
1368   myInitFileName = theFileName;
1369 }
1370
1371
1372 //---------------------------------------------------------------
1373 std::string
1374 VISU::Result_i
1375 ::GetFileName() const
1376 {
1377   if(GetSourceId() == eFile)
1378     return VISU::MakeFileName(myFileName, this);
1379
1380   return myFileName;
1381 }
1382
1383
1384 QFileInfo
1385 VISU::Result_i
1386 ::GetFileInfo() const
1387 {
1388   return myFileInfo;
1389 }
1390
1391 VISU::Result_i::ECreationId
1392 VISU::Result_i
1393 ::GetCreationId() const
1394 {
1395   return myCreationId;
1396 }
1397
1398
1399 VISU::Result_i::ESourceId
1400 VISU::Result_i
1401 ::GetSourceId() const
1402 {
1403   return mySourceId;
1404 }
1405
1406
1407 //---------------------------------------------------------------
1408 std::string
1409 VISU::Result_i
1410 ::GetEntry()
1411 {
1412   CORBA::String_var anEntry = mySObject->GetID();
1413   return anEntry.in();
1414 }
1415
1416 SALOMEDS::SObject_var
1417 VISU::Result_i
1418 ::GetSObject() const 
1419
1420   return mySObject;
1421 }
1422
1423 SALOMEDS::Study_var
1424 VISU::Result_i
1425 ::GetStudyDocument() const 
1426
1427   return myStudyDocument;
1428 }
1429
1430 _PTR(Study) 
1431 VISU::Result_i
1432 ::GetStudy() const 
1433
1434   return myStudy;
1435 }
1436
1437 SALOMEDS::SComponent_var
1438 VISU::Result_i
1439 ::GetSComponent() const
1440 {
1441   return mySComponent;
1442 }
1443
1444 std::string 
1445 VISU::Result_i
1446 ::GetEntry(const Storable::TRestoringMap& theRestoringMap)
1447 {
1448   return Storable::FindEntry(myStudyDocument,
1449                              GetEntry(),
1450                              theRestoringMap);
1451 }
1452
1453
1454 //=======================================================================
1455 //function : GetAxisInfo
1456 //purpose  :
1457 //=======================================================================
1458 const VISU::Result_i::TAxisInfo* 
1459 VISU::Result_i
1460 ::GetAxisInfo(const string& theMeshName,
1461               TAxis         theAxis,
1462               gp_Dir&       thePlaneNormal)
1463 {
1464   const TAxisInfo* components = NULL;
1465
1466   if ( theAxis < AXIS_X || theAxis > AXIS_Z ) {
1467     MESSAGE(" Bad axis index " << theAxis );
1468     return components;
1469   }
1470
1471   map< string, TGridInfo >::iterator name_info;
1472   name_info = myMeshName2GridInfoMap.find( theMeshName );
1473   TGridInfo * gInfo = 0;
1474
1475   if ( name_info != myMeshName2GridInfoMap.end() )
1476   {
1477     gInfo = & name_info->second;
1478   }
1479   else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z )
1480   {
1481     // check presence of theMeshName
1482     const VISU::TMeshMap& meshMap = myInput->GetMeshMap();
1483     PMesh theMesh;
1484     VISU::TMeshMap::const_iterator aIter = meshMap.find( theMeshName );
1485     if ( aIter == meshMap.end() ) {
1486       MESSAGE("No mesh named " << theMeshName );
1487       return components;
1488     } else
1489       theMesh = aIter->second;
1490
1491     VISU::PUnstructuredGridIDMapper anIDMapper = myInput->GetMeshOnEntity(theMeshName,
1492                                                                           CELL_ENTITY);
1493     vtkUnstructuredGrid* aMesh = anIDMapper->GetUnstructuredGridOutput();
1494
1495     if ( !aMesh || aMesh->GetNumberOfCells() == 0 ) {
1496       MESSAGE( "No cells in the mesh: " << theMeshName );
1497       return components;
1498     }
1499
1500     if ( !theMesh->IsStructured() || theMesh->myIsPolarType ) {
1501       // define axis directions and min cell size in each direction
1502       const int nbAxes = 3;
1503       int iAx;
1504       gp_Vec axDirs[ nbAxes ];
1505       float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
1506       bool axesComputed = false;
1507       for ( vtkIdType iCell = 0; iCell < aMesh->GetNumberOfCells(); ++iCell ) {
1508         vtkCell* cell = aMesh->GetCell( iCell );
1509         
1510         if (cell->GetCellType() != VTK_HEXAHEDRON && 
1511             cell->GetCellType() != VTK_QUADRATIC_HEXAHEDRON )
1512           continue;
1513         vtkPoints * points = cell->GetPoints();
1514         vtkFloatingPointType coords[ 4 ][3];
1515         points->GetPoint( 0, coords[0] );
1516         points->GetPoint( 1, coords[1] );
1517         points->GetPoint( 3, coords[2] );
1518         points->GetPoint( 4, coords[3] );
1519         gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] );
1520         for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1521           vtkFloatingPointType* coo = coords[ iAx + 1 ];
1522           gp_Pnt p( coo[0], coo[1], coo[2] );
1523           // min size
1524           vtkFloatingPointType size = p0.SquareDistance( p );
1525           if ( size > FLT_MIN && size < minSize[ iAx ] )
1526             minSize[ iAx ] = size;
1527           // axis direction
1528           if ( !axesComputed ) {
1529             gp_Vec dir( p0, p );
1530             if ( dir.SquareMagnitude() <= gp::Resolution() ) {
1531               break;
1532             }
1533             axDirs[ iAx ] = dir;
1534           }
1535         }
1536         if ( iAx == nbAxes )
1537           axesComputed = true;
1538       }
1539       if ( !axesComputed ) {
1540         MESSAGE("No good hexahedrons in the mesh: " << theMeshName );
1541         return components;
1542       }
1543       
1544       // compute axes dirs
1545       gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1546       for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1547         int iPrev = ( iAx == 0 ) ? 2 : iAx - 1;
1548         int iNext = ( iAx == 2 ) ? 0 : iAx + 1;
1549         gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ];
1550       }
1551       
1552       // get and sort intermediate component values - projections of nodes
1553       // on axis direction; define bnd box
1554       set< vtkFloatingPointType > comps[ 3 ];
1555       Bnd_Box box;
1556       vtkPoints * points = aMesh->GetPoints();
1557       vtkIdType iP, nbP = aMesh->GetNumberOfPoints();
1558       for ( iP = 0; iP < nbP; ++iP ) {
1559         vtkFloatingPointType coo[3];
1560         points->GetPoint( iP, coo );
1561         gp_Pnt p( coo[0], coo[1], coo[2] );
1562         box.Add( p );
1563         for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1564           const gp_Dir& dir = gInfo->myAxis[ iAx ];
1565           vtkFloatingPointType dot = dir.XYZ() * p.XYZ();
1566           comps[ iAx ].insert( dot );
1567         }
1568       }
1569       
1570       // find a range of projections of bnd box corners on each axis
1571       vtkFloatingPointType range[3], firstValue[3];
1572       double x[2],y[2],z[2];
1573       box.Get(x[0],y[0],z[0],x[1],y[1],z[1]);
1574       for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1575         set< vtkFloatingPointType > bndComps;
1576         const gp_Dir& dir = gInfo->myAxis[ iAx ];
1577         for ( int iX = 0; iX < 2; ++iX ) {
1578           for ( int iY = 0; iY < 2; ++iY ) {
1579             for ( int iZ = 0; iZ < 2; ++iZ ) {
1580               gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] );
1581               vtkFloatingPointType dot = dir.XYZ() * p.XYZ();
1582               bndComps.insert( dot );
1583             }
1584           }
1585         }
1586         firstValue[ iAx ] = *bndComps.begin();
1587         range[ iAx ] = *bndComps.rbegin() - *bndComps.begin();
1588       }
1589       
1590       // compute component values
1591       for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1592         list< vtkFloatingPointType > values;
1593         int nbVals = 0;
1594         set< vtkFloatingPointType >& comp = comps[ iAx ];
1595         set< vtkFloatingPointType >::iterator val = comp.begin();
1596         vtkFloatingPointType bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ];
1597         vtkFloatingPointType tol = 0.1 * sqrt( minSize[ iAx ]) / rng;
1598         for ( ; val != comp.end(); ++val ) {
1599           vtkFloatingPointType value = ( *val - first ) / rng;
1600           if ( value > bnd ) {
1601             values.push_back( value );
1602             bnd = value + tol;
1603             nbVals++;
1604           }
1605         }
1606         // store values in gInfo
1607         vector< vtkFloatingPointType >& myComp = gInfo->myComponets[ iAx ];
1608         myComp.resize( nbVals );
1609         list< vtkFloatingPointType >::iterator v = values.begin();
1610         for ( int i = 0; v != values.end(); ++v ){
1611           myComp[ i++ ] = *v;
1612         }
1613       }
1614     }
1615     else {
1616       vtkIdType aMeshDim = theMesh->myDim;
1617       gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1618       switch ( aMeshDim ) {
1619       case 3: {
1620         gp_Dir aDir(0.0,0.0,1.0);
1621         gInfo->myAxis[ 2 ] = aDir;
1622       }
1623       case 2: {
1624         gp_Dir aDir(0.0,1.0,0.0);
1625         gInfo->myAxis[ 1 ] = aDir;
1626       }
1627       case 1: {
1628         gp_Dir aDir(1.0,0.0,0.0);
1629         gInfo->myAxis[ 0 ] = aDir;
1630       }}
1631       
1632       TStructuredId aStructuredId = theMesh->GetStructure();
1633       vector<vtkFloatingPointType> PointsCoords[3];
1634       vtkPoints* aPoints = aMesh->GetPoints();
1635       switch ( aMeshDim ) {
1636       case 3: {
1637         TStructuredId aCoordIJK;
1638         vtkIdType nbZ = aStructuredId[2];
1639         for ( int i = 0; i < nbZ; i++ ) {
1640           aCoordIJK[2] = i + 1;
1641           vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1642           vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1643           vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1644           PointsCoords[2].push_back(aPCoord[2]);
1645         }
1646       }
1647       case 2: {
1648         TStructuredId aCoordIJK;
1649         vtkIdType nbJ = aStructuredId[1];
1650         for ( int i = 0; i < nbJ; i++ ) {
1651           aCoordIJK[1] = i + 1;
1652           vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1653           vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1654           vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1655           PointsCoords[1].push_back(aPCoord[1]);
1656         }
1657       }
1658       case 1: {
1659         TStructuredId aCoordIJK;
1660         vtkIdType nbI = aStructuredId[0];
1661         for ( int i = 0; i < nbI; i++ ) {
1662           aCoordIJK[0] = i + 1;
1663           vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1664           vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1665           vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1666           PointsCoords[0].push_back(aPCoord[0]);
1667         }
1668       }}
1669       for ( int i = 0; i < aMeshDim; i++ ) {
1670         vector< vtkFloatingPointType >& myComp = gInfo->myComponets[ i ];
1671         int aSize = PointsCoords[i].size();
1672         if ( aSize > 0 ) {
1673           vtkFloatingPointType aLen = PointsCoords[i][aSize-1] - PointsCoords[i][0];
1674           myComp.resize(aSize);
1675           myComp[0] = 0;
1676           for ( int k = 1; k < aSize; k++ ) {
1677             myComp[k]=myComp[k-1] + (PointsCoords[i][k]-PointsCoords[i][k-1])/aLen;
1678           }
1679         }
1680       }
1681     }
1682   }
1683
1684   // set return values
1685   if ( gInfo ) {
1686     thePlaneNormal = gInfo->myAxis[ theAxis ];
1687     components = & gInfo->myComponets[ theAxis ];
1688   }
1689
1690   return components;
1691 }
1692
1693 SALOME_MED::MedFileInfo* VISU::Result_i::GetMEDFileInfo()
1694 {
1695   SALOME_MED::MedFileInfo_var res = new SALOME_MED::MedFileInfo();
1696
1697   QString fpath = myFileInfo.absoluteFilePath();
1698   res->fileName = fpath.toLatin1().constData();
1699   res->fileSize = myFileInfo.size();
1700   int major, minor, release;
1701   if( !MED::getMEDVersion( fpath.toLatin1().constData(), major, minor, release ) )
1702   {
1703     major = -1;
1704     minor = -1;
1705     release = -1;
1706   }
1707   res->major = major;
1708   res->minor = minor;
1709   res->release = release;
1710   return res._retn();
1711 }