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_ActorUtils.h"
28 #include "SMESH_ObjectDef.h"
29 #include <SMDS_Mesh.hxx>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_Study.h>
34 #include <SUIT_MessageBox.h>
36 #include <SALOME_ListIO.hxx>
37 #include <SALOME_ListIteratorOfListIO.hxx>
39 #include <SVTK_Selector.h>
40 #include <SVTK_ViewModel.h>
41 #include <SVTK_ViewWindow.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <SalomeApp_Application.h>
45 #include <SalomeApp_Study.h>
47 #include <utilities.h>
49 #include <SALOMEconfig.h>
50 #include CORBA_CLIENT_HEADER(SMESH_Gen)
51 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
52 #include CORBA_CLIENT_HEADER(SMESH_Group)
53 #include CORBA_CLIENT_HEADER(SMESH_Hypothesis)
55 #include <SALOMEDSClient_Study.hxx>
56 #include <SALOMEDSClient_SObject.hxx>
59 #include <vtkRenderer.h>
60 #include <vtkActorCollection.h>
61 #include <vtkUnstructuredGrid.h>
64 #include <TColStd_IndexedMapOfInteger.hxx>
65 #include <Standard_ErrorHandler.hxx>
74 typedef map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
75 static TVisualObjCont VISUAL_OBJ_CONT;
77 //================================================================================
79 * \brief Remove VisualObj and its actor from all views
81 //================================================================================
83 void RemoveVisualObjectWithActors( const char* theEntry )
85 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
86 ( SUIT_Session::session()->activeApplication() );
87 SUIT_ViewManager* aViewManager =
88 app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
90 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
91 for ( int iV = 0; iV < views.count(); ++iV ) {
92 if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
93 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV]))
94 vtkWnd->RemoveActor(actor);
98 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( aViewManager->study() );
99 int aStudyId = aStudy->id();
100 TVisualObjCont::key_type aKey(aStudyId,theEntry);
101 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
102 if(anIter != VISUAL_OBJ_CONT.end()) {
103 // for unknown reason, object destructor is not called, so clear object manually
104 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
105 anIter->second->GetUnstructuredGrid()->SetPoints(0);
107 VISUAL_OBJ_CONT.erase(aKey);
110 //================================================================================
112 * \brief Remove all VisualObjs and their actors from all views
114 //================================================================================
116 void RemoveAllObjectsWithActors()
118 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
119 ( SUIT_Session::session()->activeApplication() );
120 SUIT_ViewManager* aViewManager =
121 app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
122 if ( aViewManager ) {
123 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
124 for ( int iV = 0; iV < views.count(); ++iV ) {
125 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
126 vtkRenderer *aRenderer = vtkWnd->getRenderer();
127 vtkActorCollection *aCollection = aRenderer->GetActors();
128 aCollection->InitTraversal();
129 while(vtkActor *anAct = aCollection->GetNextActor()){
130 if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(anAct)){
131 vtkWnd->RemoveActor(actor);
137 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
138 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
139 // for unknown reason, object destructor is not called, so clear object manually
140 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
141 anIter->second->GetUnstructuredGrid()->SetPoints(0);
143 VISUAL_OBJ_CONT.clear();
146 //================================================================================
148 * \brief Notify the user on problems during visualization
150 //================================================================================
152 void OnVisuException()
154 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
155 QObject::tr("SMESH_VISU_PROBLEM"),
156 QObject::tr("SMESH_BUT_OK"));
158 //================================================================================
160 * \brief Returns an updated visual object
162 //================================================================================
164 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
165 TVisualObjPtr aVisualObj;
166 TVisualObjCont::key_type aKey(theStudyId,theEntry);
168 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
171 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
172 if(anIter != VISUAL_OBJ_CONT.end()){
173 aVisualObj = anIter->second;
175 SalomeApp_Application* app =
176 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
177 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
178 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
180 _PTR(GenericAttribute) anAttr;
181 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
182 _PTR(AttributeIOR) anIOR = anAttr;
183 CORBA::String_var aVal = anIOR->Value().c_str();
184 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
185 if(!CORBA::is_nil(anObj)){
186 //Try narrow to SMESH_Mesh interafce
187 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
188 if(!aMesh->_is_nil()){
189 aVisualObj.reset(new SMESH_MeshObj(aMesh));
190 TVisualObjCont::value_type aValue(aKey,aVisualObj);
191 VISUAL_OBJ_CONT.insert(aValue);
193 //Try narrow to SMESH_Group interafce
194 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
195 if(!aGroup->_is_nil()){
196 _PTR(SObject) aFatherSObj = aSObj->GetFather();
197 if(!aFatherSObj) return aVisualObj;
198 aFatherSObj = aFatherSObj->GetFather();
199 if(!aFatherSObj) return aVisualObj;
200 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
201 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
202 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
203 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
204 TVisualObjCont::value_type aValue(aKey,aVisualObj);
205 VISUAL_OBJ_CONT.insert(aValue);
208 //Try narrow to SMESH_subMesh interafce
209 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
210 if(!aSubMesh->_is_nil()){
211 _PTR(SObject) aFatherSObj = aSObj->GetFather();
212 if(!aFatherSObj) return aVisualObj;
213 aFatherSObj = aFatherSObj->GetFather();
214 if(!aFatherSObj) return aVisualObj;
215 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
216 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
217 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
218 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
219 TVisualObjCont::value_type aValue(aKey,aVisualObj);
220 VISUAL_OBJ_CONT.insert(aValue);
228 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
229 return TVisualObjPtr();
232 bool objModified = false;
235 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
238 objModified = aVisualObj->Update();
242 cout << "Exception in SMESHGUI_VTKUtils::GetVisualObj()" << endl;
245 RemoveVisualObjectWithActors( theEntry ); // remove this object
251 // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
252 // ~10 times more memory is used than it occupies.
253 // Warn the user if there is less free memory than 30 sizes of a grid
254 // TODO: estimate memory usage in other modes and take current mode into account
255 int freeMB = SMDS_Mesh::CheckMemory(true);
256 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
257 if ( freeMB > 0 && usedMB * 30 > freeMB ) {
259 cout << "SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB
260 << ", usedMB=" << usedMB<< endl;
263 if ( usedMB * 10 > freeMB )
264 // even dont try to show
265 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
266 QObject::tr("SMESH_NO_MESH_VISUALIZATION"),
267 QObject::tr("SMESH_BUT_OK"));
269 // there is a chance to succeed
270 continu = SUIT_MessageBox::warn2
271 (SMESHGUI::desktop(),
272 QObject::tr("SMESH_WRN_WARNING"),
273 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
274 QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"),
277 // remove the corresponding actors from all views
278 RemoveVisualObjectWithActors( theEntry );
288 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
289 * overwise find or create corresponding view window, make it active and return it.
290 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
292 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
293 bool createIfNotFound)
295 SalomeApp_Application* anApp;
297 anApp = theModule->getApp();
299 anApp = dynamic_cast<SalomeApp_Application*>
300 (SUIT_Session::session()->activeApplication());
303 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
306 SUIT_ViewManager* aViewManager =
307 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
309 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
310 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
311 aViewWindow->raise();
312 aViewWindow->setFocus();
321 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
322 SUIT_ViewWindow * theWindow)
327 QPtrVector<SUIT_ViewWindow> views = theMgr->getViews();
328 if( views.containsRef( theWindow ) )
329 return GetVtkViewWindow( theWindow );
334 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
335 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
338 /* SUIT_ViewWindow* GetActiveWindow()
340 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
343 SUIT_ViewManager* mgr = app->activeViewManager();
345 return mgr->getActiveView();
350 SVTK_ViewWindow* GetCurrentVtkView(){
351 return GetVtkViewWindow( GetActiveWindow() );
355 void RepaintCurrentView()
357 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
360 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
363 wnd->getRenderer()->Render();
368 cout << "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" << endl;
375 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
378 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
381 theWindow->getRenderer()->Render();
382 theWindow->Repaint();
386 cout << "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow)" << endl;
392 void RenderViewWindow(SVTK_ViewWindow* theWindow)
395 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
398 theWindow->getRenderer()->Render();
399 theWindow->Repaint();
403 cout << "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow)" << endl;
410 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
412 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
420 cout << "Exception in SMESHGUI_VTKUtils::FitAll()" << endl;
428 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
429 const char* theEntry)
431 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
432 vtkRenderer *aRenderer = aViewWindow->getRenderer();
433 vtkActorCollection *aCollection = aRenderer->GetActors();
434 aCollection->InitTraversal();
435 while(vtkActor *anAct = aCollection->GetNextActor()){
436 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
437 if(anActor->hasIO()){
438 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
439 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
450 SMESH_Actor* FindActorByEntry(const char* theEntry){
451 return FindActorByEntry(GetActiveWindow(),theEntry);
455 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
456 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
460 if(!CORBA::is_nil(theObject)){
461 _PTR(Study) aStudy = GetActiveStudyDocument();
462 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
463 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
465 CORBA::String_var anEntry = aSObject->GetID().c_str();
466 return FindActorByEntry(anEntry.in());
473 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
474 const char* theEntry,
477 SMESH_Actor *anActor = NULL;
478 CORBA::Long anId = theStudy->StudyId();
479 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
480 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
482 _PTR(GenericAttribute) anAttr;
483 if(aSObj->FindAttribute(anAttr,"AttributeName")){
484 _PTR(AttributeName) aName = anAttr;
485 std::string aNameVal = aName->Value();
486 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
489 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
490 if(!CORBA::is_nil(aGroup))
492 SALOMEDS::Color aColor = aGroup->GetColor();
493 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ) )
495 int r = 0, g = 0, b = 0;
496 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
497 aColor.R = (float)r / 255.0;
498 aColor.G = (float)g / 255.0;
499 aColor.B = (float)b / 255.0;
500 aGroup->SetColor( aColor );
502 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
510 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
511 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
513 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
516 vtkWnd->AddActor(theActor);
521 cout << "Exception in SMESHGUI_VTKUtils::DisplayActor()" << endl;
529 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
530 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
531 vtkWnd->RemoveActor(theActor);
532 if(theActor->hasIO()){
533 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
534 if(anIO->hasEntry()){
535 std::string anEntry = anIO->getEntry();
536 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
537 int aStudyId = aStudy->id();
538 TVisualObjCont::key_type aKey(aStudyId,anEntry);
539 VISUAL_OBJ_CONT.erase(aKey);
547 void UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
549 if(SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd)){
550 vtkRenderer *aRenderer = aViewWnd->getRenderer();
551 vtkActorCollection *aCollection = aRenderer->GetActors();
552 aCollection->InitTraversal();
555 while(vtkActor *anAct = aCollection->GetNextActor()){
556 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
557 anActor->SetVisibility(true);
564 while(vtkActor *anAct = aCollection->GetNextActor()){
565 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
566 anActor->SetVisibility(false);
571 if(SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)){
575 anActor->SetVisibility(true);
576 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
579 anActor->SetVisibility(false);
586 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( theWnd->getViewManager()->study() );
587 _PTR(Study) aDocument = aStudy->studyDS();
588 if((anActor = CreateActor(aDocument,theEntry,true))) {
589 DisplayActor(theWnd,anActor);
590 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
602 void UpdateView(EDisplaing theAction, const char* theEntry){
603 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
604 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
605 SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
606 UpdateView(aWnd,theAction,theEntry);
610 if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
611 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
612 SALOME_ListIO selected; mgr->selectedObjects( selected );
614 if( selected.Extent() == 0){
615 vtkRenderer* aRenderer = aWnd->getRenderer();
616 vtkActorCollection *aCollection = aRenderer->GetActors();
617 aCollection->InitTraversal();
618 while(vtkActor *anAct = aCollection->GetNextActor()){
619 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
621 if (!Update(anActor->getIO(),anActor->GetVisibility()))
622 break; // avoid multiple warinings if visu failed
626 SALOME_ListIteratorOfListIO anIter( selected );
627 for(; anIter.More(); anIter.Next()){
628 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
629 if ( !Update(anIO,true) )
630 break; // avoid multiple warinings if visu failed
633 RepaintCurrentView();
638 bool Update(const Handle(SALOME_InteractiveObject)& theIO,
641 _PTR(Study) aStudy = GetActiveStudyDocument();
642 CORBA::Long anId = aStudy->StudyId();
643 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
645 UpdateView(SMESH::eDisplay,theIO->getEntry());
652 void UpdateSelectionProp( SMESHGUI* theModule ) {
656 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
659 MESSAGE( "UpdateSelectionProp: Application is null" );
663 SUIT_ViewManager* vm = app->activeViewManager();
666 MESSAGE( "UpdateSelectionProp: View manager is null" );
670 QPtrVector<SUIT_ViewWindow> views = vm->getViews();
672 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
675 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
679 QColor aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
680 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
681 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
683 int SW = mgr->integerValue( "SMESH", "selection_width", 5 ),
684 PW = mgr->integerValue( "SMESH", "highlight_width", 5 );
686 double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
687 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
688 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
690 for ( int i=0, n=views.count(); i<n; i++ ){
691 // update VTK viewer properties
692 if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
693 // mesh element selection
694 aVtkView->SetSelectionProp(aSelColor.red()/255.,
695 aSelColor.green()/255.,
696 aSelColor.blue()/255.,
699 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
702 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
703 aPreColor.green()/255.,
704 aPreColor.blue()/255.,
707 vtkRenderer* aRenderer = aVtkView->getRenderer();
708 vtkActorCollection *aCollection = aRenderer->GetActors();
709 aCollection->InitTraversal();
710 while(vtkActor *anAct = aCollection->GetNextActor()){
711 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
712 anActor->SetHighlightColor(aHiColor.red()/255.,
713 aHiColor.green()/255.,
714 aHiColor.blue()/255.);
715 anActor->SetPreHighlightColor(aPreColor.red()/255.,
716 aPreColor.green()/255.,
717 aPreColor.blue()/255.);
725 //----------------------------------------------------------------------------
727 GetSelector(SUIT_ViewWindow *theWindow)
729 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
730 return aWnd->GetSelector();
735 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
736 SVTK_Selector* theSelector)
739 theSelector->SetFilter(theFilter);
742 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
744 return theSelector->GetFilter(theId);
747 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
749 return theSelector->IsFilterPresent(theId);
752 void RemoveFilter(int theId, SVTK_Selector* theSelector)
754 theSelector->RemoveFilter(theId);
757 void RemoveFilters(SVTK_Selector* theSelector)
759 for ( int id = SMESHGUI_NodeFilter; theSelector && id < SMESHGUI_LastFilter; id++ )
760 theSelector->RemoveFilter( id );
763 bool IsValid(SALOME_Actor* theActor, int theCellId,
764 SVTK_Selector* theSelector)
766 return theSelector->IsValid(theActor,theCellId);
770 //----------------------------------------------------------------------------
771 void SetPointRepresentation(bool theIsVisible){
772 if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
773 vtkRenderer *aRenderer = aViewWindow->getRenderer();
774 vtkActorCollection *aCollection = aRenderer->GetActors();
775 aCollection->InitTraversal();
776 while(vtkActor *anAct = aCollection->GetNextActor()){
777 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
778 if(anActor->GetVisibility()){
779 anActor->SetPointRepresentation(theIsVisible);
783 RepaintCurrentView();
788 void SetPickable(SMESH_Actor* theActor){
789 if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
790 int anIsAllPickable = (theActor == NULL);
791 vtkRenderer *aRenderer = aWnd->getRenderer();
792 vtkActorCollection *aCollection = aRenderer->GetActors();
793 aCollection->InitTraversal();
794 while(vtkActor *anAct = aCollection->GetNextActor()){
795 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
796 if(anActor->GetVisibility()){
797 anActor->SetPickable(anIsAllPickable);
802 theActor->SetPickable(!anIsAllPickable);
803 RepaintCurrentView();
808 //----------------------------------------------------------------------------
809 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
810 const Handle(SALOME_InteractiveObject)& theIO,
814 TColStd_IndexedMapOfInteger aMapIndex;
815 theSelector->GetIndex(theIO,aMapIndex);
817 for(int i = 1; i <= aMapIndex.Extent(); i++)
818 theName += QString(" %1").arg(aMapIndex(i));
820 return aMapIndex.Extent();
823 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
824 const Handle(SALOME_InteractiveObject)& theIO,
828 TColStd_IndexedMapOfInteger aMapIndex;
829 theSelector->GetIndex(theIO,aMapIndex);
831 typedef std::set<int> TIdContainer;
832 TIdContainer anIdContainer;
833 for( int i = 1; i <= aMapIndex.Extent(); i++)
834 anIdContainer.insert(aMapIndex(i));
836 TIdContainer::const_iterator anIter = anIdContainer.begin();
837 for(; anIter != anIdContainer.end(); anIter++)
838 theName += QString(" %1").arg(*anIter);
840 return aMapIndex.Extent();
844 int GetEdgeNodes(SVTK_Selector* theSelector,
845 const TVisualObjPtr& theVisualObject,
849 const SALOME_ListIO& selected = theSelector->StoredIObjects();
851 if ( selected.Extent() != 1 )
854 Handle(SALOME_InteractiveObject) anIO = selected.First();
855 if ( anIO.IsNull() || !anIO->hasEntry() )
858 TColStd_IndexedMapOfInteger aMapIndex;
859 theSelector->GetIndex( anIO, aMapIndex );
860 if ( aMapIndex.Extent() != 2 )
863 int anObjId = -1, anEdgeNum = -1;
864 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
865 int aVal = aMapIndex( i );
869 anEdgeNum = abs( aVal ) - 1;
872 if ( anObjId == -1 || anEdgeNum == -1 )
875 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
878 //----------------------------------------------------------------------------
879 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
880 const Handle(SALOME_InteractiveObject)& theIO,
884 if(theIO->hasEntry()){
885 if(FindActorByEntry(theIO->getEntry())){
886 TColStd_IndexedMapOfInteger aMapIndex;
887 theMgr->GetIndexes(theIO,aMapIndex);
888 for(int i = 1; i <= aMapIndex.Extent(); i++){
889 theName += QString(" %1").arg(aMapIndex(i));
891 return aMapIndex.Extent();
897 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName){
899 SALOME_ListIO selected; theMgr->selectedObjects( selected );
900 if(selected.Extent() == 1){
901 Handle(SALOME_InteractiveObject) anIO = selected.First();
902 return GetNameOfSelectedNodes(theMgr,anIO,theName);
908 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr,
909 const Handle(SALOME_InteractiveObject)& theIO,
913 if(theIO->hasEntry()){
914 if(FindActorByEntry(theIO->getEntry())){
915 TColStd_IndexedMapOfInteger aMapIndex;
916 theMgr->GetIndexes(theIO,aMapIndex);
917 typedef set<int> TIdContainer;
918 TIdContainer anIdContainer;
919 for( int i = 1; i <= aMapIndex.Extent(); i++)
920 anIdContainer.insert(aMapIndex(i));
921 TIdContainer::const_iterator anIter = anIdContainer.begin();
922 for(; anIter != anIdContainer.end(); anIter++){
923 theName += QString(" %1").arg(*anIter);
925 return aMapIndex.Extent();
932 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
935 SALOME_ListIO selected; theMgr->selectedObjects( selected );
937 if( selected.Extent() == 1){
938 Handle(SALOME_InteractiveObject) anIO = selected.First();
939 return GetNameOfSelectedElements(theMgr,anIO,theName);
944 int GetSelected(LightApp_SelectionMgr* theMgr,
945 TColStd_IndexedMapOfInteger& theMap,
946 const bool theIsElement)
949 SALOME_ListIO selected; theMgr->selectedObjects( selected );
951 if ( selected.Extent() == 1 )
953 Handle(SALOME_InteractiveObject) anIO = selected.First();
954 if ( anIO->hasEntry() ) {
955 theMgr->GetIndexes( anIO, theMap );
958 return theMap.Extent();
962 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
964 SALOME_ListIO selected; theMgr->selectedObjects( selected );
966 if ( selected.Extent() != 1 )
969 Handle(SALOME_InteractiveObject) anIO = selected.First();
970 if ( anIO.IsNull() || !anIO->hasEntry() )
973 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
977 TColStd_IndexedMapOfInteger aMapIndex;
978 theMgr->GetIndexes( anIO, aMapIndex );
979 if ( aMapIndex.Extent() != 2 )
982 int anObjId = -1, anEdgeNum = -1;
983 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
984 int aVal = aMapIndex( i );
988 anEdgeNum = abs( aVal );
991 if ( anObjId == -1 || anEdgeNum == -1 )
994 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
997 void SetControlsPrecision( const long theVal )
999 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1001 vtkRenderer *aRenderer = aWnd->getRenderer();
1002 vtkActorCollection *aCollection = aRenderer->GetActors();
1003 aCollection->InitTraversal();
1005 while ( vtkActor *anAct = aCollection->GetNextActor())
1007 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1009 anActor->SetControlsPrecision( theVal );
1010 anActor->SetControlMode( anActor->GetControlMode() );