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