1 // Copyright (C) 2007-2015 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 <TColStd_IndexedMapOfInteger.hxx>
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()
255 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
258 // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
259 // after or at showing this message, so we do an additional check of available memory
260 // char* buf = new char[100*1024];
262 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
263 QObject::tr("SMESH_VISU_PROBLEM"));
265 // no more memory at all: last resort
266 MESSAGE_BEGIN ( "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<
267 std::endl << "Try to remove all visual data..." );
268 if (theVISU_MemoryReserve) {
269 delete theVISU_MemoryReserve;
270 theVISU_MemoryReserve = 0;
272 RemoveAllObjectsWithActors();
273 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
274 QObject::tr("SMESH_VISU_PROBLEM_CLEAR"));
275 MESSAGE_END ( "...done" );
278 //================================================================================
280 * \brief Returns an updated visual object
282 //================================================================================
284 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry, bool nulData){
285 TVisualObjPtr aVisualObj;
286 TVisualObjCont::key_type aKey(theStudyId,theEntry);
288 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
291 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
292 if(anIter != VISUAL_OBJ_CONT.end()){
293 aVisualObj = anIter->second;
295 SalomeApp_Application* app =
296 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
297 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
298 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
300 _PTR(GenericAttribute) anAttr;
301 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
302 _PTR(AttributeIOR) anIOR = anAttr;
303 CORBA::String_var aVal = anIOR->Value().c_str();
304 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
305 if(!CORBA::is_nil(anObj)){
306 //Try narrow to SMESH_Mesh interface
307 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
308 if(!aMesh->_is_nil()){
309 aVisualObj.reset(new SMESH_MeshObj(aMesh));
310 TVisualObjCont::value_type aValue(aKey,aVisualObj);
311 VISUAL_OBJ_CONT.insert(aValue);
313 //Try narrow to SMESH_Group interface
314 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
315 if(!aGroup->_is_nil()){
316 _PTR(SObject) aFatherSObj = aSObj->GetFather();
317 if(!aFatherSObj) return aVisualObj;
318 aFatherSObj = aFatherSObj->GetFather();
319 if(!aFatherSObj) return aVisualObj;
320 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
321 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
322 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
323 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
324 TVisualObjCont::value_type aValue(aKey,aVisualObj);
325 VISUAL_OBJ_CONT.insert(aValue);
328 //Try narrow to SMESH_subMesh interface
329 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
330 if(!aSubMesh->_is_nil()){
331 _PTR(SObject) aFatherSObj = aSObj->GetFather();
332 if(!aFatherSObj) return aVisualObj;
333 aFatherSObj = aFatherSObj->GetFather();
334 if(!aFatherSObj) return aVisualObj;
335 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
336 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
337 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
338 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
339 TVisualObjCont::value_type aValue(aKey,aVisualObj);
340 VISUAL_OBJ_CONT.insert(aValue);
348 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
349 return TVisualObjPtr();
352 bool objModified = false;
355 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
358 //MESSAGE("GetVisualObj");
360 objModified = aVisualObj->NulData();
362 objModified = aVisualObj->Update();
366 MESSAGE ( "Exception in SMESHGUI_VTKUtils::GetVisualObj()" );
368 RemoveVisualObjectWithActors( theEntry ); // remove this object
375 // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
376 // ~5 times more memory is used than it occupies.
377 // Warn the user if there is less free memory than 30 sizes of a grid
378 // TODO: estimate memory usage in other modes and take current mode into account
379 int freeMB = SMDS_Mesh::CheckMemory(true);
380 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
381 MESSAGE("SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB << ", usedMB=" <<usedMB);
382 if ( freeMB > 0 && usedMB * 5 > freeMB ) {
383 bool continu = false;
384 if ( usedMB * 3 > freeMB )
385 // even dont try to show
386 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
387 QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
389 // there is a chance to succeed
390 continu = SUIT_MessageBox::warning
391 (SMESHGUI::desktop(),
392 QObject::tr("SMESH_WRN_WARNING"),
393 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
394 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
395 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
397 // remove the corresponding actors from all views
398 RemoveVisualObjectWithActors( theEntry );
408 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
409 * overwise find or create corresponding view window, make it active and return it.
410 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
412 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
413 bool createIfNotFound)
415 SalomeApp_Application* anApp;
417 anApp = theModule->getApp();
419 anApp = dynamic_cast<SalomeApp_Application*>
420 (SUIT_Session::session()->activeApplication());
423 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
426 SUIT_ViewManager* aViewManager =
427 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
429 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
430 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
431 aViewWindow->raise();
432 aViewWindow->setFocus();
441 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
442 SUIT_ViewWindow * theWindow)
447 QVector<SUIT_ViewWindow*> views = theMgr->getViews();
448 if( views.contains( theWindow ) )
449 return GetVtkViewWindow( theWindow );
454 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
455 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
458 /* SUIT_ViewWindow* GetActiveWindow()
460 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
463 SUIT_ViewManager* mgr = app->activeViewManager();
465 return mgr->getActiveView();
470 SVTK_ViewWindow* GetCurrentVtkView(){
471 return GetVtkViewWindow( GetActiveWindow() );
475 void RepaintCurrentView()
477 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
480 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
483 wnd->getRenderer()->Render();
488 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" );
495 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
498 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
501 theWindow->getRenderer()->Render();
502 theWindow->Repaint();
506 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow*)" );
512 void RenderViewWindow(SVTK_ViewWindow* theWindow)
515 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
518 theWindow->getRenderer()->Render();
519 theWindow->Repaint();
523 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow*)" );
530 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
532 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
540 MESSAGE ( "Exception in SMESHGUI_VTKUtils::FitAll()" );
548 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
549 const char* theEntry)
551 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
552 vtkRenderer *aRenderer = aViewWindow->getRenderer();
553 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
554 vtkActorCollection *aCollection = aCopy.GetActors();
555 aCollection->InitTraversal();
556 while(vtkActor *anAct = aCollection->GetNextActor()){
557 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
558 if(anActor->hasIO()){
559 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
560 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
571 SMESH_Actor* FindActorByEntry(const char* theEntry){
572 return FindActorByEntry(GetActiveWindow(),theEntry);
576 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
577 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
581 if(!CORBA::is_nil(theObject)){
582 _PTR(Study) aStudy = GetActiveStudyDocument();
583 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
584 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
586 CORBA::String_var anEntry = aSObject->GetID().c_str();
587 return FindActorByEntry(anEntry.in());
594 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
595 const char* theEntry,
598 SMESH_Actor *anActor = NULL;
599 CORBA::Long anId = theStudy->StudyId();
600 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
601 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
603 _PTR(GenericAttribute) anAttr;
604 if(aSObj->FindAttribute(anAttr,"AttributeName")){
605 _PTR(AttributeName) aName = anAttr;
606 std::string aNameVal = aName->Value();
607 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
610 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
611 if(!CORBA::is_nil(aGroup) && anActor)
615 SMESH::GetColor( "SMESH", "fill_color", c, deltaF, "0,170,255|-100" );
616 SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
617 c = SMESH::GetColor( "SMESH", "default_grp_color", c );
618 SALOMEDS::Color aColor = aGroup->GetColor();
619 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ))
622 aColor.G = c.greenF();
623 aColor.B = c.blueF();
624 aGroup->SetColor( aColor );
626 if( aGroup->GetType() == SMESH::NODE )
627 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
628 else if( aGroup->GetType() == SMESH::EDGE )
629 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
630 else if( aGroup->GetType() == SMESH::ELEM0D )
631 anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
632 else if( aGroup->GetType() == SMESH::BALL )
633 anActor->SetBallColor( aColor.R, aColor.G, aColor.B );
634 else if( aGroup->GetType() == SMESH::VOLUME )
635 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, deltaV );
637 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, deltaF );
641 MESSAGE("CreateActor " << anActor);
643 if( SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI() )
644 aSMESHGUI->addActorAsObserver( anActor );
649 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
650 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
652 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
655 MESSAGE("DisplayActor " << theActor);
656 vtkWnd->AddActor(theActor);
661 MESSAGE ( "Exception in SMESHGUI_VTKUtils::DisplayActor()" );
669 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
670 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
671 MESSAGE("RemoveActor " << theActor);
672 vtkWnd->RemoveActor(theActor);
673 if(theActor->hasIO()){
674 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
675 if(anIO->hasEntry()){
676 std::string anEntry = anIO->getEntry();
677 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
678 int aStudyId = aStudy->id();
679 TVisualObjCont::key_type aKey(aStudyId,anEntry);
680 VISUAL_OBJ_CONT.erase(aKey);
688 //================================================================================
690 * \brief Return true if there are no SMESH actors in a view
692 //================================================================================
694 bool noSmeshActors(SUIT_ViewWindow *theWnd)
696 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWnd)) {
697 vtkRenderer *aRenderer = aViewWindow->getRenderer();
698 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
699 vtkActorCollection *aCollection = aCopy.GetActors();
700 aCollection->InitTraversal();
701 while(vtkActor *anAct = aCollection->GetNextActor())
702 if(dynamic_cast<SMESH_Actor*>(anAct))
708 bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
710 //MESSAGE("UpdateView");
712 SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
716 SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd);
720 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
727 vtkRenderer *aRenderer = aViewWnd->getRenderer();
728 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
729 vtkActorCollection *aCollection = aCopy.GetActors();
730 aCollection->InitTraversal();
734 while (vtkActor *anAct = aCollection->GetNextActor()) {
735 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
736 MESSAGE("--- display " << anActor);
737 anActor->SetVisibility(true);
739 if(anActor->hasIO()){
740 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
741 if(anIO->hasEntry()){
742 aStudy->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
751 //MESSAGE("---case eDisplayOnly");
752 while (vtkActor *anAct = aCollection->GetNextActor()) {
753 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
754 //MESSAGE("--- erase " << anActor);
755 anActor->SetVisibility(false);
758 aStudy->setVisibilityStateForAll(Qtx::HiddenState);
761 if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
765 //MESSAGE("--- display " << anActor);
767 anActor->SetVisibility(true);
768 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
769 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
772 //MESSAGE("--- erase " << anActor);
773 anActor->SetVisibility(false);
774 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
783 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(theWnd->getViewManager()->study());
784 _PTR(Study) aDocument = aStudy->studyDS();
785 // Pass non-visual objects (hypotheses, etc.), return true in this case
786 CORBA::Long anId = aDocument->StudyId();
787 TVisualObjPtr aVisualObj;
788 if ( (aVisualObj = GetVisualObj(anId,theEntry)) && aVisualObj->IsValid())
790 if ((anActor = CreateActor(aDocument,theEntry,true))) {
791 bool needFitAll = noSmeshActors(theWnd); // fit for the first object only
792 DisplayActor(theWnd,anActor);
793 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
794 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
795 if (needFitAll) FitAll();
811 bool UpdateView(EDisplaing theAction, const char* theEntry){
812 //MESSAGE("UpdateView");
813 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
814 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
815 SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
816 return UpdateView(aWnd,theAction,theEntry);
820 if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
821 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
822 SALOME_ListIO selected; mgr->selectedObjects( selected );
824 if( selected.Extent() == 0){
825 vtkRenderer* aRenderer = aWnd->getRenderer();
826 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
827 vtkActorCollection *aCollection = aCopy.GetActors();
828 aCollection->InitTraversal();
829 while(vtkActor *anAct = aCollection->GetNextActor()){
830 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
832 if (!Update(anActor->getIO(),anActor->GetVisibility()))
833 break; // avoid multiple warinings if visu failed
837 SALOME_ListIteratorOfListIO anIter( selected );
838 for( ; anIter.More(); anIter.Next()){
839 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
840 if ( !Update(anIO,true) )
841 break; // avoid multiple warinings if visu failed
844 RepaintCurrentView();
849 bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
852 _PTR(Study) aStudy = GetActiveStudyDocument();
853 CORBA::Long anId = aStudy->StudyId();
854 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
856 UpdateView(SMESH::eDisplay,theIO->getEntry());
862 bool UpdateNulData(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
864 MESSAGE("UpdateNulData");
865 _PTR(Study) aStudy = GetActiveStudyDocument();
866 CORBA::Long anId = aStudy->StudyId();
867 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry(), true)) {
869 UpdateView(SMESH::eDisplay,theIO->getEntry());
875 void UpdateSelectionProp( SMESHGUI* theModule ) {
879 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
882 MESSAGE( "UpdateSelectionProp: Application is null" );
886 SUIT_ViewManager* vm = app->activeViewManager();
889 MESSAGE( "UpdateSelectionProp: View manager is null" );
893 QVector<SUIT_ViewWindow*> views = vm->getViews();
895 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
898 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
902 QColor aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
903 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
904 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
906 int aElem0DSize = mgr->integerValue("SMESH", "elem0d_size", 5);
907 // int aBallSize = mgr->integerValue("SMESH", "ball_elem_size", 5);
908 int aLineWidth = mgr->integerValue("SMESH", "element_width", 1);
909 int maxSize = aElem0DSize;
910 if (aElem0DSize > maxSize) maxSize = aElem0DSize;
911 if (aLineWidth > maxSize) maxSize = aLineWidth;
912 // if (aBallSize > maxSize) maxSize = aBallSize;
914 double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
915 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
916 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
918 for ( int i=0, n=views.count(); i<n; i++ ){
919 // update VTK viewer properties
920 if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
921 // mesh element selection
922 aVtkView->SetSelectionProp(aSelColor.red()/255.,
923 aSelColor.green()/255.,
924 aSelColor.blue()/255.);
926 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
929 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
930 aPreColor.green()/255.,
931 aPreColor.blue()/255.);
933 vtkRenderer* aRenderer = aVtkView->getRenderer();
934 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
935 vtkActorCollection *aCollection = aCopy.GetActors();
936 aCollection->InitTraversal();
937 while(vtkActor *anAct = aCollection->GetNextActor()){
938 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
939 anActor->SetHighlightColor(aHiColor.red()/255.,
940 aHiColor.green()/255.,
941 aHiColor.blue()/255.);
942 anActor->SetPreHighlightColor(aPreColor.red()/255.,
943 aPreColor.green()/255.,
944 aPreColor.blue()/255.);
952 void UpdateFontProp( SMESHGUI* theModule )
954 if ( !theModule ) return;
956 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
959 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
962 double anRGBNd[3] = {1,1,1};
963 SMESH::GetColor( "SMESH", "numbering_node_color", anRGBNd[0], anRGBNd[1], anRGBNd[2], QColor( 255, 255, 255 ) );
965 SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
967 bool anItalicNd = false;
968 bool aShadowNd = false;
970 if ( mgr->hasValue( "SMESH", "numbering_node_font" ) ) {
971 QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
972 if ( f.family() == "Arial" ) aFamilyNd = SMESH::FntArial;
973 else if ( f.family() == "Courier" ) aFamilyNd = SMESH::FntCourier;
974 else if ( f.family() == "Times" ) aFamilyNd = SMESH::FntTimes;
976 anItalicNd = f.italic();
977 aShadowNd = f.overline();
978 aSizeNd = f.pointSize();
981 double anRGBEl[3] = {0,1,0};
982 SMESH::GetColor( "SMESH", "numbering_elem_color", anRGBEl[0], anRGBEl[1], anRGBEl[2], QColor( 0, 255, 0 ) );
984 SMESH::LabelFont aFamilyEl = SMESH::FntTimes;
986 bool anItalicEl = false;
987 bool aShadowEl = false;
989 if ( mgr->hasValue( "SMESH", "numbering_elem_font" ) ) {
990 QFont f = mgr->fontValue( "SMESH", "numbering_elem_font" );
992 if ( f.family() == "Arial" ) aFamilyEl = SMESH::FntArial;
993 else if ( f.family() == "Courier" ) aFamilyEl = SMESH::FntCourier;
994 else if ( f.family() == "Times" ) aFamilyEl = SMESH::FntTimes;
996 anItalicEl = f.italic();
997 aShadowEl = f.overline();
998 aSizeEl = f.pointSize();
1001 ViewManagerList vmList;
1002 app->viewManagers( SVTK_Viewer::Type(), vmList );
1003 foreach ( SUIT_ViewManager* vm, vmList ) {
1004 QVector<SUIT_ViewWindow*> views = vm->getViews();
1005 foreach ( SUIT_ViewWindow* vw, views ) {
1006 // update VTK viewer properties
1007 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( vw ) ) {
1009 vtkRenderer* aRenderer = aVtkView->getRenderer();
1010 VTK::ActorCollectionCopy aCopy( aRenderer->GetActors() );
1011 vtkActorCollection* aCollection = aCopy.GetActors();
1012 aCollection->InitTraversal();
1013 while ( vtkActor* anAct = aCollection->GetNextActor() ) {
1014 if ( SMESH_NodeLabelActor* anActor = dynamic_cast< SMESH_NodeLabelActor* >( anAct ) ) {
1015 anActor->SetFontProperties( aFamilyNd, aSizeNd, aBoldNd, anItalicNd, aShadowNd, anRGBNd[0], anRGBNd[1], anRGBNd[2] );
1017 else if ( SMESH_CellLabelActor* anActor = dynamic_cast< SMESH_CellLabelActor* >( anAct ) ) {
1018 anActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
1021 aVtkView->Repaint( false );
1027 //----------------------------------------------------------------------------
1029 GetSelector(SUIT_ViewWindow *theWindow)
1031 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
1032 return aWnd->GetSelector();
1037 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
1038 SVTK_Selector* theSelector)
1041 theSelector->SetFilter(theFilter);
1044 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
1046 return theSelector->GetFilter(theId);
1049 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
1051 return theSelector->IsFilterPresent(theId);
1054 void RemoveFilter(int theId, SVTK_Selector* theSelector)
1056 theSelector->RemoveFilter(theId);
1059 void RemoveFilters(SVTK_Selector* theSelector)
1061 for ( int id = SMESH::NodeFilter; theSelector && id < SMESH::LastFilter; id++ )
1062 theSelector->RemoveFilter( id );
1065 bool IsValid(SALOME_Actor* theActor, int theCellId,
1066 SVTK_Selector* theSelector)
1068 return theSelector->IsValid(theActor,theCellId);
1072 //----------------------------------------------------------------------------
1073 void SetPointRepresentation(bool theIsVisible){
1074 if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
1075 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1076 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1077 vtkActorCollection *aCollection = aCopy.GetActors();
1078 aCollection->InitTraversal();
1079 while(vtkActor *anAct = aCollection->GetNextActor()){
1080 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1081 if(anActor->GetVisibility()){
1082 anActor->SetPointRepresentation(theIsVisible);
1086 RepaintCurrentView();
1091 void SetPickable(SMESH_Actor* theActor){
1092 if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
1093 int anIsAllPickable = (theActor == NULL);
1094 vtkRenderer *aRenderer = aWnd->getRenderer();
1095 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1096 vtkActorCollection *aCollection = aCopy.GetActors();
1097 aCollection->InitTraversal();
1098 while(vtkActor *anAct = aCollection->GetNextActor()){
1099 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
1100 if(anActor->GetVisibility()){
1101 anActor->SetPickable(anIsAllPickable);
1106 theActor->SetPickable(!anIsAllPickable);
1107 RepaintCurrentView();
1112 //----------------------------------------------------------------------------
1113 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
1114 const Handle(SALOME_InteractiveObject)& theIO,
1118 TColStd_IndexedMapOfInteger aMapIndex;
1119 theSelector->GetIndex(theIO,aMapIndex);
1121 for(int i = 1; i <= aMapIndex.Extent(); i++)
1122 theName += QString(" %1").arg(aMapIndex(i));
1124 return aMapIndex.Extent();
1127 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
1128 const Handle(SALOME_InteractiveObject)& theIO,
1132 TColStd_IndexedMapOfInteger aMapIndex;
1133 theSelector->GetIndex(theIO,aMapIndex);
1135 typedef std::set<int> TIdContainer;
1136 TIdContainer anIdContainer;
1137 for( int i = 1; i <= aMapIndex.Extent(); i++)
1138 anIdContainer.insert(aMapIndex(i));
1140 TIdContainer::const_iterator anIter = anIdContainer.begin();
1141 for( ; anIter != anIdContainer.end(); anIter++)
1142 theName += QString(" %1").arg(*anIter);
1144 return aMapIndex.Extent();
1148 int GetEdgeNodes(SVTK_Selector* theSelector,
1149 const TVisualObjPtr& theVisualObject,
1153 const SALOME_ListIO& selected = theSelector->StoredIObjects();
1155 if ( selected.Extent() != 1 )
1158 Handle(SALOME_InteractiveObject) anIO = selected.First();
1159 if ( anIO.IsNull() || !anIO->hasEntry() )
1162 TColStd_IndexedMapOfInteger aMapIndex;
1163 theSelector->GetIndex( anIO, aMapIndex );
1164 if ( aMapIndex.Extent() != 2 )
1167 int anObjId = -1, anEdgeNum = -1;
1168 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1169 int aVal = aMapIndex( i );
1173 anEdgeNum = abs( aVal ) - 1;
1176 if ( anObjId == -1 || anEdgeNum == -1 )
1179 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1182 //----------------------------------------------------------------------------
1183 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1184 const Handle(SALOME_InteractiveObject)& theIO,
1188 if(theIO->hasEntry()){
1189 if(FindActorByEntry(theIO->getEntry())){
1190 TColStd_IndexedMapOfInteger aMapIndex;
1191 theMgr->GetIndexes(theIO,aMapIndex);
1192 for(int i = 1; i <= aMapIndex.Extent(); i++){
1193 theName += QString(" %1").arg(aMapIndex(i));
1195 return aMapIndex.Extent();
1201 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName){
1203 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1204 if(selected.Extent() == 1){
1205 Handle(SALOME_InteractiveObject) anIO = selected.First();
1206 return GetNameOfSelectedNodes(theMgr,anIO,theName);
1212 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr,
1213 const Handle(SALOME_InteractiveObject)& theIO,
1217 if(theIO->hasEntry()){
1218 if(FindActorByEntry(theIO->getEntry())){
1219 TColStd_IndexedMapOfInteger aMapIndex;
1220 theMgr->GetIndexes(theIO,aMapIndex);
1221 typedef std::set<int> TIdContainer;
1222 TIdContainer anIdContainer;
1223 for( int i = 1; i <= aMapIndex.Extent(); i++)
1224 anIdContainer.insert(aMapIndex(i));
1225 TIdContainer::const_iterator anIter = anIdContainer.begin();
1226 for( ; anIter != anIdContainer.end(); anIter++){
1227 theName += QString(" %1").arg(*anIter);
1229 return aMapIndex.Extent();
1236 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1239 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1241 if( selected.Extent() == 1){
1242 Handle(SALOME_InteractiveObject) anIO = selected.First();
1243 return GetNameOfSelectedElements(theMgr,anIO,theName);
1248 int GetSelected(LightApp_SelectionMgr* theMgr,
1249 TColStd_IndexedMapOfInteger& theMap,
1250 const bool theIsElement)
1253 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1255 if ( selected.Extent() == 1 )
1257 Handle(SALOME_InteractiveObject) anIO = selected.First();
1258 if ( anIO->hasEntry() ) {
1259 theMgr->GetIndexes( anIO, theMap );
1262 return theMap.Extent();
1266 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
1268 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1270 if ( selected.Extent() != 1 )
1273 Handle(SALOME_InteractiveObject) anIO = selected.First();
1274 if ( anIO.IsNull() || !anIO->hasEntry() )
1277 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1281 TColStd_IndexedMapOfInteger aMapIndex;
1282 theMgr->GetIndexes( anIO, aMapIndex );
1283 if ( aMapIndex.Extent() != 2 )
1286 int anObjId = -1, anEdgeNum = -1;
1287 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1288 int aVal = aMapIndex( i );
1292 anEdgeNum = abs( aVal );
1295 if ( anObjId == -1 || anEdgeNum == -1 )
1298 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1301 void SetControlsPrecision( const long theVal )
1303 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1305 vtkRenderer *aRenderer = aWnd->getRenderer();
1306 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1307 vtkActorCollection *aCollection = aCopy.GetActors();
1308 aCollection->InitTraversal();
1310 while ( vtkActor *anAct = aCollection->GetNextActor())
1312 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1314 anActor->SetControlsPrecision( theVal );
1315 anActor->SetControlMode( anActor->GetControlMode() );
1322 //----------------------------------------------------------------------------
1323 // internal function
1324 void ComputeBoundsParam( double theBounds[6],
1325 double theDirection[3],
1326 double theMinPnt[3],
1327 double& theMaxBoundPrj,
1328 double& theMinBoundPrj )
1330 //Enlarge bounds in order to avoid conflicts of precision
1331 for(int i = 0; i < 6; i += 2){
1332 static double EPS = 1.0E-3;
1333 double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
1334 theBounds[i] -= aDelta;
1335 theBounds[i+1] += aDelta;
1338 double aBoundPoints[8][3] = { {theBounds[0],theBounds[2],theBounds[4]},
1339 {theBounds[1],theBounds[2],theBounds[4]},
1340 {theBounds[0],theBounds[3],theBounds[4]},
1341 {theBounds[1],theBounds[3],theBounds[4]},
1342 {theBounds[0],theBounds[2],theBounds[5]},
1343 {theBounds[1],theBounds[2],theBounds[5]},
1344 {theBounds[0],theBounds[3],theBounds[5]},
1345 {theBounds[1],theBounds[3],theBounds[5]}};
1348 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1349 theMinBoundPrj = theMaxBoundPrj;
1350 for(int i = 1; i < 8; i++){
1351 double aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1352 if(theMaxBoundPrj < aTmp){
1353 theMaxBoundPrj = aTmp;
1356 if(theMinBoundPrj > aTmp){
1357 theMinBoundPrj = aTmp;
1360 double *aMinPnt = aBoundPoints[aMaxId];
1361 theMinPnt[0] = aMinPnt[0];
1362 theMinPnt[1] = aMinPnt[1];
1363 theMinPnt[2] = aMinPnt[2];
1366 // internal function
1367 void DistanceToPosition( double theBounds[6],
1368 double theDirection[3],
1372 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1373 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1374 double aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1375 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1376 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1377 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1380 // internal function (currently unused, left just in case)
1381 void PositionToDistance( double theBounds[6],
1382 double theDirection[3],
1386 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1387 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1388 double aPrj = vtkMath::Dot(theDirection,thePos);
1389 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1392 bool ComputeClippingPlaneParameters( std::list<vtkActor*> theActorList,
1393 double theNormal[3],
1395 double theBounds[6],
1396 double theOrigin[3] )
1398 bool anIsOk = false;
1399 anIsOk = ComputeBounds( theActorList, theBounds );
1405 DistanceToPosition( theBounds, theNormal, theDist, theOrigin );
1409 bool ComputeBounds( std::list<vtkActor*> theActorList,
1410 double theBounds[6])
1412 bool anIsOk = false;
1413 theBounds[0] = theBounds[2] = theBounds[4] = VTK_DOUBLE_MAX;
1414 theBounds[1] = theBounds[3] = theBounds[5] = -VTK_DOUBLE_MAX;
1415 std::list<vtkActor*>::iterator anIter = theActorList.begin();
1416 for( ; anIter != theActorList.end(); anIter++ ) {
1417 if( vtkActor* aVTKActor = *anIter ) {
1418 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1420 anActor->GetUnstructuredGrid()->GetBounds( aBounds );
1421 theBounds[0] = std::min( theBounds[0], aBounds[0] );
1422 theBounds[1] = std::max( theBounds[1], aBounds[1] );
1423 theBounds[2] = std::min( theBounds[2], aBounds[2] );
1424 theBounds[3] = std::max( theBounds[3], aBounds[3] );
1425 theBounds[4] = std::min( theBounds[4], aBounds[4] );
1426 theBounds[5] = std::max( theBounds[5], aBounds[5] );
1434 #ifndef DISABLE_PLOT2DVIEWER
1435 //================================================================================
1437 * \brief Find all SMESH_Actor's in the View Window.
1438 * If actor constains Plot2d_Histogram object remove it from each Plot2d Viewer.
1440 //================================================================================
1442 void ClearPlot2Viewers( SUIT_ViewWindow* theWindow ) {
1443 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
1444 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1445 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1446 vtkActorCollection *aCollection = aCopy.GetActors();
1447 aCollection->InitTraversal();
1448 while(vtkActor *anAct = aCollection->GetNextActor()){
1449 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1450 if(anActor->hasIO() && anActor->GetPlot2Histogram() ){
1451 ProcessIn2DViewers(anActor,RemoveFrom2dViewer);
1460 } // end of namespace SMESH