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