Salome HOME
1. Implementation of new pattern mapping algorthm (mesh refinement)
[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   void RepaintViewFrame(VTKViewer_ViewFrame* theFrame)
160   {
161     theFrame->Repaint();
162   }
163
164
165   void RenderViewFrame(VTKViewer_ViewFrame* theFrame)
166   {
167     theFrame->getRW()->getRenderWindow()->Render();
168     theFrame->Repaint();
169   }
170
171
172   SMESH_Actor* FindActorByEntry(QAD_StudyFrame *theStudyFrame, 
173                                 const char* theEntry)
174   {
175     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
176       vtkRenderer *aRenderer = aViewFrame->getRenderer();
177       vtkActorCollection *aCollection = aRenderer->GetActors();
178       aCollection->InitTraversal();
179       while(vtkActor *anAct = aCollection->GetNextActor()){
180         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
181           if(anActor->hasIO()){
182             Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
183             if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
184               return anActor;
185             }
186           }
187         }
188       }
189     }
190     return NULL;
191   }
192   
193   
194   SMESH_Actor* FindActorByEntry(const char* theEntry){
195     return FindActorByEntry(GetActiveStudy()->getActiveStudyFrame(),theEntry);
196   }
197   
198   
199   SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
200     if(!CORBA::is_nil(theObject)){
201       SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
202       CORBA::String_var anIOR = aStudy->ConvertObjectToIOR(theObject);
203       SALOMEDS::SObject_var aSObject = aStudy->FindObjectIOR(anIOR.in());
204       if(!aSObject->_is_nil()){
205         CORBA::String_var anEntry = aSObject->GetID();
206         return FindActorByEntry(anEntry.in());
207       }
208     }
209     return NULL;
210   }
211
212
213   SMESH_Actor* CreateActor(SALOMEDS::Study_ptr theStudy,
214                            const char* theEntry,
215                            int theIsClear)
216   {
217     SMESH_Actor *anActor = NULL;
218     CORBA::Long anId = theStudy->StudyId();
219     if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
220       SALOMEDS::SObject_var aSObj = theStudy->FindObjectID(theEntry);
221       if(!aSObj->_is_nil()){
222         SALOMEDS::GenericAttribute_var anAttr;
223         if(aSObj->FindAttribute(anAttr,"AttributeName")){
224           SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
225           CORBA::String_var aVal = aName->Value();
226           string aNameVal = aVal.in();
227           anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
228         }
229       }
230     }
231     return anActor;
232   }
233
234
235   void DisplayActor(QAD_StudyFrame *theStudyFrame, SMESH_Actor* theActor){
236     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
237       aViewFrame->AddActor(theActor);
238       aViewFrame->Repaint();
239     }
240   }
241
242
243   void RemoveActor(QAD_StudyFrame *theStudyFrame, SMESH_Actor* theActor){
244     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
245       aViewFrame->RemoveActor(theActor);
246       aViewFrame->Repaint();
247     }
248   }
249   
250
251   void FitAll(){
252     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(GetActiveStudy()->getActiveStudyFrame())){
253       aViewFrame->onViewFitAll();
254       aViewFrame->Repaint();
255     }
256   }
257   
258   vtkRenderer* GetCurrentRenderer(){
259     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(GetActiveStudy()->getActiveStudyFrame()))
260       return aViewFrame->getRenderer();
261     return NULL;
262   }
263
264   void RepaintCurrentView(){
265     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(GetActiveStudy()->getActiveStudyFrame())){
266       aViewFrame->getRW()->getRenderWindow()->Render();
267       //aViewFrame->Repaint();
268     }
269   }
270   
271   
272   void UpdateView(QAD_StudyFrame *theStudyFrame, EDisplaing theAction, const char* theEntry)
273   {
274     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
275       vtkRenderer *aRenderer = aViewFrame->getRenderer();
276       vtkActorCollection *aCollection = aRenderer->GetActors();
277       aCollection->InitTraversal();
278       switch(theAction){
279       case eDisplayAll: {
280         while(vtkActor *anAct = aCollection->GetNextActor()){
281           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
282             anActor->SetVisibility(true);
283           }
284         }
285         break;
286       }
287       case eDisplayOnly:
288       case eEraseAll: {
289         while(vtkActor *anAct = aCollection->GetNextActor()){
290           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
291             anActor->SetVisibility(false);
292           }
293         }
294       }
295       default: {
296         if(SMESH_Actor *anActor = FindActorByEntry(theStudyFrame,theEntry)){
297           switch(theAction) {
298             case eDisplay:
299             case eDisplayOnly:
300               anActor->SetVisibility(true);
301               break;
302             case eErase:
303               anActor->SetVisibility(false);
304               break;
305           }
306         } else {
307           switch(theAction){
308           case eDisplay:
309           case eDisplayOnly:{
310             QAD_Study* aStudy = theStudyFrame->getStudy();
311             SALOMEDS::Study_var aDocument = aStudy->getStudyDocument();
312             if((anActor = CreateActor(aDocument,theEntry,true))) {
313               DisplayActor(theStudyFrame,anActor);
314               FitAll();
315             }
316             break;
317           }
318           }
319         }
320       }
321       }
322     }
323   }
324
325
326   void UpdateView(EDisplaing theAction, const char* theEntry){
327     QAD_Study* aStudy = GetActiveStudy();
328     QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
329     UpdateView(aStudyFrame,theAction,theEntry);
330   }
331   
332   void UpdateView(){
333     if(VTKViewer_ViewFrame* aViewFrame = SMESH::GetCurrentVtkView()){
334       SALOME_Selection *aSel = SALOME_Selection::Selection(GetActiveStudy()->getSelection());
335       if(aSel->IObjectCount() == 0){
336         vtkRenderer* aRenderer = aViewFrame->getRenderer();
337         vtkActorCollection *aCollection = aRenderer->GetActors();
338         aCollection->InitTraversal();
339         while(vtkActor *anAct = aCollection->GetNextActor()){
340           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
341             if(anActor->hasIO())
342               Update(anActor->getIO(),anActor->GetVisibility());
343           }
344         }
345       }else{
346         SALOME_ListIteratorOfListIO anIter(aSel->StoredIObjects());
347         for(; anIter.More(); anIter.Next()){
348           Handle(SALOME_InteractiveObject) anIO = anIter.Value();
349           Update(anIO,true);
350         }
351       }
352       RepaintCurrentView();
353     }
354   }
355
356
357   void Update(const Handle(SALOME_InteractiveObject)& theIO,
358               bool theDisplay)
359   {
360     SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
361     CORBA::Long anId = aStudy->StudyId();
362     TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry());
363     aVisualObj->Update();
364     if ( theDisplay )
365       UpdateView(SMESH::eDisplay,theIO->getEntry());
366   }
367
368
369   void UpdateSelectionProp() {
370     QAD_Study* aStudy = GetActiveStudy();
371     QList<QAD_StudyFrame> aFrameList = aStudy->getStudyFrames();
372     
373     QString SCr, SCg, SCb;
374     SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
375     SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
376     SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
377     QColor aHiColor = Qt::white;
378     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
379       aHiColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
380     
381     SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
382     SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
383     SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
384     QColor aSelColor = Qt::yellow;
385     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
386       aSelColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
387     QString SW = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
388     if (SW.isEmpty()) SW = "5";
389     
390     SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
391     SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
392     SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
393     QColor aPreColor = Qt::cyan;
394     if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
395       aPreColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
396     QString PW = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
397     if (PW.isEmpty()) PW = "5";
398     
399     QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
400     if (SP1.isEmpty()) SP1 = "0.025";
401     QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
402     if (SP2.isEmpty()) SP2 = "0.001";
403     
404     for (QAD_StudyFrame* aStudyFrame = aFrameList.first(); aStudyFrame; aStudyFrame = aFrameList.next()) {
405       if (aStudyFrame->getTypeView() == VIEW_VTK) {
406         VTKViewer_ViewFrame* aVtkViewFrame = GetVtkViewFrame(aStudyFrame);
407         if (!aVtkViewFrame) continue;
408         // update VTK viewer properties
409         VTKViewer_RenderWindowInteractor* anInteractor = aVtkViewFrame->getRWInteractor();
410         if (anInteractor) {
411           // mesh element selection
412           anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255., 
413                                          aSelColor.blue()/255., SW.toInt());
414           
415           // tolerances
416           anInteractor->SetSelectionTolerance(SP1.toDouble(), SP2.toDouble());
417           
418           // pre-selection
419           VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
420           if (aStyle) {
421             aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255., 
422                                         aPreColor.blue()/255., PW.toInt());
423           }
424         }
425         // update actors
426         vtkRenderer* aRenderer = aVtkViewFrame->getRenderer();
427         vtkActorCollection *aCollection = aRenderer->GetActors();
428         aCollection->InitTraversal();
429         while(vtkActor *anAct = aCollection->GetNextActor()){
430           if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
431             anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255., 
432                                        aHiColor.blue()/255.);
433             anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255., 
434                                           aPreColor.blue()/255.);
435           }
436         }
437       }
438     }
439   }
440
441   
442   //----------------------------------------------------------------------------
443   VTKViewer_InteractorStyleSALOME* GetInteractorStyle(QAD_StudyFrame *theStudyFrame){
444     if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
445       if(VTKViewer_RenderWindowInteractor* anInteractor = aViewFrame->getRWInteractor()){
446         return anInteractor->GetInteractorStyleSALOME();
447       }
448     }
449     return NULL;
450   }
451
452   void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
453                  VTKViewer_InteractorStyleSALOME* theStyle)
454   {
455     theStyle->SetFilter(theFilter);
456   }
457
458   Handle(VTKViewer_Filter) GetFilter(int theId, VTKViewer_InteractorStyleSALOME* theStyle)
459   {
460     return theStyle->GetFilter(theId);
461   }
462
463   bool IsFilterPresent(int theId, VTKViewer_InteractorStyleSALOME* theStyle)
464   {
465     return theStyle->IsFilterPresent(theId);
466   }
467
468   void RemoveFilter(int theId, VTKViewer_InteractorStyleSALOME* theStyle){
469     theStyle->RemoveFilter(theId);
470   }
471
472   bool IsValid(SALOME_Actor* theActor, int theCellId,
473                VTKViewer_InteractorStyleSALOME* theStyle)
474   {
475     return theStyle->IsValid(theActor,theCellId);
476   }
477
478
479   //----------------------------------------------------------------------------
480   void SetPointRepresentation(bool theIsVisible){
481     if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
482       vtkRenderer *aRenderer = aViewFrame->getRenderer();
483       vtkActorCollection *aCollection = aRenderer->GetActors();
484       aCollection->InitTraversal();
485       while(vtkActor *anAct = aCollection->GetNextActor()){
486         if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
487           if(anActor->GetVisibility()){
488             anActor->SetPointRepresentation(theIsVisible);
489           }
490         }
491       }
492       RepaintCurrentView();
493     }
494   }
495
496
497   void SetPickable(SMESH_Actor* theActor){
498     if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
499       int anIsAllPickable = (theActor == NULL);
500       vtkRenderer *aRenderer = aViewFrame->getRenderer();
501       vtkActorCollection *aCollection = aRenderer->GetActors();
502       aCollection->InitTraversal();
503       while(vtkActor *anAct = aCollection->GetNextActor()){
504         if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
505           if(anActor->GetVisibility()){
506             anActor->SetPickable(anIsAllPickable);
507           }
508         }
509       }
510       if(theActor)
511         theActor->SetPickable(!anIsAllPickable);
512       RepaintCurrentView();
513     }
514   }
515
516
517   int GetNameOfSelectedNodes(SALOME_Selection *theSel, 
518                              const Handle(SALOME_InteractiveObject)& theIO, 
519                              QString& theName)
520   {
521     theName = "";
522     if(theIO->hasEntry()){
523       if(FindActorByEntry(theIO->getEntry())){
524         TColStd_IndexedMapOfInteger aMapIndex;
525         theSel->GetIndex(theIO,aMapIndex);
526         for(int i = 1; i <= aMapIndex.Extent(); i++){
527           theName += QString(" %1").arg(aMapIndex(i));
528         }
529         return aMapIndex.Extent();
530       }
531     }
532     return -1;
533   }
534   
535
536   int GetNameOfSelectedNodes(SALOME_Selection *theSel, QString& theName){
537     theName = "";
538     if(theSel->IObjectCount() == 1){
539       Handle(SALOME_InteractiveObject) anIO = theSel->firstIObject();
540       return GetNameOfSelectedNodes(theSel,anIO,theName);
541     }
542     return -1;
543   }
544   
545
546   int GetNameOfSelectedElements(SALOME_Selection *theSel, 
547                                 const Handle(SALOME_InteractiveObject)& theIO, 
548                                 QString& theName)
549   {
550     theName = "";
551     if(theIO->hasEntry()){
552       if(FindActorByEntry(theIO->getEntry())){
553         TColStd_IndexedMapOfInteger aMapIndex;
554         theSel->GetIndex(theIO,aMapIndex);
555         typedef std::set<int> TIdContainer;
556         TIdContainer anIdContainer;
557         for( int i = 1; i <= aMapIndex.Extent(); i++)
558           anIdContainer.insert(aMapIndex(i));
559         TIdContainer::const_iterator anIter = anIdContainer.begin();
560         for(; anIter != anIdContainer.end(); anIter++){
561           theName += QString(" %1").arg(*anIter);
562         }
563         return aMapIndex.Extent();
564       }
565     }
566     return -1;
567   }
568
569
570   int GetNameOfSelectedElements(SALOME_Selection *theSel, QString& theName)
571   {
572     theName = "";
573     if(theSel->IObjectCount() == 1){
574       Handle(SALOME_InteractiveObject) anIO = theSel->firstIObject();
575       return GetNameOfSelectedElements(theSel,anIO,theName);
576     }
577     return -1;
578   }
579
580   
581   int GetSelected(SALOME_Selection*            theSel, 
582                   TColStd_IndexedMapOfInteger& theMap, 
583                   const bool                   theIsElement)
584   {
585     theMap.Clear();
586
587     if ( theSel->IObjectCount() == 1 )
588     {
589       Handle(SALOME_InteractiveObject) anIO = theSel->firstIObject();
590       if ( anIO->hasEntry() ) {
591         theSel->GetIndex( anIO, theMap );
592       }
593     }
594     return theMap.Extent();
595   }
596
597
598   int GetEdgeNodes( SALOME_Selection* theSel, int& theId1, int& theId2 )
599   {
600     if ( theSel->IObjectCount() != 1 )
601       return -1;
602
603     Handle(SALOME_InteractiveObject) anIO = theSel->firstIObject();
604     if ( anIO.IsNull() || !anIO->hasEntry() )
605       return -1;
606
607     SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
608     if ( anActor == 0 )
609       return -1;
610
611     TColStd_IndexedMapOfInteger aMapIndex;
612     theSel->GetIndex( anIO, aMapIndex );
613     if ( aMapIndex.Extent() != 2 )
614       return -1;
615     
616     int anObjId = -1, anEdgeNum = -1;
617     for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
618       int aVal = aMapIndex( i );
619       if ( aVal > 0 )
620         anObjId = aVal;
621       else
622         anEdgeNum = abs( aVal );
623     }
624     
625     if ( anObjId == -1 || anEdgeNum == -1 )
626       return -1;
627     
628     return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
629   }
630   
631   void SetControlsPrecision( const long theVal )
632   {
633     if( VTKViewer_ViewFrame* aViewFrame = SMESH::GetCurrentVtkView() )
634     {
635       vtkRenderer *aRenderer = aViewFrame->getRenderer();
636       vtkActorCollection *aCollection = aRenderer->GetActors();
637       aCollection->InitTraversal();
638       
639       while ( vtkActor *anAct = aCollection->GetNextActor())
640       {
641         if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
642         {
643           anActor->SetControlsPrecision( theVal );
644           anActor->SetControlMode( anActor->GetControlMode() );
645         }
646       }
647
648     }
649   }
650 }
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667