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