1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SMESHGUI_VTKUtils.h"
23 #include "SMESHGUI_Utils.h"
24 #include "SMESHGUI_Filter.h"
27 #include "SMESH_Actor.h"
28 #include "SMESH_ActorUtils.h"
29 #include "SMESH_ObjectDef.h"
30 #include <SMDS_Mesh.hxx>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_Study.h>
35 #include <SUIT_MessageBox.h>
37 #include <SALOME_ListIO.hxx>
38 #include <SALOME_ListIteratorOfListIO.hxx>
40 #include <SVTK_Selector.h>
41 #include <SVTK_ViewModel.h>
42 #include <SVTK_ViewWindow.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <SalomeApp_Application.h>
46 #include <SalomeApp_Study.h>
48 #include <utilities.h>
50 #include <SALOMEconfig.h>
51 #include CORBA_CLIENT_HEADER(SMESH_Gen)
52 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
53 #include CORBA_CLIENT_HEADER(SMESH_Group)
54 #include CORBA_CLIENT_HEADER(SMESH_Hypothesis)
56 #include <SALOMEDSClient_Study.hxx>
57 #include <SALOMEDSClient_SObject.hxx>
60 #include <vtkRenderer.h>
61 #include <vtkActorCollection.h>
62 #include <vtkUnstructuredGrid.h>
65 #include <TColStd_IndexedMapOfInteger.hxx>
66 #include <Standard_ErrorHandler.hxx>
75 typedef map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
76 static TVisualObjCont VISUAL_OBJ_CONT;
78 //=============================================================================
80 * \brief Allocate some memory at construction and release it at destruction.
81 * Is used to be able to continue working after mesh generation or visualization
82 * break due to lack of memory
84 //=============================================================================
89 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
90 void Free() { if (myBuf) { delete [] myBuf; myBuf = 0; }}
91 ~MemoryReserve() { Free(); }
93 static MemoryReserve* theVISU_MemoryReserve = new MemoryReserve;
95 //================================================================================
97 * \brief Remove VisualObj and its actor from all views
99 //================================================================================
101 void RemoveVisualObjectWithActors( const char* theEntry )
103 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
104 ( SUIT_Session::session()->activeApplication() );
105 SUIT_ViewManager* aViewManager =
106 app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
107 if ( aViewManager ) {
108 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
109 for ( int iV = 0; iV < views.count(); ++iV ) {
110 if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
111 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV]))
112 vtkWnd->RemoveActor(actor);
116 int aStudyId = aViewManager->study()->id();
117 TVisualObjCont::key_type aKey(aStudyId,theEntry);
118 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
119 if(anIter != VISUAL_OBJ_CONT.end()) {
120 // for unknown reason, object destructor is not called, so clear object manually
121 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
122 anIter->second->GetUnstructuredGrid()->SetPoints(0);
124 VISUAL_OBJ_CONT.erase(aKey);
127 //================================================================================
129 * \brief Remove all VisualObjs and their actors from all views
131 //================================================================================
133 void RemoveAllObjectsWithActors()
135 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
136 ( SUIT_Session::session()->activeApplication() );
138 ViewManagerList viewMgrs = app->viewManagers();
139 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
140 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
141 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type()) {
142 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
143 for ( int iV = 0; iV < views.count(); ++iV ) {
144 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
145 vtkRenderer *aRenderer = vtkWnd->getRenderer();
146 vtkActorCollection *actors = aRenderer->GetActors();
147 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
148 // size of actors changes inside the loop
149 while (SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
151 vtkWnd->RemoveActor(actor);
159 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
160 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
161 // for unknown reason, object destructor is not called, so clear object manually
162 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
163 anIter->second->GetUnstructuredGrid()->SetPoints(0);
165 VISUAL_OBJ_CONT.clear();
168 //================================================================================
170 * \brief Remove all VisualObjs of a study
172 //================================================================================
174 void RemoveVisuData(int studyID)
176 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
177 ( SUIT_Session::session()->activeApplication() );
179 ViewManagerList viewMgrs = app->viewManagers();
180 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
181 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
182 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type() &&
183 aViewManager->study()->id() == studyID ) {
184 QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
185 for ( int iV = 0; iV < views.count(); ++iV ) {
186 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
187 vtkRenderer *aRenderer = vtkWnd->getRenderer();
188 vtkActorCollection *actors = aRenderer->GetActors();
189 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
190 // size of actors changes inside the loop
191 while(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
193 vtkWnd->RemoveActor(actor);
201 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
202 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
203 int curId = anIter->first.first;
204 if ( curId == studyID ) {
205 // for unknown reason, object destructor is not called, so clear object manually
206 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
207 anIter->second->GetUnstructuredGrid()->SetPoints(0);
208 VISUAL_OBJ_CONT.erase( anIter-- ); // dercement occures before erase()
213 //================================================================================
215 * \brief Notify the user on problems during visualization
217 //================================================================================
219 void OnVisuException()
222 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
225 // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
226 // after or at showing this message, so we do an additional check of available memory
227 // char* buf = new char[100*1024];
229 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
230 QObject::tr("SMESH_VISU_PROBLEM"),
231 QObject::tr("SMESH_BUT_OK"));
233 // no more memory at all: last resort
234 MESSAGE_BEGIN ( "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<
235 std::endl << "Try to remove all visual data..." );
236 if (theVISU_MemoryReserve) {
237 delete theVISU_MemoryReserve;
238 theVISU_MemoryReserve = 0;
240 RemoveAllObjectsWithActors();
241 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
242 QObject::tr("SMESH_VISU_PROBLEM_CLEAR"),
243 QObject::tr("SMESH_BUT_OK"));
244 MESSAGE_END ( "...done" );
247 //================================================================================
249 * \brief Returns an updated visual object
251 //================================================================================
253 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
254 TVisualObjPtr aVisualObj;
255 TVisualObjCont::key_type aKey(theStudyId,theEntry);
257 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
260 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
261 if(anIter != VISUAL_OBJ_CONT.end()){
262 aVisualObj = anIter->second;
264 SalomeApp_Application* app =
265 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
266 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
267 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
269 _PTR(GenericAttribute) anAttr;
270 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
271 _PTR(AttributeIOR) anIOR = anAttr;
272 CORBA::String_var aVal = anIOR->Value().c_str();
273 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
274 if(!CORBA::is_nil(anObj)){
275 //Try narrow to SMESH_Mesh interface
276 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
277 if(!aMesh->_is_nil()){
278 aVisualObj.reset(new SMESH_MeshObj(aMesh));
279 TVisualObjCont::value_type aValue(aKey,aVisualObj);
280 VISUAL_OBJ_CONT.insert(aValue);
282 //Try narrow to SMESH_Group interface
283 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
284 if(!aGroup->_is_nil()){
285 _PTR(SObject) aFatherSObj = aSObj->GetFather();
286 if(!aFatherSObj) return aVisualObj;
287 aFatherSObj = aFatherSObj->GetFather();
288 if(!aFatherSObj) return aVisualObj;
289 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
290 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
291 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
292 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
293 TVisualObjCont::value_type aValue(aKey,aVisualObj);
294 VISUAL_OBJ_CONT.insert(aValue);
297 //Try narrow to SMESH_subMesh interface
298 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
299 if(!aSubMesh->_is_nil()){
300 _PTR(SObject) aFatherSObj = aSObj->GetFather();
301 if(!aFatherSObj) return aVisualObj;
302 aFatherSObj = aFatherSObj->GetFather();
303 if(!aFatherSObj) return aVisualObj;
304 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
305 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
306 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
307 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
308 TVisualObjCont::value_type aValue(aKey,aVisualObj);
309 VISUAL_OBJ_CONT.insert(aValue);
317 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
318 return TVisualObjPtr();
321 bool objModified = false;
324 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
327 objModified = aVisualObj->Update();
331 MESSAGE ( "Exception in SMESHGUI_VTKUtils::GetVisualObj()" );
333 RemoveVisualObjectWithActors( theEntry ); // remove this object
340 // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
341 // ~10 times more memory is used than it occupies.
342 // Warn the user if there is less free memory than 30 sizes of a grid
343 // TODO: estimate memory usage in other modes and take current mode into account
344 int freeMB = SMDS_Mesh::CheckMemory(true);
345 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
346 if ( freeMB > 0 && usedMB * 30 > freeMB ) {
348 MESSAGE ( "SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB
349 << ", usedMB=" << usedMB );
352 if ( usedMB * 10 > freeMB )
353 // even dont try to show
354 SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
355 QObject::tr("SMESH_NO_MESH_VISUALIZATION"),
356 QObject::tr("SMESH_BUT_OK"));
358 // there is a chance to succeed
359 continu = SUIT_MessageBox::warn2
360 (SMESHGUI::desktop(),
361 QObject::tr("SMESH_WRN_WARNING"),
362 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
363 QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"),
366 // remove the corresponding actors from all views
367 RemoveVisualObjectWithActors( theEntry );
377 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
378 * overwise find or create corresponding view window, make it active and return it.
379 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
381 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
382 bool createIfNotFound)
384 SalomeApp_Application* anApp;
386 anApp = theModule->getApp();
388 anApp = dynamic_cast<SalomeApp_Application*>
389 (SUIT_Session::session()->activeApplication());
392 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
395 SUIT_ViewManager* aViewManager =
396 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
398 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
399 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
400 aViewWindow->raise();
401 aViewWindow->setFocus();
410 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
411 SUIT_ViewWindow * theWindow)
416 QPtrVector<SUIT_ViewWindow> views = theMgr->getViews();
417 if( views.containsRef( theWindow ) )
418 return GetVtkViewWindow( theWindow );
423 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
424 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
427 /* SUIT_ViewWindow* GetActiveWindow()
429 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
432 SUIT_ViewManager* mgr = app->activeViewManager();
434 return mgr->getActiveView();
439 SVTK_ViewWindow* GetCurrentVtkView(){
440 return GetVtkViewWindow( GetActiveWindow() );
444 void RepaintCurrentView()
446 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
449 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
452 wnd->getRenderer()->Render();
457 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" );
464 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
467 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
470 theWindow->getRenderer()->Render();
471 theWindow->Repaint();
475 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow)" );
481 void RenderViewWindow(SVTK_ViewWindow* theWindow)
484 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
487 theWindow->getRenderer()->Render();
488 theWindow->Repaint();
492 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow)" );
499 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
501 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
509 MESSAGE ( "Exception in SMESHGUI_VTKUtils::FitAll()" );
517 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
518 const char* theEntry)
520 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
521 vtkRenderer *aRenderer = aViewWindow->getRenderer();
522 vtkActorCollection *aCollection = aRenderer->GetActors();
523 aCollection->InitTraversal();
524 while(vtkActor *anAct = aCollection->GetNextActor()){
525 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
526 if(anActor->hasIO()){
527 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
528 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
539 SMESH_Actor* FindActorByEntry(const char* theEntry){
540 return FindActorByEntry(GetActiveWindow(),theEntry);
544 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
545 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
549 if(!CORBA::is_nil(theObject)){
550 _PTR(Study) aStudy = GetActiveStudyDocument();
551 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
552 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
554 CORBA::String_var anEntry = aSObject->GetID().c_str();
555 return FindActorByEntry(anEntry.in());
562 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
563 const char* theEntry,
566 SMESH_Actor *anActor = NULL;
567 CORBA::Long anId = theStudy->StudyId();
568 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
569 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
571 _PTR(GenericAttribute) anAttr;
572 if(aSObj->FindAttribute(anAttr,"AttributeName")){
573 _PTR(AttributeName) aName = anAttr;
574 std::string aNameVal = aName->Value();
575 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
578 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
579 if(!CORBA::is_nil(aGroup))
581 SALOMEDS::Color aColor = aGroup->GetColor();
582 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ) )
584 int r = 0, g = 0, b = 0;
585 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
586 aColor.R = (float)r / 255.0;
587 aColor.G = (float)g / 255.0;
588 aColor.B = (float)b / 255.0;
589 aGroup->SetColor( aColor );
591 if( aGroup->GetType() == SMESH::NODE )
592 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
593 else if( aGroup->GetType() == SMESH::EDGE )
594 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
596 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
604 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
605 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
607 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
610 vtkWnd->AddActor(theActor);
615 MESSAGE ( "Exception in SMESHGUI_VTKUtils::DisplayActor()" );
623 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
624 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
625 vtkWnd->RemoveActor(theActor);
626 if(theActor->hasIO()){
627 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
628 if(anIO->hasEntry()){
629 std::string anEntry = anIO->getEntry();
630 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
631 int aStudyId = aStudy->id();
632 TVisualObjCont::key_type aKey(aStudyId,anEntry);
633 VISUAL_OBJ_CONT.erase(aKey);
641 //================================================================================
643 * \brief Return true if there are no SMESH actors in a view
645 //================================================================================
647 bool noSmeshActors(SUIT_ViewWindow *theWnd)
649 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWnd)) {
650 vtkRenderer *aRenderer = aViewWindow->getRenderer();
651 vtkActorCollection *aCollection = aRenderer->GetActors();
652 aCollection->InitTraversal();
653 while(vtkActor *anAct = aCollection->GetNextActor())
654 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct))
660 bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
663 SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
669 vtkRenderer *aRenderer = aViewWnd->getRenderer();
670 vtkActorCollection *aCollection = aRenderer->GetActors();
671 aCollection->InitTraversal();
675 while (vtkActor *anAct = aCollection->GetNextActor()) {
676 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
677 anActor->SetVisibility(true);
684 while (vtkActor *anAct = aCollection->GetNextActor()) {
685 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
686 anActor->SetVisibility(false);
691 if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
695 anActor->SetVisibility(true);
696 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
699 anActor->SetVisibility(false);
707 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(theWnd->getViewManager()->study());
708 _PTR(Study) aDocument = aStudy->studyDS();
709 // Pass non-visual objects (hypotheses, etc.), return true in this case
710 CORBA::Long anId = aDocument->StudyId();
711 if (TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry))
713 if ((anActor = CreateActor(aDocument,theEntry,true))) {
714 bool needFitAll = noSmeshActors(theWnd); // fit for the first object only
715 DisplayActor(theWnd,anActor);
716 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
717 if (needFitAll) FitAll();
733 bool UpdateView(EDisplaing theAction, const char* theEntry){
734 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
735 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
736 SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
737 return UpdateView(aWnd,theAction,theEntry);
741 if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
742 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
743 SALOME_ListIO selected; mgr->selectedObjects( selected );
745 if( selected.Extent() == 0){
746 vtkRenderer* aRenderer = aWnd->getRenderer();
747 vtkActorCollection *aCollection = aRenderer->GetActors();
748 aCollection->InitTraversal();
749 while(vtkActor *anAct = aCollection->GetNextActor()){
750 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
752 if (!Update(anActor->getIO(),anActor->GetVisibility()))
753 break; // avoid multiple warinings if visu failed
757 SALOME_ListIteratorOfListIO anIter( selected );
758 for(; anIter.More(); anIter.Next()){
759 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
760 if ( !Update(anIO,true) )
761 break; // avoid multiple warinings if visu failed
764 RepaintCurrentView();
769 bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
771 _PTR(Study) aStudy = GetActiveStudyDocument();
772 CORBA::Long anId = aStudy->StudyId();
773 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
775 UpdateView(SMESH::eDisplay,theIO->getEntry());
782 void UpdateSelectionProp( SMESHGUI* theModule ) {
786 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
789 MESSAGE( "UpdateSelectionProp: Application is null" );
793 SUIT_ViewManager* vm = app->activeViewManager();
796 MESSAGE( "UpdateSelectionProp: View manager is null" );
800 QPtrVector<SUIT_ViewWindow> views = vm->getViews();
802 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
805 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
809 QColor aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
810 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
811 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
813 int SW = mgr->integerValue( "SMESH", "selection_width", 5 ),
814 PW = mgr->integerValue( "SMESH", "highlight_width", 5 );
816 double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
817 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
818 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
820 for ( int i=0, n=views.count(); i<n; i++ ){
821 // update VTK viewer properties
822 if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
823 // mesh element selection
824 aVtkView->SetSelectionProp(aSelColor.red()/255.,
825 aSelColor.green()/255.,
826 aSelColor.blue()/255.,
829 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
832 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
833 aPreColor.green()/255.,
834 aPreColor.blue()/255.,
837 vtkRenderer* aRenderer = aVtkView->getRenderer();
838 vtkActorCollection *aCollection = aRenderer->GetActors();
839 aCollection->InitTraversal();
840 while(vtkActor *anAct = aCollection->GetNextActor()){
841 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
842 anActor->SetHighlightColor(aHiColor.red()/255.,
843 aHiColor.green()/255.,
844 aHiColor.blue()/255.);
845 anActor->SetPreHighlightColor(aPreColor.red()/255.,
846 aPreColor.green()/255.,
847 aPreColor.blue()/255.);
855 //----------------------------------------------------------------------------
857 GetSelector(SUIT_ViewWindow *theWindow)
859 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
860 return aWnd->GetSelector();
865 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
866 SVTK_Selector* theSelector)
869 theSelector->SetFilter(theFilter);
872 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
874 return theSelector->GetFilter(theId);
877 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
879 return theSelector->IsFilterPresent(theId);
882 void RemoveFilter(int theId, SVTK_Selector* theSelector)
884 theSelector->RemoveFilter(theId);
887 void RemoveFilters(SVTK_Selector* theSelector)
889 for ( int id = SMESHGUI_NodeFilter; theSelector && id < SMESHGUI_LastFilter; id++ )
890 theSelector->RemoveFilter( id );
893 bool IsValid(SALOME_Actor* theActor, int theCellId,
894 SVTK_Selector* theSelector)
896 return theSelector->IsValid(theActor,theCellId);
900 //----------------------------------------------------------------------------
901 void SetPointRepresentation(bool theIsVisible){
902 if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
903 vtkRenderer *aRenderer = aViewWindow->getRenderer();
904 vtkActorCollection *aCollection = aRenderer->GetActors();
905 aCollection->InitTraversal();
906 while(vtkActor *anAct = aCollection->GetNextActor()){
907 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
908 if(anActor->GetVisibility()){
909 anActor->SetPointRepresentation(theIsVisible);
913 RepaintCurrentView();
918 void SetPickable(SMESH_Actor* theActor){
919 if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
920 int anIsAllPickable = (theActor == NULL);
921 vtkRenderer *aRenderer = aWnd->getRenderer();
922 vtkActorCollection *aCollection = aRenderer->GetActors();
923 aCollection->InitTraversal();
924 while(vtkActor *anAct = aCollection->GetNextActor()){
925 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
926 if(anActor->GetVisibility()){
927 anActor->SetPickable(anIsAllPickable);
932 theActor->SetPickable(!anIsAllPickable);
933 RepaintCurrentView();
938 //----------------------------------------------------------------------------
939 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
940 const Handle(SALOME_InteractiveObject)& theIO,
944 TColStd_IndexedMapOfInteger aMapIndex;
945 theSelector->GetIndex(theIO,aMapIndex);
947 for(int i = 1; i <= aMapIndex.Extent(); i++)
948 theName += QString(" %1").arg(aMapIndex(i));
950 return aMapIndex.Extent();
953 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
954 const Handle(SALOME_InteractiveObject)& theIO,
958 TColStd_IndexedMapOfInteger aMapIndex;
959 theSelector->GetIndex(theIO,aMapIndex);
961 typedef std::set<int> TIdContainer;
962 TIdContainer anIdContainer;
963 for( int i = 1; i <= aMapIndex.Extent(); i++)
964 anIdContainer.insert(aMapIndex(i));
966 TIdContainer::const_iterator anIter = anIdContainer.begin();
967 for(; anIter != anIdContainer.end(); anIter++)
968 theName += QString(" %1").arg(*anIter);
970 return aMapIndex.Extent();
974 int GetEdgeNodes(SVTK_Selector* theSelector,
975 const TVisualObjPtr& theVisualObject,
979 const SALOME_ListIO& selected = theSelector->StoredIObjects();
981 if ( selected.Extent() != 1 )
984 Handle(SALOME_InteractiveObject) anIO = selected.First();
985 if ( anIO.IsNull() || !anIO->hasEntry() )
988 TColStd_IndexedMapOfInteger aMapIndex;
989 theSelector->GetIndex( anIO, aMapIndex );
990 if ( aMapIndex.Extent() != 2 )
993 int anObjId = -1, anEdgeNum = -1;
994 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
995 int aVal = aMapIndex( i );
999 anEdgeNum = abs( aVal ) - 1;
1002 if ( anObjId == -1 || anEdgeNum == -1 )
1005 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1008 //----------------------------------------------------------------------------
1009 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1010 const Handle(SALOME_InteractiveObject)& theIO,
1014 if(theIO->hasEntry()){
1015 if(FindActorByEntry(theIO->getEntry())){
1016 TColStd_IndexedMapOfInteger aMapIndex;
1017 theMgr->GetIndexes(theIO,aMapIndex);
1018 for(int i = 1; i <= aMapIndex.Extent(); i++){
1019 theName += QString(" %1").arg(aMapIndex(i));
1021 return aMapIndex.Extent();
1027 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName){
1029 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1030 if(selected.Extent() == 1){
1031 Handle(SALOME_InteractiveObject) anIO = selected.First();
1032 return GetNameOfSelectedNodes(theMgr,anIO,theName);
1038 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr,
1039 const Handle(SALOME_InteractiveObject)& theIO,
1043 if(theIO->hasEntry()){
1044 if(FindActorByEntry(theIO->getEntry())){
1045 TColStd_IndexedMapOfInteger aMapIndex;
1046 theMgr->GetIndexes(theIO,aMapIndex);
1047 typedef set<int> TIdContainer;
1048 TIdContainer anIdContainer;
1049 for( int i = 1; i <= aMapIndex.Extent(); i++)
1050 anIdContainer.insert(aMapIndex(i));
1051 TIdContainer::const_iterator anIter = anIdContainer.begin();
1052 for(; anIter != anIdContainer.end(); anIter++){
1053 theName += QString(" %1").arg(*anIter);
1055 return aMapIndex.Extent();
1062 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1065 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1067 if( selected.Extent() == 1){
1068 Handle(SALOME_InteractiveObject) anIO = selected.First();
1069 return GetNameOfSelectedElements(theMgr,anIO,theName);
1074 int GetSelected(LightApp_SelectionMgr* theMgr,
1075 TColStd_IndexedMapOfInteger& theMap,
1076 const bool theIsElement)
1079 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1081 if ( selected.Extent() == 1 )
1083 Handle(SALOME_InteractiveObject) anIO = selected.First();
1084 if ( anIO->hasEntry() ) {
1085 theMgr->GetIndexes( anIO, theMap );
1088 return theMap.Extent();
1092 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
1094 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1096 if ( selected.Extent() != 1 )
1099 Handle(SALOME_InteractiveObject) anIO = selected.First();
1100 if ( anIO.IsNull() || !anIO->hasEntry() )
1103 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1107 TColStd_IndexedMapOfInteger aMapIndex;
1108 theMgr->GetIndexes( anIO, aMapIndex );
1109 if ( aMapIndex.Extent() != 2 )
1112 int anObjId = -1, anEdgeNum = -1;
1113 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1114 int aVal = aMapIndex( i );
1118 anEdgeNum = abs( aVal );
1121 if ( anObjId == -1 || anEdgeNum == -1 )
1124 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1127 void SetControlsPrecision( const long theVal )
1129 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1131 vtkRenderer *aRenderer = aWnd->getRenderer();
1132 vtkActorCollection *aCollection = aRenderer->GetActors();
1133 aCollection->InitTraversal();
1135 while ( vtkActor *anAct = aCollection->GetNextActor())
1137 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1139 anActor->SetControlsPrecision( theVal );
1140 anActor->SetControlMode( anActor->GetControlMode() );