1 // Copyright (C) 2007-2020 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_ActorProps.h"
36 #include "SMESH_ActorUtils.h"
37 #include "SMESH_CellLabelActor.h"
38 #include "SMESH_ControlsDef.hxx"
39 #include "SMESH_NodeLabelActor.h"
40 #include "SMESH_ObjectDef.h"
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_ResourceMgr.h>
49 #include <SALOME_ListIO.hxx>
51 #include <SVTK_Selector.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
55 #include <VTKViewer_Algorithm.h>
57 #include <LightApp_SelectionMgr.h>
58 #include <SalomeApp_Application.h>
59 #include <SalomeApp_Study.h>
61 // SALOME KERNEL includes
62 #include <utilities.h>
65 #include <SALOMEconfig.h>
66 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
67 #include CORBA_CLIENT_HEADER(SMESH_Group)
71 #include <vtkRenderer.h>
72 #include <vtkActorCollection.h>
73 #include <vtkUnstructuredGrid.h>
76 #include <Standard_ErrorHandler.hxx>
80 typedef std::map<std::string,TVisualObjPtr> TVisualObjCont;
81 static TVisualObjCont VISUAL_OBJ_CONT;
83 //=============================================================================
85 * \brief Allocate some memory at construction and release it at destruction.
86 * Is used to be able to continue working after mesh generation or visualization
87 * break due to lack of memory
89 //=============================================================================
94 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
95 void Free() { if (myBuf) { delete [] myBuf; myBuf = 0; }}
96 ~MemoryReserve() { Free(); }
98 static MemoryReserve* theVISU_MemoryReserve = new MemoryReserve;
100 //================================================================================
102 * \brief Remove VisualObj and its actor from all views
104 //================================================================================
106 void RemoveVisualObjectWithActors( const char* theEntry, bool fromAllViews )
108 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
111 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
114 ViewManagerList aList;
117 app->viewManagers(SVTK_Viewer::Type() , aList);
119 SUIT_ViewManager* aVM = app->getViewManager(SVTK_Viewer::Type(), true);
123 bool actorRemoved = false;
124 ViewManagerList::ConstIterator it = aList.begin();
125 SUIT_ViewManager* aViewManager = 0;
126 for( ; it!=aList.end();it++) {
128 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
129 for ( int iV = 0; iV < views.count(); ++iV ) {
130 if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
131 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
132 vtkWnd->RemoveActor(actor);
140 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(theEntry);
141 if(anIter != VISUAL_OBJ_CONT.end()) {
142 // for unknown reason, object destructor is not called, so clear object manually
143 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
144 anIter->second->GetUnstructuredGrid()->SetPoints(0);
146 VISUAL_OBJ_CONT.erase(theEntry);
149 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
151 //================================================================================
153 * \brief Remove all VisualObjs and their actors from all views
155 //================================================================================
157 void RemoveAllObjectsWithActors()
159 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
160 ( SUIT_Session::session()->activeApplication() );
162 ViewManagerList viewMgrs = app->viewManagers();
163 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
164 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
165 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type()) {
166 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
167 for ( int iV = 0; iV < views.count(); ++iV ) {
168 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
169 vtkRenderer *aRenderer = vtkWnd->getRenderer();
170 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
171 vtkActorCollection *actors = aCopy.GetActors();
172 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
173 // size of actors changes inside the loop
174 if (SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
176 vtkWnd->RemoveActor(actor);
184 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
185 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
186 // for unknown reason, object destructor is not called, so clear object manually
187 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
188 anIter->second->GetUnstructuredGrid()->SetPoints(0);
190 VISUAL_OBJ_CONT.clear();
193 //================================================================================
195 * \brief Remove all VisualObjs of a study
197 //================================================================================
199 void RemoveVisuData()
201 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
202 ( SUIT_Session::session()->activeApplication() );
204 ViewManagerList viewMgrs = app->viewManagers();
205 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
206 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
207 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type() ) {
208 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
209 for ( int iV = 0; iV < views.count(); ++iV ) {
210 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
211 vtkRenderer *aRenderer = vtkWnd->getRenderer();
212 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
213 vtkActorCollection *actors = aCopy.GetActors();
214 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
215 // size of actors changes inside the loop
216 if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
218 vtkWnd->RemoveActor(actor);
226 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
227 for ( ; anIter != VISUAL_OBJ_CONT.end(); ) {
228 // for unknown reason, object destructor is not called, so clear object manually
229 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
230 anIter->second->GetUnstructuredGrid()->SetPoints(0);
231 VISUAL_OBJ_CONT.erase( anIter++ ); // anIter++ returns a copy of self before incrementing
235 //================================================================================
237 * \brief Remove/update actors while module activation
238 * \param [in] wnd - window
240 * At module activation, groups and sub-meshes can be removed on engine side due
241 * to modification of meshed geometry, while their actors can remain.
242 * Here we remove/update SMESH_Actor's of changed objects. State (emptiness) of objects
243 * is defined by their icons in the Object Browser
245 //================================================================================
247 void UpdateActorsAfterUpdateStudy( SUIT_ViewWindow* theWindow )
249 const char* emptyIcon = "ICON_SMESH_TREE_MESH_WARN";
250 _PTR(Study) aStudy = SMESH::getStudy();
252 if ( SVTK_ViewWindow* aViewWindow = GetVtkViewWindow( theWindow ))
254 vtkRenderer *aRenderer = aViewWindow->getRenderer();
255 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
256 vtkActorCollection *aCollection = aCopy.GetActors();
257 aCollection->InitTraversal();
258 while ( vtkActor *actor = aCollection->GetNextActor() ) {
259 if ( SMESH_Actor *smeshActor = dynamic_cast<SMESH_Actor*>( actor ))
261 if ( !smeshActor->hasIO() )
263 Handle(SALOME_InteractiveObject) io = smeshActor->getIO();
264 if ( !io->hasEntry() )
266 _PTR(SObject) so = aStudy->FindObjectID( io->getEntry() );
268 continue; // seems impossible
270 CORBA::Object_var obj = SMESH::SObjectToObject( so );
271 if ( CORBA::is_nil( obj )) // removed object
273 RemoveActor( theWindow, smeshActor );
277 bool toShow = smeshActor->GetVisibility();
278 _PTR(GenericAttribute) attr;
279 if ( toShow && so->FindAttribute( attr, "AttributePixMap" )) // check emptiness
281 _PTR(AttributePixMap) pixMap = attr;
282 toShow = ( pixMap->GetPixMap() != emptyIcon );
284 //smeshActor->Update();
285 UpdateView( theWindow, toShow ? eDisplay : eErase, io->getEntry() );
292 //================================================================================
294 * \brief Remove/update actors while module activation
296 * At module activation, groups and sub-meshes can be removed on engine side due
297 * to modification of meshed geometry, while their actors can remain.
298 * Here we remove/update SMESH_Actor's of changed objects. State (emptiness) of objects
299 * is defined by their icons in the Object Browser
301 //================================================================================
303 void UpdateActorsAfterUpdateStudy()
305 SUIT_Study* study = SMESH::GetActiveStudy();
306 if ( SUIT_Desktop* desk = study->application()->desktop() )
308 QList<SUIT_ViewWindow*> wndList = desk->windows();
309 SUIT_ViewWindow* wnd;
310 foreach ( wnd, wndList )
311 SMESH::UpdateActorsAfterUpdateStudy(wnd);
315 //================================================================================
317 * \brief Notify the user on problems during visualization
319 //================================================================================
321 void OnVisuException()
325 // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
326 // after or at showing this message, so we do an additional check of available memory
327 // char* buf = new char[100*1024];
329 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
330 QObject::tr("SMESH_VISU_PROBLEM"));
332 // no more memory at all: last resort
333 MESSAGE_BEGIN ( "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<
334 std::endl << "Try to remove all visual data..." );
335 if (theVISU_MemoryReserve) {
336 delete theVISU_MemoryReserve;
337 theVISU_MemoryReserve = 0;
339 RemoveAllObjectsWithActors();
340 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
341 QObject::tr("SMESH_VISU_PROBLEM_CLEAR"));
342 MESSAGE_END ( "...done" );
345 //================================================================================
347 * \brief Returns an updated visual object
349 //================================================================================
351 TVisualObjPtr GetVisualObj(const char* theEntry, bool nulData){
352 TVisualObjPtr aVisualObj;
355 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(theEntry);
356 if(anIter != VISUAL_OBJ_CONT.end()){
357 aVisualObj = anIter->second;
359 SalomeApp_Application* app =
360 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
361 _PTR(Study) aStudy = SMESH::getStudy();
362 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
364 _PTR(GenericAttribute) anAttr;
365 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
366 _PTR(AttributeIOR) anIOR = anAttr;
367 CORBA::String_var aVal = anIOR->Value().c_str();
368 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
369 if(!CORBA::is_nil(anObj)){
370 //Try narrow to SMESH_Mesh interface
371 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
372 if(!aMesh->_is_nil()){
373 aVisualObj.reset(new SMESH_MeshObj(aMesh));
374 TVisualObjCont::value_type aValue(theEntry,aVisualObj);
375 VISUAL_OBJ_CONT.insert(aValue);
377 //Try narrow to SMESH_Group interface
378 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
379 if(!aGroup->_is_nil()){
380 _PTR(SObject) aFatherSObj = aSObj->GetFather();
381 if(!aFatherSObj) return aVisualObj;
382 aFatherSObj = aFatherSObj->GetFather();
383 if(!aFatherSObj) return aVisualObj;
384 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
385 TVisualObjPtr aVisObj = GetVisualObj(anEntry.in());
386 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
387 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
388 TVisualObjCont::value_type aValue(theEntry,aVisualObj);
389 VISUAL_OBJ_CONT.insert(aValue);
392 //Try narrow to SMESH_subMesh interface
393 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
394 if(!aSubMesh->_is_nil()){
395 _PTR(SObject) aFatherSObj = aSObj->GetFather();
396 if(!aFatherSObj) return aVisualObj;
397 aFatherSObj = aFatherSObj->GetFather();
398 if(!aFatherSObj) return aVisualObj;
399 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
400 TVisualObjPtr aVisObj = GetVisualObj(anEntry.in());
401 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
402 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
403 TVisualObjCont::value_type aValue(theEntry,aVisualObj);
404 VISUAL_OBJ_CONT.insert(aValue);
412 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
413 return TVisualObjPtr();
416 bool objModified = false;
421 objModified = aVisualObj->NulData();
423 objModified = aVisualObj->Update();
426 MESSAGE ( "Exception in SMESHGUI_VTKUtils::GetVisualObj()" );
427 RemoveVisualObjectWithActors( theEntry ); // remove this object
434 // PAL16631. Measurements showed that to show aVisualObj in SHADING(default) mode,
435 // ~5 times more memory is used than it occupies.
436 // Warn the user if there is less free memory than 30 sizes of a grid
437 // TODO: estimate memory usage in other modes and take current mode into account
438 int freeMB = SMDS_Mesh::CheckMemory(true);
439 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
440 //MESSAGE("SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB << ", usedMB=" <<usedMB);
441 if ( freeMB > 0 && usedMB * 5 > freeMB ) {
442 bool continu = false;
443 if ( usedMB * 3 > freeMB )
444 // don't even try to show
445 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
446 QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
448 // there is a chance to succeed
449 continu = SUIT_MessageBox::warning
450 (SMESHGUI::desktop(),
451 QObject::tr("SMESH_WRN_WARNING"),
452 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
453 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
454 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
456 // remove the corresponding actors from all views
457 RemoveVisualObjectWithActors( theEntry );
467 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
468 * otherwise find or create corresponding view window, make it active and return it.
469 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
471 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
472 bool createIfNotFound)
474 SalomeApp_Application* anApp;
476 anApp = theModule->getApp();
478 anApp = dynamic_cast<SalomeApp_Application*>
479 (SUIT_Session::session()->activeApplication());
482 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
485 SUIT_ViewManager* aViewManager =
486 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
488 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
489 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
490 aViewWindow->raise();
491 aViewWindow->setFocus();
500 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
501 SUIT_ViewWindow * theWindow)
506 QVector<SUIT_ViewWindow*> views = theMgr->getViews();
507 if( views.contains( theWindow ) )
508 return GetVtkViewWindow( theWindow );
513 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
514 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
517 /* SUIT_ViewWindow* GetActiveWindow()
519 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
522 SUIT_ViewManager* mgr = app->activeViewManager();
524 return mgr->getActiveView();
529 SVTK_ViewWindow* GetCurrentVtkView(){
530 return GetVtkViewWindow( GetActiveWindow() );
534 void RepaintCurrentView()
536 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
540 wnd->getRenderer()->Render();
544 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" );
550 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
554 theWindow->getRenderer()->Render();
555 theWindow->Repaint();
558 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow*)" );
563 void RenderViewWindow(SVTK_ViewWindow* theWindow)
567 theWindow->getRenderer()->Render();
568 theWindow->Repaint();
571 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow*)" );
577 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
584 MESSAGE ( "Exception in SMESHGUI_VTKUtils::FitAll()" );
591 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
592 const char* theEntry)
594 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
595 vtkRenderer *aRenderer = aViewWindow->getRenderer();
596 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
597 vtkActorCollection *aCollection = aCopy.GetActors();
598 aCollection->InitTraversal();
599 while(vtkActor *anAct = aCollection->GetNextActor()){
600 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
601 if(anActor->hasIO()){
602 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
603 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
614 SMESH_Actor* FindActorByEntry(const char* theEntry){
615 return FindActorByEntry(GetActiveWindow(),theEntry);
619 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
620 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
624 if(!CORBA::is_nil(theObject)){
625 _PTR(Study) aStudy = getStudy();
626 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
627 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
629 CORBA::String_var anEntry = aSObject->GetID().c_str();
630 return FindActorByEntry(anEntry.in());
637 SMESH_Actor* CreateActor(const char* theEntry,
640 SMESH_Actor *anActor = NULL;
641 if(TVisualObjPtr aVisualObj = GetVisualObj(theEntry)){
642 _PTR(SObject) aSObj = getStudy()->FindObjectID(theEntry);
644 _PTR(GenericAttribute) anAttr;
645 if(aSObj->FindAttribute(anAttr,"AttributeName")){
646 _PTR(AttributeName) aName = anAttr;
647 std::string aNameVal = aName->Value();
648 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
651 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
652 if(!CORBA::is_nil(aGroup) && anActor)
656 SMESH::GetColor( "SMESH", "fill_color", c, deltaF, "0,170,255|-100" );
657 SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
658 c = SMESH::GetColor( "SMESH", "default_grp_color", c );
659 SALOMEDS::Color aColor = aGroup->GetColor();
660 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ))
663 aColor.G = c.greenF();
664 aColor.B = c.blueF();
665 aGroup->SetColor( aColor );
667 if( aGroup->GetType() == SMESH::NODE )
668 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
669 else if( aGroup->GetType() == SMESH::EDGE )
670 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
671 else if( aGroup->GetType() == SMESH::ELEM0D )
672 anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
673 else if( aGroup->GetType() == SMESH::BALL )
674 anActor->SetBallColor( aColor.R, aColor.G, aColor.B );
675 else if( aGroup->GetType() == SMESH::VOLUME )
676 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, deltaV );
678 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, deltaF );
682 //MESSAGE("CreateActor " << anActor);
684 if( SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI() )
685 aSMESHGUI->addActorAsObserver( anActor );
690 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
691 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
694 //MESSAGE("DisplayActor " << theActor);
695 vtkWnd->AddActor(theActor);
699 MESSAGE ( "Exception in SMESHGUI_VTKUtils::DisplayActor()" );
706 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor)
708 if ( SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)) {
709 //MESSAGE("RemoveActor " << theActor);
710 vtkWnd->RemoveActor(theActor);
711 if(theActor->hasIO()){
712 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
713 if(anIO->hasEntry()){
714 std::string anEntry = anIO->getEntry();
715 VISUAL_OBJ_CONT.erase(anEntry);
723 //================================================================================
725 * \brief Return true if there are no SMESH actors in a view
727 //================================================================================
729 bool NoSmeshActors(SUIT_ViewWindow *theWnd)
731 SUIT_ViewWindow* aWnd = ( theWnd == nullptr ) ? GetActiveWindow() : theWnd;
732 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(aWnd)) {
733 vtkRenderer *aRenderer = aViewWindow->getRenderer();
734 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
735 vtkActorCollection *aCollection = aCopy.GetActors();
736 aCollection->InitTraversal();
737 while(vtkActor *anAct = aCollection->GetNextActor())
738 if(dynamic_cast<SMESH_Actor*>(anAct))
744 bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
746 //MESSAGE("UpdateView");
748 SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
752 SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd);
756 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
761 SUIT_ResourceMgr* resMgr;
764 vtkRenderer *aRenderer = aViewWnd->getRenderer();
765 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
766 vtkActorCollection *aCollection = aCopy.GetActors();
767 aCollection->InitTraversal();
771 while (vtkActor *anAct = aCollection->GetNextActor()) {
772 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
773 //MESSAGE("--- display " << anActor);
774 anActor->SetVisibility(true);
776 if(anActor->hasIO()){
777 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
778 if(anIO->hasEntry()){
779 aStudy->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
788 //MESSAGE("---case eDisplayOnly");
789 while (vtkActor *anAct = aCollection->GetNextActor()) {
790 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
791 //MESSAGE("--- erase " << anActor);
792 anActor->SetVisibility(false);
795 aStudy->setVisibilityStateForAll(Qtx::HiddenState);
799 if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
803 //MESSAGE("--- display " << anActor);
805 anActor->SetVisibility(true);
806 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
807 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
808 if (( theAction == eDisplayOnly ) &&
809 ( resMgr = SMESHGUI::resourceMgr() ) &&
810 ( resMgr->booleanValue( "SMESH", "fitall_on_displayonly", false )))
811 FitAll(); // PAL23615
814 //MESSAGE("--- erase " << anActor);
815 anActor->SetVisibility(false);
816 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
826 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(theWnd->getViewManager()->study());
827 TVisualObjPtr aVisualObj;
828 if ( (aVisualObj = GetVisualObj(theEntry)) && aVisualObj->IsValid())
830 if ((anActor = CreateActor(theEntry,true))) {
831 bool needFitAll = NoSmeshActors(theWnd); // fit for the first object only
832 DisplayActor(theWnd,anActor);
833 anActor->SetVisibility(true);
834 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
835 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
836 if (( !needFitAll ) &&
837 ( theAction == eDisplayOnly ) &&
838 ( resMgr = SMESHGUI::resourceMgr() ))
840 needFitAll = resMgr->booleanValue( "SMESH", "fitall_on_displayonly", false );
861 bool UpdateView(EDisplaing theAction, const char* theEntry) {
862 //MESSAGE("UpdateView");
863 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
864 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
865 if ( SUIT_ViewManager* vm = app->activeViewManager() )
867 SUIT_ViewWindow *aWnd = vm->getActiveView();
868 return UpdateView(aWnd,theAction,theEntry);
873 void UpdateView( bool withChildrenOfSelected )
875 if ( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()) {
876 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
877 SALOME_ListIO selected; mgr->selectedObjects( selected );
879 if ( selected.Extent() == 0 ) {
880 vtkRenderer* aRenderer = aWnd->getRenderer();
881 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
882 vtkActorCollection *aCollection = aCopy.GetActors();
883 aCollection->InitTraversal();
884 while(vtkActor *anAct = aCollection->GetNextActor()){
885 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
887 if (!Update(anActor->getIO(),anActor->GetVisibility()))
888 break; // avoid multiple warnings if visu failed
894 SALOME_ListIteratorOfListIO anIter( selected );
895 for( ; anIter.More(); anIter.Next())
897 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
898 if ( !Update( anIO, true ))
899 break; // avoid multiple warnings if visu failed
901 if ( withChildrenOfSelected ) // update all visible children
903 QString aFatherID = anIO->getEntry();
904 vtkRenderer* aRenderer = aWnd->getRenderer();
905 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
906 vtkActorCollection *aCollection = aCopy.GetActors();
907 aCollection->InitTraversal();
908 while ( vtkActor *anAct = aCollection->GetNextActor() ) {
909 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct )) {
910 if ( anActor->hasIO() && anActor->GetVisibility() )
912 QString aChildID = anActor->getIO()->getEntry();
913 if ( aChildID.size() > aFatherID.size() &&
914 aChildID.startsWith( aFatherID ))
915 if ( ! Update( anActor->getIO(), true ))
923 RepaintCurrentView();
928 bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
931 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(theIO->getEntry())) {
933 UpdateView(SMESH::eDisplay,theIO->getEntry());
939 bool UpdateNulData(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
941 //MESSAGE("UpdateNulData");
942 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(theIO->getEntry(), true)) {
944 UpdateView(SMESH::eDisplay,theIO->getEntry());
950 void UpdateSelectionProp( SMESHGUI* theModule )
955 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
958 MESSAGE( "UpdateSelectionProp: Application is null" );
962 SUIT_ViewManager* vm = app->activeViewManager();
965 MESSAGE( "UpdateSelectionProp: View manager is null" );
969 QVector<SUIT_ViewWindow*> views = vm->getViews();
971 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
974 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
978 SMESH_ActorProps::props()->reset();
981 //aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
982 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
983 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
985 int aElem0DSize = mgr->integerValue("SMESH", "elem0d_size", 5);
986 // int aBallSize = mgr->integerValue("SMESH", "ball_elem_size", 5);
987 int aLineWidth = mgr->integerValue("SMESH", "element_width", 1);
988 int maxSize = aElem0DSize;
989 if (aElem0DSize > maxSize) maxSize = aElem0DSize;
990 if (aLineWidth > maxSize) maxSize = aLineWidth;
991 // if (aBallSize > maxSize) maxSize = aBallSize;
994 SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
995 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
996 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
998 for ( int i=0, n=views.count(); i<n; i++ )
1000 // update VTK viewer properties
1001 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] ))
1003 // mesh element selection
1004 aVtkView->SetSelectionProp(aSelColor.red()/255.,
1005 aSelColor.green()/255.,
1006 aSelColor.blue()/255.);
1008 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
1011 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
1012 aPreColor.green()/255.,
1013 aPreColor.blue()/255.);
1015 vtkRenderer* aRenderer = aVtkView->getRenderer();
1016 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1017 vtkActorCollection *aCollection = aCopy.GetActors();
1018 aCollection->InitTraversal();
1019 while ( vtkActor *anAct = aCollection->GetNextActor() ) {
1020 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct) ) {
1021 anActor->UpdateSelectionProps();
1029 void UpdateFontProp( SMESHGUI* theModule )
1031 if ( !theModule ) return;
1033 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
1036 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
1039 double anRGBNd[3] = {1,1,1};
1040 SMESH::GetColor( "SMESH", "numbering_node_color", anRGBNd[0], anRGBNd[1], anRGBNd[2], QColor( 255, 255, 255 ) );
1042 SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
1043 bool aBoldNd = true;
1044 bool anItalicNd = false;
1045 bool aShadowNd = false;
1047 if ( mgr->hasValue( "SMESH", "numbering_node_font" ) ) {
1048 QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
1049 if ( f.family() == "Arial" ) aFamilyNd = SMESH::FntArial;
1050 else if ( f.family() == "Courier" ) aFamilyNd = SMESH::FntCourier;
1051 else if ( f.family() == "Times" ) aFamilyNd = SMESH::FntTimes;
1053 anItalicNd = f.italic();
1054 aShadowNd = f.overline();
1055 aSizeNd = f.pointSize();
1058 double anRGBEl[3] = {0,1,0};
1059 SMESH::GetColor( "SMESH", "numbering_elem_color", anRGBEl[0], anRGBEl[1], anRGBEl[2], QColor( 0, 255, 0 ) );
1061 SMESH::LabelFont aFamilyEl = SMESH::FntTimes;
1062 bool aBoldEl = true;
1063 bool anItalicEl = false;
1064 bool aShadowEl = false;
1066 if ( mgr->hasValue( "SMESH", "numbering_elem_font" ) ) {
1067 QFont f = mgr->fontValue( "SMESH", "numbering_elem_font" );
1069 if ( f.family() == "Arial" ) aFamilyEl = SMESH::FntArial;
1070 else if ( f.family() == "Courier" ) aFamilyEl = SMESH::FntCourier;
1071 else if ( f.family() == "Times" ) aFamilyEl = SMESH::FntTimes;
1073 anItalicEl = f.italic();
1074 aShadowEl = f.overline();
1075 aSizeEl = f.pointSize();
1078 ViewManagerList vmList;
1079 app->viewManagers( SVTK_Viewer::Type(), vmList );
1080 foreach ( SUIT_ViewManager* vm, vmList ) {
1081 QVector<SUIT_ViewWindow*> views = vm->getViews();
1082 foreach ( SUIT_ViewWindow* vw, views ) {
1083 // update VTK viewer properties
1084 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( vw ) ) {
1086 vtkRenderer* aRenderer = aVtkView->getRenderer();
1087 VTK::ActorCollectionCopy aCopy( aRenderer->GetActors() );
1088 vtkActorCollection* aCollection = aCopy.GetActors();
1089 aCollection->InitTraversal();
1090 while ( vtkActor* anAct = aCollection->GetNextActor() ) {
1091 if ( SMESH_NodeLabelActor* anActor = dynamic_cast< SMESH_NodeLabelActor* >( anAct ) ) {
1092 anActor->SetFontProperties( aFamilyNd, aSizeNd, aBoldNd, anItalicNd, aShadowNd, anRGBNd[0], anRGBNd[1], anRGBNd[2] );
1094 else if ( SMESH_CellLabelActor* anActor = dynamic_cast< SMESH_CellLabelActor* >( anAct ) ) {
1095 anActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
1098 aVtkView->Repaint( false );
1104 //----------------------------------------------------------------------------
1106 GetSelector(SUIT_ViewWindow *theWindow)
1108 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
1109 return aWnd->GetSelector();
1114 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
1115 SVTK_Selector* theSelector)
1118 theSelector->SetFilter(theFilter);
1121 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
1123 return theSelector->GetFilter(theId);
1126 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
1128 return theSelector->IsFilterPresent(theId);
1131 void RemoveFilter(int theId, SVTK_Selector* theSelector)
1133 theSelector->RemoveFilter(theId);
1136 void RemoveFilters(SVTK_Selector* theSelector)
1138 for ( int id = SMESH::NodeFilter; theSelector && id < SMESH::LastFilter; id++ )
1139 theSelector->RemoveFilter( id );
1142 bool IsValid(SALOME_Actor* theActor, int theCellId,
1143 SVTK_Selector* theSelector)
1145 return theSelector->IsValid(theActor,theCellId);
1149 //----------------------------------------------------------------------------
1150 void SetPointRepresentation(bool theIsVisible)
1152 if ( SVTK_ViewWindow* aViewWindow = GetCurrentVtkView() ) {
1153 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1154 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1155 vtkActorCollection *aCollection = aCopy.GetActors();
1156 aCollection->InitTraversal();
1157 while(vtkActor *anAct = aCollection->GetNextActor()){
1158 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1159 if(anActor->GetVisibility()){
1160 anActor->SetPointRepresentation(theIsVisible);
1164 RepaintCurrentView();
1169 void SetPickable(SMESH_Actor* theActor)
1171 if ( SVTK_ViewWindow* aWnd = GetCurrentVtkView() ) {
1172 int anIsAllPickable = (theActor == NULL);
1173 vtkRenderer *aRenderer = aWnd->getRenderer();
1174 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1175 vtkActorCollection *aCollection = aCopy.GetActors();
1176 aCollection->InitTraversal();
1177 while(vtkActor *anAct = aCollection->GetNextActor()){
1178 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
1179 if(anActor->GetVisibility()){
1180 anActor->SetPickable(anIsAllPickable);
1185 theActor->SetPickable(!anIsAllPickable);
1186 RepaintCurrentView();
1191 //----------------------------------------------------------------------------
1192 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
1193 const Handle(SALOME_InteractiveObject)& theIO,
1197 SVTK_TIndexedMapOfVtkId aMapIndex;
1198 theSelector->GetIndex(theIO,aMapIndex);
1200 for(int i = 1; i <= aMapIndex.Extent(); i++)
1201 theName += QString(" %1").arg(aMapIndex(i));
1203 return aMapIndex.Extent();
1206 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
1207 const Handle(SALOME_InteractiveObject)& theIO,
1211 SVTK_TIndexedMapOfVtkId aMapIndex;
1212 theSelector->GetIndex(theIO,aMapIndex);
1214 typedef std::set<int> TIdContainer;
1215 TIdContainer anIdContainer;
1216 for( int i = 1; i <= aMapIndex.Extent(); i++)
1217 anIdContainer.insert(aMapIndex(i));
1219 TIdContainer::const_iterator anIter = anIdContainer.begin();
1220 for( ; anIter != anIdContainer.end(); anIter++)
1221 theName += QString(" %1").arg(*anIter);
1223 return aMapIndex.Extent();
1227 int GetEdgeNodes(SVTK_Selector* theSelector,
1228 const TVisualObjPtr& theVisualObject,
1232 const SALOME_ListIO& selected = theSelector->StoredIObjects();
1234 if ( selected.Extent() != 1 )
1237 Handle(SALOME_InteractiveObject) anIO = selected.First();
1238 if ( anIO.IsNull() || !anIO->hasEntry() )
1241 SVTK_TIndexedMapOfVtkId aMapIndex;
1242 theSelector->GetIndex( anIO, aMapIndex );
1243 if ( aMapIndex.Extent() != 2 )
1246 smIdType anObjId = -1, anEdgeNum = -1;
1247 for ( smIdType i = 1; i <= aMapIndex.Extent(); i++ ) {
1248 smIdType aVal = aMapIndex( i );
1252 anEdgeNum = abs( aVal ) - 1;
1255 if ( anObjId == -1 || anEdgeNum == -1 )
1258 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1261 //----------------------------------------------------------------------------
1262 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1263 const Handle(SALOME_InteractiveObject)& theIO,
1267 if(theIO->hasEntry()){
1268 if(FindActorByEntry(theIO->getEntry())){
1269 TColStd_IndexedMapOfInteger aMapIndex;
1270 theMgr->GetIndexes(theIO,aMapIndex);
1271 for(int i = 1; i <= aMapIndex.Extent(); i++){
1272 theName += QString(" %1").arg(aMapIndex(i));
1274 return aMapIndex.Extent();
1280 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName)
1283 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1284 if(selected.Extent() == 1){
1285 Handle(SALOME_InteractiveObject) anIO = selected.First();
1286 return GetNameOfSelectedNodes(theMgr,anIO,theName);
1292 int GetNameOfSelectedElements(LightApp_SelectionMgr * theMgr,
1293 const Handle(SALOME_InteractiveObject)& theIO,
1297 if(theIO->hasEntry()){
1298 if(FindActorByEntry(theIO->getEntry())){
1299 TColStd_IndexedMapOfInteger aMapIndex;
1300 theMgr->GetIndexes(theIO,aMapIndex);
1301 typedef std::set<int> TIdContainer;
1302 TIdContainer anIdContainer;
1303 for( int i = 1; i <= aMapIndex.Extent(); i++)
1304 anIdContainer.insert(aMapIndex(i));
1305 TIdContainer::const_iterator anIter = anIdContainer.begin();
1306 for( ; anIter != anIdContainer.end(); anIter++){
1307 theName += QString(" %1").arg(*anIter);
1309 return aMapIndex.Extent();
1316 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1319 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1321 if( selected.Extent() == 1){
1322 Handle(SALOME_InteractiveObject) anIO = selected.First();
1323 return GetNameOfSelectedElements(theMgr,anIO,theName);
1328 int GetSelected(LightApp_SelectionMgr* theMgr,
1329 TColStd_IndexedMapOfInteger& theMap,
1330 const bool /*theIsElement*/)
1333 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1335 if ( selected.Extent() == 1 )
1337 Handle(SALOME_InteractiveObject) anIO = selected.First();
1338 if ( anIO->hasEntry() ) {
1339 theMgr->GetIndexes( anIO, theMap );
1342 return theMap.Extent();
1346 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, smIdType& theId1, smIdType& theId2 )
1348 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1350 if ( selected.Extent() != 1 )
1353 Handle(SALOME_InteractiveObject) anIO = selected.First();
1354 if ( anIO.IsNull() || !anIO->hasEntry() )
1357 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1361 TColStd_IndexedMapOfInteger aMapIndex;
1362 theMgr->GetIndexes( anIO, aMapIndex );
1363 if ( aMapIndex.Extent() != 2 )
1366 smIdType anObjId = -1, anEdgeNum = -1;
1367 for ( smIdType i = 1; i <= aMapIndex.Extent(); i++ ) {
1368 smIdType aVal = aMapIndex( i );
1372 anEdgeNum = abs( aVal );
1375 if ( anObjId == -1 || anEdgeNum == -1 )
1378 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1381 void SetControlsPrecision( const long theVal )
1383 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1385 vtkRenderer *aRenderer = aWnd->getRenderer();
1386 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1387 vtkActorCollection *aCollection = aCopy.GetActors();
1388 aCollection->InitTraversal();
1390 while ( vtkActor *anAct = aCollection->GetNextActor())
1392 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1394 anActor->SetControlsPrecision( theVal );
1395 anActor->SetControlMode( anActor->GetControlMode() );
1402 //----------------------------------------------------------------------------
1403 // internal function
1404 void ComputeBoundsParam( double theBounds[6],
1405 double theDirection[3],
1406 double theMinPnt[3],
1407 double& theMaxBoundPrj,
1408 double& theMinBoundPrj )
1410 //Enlarge bounds in order to avoid conflicts of precision
1411 for(int i = 0; i < 6; i += 2){
1412 static double EPS = 1.0E-3;
1413 double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
1414 theBounds[i] -= aDelta;
1415 theBounds[i+1] += aDelta;
1418 double aBoundPoints[8][3] = { {theBounds[0],theBounds[2],theBounds[4]},
1419 {theBounds[1],theBounds[2],theBounds[4]},
1420 {theBounds[0],theBounds[3],theBounds[4]},
1421 {theBounds[1],theBounds[3],theBounds[4]},
1422 {theBounds[0],theBounds[2],theBounds[5]},
1423 {theBounds[1],theBounds[2],theBounds[5]},
1424 {theBounds[0],theBounds[3],theBounds[5]},
1425 {theBounds[1],theBounds[3],theBounds[5]}};
1428 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1429 theMinBoundPrj = theMaxBoundPrj;
1430 for(int i = 1; i < 8; i++){
1431 double aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1432 if(theMaxBoundPrj < aTmp){
1433 theMaxBoundPrj = aTmp;
1436 if(theMinBoundPrj > aTmp){
1437 theMinBoundPrj = aTmp;
1440 double *aMinPnt = aBoundPoints[aMaxId];
1441 theMinPnt[0] = aMinPnt[0];
1442 theMinPnt[1] = aMinPnt[1];
1443 theMinPnt[2] = aMinPnt[2];
1446 // internal function
1447 void DistanceToPosition( double theBounds[6],
1448 double theDirection[3],
1452 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1453 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1454 double aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1455 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1456 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1457 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1460 // internal function (currently unused, left just in case)
1461 void PositionToDistance( double theBounds[6],
1462 double theDirection[3],
1466 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1467 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1468 double aPrj = vtkMath::Dot(theDirection,thePos);
1469 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1472 bool ComputeClippingPlaneParameters( std::list<vtkActor*> theActorList,
1473 double theNormal[3],
1475 double theBounds[6],
1476 double theOrigin[3] )
1478 bool anIsOk = false;
1479 anIsOk = ComputeBounds( theActorList, theBounds );
1485 DistanceToPosition( theBounds, theNormal, theDist, theOrigin );
1489 bool ComputeBounds( std::list<vtkActor*> theActorList,
1490 double theBounds[6])
1492 bool anIsOk = false;
1493 theBounds[0] = theBounds[2] = theBounds[4] = VTK_DOUBLE_MAX;
1494 theBounds[1] = theBounds[3] = theBounds[5] = -VTK_DOUBLE_MAX;
1495 std::list<vtkActor*>::iterator anIter = theActorList.begin();
1496 for( ; anIter != theActorList.end(); anIter++ ) {
1497 if( vtkActor* aVTKActor = *anIter ) {
1498 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1500 anActor->GetUnstructuredGrid()->GetBounds( aBounds );
1501 theBounds[0] = std::min( theBounds[0], aBounds[0] );
1502 theBounds[1] = std::max( theBounds[1], aBounds[1] );
1503 theBounds[2] = std::min( theBounds[2], aBounds[2] );
1504 theBounds[3] = std::max( theBounds[3], aBounds[3] );
1505 theBounds[4] = std::min( theBounds[4], aBounds[4] );
1506 theBounds[5] = std::max( theBounds[5], aBounds[5] );
1514 #ifndef DISABLE_PLOT2DVIEWER
1515 //================================================================================
1517 * \brief Find all SMESH_Actor's in the View Window.
1518 * If actor contains Plot2d_Histogram object remove it from each Plot2d Viewer.
1520 //================================================================================
1522 void ClearPlot2Viewers( SUIT_ViewWindow* theWindow )
1524 if ( SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow) ) {
1525 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1526 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1527 vtkActorCollection *aCollection = aCopy.GetActors();
1528 aCollection->InitTraversal();
1529 while(vtkActor *anAct = aCollection->GetNextActor()){
1530 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1531 if(anActor->hasIO() && anActor->GetPlot2Histogram() ){
1532 ProcessIn2DViewers(anActor,RemoveFrom2dViewer);
1541 } // end of namespace SMESH