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