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