X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVISUGUI%2FVisuGUI_ViewTools.h;h=bb28861a977638c2bca62288146376f408b06e1d;hb=e208a04edd5d8cebc0185834ecdf3faec4514f99;hp=f10bf63e9a5ee9e442e82c94967aa191dd359286;hpb=776278fcaf14fcaa6265ddca8116a6a0209aa375;p=modules%2Fvisu.git diff --git a/src/VISUGUI/VisuGUI_ViewTools.h b/src/VISUGUI/VisuGUI_ViewTools.h index f10bf63e..bb28861a 100644 --- a/src/VISUGUI/VisuGUI_ViewTools.h +++ b/src/VISUGUI/VisuGUI_ViewTools.h @@ -30,34 +30,36 @@ #include "VisuGUI.h" -#include "SUIT_MessageBox.h" -#include "SUIT_ViewManager.h" -#include "SUIT_ViewWindow.h" +#include "VisuGUI_Tools.h" + +#include "VISU_Prs3d_i.hh" +#include "VISU_Table_i.hh" +#include "VISU_ViewManager_i.hh" + +#include "VISU_Actor.h" #include "SalomeApp_Module.h" #include "SalomeApp_Application.h" -#include "VISU_Prs3d_i.hh" - #include "VVTK_ViewModel.h" #include "VVTK_ViewWindow.h" +#include "SVTK_Functor.h" #include "SVTK_ViewModel.h" #include "SVTK_ViewWindow.h" -#include "VisuGUI_Tools.h" +#include "SPlot2d_ViewModel.h" + #include "VTKViewer_Algorithm.h" -#include "SVTK_Functor.h" -#include "VISU_Table_i.hh" -#include "VISU_ViewManager_i.hh" +#include "SUIT_Session.h" +#include "SUIT_MessageBox.h" +#include "SUIT_ViewManager.h" +#include "SUIT_ViewWindow.h" + #include "SALOME_ListIO.hxx" #include "SALOME_ListIteratorOfListIO.hxx" -#include "SPlot2d_ViewModel.h" - -#include "VISU_Actor.h" - #include #include @@ -65,17 +67,26 @@ class VVTK_Viewer; namespace VISU { - //--------------------------------------------------------------- + /*! Return active view window, if it instantiates TViewer::TViewWindow class, + * overwise find or create corresponding view window, make it active and return it. + * \note Active VVTK_ViewWindow can be returned by request GetViewWindow(), + * because VVTK_ViewWindow inherits SVTK_ViewWindow. + */ template inline typename TViewer::TViewWindow* - GetViewWindow(VisuGUI* theModule, - const bool theIsViewCreate = false) + GetViewWindow(VisuGUI* theModule) { - typedef typename TViewer::TViewWindow TView; - if(SUIT_ViewManager* aViewManager = theModule->getViewManager(TViewer::Type(),theIsViewCreate)){ - if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){ - if(TView* aView = dynamic_cast(aViewWindow)){ + typedef typename TViewer::TViewWindow TViewWindow; + if (SalomeApp_Application* anApp = theModule->getApp()) { + if (TViewWindow* aView = dynamic_cast(anApp->desktop()->activeWindow())) + return aView; + } + SUIT_ViewManager* aViewManager = + theModule->getViewManager(TViewer::Type(), /*create = */true); + if (aViewManager) { + if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) { + if (TViewWindow* aView = dynamic_cast(aViewWindow)) { aViewWindow->raise(); aViewWindow->setFocus(); return aView; @@ -85,30 +96,54 @@ namespace VISU return NULL; } + /*! Return active view window, if it instantiates TViewWindow class, overwise return NULL. + * \note Active VVTK_ViewWindow can be returned by request GetActiveViewWindow(), + * because VVTK_ViewWindow inherits SVTK_ViewWindow. + */ + template + inline + TViewWindow* + GetActiveViewWindow(const SalomeApp_Module* theModule = NULL) + { + SalomeApp_Application* anApp = NULL; + if (theModule) + anApp = theModule->getApp(); + else + anApp = dynamic_cast + (SUIT_Session::session()->activeApplication()); + + if (anApp) + if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) + if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) + return dynamic_cast(aViewWindow); + + return NULL; + } + //--------------------------------------------------------------- - template inline VISU_Actor* PublishInView(VisuGUI* theModule, Prs3d_i* thePrs, - const bool theIsHighlight = false, - const bool theIsCreateView = false) + SVTK_ViewWindow* theViewWindow, + const bool theIsHighlight = false) { - typedef typename TViewer::TViewWindow TView; - if(TView* aView = GetViewWindow(theModule,theIsCreateView)){ + if (theViewWindow) { QApplication::setOverrideCursor( Qt::waitCursor ); try { - if(VISU_Actor* anActor = thePrs->CreateActor()){ - aView->AddActor(anActor); - if(theIsHighlight) - aView->highlight(anActor->getIO(),true); - aView->getRenderer()->ResetCameraClippingRange(); - aView->Repaint(); + if (VISU_Actor* anActor = thePrs->CreateActor()) { + theViewWindow->AddActor(anActor); + if (theIsHighlight) + theViewWindow->highlight(anActor->getIO(),true); + theViewWindow->getRenderer()->ResetCameraClippingRange(); + theViewWindow->Repaint(); QApplication::restoreOverrideCursor(); return anActor; } } catch(std::exception& exc) { + thePrs->RemoveActors(); + QApplication::restoreOverrideCursor(); INFOS(exc.what()); SUIT_MessageBox::warn1 @@ -122,56 +157,53 @@ namespace VISU //--------------------------------------------------------------- - template inline VISU_Actor* UpdateViewer(VisuGUI* theModule, VISU::Prs3d_i* thePrs, bool theDispOnly = false, - const bool theIsHighlight = false, - const bool theIsViewCreate = false) + const bool theIsHighlight = false) { - typedef typename TViewer::TViewWindow TView; - if(TView* aView = GetViewWindow(theModule,theIsViewCreate)){ - vtkRenderer *aRen = aView->getRenderer(); + if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow(theModule)) { + vtkRenderer *aRen = aViewWindow->getRenderer(); vtkActorCollection *anActColl = aRen->GetActors(); anActColl->InitTraversal(); VISU_Actor* aResActor = NULL; - while(vtkActor *anAct = anActColl->GetNextActor()){ - if(VISU_Actor* anActor = dynamic_cast(anAct)){ - if(VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d()){ - if(thePrs == aPrs3d){ + bool isOk = true; + while (vtkActor *anAct = anActColl->GetNextActor()) { + if (VISU_Actor* anActor = dynamic_cast(anAct)) { + if (VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d()) { + if (thePrs == aPrs3d) { try { + aResActor = anActor; thePrs->UpdateActors(); + aResActor->VisibilityOn(); } catch (std::runtime_error& exc) { + thePrs->RemoveActors(); + isOk = false; + INFOS(exc.what()); - QApplication::restoreOverrideCursor(); SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"), QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()), QObject::tr("BUT_OK")); - - thePrs->RemoveActors(); - return NULL; } - aResActor = anActor; - aResActor->VisibilityOn(); - }else if(theDispOnly){ + } else if (theDispOnly) { anActor->VisibilityOff(); } - }else if(theDispOnly && anActor->GetVisibility()){ + } else if (theDispOnly && anActor->GetVisibility()) { anActor->VisibilityOff(); } } } - if(aResActor){ - if(theIsHighlight) - aView->highlight(aResActor->getIO(),true); - aView->getRenderer()->ResetCameraClippingRange(); - aView->Repaint(); + if (aResActor) { + if (theIsHighlight && isOk) + aViewWindow->highlight(aResActor->getIO(), true); + aViewWindow->getRenderer()->ResetCameraClippingRange(); + aViewWindow->Repaint(); return aResActor; } - return PublishInView(theModule,thePrs,theIsHighlight,theIsViewCreate); + return PublishInView(theModule, thePrs, aViewWindow, theIsHighlight); } return NULL; } @@ -184,14 +216,14 @@ namespace VISU OnEraseAll(VisuGUI* theModule) { typedef typename TViewer::TViewWindow TViewWindow; - if(TViewWindow* aViewWindow = GetViewWindow(theModule)){ + if (TViewWindow* aViewWindow = GetActiveViewWindow(theModule)) { aViewWindow->unHighlightAll(); - if(vtkRenderer *aRen = aViewWindow->getRenderer()){ + if (vtkRenderer *aRen = aViewWindow->getRenderer()) { vtkActorCollection *aCollection = aRen->GetActors(); aCollection->InitTraversal(); - while(vtkActor *anAct = aCollection->GetNextActor()){ - if(anAct->GetVisibility() > 0) - if(SALOME_Actor* anActor = dynamic_cast(anAct)){ + while (vtkActor *anAct = aCollection->GetNextActor()) { + if (anAct->GetVisibility() > 0) + if (SALOME_Actor* anActor = dynamic_cast(anAct)) { anActor->VisibilityOff(); } } @@ -199,57 +231,37 @@ namespace VISU } } } - + template<> inline void OnEraseAll(VisuGUI* theModule) { - if(SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule,false)) + if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false)) aPlot2d->EraseAll(); } //--------------------------------------------------------------- - template - inline - VISU_Actor* - FindActor(TVieweWindow* theViewWindow, - const char* theEntry) - { - using namespace SVTK; - if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){ - if(vtkActorCollection* aCollection = aRenderer->GetActors()){ - if(VISU_Actor* anActor = Find(aCollection,TIsSameEntry(theEntry))){ - return anActor; - } - } - } - return NULL; - } - - template inline void ErasePrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs, - const bool thIsUpdate = true) + const bool theDoRepaintVW = true) { - typedef typename TViewer::TViewWindow TViewWindow; - if(TViewWindow* aViewWindow = GetViewWindow(theModule)){ - if(VISU_Actor* anActor = FindActor(aViewWindow,thePrs)){ + if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow(theModule)) { + if (VISU_Actor* anActor = FindActor(aViewWindow, thePrs)) { anActor->VisibilityOff(); - if(thIsUpdate) + if (theDoRepaintVW) aViewWindow->Repaint(); } } } - void ErasePrs(VisuGUI* theModule, - VISU::Base_ptr theBase, - bool thIsUpdate); + CORBA::Object_ptr theObject, + bool theDoRepaintVW); } #endif