Salome HOME
Merge from PortingMED3 07Apr11
[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   {
510     boost::thread aThread(boost::bind(&BuildFieldDataTree,
511                                       this,
512                                       myInput,
513                                       &myIsFieldsDone,
514                                       myIsBuildFields,
515                                       &myIsMinMaxDone,
516                                       myIsBuildMinMax,
517                                       myStudy));
518   }
519 }
520
521 //---------------------------------------------------------------
522 VISU::Storable*
523 VISU::Result_i
524 ::BuildAll(SALOMEDS::SObject_ptr theSObject)
525 {
526   if(MYDEBUG) MESSAGE("Result_i::Build");
527   try{
528     Build(theSObject);
529     BuildAll();
530   }catch(std::exception& exc){
531     INFOS("Follow exception was occured :\n"<<exc.what());
532     return NULL;
533   }catch(...){
534     INFOS("Unknown exception was occured!!!");
535     return NULL;
536   }
537
538   return this;
539 }
540
541
542 //---------------------------------------------------------------
543 VISU::Storable*
544 VISU::Result_i
545 ::Create(const char* theFileName)
546 {        
547   try {
548     myFileInfo.setFile(theFileName);
549     myFileName = myFileInfo.fileName().toLatin1().data();
550
551     if(!myIsBuildParts){
552       SetInitFileName(myFileInfo.filePath().toLatin1().data());
553       SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
554     }
555
556     if(mySourceId == eRestoredFile){
557       QString aTmpDir(SALOMEDS_Tool::GetTmpDir().c_str());
558       std::string aFileName = VISU::MakeFileName(myFileInfo.fileName().toLatin1().data(), this);
559       QString aPathToCopy(aTmpDir + aFileName.c_str());
560       if(!VISU::CopyFile(myFileInfo.absoluteFilePath().toLatin1().data(), aPathToCopy.toLatin1().data()))
561         return NULL;
562
563       myFileInfo.setFile(aPathToCopy);
564       myFileName = myFileInfo.fileName().toLatin1().data();
565     }
566
567     myInput.reset(CreateConvertor(myFileInfo.absoluteFilePath().toLatin1().data()));
568
569     if(myInput){
570       if(myIsBuildImmediately)
571         Build(SALOMEDS::SObject::_nil());
572       return this;
573     }
574   }catch(std::exception& exc){
575     MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
576   }catch(...){
577     MSG(MYDEBUG,"Unknown exception !!!");
578   }
579   return NULL;
580 }
581
582
583 //---------------------------------------------------------------
584 VISU::Storable*
585 VISU::Result_i
586 ::Create(SALOMEDS::SObject_ptr theMedSObject)
587 {
588   if(MYDEBUG)  MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
589   try{
590     myInput.reset(CreateMEDConvertor(theMedSObject));
591     if(!myInput)
592       return NULL;
593
594     myInput->Build();
595
596     string aCompDataType = GetComponentDataType(theMedSObject);
597     myFileInfo.setFile(aCompDataType.c_str());
598     myFileName = VISU::GenerateName("aResult").toLatin1().data();
599
600     SetInitFileName(aCompDataType);
601     SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
602
603     return Build(theMedSObject);
604   }catch(std::exception& exc){
605     INFOS("Follow exception was occured :\n"<<exc.what());
606   }catch(...){
607     INFOS("Unknown exception was occured!!!");
608   }
609   return NULL;
610 }
611
612
613 //---------------------------------------------------------------
614 VISU::Storable*
615 VISU::Result_i
616 ::Create(SALOME_MED::FIELD_ptr theField)
617 {
618   if(MYDEBUG)  MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
619   try{
620     myInput.reset(CreateMEDFieldConvertor(theField));
621     if(!myInput)
622       return NULL;
623
624     myInput->Build();
625
626     string aCompDataType = "MED";
627     myFileInfo.setFile(aCompDataType.c_str());
628
629     myFileName = VISU::GenerateName("aResult").toLatin1().data();
630     SetInitFileName(aCompDataType);
631     SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
632
633     CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
634     SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
635
636     return Build(aFieldSObject);
637   }catch(std::exception& exc){
638     INFOS("Follow exception was occured :\n"<<exc.what());
639   }catch(...){
640     INFOS("Unknown exception was occured!!!");
641   }
642   return NULL;
643 }
644
645
646 //---------------------------------------------------------------
647 bool
648 VISU::Result_i
649 ::Save(SALOMEDS::SComponent_ptr theComponent,
650        const std::string& theURL,
651        bool theIsMultiFile,
652        bool theIsASCII,
653        TFileNames& theFileNames,
654        TFileNames& theFiles)
655 {
656   switch(GetCreationId()){
657   case Result_i::eImportFile:
658   case Result_i::eCopyAndImportFile: {
659     INITMSG(MYDEBUG, "Result::Save - this = "<<this<<"\n");
660     INITMSGA(MYDEBUG, 0, "theIsMultiFile = "<<theIsMultiFile<<"; theIsASCII = "<<theIsASCII<<"\n");
661
662     std::string aPrefix;
663     if (theIsMultiFile) {
664       CORBA::String_var anURL = GetStudyDocument()->URL();
665       aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
666     }
667
668     std::string aFileName = aPrefix + "_" + GetFileName().c_str();
669     BEGMSG(MYDEBUG, "aFileName = '"<<aFileName<<"'\n");
670
671     std::string aFile = GetFileInfo().filePath().toLatin1().data();
672     BEGMSG(MYDEBUG, "aFile = '"<<aFile<<"'\n");
673
674     if(theIsMultiFile || theIsASCII){
675       std::string aPathToCopy(theURL + aFileName);
676       BEGMSG(MYDEBUG, "aPathToCopy = '"<<aPathToCopy<<"'\n");
677
678       if(!VISU::CopyFile(aFile, aPathToCopy))
679         return false;
680
681       if(theIsASCII)
682         HDFascii::ConvertFromHDFToASCII(const_cast<char*>(aPathToCopy.c_str()), true);
683     }
684
685     theFileNames.push_back(aFileName);
686     theFiles.push_back(aFile);
687
688     return true;
689   }}
690
691   return false;
692 }
693
694
695 //---------------------------------------------------------------
696 CORBA::Boolean
697 VISU::Result_i
698 ::CanCopy(SALOMEDS::SObject_ptr theObject)
699 {
700   switch(GetCreationId()){
701   case Result_i::eImportFile:
702   case Result_i::eCopyAndImportFile:
703     return true;
704   }
705
706   return false;
707 }
708
709
710 //---------------------------------------------------------------
711 bool
712 VISU::Result_i
713 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
714            CORBA::Long& theObjectID,
715            const std::string& theTmpDir,
716            TFileNames& theFileNames)
717 {
718   if(!Storable::CopyFrom(theObject, theObjectID, theTmpDir, theFileNames))
719     return false;
720
721   SALOMEDS::Study_var aStudy = theObject->GetStudy();
722   CORBA::String_var anURL = aStudy->URL();
723   std::string aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
724   std::string aFileName = aPrefix + GetFileInfo().fileName().toLatin1().data();
725
726   static QString aCommand;
727   std::string aFilePath =  theTmpDir + aFileName;
728   aCommand.sprintf(" %s %s", GetFileInfo().filePath().toLatin1().data(), aFilePath.c_str());
729   aCommand = QDir::convertSeparators( aCommand );
730   aCommand.prepend( COPY_COMMAND );
731
732   if(system(aCommand.toLatin1().data()) != 0) {
733     if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand.toLatin1().data());
734     return false;
735   }
736
737   SALOMEDS::SComponent_var aSComponent = aStudy->FindComponent("VISU");
738
739   theFileNames.push_back(aFileName);
740
741   return true;
742 }
743
744
745 //---------------------------------------------------------------
746 VISU::Storable*
747 VISU::Result_i
748 ::Restore(SALOMEDS::SObject_ptr theSObject,
749           const Storable::TRestoringMap& theMap,
750           const string& thePrefix,
751           CORBA::Boolean theIsMultiFile)
752 {
753   if(MYDEBUG) MESSAGE("Result_i::Restore - " << thePrefix);
754   mySObject = SALOMEDS::SObject::_duplicate(theSObject);
755   mySComponent = mySObject->GetFatherComponent();
756   myStudyDocument = theSObject->GetStudy();
757   myStudy = VISU::GetStudy(myStudyDocument);
758
759   myCreationId = ECreationId(Storable::FindValue(theMap, "myCreationId").toInt());
760   mySourceId = eRestoredFile;
761   if(myCreationId == eImportMed || myCreationId == eImportMedField)
762     mySourceId = eRestoredComponent;
763
764   myIsBuildFields = Storable::FindValue(theMap, "myIsBuildFields", "1").toInt();
765   myIsBuildMinMax = Storable::FindValue(theMap, "myIsBuildMinMax", "1").toInt();
766   myIsBuildGroups = Storable::FindValue(theMap, "myIsBuildGroups", "1").toInt();
767
768   myIsBuildImmediately = true;
769
770   try {
771     myFileName = VISU::Storable::FindValue(theMap, "myName").toLatin1().data();
772 #ifdef WIN32
773     for (int i = 0; i < myFileName.length(); i++)
774     {
775       if (myFileName[i] == ':')
776         myFileName[i] = '_';
777     }
778 #endif
779     SetInitFileName(VISU::Storable::FindValue(theMap, "myInitFileName").toLatin1().data());
780
781     SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
782     if (theSObject->FindSubObject(1, aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)) {
783       if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
784       SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
785       CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
786       myFileInfo.setFile(aDataType.in());
787       if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType);
788       Engines::EngineComponent_var aEngComp =
789         Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
790       if (CORBA::is_nil(aEngComp))
791         throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
792       SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
793       SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
794       aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
795       // create field or MED converter
796       CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj);
797       SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject);
798       if (!CORBA::is_nil(aField)) {
799         // create field converter
800         myInput.reset(CreateMEDFieldConvertor(aField));
801         myInput->Build();
802       }
803       else if (strcmp(aDataType, "MED") == 0) {
804         // create MED converter
805         myInput.reset(CreateMEDConvertor(aTargetRefSObj));
806         myInput->Build();
807       }
808       else {
809         throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
810       }
811     } else {
812       myFileInfo.setFile(thePrefix.c_str());
813
814       std::string aStudyPrefix ("");
815       if (theIsMultiFile) {
816         CORBA::String_var anURL(GetStudyDocument()->URL());
817         aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
818       }
819       if (!myFileInfo.isFile()) {
820         std::string aFileName = thePrefix + aStudyPrefix + "_" + myFileName;
821         myFileInfo.setFile(aFileName.c_str());
822       }
823       if(MYDEBUG)
824         MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath().toLatin1().data() << "; " << myFileInfo.isFile());
825
826       if (HDFascii::isASCII(myFileInfo.filePath().toLatin1().data())) {
827         MESSAGE("ConvertFromASCIIToHDF(" << myFileInfo.filePath().toLatin1().data() << ")");
828         char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().toLatin1().data());
829         MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath);
830         char* aHDFFileName = new char[strlen(aResultPath) + 19];
831         sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
832         
833         if (theIsMultiFile) { // set this file as new - temporary
834           static QString aCommand;
835           aCommand.sprintf(" %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().toLatin1().data());
836           aCommand = QDir::convertSeparators( aCommand );
837           aCommand.prepend( MOVE_COMMAND );
838         
839           if (system(aCommand.toLatin1().data()) == -1) {
840             if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand.toLatin1().data());
841             return NULL;
842           } else {
843             if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand.toLatin1().data());
844           }
845           myFileInfo.setFile(QString(aResultPath) + myFileInfo.baseName());
846         } else { // change current temporary file to the new: with hdf-format
847           static QString aCommand;
848           aCommand.sprintf(" %s %s\0",aHDFFileName, myFileInfo.filePath().toLatin1().data());
849           aCommand = QDir::convertSeparators( aCommand );
850           aCommand.prepend( MOVE_COMMAND );
851         
852           if (system(aCommand.toLatin1().data()) == -1) {
853             if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand.toLatin1().data());
854             return NULL;
855           } else {
856             if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand.toLatin1().data());
857           }
858           SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
859           SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
860         }
861         mySourceId = eRestoredFile;
862         delete(aResultPath);
863         delete(aHDFFileName);
864       } else if (!theIsMultiFile) {
865         mySourceId = eRestoredFile;
866       } else {
867         mySourceId = eSavedFile;
868       }
869       if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId);
870       myInput.reset(CreateConvertor(myFileInfo.filePath().toLatin1().data()));
871
872       myInput->BuildEntities();
873       if(myIsBuildFields){
874         myInput->BuildFields();
875         myIsFieldsDone = true;
876         if(myIsBuildMinMax){
877           myInput->BuildMinMax();
878           myIsMinMaxDone = true;
879         }
880       }
881       if(myIsBuildGroups){
882         myInput->BuildGroups();
883         myIsGroupsDone = true;
884       }
885
886       QString aComment;
887       aComment.sprintf("myComment=%s;myFileName=%s;myInitFileName=%s",
888                        GetComment(),
889                        myFileInfo.filePath().toLatin1().data(),
890                        GetInitFileName().c_str()); // Restoring of Python dump
891       SALOMEDS::GenericAttribute_var anAttr;
892       if (!theSObject->FindAttribute(anAttr, "AttributeString"))
893         throw std::runtime_error("Build - There is no AttributeString for the SObject !!!");
894       SALOMEDS::AttributeString_var aCmnt = SALOMEDS::AttributeString::_narrow(anAttr);
895       aCmnt->SetValue(aComment.toLatin1().data());
896     }
897     bool anIsBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
898     if(anIsBuildAll)
899       BuildAll();
900     return this;
901   } catch(std::exception& exc) {
902     INFOS("Follow exception was occured :\n"<<exc.what());
903   } catch(...) {
904     INFOS("Unknown exception was occured!!!");
905   }
906   return NULL;
907 }
908
909
910 //---------------------------------------------------------------
911 VISU::Result_i::PInput
912 VISU::Result_i
913 ::GetInput(const std::string& theMeshName,
914            VISU::Entity theEntity,
915            const std::string& theFieldName,
916            CORBA::Long theTimeStampNumber)
917 {
918   return myInput;
919 }
920
921
922 //---------------------------------------------------------------
923 CORBA::Boolean
924 VISU::Result_i
925 ::IsDone()
926 {
927   return
928     myIsEntitiesDone &&
929     (myIsBuildFields? myIsFieldsDone: true) &&
930     (myIsBuildMinMax? myIsMinMaxDone: true) &&
931     (myIsBuildGroups? myIsGroupsDone: true);
932 }
933
934 CORBA::Boolean
935 VISU::Result_i
936 ::IsEntitiesDone()
937 {
938   return myIsEntitiesDone;
939 }
940
941 void
942 VISU::Result_i
943 ::SetBuildFields(CORBA::Boolean theIsBuildFields,
944                  CORBA::Boolean theIsCalculateMinMax)
945 {
946   myIsBuildFields = theIsBuildFields;
947   if(theIsBuildFields)
948     myIsBuildMinMax = theIsCalculateMinMax;
949   else
950     myIsBuildMinMax = false;
951 }
952
953 void
954 VISU::Result_i
955 ::SetBuildGroups(CORBA::Boolean theIsBuildGroups)
956 {
957   myIsBuildGroups = theIsBuildGroups;
958 }
959
960 CORBA::Boolean
961 VISU::Result_i
962 ::IsFieldsDone()
963 {
964   return myIsFieldsDone;
965 }
966
967 CORBA::Boolean
968 VISU::Result_i
969 ::IsGroupsDone()
970 {
971   return myIsGroupsDone;
972 }
973
974 CORBA::Boolean
975 VISU::Result_i
976 ::IsMinMaxDone()
977 {
978   return myIsMinMaxDone;
979 }
980
981 CORBA::Boolean
982 VISU::Result_i
983 ::IsPartsDone()
984 {
985   return myIsPartsDone;
986 }
987
988
989 //---------------------------------------------------------------
990 VISU::Result::EntityNames*
991 VISU::Result_i
992 ::GetMeshNames()
993 {
994   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
995   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
996   if(aMeshMap.empty())
997     return aResult._retn();
998
999   aResult->length(aMeshMap.size());
1000   VISU::TMeshMap::const_iterator anIter = aMeshMap.begin();
1001   for(size_t anId = 0; anIter != aMeshMap.end(); anIter++, anId++){
1002     const std::string& aName = anIter->first;
1003     aResult[anId] = aName.c_str();
1004   }
1005
1006   return aResult._retn();
1007 }
1008
1009
1010 //---------------------------------------------------------------
1011 VISU::Result::Entities*
1012 VISU::Result_i
1013 ::GetEntities(const char* theMeshName)
1014 {
1015   VISU::Result::Entities_var anEntities = new VISU::Result::Entities();
1016   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1017   if(aMeshMap.empty())
1018     return anEntities._retn();
1019
1020   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1021   if(anIter == aMeshMap.end())
1022     return anEntities._retn();
1023
1024   const VISU::PMesh& aMesh = anIter->second;
1025   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1026   if(aMeshOnEntityMap.empty())
1027     return anEntities._retn();
1028
1029   {
1030     anEntities->length(aMeshOnEntityMap.size());
1031     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.begin();
1032     for(size_t anId = 0; anIter != aMeshOnEntityMap.end(); anIter++, anId++){
1033       const VISU::TEntity& anEntity = anIter->first;
1034       anEntities[anId] = VISU::Entity(anEntity);
1035     }
1036   }
1037
1038   return anEntities._retn();
1039 }
1040
1041
1042 //---------------------------------------------------------------
1043 VISU::Result::EntityNames*
1044 VISU::Result_i
1045 ::GetFamilies(const char* theMeshName,
1046               VISU::Entity theEntity)
1047 {
1048   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1049   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1050   if(aMeshMap.empty())
1051     return aResult._retn();
1052
1053   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1054   if(anIter == aMeshMap.end())
1055     return aResult._retn();
1056
1057   const VISU::PMesh& aMesh = anIter->second;
1058   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1059   if(aMeshOnEntityMap.empty())
1060     return aResult._retn();
1061
1062   {
1063     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1064     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1065     if(anIter == aMeshOnEntityMap.end())
1066       return aResult._retn();
1067
1068     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1069     const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
1070     if(aFamilyMap.empty())
1071       return aResult._retn();
1072
1073     {
1074       aResult->length(aFamilyMap.size());
1075       VISU::TFamilyMap::const_iterator anIter = aFamilyMap.begin();
1076       for(size_t anId = 0; anIter != aFamilyMap.end(); anIter++, anId++){
1077         const std::string& aName = anIter->first;
1078         aResult[anId] = aName.c_str();
1079       }
1080     }
1081   }
1082
1083   return aResult._retn();
1084 }
1085
1086
1087 //---------------------------------------------------------------
1088 VISU::Result::EntityNames*
1089 VISU::Result_i
1090 ::GetGroups(const char* theMeshName)
1091 {
1092   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1093   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1094   if(aMeshMap.empty())
1095     return aResult._retn();
1096
1097   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1098   if(anIter == aMeshMap.end())
1099     return aResult._retn();
1100
1101   const VISU::PMesh& aMesh = anIter->second;
1102   const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
1103   if(aGroupMap.empty())
1104     return aResult._retn();
1105
1106   {
1107     aResult->length(aGroupMap.size());
1108     VISU::TGroupMap::const_iterator anIter = aGroupMap.begin();
1109     for(size_t anId = 0; anIter != aGroupMap.end(); anIter++, anId++){
1110       const std::string& aName = anIter->first;
1111       aResult[anId] = aName.c_str();
1112     }
1113   }
1114
1115   return aResult._retn();
1116 }
1117
1118
1119 //---------------------------------------------------------------
1120 VISU::Result::EntityNames*
1121 VISU::Result_i
1122 ::GetFields(const char* theMeshName,
1123             VISU::Entity theEntity)
1124 {
1125   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1126   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1127   if(aMeshMap.empty())
1128     return aResult._retn();
1129
1130   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1131   if(anIter == aMeshMap.end())
1132     return aResult._retn();
1133
1134   const VISU::PMesh& aMesh = anIter->second;
1135   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1136   if(aMeshOnEntityMap.empty())
1137     return aResult._retn();
1138
1139   {
1140     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1141     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1142     if(anIter == aMeshOnEntityMap.end())
1143       return aResult._retn();
1144
1145     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1146     const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1147     if(aFieldMap.empty())
1148       return aResult._retn();
1149
1150     {
1151       aResult->length(aFieldMap.size());
1152       VISU::TFieldMap::const_iterator anIter = aFieldMap.begin();
1153       for(size_t anId = 0; anIter != aFieldMap.end(); anIter++, anId++){
1154         const std::string& aName = anIter->first;
1155         aResult[anId] = aName.c_str();
1156       }
1157     }
1158   }
1159
1160   return aResult._retn();
1161 }
1162
1163
1164 //---------------------------------------------------------------
1165 VISU::Result::TimeStampNumbers*
1166 VISU::Result_i
1167 ::GetTimeStampNumbers(const char* theMeshName,
1168                       VISU::Entity theEntity,
1169                       const char* theFieldName)
1170 {
1171   VISU::Result::TimeStampNumbers_var aResult = new VISU::Result::TimeStampNumbers();
1172   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1173   if(aMeshMap.empty())
1174     return aResult._retn();
1175
1176   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1177   if(anIter == aMeshMap.end())
1178     return aResult._retn();
1179
1180   const VISU::PMesh& aMesh = anIter->second;
1181   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1182   if(aMeshOnEntityMap.empty())
1183     return aResult._retn();
1184
1185   {
1186     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1187     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1188     if(anIter == aMeshOnEntityMap.end())
1189       return aResult._retn();
1190
1191     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1192     const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1193     if(aFieldMap.empty())
1194       return aResult._retn();
1195
1196     {
1197       VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1198       if(anIter == aFieldMap.end())
1199         return aResult._retn();
1200
1201       {
1202         const VISU::PField& aField = anIter->second;
1203         const VISU::TValField& aValField = aField->myValField;
1204         if(aValField.empty())
1205           return aResult._retn();
1206
1207         {
1208           aResult->length(aValField.size());
1209           VISU::TValField::const_iterator anIter = aValField.begin();
1210           for(size_t anId = 0; anIter != aValField.end(); anIter++, anId++){
1211             const vtkIdType& aTimeStampNumber = anIter->first;
1212             aResult[anId] = aTimeStampNumber;
1213           }
1214         }
1215       }
1216     }
1217   }
1218
1219   return aResult._retn();
1220 }
1221
1222
1223 //---------------------------------------------------------------
1224 VISU::double_array*
1225 VISU::Result_i
1226 ::GetTimeStampValues(const char* theMeshName,
1227                      VISU::Entity theEntity,
1228                      const char* theFieldName)
1229 {
1230   VISU::double_array_var aResult = new VISU::double_array();
1231   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1232   if(aMeshMap.empty())
1233     return aResult._retn();
1234
1235   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1236   if(anIter == aMeshMap.end())
1237     return aResult._retn();
1238
1239   const VISU::PMesh& aMesh = anIter->second;
1240   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1241   if(aMeshOnEntityMap.empty())
1242     return aResult._retn();
1243
1244   {
1245     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1246     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1247     if(anIter == aMeshOnEntityMap.end())
1248       return aResult._retn();
1249
1250     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1251     const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1252     if(aFieldMap.empty())
1253       return aResult._retn();
1254
1255     {
1256       VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1257       if(anIter == aFieldMap.end())
1258         return aResult._retn();
1259
1260       {
1261         const VISU::PField& aField = anIter->second;
1262         const VISU::TValField& aValField = aField->myValField;
1263         if(aValField.empty())
1264           return aResult._retn();
1265
1266         {
1267           aResult->length(aValField.size());
1268           VISU::TValField::const_iterator anIter = aValField.begin();
1269           for(size_t anId = 0; anIter != aValField.end(); anIter++, anId++){
1270             const PValForTime& aValForTime = anIter->second;
1271             aResult[anId] = aValForTime->myTime.first;
1272           }
1273         }
1274       }
1275     }
1276   }
1277
1278   return aResult._retn();
1279 }
1280
1281
1282 //---------------------------------------------------------------
1283 CORBA::Long
1284 VISU::Result_i
1285 ::GetNumberOfComponents(const char* theMeshName,
1286                         VISU::Entity theEntity,
1287                         const char* theFieldName)
1288 {
1289   CORBA::Long aResult = 0;
1290   const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1291   if(aMeshMap.empty())
1292     return aResult;
1293
1294   VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1295   if(anIter == aMeshMap.end())
1296     return aResult;
1297
1298   const VISU::PMesh& aMesh = anIter->second;
1299   const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1300   if(aMeshOnEntityMap.empty())
1301     return aResult;
1302
1303   {
1304     VISU::TEntity anEntity = VISU::TEntity(theEntity);
1305     VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1306     if(anIter == aMeshOnEntityMap.end())
1307       return aResult;
1308
1309     const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1310     const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1311     if(aFieldMap.empty())
1312       return aResult;
1313
1314     {
1315       VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1316       if(anIter == aFieldMap.end())
1317         return aResult;
1318
1319       {
1320         const VISU::PField& aField = anIter->second;
1321         aResult = aField->myNbComp;
1322       }
1323     }
1324   }
1325
1326   return aResult;
1327 }
1328
1329
1330 //---------------------------------------------------------------
1331 VISU::Result::EntityNames*
1332 VISU::Result_i
1333 ::GetPartNames(const char* theMeshName)
1334 {
1335   VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1336   return aResult._retn();
1337 }
1338
1339
1340 //---------------------------------------------------------------
1341 VISU::Result::Resolutions*
1342 VISU::Result_i
1343 ::GetResolutions(const char* theMeshName,
1344                  const char* thePartName)
1345 {
1346   VISU::Result::Resolutions_var aResult = new VISU::Result::Resolutions();
1347   return aResult._retn();
1348 }
1349
1350
1351 //---------------------------------------------------------------
1352 VISU::Result::Resolution
1353 VISU::Result_i
1354 ::GetResolution(const char* theMeshName,
1355                 const char* thePartName)
1356 {
1357   return VISU::Result::HIDDEN;
1358 }
1359
1360
1361 //---------------------------------------------------------------
1362 void
1363 VISU::Result_i
1364 ::SetResolution(const char* theMeshName,
1365                 const char* thePartName,
1366                 VISU::Result::Resolution theResolution)
1367 {}
1368
1369
1370 //---------------------------------------------------------------
1371 VISU::Result_i*
1372 VISU::Result_i
1373 ::New(SALOMEDS::Study_ptr theStudy,
1374       const ESourceId& theSourceId,
1375       const ECreationId& theCreationId,
1376       CORBA::Boolean theIsBuildImmediately,
1377       CORBA::Boolean theIsBuildFields,
1378       CORBA::Boolean theIsBuildMinMax,
1379       CORBA::Boolean theIsBuildGroups)
1380 {
1381   return new RESULT_CLASS_NAME(theStudy,
1382                                theSourceId,
1383                                theCreationId,
1384                                theIsBuildImmediately,
1385                                theIsBuildFields,
1386                                theIsBuildMinMax,
1387                                theIsBuildGroups);
1388 }
1389
1390
1391 //---------------------------------------------------------------
1392 VISU::Storable*
1393 VISU::Result_i
1394 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
1395                  const Storable::TRestoringMap& theMap,
1396                  const std::string& thePrefix,
1397                  CORBA::Boolean theIsMultiFile)
1398 {
1399   VISU::Result_i* aResult = new RESULT_CLASS_NAME();
1400   return aResult->Restore(theSObject, theMap, thePrefix, theIsMultiFile);
1401 }
1402
1403
1404 //---------------------------------------------------------------
1405 void
1406 VISU::Result_i
1407 ::ToStream(std::ostringstream& theStr)
1408 {
1409   Storable::DataToStream(theStr,"myName", GetFileName().c_str());
1410   Storable::DataToStream(theStr,"myInitFileName", GetInitFileName().c_str());
1411   Storable::DataToStream(theStr,"myCreationId", myCreationId);
1412   Storable::DataToStream(theStr,"myIsBuildFields", myIsFieldsDone);
1413   Storable::DataToStream(theStr,"myIsBuildMinMax", myIsMinMaxDone);
1414   Storable::DataToStream(theStr,"myIsBuildGroups", myIsGroupsDone);
1415 }
1416
1417 //---------------------------------------------------------------
1418
1419 bool
1420 VISU::Result_i
1421 ::ExportMED(const char* theTargetFileName)
1422 {
1423   static QString aCommand;
1424   const char* aTempFileName = myFileInfo.absoluteFilePath().toLatin1();
1425   aCommand.sprintf(" %s %s", aTempFileName, theTargetFileName);
1426   aCommand = QDir::convertSeparators( aCommand );
1427   aCommand.prepend( COPY_COMMAND );
1428
1429   if(system(aCommand.toLatin1().data()) != 0) {
1430     if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand.toLatin1().data());
1431     return false;
1432   }
1433   return true;
1434 }
1435
1436
1437 //---------------------------------------------------------------
1438 std::string
1439 VISU::Result_i
1440 ::GetInitFileName() const
1441 {
1442   return myInitFileName;
1443 }
1444
1445
1446 void
1447 VISU::Result_i
1448 ::SetInitFileName(const std::string& theFileName)
1449 {
1450   myInitFileName = theFileName;
1451 }
1452
1453
1454 //---------------------------------------------------------------
1455 std::string
1456 VISU::Result_i
1457 ::GetFileName() const
1458 {
1459   if(GetSourceId() == eFile)
1460     return VISU::MakeFileName(myFileName, this);
1461
1462   return myFileName;
1463 }
1464
1465
1466 QFileInfo
1467 VISU::Result_i
1468 ::GetFileInfo() const
1469 {
1470   return myFileInfo;
1471 }
1472
1473 VISU::Result_i::ECreationId
1474 VISU::Result_i
1475 ::GetCreationId() const
1476 {
1477   return myCreationId;
1478 }
1479
1480
1481 VISU::Result_i::ESourceId
1482 VISU::Result_i
1483 ::GetSourceId() const
1484 {
1485   return mySourceId;
1486 }
1487
1488
1489 //---------------------------------------------------------------
1490 std::string
1491 VISU::Result_i
1492 ::GetEntry()
1493 {
1494   CORBA::String_var anEntry = mySObject->GetID();
1495   return anEntry.in();
1496 }
1497
1498 SALOMEDS::SObject_var
1499 VISU::Result_i
1500 ::GetSObject() const
1501 {
1502   return mySObject;
1503 }
1504
1505 SALOMEDS::Study_var
1506 VISU::Result_i
1507 ::GetStudyDocument() const
1508 {
1509   return myStudyDocument;
1510 }
1511
1512 _PTR(Study)
1513 VISU::Result_i
1514 ::GetStudy() const
1515 {
1516   return myStudy;
1517 }
1518
1519 SALOMEDS::SComponent_var
1520 VISU::Result_i
1521 ::GetSComponent() const
1522 {
1523   return mySComponent;
1524 }
1525
1526 std::string
1527 VISU::Result_i
1528 ::GetEntry(const Storable::TRestoringMap& theRestoringMap)
1529 {
1530   return Storable::FindEntry(myStudyDocument,
1531                              GetEntry(),
1532                              theRestoringMap);
1533 }
1534
1535
1536 //=======================================================================
1537 //function : GetAxisInfo
1538 //purpose  :
1539 //=======================================================================
1540 const VISU::Result_i::TAxisInfo*
1541 VISU::Result_i
1542 ::GetAxisInfo(const string& theMeshName,
1543               TAxis         theAxis,
1544               gp_Dir&       thePlaneNormal)
1545 {
1546   const TAxisInfo* components = NULL;
1547
1548   if ( theAxis < AXIS_X || theAxis > AXIS_Z ) {
1549     MESSAGE(" Bad axis index " << theAxis );
1550     return components;
1551   }
1552
1553   map< string, TGridInfo >::iterator name_info;
1554   name_info = myMeshName2GridInfoMap.find( theMeshName );
1555   TGridInfo * gInfo = 0;
1556
1557   if ( name_info != myMeshName2GridInfoMap.end() )
1558   {
1559     gInfo = & name_info->second;
1560   }
1561   else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z )
1562   {
1563     // check presence of theMeshName
1564     const VISU::TMeshMap& meshMap = myInput->GetMeshMap();
1565     PMesh theMesh;
1566     VISU::TMeshMap::const_iterator aIter = meshMap.find( theMeshName );
1567     if ( aIter == meshMap.end() ) {
1568       MESSAGE("No mesh named " << theMeshName );
1569       return components;
1570     } else
1571       theMesh = aIter->second;
1572
1573     VISU::PUnstructuredGridIDMapper anIDMapper = myInput->GetMeshOnEntity(theMeshName,
1574                                                                           CELL_ENTITY);
1575     vtkUnstructuredGrid* aMesh = anIDMapper->GetUnstructuredGridOutput();
1576
1577     if ( !aMesh || aMesh->GetNumberOfCells() == 0 ) {
1578       MESSAGE( "No cells in the mesh: " << theMeshName );
1579       return components;
1580     }
1581
1582     if ( !theMesh->IsStructured() || theMesh->myIsPolarType ) {
1583       // define axis directions and min cell size in each direction
1584       const int nbAxes = 3;
1585       int iAx;
1586       gp_Vec axDirs[ nbAxes ];
1587       float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
1588       bool axesComputed = false;
1589       for ( vtkIdType iCell = 0; iCell < aMesh->GetNumberOfCells(); ++iCell ) {
1590         vtkCell* cell = aMesh->GetCell( iCell );
1591         
1592         if (cell->GetCellType() != VTK_HEXAHEDRON &&
1593             cell->GetCellType() != VTK_QUADRATIC_HEXAHEDRON )
1594           continue;
1595         vtkPoints * points = cell->GetPoints();
1596         vtkFloatingPointType coords[ 4 ][3];
1597         points->GetPoint( 0, coords[0] );
1598         points->GetPoint( 1, coords[1] );
1599         points->GetPoint( 3, coords[2] );
1600         points->GetPoint( 4, coords[3] );
1601         gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] );
1602         for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1603           vtkFloatingPointType* coo = coords[ iAx + 1 ];
1604           gp_Pnt p( coo[0], coo[1], coo[2] );
1605           // min size
1606           vtkFloatingPointType size = p0.SquareDistance( p );
1607           if ( size > FLT_MIN && size < minSize[ iAx ] )
1608             minSize[ iAx ] = size;
1609           // axis direction
1610           if ( !axesComputed ) {
1611             gp_Vec dir( p0, p );
1612             if ( dir.SquareMagnitude() <= gp::Resolution() ) {
1613               break;
1614             }
1615             axDirs[ iAx ] = dir;
1616           }
1617         }
1618         if ( iAx == nbAxes )
1619           axesComputed = true;
1620       }
1621       if ( !axesComputed ) {
1622         MESSAGE("No good hexahedrons in the mesh: " << theMeshName );
1623         return components;
1624       }
1625
1626       // compute axes dirs
1627       gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1628       for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1629         int iPrev = ( iAx == 0 ) ? 2 : iAx - 1;
1630         int iNext = ( iAx == 2 ) ? 0 : iAx + 1;
1631         gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ];
1632       }
1633
1634       // get and sort intermediate component values - projections of nodes
1635       // on axis direction; define bnd box
1636       set< vtkFloatingPointType > comps[ 3 ];
1637       Bnd_Box box;
1638       vtkPoints * points = aMesh->GetPoints();
1639       vtkIdType iP, nbP = aMesh->GetNumberOfPoints();
1640       for ( iP = 0; iP < nbP; ++iP ) {
1641         vtkFloatingPointType coo[3];
1642         points->GetPoint( iP, coo );
1643         gp_Pnt p( coo[0], coo[1], coo[2] );
1644         box.Add( p );
1645         for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1646           const gp_Dir& dir = gInfo->myAxis[ iAx ];
1647           vtkFloatingPointType dot = dir.XYZ() * p.XYZ();
1648           comps[ iAx ].insert( dot );
1649         }
1650       }
1651
1652       // find a range of projections of bnd box corners on each axis
1653       vtkFloatingPointType range[3], firstValue[3];
1654       double x[2],y[2],z[2];
1655       box.Get(x[0],y[0],z[0],x[1],y[1],z[1]);
1656       for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1657         set< vtkFloatingPointType > bndComps;
1658         const gp_Dir& dir = gInfo->myAxis[ iAx ];
1659         for ( int iX = 0; iX < 2; ++iX ) {
1660           for ( int iY = 0; iY < 2; ++iY ) {
1661             for ( int iZ = 0; iZ < 2; ++iZ ) {
1662               gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] );
1663               vtkFloatingPointType dot = dir.XYZ() * p.XYZ();
1664               bndComps.insert( dot );
1665             }
1666           }
1667         }
1668         firstValue[ iAx ] = *bndComps.begin();
1669         range[ iAx ] = *bndComps.rbegin() - *bndComps.begin();
1670       }
1671
1672       // compute component values
1673       for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1674         list< vtkFloatingPointType > values;
1675         int nbVals = 0;
1676         set< vtkFloatingPointType >& comp = comps[ iAx ];
1677         set< vtkFloatingPointType >::iterator val = comp.begin();
1678         vtkFloatingPointType bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ];
1679         vtkFloatingPointType tol = 0.1 * sqrt( minSize[ iAx ]) / rng;
1680         for ( ; val != comp.end(); ++val ) {
1681           vtkFloatingPointType value = ( *val - first ) / rng;
1682           if ( value > bnd ) {
1683             values.push_back( value );
1684             bnd = value + tol;
1685             nbVals++;
1686           }
1687         }
1688         // store values in gInfo
1689         vector< vtkFloatingPointType >& myComp = gInfo->myComponets[ iAx ];
1690         myComp.resize( nbVals );
1691         list< vtkFloatingPointType >::iterator v = values.begin();
1692         for ( int i = 0; v != values.end(); ++v ){
1693           myComp[ i++ ] = *v;
1694         }
1695       }
1696     }
1697     else {
1698       vtkIdType aMeshDim = theMesh->myDim;
1699       gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1700       switch ( aMeshDim ) {
1701       case 3: {
1702         gp_Dir aDir(0.0,0.0,1.0);
1703         gInfo->myAxis[ 2 ] = aDir;
1704       }
1705       case 2: {
1706         gp_Dir aDir(0.0,1.0,0.0);
1707         gInfo->myAxis[ 1 ] = aDir;
1708       }
1709       case 1: {
1710         gp_Dir aDir(1.0,0.0,0.0);
1711         gInfo->myAxis[ 0 ] = aDir;
1712       }}
1713
1714       TStructuredId aStructuredId = theMesh->GetStructure();
1715       vector<vtkFloatingPointType> PointsCoords[3];
1716       vtkPoints* aPoints = aMesh->GetPoints();
1717       switch ( aMeshDim ) {
1718       case 3: {
1719         TStructuredId aCoordIJK;
1720         vtkIdType nbZ = aStructuredId[2];
1721         for ( int i = 0; i < nbZ; i++ ) {
1722           aCoordIJK[2] = i + 1;
1723           vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1724           vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1725           vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1726           PointsCoords[2].push_back(aPCoord[2]);
1727         }
1728       }
1729       case 2: {
1730         TStructuredId aCoordIJK;
1731         vtkIdType nbJ = aStructuredId[1];
1732         for ( int i = 0; i < nbJ; i++ ) {
1733           aCoordIJK[1] = i + 1;
1734           vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1735           vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1736           vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1737           PointsCoords[1].push_back(aPCoord[1]);
1738         }
1739       }
1740       case 1: {
1741         TStructuredId aCoordIJK;
1742         vtkIdType nbI = aStructuredId[0];
1743         for ( int i = 0; i < nbI; i++ ) {
1744           aCoordIJK[0] = i + 1;
1745           vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1746           vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1747           vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1748           PointsCoords[0].push_back(aPCoord[0]);
1749         }
1750       }}
1751       for ( int i = 0; i < aMeshDim; i++ ) {
1752         vector< vtkFloatingPointType >& myComp = gInfo->myComponets[ i ];
1753         int aSize = PointsCoords[i].size();
1754         if ( aSize > 0 ) {
1755           vtkFloatingPointType aLen = PointsCoords[i][aSize-1] - PointsCoords[i][0];
1756           myComp.resize(aSize);
1757           myComp[0] = 0;
1758           for ( int k = 1; k < aSize; k++ ) {
1759             myComp[k]=myComp[k-1] + (PointsCoords[i][k]-PointsCoords[i][k-1])/aLen;
1760           }
1761         }
1762       }
1763     }
1764   }
1765
1766   // set return values
1767   if ( gInfo ) {
1768     thePlaneNormal = gInfo->myAxis[ theAxis ];
1769     components = & gInfo->myComponets[ theAxis ];
1770   }
1771
1772   return components;
1773 }
1774
1775 SALOME_MED::MedFileInfo* VISU::Result_i::GetMEDFileInfo()
1776 {
1777   SALOME_MED::MedFileInfo_var res = new SALOME_MED::MedFileInfo();
1778
1779   QString fpath = myFileInfo.absoluteFilePath();
1780   res->fileName = fpath.toLatin1().constData();
1781   res->fileSize = myFileInfo.size();
1782   int major, minor, release;
1783   if( !MED::getMEDVersion( fpath.toLatin1().constData(), major, minor, release ) )
1784   {
1785     major = -1;
1786     minor = -1;
1787     release = -1;
1788   }
1789   res->major = major;
1790   res->minor = minor;
1791   res->release = release;
1792   return res._retn();
1793 }