From: vsr Date: Tue, 11 Sep 2018 14:40:19 +0000 (+0300) Subject: [EDF] AsterStudy: fit 3D view to given presentations X-Git-Tag: V9_1_0~1^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FV8_5_asterstudy;p=modules%2Fgui.git [EDF] AsterStudy: fit 3D view to given presentations --- diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx index 32178b894..ff1eaf98b 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx @@ -706,6 +706,63 @@ void SALOMEGUI_Swig::FitAll() ProcessVoidEvent( new TEvent() ); } +void SALOMEGUI_Swig::FitSelection() +{ + class TEvent: public SALOME_Event + { + public: + TEvent() {} + virtual void Execute() + { + if ( LightApp_Application* anApp = getApplication() ) { + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); + if ( window ) { +#if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER) + if ( dynamic_cast( window ) ) + (dynamic_cast( window ))->onFitSelection(); +#endif +#if !defined(DISABLE_OCCVIEWER) + if ( dynamic_cast( window ) ) + (dynamic_cast( window ))->onFitSelection(); +#endif + } + } + } + }; + ProcessVoidEvent( new TEvent() ); +} + +void SALOMEGUI_Swig::FitIObjects(const std::list& entries) +{ + class TEvent: public SALOME_Event + { + const std::list& myEntries; + public: + TEvent( const std::list& objs ) : myEntries( objs ) {} + virtual void Execute() + { + if ( LightApp_Application* anApp = getApplication() ) { + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); + if ( window ) { + SALOME_ListIO objects; + std::list::const_iterator it; + for ( it = myEntries.begin(); it != myEntries.end(); ++it ) + objects.Append( new SALOME_InteractiveObject( (*it).c_str(), "" ) ); +#if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER) + if ( dynamic_cast( window ) ) + (dynamic_cast( window ))->onFitIObjects( objects ); +#endif + } + } + } + }; + ProcessVoidEvent( new TEvent( entries ) ); +} + /*! \brief Reset current view window to the default state. */ diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.hxx b/src/SALOME_SWIG/SALOMEGUI_Swig.hxx index 6b537c8c9..297dbe0af 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.hxx +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.hxx @@ -27,6 +27,9 @@ #ifndef SALOMEGUI_SWIG_HXX #define SALOMEGUI_SWIG_HXX +#include +#include + class SALOMEGUI_Swig { public: @@ -58,6 +61,8 @@ public: void UpdateView(); void FitAll(); + void FitSelection(); + void FitIObjects(const std::list&); void ResetView(); void ViewTop(); void ViewBottom(); diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.i b/src/SALOME_SWIG/SALOMEGUI_Swig.i index 10631d881..00614acad 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.i +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.i @@ -29,6 +29,12 @@ %} %include "cpointer.i" +%include "std_string.i" +%include "std_list.i" + +#if SWIG_VERSION >= 0x010329 +%template() std::list; +#endif /* Exception handler for all functions */ %exception { @@ -85,6 +91,8 @@ public: /* view operations */ void FitAll(); + void FitSelection(); + void FitIObjects(const std::list&); void ResetView(); void ViewTop(); void ViewBottom(); diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index b76356503..4ce4cae00 100644 --- a/src/SVTK/SVTK_Renderer.cxx +++ b/src/SVTK/SVTK_Renderer.cxx @@ -726,6 +726,43 @@ void SVTK_Renderer::onFitSelection() } } +void SVTK_Renderer::OnFitIObjects(const SALOME_ListIO& objects) +{ + vtkActorCollection* aSelectedCollection = vtkActorCollection::New(); + + VTK::ActorCollectionCopy aCopy( GetDevice()->GetActors() ); + vtkActorCollection* aCollection = aCopy.GetActors(); + aCollection->InitTraversal(); + while ( vtkActor* aProp = aCollection->GetNextActor() ) + { + if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aProp ) ) { + const Handle(SALOME_InteractiveObject)& io = anActor->getIO(); + if ( anActor->GetVisibility() && !io.IsNull() ) { + SALOME_ListIteratorOfListIO iter( objects ); + for ( ; iter.More(); iter.Next() ) { + if ( iter.Value().IsNull() ) + continue; + if ( io->isSame( iter.Value() ) ) { + aSelectedCollection->AddItem( aProp ); + break; + } + } + } + } + } + + if( aSelectedCollection->GetNumberOfItems() == 0 ) + return; // if collection is empty + + double bounds[6]; + ::ComputeBounds( aSelectedCollection, bounds ); + + if ( aSelectedCollection->GetNumberOfItems() && ::isBoundValid( bounds ) ) { + GetDevice()->ResetCamera( bounds ); + GetDevice()->ResetCameraClippingRange( bounds ); + } +} + /*! Reset camera clipping range to adjust the range to the bounding box of the scene */ diff --git a/src/SVTK/SVTK_Renderer.h b/src/SVTK/SVTK_Renderer.h index ab5e4318b..e5232dcbf 100644 --- a/src/SVTK/SVTK_Renderer.h +++ b/src/SVTK/SVTK_Renderer.h @@ -29,6 +29,7 @@ #include "SVTK.h" #include "VTKViewer.h" +#include "SALOME_ListIO.hxx" #include #include @@ -187,6 +188,9 @@ class SVTK_EXPORT SVTK_Renderer : public vtkObject //! Fit all selected presentation in the scene void onFitSelection(); + //! Fit given presentations in the scene + void OnFitIObjects(const SALOME_ListIO& objects); + //! Set camera into predefined state void OnResetView(); diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index c2daba504..3e51def0a 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -459,6 +459,16 @@ void SVTK_ViewWindow::onFitSelection() emit transformed( this ); } +/*! + Processes transformation "fit given objects" +*/ +void SVTK_ViewWindow::onFitIObjects(const SALOME_ListIO& objects) +{ + GetRenderer()->OnFitIObjects(objects); + Repaint(); + emit transformed( this ); +} + /*! SLOT: called if selection is changed */ diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index d43e76783..5ed845119 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -33,6 +33,7 @@ #include "SUIT_ViewWindow.h" #include "SALOME_InteractiveObject.hxx" +#include "SALOME_ListIO.hxx" #include #include @@ -381,6 +382,9 @@ public slots: //! Redirect the request to #SVTK_Renderer::OnFitSelection virtual void onFitSelection(); + //! Redirect the request to #SVTK_Renderer::OnFitIObjects + virtual void onFitIObjects(const SALOME_ListIO&); + //! Redirect the request to #SVTK_Renderer::OnViewTrihedron virtual void onViewTrihedron(bool);