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