Salome HOME
7070d7157f2b33bb91c946068ccea62ebf124139
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
1 // Copyright (C) 2007-2013  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::EngineComponent_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::EngineComponent_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 UnRegister() 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   // Presentation management
568   void
569   ChangeRepresentation (const SalomeApp_Module* theModule,
570                         VISU::PresentationType  theType)
571   {
572     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
573     if(aSelectionInfo.empty())
574       return;
575
576     VISU::Prs3d_i* aPrs3d;
577     VISU::PointMap3d_i* aTable;
578     VISU_Actor* anActor;
579     VISU_ActorBase* anActorBase;
580
581     TSelectionItem aSelectionItem = aSelectionInfo.front();
582     aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
583     if(!aPrs3d) {
584       aTable = dynamic_cast<VISU::PointMap3d_i*>(aSelectionItem.myObjectInfo.myBase);
585       if(!aTable)
586         return;
587     }
588
589     SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
590     if(!aViewWindow)
591       return;
592
593     if (aPrs3d) {
594       anActor = FindActor(aViewWindow, aPrs3d);
595       if(!anActor)
596         return;
597     } else {
598       anActorBase = VISU::FindActorBase(aViewWindow, aTable);
599       if(!anActorBase)
600         return;
601     }
602
603     switch (theType) {
604     case VISU::SHRINK:
605       if (aPrs3d) {
606         bool toShrink;
607         if (anActor->IsShrunk()) {
608           anActor->UnShrink();
609           toShrink = false;
610         }
611         else {
612           anActor->SetShrink();
613           toShrink = true;
614         }
615         if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
616           aMesh->SetShrink(toShrink);
617         }
618       } else if (aTable) {
619         if (anActorBase->IsShrunk())
620           anActorBase->UnShrink();
621         else
622           anActorBase->SetShrink();
623       }
624       break;
625     default:
626       if (aPrs3d) {
627         if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
628           aMesh->SetPresentationType(theType);
629           RecreateActor(theModule, aMesh);
630         } else {
631           anActor->SetRepresentation(theType);
632         }
633       }
634       else if (aTable) {
635         anActorBase->SetRepresentation(theType);
636       }
637     }
638     aViewWindow->Repaint();
639   }
640
641
642   void ChangeQuadratic2DRepresentation (const SalomeApp_Module* theModule,
643                                         VISU::Quadratic2DPresentationType  theType)
644   {
645     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
646     if(aSelectionInfo.empty())
647       return;
648
649     TSelectionItem aSelectionItem = aSelectionInfo.front();
650
651     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
652
653     SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
654
655     if(!aPrs3d || !aViewWindow)
656       return;
657
658     VISU_Actor *anActor = FindActor(aViewWindow, aPrs3d);
659     if(!anActor)
660       return;
661
662     if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
663       aMesh->SetQuadratic2DPresentationType(theType);
664       RecreateActor(theModule, aMesh);
665     } else {
666       switch(theType){
667       case VISU::LINES:
668         anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
669         break;
670       case VISU::ARCS:
671         anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
672         break;
673       default:
674         break;
675       }
676     }
677   }
678
679   //------------------------------------------------------------
680   void
681   SetShading ( const SalomeApp_Module* theModule,
682               bool theOn )
683   {
684     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
685     if(aSelectionInfo.empty())
686       return;
687
688     TSelectionItem aSelectionItem = GetSelectedObjects(theModule).front();
689     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
690     if(!aPrs3d)
691       return;
692
693     SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
694     if(!aViewWindow)
695       return;
696
697     VISU_Actor* anActor = FindActor(aViewWindow, aPrs3d);
698     if(!anActor)
699       return;
700
701     if(VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor)){
702       aScalarMapActor->SetShading(theOn);
703       aViewWindow->Repaint();
704     }
705   }
706
707   //------------------------------------------------------------
708   // SObject type
709   bool
710   CheckTimeStamp(const SalomeApp_Module* theModule,
711                  _PTR(SObject)&          theSObject,
712                  Handle(SALOME_InteractiveObject)& theIO,
713                  ColoredPrs3d_i::EPublishInStudyMode& thePublishInStudyMode)
714   {
715     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
716     if(!aSelectionInfo.empty()){
717       TSelectionItem aSelectionItem = aSelectionInfo.front();
718       theIO = aSelectionItem.myIO;
719       theSObject = aSelectionItem.myObjectInfo.mySObject;
720       VISU::VISUType aType = VISU::Storable::SObject2Type(theSObject);
721       if (VISU::TTIMESTAMP == aType){
722         thePublishInStudyMode = ColoredPrs3d_i::EPublishUnderTimeStamp;
723         return true;
724       }
725       if (VISU::TFIELD == aType){
726         thePublishInStudyMode = ColoredPrs3d_i::EPublishIndependently;
727         if(theSObject->FindSubObject(2,theSObject))
728           return true;
729       }
730     }
731     SUIT_MessageBox::warning(GetDesktop(theModule),
732                              QObject::tr("WRN_VISU"),
733                              QObject::tr("WRN_NO_AVAILABLE_DATA") );
734     return false;
735   }
736
737   //------------------------------------------------------------
738   VISU::Result_i*
739   CheckResult(const SalomeApp_Module* theModule,
740               _PTR(SObject)           theSource,
741               VISU::Result_var&       theResult)
742   {
743     if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
744       return NULL;
745
746     _PTR(SObject) aSObj = theSource->GetFather();
747     if (!aSObj)
748       return NULL;
749
750     aSObj = aSObj->GetFather();
751     if (!aSObj)
752       return NULL;
753
754     aSObj = aSObj->GetFather();
755     if (!aSObj)
756       return NULL;
757
758     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
759     if (CORBA::is_nil(anObject)) {
760       aSObj = aSObj->GetFather();
761       if (!aSObj)
762         return NULL;
763       anObject = VISU::ClientSObjectToObject(aSObj);
764     }
765
766     if (CORBA::is_nil(anObject))
767       return NULL;
768
769     theResult = VISU::Result::_narrow(anObject);
770     return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
771   }
772
773   //------------------------------------------------------------
774   // VTK View
775   VISU_Actor*
776   PublishMeshInView(const SalomeApp_Module* theModule,
777                     VISU::Prs3d_i* thePrs,
778                     SVTK_ViewWindow* theViewWindow)
779   {
780     VISU_Actor* anActor = NULL;
781     if (!thePrs || !theViewWindow)
782       return anActor;
783
784     SalomeApp_Application *anApp = dynamic_cast<SalomeApp_Application*>(theModule->application());
785     if(!anApp)
786       return anActor;
787     
788     SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
789
790     if(!aStudy)
791       return anActor;
792     
793
794     QApplication::setOverrideCursor( Qt::WaitCursor );
795     try {
796       if ((anActor = thePrs->CreateActor())) {
797         theViewWindow->AddActor(anActor);
798
799         if(anActor->hasIO() && anActor->getIO()->hasEntry())
800           aStudy->setVisibilityState(anActor->getIO()->getEntry(), Qtx::ShownState);
801       }
802     } catch(std::exception& exc) {
803       SUIT_MessageBox::warning
804         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
805          QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
806     }
807     QApplication::restoreOverrideCursor();
808
809     return anActor;
810   }
811
812   //------------------------------------------------------------
813   void
814   RepaintViewWindows (const SalomeApp_Module* theModule,
815                       const Handle(SALOME_InteractiveObject)& theIObject)
816   {
817     TViewWindows aViewWindows;
818     if (SalomeApp_Application* anApp = theModule->getApp()) {
819       ViewManagerList aViewManagerList;
820       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
821       QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
822       while ( anIter != aViewManagerList.end() )
823       {
824         QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
825         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
826           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
827             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
828               if (vw->isVisible(theIObject)) {
829                 vw->getRenderer()->ResetCameraClippingRange();
830                 vw->Repaint();
831                 vw->highlight(theIObject, true, true);
832               }
833             }
834           }
835         }
836         anIter++;
837       }
838     }
839   }
840
841   //------------------------------------------------------------
842   VISU_Actor*
843   FindActor(const SalomeApp_Study* theStudy,
844             SVTK_ViewWindow* theViewWindow,
845             const QString& theEntry)
846   {
847     TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
848     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
849     return FindActor(theViewWindow, aPrs3d);
850   }
851
852   //------------------------------------------------------------
853   VISU_ActorBase*
854   FindActorBase(const SalomeApp_Study* theStudy,
855                 SVTK_ViewWindow* theViewWindow,
856                 const QString& theEntry)
857   {
858     TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
859     VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
860     return FindActorBase(theViewWindow, aTable);
861   }
862
863   //------------------------------------------------------------
864   void
865   RecreateActor (const SalomeApp_Module* theModule,
866                  VISU::Prs3d_i* thePrs)
867   {
868     QApplication::setOverrideCursor(Qt::WaitCursor);
869
870     /*    SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
871           CORBA::String_var anEntry = aSObject->GetID();*/
872
873     try {
874       thePrs->UpdateActors();
875     } catch (std::runtime_error& exc) {
876       INFOS(exc.what());
877       QApplication::restoreOverrideCursor();
878       SUIT_MessageBox::warning
879         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
880          QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
881
882       thePrs->RemoveActors();
883       return;
884     }
885     QApplication::restoreOverrideCursor();
886   }
887
888   //------------------------------------------------------------
889   bool
890   ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
891                            double allBounds[6],
892                            const char* theActorClassName)
893   {
894     vtkRenderer *aRen = theViewWindow->getRenderer();
895     VTK::ActorCollectionCopy aCopy(aRen->GetActors());
896     vtkActorCollection *anActColl = aCopy.GetActors();
897     vtkProp *prop;
898     double *bounds;
899     int somethingVisible = false;
900
901     allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
902     allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
903     // loop through all props
904     for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
905       // if it's invisible, or has no geometry, we can skip the rest
906       if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
907         bounds = prop->GetBounds();
908         // make sure we haven't got bogus bounds
909         if (bounds != NULL &&
910             bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
911             bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
912             bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
913         {
914           somethingVisible = true;
915           if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
916           if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
917           if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
918           if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
919           if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
920           if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
921         }//not bogus
922       }
923     }
924     return somethingVisible;
925   }
926
927   //------------------------------------------------------------
928   void SetFitAll(SVTK_ViewWindow* theViewWindow)
929   {
930     static double PRECISION = 0.000001;
931     static double DEVIATION = 600;
932     double XYZ_Bnd[6];
933     if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
934
935     double absX = XYZ_Bnd[1] - XYZ_Bnd[0];
936     double absY = XYZ_Bnd[3] - XYZ_Bnd[2];
937     double absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
938
939     enum CameraOrient {e3D, eFront, eLeft, eTop};
940     CameraOrient aCameraOrient = e3D;
941     if (absX <= PRECISION) aCameraOrient = eFront;
942     else {
943       if (absY <= PRECISION) aCameraOrient = eLeft;
944       else {
945         if (absZ <= PRECISION) aCameraOrient = eTop;
946         else {
947           // all the three dimensions exceeds precision
948           double dev_abs_XY = absX / absY;
949           double dev_abs_YZ = absY / absZ;
950           double dev_abs_XZ = absX / absZ;
951           if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
952             aCameraOrient = eLeft;
953           else {
954             if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
955               aCameraOrient = eFront;
956             else {
957               if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
958                 aCameraOrient = eTop;
959             }
960           }
961         }
962       }
963     }
964
965     switch (aCameraOrient) {
966     case eFront: theViewWindow->onFrontView(); break;
967     case eLeft:  theViewWindow->onLeftView();  break;
968     case eTop:   theViewWindow->onTopView();   break;
969     case e3D:    theViewWindow->onResetView(); break;
970     }
971     theViewWindow->getRenderer()->ResetCameraClippingRange();
972     theViewWindow->onFitAll();
973   }
974
975   //************************************************************
976   // Plot2d View
977
978   SPlot2d_Viewer*
979   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
980   {
981     if(SalomeApp_Application* anApp = theModule->getApp()){
982       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
983         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
984       }
985     }
986     return NULL;
987   }
988
989   //------------------------------------------------------------
990   void
991   PlotTable(const SalomeApp_Module* theModule,
992             VISU::Table_i* table,
993             int theDisplaying)
994   {
995     SalomeApp_Study* aStudy = GetAppStudy( theModule );
996     if( !aStudy )
997       return;
998
999     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
1000     if ( !aView )
1001       return;
1002     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1003     if ( !aPlot )
1004       return;
1005
1006     // implementation moved to VISU_I package (see VISU_Tools.h)
1007     VISU::PlotTable( aStudy, aPlot, table, theDisplaying );
1008   }
1009
1010   //------------------------------------------------------------
1011   void
1012   PlotCurve(const SalomeApp_Module* theModule,
1013             VISU::Curve_i* theCurve,
1014             int theDisplaying)
1015   {
1016     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1017     if ( !aView )
1018       return;
1019     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1020     if ( !aPlot )
1021       return;
1022
1023     // implementation moved to VISU_I package (see VISU_Tools.h)
1024     VISU::PlotCurve( aPlot, theCurve, theDisplaying );
1025   }
1026
1027   //------------------------------------------------------------
1028   void
1029   PlotRemoveCurve(const SalomeApp_Module* theModule,
1030                   VISU::Curve_i* pCrv)
1031   {
1032     // implementation moved to VISU_I package (see VISU_Tools.h)
1033     VISU::PlotRemoveCurve( theModule->getApp(), pCrv );
1034   }
1035
1036   //------------------------------------------------------------
1037   void
1038   PlotContainer(const SalomeApp_Module* theModule,
1039                 VISU::Container_i* container,
1040                 int theDisplaying)
1041   {
1042     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1043     if ( !aView )
1044       return;
1045     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1046     if ( !aPlot )
1047       return;
1048
1049     // implementation moved to VISU_I package (see VISU_Tools.h)
1050     VISU::PlotContainer( aPlot, container, theDisplaying );
1051   }
1052
1053   //------------------------------------------------------------
1054   void
1055   CreatePlot(SalomeApp_Module* theModule,
1056              _PTR(SObject) theTableSO)
1057   {
1058     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1059     if ( !aView )
1060       return;
1061     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1062     if ( !aPlot )
1063       return;
1064
1065     VISU::VISU_Gen_i* aVisuGen = VISU::GetVisuGen( theModule );
1066
1067     // implementation moved to VISU_I package (see VISU_Tools.h)
1068     VISU::CreatePlot( aVisuGen, aPlot, theTableSO );
1069   }
1070
1071   //************************************************************
1072   // Others
1073   VISU::Mesh_i*
1074   CreateMesh(VisuGUI* theModule,
1075              const Handle(SALOME_InteractiveObject)& theIO,
1076              SVTK_ViewWindow* theViewWindow)
1077   {
1078         _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1079     //if (CheckLock(aStudy))
1080     //  return;
1081
1082     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1083
1084     // Get VISU::Result
1085     VISU::Result_var aResult;
1086     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1087     if (pResult == NULL)
1088       return NULL;
1089
1090     Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1091     if (aMap.empty())
1092       return NULL;
1093
1094     CORBA::Object_var aMesh;
1095     string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1096     string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1097 #ifdef CHECKTIME
1098     Utils_Timer timer;
1099     timer.Start();
1100 #endif
1101     if (aComment == "ENTITY") {
1102       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1103       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1104         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1105     } else if (aComment == "FAMILY") {
1106       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1107       string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1108       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1109         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1110           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1111     } else if (aComment == "GROUP") {
1112       string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1113       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1114         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1115     }
1116 #ifdef CHECKTIME
1117     timer.Stop();
1118     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1119     timer.Show();
1120 #endif
1121
1122     //QApplication::restoreOverrideCursor();
1123     VISU::Mesh_i* pPresent = NULL;
1124     if (!CORBA::is_nil(aMesh))
1125       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1126     if (pPresent == NULL) {
1127       SUIT_MessageBox::warning (GetDesktop(theModule),
1128                                 QObject::tr("WRN_VISU"),
1129                                 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1130       return NULL;
1131     }
1132
1133     if (theViewWindow) {
1134       try {
1135 #ifdef CHECKTIME
1136         Utils_Timer timer;
1137         timer.Start();
1138 #endif
1139         if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1140           const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1141           if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1142         }
1143         PublishMeshInView(theModule, pPresent, theViewWindow);
1144         if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1145           SetFitAll(theViewWindow);
1146         }
1147 #ifdef CHECKTIME
1148         timer.Stop();
1149         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1150         timer.Show();
1151 #endif
1152       } catch (std::runtime_error& exc) {
1153         INFOS(exc.what());
1154         SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1155                                  QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1156       }
1157     }
1158
1159     UpdateObjBrowser(theModule, false, aResultSObj);
1160
1161     theModule->application()->putInfo(QObject::tr("INF_DONE"));
1162     // Make "Save" button active
1163     theModule->getApp()->updateActions();
1164     return pPresent;
1165   }
1166
1167   // ========================================================================================
1168   // GetPrs3dList: find list of presentations for the given object
1169   // ========================================================================================
1170   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1171                                             const Handle(SALOME_InteractiveObject)& theIO,
1172                                             bool theGP)
1173   {
1174     std::vector<VISU::Prs3d_i*> aList;
1175     if (!theIO.IsNull() && theIO->hasEntry()) {
1176       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1177       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1178       aList = GetPrs3dList(theModule, aSObject, theGP);
1179     }
1180     return aList;
1181   }
1182
1183   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1184                                             _PTR(SObject) theObject,
1185                                             bool theGP)
1186   {
1187     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1188     if (!theObject)
1189       return aList;
1190
1191     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1192
1193     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1194     if (!CORBA::is_nil(aCORBAObject)) {
1195       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1196       if (!CORBA::is_nil(aVisuObj)) {
1197         VISU::VISUType aType = aVisuObj->GetType();
1198         switch (aType) {
1199         case VISU::TGAUSSPOINTS:
1200           if ( !theGP ) break;
1201         case VISU::TSCALARMAP:
1202         case VISU::TISOSURFACES:
1203         case VISU::TDEFORMEDSHAPE:
1204         case VISU::TCUTPLANES:
1205         case VISU::TCUTLINES:
1206         case VISU::TCUTSEGMENT:
1207         case VISU::TVECTORS:
1208         case VISU::TSTREAMLINES:
1209         case VISU::TPLOT3D:
1210         case VISU::TSCALARMAPONDEFORMEDSHAPE:
1211         case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1212         case VISU::TMESH:
1213           {
1214             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1215             if (aServant.in()) {
1216               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1217               aList.resize(k+1);
1218               aList[k] = aPrsObject;
1219               k++;
1220             }
1221           }
1222           break;
1223         case VISU::TFIELD:
1224           {
1225             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1226             _PTR(SObject) aTimeStamp;
1227             anIter->Next(); // First is reference on support
1228             for (; anIter->More(); anIter->Next()) {
1229               aTimeStamp = anIter->Value();
1230               if (!aTimeStamp) continue;
1231               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1232               if (!aSubList.empty()) {
1233                 int n = aSubList.size();
1234                 aList.resize(k+n);
1235                 for (int i = 0; i < n; i++) {
1236                   aList[k] = aSubList[i];
1237                   k++;
1238                 }
1239               }
1240             }
1241           }
1242           break;
1243         case VISU::TCOLOREDPRS3DHOLDER:
1244           {
1245             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1246             if (aServant.in()) {
1247               VISU::ColoredPrs3dHolder_i* aPrsHolderObject = dynamic_cast<VISU::ColoredPrs3dHolder_i*>(aServant.in());
1248               if( aPrsHolderObject ) {
1249                 VISU::Prs3d_i* aPrsObject = aPrsHolderObject->GetPrs3dDevice();
1250                 aList.resize(k+1);
1251                 aList[k] = aPrsObject;
1252                 k++;
1253               }
1254             }
1255           }
1256         }
1257       }
1258     } else {
1259       VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1260       switch (aType) {
1261       case VISU::TFIELD: {
1262         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1263         _PTR(SObject) aTimeStamp;
1264         anIter->Next(); // First is reference on support
1265         for (; anIter->More(); anIter->Next()) {
1266           aTimeStamp = anIter->Value();
1267           if (!aTimeStamp) continue;
1268           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1269           if (!aSubList.empty()) {
1270             int n = aSubList.size();
1271             aList.resize(k+n);
1272             for (int i = 0; i < n; i++) {
1273               aList[k] = aSubList[i];
1274               k++;
1275             }
1276           }
1277         }
1278         break;
1279       }
1280       case VISU::TTIMESTAMP: {
1281         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1282         _PTR(SObject) aPrs;
1283         for (; anIter->More(); anIter->Next()) {
1284           aPrs = anIter->Value();
1285           if (!aPrs) continue;
1286           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1287           if (!aSubList.empty()) {
1288             int n = aSubList.size();
1289             aList.resize(k+n);
1290             for (int i = 0; i < n; i++) {
1291               aList[k] = aSubList[i];
1292               k++;
1293             }
1294           }
1295         }
1296         break;
1297       }}
1298     }
1299     return aList;
1300   }
1301
1302   //------------------------------------------------------------
1303   int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1304   {
1305     int minIndx = 1;
1306     std::set<int> aIndexes;
1307     TViewToPrs3d aMap = theModule->getScalarBarsMap();
1308     TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1309     if (aViewToPrsIter != aMap.end()) {
1310       TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1311       for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1312         aIndexes.insert((*aPrsIter).second);
1313       }
1314     }
1315     std::set<int>::const_iterator aIter = aIndexes.begin();
1316     for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1317       std::set<int>::const_iterator aIter = aIndexes.find(i);
1318       if (aIter == aIndexes.end()) { minIndx = i; break; }
1319       else minIndx = i + 1;
1320     }
1321     return minIndx;
1322   }
1323
1324   //------------------------------------------------------------
1325   void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1326                              VISU::Prs3d_i* thePrs3d, int pos)
1327   {
1328     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1329     TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1330     aMap[theViewWindow].insert(aPair);
1331   }
1332
1333   //------------------------------------------------------------
1334   void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1335                                VISU::Prs3d_i* thePrs3d)
1336   {
1337     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1338     TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1339     for (; aIter != aMap[theViewWindow].end(); aIter++)
1340       if ((*aIter).first == thePrs3d) {
1341         aMap[theViewWindow].erase(*aIter);
1342         return;
1343       }
1344   }
1345   //------------------------------------------------------------
1346   bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1347   {
1348     _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1349     if (!aVisuSO) return false;
1350     _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1351     if (!aFolder) {
1352       _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1353       aFolder = aBuilder->NewObject(aVisuSO);
1354
1355       _PTR(GenericAttribute) anAttr;
1356       anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1357       _PTR(AttributeName) aName(anAttr);
1358       aName->SetValue(CLIP_PLANES_FOLDER);
1359     }
1360     theSObject = aFolder;
1361     return true;
1362   }
1363
1364   //------------------------------------------------------------
1365   void initSpinBox( SalomeApp_IntSpinBox* sb,
1366                     const int bottom,
1367                     const int top,
1368                     const int step )
1369   {
1370     sb->setAcceptNames( false );
1371     sb->setRange( bottom, top );
1372     sb->setSingleStep( step );
1373   }
1374
1375   //------------------------------------------------------------
1376   void initSpinBox( SalomeApp_DoubleSpinBox* sb,
1377                     const double& bottom,
1378                     const double& top,
1379                     const double& step,
1380                     const char* quantity )
1381   {
1382     // Obtain precision from preferences
1383     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1384     int precision = resMgr->integerValue( "VISU", quantity, 3 );
1385
1386     sb->setPrecision   ( precision );
1387     sb->setDecimals    ( qAbs(precision) );
1388     sb->setRange       ( bottom, top );
1389     sb->setSingleStep  ( step );
1390     sb->setDefaultValue( bottom );
1391     sb->setAcceptNames ( false );
1392
1393     // Add a hint for the user saying how to tune precision
1394     QString userPropName = QObject::tr( QString( "VISU_PREF_%1" ).arg( quantity ).toLatin1().constData() );
1395     sb->setProperty( "validity_tune_hint",
1396                      QVariant( QObject::tr( "VISU_PRECISION_HINT" ).arg( userPropName ) ) );
1397   }
1398 }