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 Allocate some memory at construction and release it at destruction.
80 * Is used to be able to continue working after mesh generation or visualization
81 * break due to lack of memory
83 //=============================================================================
88 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
89 void Free() { if (myBuf) { delete [] myBuf; myBuf = 0; }}
90 ~MemoryReserve() { Free(); }
92 static MemoryReserve* theVISU_MemoryReserve = new MemoryReserve;
94 //================================================================================
96 * \brief Remove VisualObj and its actor from all views
98 //================================================================================
100 void RemoveVisualObjectWithActors( const char* theEntry )
102 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
103 ( SUIT_Session::session()->activeApplication() );
104 SUIT_ViewManager* aViewManager =
105 app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
106 if ( aViewManager ) {
107 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
108 for ( int iV = 0; iV < views.count(); ++iV ) {
109 if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
110 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV]))
111 vtkWnd->RemoveActor(actor);
115 int aStudyId = aViewManager->study()->id();
116 TVisualObjCont::key_type aKey(aStudyId,theEntry);
117 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
118 if(anIter != VISUAL_OBJ_CONT.end()) {
119 // for unknown reason, object destructor is not called, so clear object manually
120 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
121 anIter->second->GetUnstructuredGrid()->SetPoints(0);
123 VISUAL_OBJ_CONT.erase(aKey);
126 //================================================================================
128 * \brief Remove all VisualObjs and their actors from all views
130 //================================================================================
132 void RemoveAllObjectsWithActors()
134 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
135 ( SUIT_Session::session()->activeApplication() );
137 ViewManagerList viewMgrs = app->viewManagers();
138 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
139 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
140 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type()) {
141 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
142 for ( int iV = 0; iV < views.count(); ++iV ) {
143 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
144 vtkRenderer *aRenderer = vtkWnd->getRenderer();
145 vtkActorCollection *actors = aRenderer->GetActors();
146 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
147 // size of actors changes inside the loop
148 while (SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
150 vtkWnd->RemoveActor(actor);
158 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
159 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
160 // for unknown reason, object destructor is not called, so clear object manually
161 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
162 anIter->second->GetUnstructuredGrid()->SetPoints(0);
164 VISUAL_OBJ_CONT.clear();
167 //================================================================================
169 * \brief Remove all VisualObjs of a study
171 //================================================================================
173 void RemoveVisuData(int studyID)
175 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
176 ( SUIT_Session::session()->activeApplication() );
178 ViewManagerList viewMgrs = app->viewManagers();
179 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
180 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
181 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type() &&
182 aViewManager->study()->id() == studyID ) {
183 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
184 for ( int iV = 0; iV < views.count(); ++iV ) {
185 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
186 vtkRenderer *aRenderer = vtkWnd->getRenderer();
187 vtkActorCollection *actors = aRenderer->GetActors();
188 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
189 // size of actors changes inside the loop
190 while(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
192 vtkWnd->RemoveActor(actor);
200 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
201 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
202 int curId = anIter->first.first;
203 if ( curId == studyID ) {
204 // for unknown reason, object destructor is not called, so clear object manually
205 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
206 anIter->second->GetUnstructuredGrid()->SetPoints(0);
207 VISUAL_OBJ_CONT.erase( anIter-- ); // dercement occures before erase()
212 //================================================================================
214 * \brief Notify the user on problems during visualization
216 //================================================================================
218 void OnVisuException()
221 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
224 // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
225 // after or at showing this message, so we do an additional check of available memory
226 // char* buf = new char[100*1024];
228 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
229 QObject::tr("SMESH_VISU_PROBLEM"),
230 QObject::tr("SMESH_BUT_OK"));
232 // no more memory at all: last resort
233 cout<< "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<endl;
234 cout<< "Try to remove all visual data..." <<endl;
235 if (theVISU_MemoryReserve) {
236 delete theVISU_MemoryReserve;
237 theVISU_MemoryReserve = 0;
239 RemoveAllObjectsWithActors();
240 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
241 QObject::tr("SMESH_VISU_PROBLEM_CLEAR"),
242 QObject::tr("SMESH_BUT_OK"));
243 cout<< "...done" << endl;
246 //================================================================================
248 * \brief Returns an updated visual object
250 //================================================================================
252 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
253 TVisualObjPtr aVisualObj;
254 TVisualObjCont::key_type aKey(theStudyId,theEntry);
256 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
259 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
260 if(anIter != VISUAL_OBJ_CONT.end()){
261 aVisualObj = anIter->second;
263 SalomeApp_Application* app =
264 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
265 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
266 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
268 _PTR(GenericAttribute) anAttr;
269 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
270 _PTR(AttributeIOR) anIOR = anAttr;
271 CORBA::String_var aVal = anIOR->Value().c_str();
272 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
273 if(!CORBA::is_nil(anObj)){
274 //Try narrow to SMESH_Mesh interface
275 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
276 if(!aMesh->_is_nil()){
277 aVisualObj.reset(new SMESH_MeshObj(aMesh));
278 TVisualObjCont::value_type aValue(aKey,aVisualObj);
279 VISUAL_OBJ_CONT.insert(aValue);
281 //Try narrow to SMESH_Group interface
282 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
283 if(!aGroup->_is_nil()){
284 _PTR(SObject) aFatherSObj = aSObj->GetFather();
285 if(!aFatherSObj) return aVisualObj;
286 aFatherSObj = aFatherSObj->GetFather();
287 if(!aFatherSObj) return aVisualObj;
288 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
289 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
290 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
291 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
292 TVisualObjCont::value_type aValue(aKey,aVisualObj);
293 VISUAL_OBJ_CONT.insert(aValue);
296 //Try narrow to SMESH_subMesh interface
297 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
298 if(!aSubMesh->_is_nil()){
299 _PTR(SObject) aFatherSObj = aSObj->GetFather();
300 if(!aFatherSObj) return aVisualObj;
301 aFatherSObj = aFatherSObj->GetFather();
302 if(!aFatherSObj) return aVisualObj;
303 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
304 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
305 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
306 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
307 TVisualObjCont::value_type aValue(aKey,aVisualObj);
308 VISUAL_OBJ_CONT.insert(aValue);
316 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
317 return TVisualObjPtr();
320 bool objModified = false;
323 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
326 objModified = aVisualObj->Update();
330 cout << "Exception in SMESHGUI_VTKUtils::GetVisualObj()" << endl;
332 RemoveVisualObjectWithActors( theEntry ); // remove this object
339 // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
340 // ~10 times more memory is used than it occupies.
341 // Warn the user if there is less free memory than 30 sizes of a grid
342 // TODO: estimate memory usage in other modes and take current mode into account
343 int freeMB = SMDS_Mesh::CheckMemory(true);
344 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
345 if ( freeMB > 0 && usedMB * 30 > freeMB ) {
347 cout << "SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB
348 << ", usedMB=" << usedMB<< endl;
351 if ( usedMB * 10 > freeMB )
352 // even dont try to show
353 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
354 QObject::tr("SMESH_NO_MESH_VISUALIZATION"),
355 QObject::tr("SMESH_BUT_OK"));
357 // there is a chance to succeed
358 continu = SUIT_MessageBox::warn2
359 (SMESHGUI::desktop(),
360 QObject::tr("SMESH_WRN_WARNING"),
361 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
362 QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"),
365 // remove the corresponding actors from all views
366 RemoveVisualObjectWithActors( theEntry );
376 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
377 * overwise find or create corresponding view window, make it active and return it.
378 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
380 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
381 bool createIfNotFound)
383 SalomeApp_Application* anApp;
385 anApp = theModule->getApp();
387 anApp = dynamic_cast<SalomeApp_Application*>
388 (SUIT_Session::session()->activeApplication());
391 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
394 SUIT_ViewManager* aViewManager =
395 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
397 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
398 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
399 aViewWindow->raise();
400 aViewWindow->setFocus();
409 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
410 SUIT_ViewWindow * theWindow)
415 QPtrVector<SUIT_ViewWindow> views = theMgr->getViews();
416 if( views.containsRef( theWindow ) )
417 return GetVtkViewWindow( theWindow );
422 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
423 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
426 /* SUIT_ViewWindow* GetActiveWindow()
428 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
431 SUIT_ViewManager* mgr = app->activeViewManager();
433 return mgr->getActiveView();
438 SVTK_ViewWindow* GetCurrentVtkView(){
439 return GetVtkViewWindow( GetActiveWindow() );
443 void RepaintCurrentView()
445 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
448 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
451 wnd->getRenderer()->Render();
456 cout << "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" << endl;
463 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
466 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
469 theWindow->getRenderer()->Render();
470 theWindow->Repaint();
474 cout << "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow)" << endl;
480 void RenderViewWindow(SVTK_ViewWindow* theWindow)
483 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
486 theWindow->getRenderer()->Render();
487 theWindow->Repaint();
491 cout << "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow)" << endl;
498 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
500 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
508 cout << "Exception in SMESHGUI_VTKUtils::FitAll()" << endl;
516 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
517 const char* theEntry)
519 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
520 vtkRenderer *aRenderer = aViewWindow->getRenderer();
521 vtkActorCollection *aCollection = aRenderer->GetActors();
522 aCollection->InitTraversal();
523 while(vtkActor *anAct = aCollection->GetNextActor()){
524 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
525 if(anActor->hasIO()){
526 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
527 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
538 SMESH_Actor* FindActorByEntry(const char* theEntry){
539 return FindActorByEntry(GetActiveWindow(),theEntry);
543 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
544 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
548 if(!CORBA::is_nil(theObject)){
549 _PTR(Study) aStudy = GetActiveStudyDocument();
550 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
551 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
553 CORBA::String_var anEntry = aSObject->GetID().c_str();
554 return FindActorByEntry(anEntry.in());
561 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
562 const char* theEntry,
565 SMESH_Actor *anActor = NULL;
566 CORBA::Long anId = theStudy->StudyId();
567 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
568 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
570 _PTR(GenericAttribute) anAttr;
571 if(aSObj->FindAttribute(anAttr,"AttributeName")){
572 _PTR(AttributeName) aName = anAttr;
573 std::string aNameVal = aName->Value();
574 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
577 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
578 if(!CORBA::is_nil(aGroup))
580 SALOMEDS::Color aColor = aGroup->GetColor();
581 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ) )
583 int r = 0, g = 0, b = 0;
584 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
585 aColor.R = (float)r / 255.0;
586 aColor.G = (float)g / 255.0;
587 aColor.B = (float)b / 255.0;
588 aGroup->SetColor( aColor );
590 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
598 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
599 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
601 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
604 vtkWnd->AddActor(theActor);
609 cout << "Exception in SMESHGUI_VTKUtils::DisplayActor()" << endl;
617 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
618 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
619 vtkWnd->RemoveActor(theActor);
620 if(theActor->hasIO()){
621 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
622 if(anIO->hasEntry()){
623 std::string anEntry = anIO->getEntry();
624 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
625 int aStudyId = aStudy->id();
626 TVisualObjCont::key_type aKey(aStudyId,anEntry);
627 VISUAL_OBJ_CONT.erase(aKey);
635 //================================================================================
637 * \brief Return true if there are no SMESH actors in a view
639 //================================================================================
641 bool noSmeshActors(SUIT_ViewWindow *theWnd)
643 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWnd)) {
644 vtkRenderer *aRenderer = aViewWindow->getRenderer();
645 vtkActorCollection *aCollection = aRenderer->GetActors();
646 aCollection->InitTraversal();
647 while(vtkActor *anAct = aCollection->GetNextActor())
648 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct))
654 bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
657 SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
663 vtkRenderer *aRenderer = aViewWnd->getRenderer();
664 vtkActorCollection *aCollection = aRenderer->GetActors();
665 aCollection->InitTraversal();
669 while (vtkActor *anAct = aCollection->GetNextActor()) {
670 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
671 anActor->SetVisibility(true);
678 while (vtkActor *anAct = aCollection->GetNextActor()) {
679 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
680 anActor->SetVisibility(false);
685 if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
689 anActor->SetVisibility(true);
690 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
693 anActor->SetVisibility(false);
701 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(theWnd->getViewManager()->study());
702 _PTR(Study) aDocument = aStudy->studyDS();
703 // Pass non-visual objects (hypotheses, etc.), return true in this case
704 CORBA::Long anId = aDocument->StudyId();
705 if (TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry))
707 if ((anActor = CreateActor(aDocument,theEntry,true))) {
708 bool needFitAll = noSmeshActors(theWnd); // fit for the first object only
709 DisplayActor(theWnd,anActor);
710 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
711 if (needFitAll) FitAll();
727 bool UpdateView(EDisplaing theAction, const char* theEntry){
728 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
729 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
730 SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
731 return UpdateView(aWnd,theAction,theEntry);
735 if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
736 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
737 SALOME_ListIO selected; mgr->selectedObjects( selected );
739 if( selected.Extent() == 0){
740 vtkRenderer* aRenderer = aWnd->getRenderer();
741 vtkActorCollection *aCollection = aRenderer->GetActors();
742 aCollection->InitTraversal();
743 while(vtkActor *anAct = aCollection->GetNextActor()){
744 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
746 if (!Update(anActor->getIO(),anActor->GetVisibility()))
747 break; // avoid multiple warinings if visu failed
751 SALOME_ListIteratorOfListIO anIter( selected );
752 for(; anIter.More(); anIter.Next()){
753 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
754 if ( !Update(anIO,true) )
755 break; // avoid multiple warinings if visu failed
758 RepaintCurrentView();
763 bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
765 _PTR(Study) aStudy = GetActiveStudyDocument();
766 CORBA::Long anId = aStudy->StudyId();
767 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
769 UpdateView(SMESH::eDisplay,theIO->getEntry());
776 void UpdateSelectionProp( SMESHGUI* theModule ) {
780 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
783 MESSAGE( "UpdateSelectionProp: Application is null" );
787 SUIT_ViewManager* vm = app->activeViewManager();
790 MESSAGE( "UpdateSelectionProp: View manager is null" );
794 QPtrVector<SUIT_ViewWindow> views = vm->getViews();
796 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
799 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
803 QColor aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
804 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
805 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
807 int SW = mgr->integerValue( "SMESH", "selection_width", 5 ),
808 PW = mgr->integerValue( "SMESH", "highlight_width", 5 );
810 double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
811 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
812 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
814 for ( int i=0, n=views.count(); i<n; i++ ){
815 // update VTK viewer properties
816 if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
817 // mesh element selection
818 aVtkView->SetSelectionProp(aSelColor.red()/255.,
819 aSelColor.green()/255.,
820 aSelColor.blue()/255.,
823 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
826 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
827 aPreColor.green()/255.,
828 aPreColor.blue()/255.,
831 vtkRenderer* aRenderer = aVtkView->getRenderer();
832 vtkActorCollection *aCollection = aRenderer->GetActors();
833 aCollection->InitTraversal();
834 while(vtkActor *anAct = aCollection->GetNextActor()){
835 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
836 anActor->SetHighlightColor(aHiColor.red()/255.,
837 aHiColor.green()/255.,
838 aHiColor.blue()/255.);
839 anActor->SetPreHighlightColor(aPreColor.red()/255.,
840 aPreColor.green()/255.,
841 aPreColor.blue()/255.);
849 //----------------------------------------------------------------------------
851 GetSelector(SUIT_ViewWindow *theWindow)
853 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
854 return aWnd->GetSelector();
859 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
860 SVTK_Selector* theSelector)
863 theSelector->SetFilter(theFilter);
866 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
868 return theSelector->GetFilter(theId);
871 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
873 return theSelector->IsFilterPresent(theId);
876 void RemoveFilter(int theId, SVTK_Selector* theSelector)
878 theSelector->RemoveFilter(theId);
881 void RemoveFilters(SVTK_Selector* theSelector)
883 for ( int id = SMESHGUI_NodeFilter; theSelector && id < SMESHGUI_LastFilter; id++ )
884 theSelector->RemoveFilter( id );
887 bool IsValid(SALOME_Actor* theActor, int theCellId,
888 SVTK_Selector* theSelector)
890 return theSelector->IsValid(theActor,theCellId);
894 //----------------------------------------------------------------------------
895 void SetPointRepresentation(bool theIsVisible){
896 if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
897 vtkRenderer *aRenderer = aViewWindow->getRenderer();
898 vtkActorCollection *aCollection = aRenderer->GetActors();
899 aCollection->InitTraversal();
900 while(vtkActor *anAct = aCollection->GetNextActor()){
901 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
902 if(anActor->GetVisibility()){
903 anActor->SetPointRepresentation(theIsVisible);
907 RepaintCurrentView();
912 void SetPickable(SMESH_Actor* theActor){
913 if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
914 int anIsAllPickable = (theActor == NULL);
915 vtkRenderer *aRenderer = aWnd->getRenderer();
916 vtkActorCollection *aCollection = aRenderer->GetActors();
917 aCollection->InitTraversal();
918 while(vtkActor *anAct = aCollection->GetNextActor()){
919 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
920 if(anActor->GetVisibility()){
921 anActor->SetPickable(anIsAllPickable);
926 theActor->SetPickable(!anIsAllPickable);
927 RepaintCurrentView();
932 //----------------------------------------------------------------------------
933 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
934 const Handle(SALOME_InteractiveObject)& theIO,
938 TColStd_IndexedMapOfInteger aMapIndex;
939 theSelector->GetIndex(theIO,aMapIndex);
941 for(int i = 1; i <= aMapIndex.Extent(); i++)
942 theName += QString(" %1").arg(aMapIndex(i));
944 return aMapIndex.Extent();
947 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
948 const Handle(SALOME_InteractiveObject)& theIO,
952 TColStd_IndexedMapOfInteger aMapIndex;
953 theSelector->GetIndex(theIO,aMapIndex);
955 typedef std::set<int> TIdContainer;
956 TIdContainer anIdContainer;
957 for( int i = 1; i <= aMapIndex.Extent(); i++)
958 anIdContainer.insert(aMapIndex(i));
960 TIdContainer::const_iterator anIter = anIdContainer.begin();
961 for(; anIter != anIdContainer.end(); anIter++)
962 theName += QString(" %1").arg(*anIter);
964 return aMapIndex.Extent();
968 int GetEdgeNodes(SVTK_Selector* theSelector,
969 const TVisualObjPtr& theVisualObject,
973 const SALOME_ListIO& selected = theSelector->StoredIObjects();
975 if ( selected.Extent() != 1 )
978 Handle(SALOME_InteractiveObject) anIO = selected.First();
979 if ( anIO.IsNull() || !anIO->hasEntry() )
982 TColStd_IndexedMapOfInteger aMapIndex;
983 theSelector->GetIndex( anIO, aMapIndex );
984 if ( aMapIndex.Extent() != 2 )
987 int anObjId = -1, anEdgeNum = -1;
988 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
989 int aVal = aMapIndex( i );
993 anEdgeNum = abs( aVal ) - 1;
996 if ( anObjId == -1 || anEdgeNum == -1 )
999 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1002 //----------------------------------------------------------------------------
1003 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1004 const Handle(SALOME_InteractiveObject)& theIO,
1008 if(theIO->hasEntry()){
1009 if(FindActorByEntry(theIO->getEntry())){
1010 TColStd_IndexedMapOfInteger aMapIndex;
1011 theMgr->GetIndexes(theIO,aMapIndex);
1012 for(int i = 1; i <= aMapIndex.Extent(); i++){
1013 theName += QString(" %1").arg(aMapIndex(i));
1015 return aMapIndex.Extent();
1021 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName){
1023 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1024 if(selected.Extent() == 1){
1025 Handle(SALOME_InteractiveObject) anIO = selected.First();
1026 return GetNameOfSelectedNodes(theMgr,anIO,theName);
1032 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr,
1033 const Handle(SALOME_InteractiveObject)& theIO,
1037 if(theIO->hasEntry()){
1038 if(FindActorByEntry(theIO->getEntry())){
1039 TColStd_IndexedMapOfInteger aMapIndex;
1040 theMgr->GetIndexes(theIO,aMapIndex);
1041 typedef set<int> TIdContainer;
1042 TIdContainer anIdContainer;
1043 for( int i = 1; i <= aMapIndex.Extent(); i++)
1044 anIdContainer.insert(aMapIndex(i));
1045 TIdContainer::const_iterator anIter = anIdContainer.begin();
1046 for(; anIter != anIdContainer.end(); anIter++){
1047 theName += QString(" %1").arg(*anIter);
1049 return aMapIndex.Extent();
1056 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1059 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1061 if( selected.Extent() == 1){
1062 Handle(SALOME_InteractiveObject) anIO = selected.First();
1063 return GetNameOfSelectedElements(theMgr,anIO,theName);
1068 int GetSelected(LightApp_SelectionMgr* theMgr,
1069 TColStd_IndexedMapOfInteger& theMap,
1070 const bool theIsElement)
1073 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1075 if ( selected.Extent() == 1 )
1077 Handle(SALOME_InteractiveObject) anIO = selected.First();
1078 if ( anIO->hasEntry() ) {
1079 theMgr->GetIndexes( anIO, theMap );
1082 return theMap.Extent();
1086 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
1088 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1090 if ( selected.Extent() != 1 )
1093 Handle(SALOME_InteractiveObject) anIO = selected.First();
1094 if ( anIO.IsNull() || !anIO->hasEntry() )
1097 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1101 TColStd_IndexedMapOfInteger aMapIndex;
1102 theMgr->GetIndexes( anIO, aMapIndex );
1103 if ( aMapIndex.Extent() != 2 )
1106 int anObjId = -1, anEdgeNum = -1;
1107 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1108 int aVal = aMapIndex( i );
1112 anEdgeNum = abs( aVal );
1115 if ( anObjId == -1 || anEdgeNum == -1 )
1118 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1121 void SetControlsPrecision( const long theVal )
1123 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1125 vtkRenderer *aRenderer = aWnd->getRenderer();
1126 vtkActorCollection *aCollection = aRenderer->GetActors();
1127 aCollection->InitTraversal();
1129 while ( vtkActor *anAct = aCollection->GetNextActor())
1131 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1133 anActor->SetControlsPrecision( theVal );
1134 anActor->SetControlMode( anActor->GetControlMode() );