]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
*** empty log message ***
authorouv <ouv@opencascade.com>
Wed, 10 Aug 2005 12:49:57 +0000 (12:49 +0000)
committerouv <ouv@opencascade.com>
Wed, 10 Aug 2005 12:49:57 +0000 (12:49 +0000)
src/SVTK/SVTK_View.cxx [new file with mode: 0644]
src/SVTK/SVTK_View.h [new file with mode: 0644]

diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx
new file mode 100644 (file)
index 0000000..33bb458
--- /dev/null
@@ -0,0 +1,382 @@
+#include "SALOME_Actor.h"
+
+#include <qapplication.h>
+
+#include <vtkTextProperty.h>
+#include <vtkActorCollection.h>
+#include <vtkRenderer.h>
+#include <vtkCamera.h>
+#include <vtkPointPicker.h>
+#include <vtkCellPicker.h>
+#include <vtkGenericRenderWindowInteractor.h>
+
+#include "QtxAction.h"
+
+#include "SUIT_Session.h"
+#include "SUIT_ToolButton.h"
+#include "SUIT_MessageBox.h"
+
+#include "SUIT_Tools.h"
+#include "SUIT_ResourceMgr.h"
+
+#include "VTKViewer_Utilities.h"
+#include "VTKViewer_CellRectPicker.h"
+
+#include "SVTK_View.h"
+#include "SVTK_ViewModel.h"
+#include "SVTK_InteractorStyle.h"
+
+#include "SALOME_ListIteratorOfListIO.hxx"
+
+#include "SVTK_SelectorDef.h"
+
+#include "VTKViewer_Algorithm.h"
+#include "SVTK_Functor.h"
+
+//----------------------------------------------------------------------------
+SVTK_View
+::SVTK_View( QWidget* parent, const char* name ) :
+  SVTK_RenderWindowInteractor( parent, name )
+{
+}
+
+//----------------------------------------------------------------------------
+SVTK_View
+::~SVTK_View()
+{
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::SetInteractorStyle( SVTK_InteractorStyle* theStyle )
+{
+  myInteractorStyle = theStyle;
+  getInteractor()->SetInteractorStyle( theStyle ); 
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::activateZoom()
+{
+  myInteractorStyle->startZoom();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::activatePanning()
+{
+  myInteractorStyle->startPan();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::activateRotation()
+{
+  myInteractorStyle->startRotate();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::activateGlobalPanning()
+{
+  myInteractorStyle->startGlobalPan();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::activateWindowFit()
+{
+  myInteractorStyle->startFitArea();
+}
+
+//----------------------------------------------------------------
+struct THighlightAction{
+  bool myIsHighlight;
+  THighlightAction( bool theIsHighlight ): myIsHighlight(theIsHighlight) {}
+  void operator()( SALOME_Actor* theActor) {
+    if(theActor->GetMapper()){
+      theActor->highlight( myIsHighlight );
+    }
+  }
+};
+
+//----------------------------------------------------------------
+void
+SVTK_View
+::onSelectionChanged()
+{
+  unHighlightAll();
+
+  const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
+  SALOME_ListIteratorOfListIO anIter(aListIO);
+  for(; anIter.More(); anIter.Next()){
+    highlight(anIter.Value(),true,!anIter.More());
+  }
+
+  emit selectionChanged();
+}
+
+//----------------------------------------------------------------
+void
+SVTK_View
+::SetSelectionMode(Selection_Mode theMode)
+{
+  mySelector->SetSelectionMode(theMode);
+
+  //myRWInteractor->SetSelectionMode(theMode);
+}
+
+//----------------------------------------------------------------
+Selection_Mode
+SVTK_View
+::SelectionMode() const
+{
+  return mySelector->SelectionMode();
+}
+
+//----------------------------------------------------------------
+void 
+SVTK_View
+::unHighlightAll() 
+{
+  //cout << "--------------------------------------------------" << endl;
+  //cout << "SVTK_View::unHighlightAll" << endl;
+
+  using namespace VTK;
+  ForEach<SALOME_Actor>( getRenderer()->GetActors(),
+                        THighlightAction( false ) );
+
+  //myRenderWindow->update();
+}
+
+//----------------------------------------------------------------
+void
+SVTK_View
+::highlight( const Handle(SALOME_InteractiveObject)& theIO, 
+            bool theIsHighlight, 
+            bool theIsUpdate ) 
+{
+  using namespace VTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>(theIO),
+                         THighlightAction(theIsHighlight));
+
+  //myRenderWindow->update();
+}
+
+#define INCREMENT_FOR_OP 10
+
+//=======================================================================
+// name    : onPanLeft
+// Purpose : Performs incremental panning to the left
+//=======================================================================
+void
+SVTK_View
+::onPanLeft()
+{
+  myInteractorStyle->IncrementalPan( -INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name    : onPanRight
+// Purpose : Performs incremental panning to the right
+//=======================================================================
+void
+SVTK_View
+::onPanRight()
+{
+  myInteractorStyle->IncrementalPan( INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name    : onPanUp
+// Purpose : Performs incremental panning to the top
+//=======================================================================
+void
+SVTK_View
+::onPanUp()
+{
+  myInteractorStyle->IncrementalPan( 0, INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name    : onPanDown
+// Purpose : Performs incremental panning to the bottom
+//=======================================================================
+void
+SVTK_View
+::onPanDown()
+{
+  myInteractorStyle->IncrementalPan( 0, -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name    : onZoomIn
+// Purpose : Performs incremental zooming in
+//=======================================================================
+void
+SVTK_View
+::onZoomIn()
+{
+  myInteractorStyle->IncrementalZoom( INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name    : onZoomOut
+// Purpose : Performs incremental zooming out
+//=======================================================================
+void
+SVTK_View
+::onZoomOut()
+{
+  myInteractorStyle->IncrementalZoom( -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name    : onRotateLeft
+// Purpose : Performs incremental rotating to the left
+//=======================================================================
+void
+SVTK_View
+::onRotateLeft()
+{
+  myInteractorStyle->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name    : onRotateRight
+// Purpose : Performs incremental rotating to the right
+//=======================================================================
+void
+SVTK_View
+::onRotateRight()
+{
+  myInteractorStyle->IncrementalRotate( INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// name    : onRotateUp
+// Purpose : Performs incremental rotating to the top
+//=======================================================================
+void
+SVTK_View
+::onRotateUp()
+{
+  myInteractorStyle->IncrementalRotate( 0, -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// name    : onRotateDown
+// Purpose : Performs incremental rotating to the bottom
+//=======================================================================
+void
+SVTK_View
+::onRotateDown()
+{
+  myInteractorStyle->IncrementalRotate( 0, INCREMENT_FOR_OP );
+}
+/*
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors )
+{
+  //cout << "SVTK_View::InsertActor" << endl;
+  theActor->AddToRender( getRenderer() );
+
+  //theActor->SetTransform(myTransform);
+  //if(theMoveInternalActors) 
+  //  myRWInteractor->MoveInternalActors();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::AddActor( VTKViewer_Actor* theActor, bool theUpdate )
+{
+  InsertActor(theActor);
+  if(theUpdate) 
+    Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate )
+{
+  //cout << "SVTK_View::RemoveActor" << endl;
+  theActor->RemoveFromRender( getRenderer() );
+
+  if(theUpdate) 
+    Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::MoveActor( VTKViewer_Actor* theActor)
+{
+  RemoveActor(theActor);
+  InsertActor(theActor,true);
+}
+*/
+/*
+//----------------------------------------------------------------------------
+QImage
+SVTK_View
+::dumpView()
+{
+  QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
+  return px.convertToImage();
+}
+*/
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::SetSelectionProp(const double& theRed, 
+                  const double& theGreen, 
+                  const double& theBlue, 
+                  const int& theWidth) 
+{
+  vtkActorCollection* anActors = getRenderer()->GetActors();
+  anActors->InitTraversal();
+  while( vtkActor* anActor = anActors->GetNextActor() )
+  {
+    if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
+    {
+      aSActor->getPointProperty()->SetColor( theRed, theGreen, theBlue );
+      aSActor->getPointProperty()->SetLineWidth( theWidth );
+
+      aSActor->getCellProperty()->SetColor( theRed, theGreen, theBlue );
+      aSActor->getCellProperty()->SetLineWidth( theWidth );
+
+      aSActor->getEdgeProperty()->SetColor( theRed, theGreen, theBlue );
+      aSActor->getEdgeProperty()->SetLineWidth( theWidth );
+    }
+  }
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::SetSelectionTolerance(const double& theTolNodes, 
+                       const double& theTolItems)
+{
+  vtkActorCollection* anActors = getRenderer()->GetActors();
+  anActors->InitTraversal();
+  while( vtkActor* anActor = anActors->GetNextActor() )
+  {
+    if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
+    {
+      aSActor->getPointPicker()->SetTolerance( theTolNodes );
+      aSActor->getCellPicker()->SetTolerance( theTolItems );
+      aSActor->getCellRectPicker()->SetTolerance( theTolItems );
+    }
+  }
+}
diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h
new file mode 100644 (file)
index 0000000..1c8fd0f
--- /dev/null
@@ -0,0 +1,131 @@
+#ifndef SVTK_VIEW_H
+#define SVTK_VIEW_H
+
+#ifdef WIN32
+#pragma warning( disable:4251 )
+#endif
+
+#include "SVTK.h"
+#include "SVTK_Selection.h"
+#include "SVTK_RenderWindowInteractor.h"
+
+#include "SALOME_InteractiveObject.hxx"
+
+class VTKViewer_Actor;
+
+class SVTK_Viewer;
+class SVTK_Selector;
+
+class SVTK_RenderWindow;
+class SVTK_InteractorStyle;
+
+class SVTK_EXPORT SVTK_View : public SVTK_RenderWindowInteractor
+{
+  Q_OBJECT
+
+public:
+  SVTK_View( QWidget*, const char* );
+  virtual ~SVTK_View();
+  
+  SVTK_Selector* GetSelector() { return mySelector; }
+  void SetSelector( SVTK_Selector* theSelector ) { mySelector = theSelector; }
+
+  SVTK_InteractorStyle* GetInteractorStyle() { return myInteractorStyle; }
+  void SetInteractorStyle( SVTK_InteractorStyle* );
+
+  Selection_Mode SelectionMode() const;
+  void SetSelectionMode( Selection_Mode );
+
+  /*  interactive object management */
+  void highlight( const Handle(SALOME_InteractiveObject)& IObject, 
+                  bool highlight, bool immediatly = true );
+  void unHighlightAll();
+  bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject );
+  bool isVisible( const Handle(SALOME_InteractiveObject)& IObject );
+
+  /* selection */
+  Handle(SALOME_InteractiveObject) FindIObject(const char* Entry);
+  
+  /* display */                
+  void Display( const Handle(SALOME_InteractiveObject)& IObject,
+                bool immediatly = true );
+  void DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject );
+  void Erase( const Handle(SALOME_InteractiveObject)& IObject,
+              bool immediatly = true );
+  void DisplayAll();
+  void EraseAll();
+  void Repaint( bool theUpdateTrihedron );
+  void Repaint() { Repaint(true); }
+
+  //apply existing transformation on adding SALOME_Actor
+  //void AddActor( VTKViewer_Actor*, bool update = false );
+  //void RemoveActor(VTKViewer_Actor*, bool update = false);
+
+  void AdjustTrihedrons( const bool forced );
+  //merge with V2_2_0_VISU_improvements:bool ComputeTrihedronSize( double& theNewSize,
+  //merge with V2_2_0_VISU_improvements:                          double& theOldSize );
+
+  void SetSelectionProp(const double& theRed = 1, 
+                       const double& theGreen = 1,
+                       const double& theBlue = 0, 
+                       const int& theWidth = 5);
+  void SetSelectionTolerance(const double& theTolNodes = 0.025, 
+                            const double& theTolCell = 0.001);
+
+public slots:
+  void onSelectionChanged();
+
+signals:
+  void selectionChanged();
+
+public slots:
+  void onPanLeft();
+  void onPanRight();
+  void onPanUp();
+  void onPanDown();
+  void onZoomIn();
+  void onZoomOut();
+  void onRotateLeft();
+  void onRotateRight();
+  void onRotateUp();
+  void onRotateDown();
+
+  virtual void activateZoom();
+  virtual void activateWindowFit();
+  virtual void activateRotation();
+  virtual void activatePanning(); 
+  virtual void activateGlobalPanning(); 
+
+protected:
+  //QImage dumpView();
+
+protected slots:
+  void onKeyPressed(QKeyEvent* event);
+  void onKeyReleased(QKeyEvent* event);
+  void onMousePressed(QMouseEvent* event);
+  void onMouseDoubleClicked(QMouseEvent* event);
+  void onMouseReleased(QMouseEvent* event);
+  void onMouseMoving(QMouseEvent* event);
+
+private:
+  void InitialSetup();
+  void InsertActor( VTKViewer_Actor* theActor,
+                    bool theMoveInternalActors = false );
+  void MoveActor( VTKViewer_Actor* theActor );
+
+private:  
+  SVTK_Viewer* myModel;
+  SVTK_Selector* mySelector;
+
+  SVTK_InteractorStyle* myInteractorStyle;
+
+  double myCurScale;
+
+  friend class SVTK_RenderWindowInteractor;
+};
+
+#ifdef WIN32
+#pragma warning( default:4251 )
+#endif
+
+#endif