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_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<TKeyOfVisualObj,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);
141 int aStudyId = aViewManager->study()->id();
142 TVisualObjCont::key_type aKey(aStudyId,theEntry);
143 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
144 if(anIter != VISUAL_OBJ_CONT.end()) {
145 // for unknown reason, object destructor is not called, so clear object manually
146 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
147 anIter->second->GetUnstructuredGrid()->SetPoints(0);
149 VISUAL_OBJ_CONT.erase(aKey);
153 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
155 //================================================================================
157 * \brief Remove all VisualObjs and their actors from all views
159 //================================================================================
161 void RemoveAllObjectsWithActors()
163 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
164 ( SUIT_Session::session()->activeApplication() );
166 ViewManagerList viewMgrs = app->viewManagers();
167 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
168 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
169 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type()) {
170 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
171 for ( int iV = 0; iV < views.count(); ++iV ) {
172 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
173 vtkRenderer *aRenderer = vtkWnd->getRenderer();
174 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
175 vtkActorCollection *actors = aCopy.GetActors();
176 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
177 // size of actors changes inside the loop
178 if (SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
180 vtkWnd->RemoveActor(actor);
188 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
189 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
190 // for unknown reason, object destructor is not called, so clear object manually
191 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
192 anIter->second->GetUnstructuredGrid()->SetPoints(0);
194 VISUAL_OBJ_CONT.clear();
197 //================================================================================
199 * \brief Remove all VisualObjs of a study
201 //================================================================================
203 void RemoveVisuData(int studyID)
205 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
206 ( SUIT_Session::session()->activeApplication() );
208 ViewManagerList viewMgrs = app->viewManagers();
209 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
210 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
211 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type() &&
212 aViewManager->study()->id() == studyID ) {
213 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
214 for ( int iV = 0; iV < views.count(); ++iV ) {
215 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
216 vtkRenderer *aRenderer = vtkWnd->getRenderer();
217 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
218 vtkActorCollection *actors = aCopy.GetActors();
219 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
220 // size of actors changes inside the loop
221 if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
223 vtkWnd->RemoveActor(actor);
231 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
232 for ( ; anIter != VISUAL_OBJ_CONT.end(); ) {
233 int curId = anIter->first.first;
234 if ( curId == studyID ) {
235 // for unknown reason, object destructor is not called, so clear object manually
236 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
237 anIter->second->GetUnstructuredGrid()->SetPoints(0);
238 VISUAL_OBJ_CONT.erase( anIter++ ); // anIter++ returns a copy of self before incrementing
246 //================================================================================
248 * \brief Notify the user on problems during visualization
250 //================================================================================
252 void OnVisuException()
256 // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
257 // after or at showing this message, so we do an additional check of available memory
258 // char* buf = new char[100*1024];
260 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
261 QObject::tr("SMESH_VISU_PROBLEM"));
263 // no more memory at all: last resort
264 MESSAGE_BEGIN ( "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<
265 std::endl << "Try to remove all visual data..." );
266 if (theVISU_MemoryReserve) {
267 delete theVISU_MemoryReserve;
268 theVISU_MemoryReserve = 0;
270 RemoveAllObjectsWithActors();
271 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
272 QObject::tr("SMESH_VISU_PROBLEM_CLEAR"));
273 MESSAGE_END ( "...done" );
276 //================================================================================
278 * \brief Returns an updated visual object
280 //================================================================================
282 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry, bool nulData){
283 TVisualObjPtr aVisualObj;
284 TVisualObjCont::key_type aKey(theStudyId,theEntry);
287 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
288 if(anIter != VISUAL_OBJ_CONT.end()){
289 aVisualObj = anIter->second;
291 SalomeApp_Application* app =
292 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
293 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
294 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
296 _PTR(GenericAttribute) anAttr;
297 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
298 _PTR(AttributeIOR) anIOR = anAttr;
299 CORBA::String_var aVal = anIOR->Value().c_str();
300 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
301 if(!CORBA::is_nil(anObj)){
302 //Try narrow to SMESH_Mesh interface
303 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
304 if(!aMesh->_is_nil()){
305 aVisualObj.reset(new SMESH_MeshObj(aMesh));
306 TVisualObjCont::value_type aValue(aKey,aVisualObj);
307 VISUAL_OBJ_CONT.insert(aValue);
309 //Try narrow to SMESH_Group interface
310 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
311 if(!aGroup->_is_nil()){
312 _PTR(SObject) aFatherSObj = aSObj->GetFather();
313 if(!aFatherSObj) return aVisualObj;
314 aFatherSObj = aFatherSObj->GetFather();
315 if(!aFatherSObj) return aVisualObj;
316 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
317 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
318 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
319 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
320 TVisualObjCont::value_type aValue(aKey,aVisualObj);
321 VISUAL_OBJ_CONT.insert(aValue);
324 //Try narrow to SMESH_subMesh interface
325 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
326 if(!aSubMesh->_is_nil()){
327 _PTR(SObject) aFatherSObj = aSObj->GetFather();
328 if(!aFatherSObj) return aVisualObj;
329 aFatherSObj = aFatherSObj->GetFather();
330 if(!aFatherSObj) return aVisualObj;
331 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
332 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
333 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
334 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
335 TVisualObjCont::value_type aValue(aKey,aVisualObj);
336 VISUAL_OBJ_CONT.insert(aValue);
344 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
345 return TVisualObjPtr();
348 bool objModified = false;
353 objModified = aVisualObj->NulData();
355 objModified = aVisualObj->Update();
358 MESSAGE ( "Exception in SMESHGUI_VTKUtils::GetVisualObj()" );
359 RemoveVisualObjectWithActors( theEntry ); // remove this object
366 // PAL16631. Measurements showed that to show aVisualObj in SHADING(default) mode,
367 // ~5 times more memory is used than it occupies.
368 // Warn the user if there is less free memory than 30 sizes of a grid
369 // TODO: estimate memory usage in other modes and take current mode into account
370 int freeMB = SMDS_Mesh::CheckMemory(true);
371 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
372 //MESSAGE("SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB << ", usedMB=" <<usedMB);
373 if ( freeMB > 0 && usedMB * 5 > freeMB ) {
374 bool continu = false;
375 if ( usedMB * 3 > freeMB )
376 // don't even try to show
377 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
378 QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
380 // there is a chance to succeed
381 continu = SUIT_MessageBox::warning
382 (SMESHGUI::desktop(),
383 QObject::tr("SMESH_WRN_WARNING"),
384 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
385 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
386 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
388 // remove the corresponding actors from all views
389 RemoveVisualObjectWithActors( theEntry );
399 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
400 * otherwise find or create corresponding view window, make it active and return it.
401 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
403 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
404 bool createIfNotFound)
406 SalomeApp_Application* anApp;
408 anApp = theModule->getApp();
410 anApp = dynamic_cast<SalomeApp_Application*>
411 (SUIT_Session::session()->activeApplication());
414 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
417 SUIT_ViewManager* aViewManager =
418 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
420 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
421 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
422 aViewWindow->raise();
423 aViewWindow->setFocus();
432 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
433 SUIT_ViewWindow * theWindow)
438 QVector<SUIT_ViewWindow*> views = theMgr->getViews();
439 if( views.contains( theWindow ) )
440 return GetVtkViewWindow( theWindow );
445 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
446 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
449 /* SUIT_ViewWindow* GetActiveWindow()
451 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
454 SUIT_ViewManager* mgr = app->activeViewManager();
456 return mgr->getActiveView();
461 SVTK_ViewWindow* GetCurrentVtkView(){
462 return GetVtkViewWindow( GetActiveWindow() );
466 void RepaintCurrentView()
468 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
472 wnd->getRenderer()->Render();
476 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" );
482 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
486 theWindow->getRenderer()->Render();
487 theWindow->Repaint();
490 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow*)" );
495 void RenderViewWindow(SVTK_ViewWindow* theWindow)
499 theWindow->getRenderer()->Render();
500 theWindow->Repaint();
503 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow*)" );
509 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
516 MESSAGE ( "Exception in SMESHGUI_VTKUtils::FitAll()" );
523 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
524 const char* theEntry)
526 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
527 vtkRenderer *aRenderer = aViewWindow->getRenderer();
528 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
529 vtkActorCollection *aCollection = aCopy.GetActors();
530 aCollection->InitTraversal();
531 while(vtkActor *anAct = aCollection->GetNextActor()){
532 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
533 if(anActor->hasIO()){
534 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
535 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
546 SMESH_Actor* FindActorByEntry(const char* theEntry){
547 return FindActorByEntry(GetActiveWindow(),theEntry);
551 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
552 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
556 if(!CORBA::is_nil(theObject)){
557 _PTR(Study) aStudy = GetActiveStudyDocument();
558 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
559 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
561 CORBA::String_var anEntry = aSObject->GetID().c_str();
562 return FindActorByEntry(anEntry.in());
569 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
570 const char* theEntry,
573 SMESH_Actor *anActor = NULL;
574 CORBA::Long anId = theStudy->StudyId();
575 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
576 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
578 _PTR(GenericAttribute) anAttr;
579 if(aSObj->FindAttribute(anAttr,"AttributeName")){
580 _PTR(AttributeName) aName = anAttr;
581 std::string aNameVal = aName->Value();
582 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
585 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
586 if(!CORBA::is_nil(aGroup) && anActor)
590 SMESH::GetColor( "SMESH", "fill_color", c, deltaF, "0,170,255|-100" );
591 SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
592 c = SMESH::GetColor( "SMESH", "default_grp_color", c );
593 SALOMEDS::Color aColor = aGroup->GetColor();
594 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ))
597 aColor.G = c.greenF();
598 aColor.B = c.blueF();
599 aGroup->SetColor( aColor );
601 if( aGroup->GetType() == SMESH::NODE )
602 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
603 else if( aGroup->GetType() == SMESH::EDGE )
604 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
605 else if( aGroup->GetType() == SMESH::ELEM0D )
606 anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
607 else if( aGroup->GetType() == SMESH::BALL )
608 anActor->SetBallColor( aColor.R, aColor.G, aColor.B );
609 else if( aGroup->GetType() == SMESH::VOLUME )
610 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, deltaV );
612 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, deltaF );
616 //MESSAGE("CreateActor " << anActor);
618 if( SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI() )
619 aSMESHGUI->addActorAsObserver( anActor );
624 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
625 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
628 //MESSAGE("DisplayActor " << theActor);
629 vtkWnd->AddActor(theActor);
633 MESSAGE ( "Exception in SMESHGUI_VTKUtils::DisplayActor()" );
640 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor)
642 if ( SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)) {
643 //MESSAGE("RemoveActor " << theActor);
644 vtkWnd->RemoveActor(theActor);
645 if(theActor->hasIO()){
646 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
647 if(anIO->hasEntry()){
648 std::string anEntry = anIO->getEntry();
649 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
650 int aStudyId = aStudy->id();
651 TVisualObjCont::key_type aKey(aStudyId,anEntry);
652 VISUAL_OBJ_CONT.erase(aKey);
660 //================================================================================
662 * \brief Return true if there are no SMESH actors in a view
664 //================================================================================
666 bool noSmeshActors(SUIT_ViewWindow *theWnd)
668 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWnd)) {
669 vtkRenderer *aRenderer = aViewWindow->getRenderer();
670 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
671 vtkActorCollection *aCollection = aCopy.GetActors();
672 aCollection->InitTraversal();
673 while(vtkActor *anAct = aCollection->GetNextActor())
674 if(dynamic_cast<SMESH_Actor*>(anAct))
680 bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
682 //MESSAGE("UpdateView");
684 SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
688 SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd);
692 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
699 vtkRenderer *aRenderer = aViewWnd->getRenderer();
700 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
701 vtkActorCollection *aCollection = aCopy.GetActors();
702 aCollection->InitTraversal();
706 while (vtkActor *anAct = aCollection->GetNextActor()) {
707 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
708 //MESSAGE("--- display " << anActor);
709 anActor->SetVisibility(true);
711 if(anActor->hasIO()){
712 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
713 if(anIO->hasEntry()){
714 aStudy->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
723 //MESSAGE("---case eDisplayOnly");
724 while (vtkActor *anAct = aCollection->GetNextActor()) {
725 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
726 //MESSAGE("--- erase " << anActor);
727 anActor->SetVisibility(false);
730 aStudy->setVisibilityStateForAll(Qtx::HiddenState);
733 if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
737 //MESSAGE("--- display " << anActor);
739 anActor->SetVisibility(true);
740 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
741 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
744 //MESSAGE("--- erase " << anActor);
745 anActor->SetVisibility(false);
746 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
756 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(theWnd->getViewManager()->study());
757 _PTR(Study) aDocument = aStudy->studyDS();
758 // Pass non-visual objects (hypotheses, etc.), return true in this case
759 CORBA::Long anId = aDocument->StudyId();
760 TVisualObjPtr aVisualObj;
761 if ( (aVisualObj = GetVisualObj(anId,theEntry)) && aVisualObj->IsValid())
763 if ((anActor = CreateActor(aDocument,theEntry,true))) {
764 bool needFitAll = noSmeshActors(theWnd); // fit for the first object only
765 DisplayActor(theWnd,anActor);
766 anActor->SetVisibility(true);
767 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
768 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
769 if (needFitAll) FitAll();
786 bool UpdateView(EDisplaing theAction, const char* theEntry) {
787 //MESSAGE("UpdateView");
788 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
789 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
790 if ( SUIT_ViewManager* vm = app->activeViewManager() )
792 SUIT_ViewWindow *aWnd = vm->getActiveView();
793 return UpdateView(aWnd,theAction,theEntry);
798 void UpdateView( bool withChildrenOfSelected )
800 if ( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()) {
801 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
802 SALOME_ListIO selected; mgr->selectedObjects( selected );
804 if ( selected.Extent() == 0 ) {
805 vtkRenderer* aRenderer = aWnd->getRenderer();
806 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
807 vtkActorCollection *aCollection = aCopy.GetActors();
808 aCollection->InitTraversal();
809 while(vtkActor *anAct = aCollection->GetNextActor()){
810 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
812 if (!Update(anActor->getIO(),anActor->GetVisibility()))
813 break; // avoid multiple warinings if visu failed
819 SALOME_ListIteratorOfListIO anIter( selected );
820 for( ; anIter.More(); anIter.Next())
822 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
823 if ( !Update( anIO, true ))
824 break; // avoid multiple warinings if visu failed
826 if ( withChildrenOfSelected ) // update all visible children
828 QString aFatherID = anIO->getEntry();
829 vtkRenderer* aRenderer = aWnd->getRenderer();
830 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
831 vtkActorCollection *aCollection = aCopy.GetActors();
832 aCollection->InitTraversal();
833 while ( vtkActor *anAct = aCollection->GetNextActor() ) {
834 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct )) {
835 if ( anActor->hasIO() && anActor->GetVisibility() )
837 QString aChildID = anActor->getIO()->getEntry();
838 if ( aChildID.size() > aFatherID.size() &&
839 aChildID.startsWith( aFatherID ))
840 if ( ! Update( anActor->getIO(), true ))
848 RepaintCurrentView();
853 bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
856 _PTR(Study) aStudy = GetActiveStudyDocument();
857 CORBA::Long anId = aStudy->StudyId();
858 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
860 UpdateView(SMESH::eDisplay,theIO->getEntry());
866 bool UpdateNulData(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
868 //MESSAGE("UpdateNulData");
869 _PTR(Study) aStudy = GetActiveStudyDocument();
870 CORBA::Long anId = aStudy->StudyId();
871 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry(), true)) {
873 UpdateView(SMESH::eDisplay,theIO->getEntry());
879 void UpdateSelectionProp( SMESHGUI* theModule )
884 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
887 MESSAGE( "UpdateSelectionProp: Application is null" );
891 SUIT_ViewManager* vm = app->activeViewManager();
894 MESSAGE( "UpdateSelectionProp: View manager is null" );
898 QVector<SUIT_ViewWindow*> views = vm->getViews();
900 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
903 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
907 SMESH_ActorProps::props()->reset();
910 aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
911 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
912 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
914 int aElem0DSize = mgr->integerValue("SMESH", "elem0d_size", 5);
915 // int aBallSize = mgr->integerValue("SMESH", "ball_elem_size", 5);
916 int aLineWidth = mgr->integerValue("SMESH", "element_width", 1);
917 int maxSize = aElem0DSize;
918 if (aElem0DSize > maxSize) maxSize = aElem0DSize;
919 if (aLineWidth > maxSize) maxSize = aLineWidth;
920 // if (aBallSize > maxSize) maxSize = aBallSize;
923 SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
924 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
925 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
927 for ( int i=0, n=views.count(); i<n; i++ )
929 // update VTK viewer properties
930 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] ))
932 // mesh element selection
933 aVtkView->SetSelectionProp(aSelColor.red()/255.,
934 aSelColor.green()/255.,
935 aSelColor.blue()/255.);
937 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
940 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
941 aPreColor.green()/255.,
942 aPreColor.blue()/255.);
944 vtkRenderer* aRenderer = aVtkView->getRenderer();
945 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
946 vtkActorCollection *aCollection = aCopy.GetActors();
947 aCollection->InitTraversal();
948 while ( vtkActor *anAct = aCollection->GetNextActor() ) {
949 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct) ) {
950 anActor->UpdateSelectionProps();
958 void UpdateFontProp( SMESHGUI* theModule )
960 if ( !theModule ) return;
962 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
965 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
968 double anRGBNd[3] = {1,1,1};
969 SMESH::GetColor( "SMESH", "numbering_node_color", anRGBNd[0], anRGBNd[1], anRGBNd[2], QColor( 255, 255, 255 ) );
971 SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
973 bool anItalicNd = false;
974 bool aShadowNd = false;
976 if ( mgr->hasValue( "SMESH", "numbering_node_font" ) ) {
977 QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
978 if ( f.family() == "Arial" ) aFamilyNd = SMESH::FntArial;
979 else if ( f.family() == "Courier" ) aFamilyNd = SMESH::FntCourier;
980 else if ( f.family() == "Times" ) aFamilyNd = SMESH::FntTimes;
982 anItalicNd = f.italic();
983 aShadowNd = f.overline();
984 aSizeNd = f.pointSize();
987 double anRGBEl[3] = {0,1,0};
988 SMESH::GetColor( "SMESH", "numbering_elem_color", anRGBEl[0], anRGBEl[1], anRGBEl[2], QColor( 0, 255, 0 ) );
990 SMESH::LabelFont aFamilyEl = SMESH::FntTimes;
992 bool anItalicEl = false;
993 bool aShadowEl = false;
995 if ( mgr->hasValue( "SMESH", "numbering_elem_font" ) ) {
996 QFont f = mgr->fontValue( "SMESH", "numbering_elem_font" );
998 if ( f.family() == "Arial" ) aFamilyEl = SMESH::FntArial;
999 else if ( f.family() == "Courier" ) aFamilyEl = SMESH::FntCourier;
1000 else if ( f.family() == "Times" ) aFamilyEl = SMESH::FntTimes;
1002 anItalicEl = f.italic();
1003 aShadowEl = f.overline();
1004 aSizeEl = f.pointSize();
1007 ViewManagerList vmList;
1008 app->viewManagers( SVTK_Viewer::Type(), vmList );
1009 foreach ( SUIT_ViewManager* vm, vmList ) {
1010 QVector<SUIT_ViewWindow*> views = vm->getViews();
1011 foreach ( SUIT_ViewWindow* vw, views ) {
1012 // update VTK viewer properties
1013 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( vw ) ) {
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_NodeLabelActor* anActor = dynamic_cast< SMESH_NodeLabelActor* >( anAct ) ) {
1021 anActor->SetFontProperties( aFamilyNd, aSizeNd, aBoldNd, anItalicNd, aShadowNd, anRGBNd[0], anRGBNd[1], anRGBNd[2] );
1023 else if ( SMESH_CellLabelActor* anActor = dynamic_cast< SMESH_CellLabelActor* >( anAct ) ) {
1024 anActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
1027 aVtkView->Repaint( false );
1033 //----------------------------------------------------------------------------
1035 GetSelector(SUIT_ViewWindow *theWindow)
1037 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
1038 return aWnd->GetSelector();
1043 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
1044 SVTK_Selector* theSelector)
1047 theSelector->SetFilter(theFilter);
1050 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
1052 return theSelector->GetFilter(theId);
1055 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
1057 return theSelector->IsFilterPresent(theId);
1060 void RemoveFilter(int theId, SVTK_Selector* theSelector)
1062 theSelector->RemoveFilter(theId);
1065 void RemoveFilters(SVTK_Selector* theSelector)
1067 for ( int id = SMESH::NodeFilter; theSelector && id < SMESH::LastFilter; id++ )
1068 theSelector->RemoveFilter( id );
1071 bool IsValid(SALOME_Actor* theActor, int theCellId,
1072 SVTK_Selector* theSelector)
1074 return theSelector->IsValid(theActor,theCellId);
1078 //----------------------------------------------------------------------------
1079 void SetPointRepresentation(bool theIsVisible)
1081 if ( SVTK_ViewWindow* aViewWindow = GetCurrentVtkView() ) {
1082 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1083 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1084 vtkActorCollection *aCollection = aCopy.GetActors();
1085 aCollection->InitTraversal();
1086 while(vtkActor *anAct = aCollection->GetNextActor()){
1087 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1088 if(anActor->GetVisibility()){
1089 anActor->SetPointRepresentation(theIsVisible);
1093 RepaintCurrentView();
1098 void SetPickable(SMESH_Actor* theActor)
1100 if ( SVTK_ViewWindow* aWnd = GetCurrentVtkView() ) {
1101 int anIsAllPickable = (theActor == NULL);
1102 vtkRenderer *aRenderer = aWnd->getRenderer();
1103 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1104 vtkActorCollection *aCollection = aCopy.GetActors();
1105 aCollection->InitTraversal();
1106 while(vtkActor *anAct = aCollection->GetNextActor()){
1107 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
1108 if(anActor->GetVisibility()){
1109 anActor->SetPickable(anIsAllPickable);
1114 theActor->SetPickable(!anIsAllPickable);
1115 RepaintCurrentView();
1120 //----------------------------------------------------------------------------
1121 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
1122 const Handle(SALOME_InteractiveObject)& theIO,
1126 TColStd_IndexedMapOfInteger aMapIndex;
1127 theSelector->GetIndex(theIO,aMapIndex);
1129 for(int i = 1; i <= aMapIndex.Extent(); i++)
1130 theName += QString(" %1").arg(aMapIndex(i));
1132 return aMapIndex.Extent();
1135 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
1136 const Handle(SALOME_InteractiveObject)& theIO,
1140 TColStd_IndexedMapOfInteger aMapIndex;
1141 theSelector->GetIndex(theIO,aMapIndex);
1143 typedef std::set<int> TIdContainer;
1144 TIdContainer anIdContainer;
1145 for( int i = 1; i <= aMapIndex.Extent(); i++)
1146 anIdContainer.insert(aMapIndex(i));
1148 TIdContainer::const_iterator anIter = anIdContainer.begin();
1149 for( ; anIter != anIdContainer.end(); anIter++)
1150 theName += QString(" %1").arg(*anIter);
1152 return aMapIndex.Extent();
1156 int GetEdgeNodes(SVTK_Selector* theSelector,
1157 const TVisualObjPtr& theVisualObject,
1161 const SALOME_ListIO& selected = theSelector->StoredIObjects();
1163 if ( selected.Extent() != 1 )
1166 Handle(SALOME_InteractiveObject) anIO = selected.First();
1167 if ( anIO.IsNull() || !anIO->hasEntry() )
1170 TColStd_IndexedMapOfInteger aMapIndex;
1171 theSelector->GetIndex( anIO, aMapIndex );
1172 if ( aMapIndex.Extent() != 2 )
1175 int anObjId = -1, anEdgeNum = -1;
1176 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1177 int aVal = aMapIndex( i );
1181 anEdgeNum = abs( aVal ) - 1;
1184 if ( anObjId == -1 || anEdgeNum == -1 )
1187 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1190 //----------------------------------------------------------------------------
1191 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1192 const Handle(SALOME_InteractiveObject)& theIO,
1196 if(theIO->hasEntry()){
1197 if(FindActorByEntry(theIO->getEntry())){
1198 TColStd_IndexedMapOfInteger aMapIndex;
1199 theMgr->GetIndexes(theIO,aMapIndex);
1200 for(int i = 1; i <= aMapIndex.Extent(); i++){
1201 theName += QString(" %1").arg(aMapIndex(i));
1203 return aMapIndex.Extent();
1209 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName)
1212 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1213 if(selected.Extent() == 1){
1214 Handle(SALOME_InteractiveObject) anIO = selected.First();
1215 return GetNameOfSelectedNodes(theMgr,anIO,theName);
1221 int GetNameOfSelectedElements(LightApp_SelectionMgr * theMgr,
1222 const Handle(SALOME_InteractiveObject)& theIO,
1226 if(theIO->hasEntry()){
1227 if(FindActorByEntry(theIO->getEntry())){
1228 TColStd_IndexedMapOfInteger aMapIndex;
1229 theMgr->GetIndexes(theIO,aMapIndex);
1230 typedef std::set<int> TIdContainer;
1231 TIdContainer anIdContainer;
1232 for( int i = 1; i <= aMapIndex.Extent(); i++)
1233 anIdContainer.insert(aMapIndex(i));
1234 TIdContainer::const_iterator anIter = anIdContainer.begin();
1235 for( ; anIter != anIdContainer.end(); anIter++){
1236 theName += QString(" %1").arg(*anIter);
1238 return aMapIndex.Extent();
1245 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1248 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1250 if( selected.Extent() == 1){
1251 Handle(SALOME_InteractiveObject) anIO = selected.First();
1252 return GetNameOfSelectedElements(theMgr,anIO,theName);
1257 int GetSelected(LightApp_SelectionMgr* theMgr,
1258 TColStd_IndexedMapOfInteger& theMap,
1259 const bool theIsElement)
1262 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1264 if ( selected.Extent() == 1 )
1266 Handle(SALOME_InteractiveObject) anIO = selected.First();
1267 if ( anIO->hasEntry() ) {
1268 theMgr->GetIndexes( anIO, theMap );
1271 return theMap.Extent();
1275 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
1277 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1279 if ( selected.Extent() != 1 )
1282 Handle(SALOME_InteractiveObject) anIO = selected.First();
1283 if ( anIO.IsNull() || !anIO->hasEntry() )
1286 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1290 TColStd_IndexedMapOfInteger aMapIndex;
1291 theMgr->GetIndexes( anIO, aMapIndex );
1292 if ( aMapIndex.Extent() != 2 )
1295 int anObjId = -1, anEdgeNum = -1;
1296 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1297 int aVal = aMapIndex( i );
1301 anEdgeNum = abs( aVal );
1304 if ( anObjId == -1 || anEdgeNum == -1 )
1307 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1310 void SetControlsPrecision( const long theVal )
1312 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1314 vtkRenderer *aRenderer = aWnd->getRenderer();
1315 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1316 vtkActorCollection *aCollection = aCopy.GetActors();
1317 aCollection->InitTraversal();
1319 while ( vtkActor *anAct = aCollection->GetNextActor())
1321 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1323 anActor->SetControlsPrecision( theVal );
1324 anActor->SetControlMode( anActor->GetControlMode() );
1331 //----------------------------------------------------------------------------
1332 // internal function
1333 void ComputeBoundsParam( double theBounds[6],
1334 double theDirection[3],
1335 double theMinPnt[3],
1336 double& theMaxBoundPrj,
1337 double& theMinBoundPrj )
1339 //Enlarge bounds in order to avoid conflicts of precision
1340 for(int i = 0; i < 6; i += 2){
1341 static double EPS = 1.0E-3;
1342 double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
1343 theBounds[i] -= aDelta;
1344 theBounds[i+1] += aDelta;
1347 double aBoundPoints[8][3] = { {theBounds[0],theBounds[2],theBounds[4]},
1348 {theBounds[1],theBounds[2],theBounds[4]},
1349 {theBounds[0],theBounds[3],theBounds[4]},
1350 {theBounds[1],theBounds[3],theBounds[4]},
1351 {theBounds[0],theBounds[2],theBounds[5]},
1352 {theBounds[1],theBounds[2],theBounds[5]},
1353 {theBounds[0],theBounds[3],theBounds[5]},
1354 {theBounds[1],theBounds[3],theBounds[5]}};
1357 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1358 theMinBoundPrj = theMaxBoundPrj;
1359 for(int i = 1; i < 8; i++){
1360 double aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1361 if(theMaxBoundPrj < aTmp){
1362 theMaxBoundPrj = aTmp;
1365 if(theMinBoundPrj > aTmp){
1366 theMinBoundPrj = aTmp;
1369 double *aMinPnt = aBoundPoints[aMaxId];
1370 theMinPnt[0] = aMinPnt[0];
1371 theMinPnt[1] = aMinPnt[1];
1372 theMinPnt[2] = aMinPnt[2];
1375 // internal function
1376 void DistanceToPosition( double theBounds[6],
1377 double theDirection[3],
1381 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1382 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1383 double aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1384 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1385 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1386 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1389 // internal function (currently unused, left just in case)
1390 void PositionToDistance( double theBounds[6],
1391 double theDirection[3],
1395 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1396 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1397 double aPrj = vtkMath::Dot(theDirection,thePos);
1398 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1401 bool ComputeClippingPlaneParameters( std::list<vtkActor*> theActorList,
1402 double theNormal[3],
1404 double theBounds[6],
1405 double theOrigin[3] )
1407 bool anIsOk = false;
1408 anIsOk = ComputeBounds( theActorList, theBounds );
1414 DistanceToPosition( theBounds, theNormal, theDist, theOrigin );
1418 bool ComputeBounds( std::list<vtkActor*> theActorList,
1419 double theBounds[6])
1421 bool anIsOk = false;
1422 theBounds[0] = theBounds[2] = theBounds[4] = VTK_DOUBLE_MAX;
1423 theBounds[1] = theBounds[3] = theBounds[5] = -VTK_DOUBLE_MAX;
1424 std::list<vtkActor*>::iterator anIter = theActorList.begin();
1425 for( ; anIter != theActorList.end(); anIter++ ) {
1426 if( vtkActor* aVTKActor = *anIter ) {
1427 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1429 anActor->GetUnstructuredGrid()->GetBounds( aBounds );
1430 theBounds[0] = std::min( theBounds[0], aBounds[0] );
1431 theBounds[1] = std::max( theBounds[1], aBounds[1] );
1432 theBounds[2] = std::min( theBounds[2], aBounds[2] );
1433 theBounds[3] = std::max( theBounds[3], aBounds[3] );
1434 theBounds[4] = std::min( theBounds[4], aBounds[4] );
1435 theBounds[5] = std::max( theBounds[5], aBounds[5] );
1443 #ifndef DISABLE_PLOT2DVIEWER
1444 //================================================================================
1446 * \brief Find all SMESH_Actor's in the View Window.
1447 * If actor constains Plot2d_Histogram object remove it from each Plot2d Viewer.
1449 //================================================================================
1451 void ClearPlot2Viewers( SUIT_ViewWindow* theWindow )
1453 if ( SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow) ) {
1454 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1455 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1456 vtkActorCollection *aCollection = aCopy.GetActors();
1457 aCollection->InitTraversal();
1458 while(vtkActor *anAct = aCollection->GetNextActor()){
1459 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1460 if(anActor->hasIO() && anActor->GetPlot2Histogram() ){
1461 ProcessIn2DViewers(anActor,RemoveFrom2dViewer);
1470 } // end of namespace SMESH