// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#include "SMESHGUI_VTKUtils.h"
#include "SMESHGUI_Utils.h"
#include "SMESHGUI_Filter.h"
-#include <vtkRenderer.h>
-#include <vtkActorCollection.h>
-
-#include <TColStd_IndexedMapOfInteger.hxx>
+#include "SMESHGUI.h"
+#include "SMESH_Actor.h"
+#include "SMESH_ObjectDef.h"
+#include <SMDS_Mesh.hxx>
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <SUIT_Study.h>
+#include <SUIT_MessageBox.h>
-#include "LightApp_SelectionMgr.h"
+#include <SALOME_ListIO.hxx>
+#include <SALOME_ListIteratorOfListIO.hxx>
+
+#include <SVTK_Selector.h>
+#include <SVTK_ViewModel.h>
+#include <SVTK_ViewWindow.h>
-#include "SVTK_Selector.h"
-#include "SVTK_ViewModel.h"
-#include "SVTK_ViewWindow.h"
+#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Study.h>
-#include "utilities.h"
+#include <utilities.h>
-#include "SALOMEconfig.h"
+#include <SALOMEconfig.h>
#include CORBA_CLIENT_HEADER(SMESH_Gen)
#include CORBA_CLIENT_HEADER(SMESH_Mesh)
#include CORBA_CLIENT_HEADER(SMESH_Group)
#include CORBA_CLIENT_HEADER(SMESH_Hypothesis)
-#include "SMESHGUI.h"
-#include "SMESH_Actor.h"
-#include "SMESH_ObjectDef.h"
-
-#include <SalomeApp_Application.h>
-#include <LightApp_SelectionMgr.h>
-#include <SalomeApp_Study.h>
-
#include <SALOMEDSClient_Study.hxx>
#include <SALOMEDSClient_SObject.hxx>
-#include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
+// VTK
+#include <vtkRenderer.h>
+#include <vtkActorCollection.h>
+#include <vtkUnstructuredGrid.h>
+// OCCT
+#include <TColStd_IndexedMapOfInteger.hxx>
+#include <Standard_ErrorHandler.hxx>
+
+// STL
#include <set>
using namespace std;
-namespace SMESH{
+
+namespace SMESH {
typedef map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
static TVisualObjCont VISUAL_OBJ_CONT;
+ //================================================================================
+ /*!
+ * \brief Remove VisualObj and its actor from all views
+ */
+ //================================================================================
+
+ void RemoveVisualObjectWithActors( const char* theEntry )
+ {
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
+ ( SUIT_Session::session()->activeApplication() );
+ SUIT_ViewManager* aViewManager =
+ app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
+ if ( aViewManager ) {
+ QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
+ for ( int iV = 0; iV < views.count(); ++iV ) {
+ if ( SMESH_Actor* actor = FindActorByEntry( views[iV], theEntry)) {
+ if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV]))
+ vtkWnd->RemoveActor(actor);
+ actor->Delete();
+ }
+ }
+ SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( aViewManager->study() );
+ int aStudyId = aStudy->id();
+ TVisualObjCont::key_type aKey(aStudyId,theEntry);
+ TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
+ if(anIter != VISUAL_OBJ_CONT.end()) {
+ // for unknown reason, object destructor is not called, so clear object manually
+ anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
+ anIter->second->GetUnstructuredGrid()->SetPoints(0);
+ }
+ VISUAL_OBJ_CONT.erase(aKey);
+ }
+ }
+ //================================================================================
+ /*!
+ * \brief Remove all VisualObjs and their actors from all views
+ */
+ //================================================================================
+
+ void RemoveAllObjectsWithActors()
+ {
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
+ ( SUIT_Session::session()->activeApplication() );
+ SUIT_ViewManager* aViewManager =
+ app ? app->getViewManager(SVTK_Viewer::Type(), true) : 0;
+ if ( aViewManager ) {
+ QPtrVector<SUIT_ViewWindow> views = aViewManager->getViews();
+ for ( int iV = 0; iV < views.count(); ++iV ) {
+ if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(views[iV])) {
+ vtkRenderer *aRenderer = vtkWnd->getRenderer();
+ vtkActorCollection *aCollection = aRenderer->GetActors();
+ aCollection->InitTraversal();
+ while(vtkActor *anAct = aCollection->GetNextActor()){
+ if(SMESH_Actor *actor = dynamic_cast<SMESH_Actor*>(anAct)){
+ vtkWnd->RemoveActor(actor);
+ actor->Delete();
+ }
+ }
+ }
+ }
+ TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.begin();
+ for ( ; anIter != VISUAL_OBJ_CONT.end(); ++anIter ) {
+ // for unknown reason, object destructor is not called, so clear object manually
+ anIter->second->GetUnstructuredGrid()->SetCells(0,0,0);
+ anIter->second->GetUnstructuredGrid()->SetPoints(0);
+ }
+ VISUAL_OBJ_CONT.clear();
+ }
+ }
+ //================================================================================
+ /*!
+ * \brief Notify the user on problems during visualization
+ */
+ //================================================================================
+
+ void OnVisuException()
+ {
+ SUIT_MessageBox::warn1 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
+ QObject::tr("SMESH_VISU_PROBLEM"),
+ QObject::tr("SMESH_BUT_OK"));
+ }
+ //================================================================================
+ /*!
+ * \brief Returns an updated visual object
+ */
+ //================================================================================
+
TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
TVisualObjPtr aVisualObj;
+ TVisualObjCont::key_type aKey(theStudyId,theEntry);
try{
- TVisualObjCont::key_type aKey(theStudyId,theEntry);
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
TVisualObjCont::iterator anIter = VISUAL_OBJ_CONT.find(aKey);
if(anIter != VISUAL_OBJ_CONT.end()){
aVisualObj = anIter->second;
}else{
- SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
+ SalomeApp_Application* app =
+ dynamic_cast<SalomeApp_Application*>( SMESHGUI::activeStudy()->application() );
_PTR(Study) aStudy = SMESHGUI::activeStudy()->studyDS();
_PTR(SObject) aSObj = aStudy->FindObjectID(theEntry);
if(aSObj){
SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
if(!aMesh->_is_nil()){
aVisualObj.reset(new SMESH_MeshObj(aMesh));
- aVisualObj->Update();
TVisualObjCont::value_type aValue(aKey,aVisualObj);
VISUAL_OBJ_CONT.insert(aValue);
- return aVisualObj;
}
//Try narrow to SMESH_Group interafce
SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObj);
TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
- aVisualObj->Update();
TVisualObjCont::value_type aValue(aKey,aVisualObj);
VISUAL_OBJ_CONT.insert(aValue);
- return aVisualObj;
}
}
//Try narrow to SMESH_subMesh interafce
TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
- aVisualObj->Update();
TVisualObjCont::value_type aValue(aKey,aVisualObj);
VISUAL_OBJ_CONT.insert(aValue);
- return aVisualObj;
}
}
}
}
}catch(...){
INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
+ return TVisualObjPtr();
+ }
+ // Update object
+ bool objModified = false;
+ if ( aVisualObj ) {
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ objModified = aVisualObj->Update();
+ }
+ catch (...) {
+#ifdef _DEBUG_
+ cout << "Exception in SMESHGUI_VTKUtils::GetVisualObj()" << endl;
+#endif
+ OnVisuException();
+ RemoveVisualObjectWithActors( theEntry ); // remove this object
+ aVisualObj.reset();
+ }
}
+
+ if ( objModified ) {
+ // PAL16631. Mesurements showed that to show aVisualObj in shading mode,
+ // ~10 times more memory is used than it occupies.
+ // Warn the user if there is less free memory than 30 sizes of a grid
+ int freeMB = SMDS_Mesh::CheckMemory(true);
+ int usedMB = aVisualObj->GetUnstructuredGrid()->GetActualMemorySize() / 1024;
+ if ( freeMB > 0 && usedMB * 30 > freeMB ) {
+ int continu = SUIT_MessageBox::warn2
+ (SMESHGUI::desktop(),
+ QObject::tr("SMESH_WRN_WARNING"),
+ QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
+ QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"),
+ 1, 0, 1);
+ if ( !continu ) {
+ // remove the corresponding actors from all views
+ RemoveVisualObjectWithActors( theEntry );
+ aVisualObj.reset();
+ }
+ }
+ }
+
return aVisualObj;
}
- SVTK_ViewWindow*
- GetViewWindow(const SalomeApp_Module* theModule)
+ /*! Return active view window, if it instantiates SVTK_ViewWindow class,
+ * overwise find or create corresponding view window, make it active and return it.
+ * \note Active VVTK_ViewWindow can be returned, because it inherits SVTK_ViewWindow.
+ */
+ SVTK_ViewWindow* GetViewWindow (const SalomeApp_Module* theModule,
+ bool createIfNotFound)
{
- if (SalomeApp_Application* anApp = theModule->getApp())
- return dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow());
+ SalomeApp_Application* anApp;
+ if (theModule)
+ anApp = theModule->getApp();
+ else
+ anApp = dynamic_cast<SalomeApp_Application*>
+ (SUIT_Session::session()->activeApplication());
+
+ if (anApp) {
+ if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow()))
+ return aView;
+
+ SUIT_ViewManager* aViewManager =
+ anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
+ if (aViewManager) {
+ if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
+ if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
+ aViewWindow->raise();
+ aViewWindow->setFocus();
+ return aView;
+ }
+ }
+ }
+ }
return NULL;
}
- SVTK_ViewWindow* FindVtkViewWindow( SUIT_ViewManager* theMgr,
- SUIT_ViewWindow* theWindow )
+ SVTK_ViewWindow* FindVtkViewWindow (SUIT_ViewManager* theMgr,
+ SUIT_ViewWindow * theWindow)
{
if( !theMgr )
return NULL;
return NULL;
}
-
SVTK_ViewWindow* GetVtkViewWindow(SUIT_ViewWindow* theWindow){
return dynamic_cast<SVTK_ViewWindow*>(theWindow);
}
-
/* SUIT_ViewWindow* GetActiveWindow()
{
SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
return GetVtkViewWindow( GetActiveWindow() );
}
+
+ void RepaintCurrentView()
+ {
+ if (SVTK_ViewWindow* wnd = GetCurrentVtkView())
+ {
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ wnd->getRenderer()->Render();
+ wnd->Repaint(false);
+ }
+ catch (...) {
+ OnVisuException();
+#ifdef _DEBUG_
+ cout << "Exception in SMESHGUI_VTKUtils::RepaintCurrentView()" << endl;
+#endif
+ }
+ }
+ }
+
void RepaintViewWindow(SVTK_ViewWindow* theWindow)
{
- theWindow->Repaint();
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ theWindow->getRenderer()->Render();
+ theWindow->Repaint();
+ }
+ catch (...) {
+ OnVisuException();
+#ifdef _DEBUG_
+ cout << "Exception in SMESHGUI_VTKUtils::RepaintViewWindow(SVTK_ViewWindow)" << endl;
+#endif
+ }
}
void RenderViewWindow(SVTK_ViewWindow* theWindow)
{
- theWindow->getRenderer()->Render();
- theWindow->Repaint();
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ theWindow->getRenderer()->Render();
+ theWindow->Repaint();
+ }
+ catch (...) {
+ OnVisuException();
+#ifdef _DEBUG_
+ cout << "Exception in SMESHGUI_VTKUtils::RenderViewWindow(SVTK_ViewWindow)" << endl;
+#endif
+ }
}
+ void FitAll(){
+ if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ wnd->onFitAll();
+ wnd->Repaint();
+ }
+ catch (...) {
+ OnVisuException();
+#ifdef _DEBUG_
+ cout << "Exception in SMESHGUI_VTKUtils::FitAll()" << endl;
+#endif
+ }
+ }
+ }
+
+
SMESH_Actor* FindActorByEntry(SUIT_ViewWindow *theWindow,
const char* theEntry)
{
void DisplayActor( SUIT_ViewWindow *theWnd, SMESH_Actor* theActor){
if(SVTK_ViewWindow* vtkWnd = GetVtkViewWindow(theWnd)){
- vtkWnd->AddActor(theActor);
- vtkWnd->Repaint();
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ vtkWnd->AddActor(theActor);
+ vtkWnd->Repaint();
+ }
+ catch (...) {
+ OnVisuException();
+#ifdef _DEBUG_
+ cout << "Exception in SMESHGUI_VTKUtils::DisplayActor()" << endl;
+#endif
+ }
}
}
}
}
-
- void FitAll(){
- if(SVTK_ViewWindow* wnd = GetCurrentVtkView() ){
- wnd->onFitAll();
- wnd->Repaint();
- }
- }
-
- vtkRenderer* GetCurrentRenderer(){
- if(SVTK_ViewWindow* wnd = GetCurrentVtkView() )
- return wnd->getRenderer();
- return NULL;
- }
-
- void RepaintCurrentView(){
- if(SVTK_ViewWindow* wnd = GetCurrentVtkView() )
- {
- wnd->getRenderer()->Render();
- wnd->Repaint(false);
- }
- }
-
void UpdateView(SUIT_ViewWindow *theWnd, EDisplaing theAction, const char* theEntry)
{
if(SVTK_ViewWindow* aViewWnd = GetVtkViewWindow(theWnd)){
case eDisplay:
case eDisplayOnly:
anActor->SetVisibility(true);
+ if (theAction == eDisplayOnly) aRenderer->ResetCameraClippingRange();
break;
case eErase:
anActor->SetVisibility(false);
_PTR(Study) aDocument = aStudy->studyDS();
if((anActor = CreateActor(aDocument,theEntry,true))) {
DisplayActor(theWnd,anActor);
- FitAll();
+ // FitAll(); - PAL16770(Display of a group performs an automatic fit all)
}
break;
}
{
_PTR(Study) aStudy = GetActiveStudyDocument();
CORBA::Long anId = aStudy->StudyId();
- TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry());
- if( aVisualObj )
- aVisualObj->Update();
- if ( theDisplay )
- UpdateView(SMESH::eDisplay,theIO->getEntry());
+ if ( TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,theIO->getEntry())) {
+ // if( aVisualObj )
+ // aVisualObj->Update(); -> PAL16631, already done in GetVisualObj()
+ if ( theDisplay )
+ UpdateView(SMESH::eDisplay,theIO->getEntry());
+ }
}
// update VTK viewer properties
if(SVTK_ViewWindow* aVtkView = GetVtkViewWindow( views[i] )){
// mesh element selection
- aVtkView->SetSelectionProp(aSelColor.red()/255.,
+ aVtkView->SetSelectionProp(aSelColor.red()/255.,
aSelColor.green()/255.,
- aSelColor.blue()/255.,
+ aSelColor.blue()/255.,
SW );
// tolerances
aVtkView->SetSelectionTolerance(SP1, SP2);
// pre-selection
- aVtkView->SetPreselectionProp(aPreColor.red()/255.,
+ aVtkView->SetPreselectionProp(aPreColor.red()/255.,
aPreColor.green()/255.,
- aPreColor.blue()/255.,
+ aPreColor.blue()/255.,
PW);
// update actors
vtkRenderer* aRenderer = aVtkView->getRenderer();
aCollection->InitTraversal();
while(vtkActor *anAct = aCollection->GetNextActor()){
if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
- anActor->SetHighlightColor(aHiColor.red()/255.,
+ anActor->SetHighlightColor(aHiColor.red()/255.,
aHiColor.green()/255.,
aHiColor.blue()/255.);
- anActor->SetPreHighlightColor(aPreColor.red()/255.,
+ anActor->SetPreHighlightColor(aPreColor.red()/255.,
aPreColor.green()/255.,
aPreColor.blue()/255.);
}
//----------------------------------------------------------------------------
- SVTK_Selector*
+ SVTK_Selector*
GetSelector(SUIT_ViewWindow *theWindow)
{
if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow))