Salome HOME
PR: merged from V5_1_4rc1
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_VTKUtils.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_VTKUtils.cxx
25 // Author : Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_VTKUtils.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_Filter.h"
33
34 #include <SMESH_Actor.h>
35 #include <SMESH_ActorUtils.h>
36 #include <SMESH_ObjectDef.h>
37 #include <SMDS_Mesh.hxx>
38
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_ViewManager.h>
44 #include <SUIT_ResourceMgr.h>
45
46 #include <SALOME_ListIO.hxx>
47 #include <SALOME_ListIteratorOfListIO.hxx>
48
49 #include <SVTK_Selector.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52
53 #include <VTKViewer_Algorithm.h>
54
55 #include <LightApp_SelectionMgr.h>
56 #include <SalomeApp_Application.h>
57 #include <SalomeApp_Study.h>
58
59 // SALOME KERNEL includes
60 #include <utilities.h>
61
62 // IDL includes
63 #include <SALOMEconfig.h>
64 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
65 #include CORBA_CLIENT_HEADER(SMESH_Group)
66
67 // VTK includes
68 #include <vtkRenderer.h>
69 #include <vtkActorCollection.h>
70 #include <vtkUnstructuredGrid.h>
71
72 // OCCT includes
73 #include <TColStd_IndexedMapOfInteger.hxx>
74 #include <Standard_ErrorHandler.hxx>
75
76 namespace SMESH
77 {
78   typedef std::map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
79   static TVisualObjCont VISUAL_OBJ_CONT;
80
81   //=============================================================================
82   /*!
83    * \brief Allocate some memory at construction and release it at destruction.
84    * Is used to be able to continue working after mesh generation or visualization
85    * break due to lack of memory
86    */
87   //=============================================================================
88
89   struct MemoryReserve
90   {
91     char* myBuf;
92     MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
93     void Free() { if (myBuf) { delete [] myBuf; myBuf = 0; }}
94     ~MemoryReserve() { Free(); }
95   };
96   static MemoryReserve* theVISU_MemoryReserve = new MemoryReserve;
97
98   //================================================================================
99   /*!
100    * \brief Remove VisualObj and its actor from all views
101    */
102   //================================================================================
103
104   void RemoveVisualObjectWithActors( const char* theEntry )
105   {
106     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
107       ( SUIT_Session::session()->activeApplication() );
108     SUIT_ViewManager* aViewManager =
109       app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
110     if ( aViewManager ) {
111       QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
112       for ( int iV = 0; iV < views.count(); ++iV ) {
113         if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
114           if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV]))
115             vtkWnd->RemoveActor(actor);
116           actor->Delete();
117         }
118       }
119       int aStudyId = aViewManager->study()->id();
120       TVisualObjCont::key_type aKey(aStudyId,theEntry);
121       TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
122       if(anIter != VISUAL_OBJ_CONT.end()) {
123         // for unknown reason, object destructor is not called, so clear object manually
124         anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
125         anIter->second->GetUnstructuredGrid()->SetPoints(0);
126       }
127       VISUAL_OBJ_CONT.erase(aKey);
128     }
129   }
130   //================================================================================
131   /*!
132    * \brief Remove all VisualObjs and their actors from all views
133    */
134   //================================================================================
135
136   void RemoveAllObjectsWithActors()
137   {
138     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
139       ( SUIT_Session::session()->activeApplication() );
140     if (!app) return;
141     ViewManagerList viewMgrs = app->viewManagers();
142     for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
143       SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
144       if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type()) {
145         QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
146         for ( int iV = 0; iV < views.count(); ++iV ) {
147           if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
148             vtkRenderer *aRenderer = vtkWnd->getRenderer();
149             VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
150             vtkActorCollection *actors = aCopy.GetActors();
151             for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
152               // size of actors changes inside the loop
153               if (SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
154               {
155                 vtkWnd->RemoveActor(actor);
156                 actor->Delete();
157               }
158             }
159           }
160         }
161       }
162     }
163     TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
164     for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
165       // for unknown reason, object destructor is not called, so clear object manually
166       anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
167       anIter->second->GetUnstructuredGrid()->SetPoints(0);
168     }
169     VISUAL_OBJ_CONT.clear();
170   }
171
172   //================================================================================
173   /*!
174    * \brief Remove all VisualObjs of a study
175    */
176   //================================================================================
177
178   void RemoveVisuData(int studyID)
179   {
180     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
181       ( SUIT_Session::session()->activeApplication() );
182     if (!app) return;
183     ViewManagerList viewMgrs = app->viewManagers();
184     for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
185       SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
186       if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type() &&
187            aViewManager->study()->id() == studyID ) {
188         QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
189         for ( int iV = 0; iV < views.count(); ++iV ) {
190           if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
191             vtkRenderer *aRenderer = vtkWnd->getRenderer();
192             VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
193             vtkActorCollection *actors = aCopy.GetActors();
194             for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
195               // size of actors changes inside the loop
196               if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
197               {
198                 vtkWnd->RemoveActor(actor);
199                 actor->Delete();
200               }
201             }
202           }
203         }
204       }
205     }
206     TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
207     for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
208       int curId = anIter->first.first;
209       if ( curId == studyID ) {
210         // for unknown reason, object destructor is not called, so clear object manually
211         anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
212         anIter->second->GetUnstructuredGrid()->SetPoints(0);
213         VISUAL_OBJ_CONT.erase( anIter-- );  // dercement occures before erase()
214       }
215     }
216   }
217
218   //================================================================================
219   /*!
220    * \brief Notify the user on problems during visualization
221    */
222   //================================================================================
223
224   void OnVisuException()
225   {
226     try {
227 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
228       OCC_CATCH_SIGNALS;
229 #endif
230       // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
231       // after or at showing this message, so we do an additional check of available memory
232 //       char* buf = new char[100*1024];
233 //       delete [] buf;
234       SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
235                                QObject::tr("SMESH_VISU_PROBLEM"));
236     } catch (...) {
237       // no more memory at all: last resort
238       MESSAGE_BEGIN ( "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<
239                       std::endl << "Try to remove all visual data..." );
240       if (theVISU_MemoryReserve) {
241         delete theVISU_MemoryReserve;
242         theVISU_MemoryReserve = 0;
243       }
244       RemoveAllObjectsWithActors();
245       SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
246                                QObject::tr("SMESH_VISU_PROBLEM_CLEAR"));
247       MESSAGE_END ( "...done" );
248     }
249   }
250   //================================================================================
251   /*!
252    * \brief Returns an updated visual object
253    */
254   //================================================================================
255
256   TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry, bool nulData){
257     TVisualObjPtr aVisualObj;
258     TVisualObjCont::key_type aKey(theStudyId,theEntry);
259     try{
260 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
261       OCC_CATCH_SIGNALS;
262 #endif
263       TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
264       if(anIter != VISUAL_OBJ_CONT.end()){
265         aVisualObj = anIter->second;
266       }else{
267         SalomeApp_Application* app =
268           dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
269         _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
270         _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
271         if(aSObj){
272           _PTR(GenericAttribute) anAttr;
273           if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
274             _PTR(AttributeIOR) anIOR = anAttr;
275             CORBA::String_var aVal = anIOR->Value().c_str();
276             CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
277             if(!CORBA::is_nil(anObj)){
278               //Try narrow to SMESH_Mesh interface
279               SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
280               if(!aMesh->_is_nil()){
281                 aVisualObj.reset(new SMESH_MeshObj(aMesh));
282                 TVisualObjCont::value_type aValue(aKey,aVisualObj);
283                 VISUAL_OBJ_CONT.insert(aValue);
284               }
285               //Try narrow to SMESH_Group interface
286               SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
287               if(!aGroup->_is_nil()){
288                 _PTR(SObject) aFatherSObj = aSObj->GetFather();
289                 if(!aFatherSObj) return aVisualObj;
290                 aFatherSObj = aFatherSObj->GetFather();
291                 if(!aFatherSObj) return aVisualObj;
292                 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
293                 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
294                 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
295                   aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
296                   TVisualObjCont::value_type aValue(aKey,aVisualObj);
297                   VISUAL_OBJ_CONT.insert(aValue);
298                 }
299               }
300               //Try narrow to SMESH_subMesh interface
301               SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
302               if(!aSubMesh->_is_nil()){
303                 _PTR(SObject) aFatherSObj = aSObj->GetFather();
304                 if(!aFatherSObj) return aVisualObj;
305                 aFatherSObj = aFatherSObj->GetFather();
306                 if(!aFatherSObj) return aVisualObj;
307                 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
308                 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
309                 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
310                   aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
311                   TVisualObjCont::value_type aValue(aKey,aVisualObj);
312                   VISUAL_OBJ_CONT.insert(aValue);
313                 }
314               }
315             }
316           }
317         }
318       }
319     }catch(...){
320       INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
321       return TVisualObjPtr();
322     }
323     // Update object
324     bool objModified = false;
325     if ( aVisualObj ) {
326       try {
327 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
328         OCC_CATCH_SIGNALS;
329 #endif
330         //MESSAGE("GetVisualObj");
331         if (nulData)
332                 objModified = aVisualObj->NulData();
333         else
334           objModified = aVisualObj->Update();
335       }
336       catch (...) {
337 #ifdef _DEBUG_
338         MESSAGE ( "Exception in SMESHGUI_VTKUtils::GetVisualObj()" );
339 #endif
340         RemoveVisualObjectWithActors( theEntry ); // remove this object
341         OnVisuException();
342         aVisualObj.reset();
343       }
344     }
345
346     if ( objModified ) {
347       // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
348       // ~10 times more memory is used than it occupies.
349       // Warn the user if there is less free memory than 30 sizes of a grid
350       // TODO: estimate memory usage in other modes and take current mode into account
351       int freeMB = SMDS_Mesh::CheckMemory(true);
352       int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
353       if ( freeMB > 0 && usedMB * 30 > freeMB ) {
354 #ifdef _DEBUG_
355         MESSAGE ( "SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB
356                << ", usedMB=" << usedMB );
357 #endif
358 //        bool continu = false;
359 //        if ( usedMB * 10 > freeMB )
360 //          // even dont try to show
361 //          SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
362 //                                   QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
363 //        else
364 //          // there is a chance to succeed
365 //          continu = SUIT_MessageBox::warning
366 //            (SMESHGUI::desktop(),
367 //             QObject::tr("SMESH_WRN_WARNING"),
368 //             QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
369 //             SUIT_MessageBox::Yes | SUIT_MessageBox::No,
370 //             SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
371 //        if ( !continu ) {
372 //          // remove the corresponding actors from all views
373 //          RemoveVisualObjectWithActors( theEntry );
374 //          aVisualObj.reset();
375 //        }
376       }
377     }
378
379     return aVisualObj;
380   }
381
382
383   /*! Return active view window, if it instantiates SVTK_ViewWindow class,
384    *  overwise find or create corresponding view window, make it active and return it.
385    *  \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
386    */
387   SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
388                                   bool createIfNotFound)
389   {
390     SalomeApp_Application* anApp;
391     if (theModule)
392       anApp = theModule->getApp();
393     else
394       anApp = dynamic_cast<SalomeApp_Application*>
395         (SUIT_Session::session()->activeApplication());
396
397     if (anApp) {
398       if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
399         return aView;
400
401       SUIT_ViewManager* aViewManager =
402         anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
403       if (aViewManager) {
404         if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
405           if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
406             aViewWindow->raise();
407             aViewWindow->setFocus();
408             return aView;
409           }
410         }
411       }
412     }
413     return NULL;
414   }
415
416   SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
417                                       SUIT_ViewWindow * theWindow)
418   {
419     if( !theMgr )
420       return NULL;
421
422     QVector<SUIT_ViewWindow*> views = theMgr->getViews();
423     if( views.contains( theWindow ) )
424       return GetVtkViewWindow( theWindow );
425     else
426       return NULL;
427   }
428
429   SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
430     return dynamic_cast<SVTK_ViewWindow*>(theWindow);
431   }
432
433 /*  SUIT_ViewWindow* GetActiveWindow()
434   {
435     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
436     if( !app )
437       return NULL;
438     SUIT_ViewManager* mgr = app->activeViewManager();
439     if( mgr )
440       return mgr->getActiveView();
441     else
442       return NULL;
443   }*/
444
445   SVTK_ViewWindow* GetCurrentVtkView(){
446     return GetVtkViewWindow( GetActiveWindow() );
447   }
448
449
450   void RepaintCurrentView()
451   {
452     if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
453     {
454       try {
455 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
456         OCC_CATCH_SIGNALS;
457 #endif
458         wnd->getRenderer()->Render();
459         wnd->Repaint(false);
460       }
461       catch (...) {
462 #ifdef _DEBUG_
463         MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" );
464 #endif
465         OnVisuException();
466       }
467     }
468   }
469
470   void RepaintViewWindow(SVTK_ViewWindow* theWindow)
471   {
472     try {
473 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
474       OCC_CATCH_SIGNALS;
475 #endif
476       theWindow->getRenderer()->Render();
477       theWindow->Repaint();
478     }
479     catch (...) {
480 #ifdef _DEBUG_
481       MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow*)" );
482 #endif
483       OnVisuException();
484     }
485   }
486
487   void RenderViewWindow(SVTK_ViewWindow* theWindow)
488   {
489     try {
490 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
491       OCC_CATCH_SIGNALS;
492 #endif
493       theWindow->getRenderer()->Render();
494       theWindow->Repaint();
495     }
496     catch (...) {
497 #ifdef _DEBUG_
498       MESSAGE ( "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow*)" );
499 #endif
500       OnVisuException();
501     }
502   }
503
504   void FitAll(){
505     if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
506       try {
507 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
508         OCC_CATCH_SIGNALS;
509 #endif
510         wnd->onFitAll();
511         wnd->Repaint();
512       }
513       catch (...) {
514 #ifdef _DEBUG_
515         MESSAGE ( "Exception in SMESHGUI_VTKUtils::FitAll()" );
516 #endif
517         OnVisuException();
518       }
519     }
520   }
521
522
523   SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
524                                 const char* theEntry)
525   {
526     if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
527       vtkRenderer *aRenderer = aViewWindow->getRenderer();
528       VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
529       vtkActorCollection *aCollection = aCopy.GetActors();
530       aCollection->InitTraversal();
531       while(vtkActor *anAct = aCollection->GetNextActor()){
532         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
533           if(anActor->hasIO()){
534             Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
535             if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
536               return anActor;
537             }
538           }
539         }
540       }
541     }
542     return NULL;
543   }
544
545
546   SMESH_Actor* FindActorByEntry(const char* theEntry){
547     return FindActorByEntry(GetActiveWindow(),theEntry);
548   }
549
550
551   SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
552     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
553     if( !app )
554       return NULL;
555
556     if(!CORBA::is_nil(theObject)){
557       _PTR(Study) aStudy = GetActiveStudyDocument();
558       CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
559       _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
560       if(aSObject){
561         CORBA::String_var anEntry = aSObject->GetID().c_str();
562         return FindActorByEntry(anEntry.in());
563       }
564     }
565     return NULL;
566   }
567
568
569   SMESH_Actor* CreateActor(_PTR(Study) theStudy,
570                            const char* theEntry,
571                            int theIsClear)
572   {
573     SMESH_Actor *anActor = NULL;
574     CORBA::Long anId = theStudy->StudyId();
575     if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
576       _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
577       if(aSObj){
578         _PTR(GenericAttribute) anAttr;
579         if(aSObj->FindAttribute(anAttr,"AttributeName")){
580           _PTR(AttributeName) aName = anAttr;
581           std::string aNameVal = aName->Value();
582           anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
583         }
584
585         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
586         if(!CORBA::is_nil(aGroup))
587         {
588           SALOMEDS::Color aColor = aGroup->GetColor();
589           if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ) )
590           {
591             int r = 0, g = 0, b = 0;
592             SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
593             aColor.R = (float)r / 255.0;
594             aColor.G = (float)g / 255.0;
595             aColor.B = (float)b / 255.0;
596             aGroup->SetColor( aColor );
597           }
598           if( aGroup->GetType() == SMESH::NODE )
599             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
600           else if( aGroup->GetType() == SMESH::EDGE )
601             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
602           else if( aGroup->GetType() == SMESH::ELEM0D )
603             anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
604           else
605             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
606         }
607       }
608     }
609     MESSAGE("CreateActor " << anActor);
610     return anActor;
611   }
612
613
614   void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
615     if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
616       try {
617 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
618         OCC_CATCH_SIGNALS;
619 #endif
620         MESSAGE("DisplayActor " << theActor);
621         vtkWnd->AddActor(theActor);
622         vtkWnd->Repaint();
623       }
624       catch (...) {
625 #ifdef _DEBUG_
626         MESSAGE ( "Exception in SMESHGUI_VTKUtils::DisplayActor()" );
627 #endif
628         OnVisuException();
629       }
630     }
631   }
632
633
634   void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
635     if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
636         MESSAGE("RemoveActor " << theActor);
637       vtkWnd->RemoveActor(theActor);
638       if(theActor->hasIO()){
639         Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
640         if(anIO->hasEntry()){
641           std::string anEntry = anIO->getEntry();
642           SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
643           int aStudyId = aStudy->id();
644           TVisualObjCont::key_type aKey(aStudyId,anEntry);
645           VISUAL_OBJ_CONT.erase(aKey);
646         }
647       }
648       theActor->Delete();
649       vtkWnd->Repaint();
650     }
651   }
652
653   //================================================================================
654   /*!
655    * \brief Return true if there are no SMESH actors in a view
656    */
657   //================================================================================
658
659   bool noSmeshActors(SUIT_ViewWindow *theWnd)
660   {
661     if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWnd)) {
662       vtkRenderer *aRenderer = aViewWindow->getRenderer();
663       VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
664       vtkActorCollection *aCollection = aCopy.GetActors();
665       aCollection->InitTraversal();
666       while(vtkActor *anAct = aCollection->GetNextActor())
667         if(dynamic_cast<SMESH_Actor*>(anAct))
668           return false;
669     }
670     return true;
671   }
672
673   bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
674   {
675         //MESSAGE("UpdateView");
676     bool OK = false;
677     SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
678     if (!aViewWnd)
679       return OK;
680
681     {
682       OK = true;
683       vtkRenderer *aRenderer = aViewWnd->getRenderer();
684       VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
685       vtkActorCollection *aCollection = aCopy.GetActors();
686       aCollection->InitTraversal();
687
688       switch (theAction) {
689       case eDisplayAll: {
690         while (vtkActor *anAct = aCollection->GetNextActor()) {
691           if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
692                 MESSAGE("--- display " << anActor);
693             anActor->SetVisibility(true);
694           }
695         }
696         break;
697       }
698       case eDisplayOnly:
699       case eEraseAll: {
700         //MESSAGE("---case eDisplayOnly");
701         while (vtkActor *anAct = aCollection->GetNextActor()) {
702           if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
703                 //MESSAGE("--- erase " << anActor);
704             anActor->SetVisibility(false);
705           }
706         }
707       }
708       default: {
709         if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
710           switch (theAction) {
711             case eDisplay:
712             case eDisplayOnly:
713                 //MESSAGE("--- display " << anActor);
714               anActor->SetVisibility(true);
715               if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
716               break;
717             case eErase:
718                 //MESSAGE("--- erase " << anActor);
719               anActor->SetVisibility(false);
720               break;
721           }
722         } else {
723           switch (theAction) {
724           case eDisplay:
725           case eDisplayOnly:
726             {
727                 //MESSAGE("---");
728               SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(theWnd->getViewManager()->study());
729               _PTR(Study) aDocument = aStudy->studyDS();
730               // Pass non-visual objects (hypotheses, etc.), return true in this case
731               CORBA::Long anId = aDocument->StudyId();
732               TVisualObjPtr aVisualObj;
733               if ( (aVisualObj = GetVisualObj(anId,theEntry)) && aVisualObj->IsValid())
734               {
735                 if ((anActor = CreateActor(aDocument,theEntry,true))) {
736                   bool needFitAll = noSmeshActors(theWnd); // fit for the first object only
737                   DisplayActor(theWnd,anActor);
738                   // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
739                   if (needFitAll) FitAll();
740                 } else {
741                   OK = false;
742                 }
743               }
744               break;
745             }
746           }
747         }
748       }
749       }
750     }
751     return OK;
752   }
753
754
755   bool UpdateView(EDisplaing theAction, const char* theEntry){
756         //MESSAGE("UpdateView");
757     SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
758     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
759     SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
760     return UpdateView(aWnd,theAction,theEntry);
761   }
762
763   void UpdateView(){
764     if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
765       LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
766       SALOME_ListIO selected; mgr->selectedObjects( selected );
767
768       if( selected.Extent() == 0){
769         vtkRenderer* aRenderer = aWnd->getRenderer();
770         VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
771         vtkActorCollection *aCollection = aCopy.GetActors();
772         aCollection->InitTraversal();
773         while(vtkActor *anAct = aCollection->GetNextActor()){
774           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
775             if(anActor->hasIO())
776               if (!Update(anActor->getIO(),anActor->GetVisibility()))
777                 break; // avoid multiple warinings if visu failed
778           }
779         }
780       }else{
781         SALOME_ListIteratorOfListIO anIter( selected );
782         for( ; anIter.More(); anIter.Next()){
783           Handle(SALOME_InteractiveObject) anIO = anIter.Value();
784           if ( !Update(anIO,true) )
785             break; // avoid multiple warinings if visu failed
786         }
787       }
788       RepaintCurrentView();
789     }
790   }
791
792
793   bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
794   {
795         MESSAGE("Update");
796     _PTR(Study) aStudy = GetActiveStudyDocument();
797     CORBA::Long anId = aStudy->StudyId();
798     if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
799       if ( theDisplay )
800         UpdateView(SMESH::eDisplay,theIO->getEntry());
801       return true;
802     }
803     return false;
804   }
805
806   bool UpdateNulData(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
807   {
808         MESSAGE("UpdateNulData");
809     _PTR(Study) aStudy = GetActiveStudyDocument();
810     CORBA::Long anId = aStudy->StudyId();
811     if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry(), true)) {
812       if ( theDisplay )
813         UpdateView(SMESH::eDisplay,theIO->getEntry());
814       return true;
815     }
816     return false;
817   }
818
819   void UpdateSelectionProp( SMESHGUI* theModule ) {
820     if( !theModule )
821       return;
822
823     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
824     if( !app )
825     {
826       MESSAGE( "UpdateSelectionProp: Application is null" );
827       return;
828     }
829
830     SUIT_ViewManager* vm = app->activeViewManager();
831     if( !vm )
832     {
833       MESSAGE( "UpdateSelectionProp: View manager is null" );
834       return;
835     }
836
837     QVector<SUIT_ViewWindow*> views = vm->getViews();
838
839     SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
840     if( !mgr )
841     {
842       MESSAGE( "UpdateSelectionProp: Resource manager is null" );
843       return;
844     }
845
846     QColor aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
847            aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
848            aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
849
850     int SW = mgr->integerValue( "SMESH", "selection_width", 5 ),
851         PW = mgr->integerValue( "SMESH", "highlight_width", 5 );
852
853     // adjust highlight_width to the width of mesh entities
854     int aElem0DSize = mgr->integerValue("SMESH", "elem0d_size", 5);
855     int aLineWidth  = mgr->integerValue("SMESH", "element_width", 1);
856     int maxSize = aElem0DSize;
857     if (aElem0DSize > maxSize) maxSize = aElem0DSize;
858     if (aLineWidth > maxSize) maxSize = aLineWidth;
859     if (PW < maxSize + 2) PW = maxSize + 2;
860
861     double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
862            SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
863            SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
864
865     for ( int i=0, n=views.count(); i<n; i++ ){
866       // update VTK viewer properties
867       if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
868         // mesh element selection
869         aVtkView->SetSelectionProp(aSelColor.red()/255.,
870                                    aSelColor.green()/255.,
871                                    aSelColor.blue()/255.,
872                                    SW );
873         // tolerances
874         aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
875
876         // pre-selection
877         aVtkView->SetPreselectionProp(aPreColor.red()/255.,
878                                       aPreColor.green()/255.,
879                                       aPreColor.blue()/255.,
880                                       PW);
881         // update actors
882         vtkRenderer* aRenderer = aVtkView->getRenderer();
883         VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
884         vtkActorCollection *aCollection = aCopy.GetActors();
885         aCollection->InitTraversal();
886         while(vtkActor *anAct = aCollection->GetNextActor()){
887           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
888             anActor->SetHighlightColor(aHiColor.red()/255.,
889                                        aHiColor.green()/255.,
890                                        aHiColor.blue()/255.);
891             anActor->SetPreHighlightColor(aPreColor.red()/255.,
892                                           aPreColor.green()/255.,
893                                           aPreColor.blue()/255.);
894           }
895         }
896       }
897     }
898   }
899
900
901   //----------------------------------------------------------------------------
902   SVTK_Selector*
903   GetSelector(SUIT_ViewWindow *theWindow)
904   {
905     if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
906       return aWnd->GetSelector();
907
908     return NULL;
909   }
910
911   void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
912                  SVTK_Selector* theSelector)
913   {
914     if (theSelector)
915       theSelector->SetFilter(theFilter);
916   }
917
918   Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
919   {
920     return theSelector->GetFilter(theId);
921   }
922
923   bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
924   {
925     return theSelector->IsFilterPresent(theId);
926   }
927
928   void RemoveFilter(int theId, SVTK_Selector* theSelector)
929   {
930     theSelector->RemoveFilter(theId);
931   }
932
933   void RemoveFilters(SVTK_Selector* theSelector)
934   {
935     for ( int id = SMESH::NodeFilter; theSelector && id < SMESH::LastFilter; id++ )
936       theSelector->RemoveFilter( id );
937   }
938
939   bool IsValid(SALOME_Actor* theActor, int theCellId,
940                SVTK_Selector* theSelector)
941   {
942     return theSelector->IsValid(theActor,theCellId);
943   }
944
945
946   //----------------------------------------------------------------------------
947   void SetPointRepresentation(bool theIsVisible){
948     if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
949       vtkRenderer *aRenderer = aViewWindow->getRenderer();
950       VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
951       vtkActorCollection *aCollection = aCopy.GetActors();
952       aCollection->InitTraversal();
953       while(vtkActor *anAct = aCollection->GetNextActor()){
954         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
955           if(anActor->GetVisibility()){
956             anActor->SetPointRepresentation(theIsVisible);
957           }
958         }
959       }
960       RepaintCurrentView();
961     }
962   }
963
964
965   void SetPickable(SMESH_Actor* theActor){
966     if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
967       int anIsAllPickable = (theActor == NULL);
968       vtkRenderer *aRenderer = aWnd->getRenderer();
969       VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
970       vtkActorCollection *aCollection = aCopy.GetActors();
971       aCollection->InitTraversal();
972       while(vtkActor *anAct = aCollection->GetNextActor()){
973         if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
974           if(anActor->GetVisibility()){
975             anActor->SetPickable(anIsAllPickable);
976           }
977         }
978       }
979       if(theActor)
980         theActor->SetPickable(!anIsAllPickable);
981       RepaintCurrentView();
982     }
983   }
984
985
986   //----------------------------------------------------------------------------
987   int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
988                              const Handle(SALOME_InteractiveObject)& theIO,
989                              QString& theName)
990   {
991     theName = "";
992     TColStd_IndexedMapOfInteger aMapIndex;
993     theSelector->GetIndex(theIO,aMapIndex);
994
995     for(int i = 1; i <= aMapIndex.Extent(); i++)
996       theName += QString(" %1").arg(aMapIndex(i));
997
998     return aMapIndex.Extent();
999   }
1000
1001   int GetNameOfSelectedElements(SVTK_Selector* theSelector,
1002                                 const Handle(SALOME_InteractiveObject)& theIO,
1003                                 QString& theName)
1004   {
1005     theName = "";
1006     TColStd_IndexedMapOfInteger aMapIndex;
1007     theSelector->GetIndex(theIO,aMapIndex);
1008
1009     typedef std::set<int> TIdContainer;
1010     TIdContainer anIdContainer;
1011     for( int i = 1; i <= aMapIndex.Extent(); i++)
1012       anIdContainer.insert(aMapIndex(i));
1013
1014     TIdContainer::const_iterator anIter = anIdContainer.begin();
1015     for( ; anIter != anIdContainer.end(); anIter++)
1016       theName += QString(" %1").arg(*anIter);
1017
1018     return aMapIndex.Extent();
1019   }
1020
1021
1022   int GetEdgeNodes(SVTK_Selector* theSelector,
1023                    const TVisualObjPtr& theVisualObject,
1024                    int& theId1,
1025                    int& theId2)
1026   {
1027     const SALOME_ListIO& selected = theSelector->StoredIObjects();
1028
1029     if ( selected.Extent() != 1 )
1030       return -1;
1031
1032     Handle(SALOME_InteractiveObject) anIO = selected.First();
1033     if ( anIO.IsNull() || !anIO->hasEntry() )
1034       return -1;
1035
1036     TColStd_IndexedMapOfInteger aMapIndex;
1037     theSelector->GetIndex( anIO, aMapIndex );
1038     if ( aMapIndex.Extent() != 2 )
1039       return -1;
1040
1041     int anObjId = -1, anEdgeNum = -1;
1042     for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1043       int aVal = aMapIndex( i );
1044       if ( aVal > 0 )
1045         anObjId = aVal;
1046       else
1047         anEdgeNum = abs( aVal ) - 1;
1048     }
1049
1050     if ( anObjId == -1 || anEdgeNum == -1 )
1051       return -1;
1052
1053     return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1054   }
1055
1056   //----------------------------------------------------------------------------
1057   int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1058                              const Handle(SALOME_InteractiveObject)& theIO,
1059                              QString& theName)
1060   {
1061     theName = "";
1062     if(theIO->hasEntry()){
1063       if(FindActorByEntry(theIO->getEntry())){
1064         TColStd_IndexedMapOfInteger aMapIndex;
1065         theMgr->GetIndexes(theIO,aMapIndex);
1066         for(int i = 1; i <= aMapIndex.Extent(); i++){
1067           theName += QString(" %1").arg(aMapIndex(i));
1068         }
1069         return aMapIndex.Extent();
1070       }
1071     }
1072     return -1;
1073   }
1074
1075   int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName){
1076     theName = "";
1077     SALOME_ListIO selected; theMgr->selectedObjects( selected );
1078     if(selected.Extent() == 1){
1079       Handle(SALOME_InteractiveObject) anIO = selected.First();
1080       return GetNameOfSelectedNodes(theMgr,anIO,theName);
1081     }
1082     return -1;
1083   }
1084
1085
1086   int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr,
1087                                 const Handle(SALOME_InteractiveObject)& theIO,
1088                                 QString& theName)
1089   {
1090     theName = "";
1091     if(theIO->hasEntry()){
1092       if(FindActorByEntry(theIO->getEntry())){
1093         TColStd_IndexedMapOfInteger aMapIndex;
1094         theMgr->GetIndexes(theIO,aMapIndex);
1095         typedef std::set<int> TIdContainer;
1096         TIdContainer anIdContainer;
1097         for( int i = 1; i <= aMapIndex.Extent(); i++)
1098           anIdContainer.insert(aMapIndex(i));
1099         TIdContainer::const_iterator anIter = anIdContainer.begin();
1100         for( ; anIter != anIdContainer.end(); anIter++){
1101           theName += QString(" %1").arg(*anIter);
1102         }
1103         return aMapIndex.Extent();
1104       }
1105     }
1106     return -1;
1107   }
1108
1109
1110   int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1111   {
1112     theName = "";
1113     SALOME_ListIO selected; theMgr->selectedObjects( selected );
1114
1115     if( selected.Extent() == 1){
1116       Handle(SALOME_InteractiveObject) anIO = selected.First();
1117       return GetNameOfSelectedElements(theMgr,anIO,theName);
1118     }
1119     return -1;
1120   }
1121
1122   int GetSelected(LightApp_SelectionMgr*       theMgr,
1123                   TColStd_IndexedMapOfInteger& theMap,
1124                   const bool                   theIsElement)
1125   {
1126     theMap.Clear();
1127     SALOME_ListIO selected; theMgr->selectedObjects( selected );
1128
1129     if ( selected.Extent() == 1 )
1130     {
1131       Handle(SALOME_InteractiveObject) anIO = selected.First();
1132       if ( anIO->hasEntry() ) {
1133         theMgr->GetIndexes( anIO, theMap );
1134       }
1135     }
1136     return theMap.Extent();
1137   }
1138
1139
1140   int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
1141   {
1142     SALOME_ListIO selected; theMgr->selectedObjects( selected );
1143
1144     if ( selected.Extent() != 1 )
1145       return -1;
1146
1147     Handle(SALOME_InteractiveObject) anIO = selected.First();
1148     if ( anIO.IsNull() || !anIO->hasEntry() )
1149       return -1;
1150
1151     SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1152     if ( anActor == 0 )
1153       return -1;
1154
1155     TColStd_IndexedMapOfInteger aMapIndex;
1156     theMgr->GetIndexes( anIO, aMapIndex );
1157     if ( aMapIndex.Extent() != 2 )
1158       return -1;
1159
1160     int anObjId = -1, anEdgeNum = -1;
1161     for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1162       int aVal = aMapIndex( i );
1163       if ( aVal > 0 )
1164         anObjId = aVal;
1165       else
1166         anEdgeNum = abs( aVal );
1167     }
1168
1169     if ( anObjId == -1 || anEdgeNum == -1 )
1170       return -1;
1171
1172     return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1173   }
1174
1175   void SetControlsPrecision( const long theVal )
1176   {
1177     if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1178     {
1179       vtkRenderer *aRenderer = aWnd->getRenderer();
1180       VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1181       vtkActorCollection *aCollection = aCopy.GetActors();
1182       aCollection->InitTraversal();
1183
1184       while ( vtkActor *anAct = aCollection->GetNextActor())
1185       {
1186         if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1187         {
1188           anActor->SetControlsPrecision( theVal );
1189           anActor->SetControlMode( anActor->GetControlMode() );
1190         }
1191       }
1192
1193     }
1194   }
1195 } // end of namespace SMESH