]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.cxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VisuGUI_Tools.cxx
25 //  Author : Sergey Anikin
26 //  Module : VISU
27
28
29 #include "VisuGUI_Tools.h"
30
31 #include "VisuGUI.h"
32 #include "VisuGUI_ViewTools.h"
33
34 #include "VISU_Gen_i.hh"
35 #include "VISU_Prs3d_i.hh"
36 #include "VISU_Result_i.hh"
37 #include "VISU_Table_i.hh"
38 #include "VISU_Mesh_i.hh"
39 #include "VISU_ViewManager_i.hh"
40
41 #include "VISU_Actor.h"
42 #include "VISU_ScalarMapAct.h"
43
44 #include "SalomeApp_Module.h"
45 #include "SalomeApp_Study.h"
46 #include "SalomeApp_Application.h"
47
48 #include "LightApp_DataObject.h"
49 #include "LightApp_SelectionMgr.h"
50
51 #include "OB_Browser.h"
52
53 #include "SALOME_ListIO.hxx"
54 #include "SALOME_ListIteratorOfListIO.hxx"
55
56 #include "SVTK_ViewWindow.h"
57 #include "SVTK_Functor.h"
58
59 #include "VTKViewer_Algorithm.h"
60
61 #include "SPlot2d_ViewModel.h"
62 #include "Plot2d_ViewFrame.h"
63 #include "Plot2d_ViewManager.h"
64
65 #include "SUIT_Session.h"
66 #include "SUIT_MessageBox.h"
67
68 #include <vtkRenderer.h>
69 #include <vtkActorCollection.h>
70
71
72 //=============================================================================
73 namespace VISU
74 {
75   SUIT_Desktop*
76   GetDesktop(const CAM_Module* theModule)
77   {
78     return theModule->application()->desktop();
79   }
80
81   LightApp_SelectionMgr*
82   GetSelectionMgr(const SalomeApp_Module* theModule)
83   {
84     return theModule->getApp()->selectionMgr();
85   }
86
87   SalomeApp_Study*
88   GetAppStudy(const CAM_Module* theModule)
89   {
90     return
91       dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
92   }
93
94   _PTR(Study)
95   GetCStudy(const SalomeApp_Study* theStudy)
96   {
97     return theStudy->studyDS();
98   }
99
100   bool
101   IsStudyLocked( _PTR(Study) theStudy )
102   {
103     if( theStudy )
104       return theStudy->GetProperties()->IsLocked();
105     return true;
106   }
107
108   bool
109   CheckLock( _PTR(Study) theStudy,
110              QWidget* theWidget )
111   {
112     if(IsStudyLocked(theStudy)){
113       SUIT_MessageBox::warn1(theWidget,
114                              QObject::tr("WRN_VISU_WARNING"),
115                              QObject::tr("WRN_STUDY_LOCKED"),
116                              QObject::tr("BUT_OK"));
117         return true;
118     }
119     return false;
120   }
121
122   LightApp_DataObject*
123   FindDataObject(SUIT_DataObject* theDataObject,
124                  const QString& theEntry,
125                  int theLevel)
126   {
127     int aLevel = theDataObject->level() + 2;
128     QString aSourceEntry = theEntry.section(':',0,aLevel);
129     DataObjectList aList;
130     theDataObject->children(aList);
131     DataObjectListIterator aDataObjectIter(aList);
132     while(SUIT_DataObject* aDataObject = aDataObjectIter.current()){
133       if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(aDataObject)){
134         QString anEntry = aChildDataObject->entry();
135         QString aCurrentEntry = anEntry.section(':',0,aLevel);
136         if(aSourceEntry == aCurrentEntry){
137           if(theLevel == aLevel){
138             return aChildDataObject;
139           }else{
140             return FindDataObject(aChildDataObject,theEntry,theLevel);
141           }
142         }
143       }
144       ++aDataObjectIter;
145     }
146     return NULL;
147   }
148
149   LightApp_DataObject*
150   FindDataObject(CAM_Module* theModule,
151                  _PTR(SObject) theSObject)
152   {
153     CAM_DataModel* aDataModel = theModule->dataModel();
154     CAM_DataObject* aRootDataObject = aDataModel->root();
155     if(_PTR(SComponent) aComponent = theSObject)
156       return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
157
158     int aLevel = theSObject->Depth();
159     std::string anEntry = theSObject->GetID();
160     return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
161   }
162
163   void
164   UpdateObjBrowser(SalomeApp_Module* theModule,
165                    bool theIsUpdateDataModel,
166                    _PTR(SObject) theSObject)
167   {
168     LightApp_DataObject* aDataObject = NULL;
169     if(theSObject)
170       aDataObject = FindDataObject(theModule,theSObject);
171
172     theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
173     theModule->getApp()->updateActions();
174   }
175
176   bool
177   IsSObjectTable( _PTR(SObject) theSObject )
178   {
179     if ( theSObject ) {
180       _PTR(GenericAttribute) anAttr;
181       if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
182         return true;
183       if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
184         return true;
185     }
186     return false;
187   }
188
189   VISU_Gen_i*
190   GetVisuGen(const CAM_Module* theModule)
191   {
192     static VISU_Gen_i* aGen = NULL;
193     if(!aGen){
194       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
195       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
196       VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
197       if(!CORBA::is_nil(aVISU)){
198         aGen = VISU_Gen_i::GetVisuGenImpl();
199         aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
200       }
201     }
202     if(!aGen)
203       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
204     return aGen;
205   }
206
207   SALOME_MED::MED_Gen_var
208   GetMEDEngine()
209   {
210     static SALOME_MED::MED_Gen_var aGen;
211     if(CORBA::is_nil(aGen)){
212       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
213       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
214       aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
215     }
216     if(CORBA::is_nil(aGen))
217       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
218     return aGen;
219   }
220
221
222   VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
223   {
224     VISU::Storable::TRestoringMap aMap;
225     if (theSObject) {
226       _PTR(GenericAttribute) anAttr;
227       if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
228         _PTR(AttributeComment) aComment (anAttr);
229         std::string aValue = aComment->Value();
230         QString aString (aValue.c_str());
231         VISU::Storable::StrToMap(aString, aMap);
232       }
233     }
234     return aMap;
235   }
236
237   QString getValue (_PTR(SObject) theSObject, QString theKey)
238   {
239     QString aStr("");
240     VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
241     if (!aMap.empty())
242       aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
243     return aStr;
244   }
245
246   //------------------------------------------------------------
247   // Selection
248   CORBA::Object_var
249   GetSelectedObj(const SalomeApp_Study* theStudy,
250                  const QString& theEntry,
251                  VISU::Storable::TRestoringMap* theMap)
252   {
253     if (!theStudy || theEntry.isEmpty())
254       return CORBA::Object::_nil();
255
256     _PTR(Study) aStudy = GetCStudy(theStudy);
257     _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
258     if (aSObject) {
259       _PTR(GenericAttribute) anAttr;
260       if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
261         _PTR(AttributeComment) aComment (anAttr);
262         std::string aValue = aComment->Value();
263         QString aString (aValue.c_str());
264         VISU::Storable::StrToMap(aString, *theMap);
265       }
266       return VISU::ClientSObjectToObject(aSObject);
267     }
268     return CORBA::Object::_nil();
269   }
270
271   CORBA::Object_var
272   GetSelectedObj(const SalomeApp_Module* theModule,
273                  Handle(SALOME_InteractiveObject)* theIO,
274                  VISU::Storable::TRestoringMap* theMap)
275   {
276     LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
277     SALOME_ListIO aListIO;
278     aSelectionMgr->selectedObjects(aListIO);
279     SALOME_ListIteratorOfListIO anIter(aListIO);
280     if(anIter.More()){
281       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
282       if(theIO)
283         *theIO = anIO;
284       if(anIO->hasEntry())
285         return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
286     }
287     return CORBA::Object::_nil();
288   }
289
290   VISU::Prs3d_i*
291   GetPrsToModify(const SalomeApp_Module* theModule,
292                  Handle(SALOME_InteractiveObject)* theIO,
293                  VISU::Storable::TRestoringMap* theMap)
294   {
295     if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
296       return NULL;
297
298     CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
299     if (CORBA::is_nil(anObject))
300       return NULL;
301
302     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
303     if (!aServant.in())
304       return NULL;
305
306     return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
307   }
308
309   void
310   Add(LightApp_SelectionMgr* theSelectionMgr,
311       const Handle(SALOME_InteractiveObject)& theIO)
312   {
313     SALOME_ListIO aListIO;
314     theSelectionMgr->selectedObjects(aListIO);
315     aListIO.Append(theIO);
316     theSelectionMgr->setSelectedObjects(aListIO);
317   }
318
319   void
320   Remove(LightApp_SelectionMgr* theSelectionMgr,
321          const Handle(SALOME_InteractiveObject)& theIO)
322   {
323     if (theIO.IsNull()) return;
324     SALOME_ListIO aListIO, aNewListIO;
325     theSelectionMgr->selectedObjects(aListIO);
326     SALOME_ListIteratorOfListIO anIter (aListIO);
327     for (; anIter.More(); anIter.Next()) {
328       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
329       if (!anIO->isSame(theIO)) {
330         aNewListIO.Append(theIO);
331       }
332     }
333     theSelectionMgr->setSelectedObjects(aNewListIO);
334   }
335
336   /*!
337    * \brief Check, if "Delete" popup-menu can be put on current selection
338    *
339    * \param theModule - is used to access SelectionManager, Study and VISU_Gen
340    * \retval bool - returns TRUE if all currently selected objects are removable
341    */
342   bool
343   IsRemovableSelected (const SalomeApp_Module* theModule)
344   {
345     LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
346     SALOME_ListIO aListIO;
347     aSelectionMgr->selectedObjects(aListIO);
348
349     if (aListIO.Extent() < 1)
350       return false;
351
352     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
353     if (!aStudy) return false;
354
355     // In some cases single selection can have its own popup-menu item for deletion
356     /*if (aListIO.Extent() == 1) {
357       Handle(SALOME_InteractiveObject) anIO = aListIO.First();
358       _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
359       if (aSObject) {
360         VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
361         if (aType == VISU::TVIEW3D) {
362           return false; // special case
363         }
364       }
365     }*/
366
367     SALOME_ListIteratorOfListIO anIter (aListIO);
368     for (; anIter.More(); anIter.Next()) {
369       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
370       if (anIO->hasEntry()) {
371
372         // asv : if selected object is a Save Point object selected in object browser - return false
373         if ( QString( anIO->getEntry() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
374           return false;
375
376         _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
377         VISU::Storable::TRestoringMap pMap;
378         if (aSObject) {
379           CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
380           if (!CORBA::is_nil(aCORBAObject)) {
381             VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
382             if (CORBA::is_nil(aRemovableObj)) {
383               // Not removable CORBA object
384               return false;
385             }
386           } else {
387             // Can be removed, if lays directly under VISU
388             // (first sub-level) or is a child of such an object
389             string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
390             _PTR(GenericAttribute) anAttr;
391             _PTR(AttributeComment) aComment;
392
393             bool isUnderVISU = false;
394             _PTR(SObject) aFatherSObject = aSObject->GetFather();
395             if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
396               _PTR(AttributeComment) aComment (anAttr);
397               aNAME = aComment->Value();
398               if (aNAME == aVisuNAME) {
399                 isUnderVISU = true;
400               }
401             }
402             if (!isUnderVISU) {
403               // Not directly under VISU component, check father
404               aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
405               if (!CORBA::is_nil(aCORBAObject)) {
406                 // Father has IOR
407                 return false;
408               }
409
410               isUnderVISU = false;
411               aFatherSObject = aFatherSObject->GetFather();
412               if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
413                 _PTR(AttributeComment) aComment (anAttr);
414                 aNAME = aComment->Value();
415                 if (aNAME == aVisuNAME) {
416                   isUnderVISU = true;
417                 }
418               }
419               if (!isUnderVISU) {
420                 // Father is not directly under VISU component
421                 return false;
422               }
423             }
424           }
425         }
426       }
427     }
428     return true;
429   }
430
431   void
432   DeleteSObject(VisuGUI* theModule,
433                 _PTR(Study) theStudy,
434                 _PTR(SObject) theSObject)
435   {
436     _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
437     for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
438       _PTR(SObject) aChildSObject = aChildIter->Value();
439       CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
440       ErasePrs(theModule, aChildObj, /*repaint_view_window = */false);
441     }
442
443     CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
444     if (!CORBA::is_nil(anObj)) {
445       ErasePrs(theModule, anObj, /*repaint_view_window = */true);
446
447       VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
448       if (!CORBA::is_nil(aRemovableObject)) {
449         aRemovableObject->RemoveFromStudy();
450       }
451     } else {
452       // Remove aSObject together with all its sub-objects
453
454       VISU::RemoveFromStudy(theSObject,
455                             false,  // remove not only IOR attribute, but Object With Children
456                             false); // not Destroy() sub-objects
457     }
458   }
459
460   void
461   DeletePrs3d(VisuGUI* theModule,
462               VISU::Prs3d_i* thePrs,
463               const Handle(SALOME_InteractiveObject)& theIO)
464   {
465     if (!thePrs)
466       return;
467     if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
468       return;
469
470     SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
471     RemoveScalarBarPosition(theModule, vw, thePrs);
472
473     thePrs->RemoveFromStudy();
474   }
475
476   // Presentation management
477
478   void
479   ChangeRepresentation (const SalomeApp_Module* theModule,
480                         VISU::PresentationType  theType)
481   {
482     SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
483     if (!vw)
484       return;
485
486     Handle(SALOME_InteractiveObject) anIO;
487     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
488     if (CORBA::is_nil(anObject)) return;
489
490     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
491     if (CORBA::is_nil(aVisuObj)) return;
492
493     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
494     if (!aServant.in()) return;
495
496     VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
497     if (aPrs3d) {
498       if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
499         switch (theType) {
500         case VISU::SHRINK:
501           if (anActor->IsShrunk())
502             anActor->UnShrink();
503           else
504             anActor->SetShrink();
505           break;
506         default:
507           if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
508             aMesh->SetPresentationType(theType);
509             RecreateActor(theModule, aMesh);
510           } else {
511             anActor->SetRepresentation(theType);
512           }
513         }
514         vw->Repaint();
515       }
516     }
517   }
518
519   void
520   SetShading ( const SalomeApp_Module* theModule,
521               bool theOn )
522   {
523     SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
524     if (!vw)
525       return;
526
527     Handle(SALOME_InteractiveObject) anIO;
528     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
529     if (CORBA::is_nil(anObject)) return;
530
531     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
532     if (CORBA::is_nil(aVisuObj)) return;
533
534     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
535     if (!aServant.in()) return;
536
537     VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
538     if (aPrs3d) {
539       if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
540         if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
541           aScalarMapActor->SetShading( theOn );
542       }
543       vw->Repaint();
544     }
545   }
546
547   // SObject type
548
549   bool
550   CheckTimeStamp(const SalomeApp_Module* theModule,
551                  _PTR(SObject)&          theSObject,
552                  Handle(SALOME_InteractiveObject)* theIO)
553   {
554     Handle(SALOME_InteractiveObject) anIO;
555     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
556     if (theIO)
557       *theIO = anIO;
558     if (!anIO.IsNull() && anIO->hasEntry()){
559       _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
560       theSObject = aStudy->FindObjectID(anIO->getEntry());
561       QString aValue = getValue(theSObject,"myType");
562       if (aValue.toInt() == int(VISU::TTIMESTAMP))
563         return true;
564     }
565     SUIT_MessageBox::warn1(GetDesktop(theModule),
566                            QObject::tr("WRN_VISU"),
567                            QObject::tr("WRN_NO_AVAILABLE_DATA"),
568                            QObject::tr("BUT_OK") );
569     return false;
570   }
571
572   VISU::Result_i*
573   CheckResult(const SalomeApp_Module* theModule,
574               _PTR(SObject)           theSource,
575               VISU::Result_var&       theResult)
576   {
577     if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
578       return NULL;
579       
580     _PTR(SObject) aSObj = theSource->GetFather();
581     if (!aSObj)
582       return NULL;
583
584     aSObj = aSObj->GetFather();
585     if (!aSObj)
586       return NULL;
587
588     aSObj = aSObj->GetFather();
589     if (!aSObj)
590       return NULL;
591
592     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
593     if (CORBA::is_nil(anObject)) {
594       aSObj = aSObj->GetFather();
595       if (!aSObj)
596         return NULL;
597       anObject = VISU::ClientSObjectToObject(aSObj);
598     }
599
600     if (CORBA::is_nil(anObject))
601       return NULL;
602
603     theResult = VISU::Result::_narrow(anObject);
604     return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
605   }
606
607   // VTK View
608
609   VISU_Actor*
610   PublishMeshInView(const SalomeApp_Module* theModule,
611                     VISU::Prs3d_i* thePrs,
612                     SVTK_ViewWindow* theViewWindow)
613   {
614     VISU_Actor* aActor = NULL;
615     if (!thePrs || !theViewWindow)
616       return aActor;
617
618     QApplication::setOverrideCursor( Qt::waitCursor );
619     try {
620       if ((aActor = thePrs->CreateActor()))
621         theViewWindow->AddActor(aActor);
622     } catch(std::exception& exc) {
623       SUIT_MessageBox::warn1
624         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
625          QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
626          QObject::tr("BUT_OK"));
627     }
628     QApplication::restoreOverrideCursor();
629
630     return aActor;
631   }
632
633   void
634   RepaintViewWindows (const SalomeApp_Module* theModule,
635                       const Handle(SALOME_InteractiveObject)& theIObject)
636   {
637     TViewWindows aViewWindows;
638     if (SalomeApp_Application* anApp = theModule->getApp()) {
639       ViewManagerList aViewManagerList;
640       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
641       QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
642       while (SUIT_ViewManager* aViewManager = anIter.current()) {
643         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
644         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
645           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
646             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
647               if (vw->isVisible(theIObject)) {
648                 vw->getRenderer()->ResetCameraClippingRange();
649                 vw->Repaint();
650                 vw->highlight(theIObject, true, true);
651               }
652             }
653           }
654         }
655         ++anIter;
656       }
657     }
658   }
659
660   VISU_Actor*
661   FindActor(SVTK_ViewWindow* theViewWindow,
662             const char* theEntry)
663   {
664     using namespace SVTK;
665     if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
666       if(vtkActorCollection* aCollection = aRenderer->GetActors()){
667         if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
668           return anActor;
669         }
670       }
671     }
672     return NULL;
673   }
674
675   VISU_Actor*
676   FindActor(SVTK_ViewWindow* theViewWindow,
677             VISU::Prs3d_i* thePrs)
678   {
679     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
680     CORBA::String_var anEntry = aSObject->GetID();
681     return FindActor(theViewWindow,anEntry.in());
682   }
683
684   void
685   RecreateActor (const SalomeApp_Module* theModule,
686                  VISU::Prs3d_i* thePrs)
687   {
688     QApplication::setOverrideCursor(Qt::waitCursor);
689
690     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
691     CORBA::String_var anEntry = aSObject->GetID();
692
693     try {
694       thePrs->UpdateActors();
695     } catch (std::runtime_error& exc) {
696       INFOS(exc.what());
697       QApplication::restoreOverrideCursor();
698       SUIT_MessageBox::warn1
699         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
700          QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
701          QObject::tr("BUT_OK"));
702
703       thePrs->RemoveActors();
704       return;
705     }
706     QApplication::restoreOverrideCursor();
707   }
708
709   static 
710   bool
711   ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
712                            vtkFloatingPointType allBounds[6], 
713                            const char* theActorClassName = "VISU_Actor")
714   {
715     vtkRenderer *aRen = theViewWindow->getRenderer();
716     vtkActorCollection *anActColl = aRen->GetActors(); 
717     vtkProp *prop;
718     vtkFloatingPointType *bounds;
719     int somethingVisible = false;
720
721     allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
722     allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
723     // loop through all props
724     for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
725       // if it's invisible, or has no geometry, we can skip the rest 
726       if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
727         bounds = prop->GetBounds();
728         // make sure we haven't got bogus bounds
729         if (bounds != NULL &&
730             bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
731             bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
732             bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
733         {
734           somethingVisible = true;
735           if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
736           if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
737           if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
738           if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
739           if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
740           if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
741         }//not bogus
742       }
743     }
744     return somethingVisible;
745   }
746
747   void SetFitAll(SVTK_ViewWindow* theViewWindow)
748   {
749     static vtkFloatingPointType PRECISION = 0.000001;
750     static vtkFloatingPointType DEVIATION = 600;
751     vtkFloatingPointType XYZ_Bnd[6];
752     if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
753
754     vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
755     vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
756     vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
757
758     enum CameraOrient {e3D, eFront, eLeft, eTop};
759     CameraOrient aCameraOrient = e3D;
760     if (absX <= PRECISION) aCameraOrient = eFront;
761     else {
762       if (absY <= PRECISION) aCameraOrient = eLeft;
763       else {
764         if (absZ <= PRECISION) aCameraOrient = eTop;
765         else {
766           // all the three dimensions exceeds precision
767           vtkFloatingPointType dev_abs_XY = absX / absY;
768           vtkFloatingPointType dev_abs_YZ = absY / absZ;
769           vtkFloatingPointType dev_abs_XZ = absX / absZ;
770           if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
771             aCameraOrient = eLeft;
772           else {
773             if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
774               aCameraOrient = eFront;
775             else {
776               if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
777                 aCameraOrient = eTop;
778             }
779           }
780         }
781       }
782     }
783
784     switch (aCameraOrient) {
785     case eFront: theViewWindow->onFrontView(); break;
786     case eLeft:  theViewWindow->onLeftView();  break;
787     case eTop:   theViewWindow->onTopView();   break;
788     case e3D:    theViewWindow->onResetView(); break;
789     }
790     theViewWindow->getRenderer()->ResetCameraClippingRange();
791     theViewWindow->onFitAll();
792   }
793
794   //************************************************************
795   // Plot2d View
796
797   SPlot2d_Viewer*
798   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
799   {
800     if(SalomeApp_Application* anApp = theModule->getApp()){
801       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
802         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
803       }
804     }
805     return NULL;
806   }
807
808   // Internal function used by several public functions below
809   void
810   UpdateCurve(VISU::Curve_i* theCurve,
811               Plot2d_ViewFrame* aPlot,
812               SPlot2d_Curve* plotCurve,
813               int theDisplaying)
814   {
815     if ( theDisplaying == VISU::eErase ) {
816       if ( plotCurve && aPlot )
817         aPlot->eraseCurve( plotCurve, false );
818     }
819     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
820       if ( plotCurve ) {
821         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
822         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
823         plotCurve->setVerTitle( theCurve->GetName() );
824         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
825         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
826         double* xList = 0;
827         double* yList = 0;
828         int     nbPoints = theCurve->GetData( xList, yList );
829         if ( nbPoints > 0 && xList && yList ) {
830           plotCurve->setData( xList, yList, nbPoints );
831         }
832         if ( !theCurve->IsAuto() ) {
833           plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
834           plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
835           SALOMEDS::Color color = theCurve->GetColor();
836           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
837         }
838         plotCurve->setAutoAssign( theCurve->IsAuto() );
839         if( aPlot )
840           aPlot->displayCurve( plotCurve, false );
841       }
842       else {
843         Plot2d_Curve* crv = theCurve->CreatePresentation();
844         if ( crv ) {
845           if( aPlot )
846             aPlot->displayCurve( crv, false );
847           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
848           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
849           SALOMEDS::Color newColor;
850           newColor.R = crv->getColor().red()/255.;
851           newColor.G = crv->getColor().green()/255.;
852           newColor.B = crv->getColor().blue()/255.;
853           theCurve->SetColor( newColor );
854           crv->setAutoAssign( theCurve->IsAuto() );
855         }
856       }
857     }
858   }
859
860   void
861   PlotTable(const SalomeApp_Module* theModule,
862             VISU::Table_i* table,
863             int theDisplaying)
864   {
865     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
866     if ( !aView )
867       return;
868     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
869     if ( !aPlot )
870       return;
871
872     if ( theDisplaying == VISU::eDisplayOnly )
873       aPlot->EraseAll();
874     QList<Plot2d_Curve> clist;
875     aPlot->getCurves( clist );
876     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
877     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
878     if ( TableSO ) {
879       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
880       for ( ; Iter->More(); Iter->Next() ) {
881         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
882         if( !CORBA::is_nil( childObject ) ) {
883           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
884           if( !CORBA::is_nil( aCurve ) ) {
885             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
886             SPlot2d_Curve* plotCurve = 0;
887             SPlot2d_Curve* tmpCurve;
888             for ( int i = 0; i < clist.count(); i++ ) {
889               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
890               if (tmpCurve && tmpCurve->hasIO() &&
891                   !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
892                 plotCurve = tmpCurve;
893                 break;
894               }
895             }
896
897             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
898
899             if ( theDisplaying == VISU::eErase && plotCurve ) {
900               clist.remove( plotCurve );
901             }
902           }
903         }
904       }
905       aPlot->Repaint();
906     }
907   }
908
909   void
910   PlotCurve(const SalomeApp_Module* theModule,
911             VISU::Curve_i* theCurve,
912             int theDisplaying)
913   {
914     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
915     if ( !aView )
916       return;
917     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
918     if ( !aPlot )
919       return;
920
921 //  if ( theDisplaying == VISU::eDisplayOnly )
922 //    aPlot->EraseAll();
923     QList<Plot2d_Curve> clist;
924     aPlot->getCurves( clist );
925     SPlot2d_Curve* plotCurve = 0;
926     SPlot2d_Curve* tmpCurve;
927     for (int i = 0; i < clist.count(); i++) {
928       tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
929       if (tmpCurve && tmpCurve->hasIO() &&
930           !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
931         plotCurve = tmpCurve;
932       } else if (theDisplaying == VISU::eDisplayOnly) {
933         aPlot->eraseCurve(clist.at(i));
934       }
935     }
936
937     UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
938
939     aPlot->Repaint();
940   }
941
942   void
943   PlotRemoveCurve(const SalomeApp_Module* theModule,
944                   VISU::Curve_i* pCrv)
945   {
946     QString anEntry = pCrv->GetEntry();
947     ViewManagerList pvm_list;
948     theModule->getApp()->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
949     for( SUIT_ViewManager* mgr = pvm_list.first(); mgr; mgr = pvm_list.next() ){
950       Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( mgr );
951       if( pvm ){
952         SPlot2d_Viewer* aSPlot2d = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
953         if( aSPlot2d ){
954           Plot2d_ViewFrame* aPlot = aSPlot2d->getActiveViewFrame();
955           if(aPlot){
956             QList<Plot2d_Curve> clist;
957             aPlot->getCurves( clist );
958             for (int i = 0; i < clist.count(); i++) {
959               if(SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i)))
960                 if(plotCurve->hasIO() && (plotCurve->getIO()->getEntry() == anEntry))
961                   aPlot->eraseCurve(clist.at(i));
962             }
963           }
964         }
965       }
966     }
967   }
968   
969   void
970   PlotContainer(const SalomeApp_Module* theModule,
971                 VISU::Container_i* container,
972                 int theDisplaying)
973   {
974     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
975     if ( !aView )
976       return;
977     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
978     if ( !aPlot )
979       return;
980
981     if ( theDisplaying == VISU::eDisplayOnly )
982       aPlot->EraseAll();
983     QList<Plot2d_Curve> clist;
984     aPlot->getCurves( clist );
985     if ( container->GetNbCurves() > 0 ) {
986       int nbCurves = container->GetNbCurves();
987       for ( int k = 1; k <= nbCurves; k++ ) {
988         VISU::Curve_i* theCurve = container->GetCurve( k );
989         if ( theCurve && theCurve->IsValid() ) {
990           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
991             (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
992
993           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
994
995           if ( plotCurve && theDisplaying == VISU::eErase ) {
996             clist.remove( plotCurve );
997           }
998         }
999       }
1000     }
1001     aPlot->Repaint();
1002   }
1003
1004   void
1005   CreatePlot(SalomeApp_Module* theModule,
1006              _PTR(SObject) theTableSO)
1007   {
1008     if ( IsSObjectTable(theTableSO) ) {
1009       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1010       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1011       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1012         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1013         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1014
1015         if ( pContainer && pTable ) {
1016           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1017             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1018             if( !CORBA::is_nil( aNewCurve ) ) {
1019               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1020               if ( pCrv ) {
1021                 pContainer->AddCurve( pCrv->_this() );
1022               }
1023             }
1024           }
1025           PlotContainer( theModule, pContainer, VISU::eDisplay );
1026
1027           QString anEntry = pContainer->GetEntry();
1028           _PTR(Study) aStudy = theTableSO->GetStudy();
1029           _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.latin1());
1030           _PTR(SObject) aParentSO = aContainerSO->GetFather();
1031           UpdateObjBrowser(theModule,true,aParentSO);
1032         }
1033       }
1034     }
1035   }
1036
1037   //************************************************************
1038   // Others
1039
1040   void CreateMesh (const SalomeApp_Module* theModule,
1041                    const Handle(SALOME_InteractiveObject)& theIO,
1042                    SVTK_ViewWindow* theViewWindow)
1043   {
1044     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1045     //if (CheckLock(aStudy))
1046     //  return;
1047
1048     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1049
1050     // Get VISU::Result
1051     VISU::Result_var aResult;
1052     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1053     if (pResult == NULL)
1054       return;
1055
1056     Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1057     bool isExist;
1058     string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1059     if (!isExist)
1060       return;
1061
1062     CORBA::Object_var aMesh;
1063     string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1064 #ifdef CHECKTIME
1065     Utils_Timer timer;
1066     timer.Start();
1067 #endif
1068     if (aComment == "ENTITY") {
1069       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1070       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1071         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1072     } else if (aComment == "FAMILY") {
1073       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1074       string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1075       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1076         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1077           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1078     } else if (aComment == "GROUP") {
1079       string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1080       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1081         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1082     }
1083 #ifdef CHECKTIME
1084     timer.Stop();
1085     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1086     timer.Show();
1087 #endif
1088
1089     //QApplication::restoreOverrideCursor();
1090     VISU::Mesh_i* pPresent = NULL;
1091     if (!CORBA::is_nil(aMesh))
1092       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1093     if (pPresent == NULL) {
1094       SUIT_MessageBox::warn1 (GetDesktop(theModule),
1095                               QObject::tr("WRN_VISU"),
1096                               QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1097                               QObject::tr("BUT_OK"));
1098       return;
1099     }
1100
1101     if (theViewWindow) {
1102       try {
1103 #ifdef CHECKTIME
1104         Utils_Timer timer;
1105         timer.Start();
1106 #endif
1107         PublishMeshInView(theModule, pPresent, theViewWindow);
1108         SetFitAll(theViewWindow);
1109 #ifdef CHECKTIME
1110         timer.Stop();
1111         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1112         timer.Show();
1113 #endif
1114       } catch (std::runtime_error& exc) {
1115         INFOS(exc.what());
1116         SUIT_MessageBox::warn1
1117           (GetDesktop(theModule), QObject::tr("WRN_VISU"),
1118            QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1119            QObject::tr("BUT_OK"));
1120       }
1121     }
1122
1123     theModule->application()->putInfo(QObject::tr("INF_DONE"));
1124     // Make "Save" button active
1125     theModule->getApp()->updateActions();
1126   }
1127
1128   // ========================================================================================
1129   // GetPrs3dList: find list of presentations for the given object
1130   // ========================================================================================
1131   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1132                                             const Handle(SALOME_InteractiveObject)& theIO)
1133   {
1134     std::vector<VISU::Prs3d_i*> aList;
1135     if (!theIO.IsNull() && theIO->hasEntry()) {
1136       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1137       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1138       aList = GetPrs3dList(theModule, aSObject);
1139     }
1140     return aList;
1141   }
1142
1143   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1144                                             _PTR(SObject) theObject)
1145   {
1146     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1147     if (!theObject)
1148       return aList;
1149
1150     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1151
1152     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1153     if (!CORBA::is_nil(aCORBAObject)) {
1154       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1155       if (!CORBA::is_nil(aVisuObj)) {
1156         VISU::VISUType aType = aVisuObj->GetType();
1157         switch (aType) {
1158         case VISU::TSCALARMAP:
1159         case VISU::TISOSURFACE:
1160         case VISU::TDEFORMEDSHAPE:
1161         case VISU::TCUTPLANES:
1162         case VISU::TCUTLINES:
1163         case VISU::TVECTORS:
1164         case VISU::TSTREAMLINES:
1165         case VISU::TPLOT3D:
1166         case VISU::TSCALARMAPONDEFORMEDSHAPE:
1167           {
1168             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1169             if (aServant.in()) {
1170               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1171               aList.resize(k+1);
1172               aList[k] = aPrsObject;
1173               k++;
1174             }
1175           }
1176           break;
1177         case VISU::TFIELD:
1178           {
1179             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1180             _PTR(SObject) aTimeStamp;
1181             anIter->Next(); // First is reference on support
1182             for (; anIter->More(); anIter->Next()) {
1183               aTimeStamp = anIter->Value();
1184               if (!aTimeStamp) continue;
1185               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1186               if (!aSubList.empty()) {
1187                 int n = aSubList.size();
1188                 aList.resize(k+n);
1189                 for (int i = 0; i < n; i++) {
1190                   aList[k] = aSubList[i];
1191                   k++;
1192                 }
1193               }
1194             }
1195           }
1196           break;
1197         }
1198       }
1199     } else {
1200       _PTR(GenericAttribute) anAttr;
1201       if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1202         _PTR(AttributeComment) aComment (anAttr);
1203         string aComm = aComment->Value();
1204         QString strIn (aComm.c_str());
1205         VISU::Storable::TRestoringMap pMap;
1206         VISU::Storable::StrToMap(strIn, pMap);
1207         bool isExist;
1208         VISU::VISUType aType =
1209           (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1210         if (isExist) {
1211           switch (aType) {
1212           case VISU::TFIELD:
1213             {
1214               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1215               _PTR(SObject) aTimeStamp;
1216               anIter->Next(); // First is reference on support
1217               for (; anIter->More(); anIter->Next()) {
1218                 aTimeStamp = anIter->Value();
1219                 if (!aTimeStamp) continue;
1220                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1221                 if (!aSubList.empty()) {
1222                   int n = aSubList.size();
1223                   aList.resize(k+n);
1224                   for (int i = 0; i < n; i++) {
1225                     aList[k] = aSubList[i];
1226                     k++;
1227                   }
1228                 }
1229               }
1230             }
1231             break;
1232           case VISU::TTIMESTAMP:
1233             {
1234               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1235               _PTR(SObject) aPrs;
1236               for (; anIter->More(); anIter->Next()) {
1237                 aPrs = anIter->Value();
1238                 if (!aPrs) continue;
1239                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1240                 if (!aSubList.empty()) {
1241                   int n = aSubList.size();
1242                   aList.resize(k+n);
1243                   for (int i = 0; i < n; i++) {
1244                     aList[k] = aSubList[i];
1245                     k++;
1246                   }
1247                 }
1248               }
1249             }
1250             break;
1251           }
1252         }
1253       }
1254     }
1255     return aList;
1256   }
1257
1258   int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1259   {
1260     int minIndx = 1;
1261     std::set<int> aIndexes;
1262     TViewToPrs3d aMap = theModule->getScalarBarsMap();
1263     TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1264     if (aViewToPrsIter != aMap.end()) {
1265       TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1266       for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1267         aIndexes.insert((*aPrsIter).second);
1268       }
1269     }
1270     std::set<int>::const_iterator aIter = aIndexes.begin();
1271     for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1272       std::set<int>::const_iterator aIter = aIndexes.find(i);
1273       if (aIter == aIndexes.end()) { minIndx = i; break; } 
1274       else minIndx = i + 1;
1275     }
1276     return minIndx;
1277   }
1278
1279   void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1280                              VISU::Prs3d_i* thePrs3d, int pos)
1281   {
1282     TViewToPrs3d& aMap = theModule->myScalarBarsMap;
1283     TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1284     aMap[theViewWindow].insert(aPair);
1285   }
1286
1287   void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1288                                VISU::Prs3d_i* thePrs3d)
1289   {
1290     TViewToPrs3d& aMap = theModule->myScalarBarsMap;
1291     TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1292     for (; aIter != aMap[theViewWindow].end(); aIter++)
1293       if ((*aIter).first == thePrs3d) {
1294         aMap[theViewWindow].erase(*aIter);
1295         return;
1296       }
1297   }
1298 }