Salome HOME
c2d3deeaa3649fc20125724ea7c178d02f720899
[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
24 #include <vtkRenderer.h>
25 #include <vtkActorCollection.h>
26
27 #include <TColStd_IndexedMapOfInteger.hxx>
28
29 #include "QAD_Config.h"
30 #include "QAD_Desktop.h"
31 #include "QAD_Study.h"
32 #include "QAD_Settings.h"
33 #include "QAD_RightFrame.h"
34
35 #include "SALOME_Selection.h"
36 #include "SALOME_ListIteratorOfListIO.hxx"
37
38 #include "VTKViewer_ViewFrame.h"
39 #include "VTKViewer_RenderWindow.h"
40 #include "VTKViewer_InteractorStyleSALOME.h"
41 #include "VTKViewer_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 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
51
52 #include "SMESH_Actor.h"
53 #include "SMESH_ObjectDef.h"
54
55 using namespace std;
56
57 namespace SMESH{
58
59   typedef map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
60   static TVisualObjCont VISUAL_OBJ_CONT;
61
62   TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
63     TVisualObjPtr aVisualObj;
64     try{
65       TVisualObjCont::key_type aKey(theStudyId,theEntry);
66       TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
67       if(anIter != VISUAL_OBJ_CONT.end()){
68         aVisualObj = anIter->second;
69       }else{
70         SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
71         SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theEntry);
72         if(!CORBA::is_nil(aSObj)){
73           SALOMEDS::GenericAttribute_var anAttr;
74           if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
75             SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
76             CORBA::String_var aVal = anIOR->Value();
77             CORBA::Object_var anObj = aStudy->ConvertIORToObject(aVal.in());
78             if(!CORBA::is_nil(anObj)){
79               //Try narrow to SMESH_Mesh interafce
80               SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
81               if(!aMesh->_is_nil()){
82                 aVisualObj.reset(new SMESH_MeshObj(aMesh));
83                 aVisualObj->Update();
84                 TVisualObjCont::value_type aValue(aKey,aVisualObj); 
85                 VISUAL_OBJ_CONT.insert(aValue);
86                 return aVisualObj;
87               }
88               //Try narrow to SMESH_Group interafce
89               SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
90               if(!aGroup->_is_nil()){
91                 SALOMEDS::SObject_var aFatherSObj = aSObj->GetFather();
92                 if(aFatherSObj->_is_nil()) return aVisualObj;
93                 aFatherSObj = aFatherSObj->GetFather();
94                 if(aFatherSObj->_is_nil()) return aVisualObj;
95                 CORBA::String_var anEntry = aFatherSObj->GetID();
96                 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
97                 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
98                   aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
99                   aVisualObj->Update();
100                   TVisualObjCont::value_type aValue(aKey,aVisualObj); 
101                   VISUAL_OBJ_CONT.insert(aValue);
102                   return aVisualObj;
103                 }
104               }
105               //Try narrow to SMESH_subMesh interafce
106               SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
107               if(!aSubMesh->_is_nil()){
108                 SALOMEDS::SObject_var aFatherSObj = aSObj->GetFather();
109                 if(aFatherSObj->_is_nil()) return aVisualObj;
110                 aFatherSObj = aFatherSObj->GetFather();
111                 if(aFatherSObj->_is_nil()) return aVisualObj;
112                 CORBA::String_var anEntry = aFatherSObj->GetID();
113                 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
114                 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
115                   aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
116                   aVisualObj->Update();
117                   TVisualObjCont::value_type aValue(aKey,aVisualObj); 
118                   VISUAL_OBJ_CONT.insert(aValue);
119                   return aVisualObj;
120                 }
121               }
122             }
123           }
124         }
125       }
126     }catch(...){
127       INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
128     }
129     return aVisualObj;
130   }
131
132
133   VTKViewer_ViewFrame* FindVtkViewFrame(QAD_Study* theStudy,
134                                         QAD_StudyFrame* theStudyFrame)
135   {
136     QList<QAD_Study>& aStudies = 
137       QAD_Application::getDesktop()->getActiveApp()->getStudies();
138     if(aStudies.containsRef(theStudy)){
139       const QList<QAD_StudyFrame>& aStudyFrames = theStudy->getStudyFrames();
140       if(aStudyFrames.containsRef(theStudyFrame)){
141         return GetVtkViewFrame(theStudyFrame);
142       }
143     }
144     return NULL;
145   }
146
147
148   VTKViewer_ViewFrame* GetVtkViewFrame(QAD_StudyFrame* theStudyFrame){
149     QAD_ViewFrame* aViewFrame = theStudyFrame->getRightFrame()->getViewFrame();
150     return dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
151   }
152
153
154   VTKViewer_ViewFrame* GetCurrentVtkView(){
155     return GetVtkViewFrame(GetActiveStudy()->getActiveStudyFrame());
156   }
157
158
159   SMESH_Actor* FindActorByEntry(QAD_StudyFrame *theStudyFrame, 
160                                 const char* theEntry)
161   {
162     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
163       vtkRenderer *aRenderer = aViewFrame->getRenderer();
164       vtkActorCollection *aCollection = aRenderer->GetActors();
165       aCollection->InitTraversal();
166       while(vtkActor *anAct = aCollection->GetNextActor()){
167         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
168           if(anActor->hasIO()){
169             Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
170             if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
171               return anActor;
172             }
173           }
174         }
175       }
176     }
177     return NULL;
178   }
179   
180   
181   SMESH_Actor* FindActorByEntry(const char* theEntry){
182     return FindActorByEntry(GetActiveStudy()->getActiveStudyFrame(),theEntry);
183   }
184   
185   
186   SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
187     if(!CORBA::is_nil(theObject)){
188       SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
189       CORBA::String_var anIOR = aStudy->ConvertObjectToIOR(theObject);
190       SALOMEDS::SObject_var aSObject = aStudy->FindObjectIOR(anIOR.in());
191       if(!aSObject->_is_nil()){
192         CORBA::String_var anEntry = aSObject->GetID();
193         return FindActorByEntry(anEntry.in());
194       }
195     }
196     return NULL;
197   }
198
199
200   SMESH_Actor* CreateActor(SALOMEDS::Study_ptr theStudy,
201                            const char* theEntry,
202                            int theIsClear)
203   {
204     SMESH_Actor *anActor = NULL;
205     CORBA::Long anId = theStudy->StudyId();
206     if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
207       SALOMEDS::SObject_var aSObj = theStudy->FindObjectID(theEntry);
208       if(!aSObj->_is_nil()){
209         SALOMEDS::GenericAttribute_var anAttr;
210         if(aSObj->FindAttribute(anAttr,"AttributeName")){
211           SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
212           CORBA::String_var aVal = aName->Value();
213           string aNameVal = aVal.in();
214           anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
215         }
216       }
217     }
218     return anActor;
219   }
220
221
222   void DisplayActor(QAD_StudyFrame *theStudyFrame, SMESH_Actor* theActor){
223     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
224       aViewFrame->AddActor(theActor);
225       aViewFrame->Repaint();
226     }
227   }
228
229
230   void RemoveActor(QAD_StudyFrame *theStudyFrame, SMESH_Actor* theActor){
231     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
232       aViewFrame->RemoveActor(theActor);
233       aViewFrame->Repaint();
234     }
235   }
236   
237
238   void FitAll(){
239     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(GetActiveStudy()->getActiveStudyFrame())){
240       aViewFrame->onViewFitAll();
241       aViewFrame->Repaint();
242     }
243   }
244   
245   vtkRenderer* GetCurrentRenderer(){
246     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(GetActiveStudy()->getActiveStudyFrame()))
247       return aViewFrame->getRenderer();
248     return NULL;
249   }
250
251   void RepaintCurrentView(){
252     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(GetActiveStudy()->getActiveStudyFrame())){
253       aViewFrame->getRW()->getRenderWindow()->Render();
254       //aViewFrame->Repaint();
255     }
256   }
257   
258   
259   void UpdateView(QAD_StudyFrame *theStudyFrame, EDisplaing theAction, const char* theEntry)
260   {
261     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
262       vtkRenderer *aRenderer = aViewFrame->getRenderer();
263       vtkActorCollection *aCollection = aRenderer->GetActors();
264       aCollection->InitTraversal();
265       switch(theAction){
266       case eDisplayAll: {
267         while(vtkActor *anAct = aCollection->GetNextActor()){
268           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
269             anActor->SetVisibility(true);
270           }
271         }
272         break;
273       }
274       case eDisplayOnly:
275       case eEraseAll: {
276         while(vtkActor *anAct = aCollection->GetNextActor()){
277           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
278             anActor->SetVisibility(false);
279           }
280         }
281       }
282       default: {
283         if(SMESH_Actor *anActor = FindActorByEntry(theStudyFrame,theEntry)){
284           switch(theAction) {
285             case eDisplay:
286             case eDisplayOnly:
287               anActor->SetVisibility(true);
288               break;
289             case eErase:
290               anActor->SetVisibility(false);
291               break;
292           }
293         } else {
294           switch(theAction){
295           case eDisplay:
296           case eDisplayOnly:{
297             QAD_Study* aStudy = theStudyFrame->getStudy();
298             SALOMEDS::Study_var aDocument = aStudy->getStudyDocument();
299             if((anActor = CreateActor(aDocument,theEntry,true))) {
300               DisplayActor(theStudyFrame,anActor);
301               FitAll();
302             }
303             break;
304           }
305           }
306         }
307       }
308       }
309     }
310   }
311
312
313   void UpdateView(EDisplaing theAction, const char* theEntry){
314     QAD_Study* aStudy = GetActiveStudy();
315     QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
316     UpdateView(aStudyFrame,theAction,theEntry);
317   }
318   
319   void UpdateView(){
320     if(VTKViewer_ViewFrame* aViewFrame = SMESH::GetCurrentVtkView()){
321       SALOME_Selection *aSel = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
322       if(aSel->IObjectCount() == 0){
323         vtkRenderer* aRenderer = aViewFrame->getRenderer();
324         vtkActorCollection *aCollection = aRenderer->GetActors();
325         aCollection->InitTraversal();
326         while(vtkActor *anAct = aCollection->GetNextActor()){
327           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
328             if(anActor->hasIO())
329               Update(anActor->getIO(),anActor->GetVisibility());
330           }
331         }
332       }else{
333         SALOME_ListIteratorOfListIO anIter(aSel->StoredIObjects());
334         for(; anIter.More(); anIter.Next()){
335           Handle(SALOME_InteractiveObject) anIO = anIter.Value();
336           Update(anIO,true);
337         }
338       }
339       RepaintCurrentView();
340     }
341   }
342
343
344   void Update(const Handle(SALOME_InteractiveObject)& theIO,
345               bool theDisplay)
346   {
347     SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
348     CORBA::Long anId = aStudy->StudyId();
349     TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry());
350     aVisualObj->Update();
351     if ( theDisplay )
352       UpdateView(SMESH::eDisplay,theIO->getEntry());
353   }
354
355
356   void UpdateSelectionProp() {
357     QAD_Study* aStudy = GetActiveStudy();
358     QList<QAD_StudyFrame> aFrameList = aStudy->getStudyFrames();
359     
360     QString SCr, SCg, SCb;
361     SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
362     SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
363     SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
364     QColor aHiColor = Qt::white;
365     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
366       aHiColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
367     
368     SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
369     SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
370     SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
371     QColor aSelColor = Qt::yellow;
372     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
373       aSelColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
374     QString SW = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
375     if (SW.isEmpty()) SW = "5";
376     
377     SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
378     SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
379     SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
380     QColor aPreColor = Qt::cyan;
381     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
382       aPreColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
383     QString PW = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
384     if (PW.isEmpty()) PW = "5";
385     
386     QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
387     if (SP1.isEmpty()) SP1 = "0.025";
388     QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
389     if (SP2.isEmpty()) SP2 = "0.001";
390     
391     for (QAD_StudyFrame* aStudyFrame = aFrameList.first(); aStudyFrame; aStudyFrame = aFrameList.next()) {
392       if (aStudyFrame->getTypeView() == VIEW_VTK) {
393         VTKViewer_ViewFrame* aVtkViewFrame = GetVtkViewFrame(aStudyFrame);
394         if (!aVtkViewFrame) continue;
395         // update VTK viewer properties
396         VTKViewer_RenderWindowInteractor* anInteractor = aVtkViewFrame->getRWInteractor();
397         if (anInteractor) {
398           // mesh element selection
399           anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255., 
400                                          aSelColor.blue()/255., SW.toInt());
401           
402           // tolerances
403           anInteractor->SetSelectionTolerance(SP1.toDouble(), SP2.toDouble());
404           
405           // pre-selection
406           VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
407           if (aStyle) {
408             aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255., 
409                                         aPreColor.blue()/255., PW.toInt());
410           }
411         }
412         // update actors
413         vtkRenderer* aRenderer = aVtkViewFrame->getRenderer();
414         vtkActorCollection *aCollection = aRenderer->GetActors();
415         aCollection->InitTraversal();
416         while(vtkActor *anAct = aCollection->GetNextActor()){
417           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
418             anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255., 
419                                        aHiColor.blue()/255.);
420             anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255., 
421                                           aPreColor.blue()/255.);
422           }
423         }
424       }
425     }
426   }
427
428   
429   //----------------------------------------------------------------------------
430   VTKViewer_InteractorStyleSALOME* GetInteractorStyle(QAD_StudyFrame *theStudyFrame){
431     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
432       if(VTKViewer_RenderWindowInteractor* anInteractor = aViewFrame->getRWInteractor()){
433         return anInteractor->GetInteractorStyleSALOME();
434       }
435     }
436     return NULL;
437   }
438
439   void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
440                  VTKViewer_InteractorStyleSALOME* theStyle)
441   {
442     theStyle->SetFilter(theFilter);
443   }
444
445   Handle(VTKViewer_Filter) GetFilter(int theId, VTKViewer_InteractorStyleSALOME* theStyle)
446   {
447     return theStyle->GetFilter(theId);
448   }
449
450   bool IsFilterPresent(int theId, VTKViewer_InteractorStyleSALOME* theStyle)
451   {
452     return theStyle->IsFilterPresent(theId);
453   }
454
455   void RemoveFilter(int theId, VTKViewer_InteractorStyleSALOME* theStyle){
456     theStyle->RemoveFilter(theId);
457   }
458
459   bool IsValid(SALOME_Actor* theActor, int theCellId,
460                VTKViewer_InteractorStyleSALOME* theStyle)
461   {
462     return theStyle->IsValid(theActor,theCellId);
463   }
464
465
466   //----------------------------------------------------------------------------
467   void SetPointRepresentation(bool theIsVisible){
468     if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
469       vtkRenderer *aRenderer = aViewFrame->getRenderer();
470       vtkActorCollection *aCollection = aRenderer->GetActors();
471       aCollection->InitTraversal();
472       while(vtkActor *anAct = aCollection->GetNextActor()){
473         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
474           if(anActor->GetVisibility()){
475             anActor->SetPointRepresentation(theIsVisible);
476           }
477         }
478       }
479       RepaintCurrentView();
480     }
481   }
482
483
484   void SetPickable(SMESH_Actor* theActor){
485     if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
486       int anIsAllPickable = (theActor == NULL);
487       vtkRenderer *aRenderer = aViewFrame->getRenderer();
488       vtkActorCollection *aCollection = aRenderer->GetActors();
489       aCollection->InitTraversal();
490       while(vtkActor *anAct = aCollection->GetNextActor()){
491         if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
492           if(anActor->GetVisibility()){
493             anActor->SetPickable(anIsAllPickable);
494           }
495         }
496       }
497       if(theActor)
498         theActor->SetPickable(!anIsAllPickable);
499       RepaintCurrentView();
500     }
501   }
502
503
504   int GetNameOfSelectedNodes(SALOME_Selection *theSel, 
505                              const Handle(SALOME_InteractiveObject)& theIO, 
506                              QString& theName)
507   {
508     theName = "";
509     if(theIO->hasEntry()){
510       if(SMESH_Actor *anActor = FindActorByEntry(theIO->getEntry())){
511         TColStd_IndexedMapOfInteger aMapIndex;
512         theSel->GetIndex(theIO,aMapIndex);
513         for(int i = 1; i <= aMapIndex.Extent(); i++){
514           theName += QString(" %1").arg(aMapIndex(i));
515         }
516         return aMapIndex.Extent();
517       }
518     }
519     return -1;
520   }
521   
522
523   int GetNameOfSelectedNodes(SALOME_Selection *theSel, QString& theName){
524     theName = "";
525     if(theSel->IObjectCount() == 1){
526       Handle(SALOME_InteractiveObject) anIO = theSel->firstIObject();
527       return GetNameOfSelectedNodes(theSel,anIO,theName);
528     }
529     return -1;
530   }
531   
532
533   int GetNameOfSelectedElements(SALOME_Selection *theSel, 
534                                 const Handle(SALOME_InteractiveObject)& theIO, 
535                                 QString& theName)
536   {
537     theName = "";
538     if(theIO->hasEntry()){
539       if(SMESH_Actor *anActor = FindActorByEntry(theIO->getEntry())){
540         TColStd_IndexedMapOfInteger aMapIndex;
541         theSel->GetIndex(theIO,aMapIndex);
542         typedef std::set<int> TIdContainer;
543         TIdContainer anIdContainer;
544         for( int i = 1; i <= aMapIndex.Extent(); i++)
545           anIdContainer.insert(aMapIndex(i));
546         TIdContainer::const_iterator anIter = anIdContainer.begin();
547         for(; anIter != anIdContainer.end(); anIter++){
548           theName += QString(" %1").arg(*anIter);
549         }
550         return aMapIndex.Extent();
551       }
552     }
553     return -1;
554   }
555
556
557   int GetNameOfSelectedElements(SALOME_Selection *theSel, QString& theName)
558   {
559     theName = "";
560     if(theSel->IObjectCount() == 1){
561       Handle(SALOME_InteractiveObject) anIO = theSel->firstIObject();
562       return GetNameOfSelectedElements(theSel,anIO,theName);
563     }
564     return -1;
565   }
566
567   
568   int GetSelected(SALOME_Selection*            theSel, 
569                   TColStd_IndexedMapOfInteger& theMap, 
570                   const bool                   theIsElement)
571   {
572     theMap.Clear();
573
574     if ( theSel->IObjectCount() == 1 )
575     {
576       Handle(SALOME_InteractiveObject) anIO = theSel->firstIObject();
577       if ( anIO->hasEntry() ) {
578         theSel->GetIndex( anIO, theMap );
579       }
580     }
581     return theMap.Extent();
582   }
583
584
585   int GetEdgeNodes( SALOME_Selection* theSel, int& theId1, int& theId2 )
586   {
587     if ( theSel->IObjectCount() != 1 )
588       return -1;
589
590     Handle(SALOME_InteractiveObject) anIO = theSel->firstIObject();
591     if ( anIO.IsNull() || !anIO->hasEntry() )
592       return -1;
593
594     SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
595     if ( anActor == 0 )
596       return -1;
597
598     TColStd_IndexedMapOfInteger aMapIndex;
599     theSel->GetIndex( anIO, aMapIndex );
600     if ( aMapIndex.Extent() != 2 )
601       return -1;
602     
603     int anObjId = -1, anEdgeNum = -1;
604     for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
605       int aVal = aMapIndex( i );
606       if ( aVal > 0 )
607         anObjId = aVal;
608       else
609         anEdgeNum = abs( aVal );
610     }
611     
612     if ( anObjId == -1 || anEdgeNum == -1 )
613       return -1;
614     
615     return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
616   }
617   
618   void SetControlsPrecision( const long theVal )
619   {
620     if( VTKViewer_ViewFrame* aViewFrame = SMESH::GetCurrentVtkView() )
621     {
622       vtkRenderer *aRenderer = aViewFrame->getRenderer();
623       vtkActorCollection *aCollection = aRenderer->GetActors();
624       aCollection->InitTraversal();
625       
626       while ( vtkActor *anAct = aCollection->GetNextActor())
627       {
628         if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
629         {
630           anActor->SetControlsPrecision( theVal );
631           anActor->SetControlMode( anActor->GetControlMode() );
632         }
633       }
634
635     }
636   }
637 }
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654