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(default) 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 // TODO: estimate memory usage in other modes and take current mode into account
254 int freeMB = SMDS_Mesh::CheckMemory(true);
255 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
256 if ( freeMB > 0 && usedMB * 30 > freeMB ) {
258 cout << "SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB
259 << ", usedMB=" << usedMB<< endl;
262 if ( usedMB * 10 > freeMB )
263 // even dont try to show
264 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
265 QObject::tr("SMESH_NO_MESH_VISUALIZATION"),
266 QObject::tr("SMESH_BUT_OK"));
268 // there is a chance to succeed
269 continu = SUIT_MessageBox::warn2
270 (SMESHGUI::desktop(),
271 QObject::tr("SMESH_WRN_WARNING"),
272 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
273 QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"),
276 // remove the corresponding actors from all views
277 RemoveVisualObjectWithActors( theEntry );
287 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
288 * overwise find or create corresponding view window, make it active and return it.
289 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
291 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
292 bool createIfNotFound)
294 SalomeApp_Application* anApp;
296 anApp = theModule->getApp();
298 anApp = dynamic_cast<SalomeApp_Application*>
299 (SUIT_Session::session()->activeApplication());
302 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
305 SUIT_ViewManager* aViewManager =
306 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
308 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
309 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
310 aViewWindow->raise();
311 aViewWindow->setFocus();
320 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
321 SUIT_ViewWindow * theWindow)
326 QPtrVector<SUIT_ViewWindow> views = theMgr->getViews();
327 if( views.containsRef( theWindow ) )
328 return GetVtkViewWindow( theWindow );
333 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
334 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
337 /* SUIT_ViewWindow* GetActiveWindow()
339 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
342 SUIT_ViewManager* mgr = app->activeViewManager();
344 return mgr->getActiveView();
349 SVTK_ViewWindow* GetCurrentVtkView(){
350 return GetVtkViewWindow( GetActiveWindow() );
354 void RepaintCurrentView()
356 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
359 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
362 wnd->getRenderer()->Render();
367 cout << "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" << endl;
374 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
377 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
380 theWindow->getRenderer()->Render();
381 theWindow->Repaint();
385 cout << "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow)" << endl;
391 void RenderViewWindow(SVTK_ViewWindow* theWindow)
394 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
397 theWindow->getRenderer()->Render();
398 theWindow->Repaint();
402 cout << "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow)" << endl;
409 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
411 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
419 cout << "Exception in SMESHGUI_VTKUtils::FitAll()" << endl;
427 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
428 const char* theEntry)
430 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
431 vtkRenderer *aRenderer = aViewWindow->getRenderer();
432 vtkActorCollection *aCollection = aRenderer->GetActors();
433 aCollection->InitTraversal();
434 while(vtkActor *anAct = aCollection->GetNextActor()){
435 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
436 if(anActor->hasIO()){
437 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
438 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
449 SMESH_Actor* FindActorByEntry(const char* theEntry){
450 return FindActorByEntry(GetActiveWindow(),theEntry);
454 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
455 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
459 if(!CORBA::is_nil(theObject)){
460 _PTR(Study) aStudy = GetActiveStudyDocument();
461 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
462 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
464 CORBA::String_var anEntry = aSObject->GetID().c_str();
465 return FindActorByEntry(anEntry.in());
472 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
473 const char* theEntry,
476 SMESH_Actor *anActor = NULL;
477 CORBA::Long anId = theStudy->StudyId();
478 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
479 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
481 _PTR(GenericAttribute) anAttr;
482 if(aSObj->FindAttribute(anAttr,"AttributeName")){
483 _PTR(AttributeName) aName = anAttr;
484 std::string aNameVal = aName->Value();
485 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
493 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
494 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
496 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
499 vtkWnd->AddActor(theActor);
504 cout << "Exception in SMESHGUI_VTKUtils::DisplayActor()" << endl;
512 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
513 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
514 vtkWnd->RemoveActor(theActor);
515 if(theActor->hasIO()){
516 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
517 if(anIO->hasEntry()){
518 std::string anEntry = anIO->getEntry();
519 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
520 int aStudyId = aStudy->id();
521 TVisualObjCont::key_type aKey(aStudyId,anEntry);
522 VISUAL_OBJ_CONT.erase(aKey);
530 void UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
532 if(SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd)){
533 vtkRenderer *aRenderer = aViewWnd->getRenderer();
534 vtkActorCollection *aCollection = aRenderer->GetActors();
535 aCollection->InitTraversal();
538 while(vtkActor *anAct = aCollection->GetNextActor()){
539 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
540 anActor->SetVisibility(true);
547 while(vtkActor *anAct = aCollection->GetNextActor()){
548 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
549 anActor->SetVisibility(false);
554 if(SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)){
558 anActor->SetVisibility(true);
559 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
562 anActor->SetVisibility(false);
569 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( theWnd->getViewManager()->study() );
570 _PTR(Study) aDocument = aStudy->studyDS();
571 if((anActor = CreateActor(aDocument,theEntry,true))) {
572 DisplayActor(theWnd,anActor);
573 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
585 void UpdateView(EDisplaing theAction, const char* theEntry){
586 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
587 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
588 SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
589 UpdateView(aWnd,theAction,theEntry);
593 if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
594 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
595 SALOME_ListIO selected; mgr->selectedObjects( selected );
597 if( selected.Extent() == 0){
598 vtkRenderer* aRenderer = aWnd->getRenderer();
599 vtkActorCollection *aCollection = aRenderer->GetActors();
600 aCollection->InitTraversal();
601 while(vtkActor *anAct = aCollection->GetNextActor()){
602 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
604 if (!Update(anActor->getIO(),anActor->GetVisibility()))
605 break; // avoid multiple warinings if visu failed
609 SALOME_ListIteratorOfListIO anIter( selected );
610 for(; anIter.More(); anIter.Next()){
611 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
612 if ( !Update(anIO,true) )
613 break; // avoid multiple warinings if visu failed
616 RepaintCurrentView();
621 bool Update(const Handle(SALOME_InteractiveObject)& theIO,
624 _PTR(Study) aStudy = GetActiveStudyDocument();
625 CORBA::Long anId = aStudy->StudyId();
626 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
628 UpdateView(SMESH::eDisplay,theIO->getEntry());
635 void UpdateSelectionProp( SMESHGUI* theModule ) {
639 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
642 MESSAGE( "UpdateSelectionProp: Application is null" );
646 SUIT_ViewManager* vm = app->activeViewManager();
649 MESSAGE( "UpdateSelectionProp: View manager is null" );
653 QPtrVector<SUIT_ViewWindow> views = vm->getViews();
655 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
658 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
662 QColor aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
663 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
664 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
666 int SW = mgr->integerValue( "SMESH", "selection_width", 5 ),
667 PW = mgr->integerValue( "SMESH", "highlight_width", 5 );
669 double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
670 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
671 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
673 for ( int i=0, n=views.count(); i<n; i++ ){
674 // update VTK viewer properties
675 if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
676 // mesh element selection
677 aVtkView->SetSelectionProp(aSelColor.red()/255.,
678 aSelColor.green()/255.,
679 aSelColor.blue()/255.,
682 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
685 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
686 aPreColor.green()/255.,
687 aPreColor.blue()/255.,
690 vtkRenderer* aRenderer = aVtkView->getRenderer();
691 vtkActorCollection *aCollection = aRenderer->GetActors();
692 aCollection->InitTraversal();
693 while(vtkActor *anAct = aCollection->GetNextActor()){
694 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
695 anActor->SetHighlightColor(aHiColor.red()/255.,
696 aHiColor.green()/255.,
697 aHiColor.blue()/255.);
698 anActor->SetPreHighlightColor(aPreColor.red()/255.,
699 aPreColor.green()/255.,
700 aPreColor.blue()/255.);
708 //----------------------------------------------------------------------------
710 GetSelector(SUIT_ViewWindow *theWindow)
712 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
713 return aWnd->GetSelector();
718 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
719 SVTK_Selector* theSelector)
722 theSelector->SetFilter(theFilter);
725 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
727 return theSelector->GetFilter(theId);
730 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
732 return theSelector->IsFilterPresent(theId);
735 void RemoveFilter(int theId, SVTK_Selector* theSelector)
737 theSelector->RemoveFilter(theId);
740 void RemoveFilters(SVTK_Selector* theSelector)
742 for ( int id = SMESHGUI_NodeFilter; theSelector && id < SMESHGUI_LastFilter; id++ )
743 theSelector->RemoveFilter( id );
746 bool IsValid(SALOME_Actor* theActor, int theCellId,
747 SVTK_Selector* theSelector)
749 return theSelector->IsValid(theActor,theCellId);
753 //----------------------------------------------------------------------------
754 void SetPointRepresentation(bool theIsVisible){
755 if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
756 vtkRenderer *aRenderer = aViewWindow->getRenderer();
757 vtkActorCollection *aCollection = aRenderer->GetActors();
758 aCollection->InitTraversal();
759 while(vtkActor *anAct = aCollection->GetNextActor()){
760 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
761 if(anActor->GetVisibility()){
762 anActor->SetPointRepresentation(theIsVisible);
766 RepaintCurrentView();
771 void SetPickable(SMESH_Actor* theActor){
772 if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
773 int anIsAllPickable = (theActor == NULL);
774 vtkRenderer *aRenderer = aWnd->getRenderer();
775 vtkActorCollection *aCollection = aRenderer->GetActors();
776 aCollection->InitTraversal();
777 while(vtkActor *anAct = aCollection->GetNextActor()){
778 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
779 if(anActor->GetVisibility()){
780 anActor->SetPickable(anIsAllPickable);
785 theActor->SetPickable(!anIsAllPickable);
786 RepaintCurrentView();
791 //----------------------------------------------------------------------------
792 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
793 const Handle(SALOME_InteractiveObject)& theIO,
797 TColStd_IndexedMapOfInteger aMapIndex;
798 theSelector->GetIndex(theIO,aMapIndex);
800 for(int i = 1; i <= aMapIndex.Extent(); i++)
801 theName += QString(" %1").arg(aMapIndex(i));
803 return aMapIndex.Extent();
806 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
807 const Handle(SALOME_InteractiveObject)& theIO,
811 TColStd_IndexedMapOfInteger aMapIndex;
812 theSelector->GetIndex(theIO,aMapIndex);
814 typedef std::set<int> TIdContainer;
815 TIdContainer anIdContainer;
816 for( int i = 1; i <= aMapIndex.Extent(); i++)
817 anIdContainer.insert(aMapIndex(i));
819 TIdContainer::const_iterator anIter = anIdContainer.begin();
820 for(; anIter != anIdContainer.end(); anIter++)
821 theName += QString(" %1").arg(*anIter);
823 return aMapIndex.Extent();
827 int GetEdgeNodes(SVTK_Selector* theSelector,
828 const TVisualObjPtr& theVisualObject,
832 const SALOME_ListIO& selected = theSelector->StoredIObjects();
834 if ( selected.Extent() != 1 )
837 Handle(SALOME_InteractiveObject) anIO = selected.First();
838 if ( anIO.IsNull() || !anIO->hasEntry() )
841 TColStd_IndexedMapOfInteger aMapIndex;
842 theSelector->GetIndex( anIO, aMapIndex );
843 if ( aMapIndex.Extent() != 2 )
846 int anObjId = -1, anEdgeNum = -1;
847 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
848 int aVal = aMapIndex( i );
852 anEdgeNum = abs( aVal ) - 1;
855 if ( anObjId == -1 || anEdgeNum == -1 )
858 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
861 //----------------------------------------------------------------------------
862 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
863 const Handle(SALOME_InteractiveObject)& theIO,
867 if(theIO->hasEntry()){
868 if(FindActorByEntry(theIO->getEntry())){
869 TColStd_IndexedMapOfInteger aMapIndex;
870 theMgr->GetIndexes(theIO,aMapIndex);
871 for(int i = 1; i <= aMapIndex.Extent(); i++){
872 theName += QString(" %1").arg(aMapIndex(i));
874 return aMapIndex.Extent();
880 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName){
882 SALOME_ListIO selected; theMgr->selectedObjects( selected );
883 if(selected.Extent() == 1){
884 Handle(SALOME_InteractiveObject) anIO = selected.First();
885 return GetNameOfSelectedNodes(theMgr,anIO,theName);
891 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr,
892 const Handle(SALOME_InteractiveObject)& theIO,
896 if(theIO->hasEntry()){
897 if(FindActorByEntry(theIO->getEntry())){
898 TColStd_IndexedMapOfInteger aMapIndex;
899 theMgr->GetIndexes(theIO,aMapIndex);
900 typedef set<int> TIdContainer;
901 TIdContainer anIdContainer;
902 for( int i = 1; i <= aMapIndex.Extent(); i++)
903 anIdContainer.insert(aMapIndex(i));
904 TIdContainer::const_iterator anIter = anIdContainer.begin();
905 for(; anIter != anIdContainer.end(); anIter++){
906 theName += QString(" %1").arg(*anIter);
908 return aMapIndex.Extent();
915 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
918 SALOME_ListIO selected; theMgr->selectedObjects( selected );
920 if( selected.Extent() == 1){
921 Handle(SALOME_InteractiveObject) anIO = selected.First();
922 return GetNameOfSelectedElements(theMgr,anIO,theName);
927 int GetSelected(LightApp_SelectionMgr* theMgr,
928 TColStd_IndexedMapOfInteger& theMap,
929 const bool theIsElement)
932 SALOME_ListIO selected; theMgr->selectedObjects( selected );
934 if ( selected.Extent() == 1 )
936 Handle(SALOME_InteractiveObject) anIO = selected.First();
937 if ( anIO->hasEntry() ) {
938 theMgr->GetIndexes( anIO, theMap );
941 return theMap.Extent();
945 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
947 SALOME_ListIO selected; theMgr->selectedObjects( selected );
949 if ( selected.Extent() != 1 )
952 Handle(SALOME_InteractiveObject) anIO = selected.First();
953 if ( anIO.IsNull() || !anIO->hasEntry() )
956 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
960 TColStd_IndexedMapOfInteger aMapIndex;
961 theMgr->GetIndexes( anIO, aMapIndex );
962 if ( aMapIndex.Extent() != 2 )
965 int anObjId = -1, anEdgeNum = -1;
966 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
967 int aVal = aMapIndex( i );
971 anEdgeNum = abs( aVal );
974 if ( anObjId == -1 || anEdgeNum == -1 )
977 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
980 void SetControlsPrecision( const long theVal )
982 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
984 vtkRenderer *aRenderer = aWnd->getRenderer();
985 vtkActorCollection *aCollection = aRenderer->GetActors();
986 aCollection->InitTraversal();
988 while ( vtkActor *anAct = aCollection->GetNextActor())
990 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
992 anActor->SetControlsPrecision( theVal );
993 anActor->SetControlMode( anActor->GetControlMode() );