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