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