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