1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_VTKUtils.cxx
25 // Author : Open CASCADE S.A.S.
28 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_Filter.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMDS_Mesh.hxx"
34 #include "SMESH_Actor.h"
35 #include "SMESH_ActorUtils.h"
36 #include "SMESH_CellLabelActor.h"
37 #include "SMESH_ControlsDef.hxx"
38 #include "SMESH_NodeLabelActor.h"
39 #include "SMESH_ObjectDef.h"
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_ResourceMgr.h>
48 #include <SALOME_ListIO.hxx>
50 #include <SVTK_Selector.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
54 #include <VTKViewer_Algorithm.h>
56 #include <LightApp_SelectionMgr.h>
57 #include <SalomeApp_Application.h>
58 #include <SalomeApp_Study.h>
60 // SALOME KERNEL includes
61 #include <utilities.h>
64 #include <SALOMEconfig.h>
65 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
66 #include CORBA_CLIENT_HEADER(SMESH_Group)
70 #include <vtkRenderer.h>
71 #include <vtkActorCollection.h>
72 #include <vtkUnstructuredGrid.h>
75 #include <Standard_ErrorHandler.hxx>
79 typedef std::map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
80 static TVisualObjCont VISUAL_OBJ_CONT;
82 //=============================================================================
84 * \brief Allocate some memory at construction and release it at destruction.
85 * Is used to be able to continue working after mesh generation or visualization
86 * break due to lack of memory
88 //=============================================================================
93 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
94 void Free() { if (myBuf) { delete [] myBuf; myBuf = 0; }}
95 ~MemoryReserve() { Free(); }
97 static MemoryReserve* theVISU_MemoryReserve = new MemoryReserve;
99 //================================================================================
101 * \brief Remove VisualObj and its actor from all views
103 //================================================================================
105 void RemoveVisualObjectWithActors( const char* theEntry, bool fromAllViews )
107 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
110 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
113 ViewManagerList aList;
116 app->viewManagers(SVTK_Viewer::Type() , aList);
118 SUIT_ViewManager* aVM = app->getViewManager(SVTK_Viewer::Type(), true);
122 bool actorRemoved = false;
123 ViewManagerList::ConstIterator it = aList.begin();
124 SUIT_ViewManager* aViewManager = 0;
125 for( ; it!=aList.end();it++) {
127 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
128 for ( int iV = 0; iV < views.count(); ++iV ) {
129 if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
130 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
131 vtkWnd->RemoveActor(actor);
140 int aStudyId = aViewManager->study()->id();
141 TVisualObjCont::key_type aKey(aStudyId,theEntry);
142 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
143 if(anIter != VISUAL_OBJ_CONT.end()) {
144 // for unknown reason, object destructor is not called, so clear object manually
145 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
146 anIter->second->GetUnstructuredGrid()->SetPoints(0);
148 VISUAL_OBJ_CONT.erase(aKey);
152 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
154 //================================================================================
156 * \brief Remove all VisualObjs and their actors from all views
158 //================================================================================
160 void RemoveAllObjectsWithActors()
162 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
163 ( SUIT_Session::session()->activeApplication() );
165 ViewManagerList viewMgrs = app->viewManagers();
166 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
167 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
168 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type()) {
169 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
170 for ( int iV = 0; iV < views.count(); ++iV ) {
171 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
172 vtkRenderer *aRenderer = vtkWnd->getRenderer();
173 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
174 vtkActorCollection *actors = aCopy.GetActors();
175 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
176 // size of actors changes inside the loop
177 if (SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
179 vtkWnd->RemoveActor(actor);
187 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
188 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
189 // for unknown reason, object destructor is not called, so clear object manually
190 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
191 anIter->second->GetUnstructuredGrid()->SetPoints(0);
193 VISUAL_OBJ_CONT.clear();
196 //================================================================================
198 * \brief Remove all VisualObjs of a study
200 //================================================================================
202 void RemoveVisuData(int studyID)
204 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
205 ( SUIT_Session::session()->activeApplication() );
207 ViewManagerList viewMgrs = app->viewManagers();
208 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
209 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
210 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type() &&
211 aViewManager->study()->id() == studyID ) {
212 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
213 for ( int iV = 0; iV < views.count(); ++iV ) {
214 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
215 vtkRenderer *aRenderer = vtkWnd->getRenderer();
216 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
217 vtkActorCollection *actors = aCopy.GetActors();
218 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
219 // size of actors changes inside the loop
220 if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
222 vtkWnd->RemoveActor(actor);
230 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
231 for ( ; anIter != VISUAL_OBJ_CONT.end(); ) {
232 int curId = anIter->first.first;
233 if ( curId == studyID ) {
234 // for unknown reason, object destructor is not called, so clear object manually
235 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
236 anIter->second->GetUnstructuredGrid()->SetPoints(0);
237 VISUAL_OBJ_CONT.erase( anIter++ ); // anIter++ returns a copy of self before incrementing
245 //================================================================================
247 * \brief Notify the user on problems during visualization
249 //================================================================================
251 void OnVisuException()
254 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
257 // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
258 // after or at showing this message, so we do an additional check of available memory
259 // char* buf = new char[100*1024];
261 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
262 QObject::tr("SMESH_VISU_PROBLEM"));
264 // no more memory at all: last resort
265 MESSAGE_BEGIN ( "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<
266 std::endl << "Try to remove all visual data..." );
267 if (theVISU_MemoryReserve) {
268 delete theVISU_MemoryReserve;
269 theVISU_MemoryReserve = 0;
271 RemoveAllObjectsWithActors();
272 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
273 QObject::tr("SMESH_VISU_PROBLEM_CLEAR"));
274 MESSAGE_END ( "...done" );
277 //================================================================================
279 * \brief Returns an updated visual object
281 //================================================================================
283 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry, bool nulData){
284 TVisualObjPtr aVisualObj;
285 TVisualObjCont::key_type aKey(theStudyId,theEntry);
287 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
290 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
291 if(anIter != VISUAL_OBJ_CONT.end()){
292 aVisualObj = anIter->second;
294 SalomeApp_Application* app =
295 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
296 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
297 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
299 _PTR(GenericAttribute) anAttr;
300 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
301 _PTR(AttributeIOR) anIOR = anAttr;
302 CORBA::String_var aVal = anIOR->Value().c_str();
303 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
304 if(!CORBA::is_nil(anObj)){
305 //Try narrow to SMESH_Mesh interface
306 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
307 if(!aMesh->_is_nil()){
308 aVisualObj.reset(new SMESH_MeshObj(aMesh));
309 TVisualObjCont::value_type aValue(aKey,aVisualObj);
310 VISUAL_OBJ_CONT.insert(aValue);
312 //Try narrow to SMESH_Group interface
313 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
314 if(!aGroup->_is_nil()){
315 _PTR(SObject) aFatherSObj = aSObj->GetFather();
316 if(!aFatherSObj) return aVisualObj;
317 aFatherSObj = aFatherSObj->GetFather();
318 if(!aFatherSObj) return aVisualObj;
319 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
320 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
321 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
322 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
323 TVisualObjCont::value_type aValue(aKey,aVisualObj);
324 VISUAL_OBJ_CONT.insert(aValue);
327 //Try narrow to SMESH_subMesh interface
328 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
329 if(!aSubMesh->_is_nil()){
330 _PTR(SObject) aFatherSObj = aSObj->GetFather();
331 if(!aFatherSObj) return aVisualObj;
332 aFatherSObj = aFatherSObj->GetFather();
333 if(!aFatherSObj) return aVisualObj;
334 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
335 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
336 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
337 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
338 TVisualObjCont::value_type aValue(aKey,aVisualObj);
339 VISUAL_OBJ_CONT.insert(aValue);
347 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
348 return TVisualObjPtr();
351 bool objModified = false;
354 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
357 //MESSAGE("GetVisualObj");
359 objModified = aVisualObj->NulData();
361 objModified = aVisualObj->Update();
365 MESSAGE ( "Exception in SMESHGUI_VTKUtils::GetVisualObj()" );
367 RemoveVisualObjectWithActors( theEntry ); // remove this object
374 // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
375 // ~5 times more memory is used than it occupies.
376 // Warn the user if there is less free memory than 30 sizes of a grid
377 // TODO: estimate memory usage in other modes and take current mode into account
378 int freeMB = SMDS_Mesh::CheckMemory(true);
379 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
380 MESSAGE("SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB << ", usedMB=" <<usedMB);
381 if ( freeMB > 0 && usedMB * 5 > freeMB ) {
382 bool continu = false;
383 if ( usedMB * 3 > freeMB )
384 // even dont try to show
385 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
386 QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
388 // there is a chance to succeed
389 continu = SUIT_MessageBox::warning
390 (SMESHGUI::desktop(),
391 QObject::tr("SMESH_WRN_WARNING"),
392 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
393 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
394 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
396 // remove the corresponding actors from all views
397 RemoveVisualObjectWithActors( theEntry );
407 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
408 * overwise find or create corresponding view window, make it active and return it.
409 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
411 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
412 bool createIfNotFound)
414 SalomeApp_Application* anApp;
416 anApp = theModule->getApp();
418 anApp = dynamic_cast<SalomeApp_Application*>
419 (SUIT_Session::session()->activeApplication());
422 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
425 SUIT_ViewManager* aViewManager =
426 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
428 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
429 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
430 aViewWindow->raise();
431 aViewWindow->setFocus();
440 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
441 SUIT_ViewWindow * theWindow)
446 QVector<SUIT_ViewWindow*> views = theMgr->getViews();
447 if( views.contains( theWindow ) )
448 return GetVtkViewWindow( theWindow );
453 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
454 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
457 /* SUIT_ViewWindow* GetActiveWindow()
459 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
462 SUIT_ViewManager* mgr = app->activeViewManager();
464 return mgr->getActiveView();
469 SVTK_ViewWindow* GetCurrentVtkView(){
470 return GetVtkViewWindow( GetActiveWindow() );
474 void RepaintCurrentView()
476 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
479 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
482 wnd->getRenderer()->Render();
487 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" );
494 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
497 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
500 theWindow->getRenderer()->Render();
501 theWindow->Repaint();
505 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow*)" );
511 void RenderViewWindow(SVTK_ViewWindow* theWindow)
514 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
517 theWindow->getRenderer()->Render();
518 theWindow->Repaint();
522 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow*)" );
529 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
531 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
539 MESSAGE ( "Exception in SMESHGUI_VTKUtils::FitAll()" );
547 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
548 const char* theEntry)
550 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
551 vtkRenderer *aRenderer = aViewWindow->getRenderer();
552 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
553 vtkActorCollection *aCollection = aCopy.GetActors();
554 aCollection->InitTraversal();
555 while(vtkActor *anAct = aCollection->GetNextActor()){
556 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
557 if(anActor->hasIO()){
558 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
559 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
570 SMESH_Actor* FindActorByEntry(const char* theEntry){
571 return FindActorByEntry(GetActiveWindow(),theEntry);
575 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
576 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
580 if(!CORBA::is_nil(theObject)){
581 _PTR(Study) aStudy = GetActiveStudyDocument();
582 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
583 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
585 CORBA::String_var anEntry = aSObject->GetID().c_str();
586 return FindActorByEntry(anEntry.in());
593 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
594 const char* theEntry,
597 SMESH_Actor *anActor = NULL;
598 CORBA::Long anId = theStudy->StudyId();
599 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
600 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
602 _PTR(GenericAttribute) anAttr;
603 if(aSObj->FindAttribute(anAttr,"AttributeName")){
604 _PTR(AttributeName) aName = anAttr;
605 std::string aNameVal = aName->Value();
606 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
609 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
610 if(!CORBA::is_nil(aGroup) && anActor)
614 SMESH::GetColor( "SMESH", "fill_color", c, deltaF, "0,170,255|-100" );
615 SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
616 c = SMESH::GetColor( "SMESH", "default_grp_color", c );
617 SALOMEDS::Color aColor = aGroup->GetColor();
618 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ))
621 aColor.G = c.greenF();
622 aColor.B = c.blueF();
623 aGroup->SetColor( aColor );
625 if( aGroup->GetType() == SMESH::NODE )
626 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
627 else if( aGroup->GetType() == SMESH::EDGE )
628 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
629 else if( aGroup->GetType() == SMESH::ELEM0D )
630 anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
631 else if( aGroup->GetType() == SMESH::BALL )
632 anActor->SetBallColor( aColor.R, aColor.G, aColor.B );
633 else if( aGroup->GetType() == SMESH::VOLUME )
634 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, deltaV );
636 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, deltaF );
640 MESSAGE("CreateActor " << anActor);
642 if( SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI() )
643 aSMESHGUI->addActorAsObserver( anActor );
648 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
649 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
651 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
654 MESSAGE("DisplayActor " << theActor);
655 vtkWnd->AddActor(theActor);
660 MESSAGE ( "Exception in SMESHGUI_VTKUtils::DisplayActor()" );
668 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
669 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
670 MESSAGE("RemoveActor " << theActor);
671 vtkWnd->RemoveActor(theActor);
672 if(theActor->hasIO()){
673 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
674 if(anIO->hasEntry()){
675 std::string anEntry = anIO->getEntry();
676 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
677 int aStudyId = aStudy->id();
678 TVisualObjCont::key_type aKey(aStudyId,anEntry);
679 VISUAL_OBJ_CONT.erase(aKey);
687 //================================================================================
689 * \brief Return true if there are no SMESH actors in a view
691 //================================================================================
693 bool noSmeshActors(SUIT_ViewWindow *theWnd)
695 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWnd)) {
696 vtkRenderer *aRenderer = aViewWindow->getRenderer();
697 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
698 vtkActorCollection *aCollection = aCopy.GetActors();
699 aCollection->InitTraversal();
700 while(vtkActor *anAct = aCollection->GetNextActor())
701 if(dynamic_cast<SMESH_Actor*>(anAct))
707 bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
709 //MESSAGE("UpdateView");
711 SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
715 SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd);
719 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
726 vtkRenderer *aRenderer = aViewWnd->getRenderer();
727 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
728 vtkActorCollection *aCollection = aCopy.GetActors();
729 aCollection->InitTraversal();
733 while (vtkActor *anAct = aCollection->GetNextActor()) {
734 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
735 MESSAGE("--- display " << anActor);
736 anActor->SetVisibility(true);
738 if(anActor->hasIO()){
739 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
740 if(anIO->hasEntry()){
741 aStudy->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
750 //MESSAGE("---case eDisplayOnly");
751 while (vtkActor *anAct = aCollection->GetNextActor()) {
752 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
753 //MESSAGE("--- erase " << anActor);
754 anActor->SetVisibility(false);
757 aStudy->setVisibilityStateForAll(Qtx::HiddenState);
760 if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
764 //MESSAGE("--- display " << anActor);
766 anActor->SetVisibility(true);
767 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
768 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
771 //MESSAGE("--- erase " << anActor);
772 anActor->SetVisibility(false);
773 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();
812 bool UpdateView(EDisplaing theAction, const char* theEntry) {
813 //MESSAGE("UpdateView");
814 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
815 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
816 if ( SUIT_ViewManager* vm = app->activeViewManager() )
818 SUIT_ViewWindow *aWnd = vm->getActiveView();
819 return UpdateView(aWnd,theAction,theEntry);
825 if ( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()) {
826 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
827 SALOME_ListIO selected; mgr->selectedObjects( selected );
829 if( selected.Extent() == 0){
830 vtkRenderer* aRenderer = aWnd->getRenderer();
831 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
832 vtkActorCollection *aCollection = aCopy.GetActors();
833 aCollection->InitTraversal();
834 while(vtkActor *anAct = aCollection->GetNextActor()){
835 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
837 if (!Update(anActor->getIO(),anActor->GetVisibility()))
838 break; // avoid multiple warinings if visu failed
842 SALOME_ListIteratorOfListIO anIter( selected );
843 for( ; anIter.More(); anIter.Next()){
844 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
845 if ( !Update(anIO,true) )
846 break; // avoid multiple warinings if visu failed
849 RepaintCurrentView();
854 bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
857 _PTR(Study) aStudy = GetActiveStudyDocument();
858 CORBA::Long anId = aStudy->StudyId();
859 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
861 UpdateView(SMESH::eDisplay,theIO->getEntry());
867 bool UpdateNulData(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
869 //MESSAGE("UpdateNulData");
870 _PTR(Study) aStudy = GetActiveStudyDocument();
871 CORBA::Long anId = aStudy->StudyId();
872 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry(), true)) {
874 UpdateView(SMESH::eDisplay,theIO->getEntry());
880 void UpdateSelectionProp( SMESHGUI* theModule )
885 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
888 MESSAGE( "UpdateSelectionProp: Application is null" );
892 SUIT_ViewManager* vm = app->activeViewManager();
895 MESSAGE( "UpdateSelectionProp: View manager is null" );
899 QVector<SUIT_ViewWindow*> views = vm->getViews();
901 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
904 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
909 aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
910 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
911 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
913 int aElem0DSize = mgr->integerValue("SMESH", "elem0d_size", 5);
914 // int aBallSize = mgr->integerValue("SMESH", "ball_elem_size", 5);
915 int aLineWidth = mgr->integerValue("SMESH", "element_width", 1);
916 int maxSize = aElem0DSize;
917 if (aElem0DSize > maxSize) maxSize = aElem0DSize;
918 if (aLineWidth > maxSize) maxSize = aLineWidth;
919 // if (aBallSize > maxSize) maxSize = aBallSize;
922 SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
923 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
924 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
926 for ( int i=0, n=views.count(); i<n; i++ )
928 // update VTK viewer properties
929 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] ))
931 // mesh element selection
932 aVtkView->SetSelectionProp(aSelColor.red()/255.,
933 aSelColor.green()/255.,
934 aSelColor.blue()/255.);
936 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
939 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
940 aPreColor.green()/255.,
941 aPreColor.blue()/255.);
943 vtkRenderer* aRenderer = aVtkView->getRenderer();
944 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
945 vtkActorCollection *aCollection = aCopy.GetActors();
946 aCollection->InitTraversal();
947 while ( vtkActor *anAct = aCollection->GetNextActor() ) {
948 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct) ) {
949 anActor->SetHighlightColor(aHiColor.red()/255.,
950 aHiColor.green()/255.,
951 aHiColor.blue()/255.);
952 anActor->SetPreHighlightColor(aPreColor.red()/255.,
953 aPreColor.green()/255.,
954 aPreColor.blue()/255.);
962 void UpdateFontProp( SMESHGUI* theModule )
964 if ( !theModule ) return;
966 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
969 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
972 double anRGBNd[3] = {1,1,1};
973 SMESH::GetColor( "SMESH", "numbering_node_color", anRGBNd[0], anRGBNd[1], anRGBNd[2], QColor( 255, 255, 255 ) );
975 SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
977 bool anItalicNd = false;
978 bool aShadowNd = false;
980 if ( mgr->hasValue( "SMESH", "numbering_node_font" ) ) {
981 QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
982 if ( f.family() == "Arial" ) aFamilyNd = SMESH::FntArial;
983 else if ( f.family() == "Courier" ) aFamilyNd = SMESH::FntCourier;
984 else if ( f.family() == "Times" ) aFamilyNd = SMESH::FntTimes;
986 anItalicNd = f.italic();
987 aShadowNd = f.overline();
988 aSizeNd = f.pointSize();
991 double anRGBEl[3] = {0,1,0};
992 SMESH::GetColor( "SMESH", "numbering_elem_color", anRGBEl[0], anRGBEl[1], anRGBEl[2], QColor( 0, 255, 0 ) );
994 SMESH::LabelFont aFamilyEl = SMESH::FntTimes;
996 bool anItalicEl = false;
997 bool aShadowEl = false;
999 if ( mgr->hasValue( "SMESH", "numbering_elem_font" ) ) {
1000 QFont f = mgr->fontValue( "SMESH", "numbering_elem_font" );
1002 if ( f.family() == "Arial" ) aFamilyEl = SMESH::FntArial;
1003 else if ( f.family() == "Courier" ) aFamilyEl = SMESH::FntCourier;
1004 else if ( f.family() == "Times" ) aFamilyEl = SMESH::FntTimes;
1006 anItalicEl = f.italic();
1007 aShadowEl = f.overline();
1008 aSizeEl = f.pointSize();
1011 ViewManagerList vmList;
1012 app->viewManagers( SVTK_Viewer::Type(), vmList );
1013 foreach ( SUIT_ViewManager* vm, vmList ) {
1014 QVector<SUIT_ViewWindow*> views = vm->getViews();
1015 foreach ( SUIT_ViewWindow* vw, views ) {
1016 // update VTK viewer properties
1017 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( vw ) ) {
1019 vtkRenderer* aRenderer = aVtkView->getRenderer();
1020 VTK::ActorCollectionCopy aCopy( aRenderer->GetActors() );
1021 vtkActorCollection* aCollection = aCopy.GetActors();
1022 aCollection->InitTraversal();
1023 while ( vtkActor* anAct = aCollection->GetNextActor() ) {
1024 if ( SMESH_NodeLabelActor* anActor = dynamic_cast< SMESH_NodeLabelActor* >( anAct ) ) {
1025 anActor->SetFontProperties( aFamilyNd, aSizeNd, aBoldNd, anItalicNd, aShadowNd, anRGBNd[0], anRGBNd[1], anRGBNd[2] );
1027 else if ( SMESH_CellLabelActor* anActor = dynamic_cast< SMESH_CellLabelActor* >( anAct ) ) {
1028 anActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
1031 aVtkView->Repaint( false );
1037 //----------------------------------------------------------------------------
1039 GetSelector(SUIT_ViewWindow *theWindow)
1041 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
1042 return aWnd->GetSelector();
1047 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
1048 SVTK_Selector* theSelector)
1051 theSelector->SetFilter(theFilter);
1054 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
1056 return theSelector->GetFilter(theId);
1059 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
1061 return theSelector->IsFilterPresent(theId);
1064 void RemoveFilter(int theId, SVTK_Selector* theSelector)
1066 theSelector->RemoveFilter(theId);
1069 void RemoveFilters(SVTK_Selector* theSelector)
1071 for ( int id = SMESH::NodeFilter; theSelector && id < SMESH::LastFilter; id++ )
1072 theSelector->RemoveFilter( id );
1075 bool IsValid(SALOME_Actor* theActor, int theCellId,
1076 SVTK_Selector* theSelector)
1078 return theSelector->IsValid(theActor,theCellId);
1082 //----------------------------------------------------------------------------
1083 void SetPointRepresentation(bool theIsVisible)
1085 if ( SVTK_ViewWindow* aViewWindow = GetCurrentVtkView() ) {
1086 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1087 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1088 vtkActorCollection *aCollection = aCopy.GetActors();
1089 aCollection->InitTraversal();
1090 while(vtkActor *anAct = aCollection->GetNextActor()){
1091 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1092 if(anActor->GetVisibility()){
1093 anActor->SetPointRepresentation(theIsVisible);
1097 RepaintCurrentView();
1102 void SetPickable(SMESH_Actor* theActor)
1104 if ( SVTK_ViewWindow* aWnd = GetCurrentVtkView() ) {
1105 int anIsAllPickable = (theActor == NULL);
1106 vtkRenderer *aRenderer = aWnd->getRenderer();
1107 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1108 vtkActorCollection *aCollection = aCopy.GetActors();
1109 aCollection->InitTraversal();
1110 while(vtkActor *anAct = aCollection->GetNextActor()){
1111 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
1112 if(anActor->GetVisibility()){
1113 anActor->SetPickable(anIsAllPickable);
1118 theActor->SetPickable(!anIsAllPickable);
1119 RepaintCurrentView();
1124 //----------------------------------------------------------------------------
1125 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
1126 const Handle(SALOME_InteractiveObject)& theIO,
1130 TColStd_IndexedMapOfInteger aMapIndex;
1131 theSelector->GetIndex(theIO,aMapIndex);
1133 for(int i = 1; i <= aMapIndex.Extent(); i++)
1134 theName += QString(" %1").arg(aMapIndex(i));
1136 return aMapIndex.Extent();
1139 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
1140 const Handle(SALOME_InteractiveObject)& theIO,
1144 TColStd_IndexedMapOfInteger aMapIndex;
1145 theSelector->GetIndex(theIO,aMapIndex);
1147 typedef std::set<int> TIdContainer;
1148 TIdContainer anIdContainer;
1149 for( int i = 1; i <= aMapIndex.Extent(); i++)
1150 anIdContainer.insert(aMapIndex(i));
1152 TIdContainer::const_iterator anIter = anIdContainer.begin();
1153 for( ; anIter != anIdContainer.end(); anIter++)
1154 theName += QString(" %1").arg(*anIter);
1156 return aMapIndex.Extent();
1160 int GetEdgeNodes(SVTK_Selector* theSelector,
1161 const TVisualObjPtr& theVisualObject,
1165 const SALOME_ListIO& selected = theSelector->StoredIObjects();
1167 if ( selected.Extent() != 1 )
1170 Handle(SALOME_InteractiveObject) anIO = selected.First();
1171 if ( anIO.IsNull() || !anIO->hasEntry() )
1174 TColStd_IndexedMapOfInteger aMapIndex;
1175 theSelector->GetIndex( anIO, aMapIndex );
1176 if ( aMapIndex.Extent() != 2 )
1179 int anObjId = -1, anEdgeNum = -1;
1180 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1181 int aVal = aMapIndex( i );
1185 anEdgeNum = abs( aVal ) - 1;
1188 if ( anObjId == -1 || anEdgeNum == -1 )
1191 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1194 //----------------------------------------------------------------------------
1195 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1196 const Handle(SALOME_InteractiveObject)& theIO,
1200 if(theIO->hasEntry()){
1201 if(FindActorByEntry(theIO->getEntry())){
1202 TColStd_IndexedMapOfInteger aMapIndex;
1203 theMgr->GetIndexes(theIO,aMapIndex);
1204 for(int i = 1; i <= aMapIndex.Extent(); i++){
1205 theName += QString(" %1").arg(aMapIndex(i));
1207 return aMapIndex.Extent();
1213 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName)
1216 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1217 if(selected.Extent() == 1){
1218 Handle(SALOME_InteractiveObject) anIO = selected.First();
1219 return GetNameOfSelectedNodes(theMgr,anIO,theName);
1225 int GetNameOfSelectedElements(LightApp_SelectionMgr * theMgr,
1226 const Handle(SALOME_InteractiveObject)& theIO,
1230 if(theIO->hasEntry()){
1231 if(FindActorByEntry(theIO->getEntry())){
1232 TColStd_IndexedMapOfInteger aMapIndex;
1233 theMgr->GetIndexes(theIO,aMapIndex);
1234 typedef std::set<int> TIdContainer;
1235 TIdContainer anIdContainer;
1236 for( int i = 1; i <= aMapIndex.Extent(); i++)
1237 anIdContainer.insert(aMapIndex(i));
1238 TIdContainer::const_iterator anIter = anIdContainer.begin();
1239 for( ; anIter != anIdContainer.end(); anIter++){
1240 theName += QString(" %1").arg(*anIter);
1242 return aMapIndex.Extent();
1249 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1252 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1254 if( selected.Extent() == 1){
1255 Handle(SALOME_InteractiveObject) anIO = selected.First();
1256 return GetNameOfSelectedElements(theMgr,anIO,theName);
1261 int GetSelected(LightApp_SelectionMgr* theMgr,
1262 TColStd_IndexedMapOfInteger& theMap,
1263 const bool theIsElement)
1266 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1268 if ( selected.Extent() == 1 )
1270 Handle(SALOME_InteractiveObject) anIO = selected.First();
1271 if ( anIO->hasEntry() ) {
1272 theMgr->GetIndexes( anIO, theMap );
1275 return theMap.Extent();
1279 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
1281 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1283 if ( selected.Extent() != 1 )
1286 Handle(SALOME_InteractiveObject) anIO = selected.First();
1287 if ( anIO.IsNull() || !anIO->hasEntry() )
1290 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1294 TColStd_IndexedMapOfInteger aMapIndex;
1295 theMgr->GetIndexes( anIO, aMapIndex );
1296 if ( aMapIndex.Extent() != 2 )
1299 int anObjId = -1, anEdgeNum = -1;
1300 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1301 int aVal = aMapIndex( i );
1305 anEdgeNum = abs( aVal );
1308 if ( anObjId == -1 || anEdgeNum == -1 )
1311 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1314 void SetControlsPrecision( const long theVal )
1316 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1318 vtkRenderer *aRenderer = aWnd->getRenderer();
1319 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1320 vtkActorCollection *aCollection = aCopy.GetActors();
1321 aCollection->InitTraversal();
1323 while ( vtkActor *anAct = aCollection->GetNextActor())
1325 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1327 anActor->SetControlsPrecision( theVal );
1328 anActor->SetControlMode( anActor->GetControlMode() );
1335 //----------------------------------------------------------------------------
1336 // internal function
1337 void ComputeBoundsParam( double theBounds[6],
1338 double theDirection[3],
1339 double theMinPnt[3],
1340 double& theMaxBoundPrj,
1341 double& theMinBoundPrj )
1343 //Enlarge bounds in order to avoid conflicts of precision
1344 for(int i = 0; i < 6; i += 2){
1345 static double EPS = 1.0E-3;
1346 double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
1347 theBounds[i] -= aDelta;
1348 theBounds[i+1] += aDelta;
1351 double aBoundPoints[8][3] = { {theBounds[0],theBounds[2],theBounds[4]},
1352 {theBounds[1],theBounds[2],theBounds[4]},
1353 {theBounds[0],theBounds[3],theBounds[4]},
1354 {theBounds[1],theBounds[3],theBounds[4]},
1355 {theBounds[0],theBounds[2],theBounds[5]},
1356 {theBounds[1],theBounds[2],theBounds[5]},
1357 {theBounds[0],theBounds[3],theBounds[5]},
1358 {theBounds[1],theBounds[3],theBounds[5]}};
1361 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1362 theMinBoundPrj = theMaxBoundPrj;
1363 for(int i = 1; i < 8; i++){
1364 double aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1365 if(theMaxBoundPrj < aTmp){
1366 theMaxBoundPrj = aTmp;
1369 if(theMinBoundPrj > aTmp){
1370 theMinBoundPrj = aTmp;
1373 double *aMinPnt = aBoundPoints[aMaxId];
1374 theMinPnt[0] = aMinPnt[0];
1375 theMinPnt[1] = aMinPnt[1];
1376 theMinPnt[2] = aMinPnt[2];
1379 // internal function
1380 void DistanceToPosition( double theBounds[6],
1381 double theDirection[3],
1385 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1386 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1387 double aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1388 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1389 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1390 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1393 // internal function (currently unused, left just in case)
1394 void PositionToDistance( double theBounds[6],
1395 double theDirection[3],
1399 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1400 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1401 double aPrj = vtkMath::Dot(theDirection,thePos);
1402 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1405 bool ComputeClippingPlaneParameters( std::list<vtkActor*> theActorList,
1406 double theNormal[3],
1408 double theBounds[6],
1409 double theOrigin[3] )
1411 bool anIsOk = false;
1412 anIsOk = ComputeBounds( theActorList, theBounds );
1418 DistanceToPosition( theBounds, theNormal, theDist, theOrigin );
1422 bool ComputeBounds( std::list<vtkActor*> theActorList,
1423 double theBounds[6])
1425 bool anIsOk = false;
1426 theBounds[0] = theBounds[2] = theBounds[4] = VTK_DOUBLE_MAX;
1427 theBounds[1] = theBounds[3] = theBounds[5] = -VTK_DOUBLE_MAX;
1428 std::list<vtkActor*>::iterator anIter = theActorList.begin();
1429 for( ; anIter != theActorList.end(); anIter++ ) {
1430 if( vtkActor* aVTKActor = *anIter ) {
1431 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1433 anActor->GetUnstructuredGrid()->GetBounds( aBounds );
1434 theBounds[0] = std::min( theBounds[0], aBounds[0] );
1435 theBounds[1] = std::max( theBounds[1], aBounds[1] );
1436 theBounds[2] = std::min( theBounds[2], aBounds[2] );
1437 theBounds[3] = std::max( theBounds[3], aBounds[3] );
1438 theBounds[4] = std::min( theBounds[4], aBounds[4] );
1439 theBounds[5] = std::max( theBounds[5], aBounds[5] );
1447 #ifndef DISABLE_PLOT2DVIEWER
1448 //================================================================================
1450 * \brief Find all SMESH_Actor's in the View Window.
1451 * If actor constains Plot2d_Histogram object remove it from each Plot2d Viewer.
1453 //================================================================================
1455 void ClearPlot2Viewers( SUIT_ViewWindow* theWindow )
1457 if ( SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow) ) {
1458 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1459 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1460 vtkActorCollection *aCollection = aCopy.GetActors();
1461 aCollection->InitTraversal();
1462 while(vtkActor *anAct = aCollection->GetNextActor()){
1463 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1464 if(anActor->hasIO() && anActor->GetPlot2Histogram() ){
1465 ProcessIn2DViewers(anActor,RemoveFrom2dViewer);
1474 } // end of namespace SMESH