Salome HOME
Start "Create group" with selected GEOM object occurs crash
[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       return dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow());
150   }
151
152   SVTK_ViewWindow* FindVtkViewWindow( SUIT_ViewManager* theMgr,
153                                            SUIT_ViewWindow* theWindow )
154   {
155     if( !theMgr )
156       return NULL;
157
158     QPtrVector<SUIT_ViewWindow> views = theMgr->getViews();
159     if( views.containsRef( theWindow ) )
160       return GetVtkViewWindow( theWindow );
161     else
162       return NULL;
163   }
164
165
166   SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
167     return dynamic_cast<SVTK_ViewWindow*>(theWindow);
168   }
169
170
171 /*  SUIT_ViewWindow* GetActiveWindow()
172   {
173     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
174     if( !app )
175       return NULL;
176     SUIT_ViewManager* mgr = app->activeViewManager();
177     if( mgr )
178       return mgr->getActiveView();
179     else
180       return NULL;
181   }*/
182
183   SVTK_ViewWindow* GetCurrentVtkView(){
184     return GetVtkViewWindow( GetActiveWindow() );
185   }
186
187   void RepaintViewWindow(SVTK_ViewWindow* theWindow)
188   {
189     theWindow->Repaint();
190   }
191
192   void RenderViewWindow(SVTK_ViewWindow* theWindow)
193   {
194     theWindow->getRenderer()->Render();
195     theWindow->Repaint();
196   }
197
198   SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
199                                 const char* theEntry)
200   {
201     if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
202       vtkRenderer *aRenderer = aViewWindow->getRenderer();
203       vtkActorCollection *aCollection = aRenderer->GetActors();
204       aCollection->InitTraversal();
205       while(vtkActor *anAct = aCollection->GetNextActor()){
206         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
207           if(anActor->hasIO()){
208             Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
209             if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
210               return anActor;
211             }
212           }
213         }
214       }
215     }
216     return NULL;
217   }
218
219
220   SMESH_Actor* FindActorByEntry(const char* theEntry){
221     return FindActorByEntry(GetActiveWindow(),theEntry);
222   }
223
224
225   SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
226     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
227     if( !app )
228       return NULL;
229
230     if(!CORBA::is_nil(theObject)){
231       _PTR(Study) aStudy = GetActiveStudyDocument();
232       CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
233       _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
234       if(aSObject){
235         CORBA::String_var anEntry = aSObject->GetID().c_str();
236         return FindActorByEntry(anEntry.in());
237       }
238     }
239     return NULL;
240   }
241
242
243   SMESH_Actor* CreateActor(_PTR(Study) theStudy,
244                            const char* theEntry,
245                            int theIsClear)
246   {
247     SMESH_Actor *anActor = NULL;
248     CORBA::Long anId = theStudy->StudyId();
249     if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
250       _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
251       if(aSObj){
252         _PTR(GenericAttribute) anAttr;
253         if(aSObj->FindAttribute(anAttr,"AttributeName")){
254           _PTR(AttributeName) aName = anAttr;
255           std::string aNameVal = aName->Value();
256           anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
257         }
258       }
259     }
260     return anActor;
261   }
262
263
264   void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
265     if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
266       vtkWnd->AddActor(theActor);
267       vtkWnd->Repaint();
268     }
269   }
270
271
272   void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
273     if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
274       vtkWnd->RemoveActor(theActor);
275       if(theActor->hasIO()){
276         Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
277         if(anIO->hasEntry()){
278           std::string anEntry = anIO->getEntry();
279           SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
280           int aStudyId = aStudy->id();
281           TVisualObjCont::key_type aKey(aStudyId,anEntry);
282           VISUAL_OBJ_CONT.erase(aKey);
283         }
284       }
285       theActor->Delete();
286       vtkWnd->Repaint();
287     }
288   }
289
290
291   void FitAll(){
292     if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
293       wnd->onFitAll();
294       wnd->Repaint();
295     }
296   }
297
298   vtkRenderer* GetCurrentRenderer(){
299     if(SVTK_ViewWindow* wnd = GetCurrentVtkView() )
300       return wnd->getRenderer();
301     return NULL;
302   }
303
304   void RepaintCurrentView(){
305     if(SVTK_ViewWindow* wnd = GetCurrentVtkView() )
306       wnd->getRenderer()->Render();
307       //wnd->Repaint();
308   }
309
310   void UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
311   {
312     if(SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd)){
313       vtkRenderer *aRenderer = aViewWnd->getRenderer();
314       vtkActorCollection *aCollection = aRenderer->GetActors();
315       aCollection->InitTraversal();
316       switch(theAction){
317       case eDisplayAll: {
318         while(vtkActor *anAct = aCollection->GetNextActor()){
319           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
320             anActor->SetVisibility(true);
321           }
322         }
323         break;
324       }
325       case eDisplayOnly:
326       case eEraseAll: {
327         while(vtkActor *anAct = aCollection->GetNextActor()){
328           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
329             anActor->SetVisibility(false);
330           }
331         }
332       }
333       default: {
334         if(SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)){
335           switch(theAction) {
336             case eDisplay:
337             case eDisplayOnly:
338               anActor->SetVisibility(true);
339               break;
340             case eErase:
341               anActor->SetVisibility(false);
342               break;
343           }
344         } else {
345           switch(theAction){
346           case eDisplay:
347           case eDisplayOnly:{
348             SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( theWnd->getViewManager()->study() );
349             _PTR(Study) aDocument = aStudy->studyDS();
350             if((anActor = CreateActor(aDocument,theEntry,true))) {
351               DisplayActor(theWnd,anActor);
352               FitAll();
353             }
354             break;
355           }
356           }
357         }
358       }
359       }
360     }
361   }
362
363
364   void UpdateView(EDisplaing theAction, const char* theEntry){
365     SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
366     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
367     SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
368     UpdateView(aWnd,theAction,theEntry);
369   }
370
371   void UpdateView(){
372     if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
373       SalomeApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
374       SALOME_ListIO selected; mgr->selectedObjects( selected );
375
376       if( selected.Extent() == 0){
377         vtkRenderer* aRenderer = aWnd->getRenderer();
378         vtkActorCollection *aCollection = aRenderer->GetActors();
379         aCollection->InitTraversal();
380         while(vtkActor *anAct = aCollection->GetNextActor()){
381           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
382             if(anActor->hasIO())
383               Update(anActor->getIO(),anActor->GetVisibility());
384           }
385         }
386       }else{
387         SALOME_ListIteratorOfListIO anIter( selected );
388         for(; anIter.More(); anIter.Next()){
389           Handle(SALOME_InteractiveObject) anIO = anIter.Value();
390           Update(anIO,true);
391         }
392       }
393       RepaintCurrentView();
394     }
395   }
396
397
398   void Update(const Handle(SALOME_InteractiveObject)& theIO,
399               bool theDisplay)
400   {
401     _PTR(Study) aStudy = GetActiveStudyDocument();
402     CORBA::Long anId = aStudy->StudyId();
403     TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry());
404     if( aVisualObj )
405       aVisualObj->Update();
406     if ( theDisplay )
407       UpdateView(SMESH::eDisplay,theIO->getEntry());
408   }
409
410
411   void UpdateSelectionProp( SMESHGUI* theModule ) {
412     if( !theModule )
413       return;
414
415     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
416     if( !app )
417     {
418       MESSAGE( "UpdateSelectionProp: Application is null" );
419       return;
420     }
421
422     SUIT_ViewManager* vm = app->activeViewManager();
423     if( !vm )
424     {
425       MESSAGE( "UpdateSelectionProp: View manager is null" );
426       return;
427     }
428
429     QPtrVector<SUIT_ViewWindow> views = vm->getViews();
430
431     SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
432     if( !mgr )
433     {
434       MESSAGE( "UpdateSelectionProp: Resource manager is null" );
435       return;
436     }
437
438     QColor aHiColor = mgr->colorValue( "SMESH", "SettingsSelectColor", Qt::white ),
439            aSelColor = mgr->colorValue( "SMESH", "SettingsItemSelectColor", Qt::yellow ),
440            aPreColor = mgr->colorValue( "SMESH", "SettingsPreSelectColor", Qt::cyan );
441
442     int SW = mgr->integerValue( "SMESH", "SettingsItemSelectWidth", 5 ),
443         PW = mgr->integerValue( "SMESH", "SettingsPreSelectWidth", 5 );
444
445     double SP1 = mgr->doubleValue( "SMESH", "SettingsNodeSelectTol", 0.025 ),
446            SP2 = mgr->doubleValue( "SMESH", "SettingsElementsSelectTol", 0.001 );
447
448     for ( int i=0, n=views.count(); i<n; i++ ) {
449         SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] );
450         if (!aVtkView) continue;
451         // update VTK viewer properties
452         SVTK_RenderWindowInteractor* anInteractor = aVtkView->getRWInteractor();
453         if (anInteractor) {
454           // mesh element selection
455           anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255.,
456                                          aSelColor.blue()/255., SW );
457
458           // tolerances
459           anInteractor->SetSelectionTolerance(SP1, SP2);
460
461           // pre-selection
462           SVTK_InteractorStyle* aStyle =
463             dynamic_cast<SVTK_InteractorStyle*>( anInteractor->GetInteractorStyle() );
464           if (aStyle) {
465             aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255.,
466                                         aPreColor.blue()/255., PW);
467           }
468         }
469         // update actors
470         vtkRenderer* aRenderer = aVtkView->getRenderer();
471         vtkActorCollection *aCollection = aRenderer->GetActors();
472         aCollection->InitTraversal();
473         while(vtkActor *anAct = aCollection->GetNextActor()){
474           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
475             anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255.,
476                                        aHiColor.blue()/255.);
477             anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255.,
478                                           aPreColor.blue()/255.);
479           }
480         }
481     }
482   }
483
484
485   //----------------------------------------------------------------------------
486   SVTK_InteractorStyle* GetInteractorStyle(SUIT_ViewWindow *theWindow){
487     if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow)){
488       if(SVTK_RenderWindowInteractor* anInteractor = aWnd->getRWInteractor()){
489         return dynamic_cast<SVTK_InteractorStyle*>( anInteractor->GetInteractorStyle() );
490       }
491     }
492     return NULL;
493   }
494
495   void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
496                  SVTK_InteractorStyle* theStyle)
497   {
498     theStyle->SetFilter(theFilter);
499   }
500
501   Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_InteractorStyle* theStyle)
502   {
503     return theStyle->GetFilter(theId);
504   }
505
506   bool IsFilterPresent(int theId, SVTK_InteractorStyle* theStyle)
507   {
508     return theStyle->IsFilterPresent(theId);
509   }
510
511   void RemoveFilter(int theId, SVTK_InteractorStyle* theStyle)
512   {
513     theStyle->RemoveFilter(theId);
514   }
515
516   void RemoveFilters(SVTK_InteractorStyle* theStyle)
517   {
518     for ( int id = SMESHGUI_NodeFilter; theStyle && id < SMESHGUI_LastFilter; id++ )
519       theStyle->RemoveFilter( id );
520   }
521
522   bool IsValid(SALOME_Actor* theActor, int theCellId,
523                SVTK_InteractorStyle* theStyle)
524   {
525     return theStyle->IsValid(theActor,theCellId);
526   }
527
528
529   //----------------------------------------------------------------------------
530   void SetPointRepresentation(bool theIsVisible){
531     if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
532       vtkRenderer *aRenderer = aViewWindow->getRenderer();
533       vtkActorCollection *aCollection = aRenderer->GetActors();
534       aCollection->InitTraversal();
535       while(vtkActor *anAct = aCollection->GetNextActor()){
536         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
537           if(anActor->GetVisibility()){
538             anActor->SetPointRepresentation(theIsVisible);
539           }
540         }
541       }
542       RepaintCurrentView();
543     }
544   }
545
546
547   void SetPickable(SMESH_Actor* theActor){
548     if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
549       int anIsAllPickable = (theActor == NULL);
550       vtkRenderer *aRenderer = aWnd->getRenderer();
551       vtkActorCollection *aCollection = aRenderer->GetActors();
552       aCollection->InitTraversal();
553       while(vtkActor *anAct = aCollection->GetNextActor()){
554         if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
555           if(anActor->GetVisibility()){
556             anActor->SetPickable(anIsAllPickable);
557           }
558         }
559       }
560       if(theActor)
561         theActor->SetPickable(!anIsAllPickable);
562       RepaintCurrentView();
563     }
564   }
565
566
567   //----------------------------------------------------------------------------
568   int GetNameOfSelectedNodes(SVTK_Selector* theSelector, 
569                              const Handle(SALOME_InteractiveObject)& theIO, 
570                              QString& theName)
571   {
572     theName = "";
573     TColStd_IndexedMapOfInteger aMapIndex;
574     theSelector->GetIndex(theIO,aMapIndex);
575
576     for(int i = 1; i <= aMapIndex.Extent(); i++)
577       theName += QString(" %1").arg(aMapIndex(i));
578
579     return aMapIndex.Extent();
580   }
581
582   int GetNameOfSelectedElements(SVTK_Selector* theSelector, 
583                                 const Handle(SALOME_InteractiveObject)& theIO, 
584                                 QString& theName)
585   {
586     theName = "";
587     TColStd_IndexedMapOfInteger aMapIndex;
588     theSelector->GetIndex(theIO,aMapIndex);
589
590     typedef std::set<int> TIdContainer;
591     TIdContainer anIdContainer;
592     for( int i = 1; i <= aMapIndex.Extent(); i++)
593       anIdContainer.insert(aMapIndex(i));
594
595     TIdContainer::const_iterator anIter = anIdContainer.begin();
596     for(; anIter != anIdContainer.end(); anIter++)
597       theName += QString(" %1").arg(*anIter);
598
599     return aMapIndex.Extent();
600   }
601
602
603   int GetEdgeNodes(SVTK_Selector* theSelector, 
604                    const TVisualObjPtr& theVisualObject,
605                    int& theId1, 
606                    int& theId2)
607   {
608     const SALOME_ListIO& selected = theSelector->StoredIObjects(); 
609
610     if ( selected.Extent() != 1 )
611       return -1;
612
613     Handle(SALOME_InteractiveObject) anIO = selected.First();
614     if ( anIO.IsNull() || !anIO->hasEntry() )
615       return -1;
616
617     TColStd_IndexedMapOfInteger aMapIndex;
618     theSelector->GetIndex( anIO, aMapIndex );
619     if ( aMapIndex.Extent() != 2 )
620       return -1;
621
622     int anObjId = -1, anEdgeNum = -1;
623     for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
624       int aVal = aMapIndex( i );
625       if ( aVal > 0 )
626         anObjId = aVal;
627       else
628         anEdgeNum = abs( aVal ) - 1;
629     }
630
631     if ( anObjId == -1 || anEdgeNum == -1 )
632       return -1;
633
634     return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
635   }
636
637   //----------------------------------------------------------------------------
638   int GetNameOfSelectedNodes(SalomeApp_SelectionMgr *theMgr,
639                              const Handle(SALOME_InteractiveObject)& theIO,
640                              QString& theName)
641   {
642     theName = "";
643     if(theIO->hasEntry()){
644       if(FindActorByEntry(theIO->getEntry())){
645         TColStd_IndexedMapOfInteger aMapIndex;
646         theMgr->GetIndexes(theIO,aMapIndex);
647         for(int i = 1; i <= aMapIndex.Extent(); i++){
648           theName += QString(" %1").arg(aMapIndex(i));
649         }
650         return aMapIndex.Extent();
651       }
652     }
653     return -1;
654   }
655
656   int GetNameOfSelectedNodes(SalomeApp_SelectionMgr *theMgr, QString& theName){
657     theName = "";
658     SALOME_ListIO selected; theMgr->selectedObjects( selected );
659     if(selected.Extent() == 1){
660       Handle(SALOME_InteractiveObject) anIO = selected.First();
661       return GetNameOfSelectedNodes(theMgr,anIO,theName);
662     }
663     return -1;
664   }
665   
666
667   int GetNameOfSelectedElements(SalomeApp_SelectionMgr *theMgr,
668                                 const Handle(SALOME_InteractiveObject)& theIO,
669                                 QString& theName)
670   {
671     theName = "";
672     if(theIO->hasEntry()){
673       if(FindActorByEntry(theIO->getEntry())){
674         TColStd_IndexedMapOfInteger aMapIndex;
675         theMgr->GetIndexes(theIO,aMapIndex);
676         typedef set<int> TIdContainer;
677         TIdContainer anIdContainer;
678         for( int i = 1; i <= aMapIndex.Extent(); i++)
679           anIdContainer.insert(aMapIndex(i));
680         TIdContainer::const_iterator anIter = anIdContainer.begin();
681         for(; anIter != anIdContainer.end(); anIter++){
682           theName += QString(" %1").arg(*anIter);
683         }
684         return aMapIndex.Extent();
685       }
686     }
687     return -1;
688   }
689
690
691   int GetNameOfSelectedElements(SalomeApp_SelectionMgr *theMgr, QString& theName)
692   {
693     theName = "";
694     SALOME_ListIO selected; theMgr->selectedObjects( selected );
695
696     if( selected.Extent() == 1){
697       Handle(SALOME_InteractiveObject) anIO = selected.First();
698       return GetNameOfSelectedElements(theMgr,anIO,theName);
699     }
700     return -1;
701   }
702
703   int GetSelected(SalomeApp_SelectionMgr*      theMgr,
704                   TColStd_IndexedMapOfInteger& theMap,
705                   const bool                   theIsElement)
706   {
707     theMap.Clear();
708     SALOME_ListIO selected; theMgr->selectedObjects( selected );
709
710     if ( selected.Extent() == 1 )
711     {
712       Handle(SALOME_InteractiveObject) anIO = selected.First();
713       if ( anIO->hasEntry() ) {
714         theMgr->GetIndexes( anIO, theMap );
715       }
716     }
717     return theMap.Extent();
718   }
719
720
721   int GetEdgeNodes( SalomeApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
722   {
723     SALOME_ListIO selected; theMgr->selectedObjects( selected );
724
725     if ( selected.Extent() != 1 )
726       return -1;
727
728     Handle(SALOME_InteractiveObject) anIO = selected.First();
729     if ( anIO.IsNull() || !anIO->hasEntry() )
730       return -1;
731
732     SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
733     if ( anActor == 0 )
734       return -1;
735
736     TColStd_IndexedMapOfInteger aMapIndex;
737     theMgr->GetIndexes( anIO, aMapIndex );
738     if ( aMapIndex.Extent() != 2 )
739       return -1;
740
741     int anObjId = -1, anEdgeNum = -1;
742     for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
743       int aVal = aMapIndex( i );
744       if ( aVal > 0 )
745         anObjId = aVal;
746       else
747         anEdgeNum = abs( aVal );
748     }
749
750     if ( anObjId == -1 || anEdgeNum == -1 )
751       return -1;
752
753     return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
754   }
755
756   void SetControlsPrecision( const long theVal )
757   {
758     if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
759     {
760       vtkRenderer *aRenderer = aWnd->getRenderer();
761       vtkActorCollection *aCollection = aRenderer->GetActors();
762       aCollection->InitTraversal();
763       
764       while ( vtkActor *anAct = aCollection->GetNextActor())
765       {
766         if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
767         {
768           anActor->SetControlsPrecision( theVal );
769           anActor->SetControlMode( anActor->GetControlMode() );
770         }
771       }
772
773     }
774   }
775 }