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