1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "SMESHGUI_VTKUtils.h"
22 #include "SMESHGUI_Utils.h"
23 #include "SMESHGUI_Filter.h"
26 #include "SMESH_Actor.h"
27 #include "SMESH_ObjectDef.h"
28 #include <SMDS_Mesh.hxx>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Study.h>
33 #include <SUIT_MessageBox.h>
35 #include <SALOME_ListIO.hxx>
36 #include <SALOME_ListIteratorOfListIO.hxx>
38 #include <SVTK_Selector.h>
39 #include <SVTK_ViewModel.h>
40 #include <SVTK_ViewWindow.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_Study.h>
46 #include <utilities.h>
48 #include <SALOMEconfig.h>
49 #include CORBA_CLIENT_HEADER(SMESH_Gen)
50 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
51 #include CORBA_CLIENT_HEADER(SMESH_Group)
52 #include CORBA_CLIENT_HEADER(SMESH_Hypothesis)
54 #include <SALOMEDSClient_Study.hxx>
55 #include <SALOMEDSClient_SObject.hxx>
58 #include <vtkRenderer.h>
59 #include <vtkActorCollection.h>
60 #include <vtkUnstructuredGrid.h>
63 #include <TColStd_IndexedMapOfInteger.hxx>
64 #include <Standard_ErrorHandler.hxx>
73 typedef map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
74 static TVisualObjCont VISUAL_OBJ_CONT;
76 //================================================================================
78 * \brief Remove VisualObj and its actor from all views
80 //================================================================================
82 void RemoveVisualObjectWithActors( const char* theEntry )
84 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
85 ( SUIT_Session::session()->activeApplication() );
86 SUIT_ViewManager* aViewManager =
87 app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
89 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
90 for ( int iV = 0; iV < views.count(); ++iV ) {
91 if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
92 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV]))
93 vtkWnd->RemoveActor(actor);
97 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( aViewManager->study() );
98 int aStudyId = aStudy->id();
99 TVisualObjCont::key_type aKey(aStudyId,theEntry);
100 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
101 if(anIter != VISUAL_OBJ_CONT.end()) {
102 // for unknown reason, object destructor is not called, so clear object manually
103 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
104 anIter->second->GetUnstructuredGrid()->SetPoints(0);
106 VISUAL_OBJ_CONT.erase(aKey);
109 //================================================================================
111 * \brief Remove all VisualObjs and their actors from all views
113 //================================================================================
115 void RemoveAllObjectsWithActors()
117 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
118 ( SUIT_Session::session()->activeApplication() );
119 SUIT_ViewManager* aViewManager =
120 app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
121 if ( aViewManager ) {
122 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
123 for ( int iV = 0; iV < views.count(); ++iV ) {
124 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
125 vtkRenderer *aRenderer = vtkWnd->getRenderer();
126 vtkActorCollection *aCollection = aRenderer->GetActors();
127 aCollection->InitTraversal();
128 while(vtkActor *anAct = aCollection->GetNextActor()){
129 if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(anAct)){
130 vtkWnd->RemoveActor(actor);
136 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
137 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
138 // for unknown reason, object destructor is not called, so clear object manually
139 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
140 anIter->second->GetUnstructuredGrid()->SetPoints(0);
142 VISUAL_OBJ_CONT.clear();
145 //================================================================================
147 * \brief Notify the user on problems during visualization
149 //================================================================================
151 void OnVisuException()
153 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
154 QObject::tr("SMESH_VISU_PROBLEM"),
155 QObject::tr("SMESH_BUT_OK"));
157 //================================================================================
159 * \brief Returns an updated visual object
161 //================================================================================
163 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
164 TVisualObjPtr aVisualObj;
165 TVisualObjCont::key_type aKey(theStudyId,theEntry);
167 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
170 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
171 if(anIter != VISUAL_OBJ_CONT.end()){
172 aVisualObj = anIter->second;
174 SalomeApp_Application* app =
175 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
176 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
177 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
179 _PTR(GenericAttribute) anAttr;
180 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
181 _PTR(AttributeIOR) anIOR = anAttr;
182 CORBA::String_var aVal = anIOR->Value().c_str();
183 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
184 if(!CORBA::is_nil(anObj)){
185 //Try narrow to SMESH_Mesh interafce
186 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
187 if(!aMesh->_is_nil()){
188 aVisualObj.reset(new SMESH_MeshObj(aMesh));
189 TVisualObjCont::value_type aValue(aKey,aVisualObj);
190 VISUAL_OBJ_CONT.insert(aValue);
192 //Try narrow to SMESH_Group interafce
193 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
194 if(!aGroup->_is_nil()){
195 _PTR(SObject) aFatherSObj = aSObj->GetFather();
196 if(!aFatherSObj) return aVisualObj;
197 aFatherSObj = aFatherSObj->GetFather();
198 if(!aFatherSObj) return aVisualObj;
199 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
200 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
201 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
202 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
203 TVisualObjCont::value_type aValue(aKey,aVisualObj);
204 VISUAL_OBJ_CONT.insert(aValue);
207 //Try narrow to SMESH_subMesh interafce
208 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
209 if(!aSubMesh->_is_nil()){
210 _PTR(SObject) aFatherSObj = aSObj->GetFather();
211 if(!aFatherSObj) return aVisualObj;
212 aFatherSObj = aFatherSObj->GetFather();
213 if(!aFatherSObj) return aVisualObj;
214 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
215 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
216 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
217 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
218 TVisualObjCont::value_type aValue(aKey,aVisualObj);
219 VISUAL_OBJ_CONT.insert(aValue);
227 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
228 return TVisualObjPtr();
231 bool objModified = false;
234 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
237 objModified = aVisualObj->Update();
241 cout << "Exception in SMESHGUI_VTKUtils::GetVisualObj()" << endl;
244 RemoveVisualObjectWithActors( theEntry ); // remove this object
250 // PAL16631. Mesurements showed that to show aVisualObj in shading mode,
251 // ~10 times more memory is used than it occupies.
252 // Warn the user if there is less free memory than 30 sizes of a grid
253 int freeMB = SMDS_Mesh::CheckMemory(true);
254 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
255 if ( freeMB > 0 && usedMB * 30 > freeMB ) {
256 int continu = SUIT_MessageBox::warn2
257 (SMESHGUI::desktop(),
258 QObject::tr("SMESH_WRN_WARNING"),
259 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
260 QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"),
263 // remove the corresponding actors from all views
264 RemoveVisualObjectWithActors( theEntry );
274 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
275 * overwise find or create corresponding view window, make it active and return it.
276 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
278 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
279 bool createIfNotFound)
281 SalomeApp_Application* anApp;
283 anApp = theModule->getApp();
285 anApp = dynamic_cast<SalomeApp_Application*>
286 (SUIT_Session::session()->activeApplication());
289 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
292 SUIT_ViewManager* aViewManager =
293 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
295 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
296 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
297 aViewWindow->raise();
298 aViewWindow->setFocus();
307 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
308 SUIT_ViewWindow * theWindow)
313 QPtrVector<SUIT_ViewWindow> views = theMgr->getViews();
314 if( views.containsRef( theWindow ) )
315 return GetVtkViewWindow( theWindow );
320 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
321 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
324 /* SUIT_ViewWindow* GetActiveWindow()
326 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
329 SUIT_ViewManager* mgr = app->activeViewManager();
331 return mgr->getActiveView();
336 SVTK_ViewWindow* GetCurrentVtkView(){
337 return GetVtkViewWindow( GetActiveWindow() );
341 void RepaintCurrentView()
343 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
346 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
349 wnd->getRenderer()->Render();
355 cout << "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" << endl;
361 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
364 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
367 theWindow->getRenderer()->Render();
368 theWindow->Repaint();
373 cout << "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow)" << endl;
378 void RenderViewWindow(SVTK_ViewWindow* theWindow)
381 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
384 theWindow->getRenderer()->Render();
385 theWindow->Repaint();
390 cout << "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow)" << endl;
396 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
398 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
407 cout << "Exception in SMESHGUI_VTKUtils::FitAll()" << endl;
414 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
415 const char* theEntry)
417 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
418 vtkRenderer *aRenderer = aViewWindow->getRenderer();
419 vtkActorCollection *aCollection = aRenderer->GetActors();
420 aCollection->InitTraversal();
421 while(vtkActor *anAct = aCollection->GetNextActor()){
422 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
423 if(anActor->hasIO()){
424 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
425 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
436 SMESH_Actor* FindActorByEntry(const char* theEntry){
437 return FindActorByEntry(GetActiveWindow(),theEntry);
441 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
442 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
446 if(!CORBA::is_nil(theObject)){
447 _PTR(Study) aStudy = GetActiveStudyDocument();
448 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
449 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
451 CORBA::String_var anEntry = aSObject->GetID().c_str();
452 return FindActorByEntry(anEntry.in());
459 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
460 const char* theEntry,
463 SMESH_Actor *anActor = NULL;
464 CORBA::Long anId = theStudy->StudyId();
465 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
466 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
468 _PTR(GenericAttribute) anAttr;
469 if(aSObj->FindAttribute(anAttr,"AttributeName")){
470 _PTR(AttributeName) aName = anAttr;
471 std::string aNameVal = aName->Value();
472 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
480 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
481 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
483 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
486 vtkWnd->AddActor(theActor);
492 cout << "Exception in SMESHGUI_VTKUtils::DisplayActor()" << endl;
499 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
500 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
501 vtkWnd->RemoveActor(theActor);
502 if(theActor->hasIO()){
503 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
504 if(anIO->hasEntry()){
505 std::string anEntry = anIO->getEntry();
506 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
507 int aStudyId = aStudy->id();
508 TVisualObjCont::key_type aKey(aStudyId,anEntry);
509 VISUAL_OBJ_CONT.erase(aKey);
517 void UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
519 if(SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd)){
520 vtkRenderer *aRenderer = aViewWnd->getRenderer();
521 vtkActorCollection *aCollection = aRenderer->GetActors();
522 aCollection->InitTraversal();
525 while(vtkActor *anAct = aCollection->GetNextActor()){
526 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
527 anActor->SetVisibility(true);
534 while(vtkActor *anAct = aCollection->GetNextActor()){
535 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
536 anActor->SetVisibility(false);
541 if(SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)){
545 anActor->SetVisibility(true);
546 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
549 anActor->SetVisibility(false);
556 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( theWnd->getViewManager()->study() );
557 _PTR(Study) aDocument = aStudy->studyDS();
558 if((anActor = CreateActor(aDocument,theEntry,true))) {
559 DisplayActor(theWnd,anActor);
560 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
572 void UpdateView(EDisplaing theAction, const char* theEntry){
573 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
574 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
575 SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
576 UpdateView(aWnd,theAction,theEntry);
580 if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
581 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
582 SALOME_ListIO selected; mgr->selectedObjects( selected );
584 if( selected.Extent() == 0){
585 vtkRenderer* aRenderer = aWnd->getRenderer();
586 vtkActorCollection *aCollection = aRenderer->GetActors();
587 aCollection->InitTraversal();
588 while(vtkActor *anAct = aCollection->GetNextActor()){
589 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
591 Update(anActor->getIO(),anActor->GetVisibility());
595 SALOME_ListIteratorOfListIO anIter( selected );
596 for(; anIter.More(); anIter.Next()){
597 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
601 RepaintCurrentView();
606 void Update(const Handle(SALOME_InteractiveObject)& theIO,
609 _PTR(Study) aStudy = GetActiveStudyDocument();
610 CORBA::Long anId = aStudy->StudyId();
611 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
613 // aVisualObj->Update(); -> PAL16631, already done in GetVisualObj()
615 UpdateView(SMESH::eDisplay,theIO->getEntry());
620 void UpdateSelectionProp( SMESHGUI* theModule ) {
624 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
627 MESSAGE( "UpdateSelectionProp: Application is null" );
631 SUIT_ViewManager* vm = app->activeViewManager();
634 MESSAGE( "UpdateSelectionProp: View manager is null" );
638 QPtrVector<SUIT_ViewWindow> views = vm->getViews();
640 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
643 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
647 QColor aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
648 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
649 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
651 int SW = mgr->integerValue( "SMESH", "selection_width", 5 ),
652 PW = mgr->integerValue( "SMESH", "highlight_width", 5 );
654 double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
655 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
656 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
658 for ( int i=0, n=views.count(); i<n; i++ ){
659 // update VTK viewer properties
660 if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
661 // mesh element selection
662 aVtkView->SetSelectionProp(aSelColor.red()/255.,
663 aSelColor.green()/255.,
664 aSelColor.blue()/255.,
667 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
670 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
671 aPreColor.green()/255.,
672 aPreColor.blue()/255.,
675 vtkRenderer* aRenderer = aVtkView->getRenderer();
676 vtkActorCollection *aCollection = aRenderer->GetActors();
677 aCollection->InitTraversal();
678 while(vtkActor *anAct = aCollection->GetNextActor()){
679 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
680 anActor->SetHighlightColor(aHiColor.red()/255.,
681 aHiColor.green()/255.,
682 aHiColor.blue()/255.);
683 anActor->SetPreHighlightColor(aPreColor.red()/255.,
684 aPreColor.green()/255.,
685 aPreColor.blue()/255.);
693 //----------------------------------------------------------------------------
695 GetSelector(SUIT_ViewWindow *theWindow)
697 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
698 return aWnd->GetSelector();
703 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
704 SVTK_Selector* theSelector)
707 theSelector->SetFilter(theFilter);
710 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
712 return theSelector->GetFilter(theId);
715 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
717 return theSelector->IsFilterPresent(theId);
720 void RemoveFilter(int theId, SVTK_Selector* theSelector)
722 theSelector->RemoveFilter(theId);
725 void RemoveFilters(SVTK_Selector* theSelector)
727 for ( int id = SMESHGUI_NodeFilter; theSelector && id < SMESHGUI_LastFilter; id++ )
728 theSelector->RemoveFilter( id );
731 bool IsValid(SALOME_Actor* theActor, int theCellId,
732 SVTK_Selector* theSelector)
734 return theSelector->IsValid(theActor,theCellId);
738 //----------------------------------------------------------------------------
739 void SetPointRepresentation(bool theIsVisible){
740 if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
741 vtkRenderer *aRenderer = aViewWindow->getRenderer();
742 vtkActorCollection *aCollection = aRenderer->GetActors();
743 aCollection->InitTraversal();
744 while(vtkActor *anAct = aCollection->GetNextActor()){
745 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
746 if(anActor->GetVisibility()){
747 anActor->SetPointRepresentation(theIsVisible);
751 RepaintCurrentView();
756 void SetPickable(SMESH_Actor* theActor){
757 if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
758 int anIsAllPickable = (theActor == NULL);
759 vtkRenderer *aRenderer = aWnd->getRenderer();
760 vtkActorCollection *aCollection = aRenderer->GetActors();
761 aCollection->InitTraversal();
762 while(vtkActor *anAct = aCollection->GetNextActor()){
763 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
764 if(anActor->GetVisibility()){
765 anActor->SetPickable(anIsAllPickable);
770 theActor->SetPickable(!anIsAllPickable);
771 RepaintCurrentView();
776 //----------------------------------------------------------------------------
777 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
778 const Handle(SALOME_InteractiveObject)& theIO,
782 TColStd_IndexedMapOfInteger aMapIndex;
783 theSelector->GetIndex(theIO,aMapIndex);
785 for(int i = 1; i <= aMapIndex.Extent(); i++)
786 theName += QString(" %1").arg(aMapIndex(i));
788 return aMapIndex.Extent();
791 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
792 const Handle(SALOME_InteractiveObject)& theIO,
796 TColStd_IndexedMapOfInteger aMapIndex;
797 theSelector->GetIndex(theIO,aMapIndex);
799 typedef std::set<int> TIdContainer;
800 TIdContainer anIdContainer;
801 for( int i = 1; i <= aMapIndex.Extent(); i++)
802 anIdContainer.insert(aMapIndex(i));
804 TIdContainer::const_iterator anIter = anIdContainer.begin();
805 for(; anIter != anIdContainer.end(); anIter++)
806 theName += QString(" %1").arg(*anIter);
808 return aMapIndex.Extent();
812 int GetEdgeNodes(SVTK_Selector* theSelector,
813 const TVisualObjPtr& theVisualObject,
817 const SALOME_ListIO& selected = theSelector->StoredIObjects();
819 if ( selected.Extent() != 1 )
822 Handle(SALOME_InteractiveObject) anIO = selected.First();
823 if ( anIO.IsNull() || !anIO->hasEntry() )
826 TColStd_IndexedMapOfInteger aMapIndex;
827 theSelector->GetIndex( anIO, aMapIndex );
828 if ( aMapIndex.Extent() != 2 )
831 int anObjId = -1, anEdgeNum = -1;
832 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
833 int aVal = aMapIndex( i );
837 anEdgeNum = abs( aVal ) - 1;
840 if ( anObjId == -1 || anEdgeNum == -1 )
843 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
846 //----------------------------------------------------------------------------
847 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
848 const Handle(SALOME_InteractiveObject)& theIO,
852 if(theIO->hasEntry()){
853 if(FindActorByEntry(theIO->getEntry())){
854 TColStd_IndexedMapOfInteger aMapIndex;
855 theMgr->GetIndexes(theIO,aMapIndex);
856 for(int i = 1; i <= aMapIndex.Extent(); i++){
857 theName += QString(" %1").arg(aMapIndex(i));
859 return aMapIndex.Extent();
865 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName){
867 SALOME_ListIO selected; theMgr->selectedObjects( selected );
868 if(selected.Extent() == 1){
869 Handle(SALOME_InteractiveObject) anIO = selected.First();
870 return GetNameOfSelectedNodes(theMgr,anIO,theName);
876 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr,
877 const Handle(SALOME_InteractiveObject)& theIO,
881 if(theIO->hasEntry()){
882 if(FindActorByEntry(theIO->getEntry())){
883 TColStd_IndexedMapOfInteger aMapIndex;
884 theMgr->GetIndexes(theIO,aMapIndex);
885 typedef set<int> TIdContainer;
886 TIdContainer anIdContainer;
887 for( int i = 1; i <= aMapIndex.Extent(); i++)
888 anIdContainer.insert(aMapIndex(i));
889 TIdContainer::const_iterator anIter = anIdContainer.begin();
890 for(; anIter != anIdContainer.end(); anIter++){
891 theName += QString(" %1").arg(*anIter);
893 return aMapIndex.Extent();
900 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
903 SALOME_ListIO selected; theMgr->selectedObjects( selected );
905 if( selected.Extent() == 1){
906 Handle(SALOME_InteractiveObject) anIO = selected.First();
907 return GetNameOfSelectedElements(theMgr,anIO,theName);
912 int GetSelected(LightApp_SelectionMgr* theMgr,
913 TColStd_IndexedMapOfInteger& theMap,
914 const bool theIsElement)
917 SALOME_ListIO selected; theMgr->selectedObjects( selected );
919 if ( selected.Extent() == 1 )
921 Handle(SALOME_InteractiveObject) anIO = selected.First();
922 if ( anIO->hasEntry() ) {
923 theMgr->GetIndexes( anIO, theMap );
926 return theMap.Extent();
930 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
932 SALOME_ListIO selected; theMgr->selectedObjects( selected );
934 if ( selected.Extent() != 1 )
937 Handle(SALOME_InteractiveObject) anIO = selected.First();
938 if ( anIO.IsNull() || !anIO->hasEntry() )
941 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
945 TColStd_IndexedMapOfInteger aMapIndex;
946 theMgr->GetIndexes( anIO, aMapIndex );
947 if ( aMapIndex.Extent() != 2 )
950 int anObjId = -1, anEdgeNum = -1;
951 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
952 int aVal = aMapIndex( i );
956 anEdgeNum = abs( aVal );
959 if ( anObjId == -1 || anEdgeNum == -1 )
962 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
965 void SetControlsPrecision( const long theVal )
967 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
969 vtkRenderer *aRenderer = aWnd->getRenderer();
970 vtkActorCollection *aCollection = aRenderer->GetActors();
971 aCollection->InitTraversal();
973 while ( vtkActor *anAct = aCollection->GetNextActor())
975 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
977 anActor->SetControlsPrecision( theVal );
978 anActor->SetControlMode( anActor->GetControlMode() );