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