Salome HOME
91b9e9081f32e207af1db5821c4e1e4dc07980d3
[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* aActor = NULL;
782     if (!thePrs || !theViewWindow)
783       return aActor;
784
785     QApplication::setOverrideCursor( Qt::WaitCursor );
786     try {
787       if ((aActor = thePrs->CreateActor()))
788         theViewWindow->AddActor(aActor);
789     } catch(std::exception& exc) {
790       SUIT_MessageBox::warning
791         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
792          QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
793     }
794     QApplication::restoreOverrideCursor();
795
796     return aActor;
797   }
798
799   //------------------------------------------------------------
800   void
801   RepaintViewWindows (const SalomeApp_Module* theModule,
802                       const Handle(SALOME_InteractiveObject)& theIObject)
803   {
804     TViewWindows aViewWindows;
805     if (SalomeApp_Application* anApp = theModule->getApp()) {
806       ViewManagerList aViewManagerList;
807       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
808       QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
809       while ( anIter != aViewManagerList.end() )
810       {
811         QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
812         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
813           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
814             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
815               if (vw->isVisible(theIObject)) {
816                 vw->getRenderer()->ResetCameraClippingRange();
817                 vw->Repaint();
818                 vw->highlight(theIObject, true, true);
819               }
820             }
821           }
822         }
823         anIter++;
824       }
825     }
826   }
827
828   //------------------------------------------------------------
829   VISU_Actor*
830   FindActor(const SalomeApp_Study* theStudy,
831             SVTK_ViewWindow* theViewWindow,
832             const QString& theEntry)
833   {
834     TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
835     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
836     return FindActor(theViewWindow, aPrs3d);
837   }
838
839   //------------------------------------------------------------
840   VISU_ActorBase*
841   FindActorBase(const SalomeApp_Study* theStudy,
842                 SVTK_ViewWindow* theViewWindow,
843                 const QString& theEntry)
844   {
845     TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
846     VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
847     return FindActorBase(theViewWindow, aTable);
848   }
849
850   //------------------------------------------------------------
851   void
852   RecreateActor (const SalomeApp_Module* theModule,
853                  VISU::Prs3d_i* thePrs)
854   {
855     QApplication::setOverrideCursor(Qt::WaitCursor);
856
857     /*    SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
858           CORBA::String_var anEntry = aSObject->GetID();*/
859
860     try {
861       thePrs->UpdateActors();
862     } catch (std::runtime_error& exc) {
863       INFOS(exc.what());
864       QApplication::restoreOverrideCursor();
865       SUIT_MessageBox::warning
866         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
867          QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
868
869       thePrs->RemoveActors();
870       return;
871     }
872     QApplication::restoreOverrideCursor();
873   }
874
875   //------------------------------------------------------------
876   bool
877   ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
878                            vtkFloatingPointType allBounds[6], 
879                            const char* theActorClassName)
880   {
881     vtkRenderer *aRen = theViewWindow->getRenderer();
882     VTK::ActorCollectionCopy aCopy(aRen->GetActors());
883     vtkActorCollection *anActColl = aCopy.GetActors(); 
884     vtkProp *prop;
885     vtkFloatingPointType *bounds;
886     int somethingVisible = false;
887
888     allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
889     allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
890     // loop through all props
891     for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
892       // if it's invisible, or has no geometry, we can skip the rest 
893       if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
894         bounds = prop->GetBounds();
895         // make sure we haven't got bogus bounds
896         if (bounds != NULL &&
897             bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
898             bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
899             bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
900         {
901           somethingVisible = true;
902           if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
903           if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
904           if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
905           if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
906           if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
907           if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
908         }//not bogus
909       }
910     }
911     return somethingVisible;
912   }
913
914   //------------------------------------------------------------
915   void SetFitAll(SVTK_ViewWindow* theViewWindow)
916   {
917     static vtkFloatingPointType PRECISION = 0.000001;
918     static vtkFloatingPointType DEVIATION = 600;
919     vtkFloatingPointType XYZ_Bnd[6];
920     if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
921
922     vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
923     vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
924     vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
925
926     enum CameraOrient {e3D, eFront, eLeft, eTop};
927     CameraOrient aCameraOrient = e3D;
928     if (absX <= PRECISION) aCameraOrient = eFront;
929     else {
930       if (absY <= PRECISION) aCameraOrient = eLeft;
931       else {
932         if (absZ <= PRECISION) aCameraOrient = eTop;
933         else {
934           // all the three dimensions exceeds precision
935           vtkFloatingPointType dev_abs_XY = absX / absY;
936           vtkFloatingPointType dev_abs_YZ = absY / absZ;
937           vtkFloatingPointType dev_abs_XZ = absX / absZ;
938           if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
939             aCameraOrient = eLeft;
940           else {
941             if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
942               aCameraOrient = eFront;
943             else {
944               if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
945                 aCameraOrient = eTop;
946             }
947           }
948         }
949       }
950     }
951
952     switch (aCameraOrient) {
953     case eFront: theViewWindow->onFrontView(); break;
954     case eLeft:  theViewWindow->onLeftView();  break;
955     case eTop:   theViewWindow->onTopView();   break;
956     case e3D:    theViewWindow->onResetView(); break;
957     }
958     theViewWindow->getRenderer()->ResetCameraClippingRange();
959     theViewWindow->onFitAll();
960   }
961
962   //************************************************************
963   // Plot2d View
964
965   SPlot2d_Viewer*
966   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
967   {
968     if(SalomeApp_Application* anApp = theModule->getApp()){
969       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
970         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
971       }
972     }
973     return NULL;
974   }
975
976   //------------------------------------------------------------
977   void
978   PlotTable(const SalomeApp_Module* theModule,
979             VISU::Table_i* table,
980             int theDisplaying)
981   {
982     SalomeApp_Study* aStudy = GetAppStudy( theModule );
983     if( !aStudy )
984       return;
985
986     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
987     if ( !aView )
988       return;
989     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
990     if ( !aPlot )
991       return;
992
993     // implementation moved to VISU_I package (see VISU_Tools.h)
994     VISU::PlotTable( aStudy, aPlot, table, theDisplaying );
995   }
996
997   //------------------------------------------------------------
998   void
999   PlotCurve(const SalomeApp_Module* theModule,
1000             VISU::Curve_i* theCurve,
1001             int theDisplaying)
1002   {
1003     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1004     if ( !aView )
1005       return;
1006     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1007     if ( !aPlot )
1008       return;
1009
1010     // implementation moved to VISU_I package (see VISU_Tools.h)
1011     VISU::PlotCurve( aPlot, theCurve, theDisplaying );
1012   }
1013
1014   //------------------------------------------------------------
1015   void
1016   PlotRemoveCurve(const SalomeApp_Module* theModule,
1017                   VISU::Curve_i* pCrv)
1018   {
1019     // implementation moved to VISU_I package (see VISU_Tools.h)
1020     VISU::PlotRemoveCurve( theModule->getApp(), pCrv );
1021   }
1022   
1023   //------------------------------------------------------------
1024   void
1025   PlotContainer(const SalomeApp_Module* theModule,
1026                 VISU::Container_i* container,
1027                 int theDisplaying)
1028   {
1029     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1030     if ( !aView )
1031       return;
1032     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1033     if ( !aPlot )
1034       return;
1035
1036     // implementation moved to VISU_I package (see VISU_Tools.h)
1037     VISU::PlotContainer( aPlot, container, theDisplaying );
1038   }
1039
1040   //------------------------------------------------------------
1041   void
1042   CreatePlot(SalomeApp_Module* theModule,
1043              _PTR(SObject) theTableSO)
1044   {
1045     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1046     if ( !aView )
1047       return;
1048     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1049     if ( !aPlot )
1050       return;
1051
1052     VISU::VISU_Gen_i* aVisuGen = VISU::GetVisuGen( theModule );
1053
1054     // implementation moved to VISU_I package (see VISU_Tools.h)
1055     VISU::CreatePlot( aVisuGen, aPlot, theTableSO );
1056   }
1057
1058   //************************************************************
1059   // Others
1060   VISU::Mesh_i*
1061   CreateMesh(VisuGUI* theModule,
1062              const Handle(SALOME_InteractiveObject)& theIO,
1063              SVTK_ViewWindow* theViewWindow)
1064   {  
1065         _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1066     //if (CheckLock(aStudy))
1067     //  return;
1068
1069     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1070
1071     // Get VISU::Result
1072     VISU::Result_var aResult;
1073     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1074     if (pResult == NULL)
1075       return NULL;
1076
1077     Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1078     if (aMap.empty())
1079       return NULL;
1080
1081     CORBA::Object_var aMesh;
1082     string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1083     string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1084 #ifdef CHECKTIME
1085     Utils_Timer timer;
1086     timer.Start();
1087 #endif
1088     if (aComment == "ENTITY") {
1089       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1090       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1091         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1092     } else if (aComment == "FAMILY") {
1093       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1094       string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1095       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1096         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1097           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1098     } else if (aComment == "GROUP") {
1099       string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1100       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1101         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1102     }
1103 #ifdef CHECKTIME
1104     timer.Stop();
1105     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1106     timer.Show();
1107 #endif
1108
1109     //QApplication::restoreOverrideCursor();
1110     VISU::Mesh_i* pPresent = NULL;
1111     if (!CORBA::is_nil(aMesh))
1112       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1113     if (pPresent == NULL) {
1114       SUIT_MessageBox::warning (GetDesktop(theModule),
1115                                 QObject::tr("WRN_VISU"),
1116                                 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1117       return NULL;
1118     }
1119
1120     if (theViewWindow) {
1121       try {
1122 #ifdef CHECKTIME
1123         Utils_Timer timer;
1124         timer.Start();
1125 #endif
1126         if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1127           const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1128           if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1129         }
1130         PublishMeshInView(theModule, pPresent, theViewWindow);
1131         if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1132           SetFitAll(theViewWindow);
1133         }
1134 #ifdef CHECKTIME
1135         timer.Stop();
1136         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1137         timer.Show();
1138 #endif
1139       } catch (std::runtime_error& exc) {
1140         INFOS(exc.what());
1141         SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1142                                  QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1143       }
1144     }
1145
1146     UpdateObjBrowser(theModule, false, aResultSObj);
1147
1148     theModule->application()->putInfo(QObject::tr("INF_DONE"));
1149     // Make "Save" button active
1150     theModule->getApp()->updateActions();
1151     return pPresent;
1152   }
1153
1154   // ========================================================================================
1155   // GetPrs3dList: find list of presentations for the given object
1156   // ========================================================================================
1157   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1158                                             const Handle(SALOME_InteractiveObject)& theIO,
1159                                             bool theGP)
1160   {
1161     std::vector<VISU::Prs3d_i*> aList;
1162     if (!theIO.IsNull() && theIO->hasEntry()) {
1163       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1164       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1165       aList = GetPrs3dList(theModule, aSObject, theGP);
1166     }
1167     return aList;
1168   }
1169
1170   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1171                                             _PTR(SObject) theObject,
1172                                             bool theGP)
1173   {
1174     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1175     if (!theObject)
1176       return aList;
1177
1178     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1179
1180     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1181     if (!CORBA::is_nil(aCORBAObject)) {
1182       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1183       if (!CORBA::is_nil(aVisuObj)) {
1184         VISU::VISUType aType = aVisuObj->GetType();
1185         switch (aType) {
1186         case VISU::TGAUSSPOINTS:
1187           if ( !theGP ) break;
1188         case VISU::TSCALARMAP:
1189         case VISU::TISOSURFACES:
1190         case VISU::TDEFORMEDSHAPE:
1191         case VISU::TCUTPLANES:
1192         case VISU::TCUTLINES:
1193         case VISU::TCUTSEGMENT:
1194         case VISU::TVECTORS:
1195         case VISU::TSTREAMLINES:
1196         case VISU::TPLOT3D:
1197         case VISU::TSCALARMAPONDEFORMEDSHAPE:
1198         case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1199         case VISU::TMESH:
1200           {
1201             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1202             if (aServant.in()) {
1203               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1204               aList.resize(k+1);
1205               aList[k] = aPrsObject;
1206               k++;
1207             }
1208           }
1209           break;
1210         case VISU::TFIELD:
1211           {
1212             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1213             _PTR(SObject) aTimeStamp;
1214             anIter->Next(); // First is reference on support
1215             for (; anIter->More(); anIter->Next()) {
1216               aTimeStamp = anIter->Value();
1217               if (!aTimeStamp) continue;
1218               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1219               if (!aSubList.empty()) {
1220                 int n = aSubList.size();
1221                 aList.resize(k+n);
1222                 for (int i = 0; i < n; i++) {
1223                   aList[k] = aSubList[i];
1224                   k++;
1225                 }
1226               }
1227             }
1228           }
1229           break;
1230         case VISU::TCOLOREDPRS3DHOLDER:
1231           {
1232             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1233             if (aServant.in()) {
1234               VISU::ColoredPrs3dHolder_i* aPrsHolderObject = dynamic_cast<VISU::ColoredPrs3dHolder_i*>(aServant.in());
1235               if( aPrsHolderObject ) {
1236                 VISU::Prs3d_i* aPrsObject = aPrsHolderObject->GetPrs3dDevice();
1237                 aList.resize(k+1);
1238                 aList[k] = aPrsObject;
1239                 k++;
1240               }
1241             }
1242           }
1243         }
1244       }
1245     } else {
1246       VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1247       switch (aType) {
1248       case VISU::TFIELD: {
1249         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1250         _PTR(SObject) aTimeStamp;
1251         anIter->Next(); // First is reference on support
1252         for (; anIter->More(); anIter->Next()) {
1253           aTimeStamp = anIter->Value();
1254           if (!aTimeStamp) continue;
1255           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1256           if (!aSubList.empty()) {
1257             int n = aSubList.size();
1258             aList.resize(k+n);
1259             for (int i = 0; i < n; i++) {
1260               aList[k] = aSubList[i];
1261               k++;
1262             }
1263           }
1264         }
1265         break;
1266       }
1267       case VISU::TTIMESTAMP: {
1268         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1269         _PTR(SObject) aPrs;
1270         for (; anIter->More(); anIter->Next()) {
1271           aPrs = anIter->Value();
1272           if (!aPrs) continue;
1273           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1274           if (!aSubList.empty()) {
1275             int n = aSubList.size();
1276             aList.resize(k+n);
1277             for (int i = 0; i < n; i++) {
1278               aList[k] = aSubList[i];
1279               k++;
1280             }
1281           }
1282         }
1283         break;
1284       }}
1285     }
1286     return aList;
1287   }
1288
1289   //------------------------------------------------------------
1290   int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1291   {
1292     int minIndx = 1;
1293     std::set<int> aIndexes;
1294     TViewToPrs3d aMap = theModule->getScalarBarsMap();
1295     TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1296     if (aViewToPrsIter != aMap.end()) {
1297       TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1298       for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1299         aIndexes.insert((*aPrsIter).second);
1300       }
1301     }
1302     std::set<int>::const_iterator aIter = aIndexes.begin();
1303     for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1304       std::set<int>::const_iterator aIter = aIndexes.find(i);
1305       if (aIter == aIndexes.end()) { minIndx = i; break; } 
1306       else minIndx = i + 1;
1307     }
1308     return minIndx;
1309   }
1310
1311   //------------------------------------------------------------
1312   void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1313                              VISU::Prs3d_i* thePrs3d, int pos)
1314   {
1315     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1316     TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1317     aMap[theViewWindow].insert(aPair);
1318   }
1319
1320   //------------------------------------------------------------
1321   void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1322                                VISU::Prs3d_i* thePrs3d)
1323   {
1324     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1325     TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1326     for (; aIter != aMap[theViewWindow].end(); aIter++)
1327       if ((*aIter).first == thePrs3d) {
1328         aMap[theViewWindow].erase(*aIter);
1329         return;
1330       }
1331   }
1332   //------------------------------------------------------------
1333   bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1334   {
1335     _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1336     if (!aVisuSO) return false;
1337     _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1338     if (!aFolder) {
1339       _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1340       aFolder = aBuilder->NewObject(aVisuSO);
1341       
1342       _PTR(GenericAttribute) anAttr;
1343       anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1344       _PTR(AttributeName) aName(anAttr);
1345       aName->SetValue(CLIP_PLANES_FOLDER);
1346     }
1347     theSObject = aFolder;
1348     return true;
1349   }
1350
1351   //------------------------------------------------------------
1352   void initSpinBox( SalomeApp_IntSpinBox* sb, 
1353                     const int bottom, 
1354                     const int top, 
1355                     const int step )
1356   {
1357     sb->setAcceptNames( false );
1358     sb->setRange( bottom, top );
1359     sb->setSingleStep( step );
1360   }
1361   
1362   //------------------------------------------------------------
1363   void initSpinBox( SalomeApp_DoubleSpinBox* sb, 
1364                     const double& bottom, 
1365                     const double& top, 
1366                     const double& step, 
1367                     const char* quantity )
1368   {
1369     // Obtain precision from preferences
1370     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1371     int precision = resMgr->integerValue( "VISU", quantity, 3 );
1372   
1373     sb->setPrecision   ( precision ); 
1374     sb->setDecimals    ( qAbs(precision) );
1375     sb->setRange       ( bottom, top );
1376     sb->setSingleStep  ( step );
1377     sb->setDefaultValue( bottom );
1378     sb->setAcceptNames ( false );
1379   
1380     // Add a hint for the user saying how to tune precision
1381     QString userPropName = QObject::tr( QString( "VISU_PREF_%1" ).arg( quantity ).toLatin1().constData() );
1382     sb->setProperty( "validity_tune_hint", 
1383                      QVariant( QObject::tr( "VISU_PRECISION_HINT" ).arg( userPropName ) ) );  
1384   }
1385 }