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