Salome HOME
IPAL9150
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_VTKUtils.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 //  This library is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU Lesser General Public
6 //  License as published by the Free Software Foundation; either
7 //  version 2.1 of the License.
8 //
9 //  This library is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 //  Lesser General Public License for more details.
13 //
14 //  You should have received a copy of the GNU Lesser General Public
15 //  License along with this library; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19
20
21 #include "SMESHGUI_VTKUtils.h"
22 #include "SMESHGUI_Utils.h"
23 #include "SMESHGUI_Filter.h"
24
25 #include <vtkRenderer.h>
26 #include <vtkActorCollection.h>
27
28 #include <TColStd_IndexedMapOfInteger.hxx>
29
30 #include <SUIT_Desktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Study.h>
33
34 #include "SalomeApp_SelectionMgr.h"
35
36 #include "SVTK_Selector.h"
37 #include "SVTK_ViewModel.h"
38 #include "SVTK_ViewWindow.h"
39 #include "SVTK_RenderWindow.h"
40 #include "SVTK_InteractorStyle.h"
41 #include "SVTK_RenderWindowInteractor.h"
42
43 #include "utilities.h"
44
45 #include "SALOMEconfig.h"
46 #include CORBA_CLIENT_HEADER(SMESH_Gen)
47 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
48 #include CORBA_CLIENT_HEADER(SMESH_Group)
49 #include CORBA_CLIENT_HEADER(SMESH_Hypothesis)
50
51 #include "SMESHGUI.h"
52 #include "SMESH_Actor.h"
53 #include "SMESH_ObjectDef.h"
54
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_SelectionMgr.h>
57 #include <SalomeApp_Study.h>
58
59 #include <SALOMEDSClient_Study.hxx>
60 #include <SALOMEDSClient_SObject.hxx>
61
62 #include <SALOME_ListIO.hxx>
63 #include <SALOME_ListIteratorOfListIO.hxx>
64
65 #include <set>
66 using namespace std;
67
68 namespace SMESH{
69
70   typedef map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
71   static TVisualObjCont VISUAL_OBJ_CONT;
72
73   TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
74     TVisualObjPtr aVisualObj;
75     try{
76       TVisualObjCont::key_type aKey(theStudyId,theEntry);
77       TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
78       if(anIter != VISUAL_OBJ_CONT.end()){
79         aVisualObj = anIter->second;
80       }else{
81         SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
82         _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
83         _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
84         if(aSObj){
85           _PTR(GenericAttribute) anAttr;
86           if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
87             _PTR(AttributeIOR) anIOR = anAttr;
88             CORBA::String_var aVal = anIOR->Value().c_str();
89             CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
90             if(!CORBA::is_nil(anObj)){
91               //Try narrow to SMESH_Mesh interafce
92               SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
93               if(!aMesh->_is_nil()){
94                 aVisualObj.reset(new SMESH_MeshObj(aMesh));
95                 aVisualObj->Update();
96                 TVisualObjCont::value_type aValue(aKey,aVisualObj); 
97                 VISUAL_OBJ_CONT.insert(aValue);
98                 return aVisualObj;
99               }
100               //Try narrow to SMESH_Group interafce
101               SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
102               if(!aGroup->_is_nil()){
103                 _PTR(SObject) aFatherSObj = aSObj->GetFather();
104                 if(!aFatherSObj) return aVisualObj;
105                 aFatherSObj = aFatherSObj->GetFather();
106                 if(!aFatherSObj) return aVisualObj;
107                 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
108                 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
109                 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
110                   aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
111                   aVisualObj->Update();
112                   TVisualObjCont::value_type aValue(aKey,aVisualObj);
113                   VISUAL_OBJ_CONT.insert(aValue);
114                   return aVisualObj;
115                 }
116               }
117               //Try narrow to SMESH_subMesh interafce
118               SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
119               if(!aSubMesh->_is_nil()){
120                 _PTR(SObject) aFatherSObj = aSObj->GetFather();
121                 if(!aFatherSObj) return aVisualObj;
122                 aFatherSObj = aFatherSObj->GetFather();
123                 if(!aFatherSObj) return aVisualObj;
124                 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
125                 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
126                 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
127                   aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
128                   aVisualObj->Update();
129                   TVisualObjCont::value_type aValue(aKey,aVisualObj);
130                   VISUAL_OBJ_CONT.insert(aValue);
131                   return aVisualObj;
132                 }
133               }
134             }
135           }
136         }
137       }
138     }catch(...){
139       INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
140     }
141     return aVisualObj;
142   }
143
144
145   SVTK_ViewWindow*
146   GetViewWindow(const SalomeApp_Module* theModule)
147   {
148     if(SalomeApp_Application* anApp = theModule->getApp()){
149       if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
150         if(aViewManager->getType() == SVTK_Viewer::Type()){
151           if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
152             return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
153           }
154         }
155       }
156     }
157     return NULL;
158   }
159
160   SVTK_ViewWindow* FindVtkViewWindow( SUIT_ViewManager* theMgr,
161                                            SUIT_ViewWindow* theWindow )
162   {
163     if( !theMgr )
164       return NULL;
165
166     QPtrVector<SUIT_ViewWindow> views = theMgr->getViews();
167     if( views.containsRef( theWindow ) )
168       return GetVtkViewWindow( theWindow );
169     else
170       return NULL;
171   }
172
173
174   SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
175     return dynamic_cast<SVTK_ViewWindow*>(theWindow);
176   }
177
178
179 /*  SUIT_ViewWindow* GetActiveWindow()
180   {
181     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
182     if( !app )
183       return NULL;
184     SUIT_ViewManager* mgr = app->activeViewManager();
185     if( mgr )
186       return mgr->getActiveView();
187     else
188       return NULL;
189   }*/
190
191   SVTK_ViewWindow* GetCurrentVtkView(){
192     return GetVtkViewWindow( GetActiveWindow() );
193   }
194
195   void RepaintViewWindow(SVTK_ViewWindow* theWindow)
196   {
197     theWindow->Repaint();
198   }
199
200   void RenderViewWindow(SVTK_ViewWindow* theWindow)
201   {
202     theWindow->getRenderer()->Render();
203     theWindow->Repaint();
204   }
205
206   SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
207                                 const char* theEntry)
208   {
209     if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
210       vtkRenderer *aRenderer = aViewWindow->getRenderer();
211       vtkActorCollection *aCollection = aRenderer->GetActors();
212       aCollection->InitTraversal();
213       while(vtkActor *anAct = aCollection->GetNextActor()){
214         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
215           if(anActor->hasIO()){
216             Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
217             if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
218               return anActor;
219             }
220           }
221         }
222       }
223     }
224     return NULL;
225   }
226
227
228   SMESH_Actor* FindActorByEntry(const char* theEntry){
229     return FindActorByEntry(GetActiveWindow(),theEntry);
230   }
231
232
233   SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
234     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
235     if( !app )
236       return NULL;
237
238     if(!CORBA::is_nil(theObject)){
239       _PTR(Study) aStudy = GetActiveStudyDocument();
240       CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
241       _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
242       if(aSObject){
243         CORBA::String_var anEntry = aSObject->GetID().c_str();
244         return FindActorByEntry(anEntry.in());
245       }
246     }
247     return NULL;
248   }
249
250
251   SMESH_Actor* CreateActor(_PTR(Study) theStudy,
252                            const char* theEntry,
253                            int theIsClear)
254   {
255     SMESH_Actor *anActor = NULL;
256     CORBA::Long anId = theStudy->StudyId();
257     if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
258       _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
259       if(aSObj){
260         _PTR(GenericAttribute) anAttr;
261         if(aSObj->FindAttribute(anAttr,"AttributeName")){
262           _PTR(AttributeName) aName = anAttr;
263           std::string aNameVal = aName->Value();
264           anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
265         }
266       }
267     }
268     return anActor;
269   }
270
271
272   void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
273     if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
274       vtkWnd->AddActor(theActor);
275       vtkWnd->Repaint();
276     }
277   }
278
279
280   void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
281     if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
282       vtkWnd->RemoveActor(theActor);
283       if(theActor->hasIO()){
284         Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
285         if(anIO->hasEntry()){
286           std::string anEntry = anIO->getEntry();
287           SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
288           int aStudyId = aStudy->id();
289           TVisualObjCont::key_type aKey(aStudyId,anEntry);
290           VISUAL_OBJ_CONT.erase(aKey);
291         }
292       }
293       theActor->Delete();
294       vtkWnd->Repaint();
295     }
296   }
297
298
299   void FitAll(){
300     if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
301       wnd->onFitAll();
302       wnd->Repaint();
303     }
304   }
305
306   vtkRenderer* GetCurrentRenderer(){
307     if(SVTK_ViewWindow* wnd = GetCurrentVtkView() )
308       return wnd->getRenderer();
309     return NULL;
310   }
311
312   void RepaintCurrentView(){
313     if(SVTK_ViewWindow* wnd = GetCurrentVtkView() )
314       wnd->getRenderer()->Render();
315       //wnd->Repaint();
316   }
317
318   void UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
319   {
320     if(SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd)){
321       vtkRenderer *aRenderer = aViewWnd->getRenderer();
322       vtkActorCollection *aCollection = aRenderer->GetActors();
323       aCollection->InitTraversal();
324       switch(theAction){
325       case eDisplayAll: {
326         while(vtkActor *anAct = aCollection->GetNextActor()){
327           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
328             anActor->SetVisibility(true);
329           }
330         }
331         break;
332       }
333       case eDisplayOnly:
334       case eEraseAll: {
335         while(vtkActor *anAct = aCollection->GetNextActor()){
336           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
337             anActor->SetVisibility(false);
338           }
339         }
340       }
341       default: {
342         if(SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)){
343           switch(theAction) {
344             case eDisplay:
345             case eDisplayOnly:
346               anActor->SetVisibility(true);
347               break;
348             case eErase:
349               anActor->SetVisibility(false);
350               break;
351           }
352         } else {
353           switch(theAction){
354           case eDisplay:
355           case eDisplayOnly:{
356             SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( theWnd->getViewManager()->study() );
357             _PTR(Study) aDocument = aStudy->studyDS();
358             if((anActor = CreateActor(aDocument,theEntry,true))) {
359               DisplayActor(theWnd,anActor);
360               FitAll();
361             }
362             break;
363           }
364           }
365         }
366       }
367       }
368     }
369   }
370
371
372   void UpdateView(EDisplaing theAction, const char* theEntry){
373     SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
374     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
375     SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
376     UpdateView(aWnd,theAction,theEntry);
377   }
378
379   void UpdateView(){
380     if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
381       SalomeApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
382       SALOME_ListIO selected; mgr->selectedObjects( selected );
383
384       if( selected.Extent() == 0){
385         vtkRenderer* aRenderer = aWnd->getRenderer();
386         vtkActorCollection *aCollection = aRenderer->GetActors();
387         aCollection->InitTraversal();
388         while(vtkActor *anAct = aCollection->GetNextActor()){
389           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
390             if(anActor->hasIO())
391               Update(anActor->getIO(),anActor->GetVisibility());
392           }
393         }
394       }else{
395         SALOME_ListIteratorOfListIO anIter( selected );
396         for(; anIter.More(); anIter.Next()){
397           Handle(SALOME_InteractiveObject) anIO = anIter.Value();
398           Update(anIO,true);
399         }
400       }
401       RepaintCurrentView();
402     }
403   }
404
405
406   void Update(const Handle(SALOME_InteractiveObject)& theIO,
407               bool theDisplay)
408   {
409     _PTR(Study) aStudy = GetActiveStudyDocument();
410     CORBA::Long anId = aStudy->StudyId();
411     TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry());
412     if( aVisualObj )
413       aVisualObj->Update();
414     if ( theDisplay )
415       UpdateView(SMESH::eDisplay,theIO->getEntry());
416   }
417
418
419   void UpdateSelectionProp( SMESHGUI* theModule ) {
420     if( !theModule )
421       return;
422
423     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
424     if( !app )
425     {
426       MESSAGE( "UpdateSelectionProp: Application is null" );
427       return;
428     }
429
430     SUIT_ViewManager* vm = app->activeViewManager();
431     if( !vm )
432     {
433       MESSAGE( "UpdateSelectionProp: View manager is null" );
434       return;
435     }
436
437     QPtrVector<SUIT_ViewWindow> views = vm->getViews();
438
439     SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
440     if( !mgr )
441     {
442       MESSAGE( "UpdateSelectionProp: Resource manager is null" );
443       return;
444     }
445
446     QColor aHiColor = mgr->colorValue( "SMESH", "SettingsSelectColor", Qt::white ),
447            aSelColor = mgr->colorValue( "SMESH", "SettingsItemSelectColor", Qt::yellow ),
448            aPreColor = mgr->colorValue( "SMESH", "SettingsPreSelectColor", Qt::cyan );
449
450     int SW = mgr->integerValue( "SMESH", "SettingsItemSelectWidth", 5 ),
451         PW = mgr->integerValue( "SMESH", "SettingsPreSelectWidth", 5 );
452
453     double SP1 = mgr->doubleValue( "SMESH", "SettingsNodeSelectTol", 0.025 ),
454            SP2 = mgr->doubleValue( "SMESH", "SettingsElementsSelectTol", 0.001 );
455
456     for ( int i=0, n=views.count(); i<n; i++ ) {
457         SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] );
458         if (!aVtkView) continue;
459         // update VTK viewer properties
460         SVTK_RenderWindowInteractor* anInteractor = aVtkView->getRWInteractor();
461         if (anInteractor) {
462           // mesh element selection
463           anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255.,
464                                          aSelColor.blue()/255., SW );
465
466           // tolerances
467           anInteractor->SetSelectionTolerance(SP1, SP2);
468
469           // pre-selection
470           SVTK_InteractorStyle* aStyle =
471             dynamic_cast<SVTK_InteractorStyle*>( anInteractor->GetInteractorStyle() );
472           if (aStyle) {
473             aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255.,
474                                         aPreColor.blue()/255., PW);
475           }
476         }
477         // update actors
478         vtkRenderer* aRenderer = aVtkView->getRenderer();
479         vtkActorCollection *aCollection = aRenderer->GetActors();
480         aCollection->InitTraversal();
481         while(vtkActor *anAct = aCollection->GetNextActor()){
482           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
483             anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255.,
484                                        aHiColor.blue()/255.);
485             anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255.,
486                                           aPreColor.blue()/255.);
487           }
488         }
489     }
490   }
491
492
493   //----------------------------------------------------------------------------
494   SVTK_InteractorStyle* GetInteractorStyle(SUIT_ViewWindow *theWindow){
495     if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow)){
496       if(SVTK_RenderWindowInteractor* anInteractor = aWnd->getRWInteractor()){
497         return dynamic_cast<SVTK_InteractorStyle*>( anInteractor->GetInteractorStyle() );
498       }
499     }
500     return NULL;
501   }
502
503   void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
504                  SVTK_InteractorStyle* theStyle)
505   {
506     theStyle->SetFilter(theFilter);
507   }
508
509   Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_InteractorStyle* theStyle)
510   {
511     return theStyle->GetFilter(theId);
512   }
513
514   bool IsFilterPresent(int theId, SVTK_InteractorStyle* theStyle)
515   {
516     return theStyle->IsFilterPresent(theId);
517   }
518
519   void RemoveFilter(int theId, SVTK_InteractorStyle* theStyle)
520   {
521     theStyle->RemoveFilter(theId);
522   }
523
524   void RemoveFilters(SVTK_InteractorStyle* theStyle)
525   {
526     for ( int id = SMESHGUI_NodeFilter; theStyle && id < SMESHGUI_LastFilter; id++ )
527       theStyle->RemoveFilter( id );
528   }
529
530   bool IsValid(SALOME_Actor* theActor, int theCellId,
531                SVTK_InteractorStyle* theStyle)
532   {
533     return theStyle->IsValid(theActor,theCellId);
534   }
535
536
537   //----------------------------------------------------------------------------
538   void SetPointRepresentation(bool theIsVisible){
539     if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
540       vtkRenderer *aRenderer = aViewWindow->getRenderer();
541       vtkActorCollection *aCollection = aRenderer->GetActors();
542       aCollection->InitTraversal();
543       while(vtkActor *anAct = aCollection->GetNextActor()){
544         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
545           if(anActor->GetVisibility()){
546             anActor->SetPointRepresentation(theIsVisible);
547           }
548         }
549       }
550       RepaintCurrentView();
551     }
552   }
553
554
555   void SetPickable(SMESH_Actor* theActor){
556     if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
557       int anIsAllPickable = (theActor == NULL);
558       vtkRenderer *aRenderer = aWnd->getRenderer();
559       vtkActorCollection *aCollection = aRenderer->GetActors();
560       aCollection->InitTraversal();
561       while(vtkActor *anAct = aCollection->GetNextActor()){
562         if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
563           if(anActor->GetVisibility()){
564             anActor->SetPickable(anIsAllPickable);
565           }
566         }
567       }
568       if(theActor)
569         theActor->SetPickable(!anIsAllPickable);
570       RepaintCurrentView();
571     }
572   }
573
574
575   //----------------------------------------------------------------------------
576   int GetNameOfSelectedNodes(SVTK_Selector* theSelector, 
577                              const Handle(SALOME_InteractiveObject)& theIO, 
578                              QString& theName)
579   {
580     theName = "";
581     TColStd_IndexedMapOfInteger aMapIndex;
582     theSelector->GetIndex(theIO,aMapIndex);
583
584     for(int i = 1; i <= aMapIndex.Extent(); i++)
585       theName += QString(" %1").arg(aMapIndex(i));
586
587     return aMapIndex.Extent();
588   }
589
590   int GetNameOfSelectedElements(SVTK_Selector* theSelector, 
591                                 const Handle(SALOME_InteractiveObject)& theIO, 
592                                 QString& theName)
593   {
594     theName = "";
595     TColStd_IndexedMapOfInteger aMapIndex;
596     theSelector->GetIndex(theIO,aMapIndex);
597
598     typedef std::set<int> TIdContainer;
599     TIdContainer anIdContainer;
600     for( int i = 1; i <= aMapIndex.Extent(); i++)
601       anIdContainer.insert(aMapIndex(i));
602
603     TIdContainer::const_iterator anIter = anIdContainer.begin();
604     for(; anIter != anIdContainer.end(); anIter++)
605       theName += QString(" %1").arg(*anIter);
606
607     return aMapIndex.Extent();
608   }
609
610
611   int GetEdgeNodes(SVTK_Selector* theSelector, 
612                    const TVisualObjPtr& theVisualObject,
613                    int& theId1, 
614                    int& theId2)
615   {
616     const SALOME_ListIO& selected = theSelector->StoredIObjects(); 
617
618     if ( selected.Extent() != 1 )
619       return -1;
620
621     Handle(SALOME_InteractiveObject) anIO = selected.First();
622     if ( anIO.IsNull() || !anIO->hasEntry() )
623       return -1;
624
625     TColStd_IndexedMapOfInteger aMapIndex;
626     theSelector->GetIndex( anIO, aMapIndex );
627     if ( aMapIndex.Extent() != 2 )
628       return -1;
629
630     int anObjId = -1, anEdgeNum = -1;
631     for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
632       int aVal = aMapIndex( i );
633       if ( aVal > 0 )
634         anObjId = aVal;
635       else
636         anEdgeNum = abs( aVal ) - 1;
637     }
638
639     if ( anObjId == -1 || anEdgeNum == -1 )
640       return -1;
641
642     return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
643   }
644
645   //----------------------------------------------------------------------------
646   int GetNameOfSelectedNodes(SalomeApp_SelectionMgr *theMgr,
647                              const Handle(SALOME_InteractiveObject)& theIO,
648                              QString& theName)
649   {
650     theName = "";
651     if(theIO->hasEntry()){
652       if(FindActorByEntry(theIO->getEntry())){
653         TColStd_IndexedMapOfInteger aMapIndex;
654         theMgr->GetIndexes(theIO,aMapIndex);
655         for(int i = 1; i <= aMapIndex.Extent(); i++){
656           theName += QString(" %1").arg(aMapIndex(i));
657         }
658         return aMapIndex.Extent();
659       }
660     }
661     return -1;
662   }
663
664   int GetNameOfSelectedNodes(SalomeApp_SelectionMgr *theMgr, QString& theName){
665     theName = "";
666     SALOME_ListIO selected; theMgr->selectedObjects( selected );
667     if(selected.Extent() == 1){
668       Handle(SALOME_InteractiveObject) anIO = selected.First();
669       return GetNameOfSelectedNodes(theMgr,anIO,theName);
670     }
671     return -1;
672   }
673   
674
675   int GetNameOfSelectedElements(SalomeApp_SelectionMgr *theMgr,
676                                 const Handle(SALOME_InteractiveObject)& theIO,
677                                 QString& theName)
678   {
679     theName = "";
680     if(theIO->hasEntry()){
681       if(FindActorByEntry(theIO->getEntry())){
682         TColStd_IndexedMapOfInteger aMapIndex;
683         theMgr->GetIndexes(theIO,aMapIndex);
684         typedef set<int> TIdContainer;
685         TIdContainer anIdContainer;
686         for( int i = 1; i <= aMapIndex.Extent(); i++)
687           anIdContainer.insert(aMapIndex(i));
688         TIdContainer::const_iterator anIter = anIdContainer.begin();
689         for(; anIter != anIdContainer.end(); anIter++){
690           theName += QString(" %1").arg(*anIter);
691         }
692         return aMapIndex.Extent();
693       }
694     }
695     return -1;
696   }
697
698
699   int GetNameOfSelectedElements(SalomeApp_SelectionMgr *theMgr, QString& theName)
700   {
701     theName = "";
702     SALOME_ListIO selected; theMgr->selectedObjects( selected );
703
704     if( selected.Extent() == 1){
705       Handle(SALOME_InteractiveObject) anIO = selected.First();
706       return GetNameOfSelectedElements(theMgr,anIO,theName);
707     }
708     return -1;
709   }
710
711   int GetSelected(SalomeApp_SelectionMgr*      theMgr,
712                   TColStd_IndexedMapOfInteger& theMap,
713                   const bool                   theIsElement)
714   {
715     theMap.Clear();
716     SALOME_ListIO selected; theMgr->selectedObjects( selected );
717
718     if ( selected.Extent() == 1 )
719     {
720       Handle(SALOME_InteractiveObject) anIO = selected.First();
721       if ( anIO->hasEntry() ) {
722         theMgr->GetIndexes( anIO, theMap );
723       }
724     }
725     return theMap.Extent();
726   }
727
728
729   int GetEdgeNodes( SalomeApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
730   {
731     SALOME_ListIO selected; theMgr->selectedObjects( selected );
732
733     if ( selected.Extent() != 1 )
734       return -1;
735
736     Handle(SALOME_InteractiveObject) anIO = selected.First();
737     if ( anIO.IsNull() || !anIO->hasEntry() )
738       return -1;
739
740     SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
741     if ( anActor == 0 )
742       return -1;
743
744     TColStd_IndexedMapOfInteger aMapIndex;
745     theMgr->GetIndexes( anIO, aMapIndex );
746     if ( aMapIndex.Extent() != 2 )
747       return -1;
748
749     int anObjId = -1, anEdgeNum = -1;
750     for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
751       int aVal = aMapIndex( i );
752       if ( aVal > 0 )
753         anObjId = aVal;
754       else
755         anEdgeNum = abs( aVal );
756     }
757
758     if ( anObjId == -1 || anEdgeNum == -1 )
759       return -1;
760
761     return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
762   }
763
764   void SetControlsPrecision( const long theVal )
765   {
766     if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
767     {
768       vtkRenderer *aRenderer = aWnd->getRenderer();
769       vtkActorCollection *aCollection = aRenderer->GetActors();
770       aCollection->InitTraversal();
771       
772       while ( vtkActor *anAct = aCollection->GetNextActor())
773       {
774         if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
775         {
776           anActor->SetControlsPrecision( theVal );
777           anActor->SetControlMode( anActor->GetControlMode() );
778         }
779       }
780
781     }
782   }
783 }