1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_VTKUtils.cxx
25 // Author : Open CASCADE S.A.S.
28 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_Filter.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMDS_Mesh.hxx"
34 #include "SMESH_Actor.h"
35 #include "SMESH_ActorUtils.h"
36 #include "SMESH_CellLabelActor.h"
37 #include "SMESH_ControlsDef.hxx"
38 #include "SMESH_NodeLabelActor.h"
39 #include "SMESH_ObjectDef.h"
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_ResourceMgr.h>
48 #include <SALOME_ListIO.hxx>
50 #include <SVTK_Selector.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
54 #include <VTKViewer_Algorithm.h>
56 #include <LightApp_SelectionMgr.h>
57 #include <SalomeApp_Application.h>
58 #include <SalomeApp_Study.h>
60 // SALOME KERNEL includes
61 #include <utilities.h>
64 #include <SALOMEconfig.h>
65 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
66 #include CORBA_CLIENT_HEADER(SMESH_Group)
70 #include <vtkRenderer.h>
71 #include <vtkActorCollection.h>
72 #include <vtkUnstructuredGrid.h>
75 #include <Standard_ErrorHandler.hxx>
79 typedef std::map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
80 static TVisualObjCont VISUAL_OBJ_CONT;
82 //=============================================================================
84 * \brief Allocate some memory at construction and release it at destruction.
85 * Is used to be able to continue working after mesh generation or visualization
86 * break due to lack of memory
88 //=============================================================================
93 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
94 void Free() { if (myBuf) { delete [] myBuf; myBuf = 0; }}
95 ~MemoryReserve() { Free(); }
97 static MemoryReserve* theVISU_MemoryReserve = new MemoryReserve;
99 //================================================================================
101 * \brief Remove VisualObj and its actor from all views
103 //================================================================================
105 void RemoveVisualObjectWithActors( const char* theEntry, bool fromAllViews )
107 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
110 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
113 ViewManagerList aList;
116 app->viewManagers(SVTK_Viewer::Type() , aList);
118 SUIT_ViewManager* aVM = app->getViewManager(SVTK_Viewer::Type(), true);
122 bool actorRemoved = false;
123 ViewManagerList::ConstIterator it = aList.begin();
124 SUIT_ViewManager* aViewManager = 0;
125 for( ; it!=aList.end();it++) {
127 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
128 for ( int iV = 0; iV < views.count(); ++iV ) {
129 if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
130 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
131 vtkWnd->RemoveActor(actor);
140 int aStudyId = aViewManager->study()->id();
141 TVisualObjCont::key_type aKey(aStudyId,theEntry);
142 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
143 if(anIter != VISUAL_OBJ_CONT.end()) {
144 // for unknown reason, object destructor is not called, so clear object manually
145 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
146 anIter->second->GetUnstructuredGrid()->SetPoints(0);
148 VISUAL_OBJ_CONT.erase(aKey);
152 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
154 //================================================================================
156 * \brief Remove all VisualObjs and their actors from all views
158 //================================================================================
160 void RemoveAllObjectsWithActors()
162 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
163 ( SUIT_Session::session()->activeApplication() );
165 ViewManagerList viewMgrs = app->viewManagers();
166 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
167 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
168 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type()) {
169 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
170 for ( int iV = 0; iV < views.count(); ++iV ) {
171 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
172 vtkRenderer *aRenderer = vtkWnd->getRenderer();
173 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
174 vtkActorCollection *actors = aCopy.GetActors();
175 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
176 // size of actors changes inside the loop
177 if (SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
179 vtkWnd->RemoveActor(actor);
187 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
188 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
189 // for unknown reason, object destructor is not called, so clear object manually
190 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
191 anIter->second->GetUnstructuredGrid()->SetPoints(0);
193 VISUAL_OBJ_CONT.clear();
196 //================================================================================
198 * \brief Remove all VisualObjs of a study
200 //================================================================================
202 void RemoveVisuData(int studyID)
204 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
205 ( SUIT_Session::session()->activeApplication() );
207 ViewManagerList viewMgrs = app->viewManagers();
208 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
209 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
210 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type() &&
211 aViewManager->study()->id() == studyID ) {
212 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
213 for ( int iV = 0; iV < views.count(); ++iV ) {
214 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
215 vtkRenderer *aRenderer = vtkWnd->getRenderer();
216 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
217 vtkActorCollection *actors = aCopy.GetActors();
218 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
219 // size of actors changes inside the loop
220 if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
222 vtkWnd->RemoveActor(actor);
230 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
231 for ( ; anIter != VISUAL_OBJ_CONT.end(); ) {
232 int curId = anIter->first.first;
233 if ( curId == studyID ) {
234 // for unknown reason, object destructor is not called, so clear object manually
235 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
236 anIter->second->GetUnstructuredGrid()->SetPoints(0);
237 VISUAL_OBJ_CONT.erase( anIter++ ); // anIter++ returns a copy of self before incrementing
245 //================================================================================
247 * \brief Notify the user on problems during visualization
249 //================================================================================
251 void OnVisuException()
255 // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
256 // after or at showing this message, so we do an additional check of available memory
257 // char* buf = new char[100*1024];
259 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
260 QObject::tr("SMESH_VISU_PROBLEM"));
262 // no more memory at all: last resort
263 MESSAGE_BEGIN ( "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<
264 std::endl << "Try to remove all visual data..." );
265 if (theVISU_MemoryReserve) {
266 delete theVISU_MemoryReserve;
267 theVISU_MemoryReserve = 0;
269 RemoveAllObjectsWithActors();
270 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
271 QObject::tr("SMESH_VISU_PROBLEM_CLEAR"));
272 MESSAGE_END ( "...done" );
275 //================================================================================
277 * \brief Returns an updated visual object
279 //================================================================================
281 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry, bool nulData){
282 TVisualObjPtr aVisualObj;
283 TVisualObjCont::key_type aKey(theStudyId,theEntry);
286 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
287 if(anIter != VISUAL_OBJ_CONT.end()){
288 aVisualObj = anIter->second;
290 SalomeApp_Application* app =
291 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
292 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
293 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
295 _PTR(GenericAttribute) anAttr;
296 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
297 _PTR(AttributeIOR) anIOR = anAttr;
298 CORBA::String_var aVal = anIOR->Value().c_str();
299 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
300 if(!CORBA::is_nil(anObj)){
301 //Try narrow to SMESH_Mesh interface
302 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
303 if(!aMesh->_is_nil()){
304 aVisualObj.reset(new SMESH_MeshObj(aMesh));
305 TVisualObjCont::value_type aValue(aKey,aVisualObj);
306 VISUAL_OBJ_CONT.insert(aValue);
308 //Try narrow to SMESH_Group interface
309 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
310 if(!aGroup->_is_nil()){
311 _PTR(SObject) aFatherSObj = aSObj->GetFather();
312 if(!aFatherSObj) return aVisualObj;
313 aFatherSObj = aFatherSObj->GetFather();
314 if(!aFatherSObj) return aVisualObj;
315 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
316 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
317 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
318 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
319 TVisualObjCont::value_type aValue(aKey,aVisualObj);
320 VISUAL_OBJ_CONT.insert(aValue);
323 //Try narrow to SMESH_subMesh interface
324 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
325 if(!aSubMesh->_is_nil()){
326 _PTR(SObject) aFatherSObj = aSObj->GetFather();
327 if(!aFatherSObj) return aVisualObj;
328 aFatherSObj = aFatherSObj->GetFather();
329 if(!aFatherSObj) return aVisualObj;
330 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
331 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
332 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
333 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
334 TVisualObjCont::value_type aValue(aKey,aVisualObj);
335 VISUAL_OBJ_CONT.insert(aValue);
343 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
344 return TVisualObjPtr();
347 bool objModified = false;
352 objModified = aVisualObj->NulData();
354 objModified = aVisualObj->Update();
357 MESSAGE ( "Exception in SMESHGUI_VTKUtils::GetVisualObj()" );
358 RemoveVisualObjectWithActors( theEntry ); // remove this object
365 // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
366 // ~5 times more memory is used than it occupies.
367 // Warn the user if there is less free memory than 30 sizes of a grid
368 // TODO: estimate memory usage in other modes and take current mode into account
369 int freeMB = SMDS_Mesh::CheckMemory(true);
370 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
371 //MESSAGE("SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB << ", usedMB=" <<usedMB);
372 if ( freeMB > 0 && usedMB * 5 > freeMB ) {
373 bool continu = false;
374 if ( usedMB * 3 > freeMB )
375 // don't even try to show
376 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
377 QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
379 // there is a chance to succeed
380 continu = SUIT_MessageBox::warning
381 (SMESHGUI::desktop(),
382 QObject::tr("SMESH_WRN_WARNING"),
383 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
384 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
385 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
387 // remove the corresponding actors from all views
388 RemoveVisualObjectWithActors( theEntry );
398 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
399 * overwise find or create corresponding view window, make it active and return it.
400 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
402 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
403 bool createIfNotFound)
405 SalomeApp_Application* anApp;
407 anApp = theModule->getApp();
409 anApp = dynamic_cast<SalomeApp_Application*>
410 (SUIT_Session::session()->activeApplication());
413 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
416 SUIT_ViewManager* aViewManager =
417 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
419 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
420 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
421 aViewWindow->raise();
422 aViewWindow->setFocus();
431 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
432 SUIT_ViewWindow * theWindow)
437 QVector<SUIT_ViewWindow*> views = theMgr->getViews();
438 if( views.contains( theWindow ) )
439 return GetVtkViewWindow( theWindow );
444 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
445 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
448 /* SUIT_ViewWindow* GetActiveWindow()
450 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
453 SUIT_ViewManager* mgr = app->activeViewManager();
455 return mgr->getActiveView();
460 SVTK_ViewWindow* GetCurrentVtkView(){
461 return GetVtkViewWindow( GetActiveWindow() );
465 void RepaintCurrentView()
467 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
471 wnd->getRenderer()->Render();
475 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" );
481 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
485 theWindow->getRenderer()->Render();
486 theWindow->Repaint();
489 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow*)" );
494 void RenderViewWindow(SVTK_ViewWindow* theWindow)
498 theWindow->getRenderer()->Render();
499 theWindow->Repaint();
502 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow*)" );
508 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
515 MESSAGE ( "Exception in SMESHGUI_VTKUtils::FitAll()" );
522 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
523 const char* theEntry)
525 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
526 vtkRenderer *aRenderer = aViewWindow->getRenderer();
527 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
528 vtkActorCollection *aCollection = aCopy.GetActors();
529 aCollection->InitTraversal();
530 while(vtkActor *anAct = aCollection->GetNextActor()){
531 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
532 if(anActor->hasIO()){
533 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
534 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
545 SMESH_Actor* FindActorByEntry(const char* theEntry){
546 return FindActorByEntry(GetActiveWindow(),theEntry);
550 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
551 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
555 if(!CORBA::is_nil(theObject)){
556 _PTR(Study) aStudy = GetActiveStudyDocument();
557 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
558 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
560 CORBA::String_var anEntry = aSObject->GetID().c_str();
561 return FindActorByEntry(anEntry.in());
568 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
569 const char* theEntry,
572 SMESH_Actor *anActor = NULL;
573 CORBA::Long anId = theStudy->StudyId();
574 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
575 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
577 _PTR(GenericAttribute) anAttr;
578 if(aSObj->FindAttribute(anAttr,"AttributeName")){
579 _PTR(AttributeName) aName = anAttr;
580 std::string aNameVal = aName->Value();
581 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
584 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
585 if(!CORBA::is_nil(aGroup) && anActor)
589 SMESH::GetColor( "SMESH", "fill_color", c, deltaF, "0,170,255|-100" );
590 SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
591 c = SMESH::GetColor( "SMESH", "default_grp_color", c );
592 SALOMEDS::Color aColor = aGroup->GetColor();
593 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ))
596 aColor.G = c.greenF();
597 aColor.B = c.blueF();
598 aGroup->SetColor( aColor );
600 if( aGroup->GetType() == SMESH::NODE )
601 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
602 else if( aGroup->GetType() == SMESH::EDGE )
603 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
604 else if( aGroup->GetType() == SMESH::ELEM0D )
605 anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
606 else if( aGroup->GetType() == SMESH::BALL )
607 anActor->SetBallColor( aColor.R, aColor.G, aColor.B );
608 else if( aGroup->GetType() == SMESH::VOLUME )
609 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, deltaV );
611 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, deltaF );
615 //MESSAGE("CreateActor " << anActor);
617 if( SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI() )
618 aSMESHGUI->addActorAsObserver( anActor );
623 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
624 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
627 //MESSAGE("DisplayActor " << theActor);
628 vtkWnd->AddActor(theActor);
632 MESSAGE ( "Exception in SMESHGUI_VTKUtils::DisplayActor()" );
639 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor)
641 if ( SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)) {
642 //MESSAGE("RemoveActor " << theActor);
643 vtkWnd->RemoveActor(theActor);
644 if(theActor->hasIO()){
645 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
646 if(anIO->hasEntry()){
647 std::string anEntry = anIO->getEntry();
648 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
649 int aStudyId = aStudy->id();
650 TVisualObjCont::key_type aKey(aStudyId,anEntry);
651 VISUAL_OBJ_CONT.erase(aKey);
659 //================================================================================
661 * \brief Return true if there are no SMESH actors in a view
663 //================================================================================
665 bool noSmeshActors(SUIT_ViewWindow *theWnd)
667 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWnd)) {
668 vtkRenderer *aRenderer = aViewWindow->getRenderer();
669 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
670 vtkActorCollection *aCollection = aCopy.GetActors();
671 aCollection->InitTraversal();
672 while(vtkActor *anAct = aCollection->GetNextActor())
673 if(dynamic_cast<SMESH_Actor*>(anAct))
679 bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
681 //MESSAGE("UpdateView");
683 SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
687 SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd);
691 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
698 vtkRenderer *aRenderer = aViewWnd->getRenderer();
699 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
700 vtkActorCollection *aCollection = aCopy.GetActors();
701 aCollection->InitTraversal();
705 while (vtkActor *anAct = aCollection->GetNextActor()) {
706 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
707 //MESSAGE("--- display " << anActor);
708 anActor->SetVisibility(true);
710 if(anActor->hasIO()){
711 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
712 if(anIO->hasEntry()){
713 aStudy->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
722 //MESSAGE("---case eDisplayOnly");
723 while (vtkActor *anAct = aCollection->GetNextActor()) {
724 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
725 //MESSAGE("--- erase " << anActor);
726 anActor->SetVisibility(false);
729 aStudy->setVisibilityStateForAll(Qtx::HiddenState);
732 if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
736 //MESSAGE("--- display " << anActor);
738 anActor->SetVisibility(true);
739 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
740 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
743 //MESSAGE("--- erase " << anActor);
744 anActor->SetVisibility(false);
745 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
755 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(theWnd->getViewManager()->study());
756 _PTR(Study) aDocument = aStudy->studyDS();
757 // Pass non-visual objects (hypotheses, etc.), return true in this case
758 CORBA::Long anId = aDocument->StudyId();
759 TVisualObjPtr aVisualObj;
760 if ( (aVisualObj = GetVisualObj(anId,theEntry)) && aVisualObj->IsValid())
762 if ((anActor = CreateActor(aDocument,theEntry,true))) {
763 bool needFitAll = noSmeshActors(theWnd); // fit for the first object only
764 DisplayActor(theWnd,anActor);
765 anActor->SetVisibility(true);
766 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
767 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
768 if (needFitAll) FitAll();
785 bool UpdateView(EDisplaing theAction, const char* theEntry) {
786 //MESSAGE("UpdateView");
787 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
788 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
789 if ( SUIT_ViewManager* vm = app->activeViewManager() )
791 SUIT_ViewWindow *aWnd = vm->getActiveView();
792 return UpdateView(aWnd,theAction,theEntry);
798 if ( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()) {
799 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
800 SALOME_ListIO selected; mgr->selectedObjects( selected );
802 if( selected.Extent() == 0){
803 vtkRenderer* aRenderer = aWnd->getRenderer();
804 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
805 vtkActorCollection *aCollection = aCopy.GetActors();
806 aCollection->InitTraversal();
807 while(vtkActor *anAct = aCollection->GetNextActor()){
808 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
810 if (!Update(anActor->getIO(),anActor->GetVisibility()))
811 break; // avoid multiple warinings if visu failed
815 SALOME_ListIteratorOfListIO anIter( selected );
816 for( ; anIter.More(); anIter.Next()){
817 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
818 if ( !Update(anIO,true) )
819 break; // avoid multiple warinings if visu failed
822 RepaintCurrentView();
827 bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
830 _PTR(Study) aStudy = GetActiveStudyDocument();
831 CORBA::Long anId = aStudy->StudyId();
832 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
834 UpdateView(SMESH::eDisplay,theIO->getEntry());
840 bool UpdateNulData(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
842 //MESSAGE("UpdateNulData");
843 _PTR(Study) aStudy = GetActiveStudyDocument();
844 CORBA::Long anId = aStudy->StudyId();
845 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry(), true)) {
847 UpdateView(SMESH::eDisplay,theIO->getEntry());
853 void UpdateSelectionProp( SMESHGUI* theModule )
858 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
861 MESSAGE( "UpdateSelectionProp: Application is null" );
865 SUIT_ViewManager* vm = app->activeViewManager();
868 MESSAGE( "UpdateSelectionProp: View manager is null" );
872 QVector<SUIT_ViewWindow*> views = vm->getViews();
874 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
877 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
882 aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
883 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
884 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
886 int aElem0DSize = mgr->integerValue("SMESH", "elem0d_size", 5);
887 // int aBallSize = mgr->integerValue("SMESH", "ball_elem_size", 5);
888 int aLineWidth = mgr->integerValue("SMESH", "element_width", 1);
889 int maxSize = aElem0DSize;
890 if (aElem0DSize > maxSize) maxSize = aElem0DSize;
891 if (aLineWidth > maxSize) maxSize = aLineWidth;
892 // if (aBallSize > maxSize) maxSize = aBallSize;
895 SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
896 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
897 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
899 for ( int i=0, n=views.count(); i<n; i++ )
901 // update VTK viewer properties
902 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] ))
904 // mesh element selection
905 aVtkView->SetSelectionProp(aSelColor.red()/255.,
906 aSelColor.green()/255.,
907 aSelColor.blue()/255.);
909 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
912 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
913 aPreColor.green()/255.,
914 aPreColor.blue()/255.);
916 vtkRenderer* aRenderer = aVtkView->getRenderer();
917 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
918 vtkActorCollection *aCollection = aCopy.GetActors();
919 aCollection->InitTraversal();
920 while ( vtkActor *anAct = aCollection->GetNextActor() ) {
921 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct) ) {
922 anActor->SetHighlightColor(aHiColor.red()/255.,
923 aHiColor.green()/255.,
924 aHiColor.blue()/255.);
925 anActor->SetPreHighlightColor(aPreColor.red()/255.,
926 aPreColor.green()/255.,
927 aPreColor.blue()/255.);
935 void UpdateFontProp( SMESHGUI* theModule )
937 if ( !theModule ) return;
939 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
942 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
945 double anRGBNd[3] = {1,1,1};
946 SMESH::GetColor( "SMESH", "numbering_node_color", anRGBNd[0], anRGBNd[1], anRGBNd[2], QColor( 255, 255, 255 ) );
948 SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
950 bool anItalicNd = false;
951 bool aShadowNd = false;
953 if ( mgr->hasValue( "SMESH", "numbering_node_font" ) ) {
954 QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
955 if ( f.family() == "Arial" ) aFamilyNd = SMESH::FntArial;
956 else if ( f.family() == "Courier" ) aFamilyNd = SMESH::FntCourier;
957 else if ( f.family() == "Times" ) aFamilyNd = SMESH::FntTimes;
959 anItalicNd = f.italic();
960 aShadowNd = f.overline();
961 aSizeNd = f.pointSize();
964 double anRGBEl[3] = {0,1,0};
965 SMESH::GetColor( "SMESH", "numbering_elem_color", anRGBEl[0], anRGBEl[1], anRGBEl[2], QColor( 0, 255, 0 ) );
967 SMESH::LabelFont aFamilyEl = SMESH::FntTimes;
969 bool anItalicEl = false;
970 bool aShadowEl = false;
972 if ( mgr->hasValue( "SMESH", "numbering_elem_font" ) ) {
973 QFont f = mgr->fontValue( "SMESH", "numbering_elem_font" );
975 if ( f.family() == "Arial" ) aFamilyEl = SMESH::FntArial;
976 else if ( f.family() == "Courier" ) aFamilyEl = SMESH::FntCourier;
977 else if ( f.family() == "Times" ) aFamilyEl = SMESH::FntTimes;
979 anItalicEl = f.italic();
980 aShadowEl = f.overline();
981 aSizeEl = f.pointSize();
984 ViewManagerList vmList;
985 app->viewManagers( SVTK_Viewer::Type(), vmList );
986 foreach ( SUIT_ViewManager* vm, vmList ) {
987 QVector<SUIT_ViewWindow*> views = vm->getViews();
988 foreach ( SUIT_ViewWindow* vw, views ) {
989 // update VTK viewer properties
990 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( vw ) ) {
992 vtkRenderer* aRenderer = aVtkView->getRenderer();
993 VTK::ActorCollectionCopy aCopy( aRenderer->GetActors() );
994 vtkActorCollection* aCollection = aCopy.GetActors();
995 aCollection->InitTraversal();
996 while ( vtkActor* anAct = aCollection->GetNextActor() ) {
997 if ( SMESH_NodeLabelActor* anActor = dynamic_cast< SMESH_NodeLabelActor* >( anAct ) ) {
998 anActor->SetFontProperties( aFamilyNd, aSizeNd, aBoldNd, anItalicNd, aShadowNd, anRGBNd[0], anRGBNd[1], anRGBNd[2] );
1000 else if ( SMESH_CellLabelActor* anActor = dynamic_cast< SMESH_CellLabelActor* >( anAct ) ) {
1001 anActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
1004 aVtkView->Repaint( false );
1010 //----------------------------------------------------------------------------
1012 GetSelector(SUIT_ViewWindow *theWindow)
1014 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
1015 return aWnd->GetSelector();
1020 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
1021 SVTK_Selector* theSelector)
1024 theSelector->SetFilter(theFilter);
1027 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
1029 return theSelector->GetFilter(theId);
1032 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
1034 return theSelector->IsFilterPresent(theId);
1037 void RemoveFilter(int theId, SVTK_Selector* theSelector)
1039 theSelector->RemoveFilter(theId);
1042 void RemoveFilters(SVTK_Selector* theSelector)
1044 for ( int id = SMESH::NodeFilter; theSelector && id < SMESH::LastFilter; id++ )
1045 theSelector->RemoveFilter( id );
1048 bool IsValid(SALOME_Actor* theActor, int theCellId,
1049 SVTK_Selector* theSelector)
1051 return theSelector->IsValid(theActor,theCellId);
1055 //----------------------------------------------------------------------------
1056 void SetPointRepresentation(bool theIsVisible)
1058 if ( SVTK_ViewWindow* aViewWindow = GetCurrentVtkView() ) {
1059 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1060 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1061 vtkActorCollection *aCollection = aCopy.GetActors();
1062 aCollection->InitTraversal();
1063 while(vtkActor *anAct = aCollection->GetNextActor()){
1064 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1065 if(anActor->GetVisibility()){
1066 anActor->SetPointRepresentation(theIsVisible);
1070 RepaintCurrentView();
1075 void SetPickable(SMESH_Actor* theActor)
1077 if ( SVTK_ViewWindow* aWnd = GetCurrentVtkView() ) {
1078 int anIsAllPickable = (theActor == NULL);
1079 vtkRenderer *aRenderer = aWnd->getRenderer();
1080 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1081 vtkActorCollection *aCollection = aCopy.GetActors();
1082 aCollection->InitTraversal();
1083 while(vtkActor *anAct = aCollection->GetNextActor()){
1084 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
1085 if(anActor->GetVisibility()){
1086 anActor->SetPickable(anIsAllPickable);
1091 theActor->SetPickable(!anIsAllPickable);
1092 RepaintCurrentView();
1097 //----------------------------------------------------------------------------
1098 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
1099 const Handle(SALOME_InteractiveObject)& theIO,
1103 TColStd_IndexedMapOfInteger aMapIndex;
1104 theSelector->GetIndex(theIO,aMapIndex);
1106 for(int i = 1; i <= aMapIndex.Extent(); i++)
1107 theName += QString(" %1").arg(aMapIndex(i));
1109 return aMapIndex.Extent();
1112 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
1113 const Handle(SALOME_InteractiveObject)& theIO,
1117 TColStd_IndexedMapOfInteger aMapIndex;
1118 theSelector->GetIndex(theIO,aMapIndex);
1120 typedef std::set<int> TIdContainer;
1121 TIdContainer anIdContainer;
1122 for( int i = 1; i <= aMapIndex.Extent(); i++)
1123 anIdContainer.insert(aMapIndex(i));
1125 TIdContainer::const_iterator anIter = anIdContainer.begin();
1126 for( ; anIter != anIdContainer.end(); anIter++)
1127 theName += QString(" %1").arg(*anIter);
1129 return aMapIndex.Extent();
1133 int GetEdgeNodes(SVTK_Selector* theSelector,
1134 const TVisualObjPtr& theVisualObject,
1138 const SALOME_ListIO& selected = theSelector->StoredIObjects();
1140 if ( selected.Extent() != 1 )
1143 Handle(SALOME_InteractiveObject) anIO = selected.First();
1144 if ( anIO.IsNull() || !anIO->hasEntry() )
1147 TColStd_IndexedMapOfInteger aMapIndex;
1148 theSelector->GetIndex( anIO, aMapIndex );
1149 if ( aMapIndex.Extent() != 2 )
1152 int anObjId = -1, anEdgeNum = -1;
1153 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1154 int aVal = aMapIndex( i );
1158 anEdgeNum = abs( aVal ) - 1;
1161 if ( anObjId == -1 || anEdgeNum == -1 )
1164 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1167 //----------------------------------------------------------------------------
1168 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1169 const Handle(SALOME_InteractiveObject)& theIO,
1173 if(theIO->hasEntry()){
1174 if(FindActorByEntry(theIO->getEntry())){
1175 TColStd_IndexedMapOfInteger aMapIndex;
1176 theMgr->GetIndexes(theIO,aMapIndex);
1177 for(int i = 1; i <= aMapIndex.Extent(); i++){
1178 theName += QString(" %1").arg(aMapIndex(i));
1180 return aMapIndex.Extent();
1186 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName)
1189 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1190 if(selected.Extent() == 1){
1191 Handle(SALOME_InteractiveObject) anIO = selected.First();
1192 return GetNameOfSelectedNodes(theMgr,anIO,theName);
1198 int GetNameOfSelectedElements(LightApp_SelectionMgr * theMgr,
1199 const Handle(SALOME_InteractiveObject)& theIO,
1203 if(theIO->hasEntry()){
1204 if(FindActorByEntry(theIO->getEntry())){
1205 TColStd_IndexedMapOfInteger aMapIndex;
1206 theMgr->GetIndexes(theIO,aMapIndex);
1207 typedef std::set<int> TIdContainer;
1208 TIdContainer anIdContainer;
1209 for( int i = 1; i <= aMapIndex.Extent(); i++)
1210 anIdContainer.insert(aMapIndex(i));
1211 TIdContainer::const_iterator anIter = anIdContainer.begin();
1212 for( ; anIter != anIdContainer.end(); anIter++){
1213 theName += QString(" %1").arg(*anIter);
1215 return aMapIndex.Extent();
1222 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1225 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1227 if( selected.Extent() == 1){
1228 Handle(SALOME_InteractiveObject) anIO = selected.First();
1229 return GetNameOfSelectedElements(theMgr,anIO,theName);
1234 int GetSelected(LightApp_SelectionMgr* theMgr,
1235 TColStd_IndexedMapOfInteger& theMap,
1236 const bool theIsElement)
1239 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1241 if ( selected.Extent() == 1 )
1243 Handle(SALOME_InteractiveObject) anIO = selected.First();
1244 if ( anIO->hasEntry() ) {
1245 theMgr->GetIndexes( anIO, theMap );
1248 return theMap.Extent();
1252 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
1254 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1256 if ( selected.Extent() != 1 )
1259 Handle(SALOME_InteractiveObject) anIO = selected.First();
1260 if ( anIO.IsNull() || !anIO->hasEntry() )
1263 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1267 TColStd_IndexedMapOfInteger aMapIndex;
1268 theMgr->GetIndexes( anIO, aMapIndex );
1269 if ( aMapIndex.Extent() != 2 )
1272 int anObjId = -1, anEdgeNum = -1;
1273 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1274 int aVal = aMapIndex( i );
1278 anEdgeNum = abs( aVal );
1281 if ( anObjId == -1 || anEdgeNum == -1 )
1284 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1287 void SetControlsPrecision( const long theVal )
1289 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1291 vtkRenderer *aRenderer = aWnd->getRenderer();
1292 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1293 vtkActorCollection *aCollection = aCopy.GetActors();
1294 aCollection->InitTraversal();
1296 while ( vtkActor *anAct = aCollection->GetNextActor())
1298 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1300 anActor->SetControlsPrecision( theVal );
1301 anActor->SetControlMode( anActor->GetControlMode() );
1308 //----------------------------------------------------------------------------
1309 // internal function
1310 void ComputeBoundsParam( double theBounds[6],
1311 double theDirection[3],
1312 double theMinPnt[3],
1313 double& theMaxBoundPrj,
1314 double& theMinBoundPrj )
1316 //Enlarge bounds in order to avoid conflicts of precision
1317 for(int i = 0; i < 6; i += 2){
1318 static double EPS = 1.0E-3;
1319 double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
1320 theBounds[i] -= aDelta;
1321 theBounds[i+1] += aDelta;
1324 double aBoundPoints[8][3] = { {theBounds[0],theBounds[2],theBounds[4]},
1325 {theBounds[1],theBounds[2],theBounds[4]},
1326 {theBounds[0],theBounds[3],theBounds[4]},
1327 {theBounds[1],theBounds[3],theBounds[4]},
1328 {theBounds[0],theBounds[2],theBounds[5]},
1329 {theBounds[1],theBounds[2],theBounds[5]},
1330 {theBounds[0],theBounds[3],theBounds[5]},
1331 {theBounds[1],theBounds[3],theBounds[5]}};
1334 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1335 theMinBoundPrj = theMaxBoundPrj;
1336 for(int i = 1; i < 8; i++){
1337 double aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1338 if(theMaxBoundPrj < aTmp){
1339 theMaxBoundPrj = aTmp;
1342 if(theMinBoundPrj > aTmp){
1343 theMinBoundPrj = aTmp;
1346 double *aMinPnt = aBoundPoints[aMaxId];
1347 theMinPnt[0] = aMinPnt[0];
1348 theMinPnt[1] = aMinPnt[1];
1349 theMinPnt[2] = aMinPnt[2];
1352 // internal function
1353 void DistanceToPosition( double theBounds[6],
1354 double theDirection[3],
1358 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1359 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1360 double aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1361 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1362 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1363 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1366 // internal function (currently unused, left just in case)
1367 void PositionToDistance( double theBounds[6],
1368 double theDirection[3],
1372 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1373 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1374 double aPrj = vtkMath::Dot(theDirection,thePos);
1375 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1378 bool ComputeClippingPlaneParameters( std::list<vtkActor*> theActorList,
1379 double theNormal[3],
1381 double theBounds[6],
1382 double theOrigin[3] )
1384 bool anIsOk = false;
1385 anIsOk = ComputeBounds( theActorList, theBounds );
1391 DistanceToPosition( theBounds, theNormal, theDist, theOrigin );
1395 bool ComputeBounds( std::list<vtkActor*> theActorList,
1396 double theBounds[6])
1398 bool anIsOk = false;
1399 theBounds[0] = theBounds[2] = theBounds[4] = VTK_DOUBLE_MAX;
1400 theBounds[1] = theBounds[3] = theBounds[5] = -VTK_DOUBLE_MAX;
1401 std::list<vtkActor*>::iterator anIter = theActorList.begin();
1402 for( ; anIter != theActorList.end(); anIter++ ) {
1403 if( vtkActor* aVTKActor = *anIter ) {
1404 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1406 anActor->GetUnstructuredGrid()->GetBounds( aBounds );
1407 theBounds[0] = std::min( theBounds[0], aBounds[0] );
1408 theBounds[1] = std::max( theBounds[1], aBounds[1] );
1409 theBounds[2] = std::min( theBounds[2], aBounds[2] );
1410 theBounds[3] = std::max( theBounds[3], aBounds[3] );
1411 theBounds[4] = std::min( theBounds[4], aBounds[4] );
1412 theBounds[5] = std::max( theBounds[5], aBounds[5] );
1420 #ifndef DISABLE_PLOT2DVIEWER
1421 //================================================================================
1423 * \brief Find all SMESH_Actor's in the View Window.
1424 * If actor constains Plot2d_Histogram object remove it from each Plot2d Viewer.
1426 //================================================================================
1428 void ClearPlot2Viewers( SUIT_ViewWindow* theWindow )
1430 if ( SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow) ) {
1431 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1432 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1433 vtkActorCollection *aCollection = aCopy.GetActors();
1434 aCollection->InitTraversal();
1435 while(vtkActor *anAct = aCollection->GetNextActor()){
1436 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1437 if(anActor->hasIO() && anActor->GetPlot2Histogram() ){
1438 ProcessIn2DViewers(anActor,RemoveFrom2dViewer);
1447 } // end of namespace SMESH