1 // Copyright (C) 2007-2013 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.
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_Utils.h"
32 #include "SMESHGUI_Filter.h"
33 #include "SMESH_ControlsDef.hxx"
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37 #include "SMESH_NodeLabelActor.h"
38 #include "SMESH_CellLabelActor.h"
39 #include <SMESH_ObjectDef.h>
40 #include <SMDS_Mesh.hxx>
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>
50 #include <SALOME_ListIteratorOfListIO.hxx>
52 #include <SVTK_Selector.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
56 #include <VTKViewer_Algorithm.h>
58 #include <LightApp_SelectionMgr.h>
59 #include <SalomeApp_Application.h>
60 #include <SalomeApp_Study.h>
62 // SALOME KERNEL includes
63 #include <utilities.h>
66 #include <SALOMEconfig.h>
67 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
68 #include CORBA_CLIENT_HEADER(SMESH_Group)
72 #include <vtkRenderer.h>
73 #include <vtkActorCollection.h>
74 #include <vtkUnstructuredGrid.h>
77 #include <TColStd_IndexedMapOfInteger.hxx>
78 #include <Standard_ErrorHandler.hxx>
82 typedef std::map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
83 static TVisualObjCont VISUAL_OBJ_CONT;
85 //=============================================================================
87 * \brief Allocate some memory at construction and release it at destruction.
88 * Is used to be able to continue working after mesh generation or visualization
89 * break due to lack of memory
91 //=============================================================================
96 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
97 void Free() { if (myBuf) { delete [] myBuf; myBuf = 0; }}
98 ~MemoryReserve() { Free(); }
100 static MemoryReserve* theVISU_MemoryReserve = new MemoryReserve;
102 //================================================================================
104 * \brief Remove VisualObj and its actor from all views
106 //================================================================================
108 void RemoveVisualObjectWithActors( const char* theEntry, bool fromAllViews )
110 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
113 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
116 ViewManagerList aList;
119 app->viewManagers(SVTK_Viewer::Type() , aList);
121 SUIT_ViewManager* aVM = app->getViewManager(SVTK_Viewer::Type(), true);
125 bool actorRemoved = false;
126 ViewManagerList::ConstIterator it = aList.begin();
127 SUIT_ViewManager* aViewManager = 0;
128 for( ; it!=aList.end();it++) {
130 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
131 for ( int iV = 0; iV < views.count(); ++iV ) {
132 if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
133 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
134 vtkWnd->RemoveActor(actor);
143 int aStudyId = aViewManager->study()->id();
144 TVisualObjCont::key_type aKey(aStudyId,theEntry);
145 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
146 if(anIter != VISUAL_OBJ_CONT.end()) {
147 // for unknown reason, object destructor is not called, so clear object manually
148 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
149 anIter->second->GetUnstructuredGrid()->SetPoints(0);
151 VISUAL_OBJ_CONT.erase(aKey);
155 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
157 //================================================================================
159 * \brief Remove all VisualObjs and their actors from all views
161 //================================================================================
163 void RemoveAllObjectsWithActors()
165 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
166 ( SUIT_Session::session()->activeApplication() );
168 ViewManagerList viewMgrs = app->viewManagers();
169 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
170 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
171 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type()) {
172 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
173 for ( int iV = 0; iV < views.count(); ++iV ) {
174 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
175 vtkRenderer *aRenderer = vtkWnd->getRenderer();
176 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
177 vtkActorCollection *actors = aCopy.GetActors();
178 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
179 // size of actors changes inside the loop
180 if (SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
182 vtkWnd->RemoveActor(actor);
190 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
191 for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
192 // for unknown reason, object destructor is not called, so clear object manually
193 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
194 anIter->second->GetUnstructuredGrid()->SetPoints(0);
196 VISUAL_OBJ_CONT.clear();
199 //================================================================================
201 * \brief Remove all VisualObjs of a study
203 //================================================================================
205 void RemoveVisuData(int studyID)
207 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
208 ( SUIT_Session::session()->activeApplication() );
210 ViewManagerList viewMgrs = app->viewManagers();
211 for ( int iM = 0; iM < viewMgrs.count(); ++iM ) {
212 SUIT_ViewManager* aViewManager = viewMgrs.at( iM );
213 if ( aViewManager && aViewManager->getType() == SVTK_Viewer::Type() &&
214 aViewManager->study()->id() == studyID ) {
215 QVector<SUIT_ViewWindow*> views = aViewManager->getViews();
216 for ( int iV = 0; iV < views.count(); ++iV ) {
217 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
218 vtkRenderer *aRenderer = vtkWnd->getRenderer();
219 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
220 vtkActorCollection *actors = aCopy.GetActors();
221 for (int i = 0; i < actors->GetNumberOfItems(); ++i ) {
222 // size of actors changes inside the loop
223 if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(actors->GetItemAsObject(i)))
225 vtkWnd->RemoveActor(actor);
233 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
234 for ( ; anIter != VISUAL_OBJ_CONT.end(); ) {
235 int curId = anIter->first.first;
236 if ( curId == studyID ) {
237 // for unknown reason, object destructor is not called, so clear object manually
238 anIter->second->GetUnstructuredGrid()->SetCells(0,0,0,0,0);
239 anIter->second->GetUnstructuredGrid()->SetPoints(0);
240 VISUAL_OBJ_CONT.erase( anIter++ ); // anIter++ returns a copy of self before incrementing
248 //================================================================================
250 * \brief Notify the user on problems during visualization
252 //================================================================================
254 void OnVisuException()
257 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
260 // PAL16774 (Crash after display of many groups). Salome sometimes crashes just
261 // after or at showing this message, so we do an additional check of available memory
262 // char* buf = new char[100*1024];
264 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
265 QObject::tr("SMESH_VISU_PROBLEM"));
267 // no more memory at all: last resort
268 MESSAGE_BEGIN ( "SMESHGUI_VTKUtils::OnVisuException(), exception even at showing a message!!!" <<
269 std::endl << "Try to remove all visual data..." );
270 if (theVISU_MemoryReserve) {
271 delete theVISU_MemoryReserve;
272 theVISU_MemoryReserve = 0;
274 RemoveAllObjectsWithActors();
275 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
276 QObject::tr("SMESH_VISU_PROBLEM_CLEAR"));
277 MESSAGE_END ( "...done" );
280 //================================================================================
282 * \brief Returns an updated visual object
284 //================================================================================
286 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry, bool nulData){
287 TVisualObjPtr aVisualObj;
288 TVisualObjCont::key_type aKey(theStudyId,theEntry);
290 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
293 TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
294 if(anIter != VISUAL_OBJ_CONT.end()){
295 aVisualObj = anIter->second;
297 SalomeApp_Application* app =
298 dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
299 _PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
300 _PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
302 _PTR(GenericAttribute) anAttr;
303 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
304 _PTR(AttributeIOR) anIOR = anAttr;
305 CORBA::String_var aVal = anIOR->Value().c_str();
306 CORBA::Object_var anObj = app->orb()->string_to_object( aVal.in() );
307 if(!CORBA::is_nil(anObj)){
308 //Try narrow to SMESH_Mesh interface
309 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
310 if(!aMesh->_is_nil()){
311 aVisualObj.reset(new SMESH_MeshObj(aMesh));
312 TVisualObjCont::value_type aValue(aKey,aVisualObj);
313 VISUAL_OBJ_CONT.insert(aValue);
315 //Try narrow to SMESH_Group interface
316 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
317 if(!aGroup->_is_nil()){
318 _PTR(SObject) aFatherSObj = aSObj->GetFather();
319 if(!aFatherSObj) return aVisualObj;
320 aFatherSObj = aFatherSObj->GetFather();
321 if(!aFatherSObj) return aVisualObj;
322 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
323 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
324 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
325 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
326 TVisualObjCont::value_type aValue(aKey,aVisualObj);
327 VISUAL_OBJ_CONT.insert(aValue);
330 //Try narrow to SMESH_subMesh interface
331 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
332 if(!aSubMesh->_is_nil()){
333 _PTR(SObject) aFatherSObj = aSObj->GetFather();
334 if(!aFatherSObj) return aVisualObj;
335 aFatherSObj = aFatherSObj->GetFather();
336 if(!aFatherSObj) return aVisualObj;
337 CORBA::String_var anEntry = aFatherSObj->GetID().c_str();
338 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
339 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
340 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
341 TVisualObjCont::value_type aValue(aKey,aVisualObj);
342 VISUAL_OBJ_CONT.insert(aValue);
350 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
351 return TVisualObjPtr();
354 bool objModified = false;
357 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
360 //MESSAGE("GetVisualObj");
362 objModified = aVisualObj->NulData();
364 objModified = aVisualObj->Update();
368 MESSAGE ( "Exception in SMESHGUI_VTKUtils::GetVisualObj()" );
370 RemoveVisualObjectWithActors( theEntry ); // remove this object
377 // PAL16631. Mesurements showed that to show aVisualObj in SHADING(default) mode,
378 // ~5 times more memory is used than it occupies.
379 // Warn the user if there is less free memory than 30 sizes of a grid
380 // TODO: estimate memory usage in other modes and take current mode into account
381 int freeMB = SMDS_Mesh::CheckMemory(true);
382 int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
383 MESSAGE("SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB << ", usedMB=" <<usedMB);
384 if ( freeMB > 0 && usedMB * 5 > freeMB ) {
385 bool continu = false;
386 if ( usedMB * 3 > freeMB )
387 // even dont try to show
388 SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
389 QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
391 // there is a chance to succeed
392 continu = SUIT_MessageBox::warning
393 (SMESHGUI::desktop(),
394 QObject::tr("SMESH_WRN_WARNING"),
395 QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
396 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
397 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
399 // remove the corresponding actors from all views
400 RemoveVisualObjectWithActors( theEntry );
410 /*! Return active view window, if it instantiates SVTK_ViewWindow class,
411 * overwise find or create corresponding view window, make it active and return it.
412 * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
414 SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
415 bool createIfNotFound)
417 SalomeApp_Application* anApp;
419 anApp = theModule->getApp();
421 anApp = dynamic_cast<SalomeApp_Application*>
422 (SUIT_Session::session()->activeApplication());
425 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
428 SUIT_ViewManager* aViewManager =
429 anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
431 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
432 if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
433 aViewWindow->raise();
434 aViewWindow->setFocus();
443 SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
444 SUIT_ViewWindow * theWindow)
449 QVector<SUIT_ViewWindow*> views = theMgr->getViews();
450 if( views.contains( theWindow ) )
451 return GetVtkViewWindow( theWindow );
456 SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
457 return dynamic_cast<SVTK_ViewWindow*>(theWindow);
460 /* SUIT_ViewWindow* GetActiveWindow()
462 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
465 SUIT_ViewManager* mgr = app->activeViewManager();
467 return mgr->getActiveView();
472 SVTK_ViewWindow* GetCurrentVtkView(){
473 return GetVtkViewWindow( GetActiveWindow() );
477 void RepaintCurrentView()
479 if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
482 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
485 wnd->getRenderer()->Render();
490 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" );
497 void RepaintViewWindow(SVTK_ViewWindow* theWindow)
500 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
503 theWindow->getRenderer()->Render();
504 theWindow->Repaint();
508 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow*)" );
514 void RenderViewWindow(SVTK_ViewWindow* theWindow)
517 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
520 theWindow->getRenderer()->Render();
521 theWindow->Repaint();
525 MESSAGE ( "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow*)" );
532 if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
534 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
542 MESSAGE ( "Exception in SMESHGUI_VTKUtils::FitAll()" );
550 SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
551 const char* theEntry)
553 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
554 vtkRenderer *aRenderer = aViewWindow->getRenderer();
555 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
556 vtkActorCollection *aCollection = aCopy.GetActors();
557 aCollection->InitTraversal();
558 while(vtkActor *anAct = aCollection->GetNextActor()){
559 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
560 if(anActor->hasIO()){
561 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
562 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
573 SMESH_Actor* FindActorByEntry(const char* theEntry){
574 return FindActorByEntry(GetActiveWindow(),theEntry);
578 SMESH_Actor* FindActorByObject(CORBA::Object_ptr theObject){
579 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
583 if(!CORBA::is_nil(theObject)){
584 _PTR(Study) aStudy = GetActiveStudyDocument();
585 CORBA::String_var anIOR = app->orb()->object_to_string( theObject );
586 _PTR(SObject) aSObject = aStudy->FindObjectIOR(anIOR.in());
588 CORBA::String_var anEntry = aSObject->GetID().c_str();
589 return FindActorByEntry(anEntry.in());
596 SMESH_Actor* CreateActor(_PTR(Study) theStudy,
597 const char* theEntry,
600 SMESH_Actor *anActor = NULL;
601 CORBA::Long anId = theStudy->StudyId();
602 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
603 _PTR(SObject) aSObj = theStudy->FindObjectID(theEntry);
605 _PTR(GenericAttribute) anAttr;
606 if(aSObj->FindAttribute(anAttr,"AttributeName")){
607 _PTR(AttributeName) aName = anAttr;
608 std::string aNameVal = aName->Value();
609 anActor = SMESH_Actor::New(aVisualObj,theEntry,aNameVal.c_str(),theIsClear);
612 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( aSObj ));
613 if(!CORBA::is_nil(aGroup) && anActor)
617 SMESH::GetColor( "SMESH", "fill_color", c, deltaF, "0,170,255|-100" );
618 SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
619 c = SMESH::GetColor( "SMESH", "default_grp_color", c );
620 SALOMEDS::Color aColor = aGroup->GetColor();
621 if( !( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 ))
624 aColor.G = c.greenF();
625 aColor.B = c.blueF();
626 aGroup->SetColor( aColor );
628 if( aGroup->GetType() == SMESH::NODE )
629 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
630 else if( aGroup->GetType() == SMESH::EDGE )
631 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
632 else if( aGroup->GetType() == SMESH::ELEM0D )
633 anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
634 else if( aGroup->GetType() == SMESH::BALL )
635 anActor->SetBallColor( aColor.R, aColor.G, aColor.B );
636 else if( aGroup->GetType() == SMESH::VOLUME )
637 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, deltaV );
639 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, deltaF );
643 MESSAGE("CreateActor " << anActor);
645 if( SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI() )
646 aSMESHGUI->addActorAsObserver( anActor );
651 void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
652 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
654 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
657 MESSAGE("DisplayActor " << theActor);
658 vtkWnd->AddActor(theActor);
663 MESSAGE ( "Exception in SMESHGUI_VTKUtils::DisplayActor()" );
671 void RemoveActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
672 if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
673 MESSAGE("RemoveActor " << theActor);
674 vtkWnd->RemoveActor(theActor);
675 if(theActor->hasIO()){
676 Handle(SALOME_InteractiveObject) anIO = theActor->getIO();
677 if(anIO->hasEntry()){
678 std::string anEntry = anIO->getEntry();
679 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
680 int aStudyId = aStudy->id();
681 TVisualObjCont::key_type aKey(aStudyId,anEntry);
682 VISUAL_OBJ_CONT.erase(aKey);
690 //================================================================================
692 * \brief Return true if there are no SMESH actors in a view
694 //================================================================================
696 bool noSmeshActors(SUIT_ViewWindow *theWnd)
698 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWnd)) {
699 vtkRenderer *aRenderer = aViewWindow->getRenderer();
700 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
701 vtkActorCollection *aCollection = aCopy.GetActors();
702 aCollection->InitTraversal();
703 while(vtkActor *anAct = aCollection->GetNextActor())
704 if(dynamic_cast<SMESH_Actor*>(anAct))
710 bool UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
712 //MESSAGE("UpdateView");
714 SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd);
718 SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd);
722 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( vtkWnd->getViewManager()->study() );
729 vtkRenderer *aRenderer = aViewWnd->getRenderer();
730 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
731 vtkActorCollection *aCollection = aCopy.GetActors();
732 aCollection->InitTraversal();
736 while (vtkActor *anAct = aCollection->GetNextActor()) {
737 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
738 MESSAGE("--- display " << anActor);
739 anActor->SetVisibility(true);
741 if(anActor->hasIO()){
742 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
743 if(anIO->hasEntry()){
744 aStudy->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
753 //MESSAGE("---case eDisplayOnly");
754 while (vtkActor *anAct = aCollection->GetNextActor()) {
755 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
756 //MESSAGE("--- erase " << anActor);
757 anActor->SetVisibility(false);
760 aStudy->setVisibilityStateForAll(Qtx::HiddenState);
763 if (SMESH_Actor *anActor = FindActorByEntry(theWnd,theEntry)) {
767 //MESSAGE("--- display " << anActor);
769 anActor->SetVisibility(true);
770 if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
771 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
774 //MESSAGE("--- erase " << anActor);
775 anActor->SetVisibility(false);
776 aStudy->setVisibilityState(theEntry, Qtx::HiddenState);
785 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(theWnd->getViewManager()->study());
786 _PTR(Study) aDocument = aStudy->studyDS();
787 // Pass non-visual objects (hypotheses, etc.), return true in this case
788 CORBA::Long anId = aDocument->StudyId();
789 TVisualObjPtr aVisualObj;
790 if ( (aVisualObj = GetVisualObj(anId,theEntry)) && aVisualObj->IsValid())
792 if ((anActor = CreateActor(aDocument,theEntry,true))) {
793 bool needFitAll = noSmeshActors(theWnd); // fit for the first object only
794 DisplayActor(theWnd,anActor);
795 aStudy->setVisibilityState(theEntry, Qtx::ShownState);
796 // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
797 if (needFitAll) FitAll();
813 bool UpdateView(EDisplaing theAction, const char* theEntry){
814 //MESSAGE("UpdateView");
815 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( GetActiveStudy() );
816 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( aStudy->application() );
817 SUIT_ViewWindow *aWnd = app->activeViewManager()->getActiveView();
818 return UpdateView(aWnd,theAction,theEntry);
822 if(SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView()){
823 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
824 SALOME_ListIO selected; mgr->selectedObjects( selected );
826 if( selected.Extent() == 0){
827 vtkRenderer* aRenderer = aWnd->getRenderer();
828 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
829 vtkActorCollection *aCollection = aCopy.GetActors();
830 aCollection->InitTraversal();
831 while(vtkActor *anAct = aCollection->GetNextActor()){
832 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
834 if (!Update(anActor->getIO(),anActor->GetVisibility()))
835 break; // avoid multiple warinings if visu failed
839 SALOME_ListIteratorOfListIO anIter( selected );
840 for( ; anIter.More(); anIter.Next()){
841 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
842 if ( !Update(anIO,true) )
843 break; // avoid multiple warinings if visu failed
846 RepaintCurrentView();
851 bool Update(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
854 _PTR(Study) aStudy = GetActiveStudyDocument();
855 CORBA::Long anId = aStudy->StudyId();
856 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
858 UpdateView(SMESH::eDisplay,theIO->getEntry());
864 bool UpdateNulData(const Handle(SALOME_InteractiveObject)& theIO, bool theDisplay)
866 MESSAGE("UpdateNulData");
867 _PTR(Study) aStudy = GetActiveStudyDocument();
868 CORBA::Long anId = aStudy->StudyId();
869 if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry(), true)) {
871 UpdateView(SMESH::eDisplay,theIO->getEntry());
877 void UpdateSelectionProp( SMESHGUI* theModule ) {
881 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
884 MESSAGE( "UpdateSelectionProp: Application is null" );
888 SUIT_ViewManager* vm = app->activeViewManager();
891 MESSAGE( "UpdateSelectionProp: View manager is null" );
895 QVector<SUIT_ViewWindow*> views = vm->getViews();
897 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
900 MESSAGE( "UpdateSelectionProp: Resource manager is null" );
904 QColor aHiColor = mgr->colorValue( "SMESH", "selection_object_color", Qt::white ),
905 aSelColor = mgr->colorValue( "SMESH", "selection_element_color", Qt::yellow ),
906 aPreColor = mgr->colorValue( "SMESH", "highlight_color", Qt::cyan );
908 int aElem0DSize = mgr->integerValue("SMESH", "elem0d_size", 5);
909 int aBallSize = mgr->integerValue("SMESH", "ball_elem_size", 5);
910 int aLineWidth = mgr->integerValue("SMESH", "element_width", 1);
911 int maxSize = aElem0DSize;
912 if (aElem0DSize > maxSize) maxSize = aElem0DSize;
913 if (aLineWidth > maxSize) maxSize = aLineWidth;
914 if (aBallSize > maxSize) maxSize = aBallSize;
916 double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ),
917 SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ),
918 SP3 = mgr->doubleValue( "SMESH", "selection_precision_object", 0.025 );
920 for ( int i=0, n=views.count(); i<n; i++ ){
921 // update VTK viewer properties
922 if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
923 // mesh element selection
924 aVtkView->SetSelectionProp(aSelColor.red()/255.,
925 aSelColor.green()/255.,
926 aSelColor.blue()/255.);
928 aVtkView->SetSelectionTolerance(SP1, SP2, SP3);
931 aVtkView->SetPreselectionProp(aPreColor.red()/255.,
932 aPreColor.green()/255.,
933 aPreColor.blue()/255.);
935 vtkRenderer* aRenderer = aVtkView->getRenderer();
936 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
937 vtkActorCollection *aCollection = aCopy.GetActors();
938 aCollection->InitTraversal();
939 while(vtkActor *anAct = aCollection->GetNextActor()){
940 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
941 anActor->SetHighlightColor(aHiColor.red()/255.,
942 aHiColor.green()/255.,
943 aHiColor.blue()/255.);
944 anActor->SetPreHighlightColor(aPreColor.red()/255.,
945 aPreColor.green()/255.,
946 aPreColor.blue()/255.);
954 void UpdateFontProp( SMESHGUI* theModule )
956 if ( !theModule ) return;
958 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( theModule->application() );
961 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( theModule );
964 double anRGBNd[3] = {1,1,1};
965 SMESH::GetColor( "SMESH", "numbering_node_color", anRGBNd[0], anRGBNd[1], anRGBNd[2], QColor( 255, 255, 255 ) );
967 SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
969 bool anItalicNd = false;
970 bool aShadowNd = false;
972 if ( mgr->hasValue( "SMESH", "numbering_node_font" ) ) {
973 QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
974 if ( f.family() == "Arial" ) aFamilyNd = SMESH::FntArial;
975 else if ( f.family() == "Courier" ) aFamilyNd = SMESH::FntCourier;
976 else if ( f.family() == "Times" ) aFamilyNd = SMESH::FntTimes;
978 anItalicNd = f.italic();
979 aShadowNd = f.overline();
980 aSizeNd = f.pointSize();
983 double anRGBEl[3] = {0,1,0};
984 SMESH::GetColor( "SMESH", "numbering_elem_color", anRGBEl[0], anRGBEl[1], anRGBEl[2], QColor( 0, 255, 0 ) );
986 SMESH::LabelFont aFamilyEl = SMESH::FntTimes;
988 bool anItalicEl = false;
989 bool aShadowEl = false;
991 if ( mgr->hasValue( "SMESH", "numbering_elem_font" ) ) {
992 QFont f = mgr->fontValue( "SMESH", "numbering_elem_font" );
994 if ( f.family() == "Arial" ) aFamilyEl = SMESH::FntArial;
995 else if ( f.family() == "Courier" ) aFamilyEl = SMESH::FntCourier;
996 else if ( f.family() == "Times" ) aFamilyEl = SMESH::FntTimes;
998 anItalicEl = f.italic();
999 aShadowEl = f.overline();
1000 aSizeEl = f.pointSize();
1003 ViewManagerList vmList;
1004 app->viewManagers( SVTK_Viewer::Type(), vmList );
1005 foreach ( SUIT_ViewManager* vm, vmList ) {
1006 QVector<SUIT_ViewWindow*> views = vm->getViews();
1007 foreach ( SUIT_ViewWindow* vw, views ) {
1008 // update VTK viewer properties
1009 if ( SVTK_ViewWindow* aVtkView = GetVtkViewWindow( vw ) ) {
1011 vtkRenderer* aRenderer = aVtkView->getRenderer();
1012 VTK::ActorCollectionCopy aCopy( aRenderer->GetActors() );
1013 vtkActorCollection* aCollection = aCopy.GetActors();
1014 aCollection->InitTraversal();
1015 while ( vtkActor* anAct = aCollection->GetNextActor() ) {
1016 if ( SMESH_NodeLabelActor* anActor = dynamic_cast< SMESH_NodeLabelActor* >( anAct ) ) {
1017 anActor->SetFontProperties( aFamilyNd, aSizeNd, aBoldNd, anItalicNd, aShadowNd, anRGBNd[0], anRGBNd[1], anRGBNd[2] );
1019 else if ( SMESH_CellLabelActor* anActor = dynamic_cast< SMESH_CellLabelActor* >( anAct ) ) {
1020 anActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
1023 aVtkView->Repaint( false );
1029 //----------------------------------------------------------------------------
1031 GetSelector(SUIT_ViewWindow *theWindow)
1033 if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))
1034 return aWnd->GetSelector();
1039 void SetFilter(const Handle(VTKViewer_Filter)& theFilter,
1040 SVTK_Selector* theSelector)
1043 theSelector->SetFilter(theFilter);
1046 Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector)
1048 return theSelector->GetFilter(theId);
1051 bool IsFilterPresent(int theId, SVTK_Selector* theSelector)
1053 return theSelector->IsFilterPresent(theId);
1056 void RemoveFilter(int theId, SVTK_Selector* theSelector)
1058 theSelector->RemoveFilter(theId);
1061 void RemoveFilters(SVTK_Selector* theSelector)
1063 for ( int id = SMESH::NodeFilter; theSelector && id < SMESH::LastFilter; id++ )
1064 theSelector->RemoveFilter( id );
1067 bool IsValid(SALOME_Actor* theActor, int theCellId,
1068 SVTK_Selector* theSelector)
1070 return theSelector->IsValid(theActor,theCellId);
1074 //----------------------------------------------------------------------------
1075 void SetPointRepresentation(bool theIsVisible){
1076 if(SVTK_ViewWindow* aViewWindow = GetCurrentVtkView()){
1077 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1078 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1079 vtkActorCollection *aCollection = aCopy.GetActors();
1080 aCollection->InitTraversal();
1081 while(vtkActor *anAct = aCollection->GetNextActor()){
1082 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1083 if(anActor->GetVisibility()){
1084 anActor->SetPointRepresentation(theIsVisible);
1088 RepaintCurrentView();
1093 void SetPickable(SMESH_Actor* theActor){
1094 if(SVTK_ViewWindow* aWnd = GetCurrentVtkView()){
1095 int anIsAllPickable = (theActor == NULL);
1096 vtkRenderer *aRenderer = aWnd->getRenderer();
1097 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1098 vtkActorCollection *aCollection = aCopy.GetActors();
1099 aCollection->InitTraversal();
1100 while(vtkActor *anAct = aCollection->GetNextActor()){
1101 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
1102 if(anActor->GetVisibility()){
1103 anActor->SetPickable(anIsAllPickable);
1108 theActor->SetPickable(!anIsAllPickable);
1109 RepaintCurrentView();
1114 //----------------------------------------------------------------------------
1115 int GetNameOfSelectedNodes(SVTK_Selector* theSelector,
1116 const Handle(SALOME_InteractiveObject)& theIO,
1120 TColStd_IndexedMapOfInteger aMapIndex;
1121 theSelector->GetIndex(theIO,aMapIndex);
1123 for(int i = 1; i <= aMapIndex.Extent(); i++)
1124 theName += QString(" %1").arg(aMapIndex(i));
1126 return aMapIndex.Extent();
1129 int GetNameOfSelectedElements(SVTK_Selector* theSelector,
1130 const Handle(SALOME_InteractiveObject)& theIO,
1134 TColStd_IndexedMapOfInteger aMapIndex;
1135 theSelector->GetIndex(theIO,aMapIndex);
1137 typedef std::set<int> TIdContainer;
1138 TIdContainer anIdContainer;
1139 for( int i = 1; i <= aMapIndex.Extent(); i++)
1140 anIdContainer.insert(aMapIndex(i));
1142 TIdContainer::const_iterator anIter = anIdContainer.begin();
1143 for( ; anIter != anIdContainer.end(); anIter++)
1144 theName += QString(" %1").arg(*anIter);
1146 return aMapIndex.Extent();
1150 int GetEdgeNodes(SVTK_Selector* theSelector,
1151 const TVisualObjPtr& theVisualObject,
1155 const SALOME_ListIO& selected = theSelector->StoredIObjects();
1157 if ( selected.Extent() != 1 )
1160 Handle(SALOME_InteractiveObject) anIO = selected.First();
1161 if ( anIO.IsNull() || !anIO->hasEntry() )
1164 TColStd_IndexedMapOfInteger aMapIndex;
1165 theSelector->GetIndex( anIO, aMapIndex );
1166 if ( aMapIndex.Extent() != 2 )
1169 int anObjId = -1, anEdgeNum = -1;
1170 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1171 int aVal = aMapIndex( i );
1175 anEdgeNum = abs( aVal ) - 1;
1178 if ( anObjId == -1 || anEdgeNum == -1 )
1181 return theVisualObject->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1184 //----------------------------------------------------------------------------
1185 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr,
1186 const Handle(SALOME_InteractiveObject)& theIO,
1190 if(theIO->hasEntry()){
1191 if(FindActorByEntry(theIO->getEntry())){
1192 TColStd_IndexedMapOfInteger aMapIndex;
1193 theMgr->GetIndexes(theIO,aMapIndex);
1194 for(int i = 1; i <= aMapIndex.Extent(); i++){
1195 theName += QString(" %1").arg(aMapIndex(i));
1197 return aMapIndex.Extent();
1203 int GetNameOfSelectedNodes(LightApp_SelectionMgr *theMgr, QString& theName){
1205 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1206 if(selected.Extent() == 1){
1207 Handle(SALOME_InteractiveObject) anIO = selected.First();
1208 return GetNameOfSelectedNodes(theMgr,anIO,theName);
1214 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr,
1215 const Handle(SALOME_InteractiveObject)& theIO,
1219 if(theIO->hasEntry()){
1220 if(FindActorByEntry(theIO->getEntry())){
1221 TColStd_IndexedMapOfInteger aMapIndex;
1222 theMgr->GetIndexes(theIO,aMapIndex);
1223 typedef std::set<int> TIdContainer;
1224 TIdContainer anIdContainer;
1225 for( int i = 1; i <= aMapIndex.Extent(); i++)
1226 anIdContainer.insert(aMapIndex(i));
1227 TIdContainer::const_iterator anIter = anIdContainer.begin();
1228 for( ; anIter != anIdContainer.end(); anIter++){
1229 theName += QString(" %1").arg(*anIter);
1231 return aMapIndex.Extent();
1238 int GetNameOfSelectedElements(LightApp_SelectionMgr *theMgr, QString& theName)
1241 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1243 if( selected.Extent() == 1){
1244 Handle(SALOME_InteractiveObject) anIO = selected.First();
1245 return GetNameOfSelectedElements(theMgr,anIO,theName);
1250 int GetSelected(LightApp_SelectionMgr* theMgr,
1251 TColStd_IndexedMapOfInteger& theMap,
1252 const bool theIsElement)
1255 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1257 if ( selected.Extent() == 1 )
1259 Handle(SALOME_InteractiveObject) anIO = selected.First();
1260 if ( anIO->hasEntry() ) {
1261 theMgr->GetIndexes( anIO, theMap );
1264 return theMap.Extent();
1268 int GetEdgeNodes( LightApp_SelectionMgr* theMgr, int& theId1, int& theId2 )
1270 SALOME_ListIO selected; theMgr->selectedObjects( selected );
1272 if ( selected.Extent() != 1 )
1275 Handle(SALOME_InteractiveObject) anIO = selected.First();
1276 if ( anIO.IsNull() || !anIO->hasEntry() )
1279 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1283 TColStd_IndexedMapOfInteger aMapIndex;
1284 theMgr->GetIndexes( anIO, aMapIndex );
1285 if ( aMapIndex.Extent() != 2 )
1288 int anObjId = -1, anEdgeNum = -1;
1289 for ( int i = 1; i <= aMapIndex.Extent(); i++ ) {
1290 int aVal = aMapIndex( i );
1294 anEdgeNum = abs( aVal );
1297 if ( anObjId == -1 || anEdgeNum == -1 )
1300 return anActor->GetObject()->GetEdgeNodes( anObjId, anEdgeNum, theId1, theId2 ) ? 1 : -1;
1303 void SetControlsPrecision( const long theVal )
1305 if( SVTK_ViewWindow* aWnd = SMESH::GetCurrentVtkView() )
1307 vtkRenderer *aRenderer = aWnd->getRenderer();
1308 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1309 vtkActorCollection *aCollection = aCopy.GetActors();
1310 aCollection->InitTraversal();
1312 while ( vtkActor *anAct = aCollection->GetNextActor())
1314 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) )
1316 anActor->SetControlsPrecision( theVal );
1317 anActor->SetControlMode( anActor->GetControlMode() );
1324 //----------------------------------------------------------------------------
1325 // internal function
1326 void ComputeBoundsParam( double theBounds[6],
1327 double theDirection[3],
1328 double theMinPnt[3],
1329 double& theMaxBoundPrj,
1330 double& theMinBoundPrj )
1332 //Enlarge bounds in order to avoid conflicts of precision
1333 for(int i = 0; i < 6; i += 2){
1334 static double EPS = 1.0E-3;
1335 double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
1336 theBounds[i] -= aDelta;
1337 theBounds[i+1] += aDelta;
1340 double aBoundPoints[8][3] = { {theBounds[0],theBounds[2],theBounds[4]},
1341 {theBounds[1],theBounds[2],theBounds[4]},
1342 {theBounds[0],theBounds[3],theBounds[4]},
1343 {theBounds[1],theBounds[3],theBounds[4]},
1344 {theBounds[0],theBounds[2],theBounds[5]},
1345 {theBounds[1],theBounds[2],theBounds[5]},
1346 {theBounds[0],theBounds[3],theBounds[5]},
1347 {theBounds[1],theBounds[3],theBounds[5]}};
1350 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1351 theMinBoundPrj = theMaxBoundPrj;
1352 for(int i = 1; i < 8; i++){
1353 double aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1354 if(theMaxBoundPrj < aTmp){
1355 theMaxBoundPrj = aTmp;
1358 if(theMinBoundPrj > aTmp){
1359 theMinBoundPrj = aTmp;
1362 double *aMinPnt = aBoundPoints[aMaxId];
1363 theMinPnt[0] = aMinPnt[0];
1364 theMinPnt[1] = aMinPnt[1];
1365 theMinPnt[2] = aMinPnt[2];
1368 // internal function
1369 void DistanceToPosition( double theBounds[6],
1370 double theDirection[3],
1374 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1375 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1376 double aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1377 thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1378 thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1379 thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1382 // internal function (currently unused, left just in case)
1383 void PositionToDistance( double theBounds[6],
1384 double theDirection[3],
1388 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1389 ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1390 double aPrj = vtkMath::Dot(theDirection,thePos);
1391 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1394 bool ComputeClippingPlaneParameters( std::list<vtkActor*> theActorList,
1395 double theNormal[3],
1397 double theBounds[6],
1398 double theOrigin[3] )
1400 bool anIsOk = false;
1401 theBounds[0] = theBounds[2] = theBounds[4] = VTK_DOUBLE_MAX;
1402 theBounds[1] = theBounds[3] = theBounds[5] = -VTK_DOUBLE_MAX;
1403 std::list<vtkActor*>::iterator anIter = theActorList.begin();
1404 for( ; anIter != theActorList.end(); anIter++ ) {
1405 if( vtkActor* aVTKActor = *anIter ) {
1406 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1408 anActor->GetUnstructuredGrid()->GetBounds( aBounds );
1409 theBounds[0] = std::min( theBounds[0], aBounds[0] );
1410 theBounds[1] = std::max( theBounds[1], aBounds[1] );
1411 theBounds[2] = std::min( theBounds[2], aBounds[2] );
1412 theBounds[3] = std::max( theBounds[3], aBounds[3] );
1413 theBounds[4] = std::min( theBounds[4], aBounds[4] );
1414 theBounds[5] = std::max( theBounds[5], aBounds[5] );
1423 DistanceToPosition( theBounds, theNormal, theDist, theOrigin );
1427 #ifndef DISABLE_PLOT2DVIEWER
1428 //================================================================================
1430 * \brief Find all SMESH_Actor's in the View Window.
1431 * If actor constains Plot2d_Histogram object remove it from each Plot2d Viewer.
1433 //================================================================================
1435 void ClearPlot2Viewers( SUIT_ViewWindow* theWindow ) {
1436 if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
1437 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1438 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1439 vtkActorCollection *aCollection = aCopy.GetActors();
1440 aCollection->InitTraversal();
1441 while(vtkActor *anAct = aCollection->GetNextActor()){
1442 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1443 if(anActor->hasIO() && anActor->GetPlot2Histogram() ){
1444 ProcessIn2DViewers(anActor,RemoveFrom2dViewer);
1453 } // end of namespace SMESH