Salome HOME
[EDF] AsterStudy: fit 3D view to given presentations V8_5_asterstudy
authorvsr <vsr@opencascade.com>
Tue, 11 Sep 2018 14:40:19 +0000 (17:40 +0300)
committervsr <vsr@opencascade.com>
Tue, 11 Sep 2018 14:40:19 +0000 (17:40 +0300)
src/SALOME_SWIG/SALOMEGUI_Swig.cxx
src/SALOME_SWIG/SALOMEGUI_Swig.hxx
src/SALOME_SWIG/SALOMEGUI_Swig.i
src/SVTK/SVTK_Renderer.cxx
src/SVTK/SVTK_Renderer.h
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h

index 32178b8948880aea4b46df82e65f9d687cd2bb27..ff1eaf98bbbec700bfcbf2a40a0aaf50707df4e1 100644 (file)
@@ -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<SVTK_ViewWindow*>( window ) )
+            (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitSelection();
+#endif
+#if !defined(DISABLE_OCCVIEWER)
+          if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
+            (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFitSelection();
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent() );
+}
+
+void SALOMEGUI_Swig::FitIObjects(const std::list<std::string>& entries)
+{
+  class TEvent: public SALOME_Event
+  {
+    const std::list<std::string>& myEntries;
+  public:
+    TEvent( const std::list<std::string>& 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<std::string>::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<SVTK_ViewWindow*>( window ) )
+            (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitIObjects( objects );
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent( entries ) );
+}
+
 /*!
   \brief Reset current view window to the default state.
 */
index 6b537c8c993d36ee9c9441d80f5dbcb673947504..297dbe0afc8560401f871a879b64c20c36b36639 100644 (file)
@@ -27,6 +27,9 @@
 #ifndef SALOMEGUI_SWIG_HXX
 #define SALOMEGUI_SWIG_HXX
 
+#include <string>
+#include <list>
+
 class SALOMEGUI_Swig
 {
 public:
@@ -58,6 +61,8 @@ public:
   void             UpdateView();
 
   void             FitAll();
+  void             FitSelection();
+  void             FitIObjects(const std::list<std::string>&);
   void             ResetView();
   void             ViewTop();
   void             ViewBottom();
index 10631d8810232ab643ce9b2dd737a515e7924bd2..00614acadb8de9423af85c0d12742daaae865aa1 100644 (file)
 %}
 
 %include "cpointer.i"
+%include "std_string.i"
+%include "std_list.i"
+
+#if SWIG_VERSION >= 0x010329
+%template() std::list<std::string>;
+#endif
 
 /* Exception handler for all functions */
 %exception {
@@ -85,6 +91,8 @@ public:
 
   /* view operations */
   void FitAll();
+  void FitSelection();
+  void FitIObjects(const std::list<std::string>&);
   void ResetView();
   void ViewTop();
   void ViewBottom();
index b763565036dee2438591f8b4603b66b894139a1c..4ce4cae00a2635069df61594ea84fe7202a80a8e 100644 (file)
@@ -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
 */
index ab5e4318b9132aa5f094afa302a9ed0c3478d66d..e5232dcbf38757c76a6c7076f7da0850c55e5374 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "SVTK.h"
 #include "VTKViewer.h"
+#include "SALOME_ListIO.hxx"
 
 #include <vtkObject.h>
 #include <vtkSmartPointer.h>
@@ -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(); 
 
index c2daba5045dcc4cf43307be95d073df0957c7a20..3e51def0a77bf4b92aa97f88fa14c76d1161e2cc 100755 (executable)
@@ -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
 */
index d43e7678376e82f04da6bab8c9e336dda19ef865..5ed84511983665b23d4c0aea7a6c1352bfa89ae1 100755 (executable)
@@ -33,6 +33,7 @@
 #include "SUIT_ViewWindow.h"
 
 #include "SALOME_InteractiveObject.hxx"
+#include "SALOME_ListIO.hxx"
 
 #include <QImage>
 #include <vtkSmartPointer.h>
@@ -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);